Better handling of binary message #44

This commit is contained in:
KnugiHK
2023-06-16 01:25:51 +08:00
parent bfdc68cd6a
commit be9e790b12
3 changed files with 21 additions and 5 deletions

View File

@@ -57,6 +57,7 @@ class Message():
self.meta = False
self.data = None
self.sender = None
self.safe = False
# Extra
self.reply = None
self.quoted_data = None

View File

@@ -11,7 +11,7 @@ import hmac
from pathlib import Path
from mimetypes import MimeTypes
from hashlib import sha256
from base64 import b64decode
from base64 import b64decode, b64encode
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
from Whatsapp_Chat_Exporter.utility import MAX_SIZE, ROW_SIZE, Device, rendering, sanitize_except, determine_day, Crypt
from Whatsapp_Chat_Exporter.utility import brute_force_offset, CRYPT14_OFFSETS
@@ -252,8 +252,6 @@ def messages(db, data, media_folder):
except sqlite3.OperationalError:
continue
else:
if content is not None and isinstance(content["data"], bytes):
continue
break
while content is not None:
if content["key_remote_jid"] not in data:
@@ -266,6 +264,17 @@ def messages(db, data, media_folder):
time=content["timestamp"],
key_id=content["key_id"],
)
if isinstance(content["data"], bytes):
message.data = ("The message is binary data and its base64 is "
'<a href="https://gchq.github.io/CyberChef/#recipe=From_Base64'
"('A-Za-z0-9%2B/%3D',true,false)Text_Encoding_Brute_Force"
f"""('Decode')&input={b64encode(b64encode(content["data"])).decode()}">""")
message.data += b64encode(content["data"]).decode("utf-8") + "</a>"
message.safe = message.meta = True
data[content["key_remote_jid"]].add_message(content["_id"], message)
i += 1
content = c.fetchone()
continue
invalid = False
if "-" in content["key_remote_jid"] and content["key_from_me"] == 0:
name = None
@@ -407,8 +416,6 @@ def messages(db, data, media_folder):
except sqlite3.OperationalError:
continue
else:
if content is not None and isinstance(content["data"], bytes):
continue
break
print(f"Processing messages...({total_row_number}/{total_row_number})", end="\r")

View File

@@ -125,7 +125,11 @@
{% endif %}
{% if msg.meta == true or msg.media == false and msg.data is none %}
<div class="w3-panel w3-border-blue w3-pale-blue w3-rightbar w3-leftbar w3-threequarter w3-center">
{% if msg.safe %}
<p>{{ msg.data | safe or 'Not supported WhatsApp internal message' }}</p>
{% else %}
<p>{{ msg.data or 'Not supported WhatsApp internal message' }}</p>
{% endif %}
</div>
{% else %}
{% if msg.media == false %}
@@ -205,7 +209,11 @@
{% endif %}
{% if msg.meta == true or msg.media == false and msg.data is none %}
<div class="w3-panel w3-border-blue w3-pale-blue w3-rightbar w3-leftbar w3-threequarter w3-center">
{% if msg.safe %}
<p>{{ msg.data | safe or 'Not supported WhatsApp internal message' }}</p>
{% else %}
<p>{{ msg.data or 'Not supported WhatsApp internal message' }}</p>
{% endif %}
</div>
{% else %}
{% if msg.media == false %}