原帖标题:重建重定位表脚本
原帖作者:askformore
原帖时间:2004-10-18,15:04:22
原帖地址:http://bbs.pediy.com/showthread.php?t=5878
原帖补充:http://bbs.pediy.com/showthread.php?t=5915
推荐帖子:【原创】也谈PE重定位表
推荐帖子:罗老师的第十七章-PE文件之重定位表
参考帖子:【样章2】《加密与解密(第三版)》--13.5 DLL文件脱壳(重定位表修复部分)
askformore写的重定位脚本很不错,缺点就是太慢。
原脚本一秒钟只能写大约16个字节,如果重定位表的大小是0x0AB00,那需要多长时间能写完?
大约是2800秒!45分钟?!我晕@_@
今天我将那个脚本的核心部分写成汇编形式,如果能够熟练使用那个脚本的话,就可以使用下列汇编代码来代替脚本生成重定位表,运行只有一瞬间,大部分dll都可以瞬间搞定!
感受大自然的神奇吧,aladouleinou,他们的命运归你处置!
以下代码配合MUltimate Assembler v1.2 中文修正版使用
使用方法:
[color=#009000];功能:重建重定位表
;作者:sierra
;发布地点:看雪论坛( http://bbs.pediy.com/showthread.php?p=1063543 )
;发布时间:2012/04/13
;使用方法:
;1、运行到重定位处理语句
;2、打开内存窗口,右键Allocate Memory为代码分配内存(Olly Advanced插件的功能)
;3、右键Allocate Memory为重定位表缓存分配内存(如果人比较懒可以不分配这个,直接使用代码内存的0x100字节后面当做缓存)
;4、根据实际内存地址和实际重定位寄存器修改汇编代码
;5、运行MUltimate Assembler,粘贴代码,汇编
;6、做detour patch(要记得保存原先的代码),call到30000000(实际中需要根据你分配的内存地址修改)
;7、找一个合适的地方下断,使重定位表处理完成后会断下来(如果你像我一样熟练,就可以不下断,直接F4)
;8、F9(F4)运行,断下来之后在40000000(实际中需要根据你分配的内存地址修改)就会有完整的重定位表了,
; 查一下它的实际大小(其实p+已经指向了重定位表的结尾,减去基址都不用加一就直接是表格的大小了),
; 用LordPE保存区段,大小指定为重定位表的大小,再用PETools为dll添加刚刚保存的区段并修改重定位表地址和大小
;9、保存
[color=#009000];补丁开始地址
<0x30000000> [color=#009000]; 需要修改1/4 根据申请的代码补丁存放地址修改
[color=#0000D0]pushfd
[color=#0000D0]pushad
[color=#0000D0]push [color=#FF0000]edi [color=#009000]; 需要修改2/4 根据壳中的重定位处理语句中的寄存器修改
[color=#0000D0]push [color=#FF0000]eax [color=#009000]; 选择修改2/4 一般重定位处理语句最多只涉及三个寄存器
[color=#0000D0]push [color=#FF0000]ecx [color=#009000]; 选择修改2/4 如果只涉及到一个寄存器则这两个都不用改
[color=#b000b0]db 0x0e8
[color=#b000b0]dd 0 [color=#009000];call下一条语句
[color=#0000D0]pop [color=#FF0000]ebx [color=#009000];得到EIP
[color=#0000D0]add [color=#FF0000]ebx,6 [color=#009000];得到下面数据的基址
[color=#b000b0]db 0x0eb,0x18 [color=#009000];jmp short start
[color=#009000];[ebx+0x00]:; p+
[color=#b000b0]dd 0x40000000 [color=#009000]; 需要修改3/4 根据申请的重定位表存放地址修改
[color=#009000];[ebx+0x04]:; pVA
[color=#b000b0]dd 0x40000000 [color=#009000]; 需要修改3/4 与p+相同
[color=#009000];[ebx+0x08]:; pSOB
[color=#b000b0]dd 0
[color=#009000];[ebx+0x0c]:; nImageBase
[color=#b000b0]dd 0x00870000 [color=#009000]; 需要修改4/4 根据dll实际载入时的映像基址修改
[color=#009000];[ebx+0x10]:; nRVA
[color=#b000b0]dd 0
[color=#009000];[ebx+0x14]:; nReloc
[color=#b000b0]dd 0
[color=#009000];jmp 9c0f17
[color=#009000];call 30000020
[color=#009000];add dword ptr ds:[edi], eax
[color=#009000];jmp 9c0ee7
[color=#009000];===================以下代码可以根据具体需要修改====================
[color=#009000]; 如果要修改后面的代码,禁止使用和修改ebx,其它的寄存器随便
[color=#009000];start:
[color=#0000D0]pop [color=#FF0000]ecx
[color=#0000D0]pop [color=#FF0000]eax
[color=#0000D0]pop [color=#FF0000]edi
[color=#0000D0]mov [[color=#FF0000]ebx+0x14],[color=#FF0000]edi [color=#009000];前面pop之后可以添加一些运算,但最后重定位地址应保存到nReloc
[color=#009000];=========================以下代码不要修改==========================
[color=#009000];hRVA: ;处理VA
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x14]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],[color=#FF0000]eax [color=#009000];☆☆☆映像区块重定位指针地址,需手工设置,一般是寄存器,比如:upx壳是ebx☆☆☆
[color=#0000D0]and [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],0FFFFF000
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x0c]
[color=#0000D0]sub [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],[color=#FF0000]eax [color=#009000];计算pVA块RVA地址
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x04]
[color=#0000D0]mov [color=#FF0000]eax,[[color=#FF0000]eax]
[color=#0000D0]cmp [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],[color=#FF0000]eax [color=#009000];是否还是同一VA块
[color=#b000b0]db 0x74,0x37[color=#009000];je short hPoint
[color=#009000];sub1:
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#0000D0]and [color=#FF0000]al,0x0fc
[color=#0000D0]cmp [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#b000b0]db 0x74,0x0e[color=#009000];je short sub2
[color=#0000D0]mov [color=#FF0000]ecx,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#0000D0]mov [color=#b000b0]byte [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ecx],0 [color=#009000];这里就是 ASBSOULT 类型,已经被我sierra复杂化了!
[color=#0000D0]mov [color=#FF0000]ecx,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x08]
[color=#0000D0]inc [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ecx]
[color=#0000D0]inc [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#b000b0]db 0x0eb,0x0ea[color=#009000];jmp short sub1
[color=#009000];sub2:
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x04],[color=#FF0000]eax
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10]
[color=#0000D0]mov [color=#FF0000]ecx,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x04]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ecx],[color=#FF0000]eax
[color=#0000D0]add [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00],4 [color=#009000];修正移动指针
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x08],[color=#FF0000]eax
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x08]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]eax],8
[color=#0000D0]add [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00],4 [color=#009000];修正移动指针
[color=#b000b0]db 0x0eb,0x00[color=#009000];jmp short hPoint
[color=#009000];hPoint:;处理Point
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x14]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],[color=#FF0000]eax [color=#009000];☆☆☆放入Point地址
[color=#0000D0]and [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],0FFF [color=#009000];取低12位
[color=#0000D0]add [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10],3000 [color=#009000];定为:HIGLOW 类型,这里没有考虑设计 ASBSOULT 类型,俺觉得没必要复杂化!
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x10]
[color=#0000D0]mov [color=#FF0000]ecx,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00]
[color=#0000D0]mov [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ecx],[color=#FF0000]eax
[color=#0000D0]add [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x00],2 [color=#009000];修正移动指针
[color=#0000D0]mov [color=#FF0000]eax,[color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]ebx+0x08]
[color=#0000D0]add [color=#b000b0]dword [color=#b000b0]ptr [color=#FF0000]ds:[[color=#FF0000]eax],2 [color=#009000];实时修正SIZEOfBlock
[color=#0000D0]popad
[color=#0000D0]popfd
[color=#0000D0]ret
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)