Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # undexopt.py
- import sys, os
- import struct
- import zipfile
- OPT_MAGIC = 'dey\n'
- OPT_VER = '036\0'
- optheader = '8s8i'
- header_size = struct.calcsize(optheader)
- def extractDex(odexfile):
- f = open(odexfile)
- header = struct.unpack(optheader, f.read(header_size))
- magic, offset, length, depsoffset, depslength, optoffset, optlength, flag, checksum = header
- f.seek(offset, os.SEEK_SET)
- return f.read(length)
- def addJar(jarfile, dexbuf):
- out = zipfile.ZipFile(jarfile, 'a')
- out.writestr('classes.dex', dexbuf)
- if __name__ == '__main__':
- if len(sys.argv) == 3:
- infile, outfile = sys.argv[1:3]
- elif len(sys.argv) == 4:
- infile, apk, outfile = sys.argv[1:4]
- import shutil
- shutil.copy(apk, outfile)
- else:
- print 'usage: %s odexfile apkfile [outfile]'%sys.argv[0]
- sys.exit(-1)
- dex = extractDex(infile)
- addJar(outfile, dex)
Advertisement
Add Comment
Please, Sign In to add comment