Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 is supported #694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions matrix/matrix-iOS/Script/battery2apple.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
'''
@Author: mattzheng
Expand All @@ -11,14 +11,16 @@
import os
import sys
import cgi
import html
from datetime import datetime
import traceback
import importlib

MM_IMG_LIST = ['MicroMessenger', 'WeChat', 'WeChatShareExtension', 'WeChatWatchExtension']
Component_IMG_LIST = ['MMCommon', 'MMCoreFoundation', 'MMPLCrashReporter', 'PublicComponentDylib', 'MMFoundationDylib','MMLibHooks', 'matrixreport', 'Matrix', 'QBar']

reload(sys)
sys.setdefaultencoding('utf8')
importlib.reload(sys)
# sys.setdefaultencoding('utf8')

def is_image_wechat(image_name):
return image_name in MM_IMG_LIST + Component_IMG_LIST
Expand Down Expand Up @@ -142,7 +144,7 @@ def get_crash_thread(report):
crash = get_crash_info(report)
if not crash:
return []
#print crash
print(crash)
threads = crash['threads']
for thread in threads:
crashed = thread.get('crashed', False)
Expand Down Expand Up @@ -211,7 +213,7 @@ def parse_system_info(report):
os_table ='%s_%s' %(_s('system_version').replace('.','_'), _s('os_version'))
if _s('cpu_arch') == "arm64e":
os_table += '_%s' % _s('cpu_arch')
print "os_table:", os_table
print("os_table:", os_table)

user_info = report.get("user", None)
if user_info and user_info.get('WeChat'):
Expand Down Expand Up @@ -261,7 +263,7 @@ def parse_error_info(report):
return []
error = crash.get('error')
if not error:
print "waring: no error found in crash"
print("waring: no error found in crash")
return []
mach = error['mach']
signal = error['signal']
Expand All @@ -285,10 +287,10 @@ def parse_error_info(report):
result.append('Crashed Thread: {0}'.format(crash_thread))

diagnosis = crash.get('diagnosis', None)
#print "fuck haha", diagnosis
print("fuck haha", diagnosis)
if diagnosis:
result.append('\nCrashDoctor Diagnosis: {0}'.format(diagnosis))
#print result
print(result)
return result

def parse_crash_reason(report):
Expand All @@ -304,7 +306,7 @@ def parse_crash_reason(report):

error = crash.get('error')
if not error:
print "warning: no error found in crash"
print("warning: no error found in crash")
return []
crash_type = error['type']

Expand Down Expand Up @@ -351,14 +353,14 @@ def parse_backtrace(result, img_info, stack_string, mask_pc=True):
img_name = os.path.basename(trace['image_name'])
img = img_info.get(img_name)
if not img:
print "fuck"
print("fuck")
for name in img_info:
if img_info[name]['image_addr'] <= pc <= img_info[name]['image_addr']+ img_info[name]['image_size']:
img = img_info[name]
break
if not img:
print "error, no img found for pc: %s, instruction_address: %s" % (pc, trace['instruction_address'])
print img_name
print("error, no img found for pc: %s, instruction_address: %s" % (pc, trace['instruction_address']))
print(img_name)
result.append('{0:<4}{1:31} 0x{2:016x}'.format(num, 'unknown', pc))
num += 1
continue
Expand Down Expand Up @@ -432,7 +434,7 @@ def parse_thread_list(report):
crash = get_crash_info(report)
if not crash:
return []
#print dump_json( crash)
print(dump_json( crash))
threads = crash['threads']

result = []
Expand All @@ -444,7 +446,7 @@ def parse_thread_list(report):

def get_register_order(cpu):
cpu = cpu.lower()
#print "cpu %s" % cpu
print("cpu %s" % cpu)
arm = [ 'x'+str(i) for i in range(30)] + ['fp','sp', 'lr', 'pc',
'cpsr']
x86 = ['eax', 'ebx', 'ecx', 'edx', 'edi', 'esi', 'ebp',
Expand Down Expand Up @@ -519,8 +521,8 @@ def parse_binary_images(report):
path = image['name']
name = os.path.basename(path)
uuid = image['uuid'].lower().replace('-', '')
print 'parse_binary_images'
print name, uuid
print('parse_binary_images')
print(name, uuid)
is_base = '+' if path==exe_path else ' '
if False:#image_count <=10 and not is_image_wechat(name) and simple_symbol_find.uuid_find(uuid) == False:
#name = "<em style=\"color: red;\">%s</em>"%name
Expand All @@ -529,14 +531,14 @@ def parse_binary_images(report):
uuid, path))
else:
if name == 'WeChat':
print '{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'.format(addr, addr+size-1, is_base, name,uuid, path)
print('{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'.format(addr, addr+size-1, is_base, name,uuid, path))
pass
result.append('{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'\
.format(addr, addr+size-1, is_base, name,
uuid, path))
except:
traceback.print_exc()
print image
print(image)
return
continue

Expand Down Expand Up @@ -703,7 +705,7 @@ def parse_other_info(report):
result = ['']
user_info = report.get("user", None)
if not user_info or not user_info.get("WeChat", None) or not user_info["WeChat"].get("log"):
print "no log found..."
print("no log found...")
return result

log_list = user_info["WeChat"]["log"][-2:]
Expand Down Expand Up @@ -733,34 +735,34 @@ def ks_json_2_apple(report, fout):
# fout.write(line+'\n')
stack_info = parse_stack_info(report)
for line in stack_info:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

cpu_state = parse_cpu_state(report)
for line in cpu_state:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

images = parse_binary_images(report)
for line in images:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

extra = parse_extra_info(report)
for line in extra:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

log_info = parse_log_info(report)
for line in log_info:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

if __name__ == '__main__':
reload(sys)
sys.setdefaultencoding('utf-8')
importlib.reload(sys)
# sys.setdefaultencoding('utf-8')
if len(sys.argv) != 3:
print "usage: python2.7 %s json_file out_file" % sys.argv[0]
print("usage: python3 %s json_file out_file" % sys.argv[0])
sys.exit(1)

report = json.load(open(sys.argv[1]))
Expand Down
46 changes: 24 additions & 22 deletions matrix/matrix-iOS/Script/ks2apple.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
'''
@Author: mattzheng
Expand All @@ -12,13 +12,15 @@
import os
import sys
import cgi
import html
import optparse
import traceback
from datetime import datetime
import importlib


reload(sys)
sys.setdefaultencoding('utf-8')
importlib.reload(sys)
# sys.setdefaultencoding('utf-8')

device_map = {
'iPod1,1' : 'iPod touch 1G',
Expand Down Expand Up @@ -209,7 +211,7 @@ def get_crash_thread(report):
crash = get_crash_info(report)
if not crash:
return []
#print crash
print(crash)
threads = crash['threads']
for thread in threads:
crashed = thread.get('crashed', False)
Expand Down Expand Up @@ -269,7 +271,7 @@ def parse_system_info(report):

headers = ['System Info: {']
device = _s('machine')
if device_map.has_key(device):
if device in device_map:
device = device_map[device]
headers.append(' Device: {0}'.format(device))
headers.append(' OS Version: {0} {1} ({2})'.format(_s('system_name'), _s('system_version'), _s('os_version')))
Expand Down Expand Up @@ -323,7 +325,7 @@ def parse_error_info(report):
return []
error = crash.get('error')
if not error:
print "waring: no error found in crash"
print("waring: no error found in crash")
return []
mach = error['mach']
signal = error['signal']
Expand All @@ -347,10 +349,10 @@ def parse_error_info(report):
result.append('Crashed Thread: {0}'.format(crash_thread))

diagnosis = crash.get('diagnosis', None)
#print "fuck haha", diagnosis
print("fuck haha", diagnosis)
if diagnosis:
result.append('\nCrashDoctor Diagnosis: {0}'.format(diagnosis))
#print result
print(result)
return result

def parse_crash_reason(report):
Expand All @@ -366,7 +368,7 @@ def parse_crash_reason(report):

error = crash.get('error')
if not error:
print "warning: no error found in crash"
# print "warning: no error found in crash"
return []
crash_type = error['type']

Expand Down Expand Up @@ -410,7 +412,7 @@ def parse_backtrace(report, backtrace):

img = get_belong_img(report, pc)
if not img:
print "error, no img found for pc: %s" % pc
print("error, no img found for pc: %s" % pc)
result.append('{0:<4}{1:31} 0x{2:016x}'.format(num, 'unknown', pc))
num += 1
continue
Expand Down Expand Up @@ -474,7 +476,7 @@ def parse_thread_list(report):
crash = get_crash_info(report)
if not crash:
return []
#print dump_json( crash)
print(dump_json( crash))
threads = crash['threads']

result = []
Expand All @@ -486,7 +488,7 @@ def parse_thread_list(report):

def get_register_order(cpu):
cpu = cpu.lower()
#print "cpu %s" % cpu
print("cpu %s" % cpu)
arm = [ 'x'+str(i) for i in range(30)] + ['fp','sp', 'lr', 'pc',
'cpsr']
x86 = ['eax', 'ebx', 'ecx', 'edx', 'edi', 'esi', 'ebp',
Expand Down Expand Up @@ -569,7 +571,7 @@ def parse_binary_images(report):
uuid, path))
else:
if name == 'WeChat':
print '{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'.format(addr, addr+size-1, is_base, name,uuid, path)
print('{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'.format(addr, addr+size-1, is_base, name,uuid, path))
result.append('{0:>#18x} - {1:>#18x} {2}{3} <{4}> {5}'\
.format(addr, addr+size-1, is_base, name,
uuid, path))
Expand Down Expand Up @@ -740,7 +742,7 @@ def parse_other_info(report):
result = ['']
user_info = report.get("user", None)
if not user_info or not user_info.get(APP_NAME, None) or not user_info[APP_NAME].get("log"):
print "no log found..."
print("no log found...")
return result

log_list = user_info[APP_NAME]["log"][-2:]
Expand All @@ -763,7 +765,7 @@ def ks_json_2_apple(report, fout):
traceback.print_exc()
errors = []
for line in errors:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

try:
Expand All @@ -772,7 +774,7 @@ def ks_json_2_apple(report, fout):
traceback.print_exc()
reason = []
for line in reason:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

try:
Expand Down Expand Up @@ -801,17 +803,17 @@ def ks_json_2_apple(report, fout):
# fout.write(line+'\n')
click_info = parse_click_info(report)
for line in click_info:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

threads = parse_thread_list(report)
for line in threads:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

cpu_state = parse_cpu_state(report)
for line in cpu_state:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

images = parse_binary_images(report)
Expand All @@ -821,12 +823,12 @@ def ks_json_2_apple(report, fout):

extra = parse_extra_info(report)
for line in extra:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

log_info = parse_log_info(report)
for line in log_info:
line = cgi.escape(line)
line = html.escape(line)
fout.write(line+'\n')

if __name__ == '__main__':
Expand All @@ -843,7 +845,7 @@ def ks_json_2_apple(report, fout):
fout = open(options.output_file, 'w')

if type(reports) is list:
print("this intput file contains %d report" %(len(reports)))
print(("this intput file contains %d report" %(len(reports))))
for report in reports:
fout.write("*------------------------------- report split line----------------------------*\n")
ks_json_2_apple(report, fout)
Expand Down