Skip to content

Commit

Permalink
fix 'all message belong to the opposite' bug
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyiyimu <[email protected]>
  • Loading branch information
Yiyiyimu committed Jan 2, 2021
1 parent f6d4b50 commit 1682151
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions QQ_History.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

class QQoutput():
def __init__(self, db, key, mode, s):
self.key = key #解密用的密钥
self.key = key # 解密用的密钥
self.c = sqlite3.connect(db).cursor()
self.mode = mode
self.s = s

def fix(self, data, mode):
#msgdata mode=0
#other mode=1
# msgdata mode=0
# other mode=1
if (mode == 0):
rowbyte = []
for i in range(0, len(data)):
Expand All @@ -40,10 +40,10 @@ def decode(self, cursor):
data = row[0]
MsgEnc = self.s.encode(encoding="utf-8")
KeySet = ""
#for i in range(0,min(len(MsgEnc), len(data))):
# for i in range(0,min(len(MsgEnc), len(data))):
for i in range(0, len(MsgEnc)):
KeySet += chr(data[i] ^ MsgEnc[i])
#TO AVOID LOOP
# TO AVOID LOOP
RealKey, restKey = "", ""
for i in range(4, len(KeySet)):
'''
Expand Down Expand Up @@ -78,24 +78,22 @@ def AddEmoji(self, msg):
break
return msg

def message(self, num, mode):
#mode=1 friend
#mode=2 troop
def message(self, num):
# mode=1 friend
# mode=2 troop
num = str(num).encode("utf-8")
md5num = hashlib.md5(num).hexdigest().upper()
if (mode == 1):
if (self.mode == 1):
execute = "select msgData,senderuin,time from mr_friend_{md5num}_New".format(
md5num=md5num)
elif (mode == 2):
elif (self.mode == 2):
execute = "select msgData,senderuin,time from mr_troop_{md5num}_New".format(
md5num=md5num)
else:
print("error mode")
exit(1)
#try:

cursor = self.c.execute(execute)
#except:
# raise ValueError("QQ号/db地址错误")
if (self.key == "" and len(self.s) >= 5):
self.key = self.decode(cursor)
cursor = self.c.execute(execute)
Expand All @@ -118,21 +116,20 @@ def message(self, num, mode):
allmsg.append(amsg)
return allmsg

def output(self, num, mode, n1, n2):
first = str(num)[0]
def output(self, num, n1, n2):
name1 = n1 if n1 != "" else "我"
name2 = n2 if n2 != "" else str(num)
file = str(num) + ".html"
f2 = open(file, "w", encoding="utf-8")
f2.write(
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head>"
)
allmsg = self.message(num, mode)
allmsg = self.message(num)
f2.write("<div style='white-space: pre-line'>")
for msg in allmsg:
try:
if mode == 1:
if (msg[1][0] == first):
if self.mode == 1:
if (msg[1] == str(num)):
f2.write("<p align='left'>")
f2.write("<font color=\"blue\"><b>")
f2.write(name2)
Expand Down Expand Up @@ -165,7 +162,7 @@ def output(self, num, mode, n1, n2):
def main(db, qq, key, msg, n1, n2, mode):
try:
q = QQoutput(db, key, mode, msg)
return q.output(qq, mode, n1, n2)
return q.output(qq, n1, n2)
except Exception as e:
with open('log.txt', 'w') as f:
f.write(str(e))
Expand All @@ -176,14 +173,3 @@ def main(db, qq, key, msg, n1, n2, mode):
print(repr(e))
if (err_info):
raise ValueError("QQ号/私聊群聊选择/db地址/错误")



'''
TODO:
1. use com.tencent.mobileqq/f/kc as key
2. decode friend/troop name, to use in result
3. add desensitization data to create e2e test
4. add Makefile, to run build/test
5. use pic in mobile folder, to better present result
'''

0 comments on commit 1682151

Please sign in to comment.