Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

How the CPU instructions work?


fastman92
 Share

Recommended Posts

When reverse engineering the application, it will be important to know how the CPU executes the instructions.

 

First of all, it's worth knowing that today CPUs made it possible to execute the different code simultaneously using different cores.

It's the task of operating system to properly schedule the execution time to the active threads.

 

Application which is running can have multiple threads running.

Each thread can have a different code executed at the time.

 

Each thread has its own stack and can have a set of local variables.

 

Stack - the memory used by the functions for their execution to store the local data of the function running.

 

The CPU instruction - the smallest operation that CPU can execute.

The instructions can manipulate the data stored in the CPU registers or RAM memory that belongs to the process.

The more powerful operations will require the use of system functions. however.

 

While reverse engineering it will be important to know what the specific instructions are doing.

 

Conditions in the CPU code work by using the branch instructions which allow to alter the execution depending on the flags registers.

That means some CPU instructions needs to set up the flags register and then the conditional jump instruction needs to be executed.

 

There are lots more CPU instructions that this post includes, who wants to reverse engineer will need to search for these on the Internet.

That's only a beginning.

 

x86

 

Examples:

sub - subtracts the value from the first operand given

add - adds the value to the first operand given

shr - shifts bits of the value right, often used to divide by the multiply of 2. For example the division of EAX by 32 would be written as "shr eax, 5"

shl - shifts bits of the value left, often used to multiply by the value being a power of 2. For example the multiplication of EAX by 32 would be written as "shl eax, 5"

xor - performs XOR operation. Often used to zero out the register - xoring the two equal values will give the result of 0. No bits set. "xor eax, eax" would set the value of EAX register to 0.

inc - decrements the value stored in the operand.

dec - decrements the value stored in the operand.

 

 

call - calls a function - subtracts 4 from ESP, puts an address of the next instruction following the "call" into memory address pointed by ESP, sets the EIP into the pointer of the target function.

retn - returns from a function - reads a return address which is stored on the memory as pointed by the ESP register. Sets the EIP to this return address . Adds 4 to ESP. The execution continues from return address.

 

push - pushes the value from the operand on stack, what really happens is ESP gets decreased by 4, then value from the operand is stored on memory address pointed by the ESP register.

pop - pops off the value from stack and sets the operand to that value. For example "pop ebx" means EBX will be set to the value read from the memory pointed by the ESP register. Then ESP register will be added 4.

 

 

Author: fastman92

Edited by fastman92
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.