示例#1
0
def entry(isPublic, isSelectable, threadNum):
    utils_log.info("Curr Python Version::%s", utils_config.get_py_version())

    print(u"**********所有游戏**********")
    print(u"\t appID \t\t 游戏文件夹 \t\t 游戏名称 \n\n")

    games = utils_config.getAllGames()
    if games != None and len(games) > 0:
        for ch in games:
            print(u"\t %s \t\t %s \t\t\t%s" %
                  (ch['appID'], ch['appName'], ch['appDesc']))

    sys.stdout.write(u"请选择一个游戏(输入appID):")
    sys.stdout.flush()

    selectedGameID = raw_input()
    selectedGameID = str(selectedGameID)

    game = getGameByAppID(selectedGameID, games)

    utils_log.info("current selected game is %s(%s)", game['appName'],
                   game['appDesc'])

    # if isSelectable:
    main.main(game, isPublic)
示例#2
0
def modifyFileContent(sourcefile, oldContent, newContent):
    if os.path.isdir(sourcefile):
        utils_log.warning("the source %s must be a file not a dir", sourcefile)
        return

    if not os.path.exists(sourcefile):
        utils_log.warning("the source is not exists.path:%s", sourcefile)
        return

    f = open(sourcefile, 'r+')
    data = str(f.read())
    f.close()
    bRet = False
    idx = data.find(oldContent)
    while idx != -1:
        data = data[:idx] + newContent + data[idx + len(oldContent):]
        idx = data.find(oldContent, idx + len(oldContent))
        bRet = True

    if bRet:
        fw = open(sourcefile, 'w')
        fw.write(data)
        fw.close()
        utils_log.info("modify file success.path:%s", sourcefile)
    else:
        utils_log.warning("there is no content matched in file:%s with content:%s", sourcefile, oldContent)
示例#3
0
文件: main.py 项目: kerwinzxc/sdk-1
def main(game, is_public):
    appName = game['appName']

    channels = utils_config.getAllChannels(appName, is_public)
    utils_log.info("channels data: " + str(channels))
    if channels is None or len(channels) == 0:
        print(u"没有任何可以打包的渠道")
        return

    for ch in channels:
        name = ch['name']
        if ch['name'] == 'pyw':
            defchannel = ch
        elif ch['name'] == 'oppo':
            channel = ch

    game = {'appId': '52', 'appKey': '8c7f4751', 'appName': 'sample'}
    # channel = {'id':'17','name':'pyw','sdk':'pyw','suffix':'.pyw'}  朋友玩:17 应用宝:25 九九游:26  可游:27 六六九:28 华为:29 智游:31 UC:33 柠檬:34
    utils_log.info("channel data: " + str(channel))
    utils_log.info("defchannel data: " + str(defchannel))

    baseApkPath = utils_file.getFullPath('games/' + game['appName'] +
                                         '/game.apk')
    utils_log.info("the base apk file is : %s", baseApkPath)
    core.pack(game, channel, defchannel, baseApkPath, is_public)
示例#4
0
def execFormatCmd(cmd):
    cmd = cmd.replace('\\', '/')
    cmd = re.sub('/+', '/', cmd)
    ret = 0
    utils_log.info("execFormatCmd")
    try:
        reload(sys)
        sys.setdefaultencoding('utf-8')

        if platform.system() == 'Windows':
            st = subprocess.STARTUPINFO
            st.dwFlags = subprocess.STARTF_USESHOWWINDOW
            st.wShowWindow = subprocess.SW_HIDE
            # cmd = str(cmd).encode('gbk')
        s = subprocess.Popen(cmd, shell=True)
        ret = s.wait()
        if ret:
            s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            stdoutput, erroutput = s.communicate()

            utils_log.error("*******ERROR*******")
            utils_log.error(stdoutput)
            utils_log.error(erroutput)
            utils_log.error("*******************")

            cmd = 'error::' + cmd + '  !!!exec Fail!!!  '
        else:

            s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            stdoutput, erroutput = s.communicate()

            utils_log.info(stdoutput)
            utils_log.info(erroutput)

            cmd = cmd + ' !!!exec success!!! '

        utils_log.info(cmd)

    except Exception as e:
        print(e)
        return

    return ret
示例#5
0
文件: core.py 项目: kerwinzxc/sdk-1
def pack(game, channel, defchannel, sourcepath, isPublic):
    sourcepath = sourcepath.replace('\\', '/')

    if not os.path.exists(sourcepath):
        return 1

    app_id = game['appId']
    app_key = game['appKey']
    app_name = game['appName']
    channel_id = channel["id"]
    channel_name = channel["name"]
    sdk_name = channel["sdk"]

    utils_log.info("now to package %s...", channel_name)

    workDir = 'workspace/' + app_name + '/' + channel_name
    workDir = utils_file.getFullPath(workDir)
    utils_file.del_file_folder(workDir)
    tempApkSource = workDir + "/temp.apk"
    utils_file.copy_file(sourcepath, tempApkSource)
    decompileDir = workDir + "/decompile"
    ret = utils_apk.decompileApk(tempApkSource, decompileDir)
    if ret:
        return 1

    utils_log.info("channel: " + str(channel))
    # change xml config and so on
    newPackageName = utils_apk.renamePackageName(channel, decompileDir,
                                                 channel['suffix'], isPublic)

    # copy sdk code to decompileDir
    utils_log.info("now to decompile sdk %s...", sdk_name)
    sdkSourceDir = utils_file.getFullPath('resource/channel_sdk/' + sdk_name)
    smaliDir = decompileDir + "/smali"
    sdkDestDir = workDir + "/sdk/" + sdk_name
    utils_file.copy_files(sdkSourceDir, sdkDestDir)

    if (not os.path.exists(sdkSourceDir + "/classes.dex")):
        utils_apk.jar2dex(sdkSourceDir, sdkDestDir)

    sdkDexFile = sdkDestDir + "/classes.dex"
    ret = utils_apk.dex2smali(sdkDexFile, smaliDir, "baksmali.jar")
    if ret:
        return 1

    defsdkDestDir = sdkDestDir
    if defchannel is not None:
        # copy def sdk code to decompileDir
        defsdkName = defchannel["sdk"]
        utils_log.info("now to decompile def sdk %s...", defsdkName)
        defsdkSourceDir = utils_file.getFullPath('resource/channel_sdk/' +
                                                 defsdkName)
        smaliDir = decompileDir + "/smali"
        defsdkDestDir = workDir + "/sdk/" + defsdkName
        utils_file.copy_files(defsdkSourceDir, defsdkDestDir)

        if (not os.path.exists(defsdkSourceDir + "/classes.dex")):
            utils_apk.jar2dex(defsdkSourceDir, defsdkDestDir)

        defsdkDexFile = defsdkDestDir + "/classes.dex"
        ret = utils_apk.dex2smali(defsdkDexFile, smaliDir, "baksmali.jar")
        if ret:
            return 1

    # copy main sdk resources.
    # if defchannel is not None:
    #     defchannelName = defchannel["name"]
    #     ret = utils_apk.copyResource(game, defchannel, newPackageName, defsdkDestDir, decompileDir,
    #                                  defchannel['operations'], channel_name)
    #     if ret:
    #         return 1
    ret = utils_apk.copyResource(game, channel, newPackageName, sdkDestDir,
                                 decompileDir, channel['operations'],
                                 channel_name)
    if ret:
        return 1

    # copy defchannel special resources assets libs res
    utils_log.info("defchannel is %s...", defchannel)
    if defchannel is not None:
        utils_log.info(
            "copy defchannel special resources game %s decompile %s...", game,
            decompileDir)
        ret = utils_apk.copyChannelResources(game, defchannel, decompileDir)
        if ret:
            return 1
    # copy channel special resources
    ret = utils_apk.copyChannelResources(game, channel, decompileDir)
    if ret:
        return 1
    # copy game root resources and res resources
    utils_apk.copyAppResources(game, decompileDir)
    utils_apk.copyAppRootResources(game, decompileDir)

    # generate config files for apk to run.
    utils_apk.writeDevelopInfo(app_key, channel, defchannel, decompileDir)

    if defchannel is not None:
        utils_apk.writeManifestMetaInfo(defchannel, decompileDir)
    utils_apk.writeManifestMetaInfo(channel, decompileDir)

    packgame = "output\\" + app_name + ".apk"

    utils_log.info("now to package game %s...", decompileDir)

    copyFrom = 'pywSmali'
    copyTo = 'workspace\\sample\\oppo\\decompile\\smali\\com'

    utils_log.info('start')
    utils_apk.copyResToApk(copyFrom, copyTo)
    utils_log.info('end')

    # 打包
    utils_apk.recompileApk(decompileDir, packgame, "apktool.jar")

    utils_log.info("now to reset package %s...", packgame)

    # 整合apk(删除meta-inf)
    newPackageName = utils_file.resetApk("tempApk", packgame)

    # 删除旧包
    if os.path.exists(packgame):
        os.remove(packgame)

    utils_log.info("now to sign game %s...", newPackageName)

    # 重签
    utils_apk.signApk("sample", "25", newPackageName)

    # if the main sdk has special logic. execute the special logic script.
    ret = utils_apk.doSDKScript(channel, decompileDir, newPackageName,
                                sdkDestDir)
    if ret:
        return 1
    if defchannel is not None:
        ret = utils_apk.doSDKScript(defchannel, decompileDir, newPackageName,
                                    defsdkDestDir)
        if ret:
            return 1
    # if the game has some special logic. execute the special logic script.called post_script.py
    ret = utils_apk.doGamePostScript(game, channel, decompileDir,
                                     newPackageName)
    if ret:
        return 1
示例#6
0
def execute(channel, decompileDir, packageName):
    utils_log.info("exe yyb scripts")
示例#7
0
import zipfile
import os, os.path
import utils_file
import utils_apk
import utils_log

if __name__ == "__main__":

    # ·´±àÒëapk
    utils_log.info("start copyfile and decompile")

    workDir = 'res/fq'
    utils_file.del_file_folder(workDir)
    workDir = utils_file.getFullPath(workDir)
    tempApkSource = workDir + "/temp.apk"
    utils_file.copy_file(utils_file.getFullPath('game.apk'), tempApkSource)
    decompileDir = workDir + "/decompile"
    utils_apk.decompileApk(tempApkSource, decompileDir)
    utils_log.info("copyfile and decompile success!!")

    # ÐÞ¸Ästring
    sourefile = "res\\fq\\decompile\\res\\values\\strings.xml"
    if not os.path.exists(sourefile):
        utils_log.info("%s String.xml file not exist ", sourefile)
        exit(-1)
    utils_log.info("replace string.xml start")
    temp = "<string name=\"pyw_sdk_type\">1</string>"
    targetLauncherName = "<string name=\"pyw_sdk_type\">3</string>"
    lines = open(sourefile, 'r').readlines()
    fp = open(sourefile, 'w')
    for s in lines:
示例#8
0
def execute(game, channel, decompileDir, packageName):
    utils_log.info("exe game scripts")
示例#9
0
    # 打包
    # utils_apk.recompileApk("workspace\sample\yyb\decompile", "game111.apk", "apktool2.jar")
    # f = zipfile.ZipFile("game111.apk", 'r')
    # for file in f.namelist():
    #     f.extract(file, "unzipTest")
    #     print file
    # utils_file.del_file_folder("unzipTest\META-INF")
    # zip_dir("unzipTest", "newApk.apk")
    # zipFileFullDir = os.path.join("unzipTest", 'newApk.apk')
    # newF = zipfile.ZipFile(zipFileFullDir, 'w', zipfile.ZIP_DEFLATED)
    # for fullname in iterbrowse("unzipTest"):
    #     if not fullname.endswith("newApk.apk"):
    #         newF.write(fullname.replace("unzipTest\\", ""))
    #     #print fullname.replace("unzipTest\\", "")
    # newF.close()
    utils_log.info("now to package game %s...")
    
    app_name = "sample"
    #
    packgame = "output\\" + app_name + ".apk"

    decompileDir = "workspace\sample\ky\decompile"
   
    # 打包
    utils_apk.recompileApk(decompileDir, packgame, "apktool2.jar")

    # 整合apk(删除meta-inf)
    newPackageName = utils_file.resetApk("tempApk", packgame)

    # 删除旧包
    if os.path.exists(packgame):