Apktool: apktool build "-d" option (Sets android:debuggable to "true") does not work

Created on 25 Sep 2017  Â·  4Comments  Â·  Source: iBotPeaches/Apktool

Information

  1. Apktool Version (apktool -version) - 2.2.4
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) - N/A

The option that is not working is:

usage: apktool [-q|--quiet OR -v|--verbose] b[uild] [options] <app_path>
...
 -d,--debug              Sets android:debuggable to "true" in the APK's compiled manifest
...

When the option is specified in the apktool arguments, it is processed at:
apkOptions.debugMode = true;

Ref: https://github.com/iBotPeaches/Apktool/blob/212330e0c990b69a948aff4027190177fe217f81/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java#L203

This value is used at:
ResXmlPatcher.removeApplicationDebugTag(new File(appDir, "AndroidManifest.xml"));

Ref: https://github.com/iBotPeaches/Apktool/blob/212330e0c990b69a948aff4027190177fe217f81/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java#L461

This method is in fact removing the "android:debuggable" item from the AndroidMAnifest.xml file, rather than setting it to "true".

Ref: https://github.com/iBotPeaches/Apktool/blob/212330e0c990b69a948aff4027190177fe217f81/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java#L69

Steps to Reproduce

  1. apktool d app.apk
  2. apktool b -d <app_dir>

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? Yes
  2. If you are trying to install a modified apk, did you resign it? N/A
  3. Are you using the latest apktool version? Yes

Most helpful comment

Hi @iBotPeaches:
I have been able to reproduce this issue based on your explanation. The debuggable flags is not added when the APK is decoded first with the "-r" flag, as the resources are not decoded and, therefore, "aapt" cannot add the flag during the build process.

I think it would be very useful to be able to use the "-d" flag during the build process even when the "-r" (and "-s") flags are used during the decoding process, with the goal of minimizing the changes performed over the APK.

I was originally expecting this, assuming that apktool was simply and directly modifying the AndroidManifest.xml file, rather than using "aapt".

Do you think this could be considered as a potential future request for apktool to be able to run "apktool d -r -s app.apk" and "apktool b -d "?

All 4 comments

So, we remove the element yes, but thats because we apply the debuggable trait at the aapt level. If you leave the property in, aapt fails. So we strip it out in debug mode, so that we know aapt can properly add.

I'm not sure if you discovered this in a code audit, but I tested with an actual application and could not replicate this.

I did a simple decode/build to test this and it worked.

➜  dist aapt d xmltree app-debug.apk AndroidManifest.xml
    E: application (line=3)
      A: android:theme(0x01010000)=@0x7f0900a6
      A: android:label(0x01010001)=@0x7f070022
      A: android:icon(0x01010002)=@0x7f030000
      A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff

Closing as I couldn't duplicate. Thanks for the detailed report, makes my life a lot easier when digging into tickets.

You can see the line responsible here - https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java#L365

Hi @iBotPeaches:
I have been able to reproduce this issue based on your explanation. The debuggable flags is not added when the APK is decoded first with the "-r" flag, as the resources are not decoded and, therefore, "aapt" cannot add the flag during the build process.

I think it would be very useful to be able to use the "-d" flag during the build process even when the "-r" (and "-s") flags are used during the decoding process, with the goal of minimizing the changes performed over the APK.

I was originally expecting this, assuming that apktool was simply and directly modifying the AndroidManifest.xml file, rather than using "aapt".

Do you think this could be considered as a potential future request for apktool to be able to run "apktool d -r -s app.apk" and "apktool b -d "?

@raulsiles @iBotPeaches this would be just what I am looking for. For some reason repackaging without -r fails

after I use Apktool v2.2.1 When change manifest and add android:debuggable="true" and build again, the manifest not change? why
1.apktool d main.apk
2.change manifest and add android:debuggable="true"
3.apktool b main

Was this page helpful?
0 / 5 - 0 ratings