在网上搜到的最多的 IDA dump 内存的脚本是类似以下的idc代码:
static main(void)
{
auto fp, begin, end, dexbyte;
fp = fopen("/home/t/tmpkqk.so", "wb");
begin = 0xCD96F000;
end = begin + 0x2FB000;
for ( dexbyte = begin; dexbyte < end; dexbyte ++ )
fputc(Byte(dexbyte), fp);
}
这里将对应idc的脚本代码改成idapython脚本,如下:
import idc
def main():
begin = 0xCD956000; #需对应修改
size = 0x2FB000 # #需对应修改
list = []
for i in range(size):
byte_tmp = idc.Byte(begin + i)
list.append(byte_tmp)
if (i + 1) % 0x1000 == 0:
print("All count:{}, collect current:{}, has finish {}".format(hex(size), hex(i + 1), float(i + 1) / size))
print('collect over')
file = "/home/t/tmpkqk13.so" #需对应修改
buf = bytearray(list)
with open(file, 'wb') as fw:
fw.write(buf)
print('write over')
if __name__=='__main__':
main()
这里Python代码也更好扩展一些。因为dump内存时,还是一样的慢,所以脚本中加入了处理进度显示,好心里有个底。