Extracting source code with JADX
(self, apk_file, target_dir)
| 225 | return {"result": 1, "path": extracted_source_path} |
| 226 | |
| 227 | def extract_source_code(self, apk_file, target_dir): |
| 228 | """ |
| 229 | Extracting source code with JADX |
| 230 | """ |
| 231 | util.mod_log("[+] Extracting the source code to: " + target_dir, util.OKCYAN) |
| 232 | |
| 233 | def is_running_in_docker(): |
| 234 | return os.path.exists('/.dockerenv') or ( |
| 235 | os.path.isfile('/proc/1/cgroup') and 'docker' in open('/proc/1/cgroup').read() |
| 236 | ) |
| 237 | |
| 238 | is_windows = os.name == "nt" |
| 239 | in_docker = is_running_in_docker() |
| 240 | |
| 241 | jadx_executable = "jadx.bat" if is_windows else "jadx" |
| 242 | |
| 243 | if in_docker: |
| 244 | jadx_path = "/app/static_tools/jadx/bin/jadx" |
| 245 | else: |
| 246 | jadx_path = os.path.join( |
| 247 | os.path.dirname(os.path.abspath(__file__)), |
| 248 | "static_tools", |
| 249 | "jadx", |
| 250 | "bin", |
| 251 | jadx_executable, |
| 252 | ) |
| 253 | |
| 254 | try: |
| 255 | result = subprocess.run( |
| 256 | [jadx_path, apk_file, "-d", target_dir], |
| 257 | capture_output=True, |
| 258 | text=True, |
| 259 | check=True |
| 260 | ) |
| 261 | util.mod_log("[+] jadx ran successfully.", util.OKGREEN) |
| 262 | util.mod_log(result.stdout, util.OKBLUE) |
| 263 | except subprocess.CalledProcessError as e: |
| 264 | util.mod_log("[-] jadx failed to run. Unable to Extract {} source code".format(apk_file), util.FAIL) |
| 265 | util.mod_log("Return code: " + str(e.returncode), util.WARNING) |
| 266 | util.mod_log("Stdout:\n" + e.stdout, util.WARNING) |
| 267 | util.mod_log("Stderr:\n" + e.stderr, util.WARNING) |
| 268 | except FileNotFoundError: |
| 269 | util.mod_log(f"[-] jadx not found at: {jadx_path}", util.FAIL) |
| 270 | |
| 271 | def return_abs_path(self, path): |
| 272 | """ |