Full Code of b-mueller/apkx for AI

master fcb74ff37c9f cached
6 files
5.5 KB
1.7k tokens
1 requests
Download .txt
Repository: b-mueller/apkx
Branch: master
Commit: fcb74ff37c9f
Files: 6
Total size: 5.5 KB

Directory structure:
gitextract_ke2tles2/

├── .gitignore
├── README.md
├── apkx
├── apkx-libs.jar
├── enjarify.pex
└── install.sh

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.DS_Store
.python-version


================================================
FILE: README.md
================================================
# apkx - Android APK Decompilation for the Lazy

A Python wrapper to popular free dex converters and Java decompilers. Extracts Java source code directly from the APK. Useful for experimenting with different converters/decompilers without having to worry about classpath settings and command line args.

## Installation

```bash
$ git clone https://github.com/b-mueller/apkx
$ cd apkx
$ sudo ./install.sh
```

Notes: 

- JRE needs to be installed and in PATH
- enjarify requires Python 3

## Usage

Pass the APK filename on the command line:

```bash
$ apkx HelloWorld.apk 
Extracting HelloWord.apk to HelloWord
Converting: classes.dex -> classes.jar (dex2jar)
dex2jar HelloWord/classes.dex -> HelloWord/classes.jar
Decompiling to HelloWord/src (cfr)
```

The default combination of converter and decompiler is <code>dex2jar</code> and <code>cfr</code>. Use the <code>-c</code> and <code>-d</code> flags to change this. E.g.:

```bash
$ apkx -c enjarify -d procyon HelloWorld.apk
```

To get help, run:

```bash
$ apkx -h
```

## Tools

This script integrates the following tools:

- [Procyon](https://bitbucket.org/mstrobel/procyon) by Mike Strobel - [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
- [CFR](http://www.benf.org/other/cfr/) by Lee Benfield  - [MIT License](https://opensource.org/licenses/MIT)
- [dex2jar](https://github.com/pxb1988/dex2jar) by Bob Pan - [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
- [enjarify](https://github.com/Storyyeller/enjarify) by Storyyeller - [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)

## About

This script accompanies the [OWASP Mobile Security Testing Guide](https://github.com/OWASP/owasp-mstg). For further instructions and usage examples, see also:

- [Tampering and Reverse Engineering on Android](https://github.com/OWASP/owasp-mstg/blob/master/Document/0x05c-Reverse-Engineering-and-Tampering.md)
- [Testing Resiliency Against Reverse Engineering on Android](https://github.com/OWASP/owasp-mstg/blob/master/Document/0x05j-Testing-Resiliency-Against-Reverse-Engineering.md)



================================================
FILE: apkx
================================================
#!/usr/bin/python
#
# apkx -- A Python wrapper for popular dex converters and Java decompilers.
# Because nobody likes messing with Java classpaths & jar command lines.
# v0.9.2
#
# Author: Bernhard Mueller
# This file is part of the OWASP Mobile Testing Guide (https://github.com/OWASP/owasp-mstg)
#
# See also:
#
# Dex2jar - https://github.com/pxb1988/dex2jar
# CFR - http://www.benf.org/other/cfr/
# 
# This program is free software: you can redistribute it and/or modify  
# it under the terms of the GNU General Public License as published by  
# the Free Software Foundation, version 3.

import os
import sys
import subprocess
import zipfile
import re
import argparse

cwd = os.path.dirname(os.path.realpath(__file__))
FNULL = open(os.devnull, 'w')

def convert(converter, lib_path, ext_path, infile, outfile):

	if (converter == 'dex2jar'):
		subprocess.call(['java', '-Xms512m', '-Xmx1024m', '-cp', lib_path, 'com.googlecode.dex2jar.tools.Dex2jarCmd', ext_path + '/' + infile, '-o', ext_path + '/' + outfile, '-f'])
	elif (converter == 'enjarify'):
		subprocess.call([cwd + '/enjarify.pex', ext_path + '/' + infile, '-o', ext_path + '/' + outfile, '--force'])

def decompile(decompiler, lib_path, ext_path, jar_filename):

	if (decompiler == 'cfr'):
		subprocess.call(['java','-Xms512m', '-Xmx1024m', '-cp', lib_path, 'org.benf.cfr.reader.Main', ext_path + '/' + jar_filename, '--outputdir', src_path, '--caseinsensitivefs', 'true', '--silent', 'true'], stdout=FNULL)
	elif (decompiler == 'procyon'):
		subprocess.call(['java','-Xms512m', '-Xmx1024m', '-cp', lib_path, 'com.strobel.decompiler.DecompilerDriver', '-jar', ext_path + '/' + jar_filename, '--o', src_path], stdout=FNULL)


'''
====== Main ======
'''

parser = argparse.ArgumentParser(description='Decompile an Android APK archive.')

parser.add_argument('-c', '--converter', help='Dex to jar conversion method (default: dex2jar)', choices=['dex2jar','enjarify'], default = "dex2jar")
parser.add_argument('-d', '--decompiler', help='Decompiler backend to use (default: cfr)', choices=['cfr','procyon'], default = "cfr")
parser.add_argument('apkfile', help='File to decompile')

args = parser.parse_args()

'''
	Unzip the application package.
'''

ext_path = os.path.splitext(os.path.basename(args.apkfile))[0]
src_path = ext_path + "/src"

lib_path = cwd + "/apkx-libs.jar"

print("Extracting " + args.apkfile + " to " + ext_path)

try:
	zip_ref = zipfile.ZipFile(args.apkfile, 'r')
	zip_ref.extractall(ext_path)
	zip_ref.close()
except IOError as e:
	print("Error extracting apk: " + str(e))
	sys.exit(0)

'''
	Iterate over all .dex files
'''

for root, dirs, files in os.walk(ext_path):
	for file in files:
		if file.endswith((".dex")):
			jar_filename = os.path.splitext(file)[0] + ".jar"

			print('Converting: ' + file + ' -> ' + jar_filename + ' (' + args.converter + ')')

			'''
				Conversion Step
			'''

			try:
				convert(args.converter, lib_path, ext_path, file, jar_filename)
			except Exception as e:
				print('Error converting dex to jar:'+ str(e))
				next

			'''
				Decompilation Step
			'''

			print("Decompiling to " + src_path  + ' (' + args.decompiler + ')')

			try:
				decompile(args.decompiler, lib_path, ext_path, jar_filename)
			except Exception as e:
				print('Error decompiling:' + str(e))



================================================
FILE: install.sh
================================================
#!/bin/bash

if [[ $EUID > 0 ]]; then 
  echo "The installation script needs to be run as root."
  exit 1
else
  cp apkx apkx-libs.jar enjarify.pex /usr/local/bin  
  chmod 755 /usr/local/bin/apkx /usr/local/bin/enjarify.pex
fi
Download .txt
gitextract_ke2tles2/

├── .gitignore
├── README.md
├── apkx
├── apkx-libs.jar
├── enjarify.pex
└── install.sh
Condensed preview — 6 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".gitignore",
    "chars": 26,
    "preview": ".DS_Store\n.python-version\n"
  },
  {
    "path": "README.md",
    "chars": 2129,
    "preview": "# apkx - Android APK Decompilation for the Lazy\n\nA Python wrapper to popular free dex converters and Java decompilers. E"
  },
  {
    "path": "apkx",
    "chars": 3297,
    "preview": "#!/usr/bin/python\n#\n# apkx -- A Python wrapper for popular dex converters and Java decompilers.\n# Because nobody likes m"
  },
  {
    "path": "install.sh",
    "chars": 228,
    "preview": "#!/bin/bash\n\nif [[ $EUID > 0 ]]; then \n  echo \"The installation script needs to be run as root.\"\n  exit 1\nelse\n  cp apkx"
  }
]

// ... and 2 more files (download for full content)

About this extraction

This page contains the full source code of the b-mueller/apkx GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 6 files (5.5 KB), approximately 1.7k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!