使用打开 vc 命令提示符
start->programs->vc->vc command prompt
使用 Microsoft Visual Studio 2010 x86 工具的设置环境。在桌面上创建一个临时目录用于编译和链接
C:\Program Files\Microsoft Visual Studio 10.0\VC>cd "c:\Documents and Settings\Admin\Desktop"
C:\Documents and Settings\Admin\Desktop>md pran
C:\Documents and Settings\Admin\Desktop>cd pran
C:\Documents and Settings\Admin\Desktop\pran>copy con prankasum.cpp
^Z
1 file(s) copied.
C:\Documents and Settings\Admin\Desktop\pran>write prankasum.cpp
C:\Documents and Settings\Admin\Desktop\pran>type prankasum.cpp
#include <stdio.h>
int pranit = 2;
int& sumit = pranit;
int main(int argc, char** argv)
{
sumit++;
return sumit;
}
C:\Documents and Settings\Admin\Desktop\pran>dir /b
prankasum.cpp
C:\Documents and Settings\Admin\Desktop\pran>cl /nologo /Zi prankasum.cpp /link /RELEASE
prankasum.cpp
C:\Documents and Settings\Admin\Desktop\pran>dir /b
prankasum.cpp
prankasum.exe
prankasum.obj
prankasum.pdb
vc100.pdb
在 ollydbg 中打开 exe 并导航到主
选项卡的注释列以显示源代码,并在调试选项中要求 ollydbg 使用已识别的参数和本地变量
C:\Documents and Settings\Admin\Desktop\pran> ollydbg prankasum.exe
00401000 >PUSH EBP ; {
00401001 MOV EBP, ESP
00401003 MOV EAX, DWORD PTR DS:[sumit] ; sumit++;
00401008 MOV ECX, DWORD PTR DS:[EAX]
0040100A ADD ECX, 1
0040100D MOV EDX, DWORD PTR DS:[sumit]
00401013 MOV DWORD PTR DS:[EDX], ECX
00401015 MOV EAX, DWORD PTR DS:[sumit] ; return sumit;
0040101A MOV EAX, DWORD PTR DS:[EAX]
0040101C POP EBP ; }
0040101D RETN
或在windbg
prankasum!main:
00401000 55 push ebp
0:000> uf @eip
prankasum!main [c:\documents and settings\admin\desktop\pran\prankasum.cpp @ 5]:
5 00401000 55 push ebp
5 00401001 8bec mov ebp,esp
6 00401003 a104b04000 mov eax,dword ptr [prankasum!sumit (0040b004)]
6 00401008 8b08 mov ecx,dword ptr [eax]
6 0040100a 83c101 add ecx,1
6 0040100d 8b1504b04000 mov edx,dword ptr [prankasum!sumit (0040b004)]
6 00401013 890a mov dword ptr [edx],ecx
7 00401015 a104b04000 mov eax,dword ptr [prankasum!sumit (0040b004)]
7 0040101a 8b00 mov eax,dword ptr [eax]
8 0040101c 5d pop ebp
8 0040101d c3 ret
0:000> dv
argc = 0n1 argv = 0x00033ba8
0:000> ?? sumit int * 0x0040b000
0:000> ?? pranit int 0n2
0:000> pct 0040101d c3 ret
0:000> ?? sumit int * 0x0040b000
0:000> ?? pranit int 0n3
0:000> x /t /v /q prankasum!sumit
prv global 0040b004 4 int * @!"prankasum!sumit" = 0x0040b000
0:000> x /t /v /q prankasum!pranit
prv global 0040b000 4 int @!"prankasum!pranit" = 0n3
更新
跳转评论栏的解释
ollydbg 中的每个 mdi 窗口顶部都有一个栏,可以隐藏或显示
right click -> appearance -> show bar / hide bar
每个条都有列,如果您repeatedly click the comment column
将循环显示,可以将许多列配置为在 cpu 窗口中显示不同的项目
comment / profile/ and source
评论将显示所有
analysis comments / user comments
profile 将显示所有 run trace / hittrace/ module and global profile statistics
例如,这strcpy_s
在 crt 初始化期间被调用了 50 次
004019EC |. >|CALL prankasu.strcpy_s ; 50.
在这个调用中,这个循环被调用了 ~2700 次
00403D45 /MOV CL, BYTE PTR DS:[EAX] ; 2787.
00403D47 |MOV BYTE PTR DS:[ESI+EAX], CL ; 2787.
00403D4A |INC EAX ; 2787.
00403D4B |TEST CL, CL ; 2787.
00403D4D |JE SHORT prankasu.00403D52 ; 2787.
00403D4F |DEC EDI ; 2737.
00403D50 \JNZ SHORT prankasu.00403D45 ; 2737.
00403D52 TEST EDI, EDI ; 50.
如果您循环到源列
strcpy_s is from vc\crt\stdenvp.c:133. _ERRCHECK(_tcscpy_s(*env, cchars, p));
见下文
004019E9 |PUSH ESI ; _ERRCHECK(_tcscpy_s(*env, cchars, p));
004019EA |PUSH EBX
004019EB |PUSH EAX
004019EC |CALL prankasu.strcpy_s
004019F1 |ADD ESP, 0C
循环来自 vc\crt\tcscpy_s_inl
00403D41 MOV ESI, EDX ; while ((*p++ = *_SRC++) != 0 && --available > 0)
00403D43 SUB ESI, EAX
00403D45 /MOV CL, BYTE PTR DS:[EAX]
00403D47 |MOV BYTE PTR DS:[ESI+EAX], CL
00403D4A |INC EAX
00403D4B |TEST CL, CL
00403D4D |JE SHORT prankasu.00403D52
骑车回评论你看
004019E9 |. 56 |PUSH ESI ; /Arg3 = 7C90DE6E
004019EA |. 53 |PUSH EBX ; |Arg2 = 00000000
004019EB |. 50 |PUSH EAX ; |Arg1 = 00000000
004019EC |. E8 1D>|CALL prankasu.strcpy_s ; \strcpy_s
options->debugging options->cpu->select show symbolic address
将
XXXXXX [40xxxx]
显示为
xxxxxx [sumit]
options ->debugging options->analysis->select show args and locals in procedure
将使所有ebp+XX
到arg.1 arg.2
和所有ebp-XX
到local.1 local.2
both ollydbg 1.10 and 2.01 behave similarly
full
或partial (stripped down )
任何可接受格式的符号信息 ( map tds pdb dbg
) 是**mandatory**
**requirement**