Silverst0ne commited on
Commit
6f5a20f
·
verified ·
1 Parent(s): da0e6e3

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple Python wrapper for Apktool to decompile an Android APK file.
4
+ Usage: python decompile_apk.py <path_to_apk> [output_dir]
5
+ Requirements: Apktool must be installed and in PATH.
6
+ Best practices: Use argparse for CLI, handle errors, use pathlib for paths.
7
+ """
8
+
9
+ import argparse
10
+ import os
11
+ import subprocess
12
+ import sys
13
+ from pathlib import Path
14
+
15
+
16
+ def check_apktool():
17
+ """Check if Apktool is available in PATH."""
18
+ try:
19
+ subprocess.run(['apktool', '--version'], check=True, capture_output=True)
20
+ return True
21
+ except (subprocess.CalledProcessError, FileNotFoundError):
22
+ return False
23
+
24
+
25
+ def main():
26
+ parser = argparse.ArgumentParser(description='Decompile an APK using Apktool.')
27
+ parser.add_argument('apk_path', type=Path, help='Path to the APK file.')
28
+ parser.add_argument('output_dir', type=Path, nargs='?', default=None,
29
+ help='Output directory (default: basename of APK without extension).')
30
+ args = parser.parse_args()
31
+
32
+ # Validate APK path
33
+ if not args.apk_path.exists():
34
+ print(f"Error: APK file '{args.apk_path}' not found.", file=sys.stderr)
35
+ sys.exit(1)
36
+
37
+ if not args.apk_path.suffix == '.apk':
38
+ print("Error: Input file must be an APK.", file=sys.stderr)
39
+ sys.exit(1)
40
+
41
+ # Set output directory
42
+ if args.output_dir is None:
43
+ output_dir = args.apk_path.parent / args.apk_path.stem
44
+ else:
45
+ output_dir = args.output_dir
46
+
47
+ # Check Apktool availability
48
+ if not check_apktool():
49
+ print("Error: Apktool is not installed or not in PATH.", file=sys.stderr)
50
+ print("Install it from https://ibotpeaches.github.io/Apktool/", file=sys.stderr)
51
+ sys.exit(1)
52
+
53
+ print(f"Decompiling '{args.apk_path}' to '{output_dir}'...")
54
+
55
+ # Create output directory
56
+ output_dir.mkdir(parents=True, exist_ok=True)
57
+
58
+ # Run Apktool decode
59
+ try:
60
+ subprocess.run(['apktool', 'd', str(args.apk_path), '-o', str(output_dir)],
61
+ check=True, capture_output=True)
62
+ print(f"Decompilation complete. Output in: {output_dir}")
63
+ except subprocess.CalledProcessError as e:
64
+ print(f"Error during decompilation: {e.stderr.decode()}", file=sys.stderr)
65
+ sys.exit(1)
66
+
67
+
68
+ if __name__ == '__main__':
69
+ main()