Dex2jar have the ability to modify the code of an apk.
for demo, we will modify a apk to let it showing a message when it start.
and you need following components in you PATH. android-sdk,ant,dex2jar,jdk6
you need an apk, which you didn't have the source. Just for demo, we build a simple hello-world apk by running the following command
android create project --name test_apk --path test_apk --package a.b --activity Main --target 1 cd test_apk ant debug cd bin
now we got test_apk/bin/test_apk-debug.apk. we can check it by running the apk inside an emulator.
Now we got the apk, and It's time to modify it.
we can't modify dex or jar(.class) file directly. dex2jar support to assemble/disassemble .class file from/to jasmin file. so we convert the apk to jar and disassemble it.
# convert classes.dex in test_apk-debug.apk to test_apk-debug_dex2jar.jar d2j-dex2jar.sh -f -o test_apk-debug_dex2jar.jar test_apk-debug.apk # verify jar d2j-asm-verify.sh test_apk-debug_dex2jar.jar # convert to jasmin format d2j-jar2jasmin.sh -f -o test_apk_jasmin test_apk-debug_dex2jar.jar
.method public onCreate(Landroid/os/Bundle;)V aload 0 aload 1 invokespecial android/app/Activity/onCreate(Landroid/os/Bundle;)V aload 0 ldc_w 2130837504 invokevirtual a/b/Main/setContentView(I)V ; Toast.makeText(this.getApplicationContext(), "hi", Toast.LENGTH_LONG).show(); aload 0 invokevirtual android/app/Activity/getApplicationContext()Landroid/content/Context; ldc "hi" ldc_w 1 invokestatic android/widget/Toast/makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast; invokevirtual android/widget/Toast/show()V return .limit locals 2 .limit stack 3 .end method
# build jar d2j-jasmin2jar.sh -f -o test_apk_jasmin.jar test_apk_jasmin/ # verify jar d2j-asm-verify.sh test_apk_jasmin.jar # convert to dex d2j-jar2dex.sh -f -o classes.dex test_apk_jasmin.jar # make a copy cp test_apk-debug.apk test_apk-debug-toast.apk # replace classes.dex in test_apk-debug-toast.apk zip -r test_apk-debug-toast.apk classes.dex # sign the apk d2j-apk-sign.sh -f -o test_apk-debug-toast-signed.apk test_apk-debug-toast.apk
# uninstall previously apk adb uninstall a.b # install adb install test_apk-debug-toast-signed.apk # start main activity adb shell am start -n a.b/.Main
all the above command is for *
unix, for windows users, please replace the suffix from .sh to .bat.
and for the zip command, just open the test_apk-debug-toast.apk with winRAR,winZIP or 7z, then drag the classes.dex into it.
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: haojies...@gmail.com
What is the difference between d2j-dex2jar.bat and dex2jar.bat?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: preetamk...@gmail.com
i didnt understand
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: aasha.me...@gmail.com
nice tutorial
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: sreedhar...@gmail.com
Steps to Break, Edit and Rebuild your apk file on WIndows Platform ************************ **
Create a "New Folder"
Download Dex2Jar? Utility zip file from http://code.google.com/p/dex2jar/ and Extract into the "New Folder"
Create an apk file and .. Place your apk file inside Extracted folder
Open Command prompt and switch to the Windows Extracted directory
Type in the below commands in sequence..
d2j-dex2jar.bat -f -o abc.jar MyFile?.apk
d2j-asm-verify.bat abc.jar
d2j-jar2jasmin.bat -f -o JasminFolder? abc.jar
Edit JasmineFolder?/xyz.j and save
d2j-jasmin2jar.bat -f -o JasminFile?.jar JasminFolder?/
d2j-asm-verify.bat JasminFile?.jar
d2j-jar2dex.bat -f -o classes.dex JasminFile?.jar
Backup your apk file
Rename MyFile?.apk to MyFile?.apk.zip
Delete the classes.dex file you find inside this zip file
Move the new classes.dex file to MyFile?.apk.zip
Rename MyFile?.apk.zip to MyFile?.apk
d2j-apk-sign.bat -f -o MyFile?-signed.apk MyFile?.apk
Run and test your MyFile?-signed.apk
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: kuz...@gmail.com
I've just disassembled and assembled. without changing jasmine. but after install apk it does't run. android say 'app bla-bla unfortunately stopped'. is there another method to disassemble and assemble APK classes?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: kuz...@gmail.com
apk does't work even next situa: convert dex to jar verify jar convert jar to dex zip dex to apk sign apk
I didn't change jar, but something wrong with dex file... maybe. who can explain me what is wrong? thanks a lot.
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: piqpiq90
Ive got the same problem with my own written android-app - do you know what could be the problem? I use java 1.6.0_25 for the development. Thx in advance guys :) - nice tool nevertheless.
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: piqpiq90
By the way in the end it worked for me. My problem where problems with the source-code. It did not successfully recreated my source. Problem was a "synchronized"-"Tag".
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: hram...@gmail.com
is there a tool that will prevent decompling?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: shinom...@gmail.com
I have edited some app... in the old version of app, have no any problem. But in the newer version, it crashed after run.
edit at the same class file and only 6 byte replaced... any suggestion?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: dave113x...@gmail.com
hello when i use the frst command line d2j-dex2jar.sh -f -o test_apk-debug_dex2jar.jar test_apk-debug.apk i have many errors: java.lang.NullPointerException?
3)
va:247)
.java:607)
.java:442)
:333)
:108)
don't know why
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: shubhamP...@gmail.com
i tried to follow step to convert apk into jasmin format..but after third step it respond on command prompt "disassemble Sample.jar -> sample_jasmin" but it didn't create in that directry rrlated jasmin file formate...any help?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: andrewru...@gmail.com
hello hi I use smali basmali to edit apks I like. would this be real similar or produce same or give more abilities. dont guess you could make app with just smalis but to alter with, easy. i learn new google code talk this page I google code better now. I like love Android.
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: v.j7029....@gmail.com
v.j7029.sg11@gmail.com
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: chan.sh...@gmail.com
please send that commands in the proper way that we can understand....please
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: chan.sh...@gmail.com
thanks dude it works
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: sravan6...@gmail.com
i could successfully convert .dex file to jar. but when i am trying to verify the jar using "d2j-asm-verify.sh" command, it fails.. Any help would be appreciated.. and what is this jasmin format. how to edit it?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: emneg.ze...@gmail.com
so , would the key(pem) changed after signed?
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: nevil...@gmail.com
using this tool, you will be easily able to edit your apk file. Apk Edit - Edit Your Apk File (Android App)
Last edit: Anonymous 2018-10-12
View and moderate all "wiki Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Wiki"
Originally posted by: sharanan...@gmail.com
if u see the steps it is not clear edit test_apk_jasmin/a/b/Main.j to show a toast. generally in android project it is mainactivity.java but here the author tells to edit Main.j (what is .j???). i edited mainactivity.java and followed all the steps and after that made to run the installed signed apk it gives error
Last edit: Anonymous 2018-10-12