Пример #1
0
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)
Пример #2
0
def getAllKeystores(appName):
    fileName = "games/" + appName + "/keystore.xml"

    configFile = utils_file.getFullPath(fileName)

    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except Exception as e:
        utils_log.error("can not parse keystore.xml.path:%s", configFile)
        return None

    channels = root.find("keystores").findall("channel")
    lstKeystores = []

    for cNode in channels:
        channel = {}
        params = cNode.findall("param")
        for cParam in params:
            key = cParam.get('name')
            val = cParam.get('value')
            channel[key] = val

        lstKeystores.append(channel)

    return lstKeystores
Пример #3
0
def writeDeveloperJson(game_key, channel, defchannel, targetFilePath):
    targetFilePath = utils_file.getFullPath(targetFilePath)
    proStr = {
        "info": {
            "channel_id": "",
            "game_key": ""
        },
        "channels": [{
            "name": "",
            "version": ""
        }]
    }
    projson = json.loads(json.dumps(proStr))

    projson["info"]["channel_id"] = channel["id"]
    projson["info"]["game_key"] = game_key
    # projson["info"]["ver"] = '1.0'

    if channel['params'] is not None and len(channel['params']) > 0:
        projson["channels"][0]["name"] = channel['name']
        # projson["channels"][0]["sdk_channel_id"] = channel["id"]
        projson["channels"][0]["version"] = channel["sdkLogicVersionCode"]

    if defchannel is not None and defchannel['params'] is not None and len(
            defchannel['params']) > 0:
        temp = projson["channels"][0].copy()
        temp["name"] = defchannel['name']
        # temp["sdk_channel_id"] = channel["id"]
        temp["version"] = defchannel["sdkLogicVersionCode"]
        projson["channels"].append(temp)

    for param in channel['params']:
        if param['bWriteInClient'] == '1':
            for plugin in projson["channels"]:
                if plugin['name'] == channel['name']:
                    plugin.update({param['name']: ""})

    if defchannel is not None and defchannel['params'] is not None and len(
            defchannel['params']) > 0:
        for param in defchannel['params']:
            if param['bWriteInClient'] == '1':
                for plugin in projson["channels"]:
                    if plugin['name'] == defchannel['name']:
                        plugin.update({param['name']: ""})

    utils_log.debug("the develop info is %s", proStr)
    targetFile = open(targetFilePath, 'wb')
    pro_str = json.dumps(projson, sort_keys=True, indent=2)
    pro_str = pro_str.encode('UTF-8')
    print pro_str
    targetFile.write(pro_str)
    targetFile.close()
Пример #4
0
def getAppKey():
    configFile = utils_file.getFullPath("config/config.xml")

    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except Exception as e:
        utils_log.error("can not parse config.xml.path:%s", configFile)
        return None

    gameNode = root.find("game")

    if gameNode == None:
        return None

    appID = gameNode.get('appKey')

    return appID
Пример #5
0
def getDefaultKeystore(appName):
    fileName = "games/" + appName + "/keystore.xml"
    configFile = utils_file.getFullPath(fileName)
    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except Exception as e:
        utils_log.error("can not parse keystore.xml.path:%s", configFile)
        return None

    params = root.find("default").findall("param")
    channel = {}
    for cParam in params:
        key = cParam.get('name')
        val = cParam.get('value')
        channel[key] = val

    return channel
Пример #6
0
def getAllGames():
    """
        get all games
    """
    configFile = utils_file.getFullPath("games/configs.xml")
    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except Exception as e:
        utils_log.error("can not parse games.xml.path:%s", configFile)
        return None
    gamesNode = root.find('games')
    games = gamesNode.findall('game')
    if gamesNode == None:
        return None

    if games == None or len(games) <= 0:
        return None

    lstGames = []
    for cNode in games:
        game = {}
        params = cNode.findall('param')
        if params != None and len(params) > 0:
            for cParam in params:
                key = cParam.get("name")
                val = cParam.get("value")
                game[key] = val

        logNode = cNode.find('log')
        if logNode != None:
            game['log'] = dict()
            logParams = logNode.findall('param')
            if logParams != None and len(logParams) > 0:
                for lParam in logParams:
                    key = lParam.get("name")
                    val = lParam.get('value')
                    game['log'][key] = val

        lstGames.append(game)

    return lstGames
Пример #7
0
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
Пример #8
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:
Пример #9
0
def loadChannelUserConfig(appName, channel):
    configFile = utils_file.getFullPath("resource/channel_sdk/" +
                                        channel['sdk'] + "/config.xml")

    if not os.path.exists(configFile):
        utils_log.error(
            "the config.xml is not exists of channel_sdk %s.path:%s",
            channel['name'], configFile)
        return 0

    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except:
        utils_log.error("can not parse config.xml.path:%s", configFile)
        return 0

    configNode = root

    paramNodes = configNode.find("params")
    channel['params'] = []
    if paramNodes != None and len(paramNodes) > 0:

        for paramNode in paramNodes:
            param = {}
            param['name'] = paramNode.get('name')
            param['required'] = paramNode.get('required')

            if param['required'] == '1':

                key = param['name']
                if key in channel[
                        'sdkParams'] and channel['sdkParams'][key] != None:
                    param['value'] = channel['sdkParams'][key]
                else:
                    utils_log.error(
                        "the sdk %s 'sdkParam's is not all configed in the config.xml.path:%s",
                        channel['name'], configFile)
                    return 0
            else:
                param['value'] = paramNode.get('value')

            param['showName'] = paramNode.get('showName')
            param['bWriteInManifest'] = paramNode.get('bWriteInManifest')
            param['bWriteInClient'] = paramNode.get('bWriteInClient')
            channel['params'].append(param)

    operationNodes = configNode.find("operations")
    channel['operations'] = []
    if operationNodes != None and len(operationNodes) > 0:

        for opNode in operationNodes:
            op = {}
            op['type'] = opNode.get('type')
            op['from'] = opNode.get('from')
            op['to'] = opNode.get('to')
            channel['operations'].append(op)

    pluginNodes = configNode.find("plugins")
    if pluginNodes != None and len(pluginNodes) > 0:
        channel['plugins'] = []
        for pNode in pluginNodes:
            p = {}
            p['name'] = pNode.get('name')
            p['type'] = pNode.get('type')
            channel['plugins'].append(p)

    versionNode = configNode.find("version")
    if versionNode != None and len(versionNode) > 0:
        versionCodeNode = versionNode.find("versionCode")
        versionNameNode = versionNode.find("versionName")
        # the sdk version code is used to check version update for the sdk.
        if versionCodeNode != None and versionNameNode != None:
            channel['sdkVersionCode'] = versionCodeNode.text
            channel['sdkVersionName'] = versionNameNode.text

    return 1
Пример #10
0
def getAllChannels(appName, isPublic):
    fileName = "games/" + appName + "/config.xml"

    configFile = utils_file.getFullPath(fileName)

    try:
        tree = ET.parse(configFile)
        root = tree.getroot()
    except Exception as e:
        utils_log.error("can not parse config.xml.path:%s", configFile)
        return None

    channels = root.find("channels").findall("channel")
    lstChannels = []
    for cNode in channels:
        channel = {}
        params = cNode.findall("param")
        for cParam in params:
            key = cParam.get('name')
            val = cParam.get('value')
            channel[key] = val

        sdkVersionNode = cNode.find('sdk-version')
        if sdkVersionNode != None and len(sdkVersionNode) > 0:
            versionCodeNode = sdkVersionNode.find('versionCode')
            versionNameNode = sdkVersionNode.find('versionName')
            if versionCodeNode != None and versionNameNode != None:
                # u8server use the logic version code to decide which sdk version to use
                channel['sdkLogicVersionCode'] = versionCodeNode.text
                channel['sdkLogicVersionName'] = versionNameNode.text

        sdkParams = cNode.find("sdk-params")
        tblSDKParams = {}

        if sdkParams != None:
            sdkParamNodes = sdkParams.findall('param')
            if sdkParamNodes != None and len(sdkParamNodes) > 0:
                for cParam in sdkParamNodes:
                    key = cParam.get('name')
                    val = cParam.get('value')
                    tblSDKParams[key] = val

        channel['sdkParams'] = tblSDKParams

        # if len(lstGPlugins) > 0:
        #     for p in lstGPlugins:
        #         loadThirdPluginUserConfig(appName, channel, p, p['name'])

        ret = loadChannelUserConfig(appName, channel)
        if ret:
            # lstPlugins = [] + lstGPlugins
            lstPlugins = []
            pluginsNode = cNode.find("plugins")

            if pluginsNode != None:
                pluginNodeLst = pluginsNode.findall("plugin")
                if pluginNodeLst != None and len(pluginNodeLst) > 0:

                    for cPlugin in pluginNodeLst:
                        plugin = {}
                        plugin['name'] = cPlugin.get('name')

                        exists = False
                        for p in lstPlugins:
                            if p['name'] == plugin['name']:
                                exists = True
                                break

                        if not exists:
                            plugin['desc'] = cPlugin.get('desc')
                            loadThirdPluginUserConfig(appName, channel, plugin,
                                                      plugin['name'])
                            lstPlugins.append(plugin)

            channel['third-plugins'] = lstPlugins
            lstChannels.append(channel)

    return lstChannels