给出以下代码
#include<stdio.h>
int main() {
int x = 0, y = 0, z = 0;
while (1) {
x = 0;
y = 1;
do {
printf("%d\n", x);
z = x + y;
x = y;
y = z;
} while (x < 255);
}
return 0;
}
我们把这个程序编写成32位程序,然后我们放入IDA中进行分析
.text:00801870 ; Attributes: bp-based frame
.text:00801870
.text:00801870 ; int __cdecl main()
.text:00801870 _main proc near ; CODE XREF: _main_0↑j
.text:00801870
.text:00801870 var_24 = byte ptr -24h
.text:00801870 z = dword ptr -20h
.text:00801870 y = dword ptr -14h
.text:00801870 x = dword ptr -8
.text:00801870
.text:00801870 push ebp
.text:00801871 mov ebp, esp
.text:00801873 sub esp, 0E4h
.text:00801879 push ebx
.text:0080187A push esi
.text:0080187B push edi
.text:0080187C
.text:0080187C __$EncStackInitStart_1:
.text:0080187C lea edi, [ebp+var_24]
.text:0080187F mov ecx, 9
.text:00801884 mov eax, 0CCCCCCCCh
.text:00801889 rep stosd
.text:0080188B
.text:0080188B __$EncStackInitEnd_1: ; JMC_flag
.text:0080188B mov ecx, offset _C91CCFE8__@cpp
.text:00801890 call j_@__CheckForDebuggerJustMyCode@4 ; __CheckForDebuggerJustMyCode(x)
.text:00801895 mov [ebp+x], 0
.text:0080189C mov [ebp+y], 0
.text:008018A3 mov [ebp+z], 0
.text:008018AA
.text:008018AA loc_8018AA: ; CODE XREF: _main+80↓j
.text:008018AA mov eax, 1
.text:008018AF test eax, eax
.text:008018B1 jz short loc_8018F2
.text:008018B3 mov [ebp+x], 0
.text:008018BA mov [ebp+y], 1
.text:008018C1
.text:008018C1 loc_8018C1: ; CODE XREF: _main+7E↓j
.text:008018C1 mov eax, [ebp+x]
.text:008018C4 push eax
.text:008018C5 push offset _Format ; "%d\n"
.text:008018CA call j__printf
.text:008018CF add esp, 8
.text:008018D2 mov eax, [ebp+x]
.text:008018D5 add eax, [ebp+y]
.text:008018D8 mov [ebp+z], eax
.text:008018DB mov eax, [ebp+y]
.text:008018DE mov [ebp+x], eax
.text:008018E1 mov eax, [ebp+z]
.text:008018E4 mov [ebp+y], eax
.text:008018E7 cmp [ebp+x], 0FFh
.text:008018EE jl short loc_8018C1
.text:008018F0 jmp short loc_8018AA
.text:008018F2 ; ---------------------------------------------------------------------------
.text:008018F2
.text:008018F2 loc_8018F2: ; CODE XREF: _main+41↑j
.text:008018F2 xor eax, eax
.text:008018F4 pop edi
.text:008018F5 pop esi
.text:008018F6 pop ebx
.text:008018F7 add esp, 0E4h
.text:008018FD cmp ebp, esp
.text:008018FF call j___RTC_CheckEsp
.text:00801904 mov esp, ebp
.text:00801906 pop ebp
.text:00801907 retn
.text:00801907 _main endp
.text:00801907
下图部分这一部分,属于编译器包装的,对程序的初始化
这里我们先不做研究
以下这一段可以很明显看出对x,y,z
进行了初始化
所对应的部分
x和y在循环里的赋值如图
对于中间的循环部分
以上是大概的分析,接下来,我们进行细致的分析
当然了,在实际中,逆向分析的难度是很大的,这里只是方便大家理解学习,所以给了一个十六