我最近读了这篇文章Dalvik Bytecode Obfuscation on Android
我还在https://github.com/thuxnder/dalvik-obfuscator/blob/master/injector.py下载了源代码
我知道该技术的作用是遍历所有方法,在代码块中插入垃圾字节并在代码块前面无条件分支(以确保永远不会执行代码块)。
但是我不熟悉 Python 脚本,所以我很难理解从第 204 行到第 212 行的代码块,这会导致异常:
def _obfuscator_arrayDataOverlayIf(self, method):
obfuscator = array.array('c', "\x32\x00\x09\x00\x26\x00\x03\x00\x00\x00\x00\x03\x01\x00\x00\x00\x00\x00")
size = method.getMethodSize()
if size == 0:
print "skip method @ 0x%x" % method._offset
return
payloadlen = size-len(obfuscator)
struct.pack_into('I', obfuscator, 14, payloadlen)
return method.obfuscate(obfuscator)
如果有人能向我解释这段代码的作用,我将不胜感激,以便我能理解作者的想法。
编辑:追溯如下:
Traceback (most recent call last):
File "C:\Apps\EclipsePortable\Data\workspace\DalvikObfuscator\DalvikObfuscator\injector.py", line 216, in <module>
inj.obfuscate()
File "C:\Apps\EclipsePortable\Data\workspace\DalvikObfuscator\DalvikObfuscator\injector.py", line 196, in obfuscate
if reduce(lambda op1,op2: op1 or op2, map(self._obfuscator_arrayDataOverlayIf, method), False):
File "C:\Apps\EclipsePortable\Data\workspace\DalvikObfuscator\DalvikObfuscator\injector.py", line 209, in _obfuscator_arrayDataOverlayIf
struct.pack_into('I', obfuscator, 14, payloadlen)
struct.error: integer out of range for 'I' format code