Skip to content

Commit

Permalink
Better handling of binary message #44
Browse files Browse the repository at this point in the history
  • Loading branch information
KnugiHK committed Jun 15, 2023
1 parent bfdc68c commit be9e790
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions Whatsapp_Chat_Exporter/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, from_me: Union[bool,int], timestamp: int, time: Union[int,flo
self.meta = False
self.data = None
self.sender = None
self.safe = False
# Extra
self.reply = None
self.quoted_data = None
Expand Down
17 changes: 12 additions & 5 deletions Whatsapp_Chat_Exporter/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 8 additions & 0 deletions Whatsapp_Chat_Exporter/whatsapp.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down

0 comments on commit be9e790

Please sign in to comment.