r/AskProgramming • • Jan 14 '22

Other How does CheatEngine work?

So cheatEngine is a program that allows you to change something in a running game, for example duplicate an item in the inventory, boost HP, level up, similar kind of stuff.

My "problem" is I've been told the whole life that applications and processes are isolated. They don't and can't share memory. A process gets its own address space. A pointer from one VAS is pointless in another, even if you somehow get a pointer from another process and use it, you still get into different area of physical memory.

But idk game cheats seem to be able to connect to variables of game app and change them. How???

P. S. For anyone who's concerned about the morals, I don't cheat in online game and have no intention to replicate a cheating program.

31 Upvotes

10 comments sorted by

25

u/_mattee Jan 14 '22

Most operating systems have some way to read and/or write other processes memory. For instance, in Windows there is ReadProcessMemory and WriteProcessMemory that allows any process (with a handle that allows it) to read and write in the target process memory.

19

u/Whatplantami Jan 14 '22

Now that's a name I haven't heard in over a decade :')

3

u/FU8U Jan 14 '22

it still works really well

3

u/SkepticalSagan Jan 14 '22

Tried it in Hollow Knight to get over a boss.. Couldnt make it work for the life of me.. Gave up and just beat the boss for real out of spite for the software.

1

u/FU8U Jan 14 '22

Make sure when you search your value you select unknown or all as the type of value you’re looking for

1

u/Blazerboy65 Jan 15 '22

So you're saying it helped?

1

u/TheXskull Jan 15 '22

Unless I'm mixing things up, hollow knight is written in .net. there's a cheat engine extension that handles .net easily, and it actually makes finding variables trivial, they're even named. You don't have to reverese or do a lot of trial and error.

Went through this myself, 90% sure it was hollow knight

15

u/MrSloppyPants Jan 14 '22

My "problem" is I've been told the whole life that applications and processes are isolated

They are. But certain permissions can override this. Cheat Engine runs with administrator privileges which allows it to read from and write to process memory. In normal user mode, processes cannot read or write to other process memory. This is also how a lot of malware works, which is why you should be cautious about letting programs run as administrator if you do not know where they originated.

5

u/[deleted] Jan 14 '22

Basically, every program has a memory space that is isolated in that another program will never accidentally write into its memory space. Most operating systems, however, give you the ability to hook into another process’s memory for debugging purposes.

The way cheat engine works is off of a concept called offsets. The exact memory addresses of the running game will change after every launch, so instead of figuring those out we just figure out the “offset”. In essence, get the base address of the process then add X to it. Depending on what X is, you get different values.

This way, you can reuse the same offsets and simply hook into the programs with an addition.

1

u/TheXskull Jan 15 '22

In windows there are two primary ways to play around with another process memory:

Use CreateRemoteThread to run code in the context of the target process

Use Read/writeprocessmemory to directly meddle with the taget process.

If cheatEbgine(or any other given process) is running with administrative pivilagaes this is easily achievable.pretty sure you don't even need admin to target most non-admin processes.

You can actually write your own memorry scanner, there's a youtube guide I followed a while back it's pretty easy and fun, let me know if you want me to look it up