implement more SMS handling stuff

This commit is contained in:
JJTech0130 2023-08-14 20:31:03 -04:00
parent 10a5771791
commit 21fdfc97a9
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6

View file

@ -140,6 +140,7 @@ class Message:
id: uuid.UUID id: uuid.UUID
_raw: dict _raw: dict
_compressed: bool = True _compressed: bool = True
xml: str | None = None
def from_raw(message: bytes, sender: str | None = None) -> "Message": def from_raw(message: bytes, sender: str | None = None) -> "Message":
"""Create a `Message` from raw message bytes""" """Create a `Message` from raw message bytes"""
@ -163,6 +164,8 @@ class SMSReflectedMessage(Message):
message = plistlib.loads(message) message = plistlib.loads(message)
logger.debug(f"Decoding SMSReflectedMessage: {message}")
return SMSReflectedMessage( return SMSReflectedMessage(
text=message["mD"]["plain-body"], text=message["mD"]["plain-body"],
sender=sender, sender=sender,
@ -189,7 +192,7 @@ class SMSIncomingMessage(Message):
message = plistlib.loads(message) message = plistlib.loads(message)
logger.debug(f"Decompressed message : {message}") logger.debug(f"Decoding SMSIncomingMessage: {message}")
return SMSIncomingMessage( return SMSIncomingMessage(
text=message["k"][0]["data"].decode(), text=message["k"][0]["data"].decode(),
@ -202,6 +205,14 @@ class SMSIncomingMessage(Message):
def __str__(self): def __str__(self):
return f"[SMS {self.sender}] '{self.text}'" return f"[SMS {self.sender}] '{self.text}'"
@dataclass
class SMSIncomingImage(Message):
def from_raw(message: bytes, sender: str | None = None) -> "SMSIncomingImage":
"""Create a `SMSIncomingImage` from raw message bytes"""
# TODO: Implement this
return "SMSIncomingImage"
@dataclass @dataclass
class iMessage(Message): class iMessage(Message):
@ -219,11 +230,14 @@ class iMessage(Message):
message = plistlib.loads(message) message = plistlib.loads(message)
logger.debug(f"Decoding iMessage: {message}")
return iMessage( return iMessage(
text=message["t"], text=message["t"],
participants=message["p"], participants=message["p"],
sender=sender, sender=sender,
id=uuid.UUID(message["r"]), id=uuid.UUID(message["r"]),
xml=message["x"] if "x" in message else None,
_raw=message, _raw=message,
_compressed=compressed, _compressed=compressed,
effect=message["iid"] if "iid" in message else None, effect=message["iid"] if "iid" in message else None,
@ -533,10 +547,18 @@ class iMessageUser:
# Check for SMS messages # Check for SMS messages
body = self._receive_raw(143, "com.apple.private.alloy.sms") body = self._receive_raw(143, "com.apple.private.alloy.sms")
t = SMSReflectedMessage t = SMSReflectedMessage
if body is None:
# Check for SMS reflected images
body = self._receive_raw(144, "com.apple.private.alloy.sms")
t = SMSReflectedMessage
if body is None: if body is None:
# Check for SMS incoming messages # Check for SMS incoming messages
body = self._receive_raw(140, "com.apple.private.alloy.sms") body = self._receive_raw(140, "com.apple.private.alloy.sms")
t = SMSIncomingMessage t = SMSIncomingMessage
if body is None:
# Incoming images
body = self._receive_raw(141, "com.apple.private.alloy.sms")
t = SMSIncomingImage
if body is None: if body is None:
return None return None
@ -677,7 +699,7 @@ class iMessageUser:
return False return False
resp_body = plistlib.loads(resp_body) resp_body = plistlib.loads(resp_body)
#logger.debug(f"See type {resp_body['c']}") #logger.info(f"See type {resp_body['c']}")
if isinstance(c, list): if isinstance(c, list):
if not resp_body["c"] in c: if not resp_body["c"] in c: