我试图找出一种方法来自动解密由函数多次调用的二进制文件中的某些字符串。
该函数接受三个参数,是一个简单的异或解密。但是,它为要解密的每个唯一字符串使用不同的密钥。
char* decrypt(char* string_to_decrypt, uint string_len, char xor_byte)
我试图做的是获取这个函数的外部参照列表(这是我得到的)并读入它想要在二进制文件中解密的当前字符串,并获取 xor 密钥和长度,然后修补binary 显示明文字符串。
该函数是这样调用的
.text:0040168A push 83h
.text:0040168F push 9
.text:00401691 mov eax, esi
.text:00401693 mov edx, offset unk_406D58
.text:00401698 call decrypt_string
其中EDX,始终持有加密字符串的地址,两次push是key和length(9个长度,0x83个key)
mov eax, esi 并不总是存在。有没有办法读取反汇编并获取此函数,然后动态解密数据库中的所有字符串?
为了完整起见,这就是我开始的地方。
import idaapi
import idc
ea = here()
print hex(ea)
xrefs = CodeRefsTo(ea,0)
for xref in xrefs:
print "Ref Addr: {}".format(hex(xref))
# for all xrefs, get string offset, length and key,
# decrypt that string, and patch or rename it to display decrypted string)
谢谢你。
编辑:ws 响应让我朝着正确的方向前进。这是我想出的。这很粗糙,我知道:)
import idaapi
import idc
import idautils
ea = here()
xrefs = CodeRefsTo(ea,0)
data = []
decrypted = []
for xref in xrefs:
current_x = xref
d = {}
d['addr'] = hex(current_x)
n_pushes = 0
n_movedx = 0
for i in xrange(6):
if n_pushes == 2 and n_movedx == 1:
break
current_x = idc.PrevHead(current_x)
instr = idautils.DecodeInstruction(current_x)
if instr.itype == idaapi.NN_push:
if n_pushes < 1:
d['len'] = int(GetOperandValue(current_x, 0))
if n_pushes == 1:
d['key'] = int( hex(GetOperandValue(current_x, 0)), 16)
n_pushes += 1
if instr.itype == idaapi.NN_mov:
if GetOpnd(current_x, 0) == 'edx':
d['string_offset'] = GetOperandValue(current_x, 1)
data.append(d)
......