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 


Cheat Engine Forum Index
PostGo back to topic
atom0s
Moderator
Reputation: 153
Joined: 25 Jan 2006
Posts: 7872
Location: 127.0.0.1

PostPosted: Fri Aug 30, 2019 3:09 pm    Post subject:

There are a handful of examples people have done for newer titles on sites like GitHub, one for Payday 2 here:
https://github.com/JamesWilko/Payday-2-BLT

I've never released any of mine open-source so I don't have any of mine to share personally. But the jist is the same for mine. A quick little rundown of what to do:

1. Find the version of Lua the game uses. (You can search for Lua's version string information to do this. https://github.com/lua/lua/blob/master/lua.h#L19 )
2. Find the functions used for reading/writing compiled Lua chunks. (This is optional if the game uses stock Lua but this is recommended to be done to validate the size information of how their Lua instance was compiled. A small change to 1 data type can break everything if you just try to use normal compiled Lua libs.)
- Look for functions in this: https://github.com/lua/lua/blob/1fb4d539254b67e7e35ed698250c66d1edff0e08/ldump.c#L216
- Look for functions in this: https://github.com/lua/lua/blob/1fb4d539254b67e7e35ed698250c66d1edff0e08/lundump.c#L294

At this point there are two ways you can go about doing things.

1. Obtain the Lua state pointer and just use your own compiled version of Lua in an injected DLL that matches their version and modifications.

Going this route is only really recommended if you are 100% sure they are using a stock build of Lua / LuaJIT and have done nothing to it. Any changes to how Lua works, size information that you fail to correct in your compiled build, etc. will cause crashes/errors/issues. So doing this you must be sure your compiled copy of the Lua library matches theirs.

Download the copy of Lua that you found they used, make any required adjustments to the size data or types.
- Editing types/sizes is generally just through modding these:
-- https://github.com/lua/lua/blob/1fb4d539254b67e7e35ed698250c66d1edff0e08/luaconf.h (Do your main edits in this file.)
-- https://github.com/lua/lua/blob/master/lua.h#L90 (Only edit these directly if you have to.)

Once compiled, your injected DLL just needs to find the Lua state pointer and then you can just pass that to your own Lua functions compiled in your DLL.
If the modifications made line up, you're good to go and no more additional work is required.

2. Obtain pointers to all the Lua functions you require and invoke them manually.

This is the preferred method since in most cases, companies will modify their copy of Lua to change various things around. Common things changed are:
- Type sizes.
- Additional types added.
- Extended types added.
- More metatable protos added.
- Additional library modifications for things like bitwise operations, internally added things like LuaSocket, etc.
- Use of LuaJIT with modified VM operations.
- Altered byte code generation to remove the use of simple Lua decompilers.

In this event you have to find pointers to every single function and create a header that defines the protos of each of those functions. This method is preferred since you do not need to worry about making sure your compiled Lua lib matches perfectly, in this setup you do not use Lua at all in your project. You are only creating a header that implements the required defines and protos that you plan to make use of.

There are a ton of examples at this point of doing this kind of thing on GitHub and other cheat related sites. Also keep in mind Lua is not thread safe, so you need to make sure that you are not causing threading issues with invoking Lua functions from your hooks/injected dll. Generally this is done by adding your own locking mechanism or making use of one the game already has implemented to keep their Lua instance thread safe.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Post reviews:   Approve 1
Author Review
MrViZZion
Review: Approve
Post reference:
ReviewPosted: Fri Aug 30, 2019 5:51 pm


Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites