示例#1
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
示例#2
0
def generate_rindex_v2(workDir, genPath, resPath, manifestPath):
    """
        generate R.java with appt2
    """

    androidPath = file_utils.getFullToolPath("android.jar")

    if platform.system() == 'Windows':

        aapt2Path = file_utils.getFullToolPath("aapt2.exe")
    else:
        aapt2Path = file_utils.getFullToolPath("aapt2")

    if not os.path.exists(aapt2Path):
        log_utils.error("aapt2 is not exists in tool")
        return False

    #compile res first...
    resFlatPath = workDir + "/res_flat.zip"
    cmd = '"%s" compile -o "%s" --dir "%s" -v' % (aapt2Path, resFlatPath,
                                                  resPath)
    ret = file_utils.exec_cmd(cmd)
    if not ret:
        return False

    #link res to generate R.java
    resTempPath = workDir + "/res.apk"
    cmd = '"%s" link -o "%s" --manifest "%s" -I "%s" --java "%s" "%s" -v' % (
        aapt2Path, resTempPath, manifestPath, androidPath, genPath,
        resFlatPath)
    ret = file_utils.exec_cmd(cmd)

    return ret
示例#3
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
示例#4
0
def generate_rindex_v1(genPath, resPath, manifestPath):
    """
        generate R.java with aapt
    """

    androidPath = file_utils.getFullToolPath("android.jar")
    aaptPath = file_utils.getFullToolPath("aapt")

    cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (
        aaptPath, genPath, resPath, androidPath, manifestPath)
    ret = file_utils.exec_cmd(cmd)

    return ret
示例#5
0
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)
示例#6
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
示例#7
0
def jar2dex(srcDir, dstDir, dextool="dx.jar"):
    """
        compile jar files to dex.
    """

    dexToolPath = file_utils.getFullToolPath("/lib/dx.jar")
    heapSize = config_utils.get_jvm_heap_size()
    cmd = file_utils.getJavaCMD() + ' -jar -Xms%sm -Xmx%sm "%s" --dex --multi-dex --output="%s" ' % (
        heapSize, heapSize, dexToolPath, dstDir)

    num = 0

    for f in os.listdir(srcDir):
        if f.endswith(".jar"):
            num = num + 1
            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 (not f.startswith(".")) and f.endswith(".jar"):
                num = num + 1
                cmd = cmd + " " + os.path.join(srcDir, "libs", f)

    if num == 0:
        # no jar
        log_utils.warning("no need to do jar2dex. there is no jars in " + srcDir)
        return True

    return file_utils.exec_cmd(cmd)
示例#8
0
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
示例#9
0
def align_apk(apkfile, targetapkfile):
    """
        zip align the apk file
    """

    align = file_utils.getFullToolPath('zipalign')
    aligncmd = '"%s" -f 4 "%s" "%s"' % (align, apkfile, targetapkfile)

    ret = file_utils.exec_cmd(aligncmd)

    return ret
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
示例#11
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
示例#12
0
def sign_apk_v2(apkfile, targetapkfile, keystore, password, alias, aliaspwd):

    aapt = file_utils.getFullToolPath("aapt")
    apksigner = file_utils.getFullToolPath("apksigner.jar")

    if not os.path.exists(keystore):
        log_utils.error("the keystore file is not exists. %s", keystore)
        return False

    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.exec_cmd(rmcmd)

    signcmd = '"%s" -jar "%s" sign -v --ks "%s" --ks-key-alias "%s" --ks-pass pass:"******" --key-pass pass:"******" --out "%s" "%s" ' % (
        file_utils.getJavaCMD(), apksigner, keystore, alias, password,
        aliaspwd, targetapkfile, apkfile)

    ret = file_utils.exec_cmd(signcmd)

    return ret
示例#13
0
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
示例#14
0
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
示例#15
0
def decompile(source, targetdir):
    """
        decompile apk to targetdir
    """
    apkfile = source
    apktool = file_utils.getFullToolPath('apktool2.jar')
    if os.path.exists(targetdir):
        file_utils.del_file_folder(targetdir)
    if not os.path.exists(targetdir):
        os.makedirs(targetdir)

    heapSize = config_utils.get_jvm_heap_size()
    cmd = '"%s" -jar -Xms%sm -Xmx%sm "%s" -v d -b --only-main-classes -f "%s" -o "%s"' % (
        file_utils.getJavaCMD(), heapSize, heapSize, apktool, apkfile,
        targetdir)
    ret = file_utils.exec_cmd(cmd)
    return ret
示例#16
0
def recompile(sourcefolder, apkfile):
    """
        recompile apk
    """

    apktool = file_utils.getFullToolPath('apktool2.jar')

    ret = False
    if os.path.exists(sourcefolder):
        heapSize = config_utils.get_jvm_heap_size()
        cmd = '"%s" -jar -Xms%sm -Xmx%sm "%s" -v b -f "%s" -o "%s"' % (
            file_utils.getJavaCMD(), heapSize, heapSize, apktool, sourcefolder,
            apkfile)
        ret = file_utils.exec_cmd(cmd)
    else:
        log_utils.error("recompile failed. apk source folder not exists.")

    return ret
示例#17
0
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)
示例#18
0
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 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
示例#20
0
文件: script.py 项目: leo0228/U8AAR
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
示例#21
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
示例#22
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
示例#23
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