Advertisement
ScriptzMoDz

[PowerPC] Conditions

Aug 29th, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. //Tutorial by Bad Luck Brian
  2.  
  3. Now we can set vartiables, assign them by reading the memory and store them in the memory too.
  4. but what if we want to do some actions depending on a condition ?
  5.  
  6. in programming we use the 'if' and 'else if' statements
  7. in powerpc it's different. We use 'locations'.
  8.  
  9. Let's check an example in IDA.
  10.  
  11.  
  12.  
  13. See all these boxes of codes ? let's call them 'code location'.
  14. to make a if/else you need to compare two value.
  15.  
  16. we will use cmpwi.
  17.  
  18. we use it like this:
  19.  
  20. CMPWI REGISTER, VALUE
  21.  
  22. this will compare the register and the value and will use a comparison register called 'CR'.
  23. it will return one of these:
  24. -eq (equal)
  25. -gt (greater)
  26. -lt (lesser)
  27.  
  28. they will have either a '1' or a '0'.
  29.  
  30. 1 = true
  31. 0 = false
  32.  
  33.  
  34. lets use an example:
  35.  
  36. Code:
  37.  
  38. li r3, 0x15
  39. cmpwi r3, 0x19
  40.  
  41. -eq = 0 (false, they're not equal)
  42. -lt = 1 (true, 0x15 is lesser than 0x19 )
  43. -gt = 0 (false, 0x15 is not greater than 0x19)
  44. lets use another example:
  45.  
  46. Code:
  47.  
  48. li r3, 0x15
  49. cmpwi r3, 0x15
  50.  
  51. -eq = 1 (true, they're equal)
  52. -lt = 0 (false, 0x15 is not lesser than 0x15 )
  53. -gt = 0 (false, 0x15 is not greater than 0x15)
  54. Now what ? Now we will use 'jump' and 'conditional jumps'.
  55. Here is a list:
  56. Code:
  57.  
  58. b - jumps no matter what
  59. beq - jumps if -eq = 1
  60. bne - jumps if -eq = 0
  61. bgt - jumps if -gt = 1
  62. blt - jumps if -lt = 1
  63. Lets use an example, lines will be included for the locations. i will use ' // ' to make a comment , BTW
  64. each lines in ppc has a size of 4 bytes, that's why its 0, 4, 8 , C and NOTE: it's in hexadecimal
  65.  
  66. Code:
  67.  
  68. 0: li r3, 0x20 //set r3 to: 00 00 00 15
  69. 4: cmpwi r3, 0x30 // -eq:0 -gt:0 -lt:1
  70. 8: beq 28 //it will not jump to :28 because -eq is false, so the program will continue to the next line ( :C)
  71. C: bgt 28 //it will not jump to :28 because -lt is false, so the program will continue to the next line ( :10 )
  72. 10: b 14 // jump to :14
  73. 14: bne 1C //will jump to 1C because -eq = 0
  74. 18: b 28 //this will never be executed
  75. 1C: b 28 //it will jump to :28
  76. 20: li r3, 0x1234 //not executed
  77. 24: li r3, 0x1234 //not executed
  78. 28: b 0 //jump back to 0 for an infinite loop, yeah
  79.  
  80. That's it for the if/else on powerpc !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement