This commit is contained in:
wuaho 2021-06-02 20:13:21 +08:00
parent 937d6d56d8
commit f649403571
8 changed files with 542 additions and 263 deletions

View File

@ -4,11 +4,11 @@ import os
import stat import stat
import shutil import shutil
import json import json
print(os.path.abspath(__name__)) print(os.path.abspath(__name__))
import sys import sys
RD, WD, XD = 4, 2, 1 RD, WD, XD = 4, 2, 1
BNS = [RD, WD, XD] BNS = [RD, WD, XD]
MDS = [ MDS = [
@ -17,6 +17,7 @@ MDS = [
[stat.S_IXUSR, stat.S_IXGRP, stat.S_IXOTH] [stat.S_IXUSR, stat.S_IXGRP, stat.S_IXOTH]
] ]
def chmod(path, mode): def chmod(path, mode):
if isinstance(mode, int): if isinstance(mode, int):
mode = str(mode) mode = str(mode)
@ -30,18 +31,20 @@ def chmod(path, mode):
mode_num += MDS[bnidx][midx] mode_num += MDS[bnidx][midx]
# os.chmod(path, mode_num) # os.chmod(path, mode_num)
#遍历res下的所有文件
def isFindApk (parent): # 遍历res下的所有文件
for i in os.listdir(parent) : def isFindApk(parent):
if i.endswith('.apk') : for i in os.listdir(parent):
print ('find apk file-===%s' %i) if i.endswith('.apk'):
print('find apk file-===%s' % i)
return i; return i;
print ('no apk file=====') print('no apk file=====')
return '' return ''
def readChannelfile(filename): def readChannelfile(filename):
try: try:
print (filename) print(filename)
f = open(filename) f = open(filename)
global channelList global channelList
except Exception as e: except Exception as e:
@ -49,75 +52,78 @@ def readChannelfile(filename):
exit(0) exit(0)
channelList = json.load(f) channelList = json.load(f)
def backUpManifest(): def backUpManifest():
if os.path.exists('./AndroidManifest.xml'): if os.path.exists('./AndroidManifest.xml'):
os.remove('./AndroidManifest.xml') os.remove('./AndroidManifest.xml')
manifestPath = './temp/AndroidManifest.xml' manifestPath = './temp/AndroidManifest.xml'
shutil.copyfile(manifestPath, './AndroidManifest.xml') shutil.copyfile(manifestPath, './AndroidManifest.xml')
print ('manifest info--%s' %manifestPath) print('manifest info--%s' % manifestPath)
def modifyChannel(value): def modifyChannel(value):
tempXML = '' tempXML = ''
f = open('./AndroidManifest.xml') f = open('./AndroidManifest.xml')
for line in f : for line in f:
if line.find('leguChannel') > 0 and easyName != '' : if line.find('leguChannel') > 0 and easyName != '':
if easyNameSuffix == "1" : if easyNameSuffix == "1":
if value < 10 : if value < 10:
line = '<meta-data android:name="leguChannel" android:value="%s_0%d"/>' % (easyName, value) line = '<meta-data android:name="leguChannel" android:value="%s_0%d"/>' % (easyName, value)
else : else:
line = '<meta-data android:name="leguChannel" android:value="%s_%d"/>' % (easyName, value) line = '<meta-data android:name="leguChannel" android:value="%s_%d"/>' % (easyName, value)
else : else:
line = '<meta-data android:name="leguChannel" android:value="%s"/>' % (easyName) line = '<meta-data android:name="leguChannel" android:value="%s"/>' % (easyName)
elif line.find('owner') > 0 and owner != '' : elif line.find('owner') > 0 and owner != '':
print ('owner====%s' %line) print('owner====%s' % line)
line = '<meta-data android:name="owner" android:value="%s"/>' % (owner) line = '<meta-data android:name="owner" android:value="%s"/>' % (owner)
elif line.find('package') > 0 and packageId != '' : elif line.find('package') > 0 and packageId != '':
print ('package====%s' %line) print('package====%s' % line)
line = '<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="30" android:compileSdkVersionCodename="11" android:installLocation="auto" package="%s" platformBuildVersionCode="30" platformBuildVersionName="11">' % (packageId) line = '<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="30" android:compileSdkVersionCodename="11" android:installLocation="auto" package="%s" platformBuildVersionCode="30" platformBuildVersionName="11">' % (
elif line.find('appid') > 0 and appid != '' : packageId)
print ('appid====%s' %line) elif line.find('appid') > 0 and appid != '':
print('appid====%s' % line)
line = '<meta-data android:name="appid" android:value="%s"/>' % (appid) line = '<meta-data android:name="appid" android:value="%s"/>' % (appid)
elif line.find('gism_id') > 0 and gism_id != '' : elif line.find('gism_id') > 0 and gism_id != '':
print ('gism_id====%s' %line) print('gism_id====%s' % line)
line = '<meta-data android:name="gism_id" android:value="%s"/>' % (gism_id) line = '<meta-data android:name="gism_id" android:value="%s"/>' % (gism_id)
elif line.find('gism_name') > 0 and gism_name != '' : elif line.find('gism_name') > 0 and gism_name != '':
print ('gism_name====%s' %line) print('gism_name====%s' % line)
line = '<meta-data android:name="gism_name" android:value="%s"/>' % (gism_name) line = '<meta-data android:name="gism_name" android:value="%s"/>' % (gism_name)
elif line.find('gism_channel') > 0 and gism_channel != '' : elif line.find('gism_channel') > 0 and gism_channel != '':
print ('gism_channel====%s' %line) print('gism_channel====%s' % line)
line = '<meta-data android:name="gism_channel" android:value="%s"/>' % (gism_channel) line = '<meta-data android:name="gism_channel" android:value="%s"/>' % (gism_channel)
elif line.find('lg_ad_id') > 0 and lg_ad_id != '' : elif line.find('lg_ad_id') > 0 and lg_ad_id != '':
print ('lg_ad_id====%s' %line) print('lg_ad_id====%s' % line)
line = '<meta-data android:name="lg_ad_id" android:value="%s"/>' % (lg_ad_id) line = '<meta-data android:name="lg_ad_id" android:value="%s"/>' % (lg_ad_id)
elif line.find('lg_ad_name') > 0 and lg_ad_name != '' : elif line.find('lg_ad_name') > 0 and lg_ad_name != '':
print ('lg_ad_name====%s' %line) print('lg_ad_name====%s' % line)
line = '<meta-data android:name="lg_ad_name" android:value="%s"/>' % (lg_ad_name) line = '<meta-data android:name="lg_ad_name" android:value="%s"/>' % (lg_ad_name)
elif line.find('gactionId') > 0 and gactionId != '' : elif line.find('gactionId') > 0 and gactionId != '':
print ('gactionId====%s' %line) print('gactionId====%s' % line)
line = '<meta-data android:name="gactionId" android:value="%s"/>' % (gactionId) line = '<meta-data android:name="gactionId" android:value="%s"/>' % (gactionId)
elif line.find('gappSecretKey') > 0 and gappSecretKey != '' : elif line.find('gappSecretKey') > 0 and gappSecretKey != '':
print ('gappSecretKey====%s' %line) print('gappSecretKey====%s' % line)
line = '<meta-data android:name="gappSecretKey" android:value="%s"/>' % (gappSecretKey) line = '<meta-data android:name="gappSecretKey" android:value="%s"/>' % (gappSecretKey)
elif line.find('baiduId') > 0 and baiduId != '' : elif line.find('baiduId') > 0 and baiduId != '':
print ('baiduId====%s' %line) print('baiduId====%s' % line)
line = '<meta-data android:name="baiduId" android:value="%s"/>' % (baiduId) line = '<meta-data android:name="baiduId" android:value="%s"/>' % (baiduId)
elif line.find('baiduSecretKey') > 0 and baiduSecretKey != '' : elif line.find('baiduSecretKey') > 0 and baiduSecretKey != '':
print ('baiduSecretKey====%s' %line) print('baiduSecretKey====%s' % line)
line = '<meta-data android:name="baiduSecretKey" android:value="%s"/>' % (baiduSecretKey) line = '<meta-data android:name="baiduSecretKey" android:value="%s"/>' % (baiduSecretKey)
elif line.find('lg_reyun_game_appkey') > 0 and lg_reyun_game_appkey != '' : elif line.find('lg_reyun_game_appkey') > 0 and lg_reyun_game_appkey != '':
print ('lg_reyun_game_appkey====%s' %line) print('lg_reyun_game_appkey====%s' % line)
line = '<meta-data android:name="lg_reyun_game_appkey" android:value="%s"/>' % (lg_reyun_game_appkey) line = '<meta-data android:name="lg_reyun_game_appkey" android:value="%s"/>' % (lg_reyun_game_appkey)
elif line.find('lg_reyun_game_channelId') > 0 and lg_reyun_game_channelId != '' : elif line.find('lg_reyun_game_channelId') > 0 and lg_reyun_game_channelId != '':
print ('lg_reyun_game_channelId====%s' %line) print('lg_reyun_game_channelId====%s' % line)
line = '<meta-data android:name="lg_reyun_game_channelId" android:value="%s"/>' % (lg_reyun_game_channelId) line = '<meta-data android:name="lg_reyun_game_channelId" android:value="%s"/>' % (lg_reyun_game_channelId)
elif line.find('lg_reyun_io_appkey') > 0 and lg_reyun_io_appkey != '' : elif line.find('lg_reyun_io_appkey') > 0 and lg_reyun_io_appkey != '':
print ('lg_reyun_io_appkey====%s' %line) print('lg_reyun_io_appkey====%s' % line)
line = '<meta-data android:name="lg_reyun_io_appkey" android:value="%s"/>' % (lg_reyun_io_appkey) line = '<meta-data android:name="lg_reyun_io_appkey" android:value="%s"/>' % (lg_reyun_io_appkey)
elif line.find('lg_reyun_io_channelId') > 0 and lg_reyun_io_channelId != 0 : elif line.find('lg_reyun_io_channelId') > 0 and lg_reyun_io_channelId != 0:
print ('lg_reyun_io_channelId====%s' %line) print('lg_reyun_io_channelId====%s' % line)
line = '<meta-data android:name="lg_reyun_io_channelId" android:value="%s"/>' % (lg_reyun_io_channelId) line = '<meta-data android:name="lg_reyun_io_channelId" android:value="%s"/>' % (lg_reyun_io_channelId)
elif line.find('eventType') > 0 and eventType != '' : elif line.find('eventType') > 0 and eventType != '':
print ('eventType====%s' %line) print('eventType====%s' % line)
line = '<meta-data android:name="eventType" android:value="%s"/>' % (eventType) line = '<meta-data android:name="eventType" android:value="%s"/>' % (eventType)
tempXML += line tempXML += line
f.close() f.close()
@ -125,28 +131,29 @@ def modifyChannel(value):
output = open('./temp/AndroidManifest.xml', 'w') output = open('./temp/AndroidManifest.xml', 'w')
output.write(tempXML) output.write(tempXML)
output.close() output.close()
if value < 10 : if value < 10:
unsignApk = r'./bin/%s_0%d_unsigned.apk'% (easyName, value) unsignApk = r'./bin/%s_0%d_unsigned.apk' % (easyName, value)
#chmod(unsignApk, "777") # chmod(unsignApk, "777")
else : else:
unsignApk = r'./bin/%s_%d_unsigned.apk'% (easyName, value) unsignApk = r'./bin/%s_%d_unsigned.apk' % (easyName, value)
chmod(unsignApk, "777") chmod(unsignApk, "777")
cmdPack = r'java -jar apktool.jar b temp -o %s'% (unsignApk) cmdPack = r'java -jar apktool.jar b temp -o %s' % (unsignApk)
os.system(cmdPack) os.system(cmdPack)
if value < 10 : if value < 10:
signedjar = r'./bin/%s_0%d.apk'% (easyName, value) signedjar = r'./bin/%s_0%d.apk' % (easyName, value)
unsignedjar = r'./bin/%s_0%d_unsigned.apk'% (easyName, value) unsignedjar = r'./bin/%s_0%d_unsigned.apk' % (easyName, value)
chmod(signedjar, "777") chmod(signedjar, "777")
chmod(unsignedjar, "777") chmod(unsignedjar, "777")
else : else:
signedjar = r'./bin/%s_%d.apk'% (easyName, value) signedjar = r'./bin/%s_%d.apk' % (easyName, value)
unsignedjar = r'./bin/%s_%d_unsigned.apk'% (easyName, value) unsignedjar = r'./bin/%s_%d_unsigned.apk' % (easyName, value)
chmod(signedjar, "777") chmod(signedjar, "777")
chmod(unsignedjar, "777") chmod(unsignedjar, "777")
cmd_sign = r'jarsigner -verbose -digestalg SHA1 -sigalg MD5withRSA -keystore %s -storepass %s -keypass %s -signedjar %s %s %s'% (keystore, storepass, keypass, signedjar, unsignedjar, alianame) cmd_sign = r'jarsigner -verbose -digestalg SHA1 -sigalg MD5withRSA -keystore %s -storepass %s -keypass %s -signedjar %s %s %s' % (
keystore, storepass, keypass, signedjar, unsignedjar, alianame)
os.system(cmd_sign) os.system(cmd_sign)
os.remove(unsignedjar); os.remove(unsignedjar);
@ -154,7 +161,7 @@ def modifyChannel(value):
channelList = {} channelList = {}
# #
os.system('java -jar apkool.jar empty-framework-dir --force') os.system('java -jar apkool.jar empty-framework-dir --force')
readChannelfile('./channel') readChannelfile('channel.json')
apkName = "" apkName = ""
apkNameSuffix = "0" apkNameSuffix = "0"
@ -175,7 +182,7 @@ owner = ''
packNum = 0 packNum = 0
start = 0 start = 0
#----------------------- third qudao start---------------------- # ----------------------- third qudao start----------------------
appid = '' appid = ''
gism_id = '' gism_id = ''
gism_name = '' gism_name = ''
@ -192,196 +199,190 @@ lg_reyun_io_appkey = ''
lg_reyun_io_channelId = '' lg_reyun_io_channelId = ''
eventType = '' eventType = ''
# ----------------------- third qudao end------------------------
#----------------------- third qudao end------------------------ print('-------------------- your channel.json values --------------------')
# print 'channel.json list: ', channelList
print ('-------------------- your channel values --------------------') if 'apkname' in channelList:
#print 'channel list: ', channelList print('apkname==%s' % channelList['apkname'])
print('apkname value==%s' % channelList['apkname']['value'])
if 'apkname' in channelList : print('apkname suffix==%s' % channelList['apkname']['suffix'])
print ('apkname==%s' %channelList['apkname'])
print ('apkname value==%s' %channelList['apkname']['value'])
print ('apkname suffix==%s' %channelList['apkname']['suffix'])
apkName = channelList['apkname']['value'] apkName = channelList['apkname']['value']
apkNameSuffix = channelList['apkname']['suffix'] apkNameSuffix = channelList['apkname']['suffix']
else : else:
apkName = isFindApk('./') apkName = isFindApk('./')
if 'packageId' in channelList:
if 'packageId' in channelList : print('packageId==%s' % channelList['packageId'])
print ('packageId==%s' %channelList['packageId']) print('packageId value==%s' % channelList['packageId']['value'])
print ('packageId value==%s' %channelList['packageId']['value']) print('packageId suffix==%s' % channelList['packageId']['suffix'])
print ('packageId suffix==%s' %channelList['packageId']['suffix'])
packageId = channelList['packageId']['value'] packageId = channelList['packageId']['value']
packageIdSuffix = channelList['packageId']['suffix'] packageIdSuffix = channelList['packageId']['suffix']
else : else:
print ("no key packageId") print("no key packageId")
if 'leguChannel' in channelList : if 'leguChannel' in channelList:
print ('leguchannel==%s' %channelList['leguChannel']) print('leguchannel==%s' % channelList['leguChannel'])
print ('leguchannel value==%s' %channelList['leguChannel']['value']) print('leguchannel value==%s' % channelList['leguChannel']['value'])
print ('leguchannel suffix==%s' %channelList['leguChannel']['suffix']) print('leguchannel suffix==%s' % channelList['leguChannel']['suffix'])
easyName = channelList['leguChannel']['value'] easyName = channelList['leguChannel']['value']
easyNameSuffix = channelList['leguChannel']['suffix'] easyNameSuffix = channelList['leguChannel']['suffix']
else : else:
print ("no key leguChannel") print("no key leguChannel")
if 'keystore' in channelList : if 'keystore' in channelList:
print ('keystore==%s' %channelList['keystore']) print('keystore==%s' % channelList['keystore'])
print ('keystore filename==%s' %channelList['keystore']['filename']) print('keystore filename==%s' % channelList['keystore']['filename'])
print ('keystore storepass==%s' %channelList['keystore']['storepass']) print('keystore storepass==%s' % channelList['keystore']['storepass'])
print ('keystore alianame==%s' %channelList['keystore']['alianame']) print('keystore alianame==%s' % channelList['keystore']['alianame'])
print ('keystore keypass==%s' %channelList['keystore']['keypass']) print('keystore keypass==%s' % channelList['keystore']['keypass'])
keystore = channelList['keystore']['filename'] keystore = channelList['keystore']['filename']
storepass = channelList['keystore']['storepass'] storepass = channelList['keystore']['storepass']
alianame = channelList['keystore']['alianame'] alianame = channelList['keystore']['alianame']
keypass = channelList['keystore']['keypass'] keypass = channelList['keystore']['keypass']
else : else:
print ("no key keystore") print("no key keystore")
if 'owner' in channelList : if 'owner' in channelList:
print ('owner==%s' %channelList['owner']) print('owner==%s' % channelList['owner'])
print ('owner value==%s' %channelList['owner']['value']) print('owner value==%s' % channelList['owner']['value'])
owner = channelList['owner']['value'] owner = channelList['owner']['value']
else : else:
print ("no key owner") print("no key owner")
if 'num' in channelList : if 'num' in channelList:
print ('num==%s' %channelList['num']) print('num==%s' % channelList['num'])
print ('num value==%s' %channelList['num']['value']) print('num value==%s' % channelList['num']['value'])
print ('num start==%s' %channelList['num']['start']) print('num start==%s' % channelList['num']['start'])
packNum = int(channelList['num']['value']) + 1 packNum = int(channelList['num']['value']) + 1
start = int(channelList['num']['start']) start = int(channelList['num']['start'])
else : else:
print ("no key num") print("no key num")
if 'appid' in channelList:
if 'appid' in channelList : print('appid==%s' % channelList['appid'])
print ('appid==%s' %channelList['appid']) print('appid value==%s' % channelList['appid']['value'])
print ('appid value==%s' %channelList['appid']['value'])
gism_id = channelList['appid']['value'] gism_id = channelList['appid']['value']
else : else:
print ("no key appid") print("no key appid")
if 'gism_id' in channelList : if 'gism_id' in channelList:
print ('gism_id==%s' %channelList['gism_id']) print('gism_id==%s' % channelList['gism_id'])
print ('gism_id value==%s' %channelList['gism_id']['value']) print('gism_id value==%s' % channelList['gism_id']['value'])
gism_id = channelList['gism_id']['value'] gism_id = channelList['gism_id']['value']
else : else:
print ("no key gism_id") print("no key gism_id")
if 'gism_name' in channelList : if 'gism_name' in channelList:
print ('gism_name==%s' %channelList['gism_name']) print('gism_name==%s' % channelList['gism_name'])
print ('gism_name value==%s' %channelList['gism_name']['value']) print('gism_name value==%s' % channelList['gism_name']['value'])
gism_name = channelList['gism_name']['value'] gism_name = channelList['gism_name']['value']
else : else:
print ("no key gism_name") print("no key gism_name")
if 'gism_channel' in channelList : if 'gism_channel' in channelList:
print ('gism_channel==%s' %channelList['gism_channel']) print('gism_channel==%s' % channelList['gism_channel'])
print ('gism_channel value==%s' %channelList['gism_channel']['value']) print('gism_channel value==%s' % channelList['gism_channel']['value'])
gism_channel = channelList['gism_channel']['value'] gism_channel = channelList['gism_channel']['value']
else : else:
print ("no key gism_channel") print("no key gism_channel")
if 'lg_ad_id' in channelList : if 'lg_ad_id' in channelList:
print ('lg_ad_id==%s' %channelList['lg_ad_id']) print('lg_ad_id==%s' % channelList['lg_ad_id'])
print ('lg_ad_id value==%s' %channelList['lg_ad_id']['value']) print('lg_ad_id value==%s' % channelList['lg_ad_id']['value'])
lg_ad_id = channelList['lg_ad_id']['value'] lg_ad_id = channelList['lg_ad_id']['value']
else : else:
print ("no key lg_ad_id") print("no key lg_ad_id")
if 'lg_ad_name' in channelList : if 'lg_ad_name' in channelList:
print ('lg_ad_name==%s' %channelList['lg_ad_name']) print('lg_ad_name==%s' % channelList['lg_ad_name'])
print ('lg_ad_name value==%s' %channelList['lg_ad_name']['value']) print('lg_ad_name value==%s' % channelList['lg_ad_name']['value'])
lg_ad_name = channelList['lg_ad_name']['value'] lg_ad_name = channelList['lg_ad_name']['value']
else : else:
print ("no key lg_ad_name") print("no key lg_ad_name")
if 'gactionId' in channelList : if 'gactionId' in channelList:
print ('gactionId==%s' %channelList['gactionId']) print('gactionId==%s' % channelList['gactionId'])
print ('gactionId value==%s' %channelList['gactionId']['value']) print('gactionId value==%s' % channelList['gactionId']['value'])
gactionId = channelList['gactionId']['value'] gactionId = channelList['gactionId']['value']
else : else:
print ("no key gactionId") print("no key gactionId")
if 'gappSecretKey' in channelList : if 'gappSecretKey' in channelList:
print ('gappSecretKey==%s' %channelList['gappSecretKey']) print('gappSecretKey==%s' % channelList['gappSecretKey'])
print ('gappSecretKey value==%s' %channelList['gappSecretKey']['value']) print('gappSecretKey value==%s' % channelList['gappSecretKey']['value'])
gism_id = channelList['gappSecretKey']['value'] gism_id = channelList['gappSecretKey']['value']
else : else:
print ("no key gappSecretKey") print("no key gappSecretKey")
if 'baiduId' in channelList : if 'baiduId' in channelList:
print ('baiduId ==%s' %channelList['baiduId']) print('baiduId ==%s' % channelList['baiduId'])
print ('baiduId value==%s' %channelList['baiduId']['value']) print('baiduId value==%s' % channelList['baiduId']['value'])
gism_id = channelList['baiduId']['value'] gism_id = channelList['baiduId']['value']
else : else:
print ("no key baiduId") print("no key baiduId")
if 'baiduSecretKey' in channelList : if 'baiduSecretKey' in channelList:
#print 'baiduSecretKey==', channelList['baiduSecretKey'] # print 'baiduSecretKey==', channelList['baiduSecretKey']
#print 'baiduSecretKey value==', channelList['baiduSecretKey']['value'] # print 'baiduSecretKey value==', channelList['baiduSecretKey']['value']
gism_id = channelList['baiduSecretKey']['value'] gism_id = channelList['baiduSecretKey']['value']
else : else:
print ("no key baiduSecretKey") print("no key baiduSecretKey")
if 'lg_reyun_game_appkey' in channelList : if 'lg_reyun_game_appkey' in channelList:
#print 'lg_reyun_game_appkey==', channelList['lg_reyun_game_appkey'] # print 'lg_reyun_game_appkey==', channelList['lg_reyun_game_appkey']
#print 'lg_reyun_game_appkey value==', channelList['lg_reyun_game_appkey']['value'] # print 'lg_reyun_game_appkey value==', channelList['lg_reyun_game_appkey']['value']
gism_id = channelList['lg_reyun_game_appkey']['value'] gism_id = channelList['lg_reyun_game_appkey']['value']
else : else:
print ("no key lg_reyun_game_appkey") print("no key lg_reyun_game_appkey")
if 'lg_reyun_game_channelId' in channelList : if 'lg_reyun_game_channelId' in channelList:
#print 'lg_reyun_game_channelId==', channelList['lg_reyun_game_channelId'] # print 'lg_reyun_game_channelId==', channelList['lg_reyun_game_channelId']
#print 'lg_reyun_game_channelId value==', channelList['lg_reyun_game_channelId']['value'] # print 'lg_reyun_game_channelId value==', channelList['lg_reyun_game_channelId']['value']
gism_id = channelList['lg_reyun_game_channelId']['value'] gism_id = channelList['lg_reyun_game_channelId']['value']
else : else:
print ("no key lg_reyun_game_channelId") print("no key lg_reyun_game_channelId")
if 'lg_reyun_io_appkey' in channelList : if 'lg_reyun_io_appkey' in channelList:
#print 'lg_reyun_io_appkey==', channelList['lg_reyun_io_appkey'] # print 'lg_reyun_io_appkey==', channelList['lg_reyun_io_appkey']
#print 'lg_reyun_io_appkey value==', channelList['lg_reyun_io_appkey']['value'] # print 'lg_reyun_io_appkey value==', channelList['lg_reyun_io_appkey']['value']
gism_id = channelList['lg_reyun_io_appkey']['value'] gism_id = channelList['lg_reyun_io_appkey']['value']
else : else:
print ("no key lg_reyun_io_appkey") print("no key lg_reyun_io_appkey")
if 'lg_reyun_io_channelId' in channelList : if 'lg_reyun_io_channelId' in channelList:
#print 'lg_reyun_io_channelId==', channelList['lg_reyun_io_channelId'] # print 'lg_reyun_io_channelId==', channelList['lg_reyun_io_channelId']
#print 'lg_reyun_io_channelId value==', channelList['lg_reyun_io_channelId']['value'] # print 'lg_reyun_io_channelId value==', channelList['lg_reyun_io_channelId']['value']
gism_id = channelList['lg_reyun_io_channelId']['value'] gism_id = channelList['lg_reyun_io_channelId']['value']
else : else:
print ("no key lg_reyun_io_channelId") print("no key lg_reyun_io_channelId")
if 'eventType' in channelList : if 'eventType' in channelList:
#print 'eventType==', channelList['eventType'] # print 'eventType==', channelList['eventType']
#print 'eventType value==', channelList['eventType']['value'] # print 'eventType value==', channelList['eventType']['value']
gism_id = channelList['eventType']['value'] gism_id = channelList['eventType']['value']
else : else:
print ("no key eventType") print("no key eventType")
output_apk_dir = "./bin"
output_apk_dir="./bin"
if os.path.exists(output_apk_dir): if os.path.exists(output_apk_dir):
shutil.rmtree(output_apk_dir) shutil.rmtree(output_apk_dir)
print ('apkname--==%s' %apkName) print('apkname--==%s' % apkName)
if apkName == '' : if apkName == '':
print ('apkName no, stop ...') print('apkName no, stop ...')
sys.exit() sys.exit()
else : else:
cmdExtract = r'java -jar apktool.jar d -f -s %s -o temp'% (apkName) cmdExtract = r'java -jar apktool.jar d -f -s %s -o temp' % (apkName)
os.system(cmdExtract) os.system(cmdExtract)
backUpManifest() backUpManifest()
for channel in range(start, packNum) : for channel in range(start, packNum):
modifyChannel(channel) modifyChannel(channel)
if os.path.exists('./temp'): if os.path.exists('./temp'):
shutil.rmtree('./temp') shutil.rmtree('./temp')
if os.path.exists('./AndroidManifest.xml'): if os.path.exists('./AndroidManifest.xml'):
os.remove('./AndroidManifest.xml') os.remove('./AndroidManifest.xml')
print ('Done') print('Done')

View File

@ -1 +0,0 @@
{"leguChannel": {"value": "test7", "suffix": "1"}, "num": {"value": "1", "start": "1"}, "keystore": {"filename": "/www/wwwroot/legusdk/app/Components/SDK/ApkTool/keystore/legu729.keystore", "storepass": "123456", "alianame": "legu", "keypass": "123456"}}

17
ApkTool/channel.json Normal file
View File

@ -0,0 +1,17 @@
{
"apkname":{"value":"/data/bale_apk/ApkTool/gmswz_TT_gy_01.apk"},
"leguChannel": {
"value": "test7",
"suffix": "1"
},
"num": {
"value": "1",
"start": "1"
},
"keystore": {
"filename": "/www/wwwroot/legusdk/app/Components/SDK/ApkTool/keystore/legu729.keystore",
"storepass": "123456",
"alianame": "legu",
"keypass": "123456"
}
}

View File

@ -13,13 +13,13 @@ router = APIRouter()
# #
# @router.post("/channel") # @router.post("/channel.json")
# async def channel( # async def channel.json(
# data_in: schemas.BaleCreate # data_in: schemas.BaleCreate
# ) -> schemas.Msg: # ) -> schemas.Msg:
# file = os.path.join(settings.ROOT_DIR, 'ApkTool/channel') # file = os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json')
# with open(file, 'w') as f: # with open(file, 'w') as f:
# json.dump(data_in.channel, f) # json.dump(data_in.channel.json, f)
# #
# resp = schemas.Msg( # resp = schemas.Msg(
# code=0, # code=0,
@ -130,7 +130,7 @@ async def run(
) )
return resp return resp
file = os.path.join(settings.ROOT_DIR, 'ApkTool/channel') file = os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json')
with open(file, 'w') as f: with open(file, 'w') as f:
json.dump(data_in.channel, f) json.dump(data_in.channel, f)

View File

@ -1,3 +1,8 @@
from utils import bale import os
bale.run_bale_apk('aa',334) from utils import MakeTool
from core.config import settings
make_tool = MakeTool(os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json'))
a, b = make_tool.run()
print(a, b)

View File

@ -1,2 +1,3 @@
# coding:utf-8 # coding:utf-8
from .bale import bale from .bale import bale
from .make_tool import MakeTool

View File

@ -5,6 +5,7 @@ import os
import requests import requests
from core.config import settings from core.config import settings
from .make_tool import MakeTool
from .put_file import put_file from .put_file import put_file
@ -15,13 +16,25 @@ class Bale:
def run_bale_apk(cls, dir_, id_): def run_bale_apk(cls, dir_, id_):
try: try:
pkg_num = 0 pkg_num = 0
with open(os.path.join(settings.ROOT_DIR, 'ApkTool/channel'), 'r') as f: with open(os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json'), 'r') as f:
props = json.load(f) props = json.load(f)
pkg_num = int(props.get('num', {}).get('value', 0)) pkg_num = int(props.get('num', {}).get('value', 0))
cls.status = 'busy' cls.status = 'busy'
cmd = os.path.join(settings.ROOT_DIR, 'ApkTool/run.sh') make_tool = MakeTool(os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json'))
os.system(cmd) a, b = make_tool.run()
if not a:
data = {
'id': id_,
'url': '',
'apkname': '',
'total_pkg': pkg_num,
'current_pkg': 0,
'done': 0,
'code': -1,
'msg': b
}
requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
path = os.path.join(settings.ROOT_DIR, 'ApkTool/bin') path = os.path.join(settings.ROOT_DIR, 'ApkTool/bin')
if not os.path.exists(path): if not os.path.exists(path):
@ -36,14 +49,27 @@ class Bale:
is_ok, msg = put_file(f'{dir_}/{item}', os.path.join(path, item)) is_ok, msg = put_file(f'{dir_}/{item}', os.path.join(path, item))
os.remove(os.path.join(path, item)) os.remove(os.path.join(path, item))
if not is_ok: if not is_ok:
continue
data = { data = {
'id': id_, 'id': id_,
'url': msg, 'url': msg,
'apkname': item, 'apkname': item,
'done': int(count >= pkg_num) 'total_pkg': pkg_num,
'current_pkg': count,
'done': int(count >= pkg_num),
'code': -1,
'msg': msg
} }
resp = requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data) requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
data = {
'id': id_,
'url': msg,
'apkname': item,
'total_pkg': pkg_num,
'current_pkg': count,
'done': int(count >= pkg_num),
'code': 0
}
requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
print(f'上传:{item} 完成') print(f'上传:{item} 完成')

230
utils/make_tool.py Normal file
View File

@ -0,0 +1,230 @@
# coding:utf-8
import json
import os
import shutil
from core.config import settings
class MakeTool:
MakeDir = os.path.join(settings.ROOT_DIR, 'ApkTool')
def __init__(self, channel_path):
self.channel_path = channel_path
self.apkName = ''
self.apkNameSuffix = '0'
self.easyName = ''
self.easyNameSuffix = '0'
self.packageId = ''
self.packageIdSuffix = '0'
self.keystore = ''
self.storepass = ''
self.alianame = ''
self.keypass = ''
self.owner = ''
self.packNum = 0
self.start = 0
self.appid = ''
self.gism_id = ''
self.gism_name = ''
self.gism_channel = ''
self.lg_ad_id = ''
self.lg_ad_name = ''
self.gactionId = ''
self.gappSecretKey = ''
self.baiduId = ''
self.baiduSecretKey = ''
self.lg_reyun_game_appkey = ''
self.lg_reyun_game_channelId = ''
self.lg_reyun_io_appkey = ''
self.lg_reyun_io_channelId = ''
self.eventType = ''
def _init_props(self):
# 提取参数
props = dict()
with open(self.channel_path, 'r') as f:
props = json.load(f)
# 母包路径
self.apkName = props.get('apkname', {}).get('value') or self.apkName
self.apkNameSuffix = props.get('apkname', {}).get('suffix') or self.apkNameSuffix
self.easyName = props.get('leguChannel', {}).get('value') or self.easyName
self.easyNameSuffix = props.get('leguChannel', {}).get('suffix') or self.easyNameSuffix
self.packageId = props.get('packageId', {}).get('value') or self.packageId
self.packageIdSuffix = props.get('packageId', {}).get('suffix') or self.packageIdSuffix
self.keystore = props.get('keystore', {}).get('filename') or self.keystore
self.storepass = props.get('keystore', {}).get('storepass') or self.storepass
self.alianame = props.get('keystore', {}).get('alianame') or self.alianame
self.keypass = props.get('keystore', {}).get('keypass') or self.keypass
self.owner = props.get('owner', {}).get('value') or self.owner
self.packNum = props.get('num', {}).get('value') or self.packNum
self.start = props.get('num', {}).get('start') or self.start
self.start = int(self.start)
self.packNum = int(self.packNum) + 1
self.appid = props.get('appid', {}).get('value') or self.appid
self.gism_id = props.get('gism_id', {}).get('value') or self.gism_id
self.gism_name = props.get('gism_name', {}).get('value') or self.gism_name
self.gism_channel = props.get('gism_channel', {}).get('value') or self.gism_channel
self.lg_ad_id = props.get('lg_ad_id', {}).get('value') or self.lg_ad_id
self.lg_ad_name = props.get('lg_ad_name', {}).get('value') or self.lg_ad_name
self.gactionId = props.get('gactionId', {}).get('value') or self.gactionId
self.gappSecretKey = props.get('gappSecretKey', {}).get('value') or self.gappSecretKey
self.baiduId = props.get('baiduId', {}).get('value') or self.baiduId
self.baiduSecretKey = props.get('baiduSecretKey', {}).get('value') or self.baiduSecretKey
self.lg_reyun_game_appkey = props.get('lg_reyun_game_appkey', {}).get('value') or self.lg_reyun_game_appkey
self.lg_reyun_game_channelId = props.get('lg_reyun_game_channelId', {}).get(
'value') or self.lg_reyun_game_channelId
self.lg_reyun_io_appkey = props.get('lg_reyun_io_appkey', {}).get('value') or self.lg_reyun_io_appkey
self.lg_reyun_io_channelId = props.get('lg_reyun_io_channelId', {}).get('value') or self.lg_reyun_io_channelId
self.eventType = props.get('eventType', {}).get('value') or self.eventType
def _init_path(self):
bin_dir = os.path.join(self.MakeDir, 'bin')
if os.path.exists(bin_dir):
shutil.rmtree(bin_dir)
os.makedirs(bin_dir)
def check_props(self):
if not os.path.exists(self.apkName):
return False, '缺少apkName路径'
return True, 'ok'
def modify_channel(self, value):
tempXML = ''
with open(os.path.join(self.MakeDir, 'AndroidManifest.xml')) as f:
for line in f:
if line.find('leguChannel') > 0 and self.easyName != '':
if self.easyNameSuffix == "1":
if value < 10:
line = '<meta-data android:name="leguChannel" android:value="%s_0%d"/>' % (
self.easyName, value)
else:
line = '<meta-data android:name="leguChannel" android:value="%s_%d"/>' % (
self.easyName, value)
else:
line = '<meta-data android:name="leguChannel" android:value="%s"/>' % (self.easyName)
elif line.find('owner') > 0 and self.owner != '':
print('owner====%s' % line)
line = '<meta-data android:name="owner" android:value="%s"/>' % (self.owner)
elif line.find('package') > 0 and self.packageId != '':
print('package====%s' % line)
line = '<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="30" android:compileSdkVersionCodename="11" android:installLocation="auto" package="%s" platformBuildVersionCode="30" platformBuildVersionName="11">' % (
self.packageId)
elif line.find('appid') > 0 and self.appid != '':
print('appid====%s' % line)
line = '<meta-data android:name="appid" android:value="%s"/>' % (self.appid)
elif line.find('gism_id') > 0 and self.gism_id != '':
print('gism_id====%s' % line)
line = '<meta-data android:name="gism_id" android:value="%s"/>' % (self.gism_id)
elif line.find('gism_name') > 0 and self.gism_name != '':
print('gism_name====%s' % line)
line = '<meta-data android:name="gism_name" android:value="%s"/>' % (self.gism_name)
elif line.find('gism_channel') > 0 and self.gism_channel != '':
print('gism_channel====%s' % line)
line = '<meta-data android:name="gism_channel" android:value="%s"/>' % (self.gism_channel)
elif line.find('lg_ad_id') > 0 and self.lg_ad_id != '':
print('lg_ad_id====%s' % line)
line = '<meta-data android:name="lg_ad_id" android:value="%s"/>' % (self.lg_ad_id)
elif line.find('lg_ad_name') > 0 and self.lg_ad_name != '':
print('lg_ad_name====%s' % line)
line = '<meta-data android:name="lg_ad_name" android:value="%s"/>' % (self.lg_ad_name)
elif line.find('gactionId') > 0 and self.gactionId != '':
print('gactionId====%s' % line)
line = '<meta-data android:name="gactionId" android:value="%s"/>' % (self.gactionId)
elif line.find('gappSecretKey') > 0 and self.gappSecretKey != '':
print('gappSecretKey====%s' % line)
line = '<meta-data android:name="gappSecretKey" android:value="%s"/>' % (self.gappSecretKey)
elif line.find('baiduId') > 0 and self.baiduId != '':
print('baiduId====%s' % line)
line = '<meta-data android:name="baiduId" android:value="%s"/>' % (self.baiduId)
elif line.find('baiduSecretKey') > 0 and self.baiduSecretKey != '':
print('baiduSecretKey====%s' % line)
line = '<meta-data android:name="baiduSecretKey" android:value="%s"/>' % (self.baiduSecretKey)
elif line.find('lg_reyun_game_appkey') > 0 and self.lg_reyun_game_appkey != '':
print('lg_reyun_game_appkey====%s' % line)
line = '<meta-data android:name="lg_reyun_game_appkey" android:value="%s"/>' % (
self.lg_reyun_game_appkey)
elif line.find('lg_reyun_game_channelId') > 0 and self.lg_reyun_game_channelId != '':
print('lg_reyun_game_channelId====%s' % line)
line = '<meta-data android:name="lg_reyun_game_channelId" android:value="%s"/>' % (
self.lg_reyun_game_channelId)
elif line.find('lg_reyun_io_appkey') > 0 and self.lg_reyun_io_appkey != '':
print('lg_reyun_io_appkey====%s' % line)
line = '<meta-data android:name="lg_reyun_io_appkey" android:value="%s"/>' % (
self.lg_reyun_io_appkey)
elif line.find('lg_reyun_io_channelId') > 0 and self.lg_reyun_io_channelId != 0:
print('lg_reyun_io_channelId====%s' % line)
line = '<meta-data android:name="lg_reyun_io_channelId" android:value="%s"/>' % (
self.lg_reyun_io_channelId)
elif line.find('eventType') > 0 and self.eventType != '':
print('eventType====%s' % line)
line = '<meta-data android:name="eventType" android:value="%s"/>' % (self.eventType)
tempXML += line
with open(os.path.join(self.MakeDir, 'temp/AndroidManifest.xml'), 'w') as f:
f.write(tempXML)
unsignApk = os.path.join(self.MakeDir, f'bin/{self.easyName}_{value}_unsigned.apk')
cmdPack = f'cd {self.MakeDir} && java -jar apktool.jar b temp -o {unsignApk}'
os.system(cmdPack)
signedjar = os.path.join(self.MakeDir, f'bin/{self.easyName}_{value}.apk')
unsignedjar = os.path.join(self.MakeDir, f'bin/{self.easyName}_{value}_unsigned.apk')
cmd_sign = f'cd {self.MakeDir} && jarsigner -verbose -digestalg SHA1 -sigalg MD5withRSA -keystore {self.keystore} -storepass {self.storepass} -keypass {self.keypass} -signedjar {signedjar} {unsignedjar} {self.alianame}'
os.system(cmd_sign)
os.remove(unsignedjar)
def _unpack(self, pack_name):
"""
解包
:param pack_name:
:return:
"""
cmd = f'cd {self.MakeDir} && java -jar apktool.jar d -f -s {self.apkName} -o temp'
os.system(cmd)
androidmanifest_path = os.path.join(self.MakeDir, 'AndroidManifest.xml')
if os.path.exists(androidmanifest_path):
os.remove(androidmanifest_path)
new_androidmanifest_path = os.path.join(self.MakeDir, 'temp/AndroidManifest.xml')
shutil.copyfile(new_androidmanifest_path, androidmanifest_path)
def _clear(self):
path = os.path.join(self.MakeDir, 'temp')
if os.path.exists(path):
shutil.rmtree(path)
path = os.path.join(self.MakeDir, 'AndroidManifest.xml')
if os.path.exists(path):
os.remove(path)
def _make(self):
"""
重新编译包
:return:
"""
for i in range(self.start, self.packNum):
self.modify_channel(i)
def run(self):
try:
self._init_props()
self._init_path()
is_ok, msg = self.check_props()
if not is_ok:
return False, msg
self._unpack(self.apkName)
self._make()
self._clear()
except Exception as e:
return False, str(e)
else:
return True, 'ok'