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 


string.dump

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

Joined: 02 Sep 2018
Posts: 101

PostPosted: Fri Aug 23, 2019 5:39 am    Post subject: string.dump Reply with quote

why string dump gets all code
Code:

function test()
print("hi")
end
r = string.dump(test)
print(string.len(r))

i just add some comments to outside of test function but somehow lenght of dumped code increases
how to fix
edit: i also tested on repl it and normal lua it works fine but in CE it gets whole code

_________________
hi
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Aug 23, 2019 4:25 pm    Post subject: Reply with quote

string.dump does not only dump the single function like it implies. It's basically a snapshot of the Lua state at that time to ensure the function will work again when re-executed as a normal function. So everything in the current context of the state will be recorded to some degree (the func, upvals, params, etc.).

To give you an idea of what it does behind the scenes:

string.dump calls lua_dump.
lua_dump calls luaU_dump:
https://github.com/cheat-engine/cheat-engine/blob/master/Cheat%20Engine/lua53/lua53/src/ldump.c#L201

luaU_dump calls the functions above it to rebuild the byte code which includes a header of data containing information about the chunk.

The main thing here would be DumpFunction which handles dumping all of the needed information and extra data that may be required for things to work properly. There isn't anything "wrong" or to fix. This is just how Lua works.

Keep in mind as well, Lua in CE is 5.3 so data stored is going to be larger with the different structures of the newer version of Lua. If you are testing on something else (like you said repl) it may be a different/older version of Lua.

As an example, the same code you pasted is different in size between 5.1 and 5.3:

5.1: 115 bytes
5.3: 204 bytes

You'd have to manually edit Lua's dump functions if you want it to strip out other data (such as comments) if you absolutely need that option.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
exohaxor
Expert Cheater
Reputation: 1

Joined: 02 Sep 2018
Posts: 101

PostPosted: Sat Aug 24, 2019 1:25 pm    Post subject: Reply with quote

so can i dump single function? is there a way?
_________________
hi
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 472

Joined: 09 May 2003
Posts: 25875
Location: The netherlands

PostPosted: Sat Aug 24, 2019 2:45 pm    Post subject: Reply with quote

encodeFunction strips comments so you can use that

Code:

function test()
print("hi") --fjkldsffsdfdsfsddsfsdfsdfsdfsdfsdfsdfrfdsf
end
r = string.dump(decodeFunction(encodeFunction(test)))
print(string.len(r))

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
exohaxor
Expert Cheater
Reputation: 1

Joined: 02 Sep 2018
Posts: 101

PostPosted: Sun Aug 25, 2019 4:42 am    Post subject: Reply with quote

k thanks exactly what i wanted
_________________
hi
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