Skip to main content

πŸ”§ APK/JAR Advanced Tool Kits

Advanced utilities for APK and JAR patching.


dynamic_apktool​

Dynamically decompiles or recompiles APKs/JARs with enhanced options.

FlagDescription
-decompile (-d)APK or JAR to decompile
-recompile (-r)Folder to recompile
-framework (-f) FILEFramework-res.apk to use
-add (-a) PATHFolders/files to add to result (multiple allowed)
-command (-c) OPTExtra apktool.jar options
-output (-o) DESTFull path to results
-sign (-s)Sign the result (recompile)
-zipalign (-z)Zipalign the result (recompile)
-preserve-signature (-ps)Keep original META-INF and AndroidManifest.xml (recompile)
-no-apiDisable automatic device API specification
-no-extrasDisable original resource checking/adding (decompile)
-use-baksmali FILEUse external baksmali.jar (DEXed) (decompile)
-use-smali FILEUse external smali.jar (DEXed) (recompile)
# Decompile with added folder
dynamic_apktool -decompile "Test.apk" -o "/sdcard/Test" -add "/sdcard/folder"

# Decompile with custom baksmali and no extras
dynamic_apktool -no-extras -use-baksmali "$TMP/custom.jar" -decompile "Test.apk" -o "/sdcard/Test" -add "/sdcard/folder"

# Recompile with additions, signing, and zipalign
dynamic_apktool -recompile "/sdcard/Test" -add "/sdcard/testfolder" -add "/sdcard/Test/original/META-INF" -add "/sdcard/test.txt" -zipalign -sign
note

It does not decompile or recompile resources (res/) by default, only .dex (smali). This guarantees errors prevention in most cases.


smali_kit​

Manipulates smali files for advanced APK editing.

FlagDescription
-dir (-d) FOLDERPath to find .smali files
-name (-n) PATTERNPattern for .smali file names (Multiple allowed)
-file (-f) FILESpecific .smali file to edit
-method (-m) NAMEPattern for method name to find
-replace (-r) CODEReplace entire method with new code
-replace-in-method (-rim) OLD NEWReplace OLD string with NEW in method
-delete-in-method (-dim) TEXTRemove TEXT from method
-remake (-re) CODEReplace method’s internal content
-after-line (-al) LINE TEXTAdd TEXT after LINE in method
-before-line (-bl) LINE TEXTAdd TEXT before LINE in method
-limit (-l) NLimit number of results
-check (-c)Report modified files or no changes
-delete-method (-dm)Remove entire method
-print-path (-pp)Print paths of .smali files found
REPLACE="
.method public static isTima()Z
.locals 1
const/4 v0, 0x1
return v0
.end method
"
REMAKE="
.locals 1
const/4 v0, 0x4
return v0
"

# Replace in specific file
smali_kit -check -method "isTima" -file "/sdcard/file.smali" -replace "$REPLACE"

# Search for a .smali by NAME
smali_kit -check -method "isTima" -dir "FOLDER" -name "NAME.smali" -replace "$REPLACE"

# Search for a .smali by PARTIAL NAME
# It is not necessary to know the exact name, just a PART
smali_kit -method "isTima" -d "FOLDER" -name "PART*" -replace "$REPLACE"
smali_kit -method "isTima" -d "FOLDER" -name "*PART*" -remake "$REMAKE"

# This may be more accurate
# Although the name is partial, the file extension should be .smali
smali_kit -method "isTima" -d "FOLDER" -name "PART*.smali" -delete-method

# Search for .smali files with multiple possible NAMES or PARTIAL NAMES
smali_kit -method "isTima" -d "FOLDER" -name "NAME.smali" -name "PART*.smali" -name "*PART2*.smali" -delete-method

# Replace string in method
smali_kit -method "isTima" -dir "FOLDER" -name "NAME.smali" -replace-in-method "const/4 v0, 0x1" "const/4 v0, 0x0"

# Remake method content
smali_kit -method "isTima" -d "FOLDER" -name "NAME.smali" -remake "$REMAKE"

# Simply get the paths of the .smali files that contain a valid method
found_paths=$(smali_kit -print-path -method "isTima" -d "FOLDER" -name "NAME.smali")
info

If you don't specify -name when specifying a directory (-dir), all files in the directory will be read to search for the method. This is much slower than filtering the search with multiple full or partial file names.

note

Only Search and reconstruction of Smali Code is ensured with basic principles, an analysis of the new code at the syntax level is not carried out.