Skip to content

Commit

Permalink
futurize tools
Browse files Browse the repository at this point in the history
  • Loading branch information
reox committed Feb 8, 2017
1 parent fc2a76b commit 8da45ea
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 57 deletions.
7 changes: 4 additions & 3 deletions androarsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys
from optparse import OptionParser
from xml.dom import minidom
Expand Down Expand Up @@ -68,7 +69,7 @@ def main(options, arguments):
elif ret_type == "ARSC":
arscobj = apk.ARSCParser(read(options.input))
else:
print "Unknown file type"
print("Unknown file type")
return

if not options.package and not options.type and not options.locale:
Expand All @@ -94,10 +95,10 @@ def main(options, arguments):
fd.write(buff)
fd.close()
else:
print buff
print(buff)

elif options.version != None:
print "Androarsc version %s" % androconf.ANDROGUARD_VERSION
print("Androarsc version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion androauto.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
from builtins import object
import sys

from optparse import OptionParser
Expand All @@ -43,7 +45,7 @@ def __init__(self, id_file, filename):
class AndroTest(auto.DirectoryAndroAnalysis):

def analysis_app(self, log, apkobj, dexobj, adexobj):
print log.id_file, log.filename, apkobj, dexobj, adexobj
print(log.id_file, log.filename, apkobj, dexobj, adexobj)


def main(options, arguments):
Expand Down
7 changes: 4 additions & 3 deletions androaxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys
from optparse import OptionParser
from xml.dom import minidom
Expand Down Expand Up @@ -58,18 +59,18 @@ def main(options, arguments):
buff = minidom.parseString(ap.get_buff()).toprettyxml(
encoding="utf-8")
else:
print "Unknown file type"
print("Unknown file type")
return

if options.output != None:
fd = codecs.open(options.output, "w", "utf-8")
fd.write(buff)
fd.close()
else:
print buff
print(buff)

elif options.version != None:
print "Androaxml version %s" % androconf.ANDROGUARD_VERSION
print("Androaxml version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion androcsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys

from androguard.core import androconf
Expand Down Expand Up @@ -75,7 +76,7 @@ def main(options, arguments):
s.check_db(options.check)

elif options.version != None:
print "Androcsign version %s" % androconf.ANDROGUARD_VERSION
print("Androcsign version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
29 changes: 15 additions & 14 deletions androdd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import shutil
import sys
import os
Expand Down Expand Up @@ -78,13 +79,13 @@ def export_apps_to_format(filename,
jar=None,
decompiler_type=None,
format=None):
print "Dump information %s in %s" % (filename, output)
print("Dump information %s in %s" % (filename, output))

if not os.path.exists(output):
print "Create directory %s" % output
print("Create directory %s" % output)
os.makedirs(output)
else:
print "Clean directory %s" % output
print("Clean directory %s" % output)
androconf.rrmdir(output)
os.makedirs(output)

Expand All @@ -98,7 +99,7 @@ def export_apps_to_format(filename,

dump_classes = []
for _, vm, vmx in s.get_objects_dex():
print "Decompilation ...",
print("Decompilation ...", end=' ')
sys.stdout.flush()

if decompiler_type == "dex2jad":
Expand All @@ -124,16 +125,16 @@ def export_apps_to_format(filename,
], androconf.CONF["OPTIONS_FERNFLOWER"
], androconf.CONF["TMP_DIRECTORY"]))

print "End"
print("End")

if options.jar:
print "jar ...",
print("jar ...", end=' ')
filenamejar = decompiler.Dex2Jar(
vm, androconf.CONF["PATH_DEX2JAR"],
androconf.CONF["BIN_DEX2JAR"],
androconf.CONF["TMP_DIRECTORY"]).get_jar()
shutil.move(filenamejar, output + "classes.jar")
print "End"
print("End")

for method in vm.get_methods():
if methods_filter_expr:
Expand All @@ -145,9 +146,9 @@ def export_apps_to_format(filename,
filename_class = valid_class_name(method.get_class_name())
create_directory(filename_class, output)

print "Dump %s %s %s ..." % (method.get_class_name(),
print("Dump %s %s %s ..." % (method.get_class_name(),
method.get_name(),
method.get_descriptor()),
method.get_descriptor()), end=' ')

filename_class = output_name + filename_class
if filename_class[-1] != "/":
Expand Down Expand Up @@ -175,11 +176,11 @@ def export_apps_to_format(filename,
buff = method2dot(vmx.get_method(method))

if format:
print "%s ..." % format,
print("%s ..." % format, end=' ')
method2format(filename + "." + format, format, None, buff)

if method.get_class_name() not in dump_classes:
print "source codes ...",
print("source codes ...", end=' ')
current_class = vm.get_class(method.get_class_name())
current_filename_class = valid_class_name(
current_class.get_name())
Expand All @@ -189,11 +190,11 @@ def export_apps_to_format(filename,
fd.write(current_class.get_source())
dump_classes.append(method.get_class_name())

print "bytecodes ...",
print("bytecodes ...", end=' ')
bytecode_buff = dvm.get_bytecodes_method(vm, vmx, method)
with open(filename + ".ag", "w") as fd:
fd.write(bytecode_buff)
print
print()


def main(options, arguments):
Expand All @@ -204,7 +205,7 @@ def main(options, arguments):
export_apps_to_format(options.input, s, options.output, options.limit,
options.jar, options.decompiler, options.format)
else:
print "Please, specify an input file and an output directory"
print("Please, specify an input file and an output directory")


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions androdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys

from optparse import OptionParser
Expand Down Expand Up @@ -97,7 +98,7 @@ def main(options, arguments):

dx2 = analysis.VMAnalysis(d2)

print d1, dx1, d2, dx2
print(d1, dx1, d2, dx2)
sys.stdout.flush()

threshold = None
Expand Down Expand Up @@ -125,18 +126,18 @@ def main(options, arguments):
ddm = DiffDalvikMethod(i, j, elb, eld)
ddm.show()

print "NEW METHODS"
print("NEW METHODS")
enew = el.get_new_elements()
for i in enew:
el.show_element(i, False)

print "DELETED METHODS"
print("DELETED METHODS")
edel = el.get_deleted_elements()
for i in edel:
el.show_element(i)

elif options.version != None:
print "Androdiff version %s" % androconf.ANDROGUARD_VERSION
print("Androdiff version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions androdis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys
import os
from optparse import OptionParser
Expand Down Expand Up @@ -47,9 +48,9 @@ def disassemble(dex, offset, size):
nb = 0
idx = offset
for i in d.disassemble(offset, size):
print "%-8d(%08x)" % (nb, idx),
print("%-8d(%08x)" % (nb, idx), end=' ')
i.show(idx)
print
print()

idx += i.get_length()
nb += 1
Expand Down
3 changes: 2 additions & 1 deletion androlyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys

from optparse import OptionParser
Expand Down Expand Up @@ -75,7 +76,7 @@ def main(options, arguments):
interact()

elif options.version != None:
print "Androguard version %s" % androconf.ANDROGUARD_VERSION
print("Androguard version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
27 changes: 14 additions & 13 deletions androsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function
import sys, os

from optparse import OptionParser
Expand Down Expand Up @@ -59,7 +60,7 @@


def display(ret, debug):
print "---->", ret[0]
print("---->", ret[0])
sys.stdout.flush()


Expand All @@ -75,17 +76,17 @@ def main(options, arguments):
if options.input != None:
ret_type = androconf.is_android(options.input)

print os.path.basename(options.input), ":",
print(os.path.basename(options.input), ":", end=' ')
sys.stdout.flush()
if ret_type == "APK":
try:
a = apk.APK(options.input)
if a.is_valid_APK():
display(s.check_apk(a), options.verbose)
else:
print "INVALID"
except Exception, e:
print "ERROR", e
print("INVALID")
except Exception as e:
print("ERROR", e)

elif ret_type == "DEX":
display(s.check_dex(read(options.input)), options.verbose)
Expand All @@ -100,27 +101,27 @@ def main(options, arguments):

ret_type = androconf.is_android(real_filename)
if ret_type == "APK":
print os.path.basename(real_filename), ":",
print(os.path.basename(real_filename), ":", end=' ')
sys.stdout.flush()
try:
a = apk.APK(real_filename)
if a.is_valid_APK():
display(s.check_apk(a), options.verbose)
else:
print "INVALID APK"
except Exception, e:
print "ERROR", e
print("INVALID APK")
except Exception as e:
print("ERROR", e)
elif ret_type == "DEX":
try:
print os.path.basename(real_filename), ":",
print(os.path.basename(real_filename), ":", end=' ')
sys.stdout.flush()
display(s.check_dex(read(real_filename)),
options.verbose)
except Exception, e:
print "ERROR", e
except Exception as e:
print("ERROR", e)

elif options.version != None:
print "Androsign version %s" % androconf.ANDROGUARD_VERSION
print("Androsign version %s" % androconf.ANDROGUARD_VERSION)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 8da45ea

Please sign in to comment.