Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tutorial by Bad Luck Brian
- Now we can set vartiables, assign them by reading the memory and store them in the memory too.
- but what if we want to do some actions depending on a condition ?
- in programming we use the 'if' and 'else if' statements
- in powerpc it's different. We use 'locations'.
- Let's check an example in IDA.
- See all these boxes of codes ? let's call them 'code location'.
- to make a if/else you need to compare two value.
- we will use cmpwi.
- we use it like this:
- CMPWI REGISTER, VALUE
- this will compare the register and the value and will use a comparison register called 'CR'.
- it will return one of these:
- -eq (equal)
- -gt (greater)
- -lt (lesser)
- they will have either a '1' or a '0'.
- 1 = true
- 0 = false
- lets use an example:
- Code:
- li r3, 0x15
- cmpwi r3, 0x19
- -eq = 0 (false, they're not equal)
- -lt = 1 (true, 0x15 is lesser than 0x19 )
- -gt = 0 (false, 0x15 is not greater than 0x19)
- lets use another example:
- Code:
- li r3, 0x15
- cmpwi r3, 0x15
- -eq = 1 (true, they're equal)
- -lt = 0 (false, 0x15 is not lesser than 0x15 )
- -gt = 0 (false, 0x15 is not greater than 0x15)
- Now what ? Now we will use 'jump' and 'conditional jumps'.
- Here is a list:
- Code:
- b - jumps no matter what
- beq - jumps if -eq = 1
- bne - jumps if -eq = 0
- bgt - jumps if -gt = 1
- blt - jumps if -lt = 1
- Lets use an example, lines will be included for the locations. i will use ' // ' to make a comment , BTW
- each lines in ppc has a size of 4 bytes, that's why its 0, 4, 8 , C and NOTE: it's in hexadecimal
- Code:
- 0: li r3, 0x20 //set r3 to: 00 00 00 15
- 4: cmpwi r3, 0x30 // -eq:0 -gt:0 -lt:1
- 8: beq 28 //it will not jump to :28 because -eq is false, so the program will continue to the next line ( :C)
- C: bgt 28 //it will not jump to :28 because -lt is false, so the program will continue to the next line ( :10 )
- 10: b 14 // jump to :14
- 14: bne 1C //will jump to 1C because -eq = 0
- 18: b 28 //this will never be executed
- 1C: b 28 //it will jump to :28
- 20: li r3, 0x1234 //not executed
- 24: li r3, 0x1234 //not executed
- 28: b 0 //jump back to 0 for an infinite loop, yeah
- That's it for the if/else on powerpc !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement