def execute(channel, pluginInfo, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, "${packageName}", packageName) return 0
def modify_gradle_dependencies(projPath, dependencyList): dependencyStr = "" for d in dependencyList: name = d['name'] excludes = None if 'excludes' in d: excludes = d['excludes'] name = name.strip() if excludes == None: dependencyStr += "scm '" + name + "'\n\t" else: dependencyStr += "scm('" + name + "'){\n\t" + parse_excludes( excludes) dependencyStr += "\n\t}\n\t" buildPath = os.path.join(projPath, 'app/build.gradle') if not os.path.exists(buildPath): log_utils.error("build.gradle is not exists: %s", buildPath) return False file_utils.modifyFileContent(buildPath, "${U8_DEPENDENCIES_PLACEHOLDER}", dependencyStr) return True
def execute(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, "${applicationId}", packageName)
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 modify_gradle_dependencies_path(projPath, path): buildPath = os.path.join(projPath, 'app/build.gradle') if not os.path.exists(buildPath): log_utils.error("build.gradle is not exists: %s", buildPath) return False file_utils.modifyFileContent(buildPath, "${U8_SDK_LIBS_FOLDER}", path) return True
def execute(channel, pluginInfo, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, "${applicationId}", packageName) sdk_helper.setPropOnApplicationNode(decompileDir, "{"+androidNS+"}hardwareAccelerated", "true") return 0
def execute(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, "${applicationId}", packageName) sdk_helper.setPropOnApplicationNode( decompileDir, '{' + androidNS + '}networkSecurityConfig', '@xml/network_security_config') return 0
def handleAutoResDefined(decompileDir, packageName): resPath = decompileDir + "/res" files = [] file_utils.list_files(resPath, files, []) for f in files: if (not f.endswith(".xml")): continue file_utils.modifyFileContent(f, 'http://schemas.android.com/apk/res-auto', 'http://schemas.android.com/apk/lib/' + packageName)
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 execute(channel, decompileDir, packageName): activityName = sdk_helper.removeStartActivity( decompileDir, 'com.u8.sdk.QuickSplashActivity') smaliPath = os.path.join(decompileDir, 'smali/com/u8/sdk/QuickSplashActivity.smali') file_utils.modifyFileContent(smaliPath, "${Game_Launch_Activity}", activityName) sdk_helper.modifyRootApplicationExtends( decompileDir, 'com.quicksdk.QuickSdkApplication') return 0
def execute(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, "${applicationId}", packageName) appId = sdk_helper.getSdkParamByKey(channel, 'HuaWei_AppID') cpId = sdk_helper.getSdkParamByKey(channel, 'HuaWei_CPID') log_utils.debug("huawei appId:" + appId + ";cpId:" + cpId) sdk_helper.addOrUpdateMetaData(decompileDir, 'com.huawei.hms.client.appid', 'appid=' + appId) sdk_helper.addOrUpdateMetaData(decompileDir, 'com.huawei.hms.client.cpid', 'cpid=' + cpId)
def execute(channel, pluginInfo, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" file_utils.modifyFileContent(manifestFile, '${applicationId}', packageName) if 'params' in pluginInfo and len(pluginInfo['params']) > 0: for param in pluginInfo['params']: name = param.get('name') if name == 'UM_PUSH_CHANNEL': param['value'] = channel['name'] break #sdk_helper.handleAutoResDefined(decompileDir, 'android.support.v7.appcompat') sdk_helper.modifyRootApplicationExtends( decompileDir, 'com.u8.sdk.UmengProxyApplication') return 0
def modify_app_name(manifestFile, gameName): """ modify app name """ delete_label_in_activity(manifestFile) file_utils.modifyFileContent(manifestFile, '@string/app_name', gameName) ET.register_namespace('android', androidNS) tree = ET.parse(manifestFile) root = tree.getroot() labelKey = '{' + androidNS + '}label' applicationNode = root.find('application') applicationNode.set(labelKey, gameName) tree.write(manifestFile, 'UTF-8')
def renameSmaliPackage(smaliRoot, clsName, srcPackage, dstPackage): srcPkgPath = srcPackage.replace('.', '/') dstPkgPath = dstPackage.replace('.', '/') srcDir = os.path.join(smaliRoot, srcPkgPath) dstDir = os.path.join(smaliRoot, dstPkgPath) srcFile = os.path.join(srcDir, clsName+".smali") dstFile = os.path.join(dstDir, clsName+".smali") if not os.path.exists(srcFile): print("error renamePackage: file not exist - "+srcFile) return -1 if not os.path.exists(dstDir): os.makedirs(dstDir) shutil.copy2(srcFile, dstFile) os.remove(srcFile) if len(os.listdir(srcDir)) == 0: os.rmdir(srcDir) file_utils.modifyFileContent(dstFile, srcPkgPath, dstPkgPath)
def modifyManifest(channel, decompileDir, packageName): qqAppID = "" wxAppID = "" if 'params' in channel: params = channel['params'] for param in params: if param['name'] == 'QQ_APP_ID': qqAppID = param['value'] elif param['name'] == 'WX_APP_ID': wxAppID = param['value'] manifest = decompileDir + '/AndroidManifest.xml' file_utils.modifyFileContent(manifest, '${applicationId}', packageName) file_utils.modifyFileContent(manifest, '${YSDK_QQ_APPID}', qqAppID) file_utils.modifyFileContent(manifest, '${YSDK_WX_APPID}', wxAppID)
def create_proj(projPath, targetName, classPrefix): if not os.path.exists(projPath): log_utils.debug("the U8SDK_Projects dir is not exists." + projPath) return templatePath = os.path.join(projPath, "U8SDK_Template") if not os.path.exists(templatePath): log_utils.debug("the template project is not exists." + templatePath) return if not targetName.startswith("U8SDK_"): targetName = "U8SDK_" + targetName targetPath = os.path.join(projPath, targetName) if os.path.exists(targetPath): log_utils.debug("the target project is already exists." + targetPath) return file_utils.copy_files(templatePath, targetPath) srcPath = os.path.join(targetPath, "src/com/u8/sdk") for f in os.listdir(srcPath): fname = os.path.join(srcPath, f) file_utils.modifyFileContent(fname, "Temp", classPrefix) ftarget = f.replace("Temp", classPrefix) os.rename(fname, os.path.join(srcPath, ftarget)) configPath = os.path.join(targetPath, "config.xml") file_utils.modifyFileContent(configPath, "Temp", classPrefix) projFilePath = os.path.join(targetPath, ".project") file_utils.modifyFileContent(projFilePath, "U8SDK_Template", targetName)
def handle_auto_permission(game, channel, decompileDir): autoPermission = False directPermission = False protocolUrl = "file:///android_asset/m_userprotocol.html" if 'autoPermission' in channel and len(str( channel['autoPermission'])) > 0 and str( channel['autoPermission']) == '1': autoPermission = True elif 'autoPermission' in game and len( game['autoPermission']) > 0 and game['autoPermission'] == '1': autoPermission = True if 'noPermission' in channel and len( channel['noPermission']) > 0 and channel['noPermission'] == '1': autoPermission = False elif 'noPermission' in game and len( game['noPermission']) > 0 and game['noPermission'] == '1': autoPermission = False if not autoPermission: log_utils.debug("autoPermission not enabled.") return excludeGroups = None if "excludePermissionGroups" in channel and channel[ "excludePermissionGroups"] != None and len( channel['excludePermissionGroups']) > 0: excludeGroups = channel['excludePermissionGroups'].split(',') elif "excludePermissionGroups" in game and game[ "excludePermissionGroups"] != None and len( game['excludePermissionGroups']) > 0: excludeGroups = game['excludePermissionGroups'].split(',') if 'directPermission' in channel and len(str( channel['directPermission'])) > 0 and str( channel['directPermission']) == '1': directPermission = True elif 'directPermission' in game and len( game['directPermission']) > 0 and game['directPermission'] == '1': directPermission = True else: directPermission = False autoProtocol = True log_utils.debug("auto protocol:" + str(channel['autoProtocol'])) if 'autoProtocol' in channel and len(str( channel['autoProtocol'])) > 0 and str( channel['autoProtocol']) == '0': autoProtocol = False if autoProtocol: if 'protocolUrl' in channel and len(channel['protocolUrl']) > 0: protocolUrl = channel['protocolUrl'] elif 'protocolUrl' in game and len(game['protocolUrl']) > 0: protocolUrl = game['protocolUrl'] else: protocolUrl = None manifestFile = os.path.join(decompileDir, 'AndroidManifest.xml') permissions = get_dangerous_permissions(manifestFile, excludeGroups) if permissions == None or len(permissions) == 0: log_utils.debug( "there is no dangerous permission. just ignore auto permission") return isLandscape = False if game["orientation"] == 'landscape': isLandscape = True write_dangerous_permissions(manifestFile, decompileDir, permissions, protocolUrl, isLandscape) if directPermission: log_utils.debug( "curr permission request type is direct permission. no permission activity need" ) return # remove original launcher activity of the game activityName = manifest_utils.remove_start_activity(manifestFile) append_permission_activity(manifestFile, isLandscape, activityName) smaliTargetPath = decompileDir + "/smali" # if U8PermissionActivity.smali may exists in smali, smali_classes2, smali_classes3... retryNum = 1 while retryNum > 0: curPath = smaliTargetPath if retryNum > 1: curPath = smaliTargetPath + "_classes" + str(retryNum) if not os.path.exists(curPath): retryNum = -1 else: retryNum = retryNum + 1 permissionActivityPath = curPath + "/com/u8/sdk/permission/U8PermissionActivity.smali" file_utils.modifyFileContent(permissionActivityPath, '{U8SDK_Permission_Next_Activity}', activityName) log_utils.info("modify permission smali file success.")
def create_proj(projPath, toolPath, u8serverPath, targetName, classPrefix, selectType): # if not targetName.startswith("U8SDK_"): # targetName = "U8SDK_" + targetName print("selectType:" + selectType) selectType = int(selectType) if selectType == 1 or selectType == 2: print("generate client...........") if not os.path.exists(projPath): log_utils.debug("the U8SDK_Projects dir is not exists." + projPath) return if not os.path.exists(toolPath): log_utils.debug("the U8SDKTool-Win-P34 dir is not exists." + toolPath) return templatePath = os.path.join(projPath, "U8SDK_Template") if not os.path.exists(templatePath): log_utils.debug("the template project is not exists." + templatePath) return sdkConfigPath = os.path.join(toolPath, "config/sdk/" + targetName.lower()) if os.path.exists(sdkConfigPath): log_utils.error( "sdk with same name is already exists. please change the name." + targetName) return projTargetName = "U8SDK_" + targetName targetPath = os.path.join(projPath, projTargetName) if os.path.exists(targetPath): log_utils.debug("the target project is already exists." + targetPath) return file_utils.copy_files(templatePath, targetPath) srcPath = os.path.join(targetPath, "src/com/u8/sdk") for f in os.listdir(srcPath): fname = os.path.join(srcPath, f) file_utils.modifyFileContent(fname, "Temp", classPrefix) ftarget = f.replace("Temp", classPrefix) os.rename(fname, os.path.join(srcPath, ftarget)) configPath = os.path.join(targetPath, "config.xml") file_utils.modifyFileContent(configPath, "Temp", classPrefix) projFilePath = os.path.join(targetPath, ".project") file_utils.modifyFileContent(projFilePath, "U8SDK_Template", projTargetName) os.makedirs(sdkConfigPath) if selectType == 1 or selectType == 3: u8serverSDKPath = os.path.join( u8serverPath, "src/main/java/com/u8/server/sdk/" + targetName.lower()) if os.path.exists(u8serverSDKPath): log_utils.error( "sdk with same name is already exists in server. please change the name." + targetName) return u8serverPayPath = os.path.join( u8serverPath, "src/main/java/com/u8/server/web/pay/sdk/" + targetName + "PayCallbackAction.java") if os.path.exists(u8serverPayPath): log_utils.error( "sdk with same name is already exists in server callback. please change the name." + targetName) return serverDemoSDKPath = os.path.join( u8serverPath, "src/main/java/com/u8/server/sdk/demo") file_utils.copy_files(serverDemoSDKPath, u8serverSDKPath) sdkName = os.path.join(u8serverSDKPath, 'DemoSDK.java') targetSDKName = sdkName.replace("Demo", targetName) os.rename(sdkName, targetSDKName) file_utils.modifyFileContent(targetSDKName, "Demo", targetName) file_utils.modifyFileContent(targetSDKName, "demo", targetName.lower()) serverDemoPayPath = os.path.join( u8serverPath, 'src/main/java/com/u8/server/web/pay/sdk/DemoPayCallbackAction.java' ) file_utils.copy_file(serverDemoPayPath, u8serverPayPath) file_utils.modifyFileContent(u8serverPayPath, "demo", targetName.lower()) file_utils.modifyFileContent(u8serverPayPath, "Demo", targetName)
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
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): manifestFile = os.path.join(decompileDir, "AndroidManifest.xml") file_utils.modifyFileContent(manifestFile, "${applicationId}", packageName) 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