BullyWiiHacks
Welcome dear guest! Very Happy

To start posting and being part of the BWH community, you simply need to register an account or log into an existing one.

If you do not wish to register at all, that's fine but there will be more advertisements. :/

You can probably see and download most content provided for regular members even without an account.

Your contributions will be greatly appreciated though, give it a shot and register today! thumbsup

Join the forum, it's quick and easy

BullyWiiHacks
Welcome dear guest! Very Happy

To start posting and being part of the BWH community, you simply need to register an account or log into an existing one.

If you do not wish to register at all, that's fine but there will be more advertisements. :/

You can probably see and download most content provided for regular members even without an account.

Your contributions will be greatly appreciated though, give it a shot and register today! thumbsup
BullyWiiHacks
Would you like to react to this message? Create an account in a few clicks or log in to continue.
BullyWiiHacks

Gaming, Modding & Programming

Important reminders:

- Click *HERE* for advanced forum search or check out the text field below on the front page for Google before posting
- NO support via private message (use the forum)
- Write meaningful topic titles
Site Translation
Latest topics
» Dropped Out of College to Pursue Web Dev and Life Pursuits in General
Assembly Programming in PPC/x86 (Basic Tutorial) Empty4/7/2024, 2:34 pm by SnB@BWH

» Bully Made It Into a BIG Video 400K Views
Assembly Programming in PPC/x86 (Basic Tutorial) Empty4/7/2024, 6:58 am by Bully@WiiPlaza

» Wii Play Tanks
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/24/2024, 2:46 pm by helpmeout

» [Bypass Paywalls] (Global) @magnolia1234 - GitLab
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/18/2024, 3:55 am by Seth@WiiPlaza

» [Download] Mary Shelley's Frankenhole
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/16/2024, 8:29 am by Seth@WiiPlaza

» Completely Custom Modded Controllers (Undetectable)
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/5/2024, 1:55 pm by Shadow@BWH

» (Zombies) Drink perks code?
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/5/2024, 1:24 pm by Shadow@BWH

» Die Rückkehr zu STEAM und WARFACE
Assembly Programming in PPC/x86 (Basic Tutorial) Empty3/2/2024, 3:54 am by Seth@WiiPlaza

» First person hand model change?
Assembly Programming in PPC/x86 (Basic Tutorial) Empty2/28/2024, 4:53 am by Ad3lamac611

» {RELEASE} Field Raider Firefox v1.72 by Seth@WiiPlaza
Assembly Programming in PPC/x86 (Basic Tutorial) Empty2/21/2024, 8:52 am by naxil

Search
 
 

Display results as :
 


Rechercher Advanced Search

May 2024
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  

Calendar Calendar

Country Statistics
Free counters!

You are not connected. Please login or register

Assembly Programming in PPC/x86 (Basic Tutorial)

Go down  Message [Page 1 of 1]

Bully@WiiPlaza

Bully@WiiPlaza
 
 

Most games are programmed in C/C++ which are relatively low level programming languages since they are compiled directly into the native target architecture (such as x86, PowerPC or ARM assembly). In order to hack games, we can therefore decompile the assembly code back to C/C++ using e.g. IDA Pro or Ghidra if we analyze the game's executable:

Assembly Programming in PPC/x86 (Basic Tutorial) 2021-110

The main() function is the game's or executable's entry point to the program. This is where code execution starts.

In order to modify the game's code, we should therefore learn the respective assembly dialect and/or C/C++ programming in order to understand how the code might have been written and how compilers translate C/C++ code to assembly via calling conventions and such.

In this thread we will discuss the basic of assembly programming and keep it as simple as possible to follow. Also, we'll mainly use x86 and PowerPC assembly as examples since they're the most common architectures to work with. Wink


  • Components of a computer device
    Every computer or gaming console etc. runs some sort of assembly programming architecture. For the concepts of a RAM (= random access memory) exist as well as registers. Assembly instructions are procedural machine instructions which tell the processor what to do (e.g. move some data from the RAM into a register or vice versa).

    In PowerPC assembly we have 32 general purpose registers (GPRs). They go from r0 to r31. These are used for almost all types of (numeric) data which isn't floating points. For floating point data, the floating point registers f0 to f31 are used.

    In x86 assembly the distinction is similar but there are even more registers and they are named less straight-forward, e.g. eax, ebx and ecx.

  • Basic processor operations/assembly instructions
    The most common operations are math operations such as adding, subtracting or multiplying, moving data from/to registers and/or the RAM as well as jump instructions to skip over or carry on executing instructions somewhere else. Calling and returning from functions are special cases of jumps.

  • Tools for testing and playing with assembly
    x86 assembly (Jasmin):
    Assembly Programming in PPC/x86 (Basic Tutorial) 2021-115

    x86 assembly (Cheat Engine):
    Assembly Programming in PPC/x86 (Basic Tutorial) 2021-117

    PowerPC assembly (Assembler Utility):
    Assembly Programming in PPC/x86 (Basic Tutorial) 2021-114

  • Code examples
    In x86 assembly we can use the MOV instruction to move data from one place to another. For example, MOV EAX, 1234 will write the value 1234 into the register EAX. We can load data from a memory address into a register by using e.g. MOV EAX, [EAX]. Note that an invalid address on the right side will cause a crash since accessing an invalid address is an error. We can add two registers by using e.g. ADD EAX, EBX. The result will be stored in EAX again. Also, register names are case insensitive. We can spell them lowercase or uppercase without any problems. If we want to perform a conditional jump, we can do so via a compare instruction CMP and a JE instruction (= jump equals):
    Code:
    MOV EAX, 1234
    CMP EAX, 1234
    JE _SKIP
    ADD EAX, 2
    _SKIP:
    Here, we use a branch label _SKIP to indicate where to jump to. The code can be stepped through and analyzed in Jasmin. The final value in EAX will be 1234 since the ADD EAX, 2 is skipped.

    Another important concept is function calling. For this we need the CALL instruction. Before we execute the call instruction, we also need to fill the parameters of the functions according to the calling conventions. In x86 assembly, the register ECX is the first parameter for integer arguments etc. Functions are useful to structure the code better and to re-use code. Writing bigger programs or code in general will become way too messy without functions. Assembly is no exception.

    An example code for showing how calling functions works is the following:
    Code:
    MOV ECX, 2
    MOV EDX, 10
    CALL _my_function
    MOV [EBX], ECX

    _my_function:
    MOV EAX, ECX
    MUL EDX
    MOV ECX, EAX
    RET

    This code will firstly write value 2 into ECX and therefore sets up the first function parameter, the 2nd function parameter EDX with value 10, then call the function _my_function which is defined by the branch label. The difference between CALL and JMP is that CALL will backup the stack frame while JMP will not. In order to properly return from a function and destroy the new function's stack frame, we need to use the RET instruction. Inside the function, we will setup EAX with the multiplier, perform the multiplication of AL (8-bit version of EAX) and ECX and store the result in EAX. In case this sounds confusing, make sure to read the documentation for each instruction. Jasmin conveniently provides one, so make use of this great resource:

    Assembly Programming in PPC/x86 (Basic Tutorial) 2021-112

    Finally, we write EAX into ECX again since ECX is the return value register. As the last instruction of this code snippet, MOV [EBX], EAX will be executed which will write the value in ECX into the memory address EBX:

    Assembly Programming in PPC/x86 (Basic Tutorial) 2021-113

  • Conclusion
    And with this the assembly crash course is concluded (for now). Feel free to ask any questions or let me know what I missed and should add to this post. I can recommend learning with Jasmin since it's a great simulator without crashing anything upon making a mistake. However, it may not be as sophisticated as a real processor.

    Serious hacks or mod menus should be written in C or better, in C++. Only small hacks may be written in assembly. C++ also offers the ability to inject code into other processes via hooking. This makes writing assembly by hand relatively obsolete.


Thanks for reading. Wink


_________________
Assembly Programming in PPC/x86 (Basic Tutorial) YBjg74I

Seth@WiiPlaza likes this post

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum