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 


can lua script call AA symbols?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
movss
Cheater
Reputation: 0

Joined: 10 Feb 2018
Posts: 40

PostPosted: Mon Mar 05, 2018 6:02 am    Post subject: can lua script call AA symbols? Reply with quote

i write a dll file for getMainThreadFromName,
when i inject ,it works,i can see the correct value with AA script,

but when i call it with lua script,is doesn't work

print( readInteger(myaddr)),printing nothing,

where is wrong?
can lua script call "myaddr"?







Code:

MainThreadFromName=[[
alloc(mem,1000)
alloc(name,10)
globalalloc(myaddr,4)
registersymbol(myaddr)
name:
db 'win.exe'
mem:
push name
call getMainThreadFromName
mov [addr],eax
ret
createthread(mem)
]]

if autoAssemble(MainThreadFromName) then
print("OK")
print( readInteger(myaddr))
else
print("NO")

end


_________________
A wild programmer
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater
Reputation: 31

Joined: 09 Aug 2013
Posts: 757

PostPosted: Mon Mar 05, 2018 12:42 pm    Post subject: Reply with quote

1. You have to pass it as a string which CE will interpret as a symbol and look up the address, or get the address with getAddress/getAddressSafe otherwise lua thinks you're referring to the lua variable "myaddr" not the AA symbol.

2. you have "mov [addr], eax" not myaddr so it's never being written to (the alloc would set it to 0 though).

3. globalalloc does registersymbol for you, that's essentially what makes it different from alloc, you'll actually get an error in this case using it "myaddr was supposed to be added to the symbollist, but it isn't declared"

4. I'm pretty sure it's possible that the asm code wouldn't run before the rest of the lua code does, it only waits for the auto assemble to finish, especially in the case of a hook which may only run when the player does something (eg. shoot) or a long calculation. So you may need a second address that's set to 1 when the asm code is done and a loop that runs until that's not 0, then you read the value you actually care about (though if you know the value won't be 0 you can combine those).

here's a slightly simplified example that worked for me
Code:
MainThreadFromName=[[
alloc(mem,1000)
globalalloc(myaddr,4)
mem:
  mov [myaddr], 1
  add [myaddr], #99
  ret
createthread(mem)
]]

if autoAssemble(MainThreadFromName) then
  print("OK")
  print(readInteger("myaddr"))
else
  -- I think autoAssembleCheck was added in CE 6.7
  -- but it prints the syntax message returned by
  -- autoAssemble as it's second value if it fails
  print("NO", autoAssembleCheck(MainThreadFromName))
end


alternatively you could capture the result before the if statement
Code:
local success, info = autoAssemble(MainThreadFromName)
if success then
  print("OK, info can be used to run the disable section if one exists")
  print(readInteger("myaddr"))
else
  print("NO", info)
end


edit: apparently having autoAssemble return the error (and the disable info, forgot about that) was only added in 6.7 as well, oh well lol. You'd just have to test it in a normal AA script with [enable] and an empty [disable] section.

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
movss
Cheater
Reputation: 0

Joined: 10 Feb 2018
Posts: 40

PostPosted: Tue Mar 06, 2018 4:16 am    Post subject: Reply with quote

thanks,,,,
i know now

_________________
A wild programmer
Back to top
View user's profile Send private message
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