前言
本文样本案例来自 小红书 app shield so 加密算法分析破解还原
0x1
看了上面的文章后,相信你已经对样本有个大概的了解
这是 aes decrypt
函数,地址 0x4BCBC
,这里调用了很多 c
的函数,具体作用自行百度,坑还是很多的,后面我会直接贴上代码
0x2
使用 unidbg
在这里下个断点 0x4D1F4
这里是 r0 = -1732584194, r1 = 0x54e6482b = 1424377899
, r0 + r1
这是 so c
的运算结果,我们在来看看 python
的
b
是 r0
我这里写的反的,发现结果对不上
看下 so
这里的 类型是 int32
所以我们 pyhton
里也转一下看看
这下就对的上了,同样其他的运算也要转,有符号无符号的 int
细节很多,都要注意下
0x3
还原的过程还有很多其他坑,比如字节填充,字节反转
byte2_w = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[2:4], 16)
hi_byte = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[0:2], 16)
byte1 = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[0:2], 16)
byte2 = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[2:4], 16)
byte3 = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[4:6], 16)
byte4 = lambda x: int(hex(x).replace('0x', '').rjust(8, '0')[6:8], 16)
def reverse_hex(hex_str):
if '0x' not in str(hex_str):
hex_str = hex(hex_str)
hex_str = hex_str.replace('0x', '')
hex_str_list = []
for i in range(0, len(hex_str), 2):
hex_str_list.append(hex_str[i:i + 2])
hex_str_list.reverse()
hex_str_result = '0x' + ''.join(hex_str_list)
return hex_str_result
def hex_byte_pad(hex_data):
hex_list = []
if isinstance(hex_data, list):
for i in hex_data:
new_hex = GlobalData.reverse_hex('0x' + str(i.replace('0x', '').rjust(8, '0')))
hex_list.extend([new_hex[0:4], f'0x{new_hex[4:6]}', f'0x{new_hex[6:8]}', f'0x{new_hex[8:10]}'])
else:
return hex_list
if isinstance(hex_data, str):
new_hex = '0x' + str(hex_data.replace('0x', '').rjust(8, '0'))
return ''.join([new_hex[0:4], new_hex[4:6], new_hex[6:8], new_hex[8:10]])
:cry:
2021-12-16😥 😉 🙄 😛 🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 🙄 😆 😆 😆 😆
会爬山的小脑虎
2021-12-16@:cry: 😮 😮 😮 😮 😮