mirror of
https://github.com/androguard/androguard.git
synced 2024-11-27 06:50:41 +00:00
parent
932af3bcf8
commit
ddba285b58
23
androdis.py
23
androdis.py
@ -24,8 +24,7 @@ import sys
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
from androguard.core.bytecodes import dvm
|
||||
from androguard.core.bytecodes.apk import *
|
||||
from androguard.cli import androdis_main
|
||||
|
||||
option_0 = {
|
||||
'name': ('-i', '--input'),
|
||||
@ -42,29 +41,11 @@ option_2 = {'name': ('-s', '--size'), 'help': 'size', 'nargs': 1}
|
||||
options = [option_0, option_1, option_2]
|
||||
|
||||
|
||||
def disassemble(dex, offset, size):
|
||||
with open(dex, "rb") as fp:
|
||||
d = dvm.DalvikVMFormat(fp.read())
|
||||
|
||||
if d:
|
||||
nb = 0
|
||||
idx = offset
|
||||
for i in d.disassemble(offset, size):
|
||||
print("%-8d(%08x)" % (nb, idx), end=' ')
|
||||
i.show(idx)
|
||||
print()
|
||||
|
||||
idx += i.get_length()
|
||||
nb += 1
|
||||
else:
|
||||
print("Dex could not be loaded!", file=sys.stderr)
|
||||
|
||||
|
||||
def main(options, arguments):
|
||||
if options.input and options.offset and options.size:
|
||||
offset = int(options.offset, 0)
|
||||
size = int(options.size, 0)
|
||||
disassemble(options.input, offset, size)
|
||||
androdis_main(offset, size, options.input)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -4,5 +4,6 @@ from androguard.cli.main import (androarsc_main,
|
||||
androgui_main,
|
||||
androlyze_main,
|
||||
androsign_main,
|
||||
androdis_main,
|
||||
export_apps_to_format,
|
||||
)
|
||||
|
@ -19,7 +19,9 @@ from androguard.cli import (androarsc_main,
|
||||
export_apps_to_format,
|
||||
androsign_main,
|
||||
androlyze_main,
|
||||
androgui_main)
|
||||
androgui_main,
|
||||
androdis_main
|
||||
)
|
||||
|
||||
|
||||
@click.group(help=__doc__)
|
||||
@ -434,5 +436,22 @@ def analyze(debug, ddebug, no_session, apk):
|
||||
androlyze_main(debug, ddebug, no_session, apk)
|
||||
|
||||
|
||||
@entry_point.command()
|
||||
@click.option("-o", "--offset",
|
||||
default=0,
|
||||
type=int,
|
||||
help="Offset to start dissassembly inside the file")
|
||||
@click.option("-s", "--size",
|
||||
default=0,
|
||||
type=int,
|
||||
help="Number of bytes from offset to disassemble, 0 for whole file")
|
||||
@click.argument("DEX")
|
||||
def disassemble(offset, size, dex):
|
||||
"""
|
||||
Disassemble Dalvik Code with size SIZE starting from an offset
|
||||
"""
|
||||
androdis_main(offset, size, dex)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
entry_point()
|
||||
|
@ -416,3 +416,25 @@ def androsign_main(args_apk, args_hash, args_all, show):
|
||||
|
||||
if len(args_apk) > 1:
|
||||
print()
|
||||
|
||||
|
||||
def androdis_main(offset, size, dex):
|
||||
from androguard.core.bytecodes import dvm
|
||||
|
||||
with open(dex, "rb") as fp:
|
||||
buf = fp.read()
|
||||
d = dvm.DalvikVMFormat(buf)
|
||||
|
||||
if size == 0:
|
||||
size = len(buf)
|
||||
|
||||
if d:
|
||||
idx = offset
|
||||
for nb, i in enumerate(d.disassemble(offset, size)):
|
||||
print("%-8d(%08x)" % (nb, idx), end=' ')
|
||||
i.show(idx)
|
||||
print()
|
||||
|
||||
idx += i.get_length()
|
||||
else:
|
||||
print("Dex could not be loaded!", file=sys.stderr)
|
||||
|
Loading…
Reference in New Issue
Block a user