Page 1 of 1

[Lua]AOB counter

Posted: Sun Jul 25, 2021 6:24 pm
by LeFiXER
This will count the amount of bytes in a given AOB. Useful for readmem function and perhaps others. I felt that the process could be more simplified without having to manually count the bytes for a given AOB so made this.

Installation
Copy byteCounter.lua to X:\Program Files\Cheat Engine 7.2\autorun folder, where X is your main drive and restart Cheat Engine.

Usage
Step 1.
[Link]
Step 2.
[Link]
Step 3.
[Link]
Step 4.
[Link]

If this helped in any way, I would appreciate it if you could rate this post.

Thanks to all here that have shared their knowledge with this community. Without it, I would not have been able to accomplish this extension.

Thank you :)

Re: [Lua]AOB counter

Posted: Sun Jul 25, 2021 8:34 pm
by EpicBirdi
This was something I wanted/wondered about not even 12h ago lol
Thanks!

Re: [Lua]AOB counter

Posted: Sun Jul 25, 2021 10:01 pm
by ShyTwig16
Might I suggest having the output show both decimal and hex. So it can be used to calculate offsets for AOBs scripts as well.

Re: [Lua]AOB counter

Posted: Sun Jul 25, 2021 10:48 pm
by LeFiXER
Thanks for the suggestion. I've updated to reflect that :).

Re: [Lua]AOB counter

Posted: Tue Jan 18, 2022 12:32 am
by YoucefHam
LeFiXER wrote:
Sun Jul 25, 2021 6:24 pm
This will count the amount of bytes in a given AOB. Useful for readmem function and perhaps others. I felt that the process could be more simplified without having to manually count the bytes for a given AOB so made this.
....................
Hi :D,
so I was just browsing the tools topics, and I saw AOB SIGNATURE GENERATOR AND SCANNER by ShyTwig16, and there was a way to determine how many AOBs in the selection so I tried to use those functions with your code, here the results.
CODE

Code: Select all

function countBytes()
	local dv_address1 = getMemoryViewForm().DisassemblerView.SelectedAddress
	local dv_address2 = getMemoryViewForm().DisassemblerView.SelectedAddress2
	local startAddress = math.min(dv_address1, dv_address2)
	local startAddressBytes = getInstructionSize(startAddress)
	local endAddress = math.max(dv_address1, dv_address2)
	local endAddressBytes = getInstructionSize(endAddress)
	local length = endAddress + endAddressBytes - startAddress
	
	if length > startAddressBytes then
		ShowMessage('Bytes at Start: 		' .. startAddressBytes .. '  		(0x'.. string.format("%X", startAddressBytes) .. ')\nBytes at End:  		' .. endAddressBytes .. '  		(0x'.. string.format("%X", endAddressBytes) .. ')\nAOB Length:  		' .. length .. '  		(0x'.. string.format("%X", length) .. ')')
		return
	else
		local sBytes = inputQuery('Count bytes in AOB', 'Selected Address has: ' .. startAddressBytes .. '  (0x' .. string.format("%X", startAddressBytes) .. ') Bytes\n\nEnter bytes to count: ', readFromClipboard())
		if sBytes ~= nil then
			_,count = sBytes:gsub("%S+","")
			local hex = string.format("%X", count)
			ShowMessage('The AOB has '..count..' bytes.' .. '\nDec : ' .. count .. '\nHex : ' .. hex)
		end
	end
end

function addByteCountMenu()
	local parent = getMemoryViewForm().Component[113].Items
	byteMenu = createMenuItem(parent)
	parent.add(byteMenu)
	byteMenu.Caption = 'Byte Counter'
	byteMenu.ImageIndex = 74
	byteMenu.OnClick = countBytes
end

addByteCountMenu()
if you select multiple lines
Image

if you select only one line
Image