Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


reassemble() in Lua Scripts

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Fri Aug 02, 2024 4:56 am    Post subject: reassemble() in Lua Scripts Reply with quote

Why does AA ASM reassemble() not work in AA LUA?
And what's the alternative to that?

Example:
Code:
local scriptAsm_script_example =
[[
newmem_script_example:
  pushf
  cmp rbx,[game.exe+F02F9FF]
  jne originalCode_script_example

  cmp [rbx+0000FFF],000F00F0
  jne originalCode_script_example

  popf

  jmp return_script_example

originalCode_script_example:
  popf
  reassemble(aob_script_example)      //ja game.exe+4FBFDFF
  jmp return_script_example

aob_script_example:
  jmp newmem_script_example
  nop

return_script_example:
]]
autoAssemble(scriptAsm_script_example)


Thanks
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Fri Aug 02, 2024 10:28 am    Post subject: Reply with quote

None of the labels in that script are defined. Give a better example.

You should also check for errors.
Code:
local success, disableinfo = assert(autoAssemble(...))

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Fri Aug 02, 2024 12:17 pm    Post subject: Reply with quote

This is an example of the ASM section in the Lua script and it's not the actual script. I know it's the reassemble() that doesn't work because it only works by replacing it with what it represents.

labels are not necessary to be defined.

I use this same script in an ASM version it works with reassemble()
Repeating, it also works with the original instruction instead of reassemble() in a Lua script.

I want to know if there's an alternative way. Or a solution.
Thank you
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Fri Aug 02, 2024 2:44 pm    Post subject: Reply with quote

You really need to reduce this to an SSCCE.
Here's an example that works fine for me:
Code:
local mem = allocateMemory(4096)
registerSymbol('newmem', mem)

assert(autoAssemble[[
newmem:
  jmp newmem+10
]])

print(disassemble(mem))

assert(autoAssemble[[
newmem+100:
  reassemble(newmem)
]])

print(disassemble(mem+0x100))

unregisterSymbol'newmem'
deAlloc(mem)
Attach to anything (e.g. the CE tutorial) and run this Lua script.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Fri Aug 02, 2024 3:25 pm    Post subject: Reply with quote

Thank you that helped

The giveaway:
reassebmle() in an ASM script takes an address. While in Lua it takes a registered symbol name (string)

Thank you again
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Fri Aug 02, 2024 3:48 pm    Post subject: Reply with quote

No it doesn't.
Code:
local mem = allocateMemory(4096)

assert(autoAssemble(([[
%X:
  jmp %X
]]):format(mem, mem+0x10)))

print(disassemble(mem))

assert(autoAssemble(([[
%X:
  reassemble(%X)
]]):format(mem+0x100, mem)))

print(disassemble(mem+0x100))

deAlloc(mem)
Whether you use an AA script or call autoAssemble from Lua, they both go to the same auto assembler component of CE. `reassemble` isn't going to magically change how it works.

For the third time now, it would be VERY helpful if you posted a good example of a script that doesn't work but you think should. If you don't know what is or isn't important, simply posting the entire original script that's failing would be fine (just remove the game's name).
If you're happy that it works and don't care about the reason why, then go ahead and move on, but don't spread wrong information to others.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sat Aug 03, 2024 8:30 am    Post subject: Reply with quote

if anything I'm trying to learn how things work properly. For some reason, you treat me like your enemy. I want to learn, and to keep going I need some help occasionally. Yes, my way of presenting things might not be as concise or precise. Thank you.

This is an example script that should work on any process, as long as you mind the injection point, AOB & bytes size

Code:
{$Lua}
if syntaxcheck then return end

[Enable]

aob_example = AOBScanModuleUnique(process, "0F87xxxxxxxx8Bxxxxxxxxxx85xx74xx83xxxx74xx83xxxx74xx83xxxx74xx83xxxx")   --"0F 87 81 00 00 00 8B 8B"
newmem_example = allocateMemory(256, aob_example)
oldBytes_example = copyMemory(aob_example, 6)

if aob_example == 0 or aob_example == nil or
  newmem_example == 0 or newmem_example == nil or
  oldBytes_example == 0 or oldBytes_example == nil
  then
  createTimer(10, function() memrec.Active = false end)
end

registerSymbol("example", aob_example)

local scriptAsm_example =
[[
newmem_example:


originalCode_example:
  reassemble(aob_example)           //Doesn't work (the script activates but it doesn't assemble)
  //reassemble(example)                 //Works
  //ja $process+FBFDFF                //Works
  jmp return_example

aob_example:
  jmp newmem_example
  nop

return_example:
]]

local success, disableinfo = assert(autoAssemble(scriptAsm_example))
--autoAssemble(scriptAsm_example)


[Disable]

oldBytes_example = copyMemory(oldBytes_example, 6, aob_example)
deAlloc(newmem_example)
unregisterSymbol("example")

aob_example = nil
newmem_example = nil
oldBytes_example = nil



Screenshot 2024-08-03 162506.png
 Description:
 Filesize:  18.29 KB
 Viewed:  6084 Time(s)

Screenshot 2024-08-03 162506.png


Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sat Aug 03, 2024 9:42 am    Post subject: Reply with quote

Game Hacking Dojo wrote:
For some reason, you treat me like your enemy.
You ask for help with something you think should work but doesn't. I want to teach you the correct way to do something. I ask you to help me do so. You refuse to help me do that. Yes, I find this antagonistic behaviour to be a bit annoying.
I think I could've explained what I wanted you to do better at first. That's my bad.

The problem in that script is because "aob_example" isn't defined in the AA script. The script that's passed to autoAssemble is a string. Variables won't substitute themselves into strings automatically- you have to format them in.
Code:
local foo = 0x1234
print("foo:")
print(("%X:"):format(foo))

If you use a particular variable a lot, use `define` in the AA script:
Code:
local script = ([[
define(foo,%X)

foo:
  ...
]]):format(foo)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sat Aug 03, 2024 10:54 am    Post subject: Reply with quote

Why did we add assert() to autoAssemble() to detect the error instead of using autoAssemble() alone?
How do I do the same thing using and without assert():

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)
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sat Aug 03, 2024 11:25 am    Post subject: Reply with quote

Calling autoAssemble with a bad script won't raise any errors on its own. It will just return false and a string that shows the reason why it failed.

Open the Lua engine window (Memory View -> Tools -> Lua Engine) and run this script:
Code:
return autoAssemble"Bad Script"

--[[ Output:
1:false
2:Error in line 1 (Bad Script) :This instruction can't be compiled
]]
Even though the AA script failed, the Lua script that called autoAssemble didn't fail. It just returned a boolean (false) and a string (the error message). It's practically equivalent to this:
Code:
function foo()
  return false, "some string"
end

return foo()

You need to check the result and raise an error on your own.
Code:
local success, err = autoAssemble"Bad Script"
if not success then
  error(err)  -- this will cause Lua to generate an error
end
`assert` is a shorter version of that. It checks the first argument, and if it's false, it will generate an error with the second argument.
Code:
assert(autoAssemble"Bad Script")

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sat Aug 03, 2024 12:52 pm    Post subject: Reply with quote

It is clear now. Thank you )
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites