Skip to content

Instantly share code, notes, and snippets.

@tyvsmith
Created July 22, 2013 18:45
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tyvsmith/6056422 to your computer and use it in GitHub Desktop.
Save tyvsmith/6056422 to your computer and use it in GitHub Desktop.
"`classes.dex` method count helpers. Requires smali/baksmali from https://code.google.com/p/smali/ and dexdump from the build-tools in the Android SDK be on your PATH." Use this to keep track of methods and fields in your apk. They are both limited to 65536. Example use: $ source dex-count.sh; $ dex-field-count classes.dex; Original method scrip…
function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
name=$(echo ${pkg:(${#dir} + 1)} | tr '/' '.')
echo -e "$count\t$name"
done
rm -rf $dir
}
function dex-field-count(){
cat $1 | head -c 84 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-field-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-field-count $pkg/classes.dex)
name=$(echo ${pkg:(${#dir} + 1)} | tr '/' '.')
echo -e "$count\t$name"
done
rm -rf $dir
}
@jerrellmardis
Copy link

Thanks for the script!

Baksmali/Smali usage has changed. Can you please update this gist to use baksmali/smali in the following way:

java -jar baksmali.jar ... instead of baksmali ...
java -jar smali.jar ... instead of smali ...

@tyvsmith
Copy link
Author

The executable scripts are still provided at https://bitbucket.org/JesusFreke/smali/downloads, which essentially wrap the jar in your path.

"This script is a wrapper around baksmali.jar, so you can simply call
"baksmali", instead of java -jar baksmali.jar. It is heavily based on
the "dx" script from the Android SDK"

@mandrachek
Copy link

Hey, could you maybe turn this into a gradle plugin? :)

@tyvsmith
Copy link
Author

@mandrachek I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment