[UTIL][08.12.11] Apktool v1.4.3 - a tool for reverse engineering apk files

Status
Not open for further replies.
Search This thread

tolovaj

Member
Dec 16, 2009
5
0
Hi Brut.all, I have a question;
in video "Apktool Demo 2 - Smali improvements" you "decompile" apk file using parameter "dj" and you get the src directory.

Using latest apktool, I there is no 'j' parameter and I also only get res and smali directories and no src directory.. The point is that I'm more keen on java than smali-type of code and I'd really love to have at least partial java decompiler :D

Is there anything I'm missing, or is this yet-to-come option?
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Hi Brut.all, I have a question;
in video "Apktool Demo 2 - Smali improvements" you "decompile" apk file using parameter "dj" and you get the src directory.

Using latest apktool, I there is no 'j' parameter and I also only get res and smali directories and no src directory.. The point is that I'm more keen on java than smali-type of code and I'd really love to have at least partial java decompiler :D

Is there anything I'm missing, or is this yet-to-come option?

Yet-to-come.

You could see on this video, that it isn't actually Java decoding. It creates Java interface, but whole code is still in smali - you can't run from smali ;-)
 

ErickPetru

Member
May 4, 2010
5
0
Taquaritinga, São Paulo
Dozens of congratulations, Brut.all. HelixLauncher2 is very better on my native language. :p

Then I moved myself to use apktool with Beautiful Widgets.
But wasn't possible. Here are the errors:

Code:
C:\>apktool d "C:\Android\BeautifulWidgets2.0.1.apk" "C:\Android\decompiled\BeautifulWidgets"
I: Baksmaling...
I: Decoding resource table...
I: Decoding resources...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode file "drawable/am.png" to "drawable/am.png"
        at brut.androlib.res.decoder.ResFileDecoder.decode(Unknown Source)
        at brut.androlib.res.decoder.ResFileDecoder.decode(Unknown Source)
        at brut.androlib.res.AndrolibResources.decodeFile(Unknown Source)
        at brut.androlib.res.AndrolibResources.decode(Unknown Source)
        at brut.androlib.Androlib.decodeResourcesFull(Unknown Source)
        at brut.androlib.ApkDecoder.decode(Unknown Source)
        at brut.apktool.Main.cmdDecode(Unknown Source)
        at brut.apktool.Main.main(Unknown Source)
Caused by: brut.androlib.AndrolibException: Could not decode raw stream
        at brut.androlib.res.decoder.ResRawStreamDecoder.decode(Unknown Source)
        at brut.androlib.res.decoder.ResStreamDecoderContainer.decode(Unknown Source)
        ... 8 more
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
        at java.util.zip.ZipFile.read(Native Method)
        at java.util.zip.ZipFile.access$1200(Unknown Source)
        at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source)
        at java.io.InputStream.read(Unknown Source)
        at org.apache.commons.io.IOUtils.copyLarge(Unknown Source)
        at org.apache.commons.io.IOUtils.copy(Unknown Source)
        ... 10 more

I'm doing something wrong or this file can't be extracted?
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Dozens of congratulations, Brut.all. HelixLauncher2 is very better on my native language. :p

Then I moved myself to use apktool with Beautiful Widgets.
But wasn't possible. Here are the errors:

Code:
C:\>apktool d "C:\Android\BeautifulWidgets2.0.1.apk" "C:\Android\decompiled\BeautifulWidgets"
I: Baksmaling...
I: Decoding resource table...
I: Decoding resources...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode file "drawable/am.png" to "drawable/am.png"
        at brut.androlib.res.decoder.ResFileDecoder.decode(Unknown Source)
        at brut.androlib.res.decoder.ResFileDecoder.decode(Unknown Source)
        at brut.androlib.res.AndrolibResources.decodeFile(Unknown Source)
        at brut.androlib.res.AndrolibResources.decode(Unknown Source)
        at brut.androlib.Androlib.decodeResourcesFull(Unknown Source)
        at brut.androlib.ApkDecoder.decode(Unknown Source)
        at brut.apktool.Main.cmdDecode(Unknown Source)
        at brut.apktool.Main.main(Unknown Source)
Caused by: brut.androlib.AndrolibException: Could not decode raw stream
        at brut.androlib.res.decoder.ResRawStreamDecoder.decode(Unknown Source)
        at brut.androlib.res.decoder.ResStreamDecoderContainer.decode(Unknown Source)
        ... 8 more
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
        at java.util.zip.ZipFile.read(Native Method)
        at java.util.zip.ZipFile.access$1200(Unknown Source)
        at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source)
        at java.io.InputStream.read(Unknown Source)
        at org.apache.commons.io.IOUtils.copyLarge(Unknown Source)
        at org.apache.commons.io.IOUtils.copy(Unknown Source)
        ... 10 more

I'm doing something wrong or this file can't be extracted?

Oo, something new! :-D

Could you successfully unpack this file using e.g. WinRAR? Is drawable/am.png file there and is it viewable? If double yes, then try to compress it again to zip file and use apktool on that new file.
 

ErickPetru

Member
May 4, 2010
5
0
Taquaritinga, São Paulo
Oo, something new! :-D

Could you successfully unpack this file using e.g. WinRAR? Is drawable/am.png file there and is it viewable? If double yes, then try to compress it again to zip file and use apktool on that new file.

Thanks, worked.

Details:
While extracting with Winrar, an error happened (file corrupted).
But all was extracted. Then I was able to use apktool.
After recompiling, the generated apk is runing well.

...

I would take the matter of customizing Beautiful Widgets with an absurd question: is there any converter from Smali to Java?

No need to be a perfect converter where you can decompile, recompile and all remains working. But something that makes the Smali code more readable for a Java programmer, as a basis to implement new codes more easily. There is something anywhere?
 
Last edited:

rac2030

Senior Member
Jun 9, 2007
213
3
www.2030.tk
Thanks, worked.
I would take the matter of customizing Beautiful Widgets with an absurd question: is there any converter from Smali to Java?

No need to be a perfect converter where you can decompile, recompile and all remains working. But something that makes the Smali code more readable for a Java programmer, as a basis to implement new codes more easily. There is something anywhere?
http://xdaforums.com/showthread.php?p=6525677
 
Last edited:

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
I would take the matter of customizing Beautiful Widgets with an absurd question: is there any converter from Smali to Java?

No need to be a perfect converter where you can decompile, recompile and all remains working. But something that makes the Smali code more readable for a Java programmer, as a basis to implement new codes more easily. There is something anywhere?

You have luck that rac2030 commented this part of your post - you have added this after I read your post, so I didn't see it.

And I don't think you want something like "-dj" option, linked by rac2030 above. But there is something useful for you:

http://code.google.com/p/dex2jar/

This is a tool for converting Dalvik Bytecode to regular Java bytecode. Then you could use some Java decompiler, I recommend JD-gui and you will get real Java sources of dex file. Of course this isn't perfect, but works quite well and both tools are still being developed :)

There is also undx tool, alternative to dex2jar, but I don't like it.
 
Last edited:

ErickPetru

Member
May 4, 2010
5
0
Taquaritinga, São Paulo
Yes, thanks rac2030 and Brut. :D

And I'll take a look at dex2jar (is that chinese?!). Many thanks.

So... I was trying apktool with the really new LauncherPro 0.2.0 Beta.

And nice errors:

Code:
C:\Users\Erick>apktool d "C:\Android\backup\com.fede.LauncherPro-0.2.0.apk" "C:\Android\decompiled\LauncherPro"
I: Baksmaling...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: java.io.FileNotFoundException: C:\Android\decompiled\LauncherPro"      \smali\com\fede\launcher\AddAdapter$ListItem.smali (A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta)
        at brut.androlib.Androlib.decodeSourcesSmali(Unknown Source)
        at brut.androlib.ApkDecoder.decode(Unknown Source)
        at brut.apktool.Main.cmdDecode(Unknown Source)
        at brut.apktool.Main.main(Unknown Source)
Caused by: brut.androlib.AndrolibException: java.io.FileNotFoundException: C:\Android\decompiled\LauncherPro"      \smali\com\fede\launcher\AddAdapter$ListItem.smali (A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta)
        at brut.androlib.src.SmaliDecoder.decode(Unknown Source)
        at brut.androlib.src.SmaliDecoder.decode(Unknown Source)
        ... 4 more
Caused by: java.io.FileNotFoundException: C:\Android\decompiled\LauncherPro"      \smali\com\fede\launcher\AddAdapter$ListItem.smali (A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileWriter.<init>(Unknown Source)
        at brut.androlib.src.SmaliDecoder.decodeClassDefItem(Unknown Source)
        ... 6 more
C:\Users\Erick>

What could it be?

PS.: "A sintaxe do nome do arquivo, do nome do diretório ou do rótulo do volume está incorreta" = "The syntax of the file name, directory name or volume label is incorrect"



Edit:
Unziped, reziped and worked...
 
Last edited:

aupeters

New member
Feb 22, 2010
2
0
Soo I tried installing/running this on my mac - unzipped the 2 files, put the contents (3 items) into /usr/local/bin, typed "apktool" into Terminal and that worked - gave me the directions.

Then I tried to decode an .apk and after a few moments hesitation says ".apk not found". I go and look at the directory (was on my desktop) and my whole desktop was gone. Like erased-gone. Even took my SDK which was on there.

Any idea if I did something wrong here?
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Soo I tried installing/running this on my mac - unzipped the 2 files, put the contents (3 items) into /usr/local/bin, typed "apktool" into Terminal and that worked - gave me the directions.

Then I tried to decode an .apk and after a few moments hesitation says ".apk not found". I go and look at the directory (was on my desktop) and my whole desktop was gone. Like erased-gone. Even took my SDK which was on there.

Any idea if I did something wrong here?

:-/ I guess you have set your desktop as destination directory - apktool deletes destdir before decoding and it won't warn you about that, won't require --force switch or something like that. I was considering adding such switch, but concluded for most people it would be annoying.

But you aren't first ;-) Some people on http://www.entourageedge.com/forums/ have found my tool, someone lost one of his directory and then everyone were afraid to use it, so they were asking more experienced users to decode something for them ;-D

Maybe I should reconsider adding --force switch.
 

rac2030

Senior Member
Jun 9, 2007
213
3
www.2030.tk

hawst

Inactive Recognized Developer
Jan 28, 2010
544
123
Xiaomi Mi 4
Xiaomi Mi Mix 2

I'm using latest Sprint ROM 2.27.651.5 ported to GSM Hero. All goes fine. I'm trying to repack all .apks to add localization, but faced an issue, can you please help ?

For example, i will explain on Phone.apk, just unpack & pack it back.
- command to unpack (result is attached as 'Phone_unpack.txt'
Code:
apktool.bat -v d -s Phone.apk Phone
- command to pack (result is attached as 'Phone_pack.txt'
Code:
apktool.bat -v b Phone

As i see error cause is that apktool can't find some resources, so it placed plain ID to .xml file. Of coz it can't build it back coz no such resource.
 

Attachments

  • Phone.apk
    798.9 KB · Views: 18
  • Phone_unpack.txt
    3.9 KB · Views: 22
  • Phone_pack.txt
    2.1 KB · Views: 17

Lieu10ant

Senior Member
Nov 10, 2008
437
42
anyone willing to edit Shazam to include a search intent to iMusicTao if it's installed on the phone (along side the amazon search)
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
I'm using latest Sprint ROM 2.27.651.5 ported to GSM Hero. All goes fine. I'm trying to repack all .apks to add localization, but faced an issue, can you please help ?

You could try to:

  1. Pull com.htc.resources.apk file from your device. Should be in /system/framework/ or /data/system-framework/ dir.
  2. Unpack resources.arsc file from it.
  3. Run "apktool publicize-resources resources.arsc" on it.
  4. Zip only this one file to com.htc.resources.apk archive.
  5. Unpack apktool.jar .
  6. Replace brut/androlib/com.htc.resources.apk file with one you've just created.
  7. Pack back to apktool.jar and use it.
  8. Let me know, whether this worked for you :)

I must add some automation to apktool - I can't keep HTC resources up to date all the time. Actually... I shouldn't redistribute them at all, because they are proprietary bits...

I think about something like: when you install apktool or want to use it against apks from new device, you must pull resources file from it (or maybe just connect through USB and apktool will pull it automatically), run "apktool add-framework-res file-res.apk" and apktool will do above steps, then save resulting apk somewhere in home dir for future use. It would be really nice feature.
 

stari4ek

Senior Member
Sep 2, 2009
80
3
Minsk
You could try to:

  1. Pull com.htc.resources.apk file from your device. Should be in /system/framework/ or /data/system-framework/ dir.
  2. Unpack resources.arsc file from it.
  3. Run "apktool publicize-resources resources.arsc" on it.
  4. Zip only this one file to com.htc.resources.apk archive.
  5. Unpack apktool.jar .
  6. Replace brut/androlib/com.htc.resources.apk file with one you've just created.
  7. Pack back to apktool.jar and use it.
  8. Let me know, whether this worked for you :)

I must add some automation to apktool - I can't keep HTC resources up to date all the time. Actually... I shouldn't redistribute them at all, because they are proprietary bits...

I think about something like: when you install apktool or want to use it against apks from new device, you must pull resources file from it (or maybe just connect through USB and apktool will pull it automatically), run "apktool add-framework-res file-res.apk" and apktool will do above steps, then save resulting apk somewhere in home dir for future use. It would be really nice feature.

Such a usefull information. If you didn't write it here, there is no way to find out these tidbits. Do you have plans to add it to faq/wiki?
Thank you for information, thank you for this great tool.
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Such a usefull information. If you didn't write it here, there is no way to find out these tidbits. Do you have plans to add it to faq/wiki?
Thank you for information, thank you for this great tool.

If hawst confirm that above instructions work for him, I will create enhancement task in issue tracker and add them there. I don't want to add them to wiki, because this is workaround which should be automatized and it will probably be in nearest future :)
 

hawst

Inactive Recognized Developer
Jan 28, 2010
544
123
Xiaomi Mi 4
Xiaomi Mi Mix 2
Now i'm faced another issue with WorldClock.apk
It is successfully unpacked, but can't be packed bak (WorldClock_pack.txt)

As i see apktool somehow unpacked res/amin/undim.html - binary file, of coz apktool can't build it back... Also tried on another rom - same error.

brut.zip contains updated res files to change in apktool.jar as u desribed.
 

Attachments

  • brut.zip
    195.4 KB · Views: 21
  • WorldClock.apk
    380.3 KB · Views: 4
  • WorldClock_pack.txt
    1.9 KB · Views: 14

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Now i'm faced another issue with WorldClock.apk
It is successfully unpacked, but can't be packed bak (WorldClock_pack.txt)

As i see apktool somehow unpacked res/amin/undim.html - binary file, of coz apktool can't build it back... Also tried on another rom - same error.

brut.zip contains updated res files to change in apktool.jar as u desribed.

http://code.google.com/p/android-apktool/issues/detail?id=34#c2

I must reserve some time for apktool - there are quite many things to do :)
 
Last edited:
Status
Not open for further replies.

Top Liked Posts

  • There are no posts matching your filters.
  • 95
    Brut.all said:
    It is a tool for reengineering 3rd party, closed, binary Android apps. It can decode resources to nearly original form and rebuild them after making some modifications; it makes possible to debug smali code step by step. Also it makes working with app easier because of project-like files structure and automation of some repetitive tasks like building apk, etc.

    It is NOT intended for piracy and other non-legal uses. It could be used for localizing, adding some features or support for custom platforms and other GOOD purposes. Just try to be fair with authors of an app, that you use and probably like.

    Features:

    • decoding resources to nearly original form
    • smali debugging: SmaliDebugging
    • helping with some repetitive tasks

    http://code.google.com/p/android-apktool/
    6
    Forget that Maven crap. It builds fine here. I'll just release the binary for v1.4.5. v1.4.6 is in testing and just isn't ready for the public.

    http://connortumbleson.com/apktool-v1-4-5-a-tool-for-reverse-engineering-apk-files/

    You may find the updated apktool above. It will work with ICS very well. Credits to JesusFreke and others involved in baksmali/smali as well as brut.all for the original apktool.

    Bugs here: https://github.com/iBotPeaches/brut.apktool/issues?state=open
    Updates here: http://connortumbleson.com/apktool-v1-4-5-a-tool-for-reverse-engineering-apk-files/

    Thanks,
    iBotPeaches
    6
    I'm going to make a new topic, so we don't have to post in a Legacy forum. I need to get off work and run all my last minute tests to be sure my final changes didn't break anything.

    Then I'll release. I will put a link to the new thread (when posted) here.
    5
    I've been busy. Its no easy task working with this application. I spend most my time setting breakpoints and just figuring out how the application works.

    I've been making my own whitepapers just so I can figure out how to read the data, because I can simply read the code and understand that is skips the first 4 bytes, but by re-doing the resource side of things and understanding for myself why bytes are skipped and why things are read helps me fix it.

    I don't wanna say I'll have it out by x time. I do this stuff in my free time. The positional error due to the formatted="false" is fixed in v1.4.6.