iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.11k stars 3.58k forks source link

Error with apktool b #1533

Closed MJM111 closed 7 years ago

MJM111 commented 7 years ago

Information

  1. Apktool Version (apktool -version) -2.1.1
  2. Operating System (Mac, Linux, Windows) -Linux Ubuntu 16.04 LTS
  3. APK From? (Playstore, ROM, Other) -Playstore

Stacktrace/Logcat

I: Using Apktool 2.1.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
Exception in thread "main" brut.androlib.AndrolibException: java.io.FileNotFoundException: /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/build/apk/classes.dex (No such file or directory)
    at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:55)
    at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:38)
    at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:364)
    at brut.androlib.Androlib.buildSources(Androlib.java:295)
    at brut.androlib.Androlib.build(Androlib.java:278)
    at brut.androlib.Androlib.build(Androlib.java:254)
    at brut.apktool.Main.cmdBuild(Main.java:224)
    at brut.apktool.Main.main(Main.java:84)
Caused by: java.io.FileNotFoundException: /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/build/apk/classes.dex (No such file or directory)
    at java.io.RandomAccessFile.open0(Native Method)
    at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
    at org.jf.dexlib2.writer.io.FileDataStore.<init>(FileDataStore.java:13)
    at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:53)
    ... 7 more

Steps to Reproduce

  1. apktool
  2. got the apk, changed a eqz to a nez to defeat cert pinning, saved it.
  3. did 'apktool b base' in the folder with base in it, got the above error
  4. I checked and there isn't a 'build' folder in 'base', I get that, just wondering why there isn't one/how to get around it.

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files (.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything?YES, still got errors
  2. If you are trying to install a modified apk, did you resign it?I modified it, but need to build before I resign it.
  3. Are you using the latest apktool version? no, using 2.1.1
MJM111 commented 7 years ago

I'm using 2.1.1 because I heard there was a regression error in the latest version. Will try latest version and post here.

iBotPeaches commented 7 years ago

Interesting. So a regression with latest that no one shares with the bug tracker? That will make sure it gets fixed :o

On topic... So the application was named base.apk? You decoded to base/ folder? then compiled via apktool b base? This error is some environmental oddity where the assembled dex file is not to be found.

MJM111 commented 7 years ago

Thanks for the quick response. Yep, it's named base.apk. I did: apktool d base.apk then altered the smali, saved it apktool b base, errors

Any way to fix this? Does it have to do with the aapt or the framework?

iBotPeaches commented 7 years ago

Not sure. Looks like environment problem from the details I have. aapt is not involved at the assembling of .smali file stage so not that. Frameworks also have nothing to do with this stage, so related to the filesystem creating that .dex file as it assembles the smali files.

MJM111 commented 7 years ago

When I run the same command but with sudo: sudo apktool b base I get this: [sudo] password for mm:

I: Using Apktool 2.1.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_2588416753999631477.tmp, p, --forced-package-id, 127, --min-sdk-version, 19, --target-sdk-version, 25, --version-code, 90, --version-name, 2017.20.177.471142, -F, /tmp/APKTOOL7722875278552765767.tmp, -0, arsc, -0, js, -0, bin, -0, arsc, -I, /root/apktool/framework/1.apk, -S, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/res, -M, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/AndroidManifest.xml]
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:437)
    at brut.androlib.Androlib.buildResources(Androlib.java:371)
    at brut.androlib.Androlib.build(Androlib.java:281)
    at brut.androlib.Androlib.build(Androlib.java:254)
    at brut.apktool.Main.cmdBuild(Main.java:224)
    at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_2588416753999631477.tmp, p, --forced-package-id, 127, --min-sdk-version, 19, --target-sdk-version, 25, --version-code, 90, --version-name, 2017.20.177.471142, -F, /tmp/APKTOOL7722875278552765767.tmp, -0, arsc, -0, js, -0, bin, -0, arsc, -I, /root/apktool/framework/1.apk, -S, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/res, -M, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/AndroidManifest.xml]
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:436)
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:423)
    ... 5 more
Caused by: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_2588416753999631477.tmp, p, --forced-package-id, 127, --min-sdk-version, 19, --target-sdk-version, 25, --version-code, 90, --version-name, 2017.20.177.471142, -F, /tmp/APKTOOL7722875278552765767.tmp, -0, arsc, -0, js, -0, bin, -0, arsc, -I, /root/apktool/framework/1.apk, -S, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/res, -M, /home/mm/Desktop/Work/workdayMobile/prodWorkday/base/AndroidManifest.xml]
    at brut.util.OS.exec(OS.java:97)
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:430)
    ... 6 more
Caused by: java.io.IOException: Cannot run program "/tmp/brut_util_Jar_2588416753999631477.tmp": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at brut.util.OS.exec(OS.java:90)
    ... 7 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 8 more
MJM111 commented 7 years ago

So it seems to get past the classes.dex issue

iBotPeaches commented 7 years ago

Another permission issue. You don't have permission to write/execute files from java tmpdir. You can download the aapt binaries used from the repo and use the --aapt binary_path_to_file parameter to load it elsewhere. This looks like support, not really a bug so far.

  1. aapt binaries here - https://github.com/iBotPeaches/Apktool/tree/master/brut.apktool/apktool-lib/src/main/resources/prebuilt/aapt
Delphian2015 commented 7 years ago

I have the same error using 2.2.3 jar. What shall we do with aapt? Download and install?

iBotPeaches commented 7 years ago

@Delphian2015 If you don't have permission to java tmpdir, that would be a solution.

Delphian2015 commented 7 years ago

Thank you for fast answer. Downloaded aapt. Then installed it. After that started command: apktool d base.apk, then apktool b base. And caught the same error.

Delphian2015 commented 7 years ago

This apk for Android 7.1

iBotPeaches commented 7 years ago

Did you read my comment directly above your first response? https://github.com/iBotPeaches/Apktool/issues/1533#issuecomment-309576931

You need to tell apktool where to find that aapt binary.

Delphian2015 commented 7 years ago

I put all files into folder d:\apktool (apktool.bat, apktool.jar and aapt). Then did in command prompt d:\apktool\aapt.exe. Or is this an incorrect command?

iBotPeaches commented 7 years ago

That is not correct. Please read this comment again - https://github.com/iBotPeaches/Apktool/issues/1533#issuecomment-309576931

Delphian2015 commented 7 years ago

iBotPeaches I read, but I am not an expert in this. Can you explain more detail how to "use the --aapt binary_path_to_file parameter to load it elsewhere"? I have all files and apk into d:\apktool. What shall I do? Thank you for your help.

iBotPeaches commented 7 years ago

Respectfully, this is very basic parameter stuff. We've now clogged a bug report with 10 replies over things located in the documentation and internet.

apktool d --aapt D:\apktool\aapt.exe base.apk 
Delphian2015 commented 7 years ago

iBotPeaches before that I was using apk studio, but today I caught the error and downloaded apktool and now i am trying understand how to work with it. I tried apktool d --aapt D:\apktool\aapt.exe base.apk apktool b --aapt D:\apktool\aapt.exe base

Caught the same error:

d:\apktool>apktool b --aapt d:apktool\aapt.exe base
I: Using Apktool 2.2.3
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_assets folder into assets.dex...
base\smali_assets\java\com\d\b\a\a.smali[15,4] Class Lcom/d/b/a/a; has already b
een interned
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file
: java/com/d/b/a/a.smali
        at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:75)
        at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:59)
        at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36)
        at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:420)
        at brut.androlib.Androlib.buildNonDefaultSources(Androlib.java:366)
        at brut.androlib.Androlib.build(Androlib.java:308)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:231)
        at brut.apktool.Main.main(Main.java:84)
iBotPeaches commented 7 years ago

That error has nothing to do with aapt. You can see right here

base\smali_assets\java\com\d\b\a\a.smali[15,4] Class Lcom/d/b/a/a; has already been interned

You must have two classes with same name - https://stackoverflow.com/questions/32505162/smali-multidex-has-already-been-interned/32507592

Delphian2015 commented 7 years ago

How do I understand this error is related to the language? Because there is no answer in stackoverflow. I didn't change anything in base folder, only did decode and build.

MJM111 commented 7 years ago

I've made it a bit further through the build process, I'm now getting this exact error (for which you posted a solution): https://github.com/iBotPeaches/Apktool/issues/1371 However I'm using version 2.1.1. Is there a workaround for that version?

iBotPeaches commented 7 years ago

Download the latest framework and install it apktool if newer_framework.apk? That would work around #1371 as that is just updating the internal framework to a newer version.

MJM111 commented 7 years ago

From my phone (a droid) or from a newer version of apktool?

Delphian2015 commented 7 years ago

The error because of two copy of the folder in smali_assets the first one - smali_assets/java/com, the second smali_assets/com the folders have the same files, if I delete one of them I can build apk with warnings, but the apk doesn't work.

MJM111 commented 7 years ago

I got my issue fixed. Thanks for the help!

iBotPeaches commented 7 years ago

Thanks for responding, I will close this then as you were original OP.

PRITOM360 commented 1 week ago

Using APK template: lk.apk [-] No platform was selected, choosing Msf::Module::Platform::Android from the payload [-] No arch selected, selecting arch: dalvik from the payload [] Creating signing key and keystore.. [] Decompiling original APK.. [] Decompiling payload APK.. [] Locating hook point.. [] Adding payload as package com.ludo.king.zpajj [] Loading /tmp/d20241012-224329-mdnwp6/original/smali/androidx/multidex/MultiDexApplication.smali and injecting payload.. [] Poisoning the manifest with meterpreter permissions.. [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Adding [] Rebuilding apk with meterpreter injection as /tmp/d20241012-224329-mdnwp6/output.apk [-] I: Using Apktool 2.10.0 with 4 thread(s). I: Checking whether sources has changed... I: Smaling smali folder into classes.dex... I: Checking whether sources has changed... I: Smaling smali_classes2 folder into classes2.dex... I: Checking whether resources has changed... I: Building resources... Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 2): [/tmp/brut_util_Jar_44277879414236863901837929548511017006.tmp, compile, --dir, /tmp/d20241012-224329-mdnwp6/original/res, --legacy, -o, /tmp/d20241012-224329-mdnwp6/original/build/resources.zip] W: /tmp/brut_util_Jar_44277879414236863901837929548511017006.tmp: 1: ELF: not found W: /tmp/brut_util_Jar_44277879414236863901837929548511017006.tmp: 2: Syntax error: "(" unexpected [*] Unable to rebuild apk. Trying rebuild with AAPT2.. [-] I: Using Apktool 2.10.0 with 4 thread(s). I: Checking whether sources has changed... I: Smaling smali_classes2 folder into classes2.dex... I: Checking whether sources has changed... I: Smaling smali folder into classes.dex... I: Checking whether resources has changed... I: Building resources... Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 2): [/tmp/brut_util_Jar_118998977380578432877573095624164719184.tmp, compile, --dir, /tmp/d20241012-224329-mdnwp6/original/res, --legacy, -o, /tmp/d20241012-224329-mdnwp6/original/build/resources.zip] Error: Unable to rebuild apk with apktool

where is the problem actually?