def generateNewRFile(newPackageName, decompileDir): """ Use all new resources to generate the new R.java, and compile it ,then copy it to the target smali dir """ ret = checkValueResources(decompileDir) if ret: return 1 decompileDir = file_utils.getFullPath(decompileDir) tempPath = os.path.dirname(decompileDir) tempPath = tempPath + "/temp" log_utils.debug("generate R:the temp path is %s", tempPath) if os.path.exists(tempPath): file_utils.del_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(decompileDir, "res") targetResPath = os.path.join(tempPath, "res") file_utils.copy_files(resPath, targetResPath) genPath = os.path.join(tempPath, "gen") if not os.path.exists(genPath): os.makedirs(genPath) aaptPath = file_utils.getFullToolPath("aapt") androidPath = file_utils.getFullToolPath("android.jar") manifestPath = os.path.join(decompileDir, "AndroidManifest.xml") cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath, genPath, targetResPath, androidPath, manifestPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 rPath = newPackageName.replace('.', '/') rPath = os.path.join(genPath, rPath) rPath = os.path.join(rPath, "R.java") cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_utils.getJavaBinDir(), rPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 targetDexPath = os.path.join(tempPath, "classes.dex") dexToolPath = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dexToolPath, targetDexPath, genPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 smaliPath = os.path.join(decompileDir, "smali") ret = dex2smali(targetDexPath, smaliPath, "baksmali.jar") return ret
def copyRootResFiles(apkfile, decompileDir): apkfile = file_utils.getFullPath(apkfile) aapt = file_utils.getFullToolPath("aapt") decompileDir = file_utils.getFullPath(decompileDir) igoreFiles = ['AndroidManifest.xml','apktool.yml', 'smali', 'res', 'original','lib','build','assets','unknown'] igoreFileFullPaths = [] for ifile in igoreFiles: fullpath = os.path.join(decompileDir, ifile) igoreFileFullPaths.append(fullpath) addFiles = [] addFiles = file_utils.list_files(decompileDir, addFiles, igoreFileFullPaths) if len(addFiles) <= 0: return addCmd = '"%s" add "%s"' for f in addFiles: fname = f[(len(decompileDir)+1):] addCmd = addCmd + ' ' + fname addCmd = addCmd % (aapt, apkfile) currPath = os.getcwd() os.chdir(decompileDir) file_utils.execFormatCmd(addCmd) os.chdir(currPath)
def signApkInternal(apkfile, keystore, password, alias, aliaspwd, sigalg): apkfile = file_utils.getFullPath(apkfile) keystore = file_utils.getFullPath(keystore) aapt = file_utils.getFullToolPath("aapt") if not os.path.exists(keystore): log_utils.error("the keystore file is not exists. %s", keystore) return 1 listcmd = '%s list %s' % (aapt, apkfile) 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) file_utils.execFormatCmd(rmcmd) if sigalg is None: sigalg = "SHA1withRSA" signcmd = '"%sjarsigner" -digestalg SHA1 -sigalg %s -keystore "%s" -storepass "%s" -keypass "%s" "%s" "%s" ' % ( file_utils.getJavaBinDir(), sigalg, keystore, password, aliaspwd, apkfile, alias) ret = file_utils.execFormatCmd(signcmd) return ret
def handleWXPayActivity(channel, decompileDir, packageName, className, oldPackageName): sdkDir = decompileDir + '/../sdk/' + channel['sdk'] if not os.path.exists(sdkDir): file_utils.printF("The sdk temp folder is not exists. path:" + sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' relatedJar = os.path.join(extraFilesPath, 'vivoUnionSDK.jar') relatedJar2 = os.path.join(extraFilesPath, 'libammsdk.jar') WXPayEntryActivity = os.path.join(extraFilesPath, className + '.java') file_utils.modifyFileContent(WXPayEntryActivity, oldPackageName, packageName + ".wxapi") splitdot = ';' if platform.system() == 'Darwin': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"%s"%s"' % ( file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, relatedJar2, splitdot, file_utils.getFullToolPath('android.jar')) ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir + '/wxapi' if not os.path.exists(classDir): os.makedirs(classDir) sourceClassFilePath = os.path.join(extraFilesPath, className + '.class') targetClassFilePath = classDir + '/' + className + '.class' file_utils.copy_file(sourceClassFilePath, targetClassFilePath) targetDexPath = os.path.join(sdkDir, className + '.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD( ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % ( dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = sdk_helper.dex2smali(targetDexPath, decompileDir + '/smali', "baksmali.jar") if ret: return 1 return 0
def xsigncode(workDir, game, channel, apkfile): xignClearcmd = '"%sxapk_sign clean" "%s" ' % (file_utils.getXignDir(), apkfile) file_utils.execFormatCmd(xignClearcmd) xigncmd = '"%sxapk_sign" "%s" ' % (file_utils.getXignDir(), apkfile) file_utils.execFormatCmd(xigncmd) signApk(workDir, game, channel, apkfile)
def compileWXEntryActivity(channel, decompileDir, packageName): sdkDir = decompileDir + '/../sdk/' + channel['sdk'] if not os.path.exists(sdkDir): file_utils.printF("The sdk temp folder is not exists. path:"+sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' relatedJar = os.path.join(extraFilesPath, 'MSDK_Android.jar') WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java') file_utils.modifyFileContent(WXPayEntryActivity, 'com.example.wegame.wxapi', packageName+".wxapi") splitdot = ';' if platform.system() == 'Darwin': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar')) ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir + '/wxapi' if not os.path.exists(classDir): os.makedirs(classDir) sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class') targetClassFilePath = classDir + '/WXEntryActivity.class' file_utils.copy_file(sourceClassFilePath, targetClassFilePath) targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = apk_utils.dex2smali(targetDexPath, decompileDir+'/smali', "baksmali.jar") if ret: return 1
def dex2smali(dexFile, targetdir, dextool="baksmali.jar"): """ Transfer the dex to smali. """ if not os.path.exists(dexFile): log_utils.error("the dexfile is not exists. path:%s", dexFile) return 1 if not os.path.exists(targetdir): os.makedirs(targetdir) smaliTool = file_utils.getFullToolPath(dextool) dexPath = os.path.dirname(dexFile) dexName = os.path.basename(dexFile) (dexBaseName, ext) = os.path.splitext(dexName) dexIndex = 2 dexFilePath = os.path.join(dexPath, dexName) while os.path.exists(dexFilePath): cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFilePath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 dexFilePath = os.path.join(dexPath, dexBaseName + str(dexIndex) + ext) dexIndex = dexIndex + 1 # for k in range(1, 10): # baseName = dexBaseName # if k > 1: # baseName = baseName + str(k) # baseName = baseName + ext # dexFilePath = os.path.join(dexPath, baseName) # cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFilePath) # ret = file_utils.execFormatCmd(cmd) # if ret: # return 1 # if os.path.exists(dexFilePath): # if platform.system() == 'Darwin' or platform.system() == 'Linux': # cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFilePath) # ret = file_utils.execFormatCmd(cmd) # if ret: # return 1 # else: # cmd = '"%s" -jar "%s" disassemble -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFilePath) # ret = file_utils.execFormatCmd(cmd) # if ret: # return 1 return 0
def alignApk(apkfile, targetapkfile): """ zip align the apk file """ align = file_utils.getFullToolPath('zipalign') aligncmd = '"%s" -f 4 "%s" "%s"' % (align, apkfile, targetapkfile) ret = file_utils.execFormatCmd(aligncmd) return ret
def signApkInternal(apkfile, keystore, password, alias, aliaspwd): apkfile = file_utils.getFullPath(apkfile) keystore = file_utils.getFullPath(keystore) aapt = file_utils.getFullToolPath("aapt") if not os.path.exists(keystore): log_utils.error("the keystore file is not exists. %s", keystore) return 1 listcmd = '%s list %s' % (aapt, apkfile) 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) file_utils.execFormatCmd(rmcmd) signcmd = '"%sjarsigner" -digestalg SHA1 -sigalg SHA1withRSA -keystore "%s" -storepass "%s" -keypass "%s" "%s" "%s" ' % (file_utils.getJavaBinDir(), keystore, password, aliaspwd, apkfile, alias) ret = file_utils.execFormatCmd(signcmd) return ret
def decompileApk(source, targetdir, apktool = "apktool2.jar"): """ Decompile apk """ apkfile = file_utils.getFullPath(source) targetdir = file_utils.getFullPath(targetdir) apktool = file_utils.getFullToolPath(apktool) if os.path.exists(targetdir): file_utils.del_file_folder(targetdir) if not os.path.exists(targetdir): os.makedirs(targetdir) cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q d -b -f "%s" -o "%s"' % (file_utils.getJavaCMD(), apktool, apkfile, targetdir) #cmd = '"%s" -q d -d -f "%s" "%s"' % (apktool, apkfile, targetdir) #print("decompile cmd : "+ cmd) ret = file_utils.execFormatCmd(cmd) return ret
def recompileApk(sourcefolder, apkfile, apktool = "apktool2.jar"): """ Recompile apk """ os.chdir(file_utils.curDir) sourcefolder = file_utils.getFullPath(sourcefolder) apkfile = file_utils.getFullPath(apkfile) apktool = file_utils.getFullToolPath(apktool) ret = 1 if os.path.exists(sourcefolder): cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q b -f "%s" -o "%s"' % (file_utils.getJavaCMD(), apktool, sourcefolder, apkfile) #cmd = '"%s" -q b -f "%s" "%s"' % (apktool, sourcefolder, apkfile) ret = file_utils.execFormatCmd(cmd) return ret
def jar2dex(srcDir, dstDir, dextool = "baksmali.jar"): """ compile jar files to dex. """ dexToolPath = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xms512m -Xmx512m "%s" --dex --output="%s" ' % (dexToolPath, dstDir+"/classes.dex") for f in os.listdir(srcDir): if f.endswith(".jar"): cmd = cmd + " " + os.path.join(srcDir, f) libsPath = os.path.join(srcDir, "libs") if os.path.exists(libsPath): for f in os.listdir(libsPath): if f.endswith(".jar"): cmd = cmd + " " + os.path.join(srcDir, "libs", f) ret = file_utils.execFormatCmd(cmd)
def dex2smali(dexFile, targetdir, dextool = "baksmali.jar"): """ Transfer the dex to smali. """ if not os.path.exists(dexFile): log_utils.error("the dexfile is not exists. path:%s", dexFile) return 1 if not os.path.exists(targetdir): os.makedirs(targetdir) dexFile = file_utils.getFullPath(dexFile) smaliTool = file_utils.getFullToolPath(dextool) targetdir = file_utils.getFullPath(targetdir) cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFile) ret = file_utils.execFormatCmd(cmd) return ret
def compileJava2Smali(channel, decompileDir, packageName, className, dependencyLibs): sdkDir = decompileDir + '/../sdk/' + channel['sdk'] if not os.path.exists(sdkDir): file_utils.printF("The sdk temp folder is not exists. path:" + sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' # relatedJar = os.path.join(extraFilesPath, 'vivoUnionSDK.jar') # relatedJar2 = os.path.join(extraFilesPath, 'libammsdk.jar') if not os.path.exists(extraFilesPath): log_utils.error("compileJava2Smali failed. please put java file and related jars in extraFiles folder") return 1 javaFile = os.path.join(extraFilesPath, className + '.java') replaceJavaPackage(javaFile, packageName) splitdot = ';' if platform.system() == 'Darwin' or platform.system() == 'Linux': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath ' % (file_utils.getJavaBinDir(), javaFile) for lib in dependencyLibs: cmd = cmd + '"' + os.path.join(extraFilesPath, lib) + '"' + splitdot cmd = cmd + '"' + file_utils.getFullToolPath('android.jar') + '"' ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir if not os.path.exists(classDir): os.makedirs(classDir) classFiles = file_utils.list_files_with_ext(extraFilesPath, [], '.class') for cf in classFiles: targetClassFilePath = os.path.join(classDir, os.path.basename(cf)) file_utils.copy_file(cf, targetClassFilePath) targetDexPath = os.path.join(sdkDir, className + '.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % ( dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = dex2smali(targetDexPath, decompileDir + '/smali', "baksmali.jar") if ret: return 1 return 0
def generateWXEntryActivity(channel, pluginInfo, decompileDir, packageName): sdkDir = decompileDir + '/../plugins/' + pluginInfo['name'] if not os.path.exists(sdkDir): file_utils.printF("The plugin temp folder is not exists. path:" + sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' relatedJar = os.path.join(extraFilesPath, 'ShareSDK-Wechat-Core.jar') WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java') file_utils.modifyFileContent(WXPayEntryActivity, 'cn.sharesdk.socialization.sample.wxapi', packageName + ".wxapi") splitdot = ';' if platform.system() == 'Darwin': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % ( file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar')) ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir + '/wxapi' if not os.path.exists(classDir): os.makedirs(classDir) sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class') targetClassFilePath = classDir + '/WXEntryActivity.class' file_utils.copy_file(sourceClassFilePath, targetClassFilePath) targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD( ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % ( dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = apk_utils.dex2smali(targetDexPath, decompileDir + '/smali') if ret: return 1 manifest = decompileDir + '/AndroidManifest.xml' ET.register_namespace('android', androidNS) name = '{' + androidNS + '}name' theme = '{' + androidNS + '}theme' configChanges = '{' + androidNS + '}configChanges' exported = '{' + androidNS + '}exported' screenOrientation = '{' + androidNS + '}screenOrientation' tree = ET.parse(manifest) root = tree.getroot() appNode = root.find('application') if appNode is None: return 1 activityNode = SubElement(appNode, 'activity') activityNode.set(name, packageName + '.wxapi.WXEntryActivity') activityNode.set(theme, '@android:style/Theme.Translucent.NoTitleBar') activityNode.set(configChanges, 'keyboardHidden|orientation') activityNode.set(exported, 'true') activityNode.set(screenOrientation, 'portrait') tree.write(manifest, 'UTF-8') return 0
def execute(channel, decompileDir, packageName): sdkDir = decompileDir + '/../sdk/' + channel['sdk'] if not os.path.exists(sdkDir): file_utils.printF("The sdk temp folder is not exists. path:" + sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' relatedJar = os.path.join(extraFilesPath, '360SDK.jar') WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java') file_utils.modifyFileContent(WXPayEntryActivity, 'com.u8.sdk.qh360.wxapi', packageName + ".wxapi") splitdot = ';' if platform.system() == 'Darwin': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % ( file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar')) ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir + '/wxapi' if not os.path.exists(classDir): os.makedirs(classDir) sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class') targetClassFilePath = classDir + '/WXEntryActivity.class' file_utils.copy_file(sourceClassFilePath, targetClassFilePath) targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD( ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % ( dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = apk_utils.dex2smali(targetDexPath, decompileDir + '/smali') if ret: return 1 manifest = decompileDir + '/AndroidManifest.xml' ET.register_namespace('android', androidNS) name = '{' + androidNS + '}name' hostKey = '{' + androidNS + '}host' configChanges = '{' + androidNS + '}configChanges' exported = '{' + androidNS + '}exported' screenOrientation = '{' + androidNS + '}screenOrientation' authoritiesKey = '{' + androidNS + '}authorities' tree = ET.parse(manifest) root = tree.getroot() appNode = root.find('application') if appNode is None: return 1 activityNode = SubElement(appNode, 'activity') activityNode.set(name, packageName + '.wxapi.WXEntryActivity') activityNode.set(configChanges, 'keyboardHidden|orientation') activityNode.set(exported, 'true') activityNode.set(screenOrientation, 'portrait') # appkey = "" # if 'params' in channel: # params = channel['params'] # for param in params: # if param['name'] == 'QHOPENSDK_APPKEY': # appkey = param['value'] # break #append host activityNodeLst = appNode.findall('activity') if activityNodeLst is not None and len(activityNodeLst) > 0: for activityNode in activityNodeLst: activityName = activityNode.get(name) if activityName == 'com.qihoo.gamecenter.sdk.activity.ContainerActivity': intentNodeLst = activityNode.findall('intent-filter') if intentNodeLst is not None: for itNode in intentNodeLst: dataNode = SubElement(itNode, 'data') dataNode.set(hostKey, packageName) # elif activityName == 'com.qihoo.gamecenter.sdk.activity.QhDeepLinkActivity': # intentNodeLst = activityNode.findall('intent-filter') # if intentNodeLst is not None: # for itNode in intentNodeLst: # dataNodeLst = itNode.findall('data') # if dataNodeLst is not None: # for dNode in dataNodeLst: # dNode.set(hostKey, appkey) # break providerNodeLst = appNode.findall("provider") if providerNodeLst is not None and len(providerNodeLst) > 0: for pNode in providerNodeLst: pName = pNode.get(name) if pName == 'com.qihoo.pushsdk.keepalive.account.SyncProvider': pNode.set(authoritiesKey, packageName + ".cx.accounts.syncprovider") tree.write(manifest, 'UTF-8') #modify res/xml/qihoo_game_sdk_sync_adapter.xml resXml = decompileDir + '/res/xml/qihoo_game_sdk_sync_adapter.xml' if os.path.exists(resXml): file_utils.modifyFileContent( resXml, 'com.qihoo.gamecenter.sdk.demosp.cx.accounts.syncprovider', packageName + ".cx.accounts.syncprovider") return 0
def execute(channel, decompileDir, packageName): sdkDir = decompileDir + '/../sdk/' + channel['sdk'] if not os.path.exists(sdkDir): file_utils.printF("The sdk temp folder is not exists. path:"+sdkDir) return 1 extraFilesPath = sdkDir + '/extraFiles' relatedJar = os.path.join(extraFilesPath, '360SDK.jar') WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java') file_utils.modifyFileContent(WXPayEntryActivity, 'com.u8.sdk.qh360.wxapi', packageName+".wxapi") splitdot = ';' if platform.system() == 'Darwin': splitdot = ':' cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar')) ret = file_utils.execFormatCmd(cmd) if ret: return 1 packageDir = packageName.replace('.', '/') srcDir = sdkDir + '/tempDex' classDir = srcDir + '/' + packageDir + '/wxapi' if not os.path.exists(classDir): os.makedirs(classDir) sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class') targetClassFilePath = classDir + '/WXEntryActivity.class' file_utils.copy_file(sourceClassFilePath, targetClassFilePath) targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex') dxTool = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dxTool, targetDexPath, srcDir) ret = file_utils.execFormatCmd(cmd) if ret: return 1 ret = apk_utils.dex2smali(targetDexPath, decompileDir+'/smali', "baksmali.jar") if ret: return 1 manifest = decompileDir + '/AndroidManifest.xml' ET.register_namespace('android', androidNS) name = '{' + androidNS + '}name' hostKey = '{'+androidNS+'}host' configChanges = '{' + androidNS + '}configChanges' exported = '{' + androidNS + '}exported' screenOrientation = '{' + androidNS + '}screenOrientation' tree = ET.parse(manifest) root = tree.getroot() appNode = root.find('application') if appNode is None: return 1 activityNode = SubElement(appNode, 'activity') activityNode.set(name, packageName + '.wxapi.WXEntryActivity') activityNode.set(configChanges, 'keyboardHidden|orientation') activityNode.set(exported, 'true') activityNode.set(screenOrientation, 'portrait') #append host activityNodeLst = appNode.findall('activity') if activityNodeLst is not None and len(activityNodeLst) > 0: for activityNode in activityNodeLst: activityName = activityNode.get(name) if activityName == 'com.qihoo.gamecenter.sdk.activity.ContainerActivity': intentNodeLst = activityNode.findall('intent-filter') find = False if intentNodeLst is not None: for itNode in intentNodeLst: dataNodeList = itNode.findall('data') for dataNode in dataNodeList : if dataNode.get(hostKey) == 'com.qihoo.gamecenter.sdk.demosp': dataNode.set(hostKey, packageName) find = True break if find: break tree.write(manifest, 'UTF-8') return 0