批量反编译Android XML文件Python脚本

来源:互联网 发布:帝国cms定时采集 编辑:程序博客网 时间:2024/04/30 00:23

             学习Android的过程中,难免有时候会反编译别人的APK文件,而解压APK后的XML文件数量众多,如果要逐个地敲命令来反编译的话未免太麻烦了点,于是写了个Python脚本来完成批量反编译的工作,现把代码贴上:

'''利用AXMLPrinter2.jar反编译Android的xml文件使用:decompile.py pathpath:文件路径,如:F:/Android/apk@author: Administrator'''import sysimport osdef decompile(pathname):    for root,dirs,files in os.walk(pathname):        for file in files:            if file.endswith('.xml'):                newname = file[:len(file)-3]+"txt"                os.chdir(root)                command = 'java -jar %s %s > %s'%(pathname+'AXMLPrinter2.jar',file,newname)                if(os.system(command) == 0):                    print('成功:',command)                    os.remove(file)                    os.rename(newname, file)                else:                    print('失败:',command)                if(len(sys.argv)<2):    print("缺少参数,示例:decompile.py F:/apk/")else:    path = sys.argv[1]        if(not(path.endswith('/') | path.endswith('\\'))):        path += os.sep        print(path)    decompile(path)


注:这里用到的反编译XML文件的工具是AXMLPrinter2.jar,使用时将AXMLPrinter2.jar放到你要反编译XML文件的目录下,如,要反编译 F:\360Downloads\Apk\mojitianqi\  目录下及其子目录下的所有xml文件,只需将AXMLPrinter.jar放入F:\360Downloads\Apk\mojitianqi\ 目录下,然后执行decompile.py F:\360Downloads\Apk\mojitianqi 即可将该目录及其子目录下的所有XML文件反编译:

 

原创粉丝点击