diff --git a/ApkTool/MakeTool.py b/ApkTool/MakeTool.py
index 756269e..97e29f1 100644
--- a/ApkTool/MakeTool.py
+++ b/ApkTool/MakeTool.py
@@ -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,104 +52,108 @@ 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 = '' % (easyName, value)
- else :
+ else:
line = '' % (easyName, value)
- else :
+ else:
line = '' % (easyName)
- elif line.find('owner') > 0 and owner != '' :
- print ('owner====%s' %line)
- line = '' % (owner)
- elif line.find('package') > 0 and packageId != '' :
- print ('package====%s' %line)
- line = '' % (packageId)
- elif line.find('appid') > 0 and appid != '' :
- print ('appid====%s' %line)
- line = '' % (appid)
- elif line.find('gism_id') > 0 and gism_id != '' :
- print ('gism_id====%s' %line)
- line = '' % (gism_id)
- elif line.find('gism_name') > 0 and gism_name != '' :
- print ('gism_name====%s' %line)
- line = '' % (gism_name)
- elif line.find('gism_channel') > 0 and gism_channel != '' :
- print ('gism_channel====%s' %line)
- line = '' % (gism_channel)
- elif line.find('lg_ad_id') > 0 and lg_ad_id != '' :
- print ('lg_ad_id====%s' %line)
- line = '' % (lg_ad_id)
- elif line.find('lg_ad_name') > 0 and lg_ad_name != '' :
- print ('lg_ad_name====%s' %line)
- line = '' % (lg_ad_name)
- elif line.find('gactionId') > 0 and gactionId != '' :
- print ('gactionId====%s' %line)
- line = '' % (gactionId)
- elif line.find('gappSecretKey') > 0 and gappSecretKey != '' :
- print ('gappSecretKey====%s' %line)
- line = '' % (gappSecretKey)
- elif line.find('baiduId') > 0 and baiduId != '' :
- print ('baiduId====%s' %line)
- line = '' % (baiduId)
- elif line.find('baiduSecretKey') > 0 and baiduSecretKey != '' :
- print ('baiduSecretKey====%s' %line)
- line = '' % (baiduSecretKey)
- elif line.find('lg_reyun_game_appkey') > 0 and lg_reyun_game_appkey != '' :
- print ('lg_reyun_game_appkey====%s' %line)
- line = '' % (lg_reyun_game_appkey)
- elif line.find('lg_reyun_game_channelId') > 0 and lg_reyun_game_channelId != '' :
- print ('lg_reyun_game_channelId====%s' %line)
- line = '' % (lg_reyun_game_channelId)
- elif line.find('lg_reyun_io_appkey') > 0 and lg_reyun_io_appkey != '' :
- print ('lg_reyun_io_appkey====%s' %line)
- line = '' % (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)
- line = '' % (lg_reyun_io_channelId)
- elif line.find('eventType') > 0 and eventType != '' :
- print ('eventType====%s' %line)
- line = '' % (eventType)
+ elif line.find('owner') > 0 and owner != '':
+ print('owner====%s' % line)
+ line = '' % (owner)
+ elif line.find('package') > 0 and packageId != '':
+ print('package====%s' % line)
+ line = '' % (
+ packageId)
+ elif line.find('appid') > 0 and appid != '':
+ print('appid====%s' % line)
+ line = '' % (appid)
+ elif line.find('gism_id') > 0 and gism_id != '':
+ print('gism_id====%s' % line)
+ line = '' % (gism_id)
+ elif line.find('gism_name') > 0 and gism_name != '':
+ print('gism_name====%s' % line)
+ line = '' % (gism_name)
+ elif line.find('gism_channel') > 0 and gism_channel != '':
+ print('gism_channel====%s' % line)
+ line = '' % (gism_channel)
+ elif line.find('lg_ad_id') > 0 and lg_ad_id != '':
+ print('lg_ad_id====%s' % line)
+ line = '' % (lg_ad_id)
+ elif line.find('lg_ad_name') > 0 and lg_ad_name != '':
+ print('lg_ad_name====%s' % line)
+ line = '' % (lg_ad_name)
+ elif line.find('gactionId') > 0 and gactionId != '':
+ print('gactionId====%s' % line)
+ line = '' % (gactionId)
+ elif line.find('gappSecretKey') > 0 and gappSecretKey != '':
+ print('gappSecretKey====%s' % line)
+ line = '' % (gappSecretKey)
+ elif line.find('baiduId') > 0 and baiduId != '':
+ print('baiduId====%s' % line)
+ line = '' % (baiduId)
+ elif line.find('baiduSecretKey') > 0 and baiduSecretKey != '':
+ print('baiduSecretKey====%s' % line)
+ line = '' % (baiduSecretKey)
+ elif line.find('lg_reyun_game_appkey') > 0 and lg_reyun_game_appkey != '':
+ print('lg_reyun_game_appkey====%s' % line)
+ line = '' % (lg_reyun_game_appkey)
+ elif line.find('lg_reyun_game_channelId') > 0 and lg_reyun_game_channelId != '':
+ print('lg_reyun_game_channelId====%s' % line)
+ line = '' % (lg_reyun_game_channelId)
+ elif line.find('lg_reyun_io_appkey') > 0 and lg_reyun_io_appkey != '':
+ print('lg_reyun_io_appkey====%s' % line)
+ line = '' % (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)
+ line = '' % (lg_reyun_io_channelId)
+ elif line.find('eventType') > 0 and eventType != '':
+ print('eventType====%s' % line)
+ line = '' % (eventType)
tempXML += line
f.close()
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)
- chmod(signedjar, "777")
- chmod(unsignedjar, "777")
- 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)
+
+ 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)
+ 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)
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"
@@ -165,17 +172,17 @@ packageIdSuffix = "0"
easyName = ""
easyNameSuffix = "0"
-keystore = ''
+keystore = ''
storepass = ''
-alianame = ''
-keypass = ''
+alianame = ''
+keypass = ''
owner = ''
packNum = 0
start = 0
-#----------------------- third qudao start----------------------
+# ----------------------- third qudao start----------------------
appid = ''
gism_id = ''
gism_name = ''
@@ -185,203 +192,197 @@ lg_ad_name = ''
gactionId = ''
gappSecretKey = ''
baiduId = ''
-baiduSecretKey = ''
-lg_reyun_game_appkey = ''
+baiduSecretKey = ''
+lg_reyun_game_appkey = ''
lg_reyun_game_channelId = ''
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'])
+ apkName = channelList['apkname']['value']
+ apkNameSuffix = channelList['apkname']['suffix']
+else:
+ apkName = isFindApk('./')
-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 :
- 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'])
+ packageId = channelList['packageId']['value']
+ packageIdSuffix = channelList['packageId']['suffix']
+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'])
+ easyName = channelList['leguChannel']['value']
+ easyNameSuffix = channelList['leguChannel']['suffix']
+else:
+ print("no key leguChannel")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+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")
-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")
+if 'baiduSecretKey' in channelList:
+ # print 'baiduSecretKey==', channelList['baiduSecretKey']
+ # print 'baiduSecretKey value==', channelList['baiduSecretKey']['value']
+ gism_id = channelList['baiduSecretKey']['value']
+else:
+ print("no key baiduSecretKey")
-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")
+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")
-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")
+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")
-if 'baiduSecretKey' in channelList :
- #print 'baiduSecretKey==', channelList['baiduSecretKey']
- #print 'baiduSecretKey value==', channelList['baiduSecretKey']['value']
- gism_id = channelList['baiduSecretKey']['value']
-else :
- print ("no key baiduSecretKey")
+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")
-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")
+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")
-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")
+if 'eventType' in channelList:
+ # print 'eventType==', channelList['eventType']
+ # print 'eventType value==', channelList['eventType']['value']
+ gism_id = channelList['eventType']['value']
+else:
+ print("no key eventType")
-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")
-
-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")
-
-if 'eventType' in channelList :
- #print 'eventType==', channelList['eventType']
- #print 'eventType value==', channelList['eventType']['value']
- gism_id = channelList['eventType']['value']
-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')
\ No newline at end of file
+print('Done')
diff --git a/ApkTool/channel b/ApkTool/channel
deleted file mode 100644
index ce7e2ca..0000000
--- a/ApkTool/channel
+++ /dev/null
@@ -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"}}
\ No newline at end of file
diff --git a/ApkTool/channel.json b/ApkTool/channel.json
new file mode 100644
index 0000000..6548a68
--- /dev/null
+++ b/ApkTool/channel.json
@@ -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"
+ }
+}
\ No newline at end of file
diff --git a/api/endpoints/apk_tools.py b/api/endpoints/apk_tools.py
index c101015..a03ca32 100644
--- a/api/endpoints/apk_tools.py
+++ b/api/endpoints/apk_tools.py
@@ -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)
diff --git a/test.py b/test.py
index 4b004ec..d3a8ea7 100644
--- a/test.py
+++ b/test.py
@@ -1,3 +1,8 @@
-from utils import bale
+import os
-bale.run_bale_apk('aa',334)
\ No newline at end of file
+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)
diff --git a/utils/__init__.py b/utils/__init__.py
index 12619de..0c40bef 100644
--- a/utils/__init__.py
+++ b/utils/__init__.py
@@ -1,2 +1,3 @@
# coding:utf-8
from .bale import bale
+from .make_tool import MakeTool
diff --git a/utils/bale.py b/utils/bale.py
index e4fa959..1a2d5f4 100644
--- a/utils/bale.py
+++ b/utils/bale.py
@@ -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,
+ 'total_pkg': pkg_num,
+ 'current_pkg': count,
+ 'done': int(count >= pkg_num),
+ 'code': -1,
+ 'msg': msg
+ }
+ requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
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': 0
}
- resp = requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
+ requests.post('http://gamesdk.legu.cc/api/subpackageRecord/getRecord', data=data)
print(f'上传:{item} 完成')
diff --git a/utils/make_tool.py b/utils/make_tool.py
new file mode 100644
index 0000000..d03dd34
--- /dev/null
+++ b/utils/make_tool.py
@@ -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 = '' % (
+ self.easyName, value)
+ else:
+ line = '' % (
+ self.easyName, value)
+ else:
+ line = '' % (self.easyName)
+ elif line.find('owner') > 0 and self.owner != '':
+ print('owner====%s' % line)
+ line = '' % (self.owner)
+ elif line.find('package') > 0 and self.packageId != '':
+ print('package====%s' % line)
+ line = '' % (
+ self.packageId)
+ elif line.find('appid') > 0 and self.appid != '':
+ print('appid====%s' % line)
+ line = '' % (self.appid)
+ elif line.find('gism_id') > 0 and self.gism_id != '':
+ print('gism_id====%s' % line)
+ line = '' % (self.gism_id)
+ elif line.find('gism_name') > 0 and self.gism_name != '':
+ print('gism_name====%s' % line)
+ line = '' % (self.gism_name)
+ elif line.find('gism_channel') > 0 and self.gism_channel != '':
+ print('gism_channel====%s' % line)
+ line = '' % (self.gism_channel)
+ elif line.find('lg_ad_id') > 0 and self.lg_ad_id != '':
+ print('lg_ad_id====%s' % line)
+ line = '' % (self.lg_ad_id)
+ elif line.find('lg_ad_name') > 0 and self.lg_ad_name != '':
+ print('lg_ad_name====%s' % line)
+ line = '' % (self.lg_ad_name)
+ elif line.find('gactionId') > 0 and self.gactionId != '':
+ print('gactionId====%s' % line)
+ line = '' % (self.gactionId)
+ elif line.find('gappSecretKey') > 0 and self.gappSecretKey != '':
+ print('gappSecretKey====%s' % line)
+ line = '' % (self.gappSecretKey)
+ elif line.find('baiduId') > 0 and self.baiduId != '':
+ print('baiduId====%s' % line)
+ line = '' % (self.baiduId)
+ elif line.find('baiduSecretKey') > 0 and self.baiduSecretKey != '':
+ print('baiduSecretKey====%s' % line)
+ line = '' % (self.baiduSecretKey)
+ elif line.find('lg_reyun_game_appkey') > 0 and self.lg_reyun_game_appkey != '':
+ print('lg_reyun_game_appkey====%s' % line)
+ line = '' % (
+ 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 = '' % (
+ 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 = '' % (
+ 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 = '' % (
+ self.lg_reyun_io_channelId)
+ elif line.find('eventType') > 0 and self.eventType != '':
+ print('eventType====%s' % line)
+ line = '' % (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'