Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run apktool from webcode (php)

Tags:

php

apk

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!

like image 961
t0x13 Avatar asked Feb 06 '26 18:02

t0x13


1 Answers

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.

like image 166
Frank He Avatar answered Feb 12 '26 16:02

Frank He



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!