About calculating call from different location and readmem in general

Anything Cheat Engine related, bugs, suggestions, helping others, etc..
User avatar
Horse4Horse
Expert Cheater
Expert Cheater
Posts: 79
Joined: Thu Aug 02, 2018 7:54 pm
Reputation: 30

Re: About calculating call from different location and readmem in general

Post by Horse4Horse »

ShyTwig16 wrote:
Tue Jan 11, 2022 11:06 pm
Horse4Horse wrote:
Tue Jan 11, 2022 5:14 pm
...
I understand what you're talking about(and as I said - it was an example, real values like +26 from "INJECT", its just for simplicity), but if I try to use any other address to be "desired"(inject+5 as example) - I'm getting the same error. And I dont see any other way to read memory, subtract it and write to location in one script without heavy lifting lua commands.
Sorry I was thinking wrong about a call address, I use some lua function I wrote (posted below) so I haven't needed to think about it in a long time. I should have also told you to use [Link].

Code: Select all

[ENABLE]
aobscanmodule(INJECT, Exanima.exe, E8xxxxxxxx8B04248BD0A1)
registersymbol(INJECT)
alloc(original, 5)
registersymbol(original)

original:
readmem(INJECT+11, 5)


INJECT+11:
reassemble(INJECT)

[DISABLE]

INJECT+11:
readmem(original, 5)

unregistersymbol(INJECT)
unregistersymbol(original)
As for doing it with lua, these are two functions I wrote and use regularly:

Code: Select all

---- 
---- Calculates the address stored in opcode if 64 bit, or reads the address if 32 bit.
---- 
---- getOpcodeAddress(address)
---- 
---- Parameters:
---- 	address : number - string :
---- 		The address of the opcode the stored address is.
---- Return:
---- 	number :
---- 		The address stored at the given opcode address.
function getOpcodeAddress(address)
	address = getAddress(address)
	if targetIs64Bit() then
		local os = readInteger(address, true) or 0
		return address + 4 + os
	else
		return readInteger(address)
	end
end
registerLuaFunctionHighlight('getOpcodeAddress')

---- 
---- Calculates the address stored in opcode.
---- 
---- getCallAddress(address)
---- 
---- Parameters:
---- 	address : number - string :
---- 		The address of the opcode the stored address is.
---- Return:
---- 	number :
---- 		The address stored at the given opcode address.
function getCallAddress(address)
	address = getAddress(address)
	local os = readInteger(address, true) or 0
	return address + 4 + os
end
registerLuaFunctionHighlight('getCallAddress')
EDIT:
And I actually use custom auto assembler commands in the end, but these have some dependencies (3 modules for these to work) and you need to modify them to make them work. Just thought that mutch code would be more confusing, but that these might help illustrate how the above functions work.

Code: Select all


local function getOpcodeAddressAA(parameters, syntaxcheck)
	----
	---- getOpcodeAddress(symbol, address)
	----
	local symbol, address = commands.getParameters(parameters)
	local status, msg = commands.checkParameter(symbol, 'symbol', 'getOpcodeAddress')
	if not status then return nil, msg end
	symbol = commands.checkForLuaGlobal(symbol)
	status, msg = commands.checkParameter(address, 'address', 'getOpcodeAddress')
	if not status then return nil, msg end
	address, msg = commands.parseNumberOrAddress(address, 'address', 'getOpcodeAddress')
	if not address then return nil, msg end
	if syntaxcheck then
		return string.format('define(%s, %016X)', symbol, 0)
	end
	local addr = getOpcodeAddress(address)
	return string.format('define(%s, %016X)', symbol, addr or 0)
end
registerAutoAssemblerCommand('getOpcodeAddress', getOpcodeAddressAA)

local function getCallAddressAA(parameters, syntaxcheck)
	----
	---- getCallAddress(symbol, address)
	----
	local symbol, address = commands.getParameters(parameters)
	local status, msg = commands.checkParameter(symbol, 'symbol', 'getCallAddress')
	if not status then return nil, msg end
	symbol = commands.checkForLuaGlobal(symbol)
	status, msg = commands.checkParameter(address, 'address', 'getCallAddress')
	if not status then return nil, msg end
	address, msg = commands.parseNumberOrAddress(address, 'address', 'getCallAddress')
	if not address then return nil, msg end
	if syntaxcheck then
		return string.format('define(%s, %016X)', symbol, 0)
	end
	local addr = getCallAddress(address)
	return string.format('define(%s, %016X)', symbol, addr or 0)
end
registerAutoAssemblerCommand('getCallAddress', getCallAddressAA)
Dfq I'm so dumb. I have read about that function a half year ago, thought "That a very usefull function" and then totally forgot. Many thanks for the provided code and for pointing my stupidity out!
But one question is still bothering me - is there no way to use defined by readmem symbol in the same script? Script needs to be fully executed?

ShyTwig16
Expert Cheater
Expert Cheater
Posts: 335
Joined: Thu Apr 06, 2017 7:14 pm
Reputation: 20

Re: About calculating call from different location and readmem in general

Post by ShyTwig16 »

Horse4Horse wrote:
Wed Jan 12, 2022 8:27 pm
...
Dfq I'm so dumb. I have read about that function a half year ago, thought "That a very usefull function" and then totally forgot. Many thanks for the provided code and for pointing my stupidity out!
But one question is still bothering me - is there no way to use defined by readmem symbol in the same script? Script needs to be fully executed?
It's more that you can't use a new labels with readMem, but if you use aobScan, aobScanModule, or define; you can use those and then use that created "label" with readMem.

Code: Select all

[ENABLE]
aobscanmodule(INJECT, Exanima.exe, E8xxxxxxxx8B04248BD0A1)
registersymbol(INJECT)
alloc(original, 5)
registersymbol(original)

define(injectionPoint, INJECT+11)
registersymbol(injectionPoint) // you can even register it as a symbol if needed,  but it's not needed if
//								you only use it in the enabled section or declare it in the main section.

original:
readmem(injectionPoint, 5)


injectionPoint:
reassemble(INJECT)

[DISABLE]
injectionPoint:
readmem(original, 5)

unregistersymbol(INJECT)
unregistersymbol(original)
unregistersymbol(injectionPoint)

Post Reply

Who is online

Users browsing this forum: Bloodybone