找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 5180|回复: 0

OllyDbg导入IDA符号插件LoadMap分析

[复制链接]

307

主题

228

回帖

7345

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5595 个
贡献
253 次
宅之契约
0 份
在线时间
949 小时
注册时间
2014-1-25
发表于 2015-1-14 10:52:33 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
    LoadMap插件可以在OllyDbg中调试程序时显示IDA符号,大大降低代码分析难度。先用IDA制作map文件,先用IDA载入exe文件,手动分析修改成容易理解的符号后,File->Produce file->Create map file创建map文件,使用OllyDbg载入exe文件,在插件界面选择map文件路径,就可以看到OllyDgb带符号了。
    经我分析,该插件代码并不复杂,本质上还是解析map文件,而该文件格式并不复杂,下面是我截取的一段:

Start         Length     Name                   Class
0002:00000000 0000AF000H .text                  CODE
0003:00000000 00005B000H .data                  DATA
0004:00000000 000001000H .tls                   DATA
0005:00000000 000001000H .rdata                 DATA
0006:00000000 000002000H .idata                 DATA


  Address         Publics by Value

0001:00000000       start
0001:00000012       loc_6051012
0001:00000059       __GetExceptDLLinfo
0001:00000140       sub_6051140
0001:00000150       loc_6051150
0001:0000018D       loc_605118D
0001:0000018F       loc_605118F
0001:000001B1       loc_60511B1
0001:000001BE       loc_60511BE
0001:000001F1       loc_60511F1
0001:000044AC       _Assemble
0001:000044D3       loc_60554D3
0001:000044D8       loc_60554D8
0001:000044E6       loc_60554E6
0001:000044F8       loc_60554F8
0001:00004514       loc_6055514
。。。。。。。。。。。。。。

关键反汇编代码:
.text:100010A0 ; void __cdecl LoadMap()
.text:100010A0 LoadMap         proc near               ; CODE XREF: _ODBG_Pluginaction:loc_100012BDj
.text:100010A0
.text:100010A0 var_204         = dword ptr -204h
.text:100010A0 str             = byte ptr -200h
.text:100010A0 MapFileName     = byte ptr -100h
.text:100010A0
.text:100010A0                 sub     esp, 204h
.text:100010A6                 push    esi
.text:100010A7                 push    18h             ; type
.text:100010A9                 call    _Plugingetvalue
.text:100010AE                 mov     esi, eax
.text:100010B0                 add     esp, 4
.text:100010B3                 test    esi, esi
.text:100010B5                 jnz     short loc_100010E7
.text:100010B7                 push    offset aMapconvA ; "MapConv 错误: 无进程用于添加 map 信息"
.text:100010BC                 push    1               ; highlight
.text:100010BE                 push    eax             ; addr
.text:100010BF                 call    _Addtolist
.text:100010C4                 mov     eax, hOllyWnd
.text:100010C9                 add     esp, 0Ch
.text:100010CC                 push    40h             ; uType
.text:100010CE                 push    offset Caption  ; "LoadMap v0.1"
.text:100010D3                 push    offset Text     ; "是这样 - 如果你没有调试任何程序 - 你不?...
.text:100010D8                 push    eax             ; hWnd
.text:100010D9                 call    ds:MessageBoxA
.text:100010DF                 pop     esi
.text:100010E0                 add     esp, 204h
.text:100010E6                 retn
.text:100010E7 ; ---------------------------------------------------------------------------
.text:100010E7
.text:100010E7 loc_100010E7:                           ; CODE XREF: LoadMap+15j
.text:100010E7                 push    esi             ; addr
.text:100010E8                 call    _Findmodule
.text:100010ED                 mov     edx, [eax+0Ch]
.text:100010F0                 lea     ecx, [eax+50h]
.text:100010F3                 push    ecx
.text:100010F4                 push    edx
.text:100010F5                 push    esi
.text:100010F6                 push    offset aMainbaseXCodeb ; "MainBase: %X, CodeBase: %X, %s"
.text:100010FB                 push    0               ; highlight
.text:100010FD                 push    0               ; addr
.text:100010FF                 mov     MainModule, eax
.text:10001104                 call    _Addtolist
.text:10001109                 push    0               ; getarguments
.text:1000110B                 push    offset defext   ; ".map"
.text:10001110                 lea     eax, [esp+22Ch+MapFileName]
.text:10001117                 push    eax             ; name
.text:10001118                 push    offset title    ; "选择 map 文件"
.text:1000111D                 mov     [esp+234h+MapFileName], 0
.text:10001125                 call    _Browsefilename
.text:1000112A                 add     esp, 2Ch
.text:1000112D                 test    eax, eax
.text:1000112F                 jz      loc_10001280
.text:10001135                 push    edi
.text:10001136                 lea     ecx, [esp+20Ch+MapFileName]
.text:1000113D                 push    offset aRt      ; "rt"
.text:10001142                 push    ecx             ; char *
.text:10001143                 call    _fopen
.text:10001148                 mov     edi, eax
.text:1000114A                 add     esp, 8
.text:1000114D                 test    edi, edi
.text:1000114F                 jnz     short loc_10001172
.text:10001151                 lea     edx, [esp+20Ch+MapFileName]
.text:10001158                 push    edx
.text:10001159                 push    offset aLoadmapA ; "LoadMap 错误: 无法打开 %s"
.text:1000115E                 push    1               ; highlight
.text:10001160                 push    eax             ; addr
.text:10001161                 call    _Addtolist
.text:10001166                 add     esp, 10h
.text:10001169                 pop     edi
.text:1000116A                 pop     esi
.text:1000116B                 add     esp, 204h
.text:10001171                 retn
.text:10001172 ; ---------------------------------------------------------------------------
.text:10001172
.text:10001172 loc_10001172:                           ; CODE XREF: LoadMap+AFj
.text:10001172                 test    byte ptr [edi+0Ch], 10h
.text:10001176                 jnz     loc_10001238
.text:1000117C                 lea     esp, [esp+0]
.text:10001180
.text:10001180 loc_10001180:                           ; CODE XREF: LoadMap+192j
.text:10001180                 push    6               ; size_t
.text:10001182                 lea     eax, [esp+210h+str]
.text:10001186                 push    offset a0001    ; " 0001:"
.text:1000118B                 push    eax             ; char *
.text:1000118C                 call    _strncmp
.text:10001191                 add     esp, 0Ch
.text:10001194                 test    eax, eax
.text:10001196                 jnz     loc_1000121A
.text:1000119C                 push    10h             ; int
.text:1000119E                 lea     ecx, [esp+210h+var_204]
.text:100011A2                 push    ecx             ; char **
.text:100011A3                 lea     edx, [esp+214h+str+6]
.text:100011A7                 push    edx             ; char *
.text:100011A8                 call    _strtol
.text:100011AD                 mov     esi, eax
.text:100011AF                 add     esp, 0Ch
.text:100011B2                 test    esi, esi
.text:100011B4                 jnz     short loc_100011C3
.text:100011B6                 push    edi
.text:100011B7                 push    100h
.text:100011BC                 lea     eax, [esp+214h+str]
.text:100011C0                 push    eax
.text:100011C1                 jmp     short loc_10001225
.text:100011C3 ; ---------------------------------------------------------------------------
.text:100011C3
.text:100011C3 loc_100011C3:                           ; CODE XREF: LoadMap+114j
.text:100011C3                 mov     cl, [esp+20Ch+str+15h]
.text:100011C7                 test    cl, cl
.text:100011C9                 lea     eax, [esp+20Ch+str+15h]
.text:100011CD                 jz      short loc_100011E7
.text:100011CF                 nop
.text:100011D0
.text:100011D0 loc_100011D0:                           ; CODE XREF: LoadMap+145j
.text:100011D0                 mov     cl, [eax]
.text:100011D2                 cmp     cl, 0Dh
.text:100011D5                 jz      short loc_100011DC
.text:100011D7                 cmp     cl, 0Ah
.text:100011DA                 jnz     short loc_100011DF
.text:100011DC
.text:100011DC loc_100011DC:                           ; CODE XREF: LoadMap+135j
.text:100011DC                 mov     byte ptr [eax], 0
.text:100011DF
.text:100011DF loc_100011DF:                           ; CODE XREF: LoadMap+13Aj
.text:100011DF                 mov     cl, [eax+1]
.text:100011E2                 inc     eax
.text:100011E3                 test    cl, cl
.text:100011E5                 jnz     short loc_100011D0
.text:100011E7
.text:100011E7 loc_100011E7:                           ; CODE XREF: LoadMap+12Dj
.text:100011E7                 mov     edx, MainModule
.text:100011ED                 mov     eax, [edx+0Ch]
.text:100011F0                 lea     ecx, [esp+20Ch+str+15h]
.text:100011F4                 push    ecx             ; name
.text:100011F5                 add     eax, esi
.text:100011F7                 push    31h             ; type
.text:100011F9                 push    eax             ; addr
.text:100011FA                 call    _Quickinsertname
.text:100011FF                 mov     edx, MainModule
.text:10001205                 mov     eax, [edx+0Ch]
.text:10001208                 lea     ecx, [esp+218h+str+15h]
.text:1000120C                 push    ecx             ; name
.text:1000120D                 add     eax, esi
.text:1000120F                 push    36h             ; type
.text:10001211                 push    eax             ; addr
.text:10001212                 call    _Quickinsertname
.text:10001217                 add     esp, 18h
.text:1000121A
.text:1000121A loc_1000121A:                           ; CODE XREF: LoadMap+F6j
.text:1000121A                 push    edi             ; FILE *
.text:1000121B                 push    100h            ; int
.text:10001220                 lea     ecx, [esp+214h+str]
.text:10001224                 push    ecx             ; char *
.text:10001225
.text:10001225 loc_10001225:                           ; CODE XREF: LoadMap+121j
.text:10001225                 call    _fgets
.text:1000122A                 mov     al, [edi+0Ch]
.text:1000122D                 add     esp, 0Ch
.text:10001230                 test    al, 10h
.text:10001232                 jz      loc_10001180
.text:10001238
.text:10001238 loc_10001238:                           ; CODE XREF: LoadMap+D6j
.text:10001238                 push    edi             ; FILE *
.text:10001239                 call    _fclose
.text:1000123E                 call    _Mergequicknames
.text:10001243                 push    offset aLoadmapJMap ; "LoadMap: 成功: Map 文件成功导入"
.text:10001248                 push    0               ; highlight
.text:1000124A                 push    0               ; addr
.text:1000124C                 call    _Addtolist
.text:10001251                 mov     edx, hOllyWnd
.text:10001257                 add     esp, 10h
.text:1000125A                 push    40h             ; uType
.text:1000125C                 push    offset Caption  ; "LoadMap v0.1"
.text:10001261                 push    offset aMap     ; "Map 文件成功导入"
.text:10001266                 push    edx             ; hWnd
.text:10001267                 call    ds:MessageBoxA
.text:1000126D                 push    8               ; mode
.text:1000126F                 push    0               ; stackaddr
.text:10001271                 push    0               ; dumpaddr
.text:10001273                 push    0               ; asmaddr
.text:10001275                 push    0               ; threadid
.text:10001277                 call    _Setcpu
.text:1000127C                 add     esp, 14h
.text:1000127F                 pop     edi
.text:10001280
.text:10001280 loc_10001280:                           ; CODE XREF: LoadMap+8Fj
.text:10001280                 pop     esi
.text:10001281                 add     esp, 204h
.text:10001287                 retn

分析结果:

  1. #include <Windows.h>
  2. #include "Plugin.h"
  3. #include <stdio.h>

  4. HINSTANCE hInst;
  5. HWND hOllyWnd;
  6. t_module* MainModule;
  7. BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
  8. {
  9.         if(fdwReason == DLL_PROCESS_ATTACH)
  10.                 hInst=hinstDLL;
  11.         return 1;
  12. }

  13. extc int  _export cdecl ODBG_Pluginmenu(int origin,char data[4096],void *item)
  14. {
  15.         if(origin != PM_MAIN)
  16.                 return 0;
  17.         memcpy(data,"0 载入 Map 文件|1 关于",25);
  18.         return 1;
  19. }

  20. extc int  _export cdecl ODBG_Plugininit(int ollydbgversion,HWND hw, ulong *features)
  21. {
  22.         if(ollydbgversion < 108)
  23.                 return -1;
  24.         hOllyWnd=hw;
  25.         Addtolist(0,0,"LoadMap version 0.1 by lgx/iPB loaded");
  26.         return 0;
  27. }

  28. extc int  _export cdecl ODBG_Plugindata(char shortname[32])
  29. {
  30.         strcpy(shortname,"LoadMap");
  31.         return 108;
  32. }

  33. void LoadMap()
  34. {
  35.         ulong mainbase=Plugingetvalue(VAL_MAINBASE);
  36.         if(!mainbase)
  37.         {
  38.                 Addtolist(0,1,"MapConv 错误: 无进程用于添加 map 信息");
  39.                 MessageBox(hOllyWnd,"是这样 - 如果你没有调试任何程序 - 你不需要 .map 文件 ;-)","LoadMap v0.1",MB_OK|MB_ICONASTERISK);
  40.                 return;
  41.         }
  42.         MainModule=Findmodule(mainbase);
  43.         Addtolist(0,0,"MainBase: %X, CodeBase: %X, %s",mainbase,MainModule->codebase,MainModule->path);
  44.         char MapFileName[256];
  45.         FILE* file;
  46.         char str[256];
  47.         MapFileName[0]= '\0';
  48.         if(!Browsefilename("选择 map 文件",MapFileName,".map",0))
  49.                 return;
  50.          file=fopen(MapFileName,"rt");
  51.         if(!file)
  52.         {
  53.                 Addtolist(0,1,"LoadMap 错误: 无法打开 %s",MapFileName);
  54.                 return;
  55.         }
  56. /*  map文件格式
  57.          0001:00000000       start
  58.          0001:00000012       loc_6051012
  59.          0001:00000059       __GetExceptDLLinfo
  60.          0001:00000140       sub_6051140
  61.          0001:00000150       loc_6051150
  62.          0001:0000018D       loc_605118D
  63.          0001:0000018F       loc_605118F
  64. */
  65.         while(!feof(file))
  66.         {
  67.                 fgets(str,256,file);
  68.                 if(!strncmp(str," 0001:",6))
  69.                 {
  70.                         char* endptr;
  71.                         long offset=strtol(str+6,&endptr,16);//每行偏移6处为相对地址
  72.                         if(offset)
  73.                         {
  74.                                 char* ptr=str+21;//每行偏移21处为IDA符号名
  75.                                 while(*ptr)
  76.                                 {
  77.                                         if(*ptr == '\r' || *ptr == '\n')
  78.                                                 *ptr='\0';
  79.                                         ptr++;
  80.                                 }
  81.                                 Quickinsertname(MainModule->codebase+offset,NM_LABEL,str+21);
  82.                                 Quickinsertname(MainModule->codebase+offset,NM_COMMENT,str+21);
  83.                         }
  84.                 }
  85.         }
  86.         fclose(file);
  87.         Mergequicknames();
  88.         Addtolist(0,0,"LoadMap: 成功: Map 文件成功导入");
  89.         MessageBox(hOllyWnd,"Map 文件成功导入","LoadMap v0.1",MB_OK|MB_ICONASTERISK);
  90.         Setcpu(0,0,0,0,CPU_ASMFOCUS);
  91. }

  92. extc void _export cdecl ODBG_Pluginaction(int origin,int action,void *item)
  93. {
  94.         if(origin != PM_MAIN)
  95.                 return;
  96.         if(action == 0)
  97.                 LoadMap();
  98.         else if(action == 1)
  99.                 MessageBox(hOllyWnd,"LoadMap version 0.1 by lgx/iPB","LoadMap v0.1",MB_OK|MB_ICONASTERISK);
  100. }
复制代码
回复

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-29 19:18 , Processed in 0.040136 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表