 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Leopounet How do I cheat?
Reputation: 0
Joined: 18 Feb 2023 Posts: 5
|
Posted: Sat Feb 18, 2023 10:39 pm Post subject: Cheat Engine, Patching/Modding and JIT |
|
|
For context : I am trying to create a patch for Unrailed!. In this game, there is a currency and I found the instruction that modifies it. But I find the use of Cheat Tables not ideal (especially if I want to play with friends). So I want to create a patch, so that they can just apply it and then play the modded version.
Unfortunately, the instruction does not exist until it is needed, which from what I read online means that it is JIT compiled. Now, I don't know everything about JIT and I am eager to learn, but from what I understand, the code (not compiled) has to be somewhere, and if I modify it correctly, it will act as a patch (not saying that the modifications are easy to make). But I can not find the pre-jitted code.
Right now I have found some X code stored on the heap that is modified (maybe the JIT step?), and pasted somewhere else, and the new code is modified again to generate the actual assembly code I found at first (the one I can modify via a cheat table/aob injection). But this X code is already on the heap when I find it, so it is not what I am looking for.
I have read on other post that maybe other softwares like Harmony could help me, but I am not sure if it would really help. Also, my approach is maybe bad and I am okay with any other method that could generate a patch. Anyway, any help/guidance is appreciated because I can't seem to go any further right now.
Also, I am quite a newbie when it comes to CE but otherwise I am not a newbie in computer science, low-level stuff etc. I can go in more depth if that helps too.[/b]
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4696
|
Posted: Sun Feb 19, 2023 1:00 am Post subject: |
|
|
TLDR: if you don't already know how to do it, it's probably not worth your time to learn, especially if simply sharing a cheat table works. Turn it into a trainer if you insist.
Generally speaking, source code (e.g. C#, Java, Flash ActionScript) gets compiled to bytecode (e.g. respectively: CIL, Java bytecode, Flash ABC) that gets distributed. When the user runs the program, the bytecode gets JIT-compiled to the machine code of the native computer and can then be run. This machine code is what CE reads and shows as assembly instructions.
It sounds like you want to find and modify the bytecode. This is generally easier with a decompiler (turns bytecode back into source code). e.g. for old Flash games, there are plenty of tutorials on this: look up JPEXS on youtube or something. Investigate how the game was created (language, engine, etc) and try to find a suitable decompiler.
If it's dotnet / mono / java, CE might help a little. There might be an additional menu that appears at the top of the main CE window after you attach to a process.
Permanently modifying bytecode might be easier said than done. There could be checksums or hashes that verify the integrity of the data that you'll have to figure out and update. If that's the case, find a decompiler that does it for you, or give up.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Leopounet How do I cheat?
Reputation: 0
Joined: 18 Feb 2023 Posts: 5
|
Posted: Sun Feb 19, 2023 2:43 pm Post subject: |
|
|
Quote: | TLDR: if you don't already know how to do it, it's probably not worth your time to learn, especially if simply sharing a cheat table works. Turn it into a trainer if you insist. |
To be fair, I want to learn how to do this in general, because I am curious. It is not so much about playing this modded game (although I would enjoy it too). But I didn't make that very clear, sorry.
Quote: | Investigate how the game was created (language, engine, etc) and try to find a suitable decompiler. |
As I feared, the code is obfuscated and nothing good came out of decompilers (tried 'monodis' and 'DotSeek'). Maybe there are other softwares that could help with the obfuscation though ? But that seems like a deadend.
Quote: | If that's the case, find a decompiler that does it for you, or give up. |
From what I understand, Harmony does that and I guess it's not so much about making sure the new executable is valid (this seems not too difficult with some tools) but finding the bytes I want to replace and how I want to replace them. Also, I guess since it is obfuscated, I won't get any useful information in the .Net tab on CE (but maybe I am using it wrong or missing something).
I thought that one thing that could help me would be to 'set breakpoints on memory regions'. I don't know if this is possible though. I have read somewhere else that it is possible but even by enabling Page Exceptions, I can't find any options t odo that (and selecting a range of addresses does not work either). What am I doing wrong ?
(I can not post URLs yet unfortunately but googling Cheat Engine breakpoint memory regions yields the link I am talking about).
I am still open to ideas/suggestions, and if you think this is really absolutely impossible without dedicating my life to it, let me know.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4696
|
Posted: Sun Feb 19, 2023 2:53 pm Post subject: |
|
|
Leopounet wrote: | I thought that one thing that could help me would be to 'set breakpoints on memory regions'. | Why do you think that would help you? Once the bytecode gets JIT compiled, it's not like you can reverse time and find out where it came from.
It's definitely possible to do what you want, but it would take a ridiculous amount of effort compared to simply using a cheat table.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Leopounet How do I cheat?
Reputation: 0
Joined: 18 Feb 2023 Posts: 5
|
Posted: Sun Feb 19, 2023 3:12 pm Post subject: |
|
|
There is a .exe file (UnrailedGame.exe), in which I suppose the pre-jitted code is located (otherwise where could it be ? Maybe I am wrong here). If I could detect which instructions access this memory region, I could maybe intercept the JIT process.
I would then have as the entry the pre-jitted code and as the output the 'post-JIT'. Not quite, because it is another intermediate representation from what I found, as I said, I feel like there is at least :
The pre-jitted code, [maybe something else, which would be indeed a road block for now], an intermediate code, and then the real assembly code added on the stack.
Since I know what opcode sequence I am looking for in the last two steps, if I can know when the original code is accessed (in UnrailedGame.exe supposedly), I can break when the opcodes of interest are wirtten on the heap (or just before by waiting for the preceeding opcodes). And then since I know which instruction reads the original code from the UnrailedGame.exe file, I can step until I reach it and see what opcodes are being read from the original file. Then it is just a matter of finding them in a software that can generate patches.
I don't know if this is clear or even if that makes sense/would work, but that's how I was approaching this issue. And that's why detecting accesses to memory regions could help.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4696
|
Posted: Sun Feb 19, 2023 4:32 pm Post subject: |
|
|
Leopounet wrote: | otherwise where could it be ? Maybe I am wrong here | A dll or some other resource file the game loads on startup. e.g. flash used swf files.
Leopounet wrote: | If I could detect which instructions access this memory region, I could maybe intercept the JIT process.
...
..if I can know when the original code is accessed (in UnrailedGame.exe supposedly)... | Your first goal should be to find the memory region the bytecode is in. "Probably somewhere in the exe" isn't anywhere near specific enough- sorting through every memory access in the exe would be ridiculous. You'll have better luck finding the memory region by scanning for common sequences of bytecode.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Leopounet How do I cheat?
Reputation: 0
Joined: 18 Feb 2023 Posts: 5
|
Posted: Sun Feb 19, 2023 5:39 pm Post subject: |
|
|
Quote: | A dll or some other resource file the game loads on startup. e.g. flash used swf files. |
Yeah, could be, but I have looked at every DLL's name and they are unlikely to contain the instruction according to their names (it could be in something else than the .exe, just saying I am doing a semi-educated guess on where it is the most likely to be). On the other hand, I didn't think of .swf files or anything else other than .exe and .dll files (I am not really a windows user, I am more familiar with Linux files and executables). But there aren't really many files except DLLs in the directory.
Quote: | common sequences of bytecode. |
I am unsure what you mean by "common sequences of bytecodes", are you referring to something specific? I will admit I should get more familiar with .Net/mono, this is not the smartest move but I am having fun, so whatever.
Anyway thanks for your help in general, maybe I'll come to the conclusion that it is indeed not worth doing at all as you said earlier, and not interesting. But for now I am trying, even if it may be dumb.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4696
|
Posted: Sun Feb 19, 2023 7:32 pm Post subject: |
|
|
Files typically get opened, written into the process's memory somewhere (like any other dynamically-allocated memory), then closed. You generally won't see a sign that says "this memory is from the file C:\whatever\bytecode.bin" or something. There are other ways of working with files (e.g. memory mapped files).
"common sequences of bytecode"- "common" meaning "occurring frequently," and "sequences of bytecode" practically meaning "arrays of bytes."
If you look at machine code often enough, you'll notice patterns. Some bytes may appear more often than others, or maybe they appear in specific places. In 64-bit code, the byte "48" is a very common prefix byte. The bytes "55 48 89 E5" are often the start of some function.
These heuristics can help someone ascertain something that would otherwise be very tedious using a more "correct" way.
Whatever bytecode format is being used, I'm certain heuristics exist for that as well- certain sequences of bytes that are only common in that particular bytecode format.
It might be even easier than that. e.g. swf files have magic numbers (aka file signatures) at the beginning.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Leopounet How do I cheat?
Reputation: 0
Joined: 18 Feb 2023 Posts: 5
|
Posted: Mon Feb 20, 2023 11:20 am Post subject: |
|
|
Okay I see thank you.
Also, I was wondering, is it possible that the .exe file is basically divided in two parts :
1 - The code at the entry point that is readable/executable code out of the box ;
2 - A 'compressed' .data/.text/... part that is expanded at runtime and contains the actual bytecodes I am trying to find/modify (the ones that are then jitted etc) ?
I am not saying this is the case here, but the structure of the .exe file reminds me of the structure I would find in ZIP/RAR/... files.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4696
|
Posted: Mon Feb 20, 2023 3:37 pm Post subject: |
|
|
There are several parts to an exe file. Look up "portable executable format" for more information.
My point still stands: even if the bytecode is getting packed into the exe, there's going to be a lot of other stuff there that's completely unrelated to bytecode.
_________________
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
|
|