def signApk(apkFile, keyStore, storepassword, keyalias, aliaspassword): if not os.path.exists(keyStore): print keyStore return 0 apkFile = file_operate.getFullPath(apkFile) keyStore = file_operate.getFullPath(keyStore) aapt = file_operate.getToolPath('aapt') listcmd = '%s list %s' % (aapt, apkFile) listcmd = listcmd.encode('gb2312') output = os.popen(listcmd).read() for filename in output.split('\n'): if filename.find('META-INF') == 0: rmcmd = '"%s" remove "%s" "%s"' % (aapt, apkFile, filename) bReturn = file_operate.execFormatCmd(rmcmd) jarsingnCmd = '"%sjarsigner" -keystore "%s" -storepass "%s" -keypass "%s" "%s" "%s" -sigalg SHA1withRSA -digestalg SHA1' % ( file_operate.getJavaBinDir(), keyStore, storepassword, aliaspassword, apkFile, keyalias) print jarsingnCmd ret = file_operate.execFormatCmd(jarsingnCmd) if ret: error_operate.error(140) return 1 return 0
def produceNewRFile(packName, decompileFullDir, androidManiFest='AndroidManifest.xml'): """ According to the merger of resources to create new R file """ fullPath = decompileFullDir tempPath = os.path.dirname(decompileFullDir) tempPath = tempPath + '/tempRFile' if os.path.exists(tempPath): file_operate.delete_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(decompileFullDir, 'res') targetResPath = os.path.join(tempPath, 'res') file_operate.copyFiles(resPath, targetResPath) genPath = os.path.join(tempPath, 'gen') if not os.path.exists(genPath): os.mkdir(genPath) androidPath = file_operate.getToolPath('android.jar') srcManifest = os.path.join(fullPath, androidManiFest) aaptPath = file_operate.getToolPath('aapt') cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % ( aaptPath, genPath, targetResPath, androidPath, srcManifest) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 RPath = packName.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % ( file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 #针对某系渠道通过R。xx来获取资源,在指定包名下添加R文件 try: config = ET.parse(file_operate.getConfigXmlPath()) root = config.getroot() Manifest = root.find("Manifest") num = int(Manifest.get('num')) for i in range(0, num): srcManifest_i = os.path.join( file_operate.getFullPath(constant.tmpPath), 'Manifest/' + str(i) + '/AndroidManifest.xml') cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % ( aaptPath, genPath, targetResPath, androidPath, srcManifest_i) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 packageNameArray = Manifest.get('packageNameArray') packageNameNode = packageNameArray.split(',')[i] RPath = packageNameNode.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % ( file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 except Exception, e: print e print "Error: cannot parse file: funcellconfig.xml."
def custom_package_r_file(self, packageName, androidManiFest = 'AndroidManifest.xml'): ''' create custom packageName R file :param packageName: :param androidManiFest: :return: ''' # bMerge = mergeValueXml(decompileFullDir) # if bMerge: # error_operate.error(102) # return 1 fullPath = self.__decompileDir tempPath = os.path.dirname(self.__decompileDir) tempPath = tempPath + '/tempRFile' if os.path.exists(tempPath): file_operate.delete_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(self.__decompileDir, 'res') targetResPath = os.path.join(tempPath, 'res') file_operate.copyFiles(resPath, targetResPath) genPath = os.path.join(tempPath, 'gen') if not os.path.exists(genPath): os.mkdir(genPath) androidPath = file_operate.getToolPath('android.jar') srcManifest = os.path.join(fullPath, androidManiFest) aaptPath = file_operate.getToolPath('aapt') cmd = '"%s" p -f -m -J "%s" --custom-package "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath, genPath, packageName, targetResPath, androidPath, srcManifest) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 RPath = packageName.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 dexPath = os.path.join(tempPath, 'class.dex') if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath) else: dxTool = file_operate.getToolPath('/lib/dx.jar') cmd = 'java -jar -Xms512m -Xmx512m "%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return 1 smaliPath = os.path.join(fullPath, 'smali') ret = apk_operate.dexTrans2Smali(dexPath, smaliPath, 10, 'baksmali.jar') if ret: return 1 else: return 0 pass