python apktool_Python Decompile APK using ApkTool and Subprocess

I am builing a Python Application that decompiles Android APK makes some modifications and recompiles it.

Here is the code:

from shutil import copyfile

# Copy the APK to the output directory.

copyfile('./source/rat.apk', './output/rat.apk')

# Decompiles the APK.

subprocess.call(['apktool','d','./output/rat.apk','-f'], stdout=FNULL, stderr=subprocess.STDOUT)

# Modifies address and port.

with open('./output/RAT/app/src/main/res/values/strings.xml','w+') as netaddress:

address = netaddress.read()

address.replace('youraddress','x')

address.replace('yourport','8080')

netaddress.write(address)

print(netaddress.read())

netaddress.close()

# Recompiles it.

subprocess.call(['apktool','b','./output/RAT'], stdout=FNULL, stderr=subprocess.STDOUT)

But it throws this Exception when running:

with open('./output/RAT/app/src/main/res/values/strings.xml','w+') as netaddress:

FileNotFoundError: [Errno 2] No such file or directory: './output/RAT/app/src/main/res/values/strings.xml'

Update:

When i try to use the command apktool d source/rat.apk

This is the output i receive:

18:45:51 up 1 min, 0 users, load average: 0.52, 0.58, 0.59

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

I: Using Apktool 2.0.2-dirty on rat.apk

I: Loading resource table...

I: Decoding AndroidManifest.xml with resources...

I: Loading resource table from file: /home/stecco/apktool/framework/1.apk

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

I: Loading resource table from file: /home/stecco/apktool/framework/1.apk

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

I: Loading resource table from file: /home/stecco/apktool/framework/1.apk

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

I: Loading resource table from file: /home/stecco/apktool/framework/1.apk

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

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:696)

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$1.event(XmlPullStreamDecoder.java:83)

at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:141)

at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)

at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:140)

at brut.androlib.res.AndrolibResources.decodeManifestWithResources(AndrolibResources.java:199)

at brut.androlib.Androlib.decodeManifestWithResources(Androlib.java:140)

at brut.androlib.ApkDecoder.decode(ApkDecoder.java:100)

at brut.apktool.Main.cmdDecode(Main.java:165)

at brut.apktool.Main.main(Main.java:81)

Solved every problem by installing Apktool 2.4.0 it seems that the version 2.0.2 it's really buggy and even 2.2.2 and 2.3.2.

But another problem came up when i try to recompile it it gives me a classes.dex not an apk how can i solve this?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值