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

View File

@ -5,6 +5,7 @@ import os
import requests
from core.config import settings
from .make_tool import MakeTool
from .put_file import put_file
@ -15,13 +16,25 @@ class Bale:
def run_bale_apk(cls, dir_, id_):
try:
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)
pkg_num = int(props.get('num', {}).get('value', 0))
cls.status = 'busy'
cmd = os.path.join(settings.ROOT_DIR, 'ApkTool/run.sh')
os.system(cmd)
make_tool = MakeTool(os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json'))
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')
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))
os.remove(os.path.join(path, item))
if not is_ok:
continue
data = {
'id': id_,
'url': msg,
'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} 完成')

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'