futurize tools

This commit is contained in:
Sebastian Bachmann 2017-02-08 08:35:35 +00:00
parent fc2a76b7d9
commit 8da45ea5e5
10 changed files with 68 additions and 57 deletions

View File

@ -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
@ -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:
@ -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__":

View File

@ -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
@ -43,7 +45,7 @@ class AndroLog(object):
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):

View File

@ -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
@ -58,7 +59,7 @@ 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:
@ -66,10 +67,10 @@ def main(options, arguments):
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__":

View File

@ -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
@ -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__":

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
import shutil
import sys
import os
@ -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)
@ -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":
@ -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:
@ -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] != "/":
@ -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())
@ -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):
@ -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__":

View File

@ -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
@ -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
@ -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__":

View File

@ -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
@ -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

View File

@ -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
@ -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__":

View File

@ -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
@ -59,7 +60,7 @@ options = [option_0, option_1, option_2, option_3, option_4]
def display(ret, debug):
print "---->", ret[0]
print("---->", ret[0])
sys.stdout.flush()
@ -75,7 +76,7 @@ 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:
@ -83,9 +84,9 @@ def main(options, arguments):
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)
@ -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__":

View File

@ -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
@ -120,30 +121,30 @@ def check_one_file(a,
options.compressor,
libnative=library)
el.show()
print "\t--> methods: %f%% of similarities" % el.get_similarity_value(new)
print("\t--> methods: %f%% of similarities" % el.get_similarity_value(new))
if options.display:
print "SIMILAR methods:"
print("SIMILAR methods:")
diff_methods = el.get_similar_elements()
for i in diff_methods:
el.show_element(i)
print "IDENTICAL methods:"
print("IDENTICAL methods:")
new_methods = el.get_identical_elements()
for i in new_methods:
el.show_element(i)
print "NEW methods:"
print("NEW methods:")
new_methods = el.get_new_elements()
for i in new_methods:
el.show_element(i, False)
print "DELETED methods:"
print("DELETED methods:")
del_methods = el.get_deleted_elements()
for i in del_methods:
el.show_element(i)
print "SKIPPED methods:"
print("SKIPPED methods:")
skipped_methods = el.get_skipped_elements()
for i in skipped_methods:
el.show_element(i)
@ -158,31 +159,31 @@ def check_one_file(a,
#els = elsim.Elsim( ProxyDalvikStringOne(d1, dx1),
# ProxyDalvikStringOne(d2, dx2), FILTERS_DALVIK_SIM_STRING, threshold, options.compressor, libnative=library )
els.show()
print "\t--> strings: %f%% of similarities" % els.get_similarity_value(
new)
print("\t--> strings: %f%% of similarities" % els.get_similarity_value(
new))
if options.display:
print "SIMILAR strings:"
print("SIMILAR strings:")
diff_strings = els.get_similar_elements()
for i in diff_strings:
els.show_element(i)
print "IDENTICAL strings:"
print("IDENTICAL strings:")
new_strings = els.get_identical_elements()
for i in new_strings:
els.show_element(i)
print "NEW strings:"
print("NEW strings:")
new_strings = els.get_new_elements()
for i in new_strings:
els.show_element(i, False)
print "DELETED strings:"
print("DELETED strings:")
del_strings = els.get_deleted_elements()
for i in del_strings:
els.show_element(i)
print "SKIPPED strings:"
print("SKIPPED strings:")
skipped_strings = els.get_skipped_elements()
for i in skipped_strings:
els.show_element(i)
@ -205,7 +206,7 @@ def check_one_directory(a,
real_filename += "/"
real_filename += f
print "filename: %s ..." % real_filename
print("filename: %s ..." % real_filename)
check_one_file(a, d1, dx1, FS, threshold, real_filename,
view_strings, new, library)
@ -249,7 +250,7 @@ def main(options, arguments):
options.xstrings, new, library)
elif options.version != None:
print "Androsim version %s" % androconf.ANDROGUARD_VERSION
print("Androsim version %s" % androconf.ANDROGUARD_VERSION)
if __name__ == "__main__":