Skip to content

Instantly share code, notes, and snippets.

@d0nutptr
Created April 14, 2018 23:13
Show Gist options
  • Select an option

  • Save d0nutptr/9cb9daef2eddd81610880b52c48ceadb to your computer and use it in GitHub Desktop.

Select an option

Save d0nutptr/9cb9daef2eddd81610880b52c48ceadb to your computer and use it in GitHub Desktop.
This renames all of the files with a .smali extension to a more logical filename based on the .source entry in the smali file
#!/bin/bash
# Renames files outputed by `apktool d <apk>` to <source>.smali where <source> is the value in the .source entry of the smali file
# This isn't meant to be 100% correct but it works in 99% of cases
# ./apktool_name_corrector.sh ~/Documents/my_smali_output_folder
shopt -s globstar
start_dir=$1
for e in "${start_dir}"/**; do
if [ -f "${e}" ] ; then
if [ ${e: -6} == ".smali" ] ; then
source=$(cat "${e}" | grep -Po "(?<=\.source\s\")[^\"]*")
dir_name=$(dirname "${e}")
new_name="${dir_name}/${source}.smali"
mv "${e}" "${new_name}"
fi
fi
done
echo "done"
@d0nutptr
Copy link
Author

If the smali output doesn't have a .source line then this is going to rename the file to .smali which is likely undesirable behavior. This should probably check that the name is not 0 length.

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