Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def generate_keystore(workDir, game, channel):
    """
        auto generate keystore file
        if user want to use auto generated keystore file, you can use this method
    """

    keytoolPath = file_utils.getJavaBinDir() + "keytool"

    keystorePath = os.path.join(workDir, 'temp_keystore')
    if not os.path.exists(keystorePath):
        os.makedirs(keystorePath)

    keystore = dict()
    keystore['keystore'] = os.path.join(keystorePath, "temp.keystore")
    keystore['password'] = channel['name'] + game['appName']
    keystore['aliaskey'] = game["appName"] + channel["name"] + time.strftime(
        '%Y%m%d%H%M%S')
    keystore['aliaspwd'] = channel['name'] + game['appName']
    keystore['sigalg'] = "SHA1withRSA"

    dname = "CN=mqttserver.ibm.com, OU=ID, O=IBM, L=Hursley, S=Hants, C=GB"

    cmd = '"%s" -genkeypair -dname "%s" -alias "%s" -keyalg "RSA" -sigalg "%s" -validity 20000 -keystore "%s" -storepass "%s" -keypass "%s" ' % (
        keytoolPath, dname, keystore['aliaskey'], keystore['sigalg'],
        keystore['keystore'], keystore['password'], keystore['aliaspwd'])

    ret = file_utils.exec_cmd(cmd)

    if ret:
        return None

    return keystore
Beispiel #4
0
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 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 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 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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
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