汇编还原高级代码-if判断 发表于 2018-09-20 | | 阅读次数 上一篇已经介绍了简单代码的还原,下面记录一下 if 条件判断的代码还原。高级代码如下:12345678910111213int g = 12;void func(int a,int b){if (a > b) {g = a;}else{g = b;}}int main(int argc, char * argv[]) {func(1, 2);} 通过 ida 得到的汇编代码如下: 123456__text:00000001000068B4 _func ; CODE XREF: _main+24↓p__text:00000001000068B4__text:00000001000068B4 var_8 = -8__text:00000001000068B4 var_4 = -4__text:00000001000068B4__text:00000001000068B4 SUB SP, SP, #0x10 上面的代码还是开辟栈空间 。1234__text:00000001000068B8 STR W0, [SP,#0x10+var_4]__text:00000001000068BC STR W1, [SP,#0x10+var_8]__text:00000001000068C0 LDR W0, [SP,#0x10+var_4]__text:00000001000068C4 LDR W1, [SP,#0x10+var_8] 上面判断这个 func 方法有两个参数;123// if (a > b) {__text:00000001000068C8 CMP W0, W1__text:00000001000068CC B.LE loc_1000068E4 上面的比较相当于 if 语句,小于等于的话执行后面的地址,否则的话继续执行下面的方法;123__text:00000001000068D0 ADRP X8, #_g@PAGE__text:00000001000068D4 ADD X8, X8, #_g@PAGEOFF// int *X8 = &9; 得到一个全局变量 g的地址 ,放到 X8中, x8是个地址,1234__text:00000001000068D8 LDR W9, [SP,#0x10+var_4]// int w9 = var_4;__text:00000001000068DC STR W9, [X8]// *x8 = w9; 将 w9的值赋给 x81234567891011121314151617181920__text:00000001000068E0 B loc_1000068F4__text:00000001000068E4 ; ---------------------------------------------------------------------------__text:00000001000068E4__text:00000001000068E4 loc_1000068E4 ; CODE XREF: _func+18↑j__text:00000001000068E4 ADRP X8, #_g@PAGE__text:00000001000068E8 ADD X8, X8, #_g@PAGEOFF__text:00000001000068EC LDR W9, [SP,#0x10+var_8]__text:00000001000068F0 STR W9, [X8]__text:00000001000068F4__text:00000001000068F4 loc_1000068F4 ; CODE XREF: _func+2C↑j__text:00000001000068F4 ADD SP, SP, #0x10__text:00000001000068F8 RET__text:00000001000068F8 ; End of function _func__text:00000001000068F8__text:00000001000068FC__text:00000001000068FC ; =============== S U B R O U T I N E =======================================__text:00000001000068FC__text:00000001000068FC ; Attributes: bp-based frame__text:00000001000068FC__text:00000001000068FC ; int __cdecl main(int argc, const char **argv, const char **envp) 下面是mian 函数的汇编:1234567891011121314151617181920212223__text:00000001000068FC EXPORT _main__text:00000001000068FC _main__text:00000001000068FC__text:00000001000068FC var_10 = -0x10__text:00000001000068FC var_4 = -4__text:00000001000068FC var_s0 = 0__text:00000001000068FC__text:00000001000068FC SUB SP, SP, #0x20__text:0000000100006900 STP X29, X30, [SP,#0x10+var_s0]__text:0000000100006904 ADD X29, SP, #0x10__text:0000000100006908 MOV W8, #1__text:000000010000690C MOV W9, #2__text:0000000100006910 STUR W0, [X29,#var_4]__text:0000000100006914 STR X1, [SP,#0x10+var_10]__text:0000000100006918 MOV X0, X8__text:000000010000691C MOV X1, X9__text:0000000100006920 BL _func__text:0000000100006924 MOV W8, #0__text:0000000100006928 MOV X0, X8__text:000000010000692C LDP X29, X30, [SP,#0x10+var_s0]__text:0000000100006930 ADD SP, SP, #0x20__text:0000000100006934 RET__text:0000000100006934 ; End of function _main