美好的一天。
今天,我们将看一下if, for, while, switch
用C语言编写的反汇编指令代码。
如果声明
该指令很容易以反汇编的形式与其他指令区分开。它的区别特征是单个条件跳转指令je,jne和其他跳转命令。
radare2. IDA PRO radare2 , radare2. IDA PRO.
IDA PRO
radare2
#include <stdio.h>
void main() {
int x = 1;
int y = 2;
if(x == y) {
printf("x = y\n");
}
else{
printf("x != y\n");
}
}
gcc. gcc -m32 prog_if.c -o prog_if
. -m32 , x86.
radare2, r2 prog_if
. aaa
main s main
. pdf
.
radare2
( int x; int y ), 1 var_ch ( x) 2 var10h ( y). (cmp) 1 2 (cmp edx, dword [var_10h]
). . jne ( jump if noe equal) 0x000011e1. if ( VV
radare2 IDA).
. . .
#include <stdio.h>
void main() {
int x = 0;
int y = 1;
int z = 2;
if(x == y) {
if(z == 0) {
printf("z = 0; x = y\n");
}
else{
printf("z = 0; x != y\n");
}
}
else {
if(z == 0) {
printf("z = zero and x != y.\n");
} else {
printf("z non-zero and x != y.\n");
}
}
}
radare2
.
for
for : , , /. for .
#include <stdio.h>
void main() {
int x;
for(x = 0; x < 100; x++) {
printf("x = %d", x);
}
}
radare2
1 - var_ch (x = 0)
2 - , jle. ( x 2, .)
3 - (printf)
4 - var_ch (++x)
while
while , - , . while for, . for, .
#include <stdio.h>
int func_1(int x);
int change_status();
int main() {
int status = 0;
while(status == 0) {
printf("int e = %d", func_1(5) );
status = change_status();
}
return 0;
}
int change_status() {
return 1;
}
int func_1(int x) {
int c;
int e;
int l;
c = 1 + 2;
e = x / 5;
l = 4 - 2;
return e;
}
radare2
1 - var_4h (status = 0)
2 - , je. ( x 0, .)
3 - (func1, printf, change_status)
switch
switch : .
#include <stdio.h>
int main() {
int i = 3;
switch(i) {
case 1:
printf("CASE_1 i = %d", i+4);
break;
case 2:
printf("CASE_2 i = %d", i+9);
break;
case 3:
printf("CASE_3 i = %d", i+14);
break;
}
return 0;
}
radare2
1 - var_4h (i = 3)
2 - (add, printf)
"case" , (cmp, je, jne) i case.
, ( ) , — switch if . , cmp je jne.
switch. case 4 .
#include <stdio.h>
int main() {
int i = 3;
switch(i) {
case 1:
printf("CASE_1 i = %d", i+4);
break;
case 2:
printf("CASE_2 i = %d", i+9);
break;
case 3:
printf("CASE_3 i = %d", i+14);
break;
case 4:
printf("CASE_3 i = %d", i+19);
break;
default:
break;
}
return 0;
}
radare2
1 - var_4h (i = 3)
2 - (add, printf)
c if . .
图形模式是您反汇编的朋友:)
就这样。我建议您尝试自己用C编写程序,编译并研究反汇编的代码。再练习一次!
感谢您的关注。不要生病。