how to run apktool from webcode (php)

3

Essentially when a user uploads a .apk file I need to decode it and extract some information from the AndroidManifest.xml file inside the apk. When I run this command from command line apktool decode BluetoothChat.apk everything is fine. The output:

I: Baksmaling...
I: Loading resource table...
I: Loaded.
I: Loading resource table from file: /home/tashax/apktool/framework/1.apk
I: Loaded.
I: Decoding file-resources...
I: Decoding values*/* XMLs...
I: Done.
I: Copying assets and libs...

However, if I try to execute it from the webcode using php exec() function, I get an error. It fails on I: Loading resource table from file: /home/tashax/apktool/framework/1.apk, I'm thinking it cannot find the framework/1.apk file . This seems to be the setup issue, had anyone done something similar or knows what I'm missing? Here's are the errors from apktool when ran from web:

I: Baksmaling... 
I: Loading resource table... 
I: Loaded. 
W: Could not decode attr value, using undecoded value instead: ns=android, name=versionCode, value=0x00000001 
W: Could not decode attr value, using undecoded value instead: ns=android, name=versionName, value=0x0000000d 
Exception in thread "main" java.lang.NullPointerException at   java.io.Writer.write(Writer.java:157) 
at brut.androlib.res.util.ExtMXSerializer.writeAttributeValue(ExtMXSerializer.java:38) 
at org.xmlpull.mxp1_serializer.MXSerializer.attribute(MXSerializer.java:673) 
at   org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate.attribute(XmlSerializerDelegate.java:106) 
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.writeStartTag(StaticXmlSerializerWrapper.java:267) 
at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.event(StaticXmlSerializerWrapper.java:211) 
at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:46) 
at  brut.androlib.res.decoder.ResStreamDecoderContainer.decode(ResStreamDecoderContainer.java:34) 
at brut.androlib.res.decoder.ResFileDecoder.decode(ResFileDecoder.java:100) 
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:114) 
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:93) 
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98) 
at brut.apktool.Main.cmdDecode(Main.java:128) 
at brut.apktool.Main.main(Main.java:65)

Thanks!

php
apk
asked on Stack Overflow Mar 5, 2012 by t0x13

2 Answers

2

Finally, I found the root cause.

Please notice this line of output (run from command line): I: Loading resource table from file: /home/tashax/apktool/framework/1.apk

When apktool is run in PHP, the current user does not have home directory, then apktool would not be able to create ~/apktool/framework/1.apk successfully.

Check the options of apktool. There is an option to change framework files directory: --frame-path Use the specified directory for framework files

So, change the command line and add this option: apktool decode --frame-path /tmp BluetoothChat.apk

It works now.

answered on Stack Overflow Apr 11, 2014 by Frank He
0

This error

W: Could not decode attr value, using undecoded value instead: ns=android, name=versionName, value=0x0000000d

Means that the resource couldn't be found. The framework(s) you installed are either not from that ROM / Phone (Where-ever that APK originated from), or Apktool is out of date.

Apktool v1.5.0 has support up to Android 4.1.x, while Android 4.2 is not yet supported.

answered on Stack Overflow Dec 6, 2012 by Connor Tumbleson

User contributions licensed under CC BY-SA 3.0