 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Tue May 14, 2024 10:12 am Post subject: Port Assembly Script to Lua |
|
|
I am porting an Assembly script to Lua and I couldn't get it to work properly.
Could you please show me how to do it properly?
| Code: | {$lua}
if syntaxcheck then return end
[ENABLE]
local aob_infHealth = AOBScanModuleUnique(process,"8Bxxxx89xxxx44xxxxxxxxxxxxE8xxxxxxxx4Cxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx4Dxxxxxxxx45xxxxxx49xxxxxxxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx49xxxxxxxx8Bxxxxxxxxxx41xxxxE8xxxxxxxx41xxxxxx80xxxxxx74xx48xxxxxx48xxxxFFxxxx48xxxxxx8Bxx39xxE8xxxxxxxxEBxx48xxxxE8xxxxxxxxFFxx48xxxxxx3Bxxxx0F8Cxxxxxxxx48xxxxxxxxxxxxxx41xx41xx41xxxx")
local newmem_infHealth = allocateMemory(256, process)
registerSymbol("aob_infHealth", aob_infHealth)
local oldBytes_infHealth = allocateMemory(6, aob_infHealth)
registerSymbol("oldBytes_infHealth", oldBytes_infHealth)
local scriptEnable_infHealth =
[[
oldBytes_infHealth:
readmem(aob_infHealth,6)
//define(OB,oldBytes_infHealth)
newmem_infHealth:
//add your code here
//jmp originalCode_infHealth
originalCode_infHealth:
//reassemble(aob_infHealth)
mov edx,[rbx+30]
mov [rax+1C],edx
jmp return_infHealth
aob_infHealth:
jmp newmem_infHealth
nop
return_infHealth:]]
autoAssemble(scriptEnable_infHealth)
[DISABLE]
local scriptDisable_infHealth =
[[
aob_infHealth:
readmem(oldBytes_infHealth,6)
//db 8B 53 30 89 50 1C
]]
autoAssemble(scriptDisable_infHealth)
unregisterSymbol("aob_infHealth")
unregisterSymbol("oldBytes_infHealth")
deAlloc(newmem_infHealth)
deAlloc(oldBytes_infHealth) |
The script will make a hook but the hook will be the same as the original plus repeating the same bytes copied by "oldBytes_infHealth"
The code is supposed to save the bytes in a memory address and write them back when the script is disabled.
Thank you
Last edited by Game Hacking Dojo on Tue May 14, 2024 5:54 pm; edited 1 time in total |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1530
|
Posted: Tue May 14, 2024 10:30 am Post subject: |
|
|
Until @ParkourPenguin arrives, let me give you an example.
There seems to be no errors for the code scheme.
But I can't be sure about the AA script.
| Code: | [ENABLE]
{$lua}
if syntaxcheck then return end
local scriptEnable_infHealth =
[[
AOBScanModuleUnique(process,"8Bxxxx89xxxx44xxxxxxxxxxxxE8xxxxxxxx4Cxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx4Dxxxxxxxx45xxxxxx49xxxxxxxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx49xxxxxxxx8Bxxxxxxxxxx41xxxxE8xxxxxxxx41xxxxxx80xxxxxx74xx48xxxxxx48xxxxFFxxxx48xxxxxx8Bxx39xxE8xxxxxxxxEBxx48xxxxE8xxxxxxxxFFxx48xxxxxx3Bxxxx0F8Cxxxxxxxx48xxxxxxxxxxxxxx41xx41xx41xxxx")
allocateMemory(256, process)
registerSymbol("aob_infHealth", aob_infHealth)
allocateMemory(6, aob_infHealth)
registerSymbol("oldBytes_infHealth", oldBytes_infHealth)
oldBytes_infHealth:
readmem(aob_infHealth,6)
//define(OB,oldBytes_infHealth)
newmem_infHealth:
//add your code here
//jmp originalCode_infHealth
originalCode_infHealth:
//reassemble(aob_infHealth)
mov edx,[rbx+30]
mov [rax+1C],edx
jmp return_infHealth
aob_infHealth:
jmp newmem_infHealth
nop
return_infHealth:]]
autoAssemble(scriptEnable_infHealth)
{$asm}
[DISABLE]
{$lua}
local scriptDisable_infHealth =
[[
aob_infHealth:
readmem(oldBytes_infHealth,6)
//db 8B 53 30 89 50 1C
unregisterSymbol("aob_infHealth")
unregisterSymbol("oldBytes_infHealth")
deAlloc(newmem_infHealth)
deAlloc(oldBytes_infHealth)
]]
autoAssemble(scriptDisable_infHealth) |
_________________
|
|
| Back to top |
|
 |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Tue May 14, 2024 10:45 am Post subject: |
|
|
Thank you that didn't do anything per se however you showed me that I could just use my assembly script the way it is and just pass it on to autoassemble(). Now it works better and everything in the Enable section works fine. But not the Disable section. in the Disable it only brings back the original bytes but doesn't deallocate.
tip: You don't need to use {$lua} other than once it will recognise [Enable] and [Disable] sections without {$asm}
Last edited by Game Hacking Dojo on Tue May 14, 2024 10:58 am; edited 1 time in total |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1530
|
Posted: Tue May 14, 2024 10:54 am Post subject: |
|
|
I don't know much about AA script. You will do something there.
But if you wanted to use this in a Lua script, it would look like this with the help of a "CheckBox".
(I won't touch the disable allocation or code AA script code.)
| Code: | UDF1.CECheckbox1.OnChange=function(sender)
if sender.State==1 then
autoAssemble([[
AOBScanModuleUnique(process,"8Bxxxx89xxxx44xxxxxxxxxxxxE8xxxxxxxx4Cxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx4Dxxxxxxxx45xxxxxx49xxxxxxxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx49xxxxxxxx8Bxxxxxxxxxx41xxxxE8xxxxxxxx41xxxxxx80xxxxxx74xx48xxxxxx48xxxxFFxxxx48xxxxxx8Bxx39xxE8xxxxxxxxEBxx48xxxxE8xxxxxxxxFFxx48xxxxxx3Bxxxx0F8Cxxxxxxxx48xxxxxxxxxxxxxx41xx41xx41xxxx")
allocateMemory(256, process)
registerSymbol("aob_infHealth", aob_infHealth)
allocateMemory(6, aob_infHealth)
registerSymbol("oldBytes_infHealth", oldBytes_infHealth)
oldBytes_infHealth:
readmem(aob_infHealth,6)
//define(OB,oldBytes_infHealth)
newmem_infHealth:
//add your code here
//jmp originalCode_infHealth
originalCode_infHealth:
//reassemble(aob_infHealth)
mov edx,[rbx+30]
mov [rax+1C],edx
jmp return_infHealth
aob_infHealth:
jmp newmem_infHealth
nop
return_infHealth:]])
else
autoAssemble([[
aob_infHealth:
readmem(oldBytes_infHealth,6)
//db 8B 53 30 89 50 1C
unregisterSymbol("aob_infHealth")
unregisterSymbol("oldBytes_infHealth")
deAlloc(newmem_infHealth)
deAlloc(oldBytes_infHealth)
]])
end
end |
_________________
|
|
| Back to top |
|
 |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Tue May 14, 2024 11:02 am Post subject: |
|
|
Well, I could only appreciate your help. I also don't know much about Lua if any. It's all thanks to you and ParkourPenguin if I know some Lua at this point.
And Yes, this code you just provided can be helpful )
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Tue May 14, 2024 12:11 pm Post subject: |
|
|
"It doesn't work" isn't a good description of the problem.
You're not doing any error handling. That should be the first thing you do when something isn't working. You should be doing it all the time anyway even when you expect everything to work properly.
Check if AOBScanModuleUnique returns nil or 0. Check if allocateMemory returns nil or 0. Check if autoAssemble worked properly.
The second parameter to `allocateMemory` needs to be an integer, not some arbitrary address string. Use `getAddress(process)`
`newmem_infHealth` and `oldBytes_infHealth` are undefined in the [DISABLE] section. Enabling and disabling the script are two separate script invocations: local variables aren't carried over.
| Code: | {$lua}
if syntaxcheck then return end
a = a or 4
local b = 5
[ENABLE]
a = 1
b = 2
local c = 3
print(a,b,c)
-- 1 2 3
[DISABLE]
print(a,b,c)
-- 1 5 (nil) |
Don't use multiple allocateMemory calls. Each one is a call to VirtualAllocEx. The returned address is a multiple of the windows allocation granularity (0x10000 bytes). Unlike alloc in AA, CE can't automatically combine them for better memory efficiency- you have to do that yourself.
If you're going to use a Lua aobscan to scan for code, you may as well scan only executable memory. It won't make much difference here since you're scanning in a specific module, but in general, it'll speed up scans quite a bit.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Tue May 14, 2024 4:26 pm Post subject: |
|
|
I could explain more if you need me to.
The instance that was provided by AylinCE didn't do anything when I activated it. It didn't allocate nor did it place a jump and that's evidential if we look closer at the code. The code was supposed to run as Lua however it got passed on to autoAssemble() which expects a string of assembly.
What I also mentioned is that what he showed me by passing everything on to autoAssemble() was a great idea and it worked' It placed a jump at the expected location wrote the expected piece of code and jumped back to the next set of instructions as a normal AA script would behave. However, the only difference between this and a normal AA script is that this doesn't deallocate the chunk allocated so the cave remains untouched although the script is disabled and the original bytes got written back.
It unregisters the symbols as expected but does not deallocate.
side note it also doesn't recognise asterisks as all definitions | Code: | | unregistersymbol(*) |
| Code: | {$lua}
if syntaxcheck then return end
[ENABLE]
local scriptEnable_infHealth =
[[
aobscanmodule(aob_infHealth,SOR4.exe,8Bxxxx89xxxx44xxxxxxxxxxxxE8xxxxxxxx4Cxxxxxx49xxxx48xxxxxxxxxxxxE8xxxxxxxx4Dxxxxxxxx45xxxxxx49xxxxxxxxxxxx49xxxx48xxxxxxxxxxxx)
alloc(newmem_infHealth,256,SOR4.exe)
registersymbol(aob_infHealth)
alloc(oldBytes_infHealth,6)
registersymbol(oldBytes_infHealth)
oldBytes_infHealth:
readmem(aob_infHealth,6)
newmem_infHealth:
originalCode_infHealth:
mov edx,[rbx+30]
mov [rax+1C],edx
jmp return_infHealth
aob_infHealth:
jmp newmem_infHealth
nop
return_infHealth:
]]
autoAssemble(scriptEnable_infHealth)
[DISABLE]
local scriptDisable_infHealth =
[[
aob_infHealth:
readmem(oldBytes_infHealth,6)
//db 8B 53 30 89 50 1C
unregistersymbol(oldBytes_infHealth)
unregistersymbol(aob_infHealth)
dealloc(oldBytes_infHealth)
dealloc(newmem_infHealth)
]]
autoAssemble(scriptDisable_infHealth) |
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Tue May 14, 2024 6:15 pm Post subject: |
|
|
You're not keeping track of the disableinfo at all, and you're still not checking for errors...
celua.txt:
| Quote: | autoAssemble(text, targetself OPTIONAL, disableInfo OPTIONAL) : runs the auto assembler with the given text. Returns true on success, with as secondary a table you can use when disabling (if targetself is set it will assemble into Cheat Engine itself). If disableInfo is provided the [Disable] section will be handled
autoAssemble(text, disableInfo OPTIONAL)
| This is also well documented on the CE wiki
| Code: | {$lua}
if syntaxcheck then return end
-- the [ENABLE] / [DISABLE] can't appear at the beginning of the line within this parent AA script
local script = [[[ENABLE]
alloc(foo,4096,$process)
registersymbol(foo)
]]..[[[DISABLE]
unregistersymbol(*)
dealloc(*)
]]
[ENABLE]
local success, di = autoAssemble(script)
if not success then
error('AA script failed: ' .. di)
end
myscript_disableinfo = di
[DISABLE]
local success, err = autoAssemble(script, myscript_disableinfo)
myscript_disableinfo = nil
if not success then
error('AA script failed: ' .. err)
end |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Thu May 16, 2024 4:45 pm Post subject: |
|
|
I've got everything to work properly except for one thing. The script checkbox will turn on even if the script is not activated due to unfound AOB.
I want to know how to disable a script when it's unable to find the AOB.
I've seen somewhere that this line will disable the script. However, this doesn't let my script run because of an error it gives. When using it without wrapping it in function the script runs but it doesn't disable the script. So in this case using return is still better.
https://forum.cheatengine.org/viewtopic.php?t=609775
| Code: | | function() memrec.Active = false end |
Then I wrapped it with an if statement and placed it right under the AOB scan
| Code: | if aob_infHealth == 0 or aob_infHealth == nil then
function() memrec.Active = false end
end |
Thank you for the help
PS: Now it works that I wrapped the line with a createTimer(). But could explain the difference and why I can't just use it like this:
| Code: | | function() memrec.Active = false end |
| Description: |
|
| Filesize: |
2.39 KB |
| Viewed: |
3348 Time(s) |

|
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4706
|
Posted: Thu May 16, 2024 6:50 pm Post subject: |
|
|
{$lua} blocks are run in the process of enabling a script. When they're executed, the AA script is neither enabled nor disabled. Trying to access, let alone change, a script's Enabled property in such a state doesn't make sense.
| Game Hacking Dojo wrote: | The script checkbox will turn on even if the script is not activated due to unfound AOB.
I want to know how to disable a script when it's unable to find the AOB. | It would be nice if there were posts telling you what you're doing wrong, what you should be doing, and even giving you a working example of how to do it.
| ParkourPenguin wrote: | You're not doing any error handling. That should be the first thing you do when something isn't working. You should be doing it all the time anyway even when you expect everything to work properly.
Check if AOBScanModuleUnique returns nil or 0. Check if allocateMemory returns nil or 0. Check if autoAssemble worked properly. |
| ParkourPenguin wrote: | you're still not checking for errors...
...
| Code: | | <code showing you how to handle and propagate errors> |
|
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|