class TestAPK(unittest.TestCase): def setUp(self): file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", 'data', 'test')) self.apk = APK(file_path) def test_get_manifest(self): self.assertIn('com.example', self.apk.get_manifest().get('@package')) def test_get_strings(self): self.assertEqual(len(self.apk.get_strings()), 8594) def test_get_files(self): for item in self.apk.get_files(): if item.get('crc') == 'FA974826': self.assertIn('AndroidManifest.xml', item.get('name')) break def test_get_opcodes(self): for item in self.apk.get_opcodes(): class_name = item.get('class_name') method_name = item.get('method_name') opcodes = item.get('opcodes') if class_name == 'com/example/hellojni/MainActivity' and method_name == 'onCreate': self.assertEqual(opcodes, '6F156E0E') break
class TestAPK(unittest.TestCase): def setUp(self): file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", 'data', 'test_zip_fake_pwd')) self.apk = APK(file_path) def test_get_manifest(self): self.apk.get_manifest() def test_get_strings(self): self.apk.get_strings() def test_get_files(self): self.apk.get_files() def test_get_opcodes(self): self.apk.get_opcodes()
def main(args): apk = APK(args.p) if args.m: import json if apk.get_manifest(): print(json.dumps(apk.get_manifest(), indent=1)) elif apk.get_org_manifest(): print(apk.get_org_manifest()) elif args.s: for item in apk.get_strings(): print(binascii.unhexlify(item).decode(errors='ignore')) elif args.f: for item in apk.get_files(): print(item)
import binascii import os from apkutils import APK file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", 'data', 'test')) apk = APK(file_path) strs = apk.get_strings() # the strings from all of classes\d*.dex for item in strs: s = binascii.unhexlify(item).decode('utf-8', errors='ignore') if 'hello' in s: print(s)