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 


I don't understand the relationship between Assembly and C.E

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Bunny_Wabbit
Newbie cheater
Reputation: 0

Joined: 23 Sep 2017
Posts: 23
Location: United Kingdom

PostPosted: Wed Jul 10, 2019 7:57 pm    Post subject: I don't understand the relationship between Assembly and C.E Reply with quote

And for that matter, Lua.

As someone who enjoys IT related subjects and gaming, I've always wanted to become better at understand Cheat Engine and how it works, but I've never managed to find a good resource at learning Assembly or Lua to the point where it 'clicks' as to how Cheat Engine communicates with both languages.

I get the basics of how to use the software, like how to change someone's HP or make everything free by deleting the instruction to deduct cash, but while I understand how to do it, none of the numbers make sense to me. The most I can retain from what little tutorials I've found is that the three letters are registers. But that doesn't explain what the addresses next to them are.

My main point of confusion is that, if Assembly is used to modify a processor at the hardware level, then why is it being used to change someone's HP in a video game?

There's a YouTube series by someone who's name I forgot, who reverse engineered games all the time and has a series called Let's Hack. I'm not sure if he's still uploading but I got a decent-way through his tutorials, up until he said knowing Assembly might help with the specific lesson, and because my brain is weird, I wanted to stop there and get the full course on Assembly, so everything he did in the video would make sense to me, but the question posed in the title has stopped me in my tracks. I don't know what I should be looking for if most tutorials I find online focus on processors and hardware, when it's clearly being used for software here.

Edit: Stephen Chapman, that's it. His playlist is the best I've found on Cheat Engine and I haven't watched the videos in a long while, but as I said I think I stopped watching because I told myself I was going to learn some of the ASM stuff before carrying on, and I never did.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Wed Jul 10, 2019 10:36 pm    Post subject: Reply with quote

Quote:
if Assembly is used to modify a processor at the hardware level...
It doesn't. It just changes the code a processor executes. If that code happens to modify HP, then the HP is changed.

You'd be better off learning a programming language first before trying to learn assembly. Code from a programming language eventually turns into instructions in memory (machine code; typically viewed by humans as an assembly language). The processor reads these instructions from memory and executes them. It's not like you're modifying the processor itself when you replace an instruction with nops.

If you want to learn about x86/x64 architectures, there are plenty of tutorials online. Many aren't great and contain false and/or misleading information, but you'll still come away with something from them.
I watched this a very long time ago, but it might not be for everyone. I think you'll get the most practical knowledge by looking at assembly and reading what instructions do (e.g. reference; also in official Intel/AMD documentation). godbolt is great for plugging in c++ code and seeing what instructions it turns into. Use MSVC for Windows-ABI compliant code.
I should eventually look for a good book on this subject to recommend in cases like this...

Lua, on the other hand, is just a scripting language. It's used to automate stuff. CE defines some stuff you can use for this purpose.
There are plenty of tutorials online about the Lua language (recent CE versions use Lua 5.3), and the CE API is documented in celua.txt. Look at uploaded tables and the CE wiki for examples of varying degrees of quality.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Jul 12, 2019 4:32 pm    Post subject: Reply with quote

ParkourPenguin wrote:
You'd be better off learning a programming language first before trying to learn assembly
I agree with this, I had a hard time really getting into CE even with the tutorials before I learned C and understood what datatypes and sizes are, why you'd use one vs another and pointers, ie. how things are programmed in general at a lower level than languages like JS and python and most of modern C++. Combining that with the OST asm course along with Stephen and Chris/Cheat The Game's videos were what really got me to the point that I felt like I had a solid grasp on what was happening and how to get what I wanted done, once I figured out which approach a specific game was using.

I got into lua much more slowly, even after I'd already learned the basics for modding Factorio. It's just not really necessary for using CE tables but offers a few niceties when you understand it and what CE offers, like easy custom types, breakpoint conditions, toggling multiple scripts (why have to set your favorites all manually when you launch a game if you can write a script to do it for you with one click), hotkeys/macros, various extensions, and of course customizing trainers.

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

Joined: 23 Sep 2017
Posts: 23
Location: United Kingdom

PostPosted: Wed Jul 17, 2019 7:30 pm    Post subject: Reply with quote

So you guys think I should try and learn and retain C++ first?

I looked at that playlist ParkourPenguin, but I get the feeling you need to be a student of his to understand the context of what he's talking about. He kept saying stuff like "As we talked about before". I got a little beyond converting Dec to Bin to Hex in the first video and it kinda got confusing from there, and felt like a test on whether I needed to remember what he was talking about or not.

I tried learning x86 from a Udemy course and a book on Kindle, but the instructor had scarpered and wasn't answering anyone's questions, and just wasn't very easily understood. As for the book, every time he mentioned a new CPU introducing a new feature, he'd talk about it as if you already know what it is, like he was making everything twice as wordy as it needs to be. Like, for example he'd say what features the x86 introduced after its previous iteration, and he wouldn't explain what any of the features did, he'd just breeze past them.

Seems there really are no resources that break this shit down. I'm wondering if just searching stuff I don't understand in Cheat Engine will be a better idea - I've already gotten a grasp on registers and basic instructions that way. As I said, Stpehen vaguely saying "Well some Assembly might help here" had me super worried that I'd need to study an Assembly bible in order to actually use Cheat Engine, or just basic reverse engineering on software. The latter might still be true, but I still get the feeling that understanding any of the actual code in memory is much easier to understand than these people make it out to be.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Jul 17, 2019 9:25 pm    Post subject: Reply with quote

Understanding 10-20 lines is pretty easy yeah
Most of what you're going to see is mov, add, sub, inc, dec, lea, mul, imul, div, xor, push, pop, jmp, call, and various conditional jumps like jne,je,jg,jl etc.
and for floating point
fld, fst, fstp, fadd, fsub, fmul or (older x86 code)
movss, movsd, adds*, subs*, muls* (newer x64 but also seen on new x86)

As Kovah mentions near the start of the first video there's only about 14-30 instructions that make up the majority of code and are really worth knowing.

not too hard to nop out an instruction to make it not do something or change dec/sub to inc/add so that it increases a value instead of decreasing it, or change a mov to move an immediate/literal value (harder with the floating point since they don't accept immediate values)

Understanding entire functions and how they relate to each other, as well as writing your own, how a stack frame works and some of the more complex instructions will take more effort.

As for the OST videos, there's 11 hours of content over 2 days irl, you/they are not expected to remember everything. Just watch it through once and see how much you pick upon. Don't stress over it, just see if you can follow along with the program being discussed and do the exercises. If something sounds interesting just make a note and look it up later. Some things are nice to know about in general like risc and endianness but aren't going to come up if you're just doing regular games, however they probably will if you mess with any emulators so it's nice to be aware that those are things that exist at least vaguely. Similarly for base conversions you need to be aware that various bases exist and allow you to represent the same value in different ways, but you can just use a calculator to do the conversion.

Stephen himself didn't know asm all that well through the tutorials iirc, I remember seeing him recreate call with push and jmp in his magic bug net script for terraria. Though it's possible those were made after I don't believe so. Of course he's learned a lot since then Smile

The more you're actually working with assembly the more it matters how well you understand things, and there's a lot of things that aren't very intuitive so aren't just going to pick up by doing the same basic techniques a noob knows about. You're probably not going to learn to trace function calls etc., especially without programming experience, if all you understand up to that point is nopping whatever comes up in the find what writes list, of course if you're still watching tutorials maybe it'll be shown and you can learn from that and trial and error but.

Quote:
Seems there really are no resources that break this shit down
It's a big topic and even simple tasks like changing remaining ammo when firing a gun can easily be implemented half a dozen different ways in different games (and sometimes even the same game will do it two or three ways for different gun types). There are assembly crash courses, but in my experience those don't really get you anything usable unless you rewatch them about a dozen times at which point you might as well use something trying to be an actual course, and most are not focused on asm for game hacking or CE.

Maybe look at the Squally game? Though I haven't done so myself so I can't really say whether it's worth it.

PS. looking at the transcript the base conversion is ~7-13 minutes in and the first time he says "as I've said before" is about 30 minutes in... "earlier" isn't in the transcript at all and well it's the first part of the first day so...

_________________
https://github.com/FreeER/ has a few CE related repos


Last edited by FreeER on Sat Jul 20, 2019 9:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Sat Jul 20, 2019 9:52 am    Post subject: Re: I don't understand the relationship between Assembly and Reply with quote

Bunny_Wabbit wrote:
As someone who enjoys IT related subjects and gaming, I've always wanted to become better at understand Cheat Engine and how it works, but I've never managed to find a good resource at learning Assembly or Lua to the point where it 'clicks' as to how Cheat Engine communicates with both languages.


Assembly is the instructions the processor executes in readable form, which we also refer to as opcodes. The primitive form is in machine code which is basically just byte patterns based on how the processor's instruction set is defined by its engineers. All programs you run on a computer are basically machine code i.e. the program compilation process translates the program language code into machine code corresponding to the processor it is meant to run on, different processors have different instructions sets and machine codes, so a program compiled for x86-64 will not run on an ARM processor. CE automatically transcribe the bytes in the attached process into readable assembly which you see in the top panel of the memory browser, which is called the disassembly view. CE does this as best as it can so if you browse to non-actual executable bytes like you health values you will still see assembly instructions, but they are just gibberish that aren't actually executed.

The way we use assembly in CE is by overwriting into the game's executable code itself and modify the executable assembly code itself. CE's autoassembler automatically translates the assembly instructions we write in AutoAssembler scripts into machine code and writes them into the attached process's memory. This is done through Windows API's WriteProcessMemory function. The simpler AutoAssembler codes usually just NOP the assembly instructions, which means to replace the machine code with bytes 0x90 for the instruction NOP (No op - do nothing). So if we identify an instruction as responsible for decreasing health, we NOP it and the health will no longer decrease.

However, there are times when the overwritten section does not have enough space/bytes for us to write all the assembly instructions we want. In this case, we usually allocate more virtual memory into the game's process where we then write our instructions. The overwritten section is then instead used to redirect the flow of execution through the JMP instruction into this new memory region, which we also refer to as a code cave. This allocation of memory is also provided through Windows API's VirtualAllocEx. At the end of our assembly code here we must redirect the execution flow back to the original spot in the game's code where we branched off from, though there are times we can also jump back to other parts of the game code if we want to skip or change game behaviors.

Lua is a programming language mainly embedded into applications that allows users to extend their functionality using Lua code. Lua in CE is used in the same way and Lua code is interpreted and executed through CE's Lua engine. The Lua engine has to be specifically coded into CE using Lua's FreePascal API (CE is coded in FreePascal. To extend a C++ program we may use the Lua C++ API, so forth). The internal functions CE wants Lua to use has to be exposed to the Lua engine e.g. the number of variables and their types a function accepts as its arguments and returns has to be made known to the Lua engine through the API. So for CE's Lua engine to use readInteger(address), the function has to be first coded in FreePascal and the function signature added into the Lua engine through its API. So we do not actually use Lua to directly modify an attached process's memory but instead use it to programmatically control CE which may then modify a process. Though we can also use the Lua engine to do a variety of things such as modify CE itself. Check the Lua extensions section of the forum for more info.

Bunny_Wabbit wrote:
So you guys think I should try and learn and retain C++ first?

I looked at that playlist ParkourPenguin, but I get the feeling you need to be a student of his to understand the context of what he's talking about. He kept saying stuff like "As we talked about before". I got a little beyond converting Dec to Bin to Hex in the first video and it kinda got confusing from there, and felt like a test on whether I needed to remember what he was talking about or not.

I tried learning x86 from a Udemy course and a book on Kindle, but the instructor had scarpered and wasn't answering anyone's questions, and just wasn't very easily understood. As for the book, every time he mentioned a new CPU introducing a new feature, he'd talk about it as if you already know what it is, like he was making everything twice as wordy as it needs to be. Like, for example he'd say what features the x86 introduced after its previous iteration, and he wouldn't explain what any of the features did, he'd just breeze past them.

Seems there really are no resources that break this shit down. I'm wondering if just searching stuff I don't understand in Cheat Engine will be a better idea - I've already gotten a grasp on registers and basic instructions that way. As I said, Stpehen vaguely saying "Well some Assembly might help here" had me super worried that I'd need to study an Assembly bible in order to actually use Cheat Engine, or just basic reverse engineering on software. The latter might still be true, but I still get the feeling that understanding any of the actual code in memory is much easier to understand than these people make it out to be.


C++ is actually not easy for someone entirely new into programming since it requires the programmer to be aware of memory management and how memory works in a computer. This implies the required knowledge of pointers. Inevitably, if you want to become proficient at writing assembler scripts you will have to learn what pointers are at some point but it can be really confusing for beginners who are still coming to grasp with many other basic concepts in programming. If this is the case, I would suggest starting off from an easier language like Java. The reason we say someone who wants to learn assembly hacking has to learn a programming language first is because you know where and how to find the assembly instructions you want in the game's code, and understand what the assembly instructions are actually doing. To do that, you need to think from the point of view of the game's developers and how they might have programmed a game's function in e.g. how the game decrease the player's health when getting shot, and you can't do that if you have zero knowledge on programming. So as long as you have these basic concepts you can already start on the many autoassembler tutorials in this forum e.g. https://forum.cheatengine.org/viewtopic.php?t=95363. The best advice I can give is find a game(s) that you want to hack and try learning how to write your own AA scripts from there. Its easier to learn assembly while having a concrete goal that interest you then just trying to absorb and recall all those abstract concepts with no hands on or only having hands on after an entire online course etc. Find something traditional like HP bars and displayed values instead of those Call of Duty styles health meters whose values aren't shown but represented as blood on screen which recovers over time. It's easier to search for values in traditional games HUD.
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 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