diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4978b11..e734d87 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,15 +4,12 @@ - @@ -674,7 +683,8 @@ - @@ -693,9 +703,24 @@ file://$PROJECT_DIR$/app/decrypt/decrypt.py - 103 + 107 + + file://$PROJECT_DIR$/app/person.py + 100 + + + file://$PROJECT_DIR$/app/person.py + 98 + + + file://$PROJECT_DIR$/app/person.py + 99 + diff --git a/app/components/bubble_message.py b/app/components/bubble_message.py index fc26e4b..f0bbe55 100644 --- a/app/components/bubble_message.py +++ b/app/components/bubble_message.py @@ -104,25 +104,35 @@ class OpenImageThread(QThread): class ImageMessage(QLabel): - def __init__(self, image, image_link='', max_width=480, max_height=720, parent=None): + def __init__(self, image, image_link='', max_width=480, max_height=240, parent=None): """ param:image 图像路径或者QPixmap对象 param:image_link='' 点击图像打开的文件路径 """ super().__init__(parent) self.image = QLabel(self) - + self.max_width = max_width + self.max_height = max_height if isinstance(image, str): - self.setPixmap(QPixmap(image)) + pixmap = QPixmap(image) self.image_path = image elif isinstance(image, QPixmap): - self.setPixmap(image) + pixmap = image + self.set_image(pixmap) if image_link: self.image_path = image_link - self.setMaximumWidth(max_width) - self.setMaximumHeight(max_height) + self.setMaximumWidth(self.max_width) + self.setMaximumHeight(self.max_height) # self.setScaledContents(True) + def set_image(self, pixmap): + # 计算调整后的大小 + adjusted_width = min(pixmap.width(), self.max_width) + adjusted_height = min(pixmap.height(), self.max_height) + self.setPixmap(pixmap.scaled(adjusted_width, adjusted_height, Qt.KeepAspectRatio)) + # 调整QLabel的大小以适应图片的宽高,但不超过最大宽高 + self.setFixedSize(adjusted_width, adjusted_height) + def mousePressEvent(self, event): if event.buttons() == Qt.LeftButton: # 左键按下 print('打开图像', self.image_path) diff --git a/app/decrypt/dat2pic.py b/app/decrypt/dat2pic.py index f66abd6..04e2be9 100644 --- a/app/decrypt/dat2pic.py +++ b/app/decrypt/dat2pic.py @@ -1,5 +1,5 @@ - import os + # 图片字节头信息, # [0][1]为jpg头信息, # [2][3]为png头信息, @@ -21,7 +21,7 @@ def get_code(file_path): return -1, -1 dat_file = open(file_path, "rb") dat_read = dat_file.read(2) - print(dat_read) + # print(dat_read) head_index = 0 while head_index < len(pic_head): # 使用第一个头信息字节来计算加密码 @@ -33,7 +33,7 @@ def get_code(file_path): dat_file.close() return head_index, code head_index = head_index + 1 - + dat_file.close() print("not jpg, png, gif") return -1, -1 @@ -49,26 +49,22 @@ def decode_dat(file_path, out_path): if decode_code == -1: return if file_type == 1: - pic_name = file_path.split("\\")[-1][:-4] + ".jpg" + pic_name = os.path.basename(file_path)[:-4] + ".jpg" elif file_type == 3: pic_name = file_path[:-4] + ".png" elif file_type == 5: pic_name = file_path[:-4] + ".gif" else: pic_name = file_path[:-4] + ".jpg" - - dat_file = open(file_path, "rb") file_outpath = os.path.join(out_path, pic_name) - print(pic_name) - print(file_outpath) - pic_write = open(file_outpath, "wb") - for dat_data in dat_file: - for dat_byte in dat_data: - pic_data = dat_byte ^ decode_code - pic_write.write(bytes([pic_data])) - print(pic_name + "完成") - dat_file.close() - pic_write.close() + with open(file_path, 'rb') as file_in: + data = file_in.read() + # 对数据进行异或加密/解密 + encrypted_data = bytes([byte ^ decode_code for byte in data]) + with open(file_outpath, 'wb') as file_out: + file_out.write(encrypted_data) + print(file_path, '->', file_outpath) + return file_outpath def find_datfile(dir_path, out_path): @@ -88,4 +84,4 @@ if __name__ == "__main__": outpath = "D:\\test" if not os.path.exists(outpath): os.mkdir(outpath) - find_datfile(path, outpath) \ No newline at end of file + find_datfile(path, outpath) diff --git a/app/ui_pc/tool/pc_decrypt/pc_decrypt.py b/app/ui_pc/tool/pc_decrypt/pc_decrypt.py index 99cbb33..1af9bd0 100644 --- a/app/ui_pc/tool/pc_decrypt/pc_decrypt.py +++ b/app/ui_pc/tool/pc_decrypt/pc_decrypt.py @@ -72,7 +72,7 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog): def select_db_dir(self): directory = QtWidgets.QFileDialog.getExistingDirectory( - self, "选取微信安装目录——能看到All Users文件夹", + self, "选取微信安装目录——能看到Msg文件夹", "C:/") # 起始路径 db_dir = os.path.join(directory, 'Msg') if not os.path.exists(db_dir): diff --git a/app/util/path.py b/app/util/path.py index ab32b28..3fe80c5 100644 --- a/app/util/path.py +++ b/app/util/path.py @@ -1,11 +1,17 @@ import os +from app.decrypt import dat2pic from app.person import MePC +if not os.path.exists('./data/image'): + os.mkdir('./data/image') + def get_abs_path(path): - return os.path.join(os.getcwd(), 'app/data/icons/404.png') + # return os.path.join(os.getcwd(), 'app/data/icons/404.png') if path: - return os.path.join(MePC().wx_dir, path) + # if os.path.exists(os.path.join()) + output_path = dat2pic.decode_dat(os.path.join(MePC().wx_dir, path), './data/image') + return output_path else: return os.path.join(os.getcwd(), 'app/data/icons/404.png')