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

QQ登录

只需一步,快速开始

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

对于OllyDbg加载插件过程的分析——细数OllyDbg作者的不足之处

[复制链接]

307

主题

228

回帖

7345

积分

用户组: 真·技术宅

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

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

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

×
本帖最后由 元始天尊 于 2015-1-5 14:14 编辑

    这里对v1.10版本进行逆向,加载插件是在OllyDbg启动后,加载调试程序前完成的,因此需要用OllyDbg调试自身。文档中说OllyDbg先检查_ODBG_Plugindata,那么下断点bp GetProcAddress,[esp+8]=="_ODBG_Plugindata"会发现断在以地址0x00496658开始的函数中。查看其反汇编代码,先进行总体分析,发现有多处调用GetProcAddress,初步判断为加载插件的模块,命名为LoadPlugin,反汇编代码如下:
  1. .text:00496658                 push    ebx
  2. .text:00496659                 push    esi
  3. .text:0049665A                 push    edi
  4. .text:0049665B                 push    ebp
  5. .text:0049665C                 add     esp, 0FFFFF004h
  6. .text:00496662                 mov     ebp, offset alldll ; "*.dll"
  7. .text:00496667                 push    eax
  8. .text:00496668                 add     esp, 0FFFFFBB0h
  9. .text:0049666E                 push    4B00h           ; n
  10. .text:00496673                 push    0               ; c
  11. .text:00496675                 push    offset unk_4F0AB4 ; s
  12. .text:0049667A                 call    _memset
  13. .text:0049667F                 xor     eax, eax
  14. .text:00496681                 add     esp, 0Ch
  15. .text:00496684                 mov     dword_4F55B4, eax
  16. .text:00496689                 xor     eax, eax
  17. .text:0049668B                 or      ecx, 0FFFFFFFFh
  18. .text:0049668E                 mov     edi, offset aCUsersLichaoDe ; "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
  19. .text:00496693                 repne scasb
  20. .text:00496695                 not     ecx
  21. .text:00496697                 sub     edi, ecx
  22. .text:00496699                 lea     esi, [esp+1460h+pluginpath]
  23. .text:004966A0                 xchg    esi, edi
  24. .text:004966A2                 mov     edx, ecx
  25. .text:004966A4                 mov     eax, edi
  26. .text:004966A6                 shr     ecx, 2
  27. .text:004966A9                 lea     eax, [esp+1460h+pluginpath]
  28. .text:004966B0                 rep movsd
  29. .text:004966B2                 mov     ecx, edx
  30. .text:004966B4                 and     ecx, 3
  31. .text:004966B7                 rep movsb
  32. .text:004966B9                 push    eax             ; s
  33. .text:004966BA                 call    _strlen
  34. .text:004966BF                 pop     ecx
  35. .text:004966C0                 mov     edi, eax
  36. .text:004966C2                 test    edi, edi
  37. .text:004966C4                 jle     short loc_4966DD
  38. .text:004966C6                 xor     eax, eax
  39. .text:004966C8                 mov     al, [esp+edi+1460h+var_355]
  40. .text:004966CF                 cmp     eax, 5Ch
  41. .text:004966D2                 jz      short loc_4966DD
  42. .text:004966D4                 mov     [esp+edi+1460h+pluginpath], 5Ch
  43. .text:004966DC                 inc     edi
  44. .text:004966DD
  45. .text:004966DD loc_4966DD:                             ; CODE XREF: LoadPlugins+6C j
  46. .text:004966DD                                         ; LoadPlugins+7A j
  47. .text:004966DD                 lea     edx, [esp+1460h+pluginpath]
  48. .text:004966E4                 mov     esi, ebp
  49. .text:004966E6                 add     edi, edx
  50. .text:004966E8                 push    edi
  51. .text:004966E9                 mov     eax, edi
  52. .text:004966EB                 movsd
  53. .text:004966EC                 movsw
  54. .text:004966EE                 pop     edi
  55. .text:004966EF                 lea     edx, [esp+1460h+FindFileData]
  56. .text:004966F6                 push    edx             ; lpFindFileData
  57. .text:004966F7                 lea     ecx, [esp+1464h+pluginpath]
  58. .text:004966FE                 push    ecx             ; lpFileName
  59. .text:004966FF                 call    FindFirstFileA
  60. .text:00496704                 mov     [esp+1460h+hFindFile], eax
  61. .text:00496708                 cmp     [esp+1460h+hFindFile], 0FFFFFFFFh
  62. .text:0049670D                 jnz     short loc_496716
  63. .text:0049670F                 xor     eax, eax
  64. .text:00496711                 jmp     loc_496B40
  65. .text:00496716 ; ---------------------------------------------------------------------------
  66. .text:00496716
  67. .text:00496716 loc_496716:                             ; CODE XREF: LoadPlugins+B5 j
  68. .text:00496716                 call    CreateMenu
  69. .text:0049671B                 mov     [esp+1460h+uIDNewItem], eax
  70. .text:0049671F                 cmp     [esp+1460h+uIDNewItem], 0
  71. .text:00496724                 jnz     short loc_49672D
  72. .text:00496726                 xor     eax, eax
  73. .text:00496728                 jmp     loc_496B40
  74. .text:0049672D ; ---------------------------------------------------------------------------
  75. .text:0049672D
  76. .text:0049672D loc_49672D:                             ; CODE XREF: LoadPlugins+CC j
  77. .text:0049672D                                         ; LoadPlugins+499 j
  78. .text:0049672D                 xor     esi, esi
  79. .text:0049672F                 push    0
  80. .text:00496731                 lea     eax, [esp+1464h+arglist]
  81. .text:00496738                 push    eax
  82. .text:00496739                 push    0
  83. .text:0049673B                 push    0
  84. .text:0049673D                 lea     edx, [esp+1470h+FindFileData.cFileName]
  85. .text:00496744                 push    edx
  86. .text:00496745                 call    j___fnsplit
  87. .text:0049674A                 add     esp, 14h
  88. .text:0049674D                 lea     ecx, [ebp+6]
  89. .text:00496750                 push    ecx             ; s2
  90. .text:00496751                 lea     eax, [esp+1464h+arglist]
  91. .text:00496758                 push    eax             ; s1
  92. .text:00496759                 call    _stricmp
  93. .text:0049675E                 add     esp, 8
  94. .text:00496761                 test    eax, eax
  95. .text:00496763                 jz      loc_496AD3
  96. .text:00496769                 lea     edx, [ebp+0Ch]
  97. .text:0049676C                 push    edx             ; s2
  98. .text:0049676D                 lea     ecx, [esp+1464h+arglist]
  99. .text:00496774                 push    ecx             ; s1
  100. .text:00496775                 call    _stricmp
  101. .text:0049677A                 add     esp, 8
  102. .text:0049677D                 test    eax, eax
  103. .text:0049677F                 jz      loc_496AD3
  104. .text:00496785                 xor     eax, eax
  105. .text:00496787                 or      ecx, 0FFFFFFFFh
  106. .text:0049678A                 mov     edi, offset aCUsersLichaoDe ; "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
  107. .text:0049678F                 lea     esi, [esp+1460h+pluginpath]
  108. .text:00496796                 repne scasb
  109. .text:00496798                 not     ecx
  110. .text:0049679A                 sub     edi, ecx
  111. .text:0049679C                 mov     edx, ecx
  112. .text:0049679E                 xchg    esi, edi
  113. .text:004967A0                 shr     ecx, 2
  114. .text:004967A3                 mov     eax, edi
  115. .text:004967A5                 rep movsd
  116. .text:004967A7                 mov     ecx, edx
  117. .text:004967A9                 lea     eax, [esp+1460h+pluginpath]
  118. .text:004967B0                 and     ecx, 3
  119. .text:004967B3                 rep movsb
  120. .text:004967B5                 push    eax             ; s
  121. .text:004967B6                 call    _strlen
  122. .text:004967BB                 pop     ecx
  123. .text:004967BC                 mov     edi, eax
  124. .text:004967BE                 test    edi, edi
  125. .text:004967C0                 jle     short loc_4967D9
  126. .text:004967C2                 xor     eax, eax
  127. .text:004967C4                 mov     al, [esp+edi+1460h+var_355]
  128. .text:004967CB                 cmp     eax, 5Ch
  129. .text:004967CE                 jz      short loc_4967D9
  130. .text:004967D0                 mov     [esp+edi+1460h+pluginpath], 5Ch
  131. .text:004967D8                 inc     edi
  132. .text:004967D9
  133. .text:004967D9 loc_4967D9:                             ; CODE XREF: LoadPlugins+168 j
  134. .text:004967D9                                         ; LoadPlugins+176 j
  135. .text:004967D9                 lea     edx, [esp+1460h+pluginpath]
  136. .text:004967E0                 xor     eax, eax
  137. .text:004967E2                 add     edi, edx
  138. .text:004967E4                 or      ecx, 0FFFFFFFFh
  139. .text:004967E7                 push    edi
  140. .text:004967E8                 mov     esi, edi
  141. .text:004967EA                 lea     edi, [esp+1464h+FindFileData.cFileName]
  142. .text:004967F1                 repne scasb
  143. .text:004967F3                 not     ecx
  144. .text:004967F5                 sub     edi, ecx
  145. .text:004967F7                 mov     edx, ecx
  146. .text:004967F9                 xchg    esi, edi
  147. .text:004967FB                 shr     ecx, 2
  148. .text:004967FE                 mov     eax, edi
  149. .text:00496800                 rep movsd
  150. .text:00496802                 mov     ecx, edx
  151. .text:00496804                 and     ecx, 3
  152. .text:00496807                 rep movsb
  153. .text:00496809                 pop     edi
  154. .text:0049680A                 lea     eax, [esp+1460h+pluginpath]
  155. .text:00496811                 push    eax             ; lpLibFileName
  156. .text:00496812                 call    LoadLibraryA
  157. .text:00496817                 mov     esi, eax
  158. .text:00496819                 test    esi, esi
  159. .text:0049681B                 jz      loc_496AD3
  160. .text:00496821                 lea     eax, [ebp+14h]
  161. .text:00496824                 push    eax             ; lpProcName
  162. .text:00496825                 push    esi             ; hModule
  163. .text:00496826                 call    GetProcAddress
  164. .text:0049682B                 mov     ebx, eax
  165. .text:0049682D                 lea     eax, [ebp+25h]
  166. .text:00496830                 push    eax             ; lpProcName
  167. .text:00496831                 push    esi             ; hModule
  168. .text:00496832                 call    GetProcAddress
  169. .text:00496837                 mov     edi, eax
  170. .text:00496839                 test    ebx, ebx
  171. .text:0049683B                 jz      loc_496AD3
  172. .text:00496841                 test    edi, edi
  173. .text:00496843                 jz      loc_496AD3
  174. .text:00496849                 mov     [esp+1460h+src], 0
  175. .text:0049684E                 lea     eax, [esp+1460h+src]
  176. .text:00496852                 push    eax
  177. .text:00496853                 call    ebx
  178. .text:00496855                 pop     ecx
  179. .text:00496856                 mov     ecx, eax
  180. .text:00496858                 cmp     ecx, 6Ah
  181. .text:0049685B                 jl      short loc_496869
  182. .text:0049685D                 cmp     ecx, 6Eh
  183. .text:00496860                 jg      short loc_496869
  184. .text:00496862                 cmp     [esp+1460h+src], 0
  185. .text:00496867                 jnz     short loc_49689C
  186. .text:00496869
  187. .text:00496869 loc_496869:                             ; CODE XREF: LoadPlugins+203 j
  188. .text:00496869                                         ; LoadPlugins+208 j
  189. .text:00496869                 mov     eax, ecx
  190. .text:0049686B                 mov     ebx, 64h
  191. .text:00496870                 cdq
  192. .text:00496871                 idiv    ebx
  193. .text:00496873                 push    edx
  194. .text:00496874                 mov     eax, ecx
  195. .text:00496876                 mov     ecx, 64h
  196. .text:0049687B                 cdq
  197. .text:0049687C                 idiv    ecx
  198. .text:0049687E                 push    eax
  199. .text:0049687F                 lea     eax, [esp+1468h+arglist]
  200. .text:00496886                 push    eax             ; arglist
  201. .text:00496887                 lea     edx, [ebp+36h]
  202. .text:0049688A                 push    edx             ; format
  203. .text:0049688B                 push    0               ; highlight
  204. .text:0049688D                 push    0               ; addr
  205. .text:0049688F                 call    _Addtolist
  206. .text:00496894                 add     esp, 18h
  207. .text:00496897                 jmp     loc_496AD3
  208. .text:0049689C ; ---------------------------------------------------------------------------
  209. .text:0049689C
  210. .text:0049689C loc_49689C:                             ; CODE XREF: LoadPlugins+20F j
  211. .text:0049689C                 mov     ebx, dword_4F55B4
  212. .text:004968A2                 shl     ebx, 3
  213. .text:004968A5                 lea     ebx, [ebx+ebx*2]
  214. .text:004968A8                 lea     ebx, [ebx+ebx*4]
  215. .text:004968AB                 lea     ebx, [ebx+ebx*4]
  216. .text:004968AE                 add     ebx, offset unk_4F0AB4
  217. .text:004968B4                 mov     [ebx], esi
  218. .text:004968B6                 lea     eax, [ebx+4]
  219. .text:004968B9                 push    esi
  220. .text:004968BA                 mov     esi, eax
  221. .text:004968BC                 push    edi
  222. .text:004968BD                 xor     eax, eax
  223. .text:004968BF                 lea     edi, [esp+1468h+FindFileData.cFileName]
  224. .text:004968C6                 or      ecx, 0FFFFFFFFh
  225. .text:004968C9                 repne scasb
  226. .text:004968CB                 not     ecx
  227. .text:004968CD                 sub     edi, ecx
  228. .text:004968CF                 mov     edx, ecx
  229. .text:004968D1                 xchg    esi, edi
  230. .text:004968D3                 shr     ecx, 2
  231. .text:004968D6                 mov     eax, edi
  232. .text:004968D8                 rep movsd
  233. .text:004968DA                 mov     ecx, edx
  234. .text:004968DC                 lea     edx, [ebx+108h]
  235. .text:004968E2                 and     ecx, 3
  236. .text:004968E5                 rep movsb
  237. .text:004968E7                 pop     edi
  238. .text:004968E8                 pop     esi
  239. .text:004968E9                 push    1Fh             ; maxlen
  240. .text:004968EB                 lea     eax, [esp+1464h+src]
  241. .text:004968EF                 push    eax             ; src
  242. .text:004968F0                 push    edx             ; dest
  243. .text:004968F1                 call    _strncpy
  244. .text:004968F6                 add     esp, 0Ch
  245. .text:004968F9                 lea     ecx, [ebp+60h]
  246. .text:004968FC                 mov     byte ptr [ebx+127h], 0
  247. .text:00496903                 push    ecx             ; lpProcName
  248. .text:00496904                 push    esi             ; hModule
  249. .text:00496905                 call    GetProcAddress
  250. .text:0049690A                 mov     [ebx+238h], eax
  251. .text:00496910                 lea     eax, [ebp+73h]
  252. .text:00496913                 push    eax             ; lpProcName
  253. .text:00496914                 push    esi             ; hModule
  254. .text:00496915                 call    GetProcAddress
  255. .text:0049691A                 mov     [ebx+230h], eax
  256. .text:00496920                 lea     edx, [ebp+88h]
  257. .text:00496926                 push    edx             ; lpProcName
  258. .text:00496927                 push    esi             ; hModule
  259. .text:00496928                 call    GetProcAddress
  260. .text:0049692D                 mov     [ebx+234h], eax
  261. .text:00496933                 lea     ecx, [ebp+99h]
  262. .text:00496939                 push    ecx             ; lpProcName
  263. .text:0049693A                 push    esi             ; hModule
  264. .text:0049693B                 call    GetProcAddress
  265. .text:00496940                 mov     [ebx+23Ch], eax
  266. .text:00496946                 lea     eax, [ebp+0AEh]
  267. .text:0049694C                 push    eax             ; lpProcName
  268. .text:0049694D                 push    esi             ; hModule
  269. .text:0049694E                 call    GetProcAddress
  270. .text:00496953                 mov     [ebx+240h], eax
  271. .text:00496959                 lea     edx, [ebp+0C2h]
  272. .text:0049695F                 push    edx             ; lpProcName
  273. .text:00496960                 push    esi             ; hModule
  274. .text:00496961                 call    GetProcAddress
  275. .text:00496966                 mov     [ebx+244h], eax
  276. .text:0049696C                 lea     ecx, [ebp+0D8h]
  277. .text:00496972                 push    ecx             ; lpProcName
  278. .text:00496973                 push    esi             ; hModule
  279. .text:00496974                 call    GetProcAddress
  280. .text:00496979                 mov     [ebx+248h], eax
  281. .text:0049697F                 lea     eax, [ebp+0EAh]
  282. .text:00496985                 push    eax             ; lpProcName
  283. .text:00496986                 push    esi             ; hModule
  284. .text:00496987                 call    GetProcAddress
  285. .text:0049698C                 mov     [ebx+24Ch], eax
  286. .text:00496992                 lea     edx, [ebp+0F7h]
  287. .text:00496998                 push    edx             ; lpProcName
  288. .text:00496999                 push    esi             ; hModule
  289. .text:0049699A                 call    GetProcAddress
  290. .text:0049699F                 mov     [ebx+250h], eax
  291. .text:004969A5                 lea     ecx, [ebp+106h]
  292. .text:004969AB                 push    ecx             ; lpProcName
  293. .text:004969AC                 push    esi             ; hModule
  294. .text:004969AD                 call    GetProcAddress
  295. .text:004969B2                 mov     [ebx+254h], eax
  296. .text:004969B8                 xor     eax, eax
  297. .text:004969BA                 mov     [esp+1460h+var_1460], eax
  298. .text:004969BD                 push    esp
  299. .text:004969BE                 mov     edx, hwmain
  300. .text:004969C4                 push    edx
  301. .text:004969C5                 push    6Eh
  302. .text:004969C7                 call    edi
  303. .text:004969C9                 add     esp, 0Ch
  304. .text:004969CC                 mov     edi, eax
  305. .text:004969CE                 test    edi, edi
  306. .text:004969D0                 jz      short loc_4969F3
  307. .text:004969D2                 push    edi
  308. .text:004969D3                 lea     ecx, [esp+1464h+arglist]
  309. .text:004969DA                 push    ecx             ; arglist
  310. .text:004969DB                 lea     eax, [ebp+116h]
  311. .text:004969E1                 push    eax             ; format
  312. .text:004969E2                 push    0               ; highlight
  313. .text:004969E4                 push    0               ; addr
  314. .text:004969E6                 call    _Addtolist
  315. .text:004969EB                 add     esp, 14h
  316. .text:004969EE                 jmp     loc_496AD3
  317. .text:004969F3 ; ---------------------------------------------------------------------------
  318. .text:004969F3
  319. .text:004969F3 loc_4969F3:                             ; CODE XREF: LoadPlugins+378 j
  320. .text:004969F3                 mov     esi, dword_4F55B4
  321. .text:004969F9                 shl     esi, 6
  322. .text:004969FC                 add     esi, 0E000h
  323. .text:00496A02                 mov     [esp+1460h+src], 0
  324. .text:00496A07                 cmp     dword ptr [ebx+234h], 0
  325. .text:00496A0E                 jz      short loc_496A2D
  326. .text:00496A10                 push    0
  327. .text:00496A12                 lea     eax, [esp+1464h+src]
  328. .text:00496A16                 push    eax
  329. .text:00496A17                 push    0
  330. .text:00496A19                 call    dword ptr [ebx+234h]
  331. .text:00496A1F                 add     esp, 0Ch
  332. .text:00496A22                 test    eax, eax
  333. .text:00496A24                 jz      short loc_496A2D
  334. .text:00496A26                 cmp     [esp+1460h+src], 0
  335. .text:00496A2B                 jnz     short loc_496A31
  336. .text:00496A2D
  337. .text:00496A2D loc_496A2D:                             ; CODE XREF: LoadPlugins+3B6 j
  338. .text:00496A2D                                         ; LoadPlugins+3CC j
  339. .text:00496A2D                 xor     edi, edi
  340. .text:00496A2F                 jmp     short loc_496A38
  341. .text:00496A31 ; ---------------------------------------------------------------------------
  342. .text:00496A31
  343. .text:00496A31 loc_496A31:                             ; CODE XREF: LoadPlugins+3D3 j
  344. .text:00496A31                 call    CreateMenu
  345. .text:00496A36                 mov     edi, eax
  346. .text:00496A38
  347. .text:00496A38 loc_496A38:                             ; CODE XREF: LoadPlugins+3D7 j
  348. .text:00496A38                 test    edi, edi
  349. .text:00496A3A                 jz      short loc_496A52
  350. .text:00496A3C                 lea     eax, [esp+1460h+src]
  351. .text:00496A40                 mov     dword_4F55BC, eax
  352. .text:00496A45                 push    1               ; int
  353. .text:00496A47                 push    esi             ; int
  354. .text:00496A48                 push    ebx             ; int
  355. .text:00496A49                 push    edi             ; hMenu
  356. .text:00496A4A                 call    sub_496260
  357. .text:00496A4F                 add     esp, 10h
  358. .text:00496A52
  359. .text:00496A52 loc_496A52:                             ; CODE XREF: LoadPlugins+3E2 j
  360. .text:00496A52                 mov     ecx, dword_4F55B4
  361. .text:00496A58                 cmp     ecx, 0Ah
  362. .text:00496A5B                 jge     short loc_496A86
  363. .text:00496A5D                 add     ebx, 108h
  364. .text:00496A63                 push    ebx
  365. .text:00496A64                 mov     eax, ecx
  366. .text:00496A66                 inc     eax
  367. .text:00496A67                 mov     ecx, 0Ah
  368. .text:00496A6C                 cdq
  369. .text:00496A6D                 idiv    ecx
  370. .text:00496A6F                 push    edx
  371. .text:00496A70                 lea     eax, [ebp+141h]
  372. .text:00496A76                 push    eax             ; format
  373. .text:00496A77                 lea     edx, [esp+146Ch+src]
  374. .text:00496A7B                 push    edx             ; buffer
  375. .text:00496A7C                 call    _sprintf
  376. .text:00496A81                 add     esp, 10h
  377. .text:00496A84                 jmp     short loc_496AA1
  378. .text:00496A86 ; ---------------------------------------------------------------------------
  379. .text:00496A86
  380. .text:00496A86 loc_496A86:                             ; CODE XREF: LoadPlugins+403 j
  381. .text:00496A86                 add     ebx, 108h
  382. .text:00496A8C                 push    ebx
  383. .text:00496A8D                 lea     eax, [ebp+145h]
  384. .text:00496A93                 push    eax             ; format
  385. .text:00496A94                 lea     edx, [esp+1468h+src]
  386. .text:00496A98                 push    edx             ; buffer
  387. .text:00496A99                 call    _sprintf
  388. .text:00496A9E                 add     esp, 0Ch
  389. .text:00496AA1
  390. .text:00496AA1 loc_496AA1:                             ; CODE XREF: LoadPlugins+42C j
  391. .text:00496AA1                 test    edi, edi
  392. .text:00496AA3                 jnz     short loc_496AB9
  393. .text:00496AA5                 lea     ecx, [esp+1460h+src]
  394. .text:00496AA9                 push    ecx             ; lpNewItem
  395. .text:00496AAA                 push    esi             ; uIDNewItem
  396. .text:00496AAB                 push    0               ; uFlags
  397. .text:00496AAD                 mov     eax, [esp+146Ch+uIDNewItem]
  398. .text:00496AB1                 push    eax             ; hMenu
  399. .text:00496AB2                 call    AppendMenuA
  400. .text:00496AB7                 jmp     short loc_496ACB
  401. .text:00496AB9 ; ---------------------------------------------------------------------------
  402. .text:00496AB9
  403. .text:00496AB9 loc_496AB9:                             ; CODE XREF: LoadPlugins+44B j
  404. .text:00496AB9                 lea     edx, [esp+1460h+src]
  405. .text:00496ABD                 push    edx             ; lpNewItem
  406. .text:00496ABE                 push    edi             ; uIDNewItem
  407. .text:00496ABF                 push    10h             ; uFlags
  408. .text:00496AC1                 mov     ecx, [esp+146Ch+uIDNewItem]
  409. .text:00496AC5                 push    ecx             ; hMenu
  410. .text:00496AC6                 call    AppendMenuA
  411. .text:00496ACB
  412. .text:00496ACB loc_496ACB:                             ; CODE XREF: LoadPlugins+45F j
  413. .text:00496ACB                 inc     dword_4F55B4
  414. .text:00496AD1                 xor     esi, esi
  415. .text:00496AD3
  416. .text:00496AD3 loc_496AD3:                             ; CODE XREF: LoadPlugins+10B j
  417. .text:00496AD3                                         ; LoadPlugins+127 j ...
  418. .text:00496AD3                 test    esi, esi
  419. .text:00496AD5                 jz      short loc_496ADD
  420. .text:00496AD7                 push    esi             ; hLibModule
  421. .text:00496AD8                 call    FreeLibrary
  422. .text:00496ADD
  423. .text:00496ADD loc_496ADD:                             ; CODE XREF: LoadPlugins+47D j
  424. .text:00496ADD                 lea     eax, [esp+1460h+FindFileData]
  425. .text:00496AE4                 push    eax             ; lpFindFileData
  426. .text:00496AE5                 mov     edx, [esp+1464h+hFindFile]
  427. .text:00496AE9                 push    edx             ; hFindFile
  428. .text:00496AEA                 call    FindNextFileA
  429. .text:00496AEF                 test    eax, eax
  430. .text:00496AF1                 jnz     loc_49672D
  431. .text:00496AF7                 cmp     dword_4F55B4, 0
  432. .text:00496AFE                 jle     short loc_496B31
  433. .text:00496B00                 lea     ecx, [ebp+148h]
  434. .text:00496B06                 push    ecx             ; lpNewItem
  435. .text:00496B07                 mov     eax, [esp+1464h+uIDNewItem]
  436. .text:00496B0B                 push    eax             ; uIDNewItem
  437. .text:00496B0C                 push    410h            ; uFlags
  438. .text:00496B11                 push    3               ; uPosition
  439. .text:00496B13                 mov     edx, hwmain
  440. .text:00496B19                 push    edx             ; hWnd
  441. .text:00496B1A                 call    GetMenu
  442. .text:00496B1F                 push    eax             ; hMenu
  443. .text:00496B20                 call    InsertMenuA
  444. .text:00496B25                 mov     ecx, hwmain
  445. .text:00496B2B                 push    ecx             ; hWnd
  446. .text:00496B2C                 call    DrawMenuBar
  447. .text:00496B31
  448. .text:00496B31 loc_496B31:                             ; CODE XREF: LoadPlugins+4A6 j
  449. .text:00496B31                 mov     eax, [esp+1460h+hFindFile]
  450. .text:00496B35                 push    eax             ; hFindFile
  451. .text:00496B36                 call    FindClose
  452. .text:00496B3B                 mov     eax, dword_4F55B4
  453. .text:00496B40
  454. .text:00496B40 loc_496B40:                             ; CODE XREF: LoadPlugins+B9 j
  455. .text:00496B40                                         ; LoadPlugins+D0 j
  456. .text:00496B40                 add     esp, 1450h
  457. .text:00496B46                 pop     ebp
  458. .text:00496B47                 pop     edi
  459. .text:00496B48                 pop     esi
  460. .text:00496B49                 pop     ebx
  461. .text:00496B4A                 retn
复制代码


经过分析得到:
  1. #include <windows.h>
  2. #include <dos.h>
  3. #include "plugin.h"

  4. struct PluginData
  5. {
  6.         HMODULE hPluginDll;
  7.         char        DllName[260];
  8.         char PluginName[32];
  9. //+296
  10.         ???
  11. //+560
  12.         ODBG_Pluginmainloop;
  13.         ODBG_Pluginmenu;
  14.         ODBG_Pluginaction;
  15.         ODBG_Pluginshortcut;
  16.         ODBG_Pluginsaveudd;
  17.         ODBG_Pluginuddrecord;
  18.         ODBG_Pluginreset;
  19.         ODBG_Paused;
  20.         ODBG_Pausedex;
  21.         ODBG_Plugincmd;
  22. };

  23. int pluginnum;
  24. PluginData plugindata[32];//最多32个插件
  25. char data[0x1100];
  26. HANDLE hwmain;

  27. bool LoadPlugins()
  28. {
  29.         char pluginpath[260],filename[256],pluginname[32];
  30.         HANDLE hFindFile;
  31.         WIN32_FIND_DATA FindFileData;
  32.         HMENU pluginmenu,popupmenu;
  33.         HMODULE hmod;
  34.         int ret;
  35.         int pluginmenuid;

  36.         memset(plugindata,sizeof(plugindata));
  37.         pluginnum=0;
  38.         strcpy(pluginpath,"*.dll");
  39.         hFindFile=FindFirstFile(pluginpath,&FindFileData);
  40.         if(hFindFile == INVALID_HANDLE_VALUE)
  41.                 return false;
  42.         pluginmenu=CreateMenu();
  43.         if(!pluginmenu)
  44.                 return false;
  45.         do
  46.         {//搜索根目录下所有dll文件
  47.                 hmod=NULL;
  48.                 fnsplit(FindFileData.cFileName,NULL,NULL,filename,NULL);
  49.                 if(stricmp(filename,"psapi") && stricmp(filename,"dbghelp"))
  50.                 {//如果不是psapi.dll和dbghelp.dll
  51.                         strcpy(pluginpath,FindFileData.cFileName);
  52.                         hmod=LoadLibrary(pluginpath);
  53.                         if(hmod)
  54.                         {
  55.                                 ODBG_Plugindata=GetProcAddress(hmod,"_ODBG_Plugindata");
  56.                                 ODBG_Plugininit=GetProcAddress(hmod,"_ODBG_Plugininit");
  57.                                 if(ODBG_Plugindata && ODBG_Plugininit)
  58.                                 {
  59.                                         pluginname[0]='\0';
  60.                                         ret=ODBG_Plugindata(pluginname);
  61.                                         if(ret >= 106 && ret <= 110 && pluginname[0] != '\0')//版本在1.06~1.10之间
  62.                                         {
  63.                                                 PluginData& curplugin=plugindata[pluginnum];
  64.                                                 curplugin.hPluginDll=hmod;
  65.                                                 strcpy(curplugin.DllName,FindFileData.cFileName);
  66.                                                 strncpy(curplugin.PluginName,pluginname,31);
  67.                                                 curplugin.PluginName[31]='\0';
  68.                                                 curplugin.ODBG_Pluginaction=GetProcAddress(hmod,"ODBG_Pluginaction");
  69.                                                 curplugin.ODBG_Pluginmainloop=GetProcAddress(hmod,"ODBG_Pluginmainloop");
  70.                                                 curplugin.ODBG_Pluginmenu=GetProcAddress(hmod,"ODBG_Pluginmenu");
  71.                                                 curplugin.ODBG_Pluginshortcut=GetProcAddress(hmod,"ODBG_Pluginshortcut");
  72.                                                 curplugin.ODBG_Pluginsaveudd=GetProcAddress(hmod,"ODBG_Pluginsaveudd");
  73.                                                 curplugin.ODBG_Pluginuddrecord=GetProcAddress(hmod,"ODBG_Pluginuddrecord");
  74.                                                 curplugin.ODBG_Pluginreset=GetProcAddress(hmod,"ODBG_Pluginreset");
  75.                                                 curplugin.ODBG_Paused=GetProcAddress(hmod,"ODBG_Paused");
  76.                                                 curplugin.ODBG_Pausedex=GetProcAddress(hmod,"ODBG_Pausedex");
  77.                                                 curplugin.ODBG_Plugincmd=GetProcAddress(hmod,"ODBG_Plugincmd");
  78.                                                 ulong feature=0;
  79.                                                 ret=ODBG_Plugininit(110,hwmain,&feature);
  80.                                                 if(ret)
  81.                                                 {
  82.                                                         Addtolist(0,0,"Plugin '%s' failed to initialize (code %i)",filename,ret);
  83.                                                 }
  84.                                                 else
  85.                                                 {
  86.                                                         pluginmenuid=pluginnum*32+57344;
  87.                                                         pluginname[0]='\0';
  88.                                                         if(curplugin.ODBG_Pluginmenu) && curplugin.ODBG_Pluginmenu(PM_MAIN,data,NULL))
  89.                                                         {
  90.                                                                 if(pluginname[0] != '\0' && (popupmenu=CreateMenu()) != NULL)
  91.                                                                 {
  92.                                                                         CreateSubMenu(popupmenu,curplugin,pluginmenuid,1);
  93.                                                                 }
  94.                                                                 if(pluginnum >= 10)
  95.                                                                         sprintf(pluginname,"%s",curplugin.pluginname);
  96.                                                                 else
  97.                                                                         sprintf(pluginname,"&%i %s",(pluginnum+1)%10,curplugin.pluginname);
  98.                                                                 if(popupmenu)
  99.                                                                         AppendMenu(pluginmenuid,MF_POPUP,popupmenu,pluginname);
  100.                                                                 else
  101.                                                                         AppendMenu(pluginmenuid,0,pluginmenuid,pluginname);
  102.                                                                 pluginnum++;
  103.                                                                 hmod=NULL;
  104.                                                         }
  105.                                                 }
  106.                                         }
  107.                                         else
  108.                                         {
  109.                                                 Addtolist(0,0,"Plugin '%s' has invalid version (%i.%02i)",filename,ret/100,ret%100);
  110.                                         }
  111.                                 }
  112.                         }
  113.                 }
  114.                 if(hmod)
  115.                         FreeLibrary(hmod);
  116.         }
  117.         while(FindNextFile(hFindFile,&FindFileData));
  118. }
复制代码


仅此一个函数就可以看到编码习惯的不足之处:
可见加载过程是:ODBG_Plugindata => ODBG_Plugininit => ODBG_Pluginmenu,同理可分析其它函数。
同时,可以发现OllyDbg作者代码的缺点所在,或许高手不太重视细节,呵呵
1.重要数据类型应该使用优秀的数据结构进行存储,恰巧是对内存的不善利用,造成OllyDbg所占内存较大,同时因此只能允许有限个插件加载
2.使用的函数和数组导致可能存在内存溢出的情况发生
3.滥用全局变量,如代码中的PluginData
4.代码通用性不好,其api不提供unicode版
5.函数设计混乱,返回值不够规范(比如都是int返回值有的函数正确返回1,错误返回0,而有的函数相反)
6.由于上述原因、各种其他原因和考虑不全面,导致各种奇妙bug横行,想必作者修改bug花了很长时间
7.源码和输出函数不兼容VS系列编译器,需要手动改动,这一点在OllyDbg2中有所改观,然而进行了2重输出,弄巧成拙
回复

使用道具 举报

1112

主题

1653

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
245
威望
744 点
宅币
24261 个
贡献
46222 次
宅之契约
0 份
在线时间
2298 小时
注册时间
2014-1-26
发表于 2015-1-5 07:59:56 | 显示全部楼层
额!话说Unicode版……的API,如果作者提供的话BUG恐怕更多。
回复 赞! 靠!

使用道具 举报

55

主题

275

回帖

9356

积分

用户组: 管理员

UID
77
精华
16
威望
237 点
宅币
8221 个
贡献
251 次
宅之契约
0 份
在线时间
255 小时
注册时间
2014-2-22
发表于 2015-1-5 14:35:30 | 显示全部楼层
原来插件是这么实现的,我觉得支持第三方插件的软件,都是很牛逼的。。。
回复 赞! 靠!

使用道具 举报

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

GMT+8, 2024-4-29 17:30 , Processed in 0.044150 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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