Upload files to ''

This commit is contained in:
nodemixaholic 2024-01-30 17:31:28 +00:00
parent 902965a410
commit 6598540ff9
5 changed files with 98 additions and 74 deletions

File diff suppressed because one or more lines are too long

View file

@ -320,4 +320,4 @@ def _get_field(fields: list[tuple[int, bytes]], id: int) -> bytes:
for field_id, value in fields: for field_id, value in fields:
if field_id == id: if field_id == id:
return value return value
return None return None

41
demo.py
View file

@ -178,12 +178,22 @@ while True:
if msg == 'help' or msg == 'h': if msg == 'help' or msg == 'h':
print('help (h): show this message') print('help (h): show this message')
print('quit (q): quit') print('quit (q): quit')
#print('send (s) [recipient] [message]: send a message') print('send (s) [recipient] [message]: send a message')
print('filter (f) [recipient]: set the current chat') #print('filter (f) [recipient]: set the current chat')
print('effect (e): adds an iMessage effect to the next sent message') print('effect (e): adds an iMessage effect to the next sent message')
print('note: recipient must start with tel: or mailto: and include the country code') print('note: recipient must start with tel: or mailto: and include the country code')
print('handle <handle>: set the current handle (for sending messages)') print('handle <handle>: set the current handle (for sending messages)')
print('\\: escape commands (will be removed from message)') print('\\: escape commands (will be removed from message)')
elif msg.startswith('send') or msg.startswith('s'):
msg = msg.split(' ')
if len(msg) < 3:
print('send [recipient] [message]')
else:
im.send(imessage.iMessage(
text=' '.join(msg[2:]),
participants=[msg[1], user.handles[0]],
#sender=user.handles[0]
))
elif msg == 'quit' or msg == 'q': elif msg == 'quit' or msg == 'q':
break break
elif msg == 'effect' or msg == 'e' or msg.startswith("effect ") or msg.startswith("e "): elif msg == 'effect' or msg == 'e' or msg.startswith("effect ") or msg.startswith("e "):
@ -193,14 +203,14 @@ while True:
else: else:
print(f"next message will be sent with [{msg[1]}]") print(f"next message will be sent with [{msg[1]}]")
current_effect = msg[1] current_effect = msg[1]
elif msg == 'filter' or msg == 'f' or msg.startswith('filter ') or msg.startswith('f '): #elif msg == 'filter' or msg == 'f' or msg.startswith('filter ') or msg.startswith('f '):
# Set the curernt chat # Set the curernt chat
msg = msg.split(' ') #msg = msg.split(' ')
if len(msg) < 2 or msg[1] == '': #if len(msg) < 2 or msg[1] == '':
print('filter [recipients]') #print('filter [recipients]')
else: #else:
print(f'Filtering to {[fixup_handle(h) for h in msg[1:]]}') #print(f'Filtering to {[fixup_handle(h) for h in msg[1:]]}')
current_participants = [fixup_handle(h) for h in msg[1:]] #current_participants = [fixup_handle(h) for h in msg[1:]]
elif msg == 'handle' or msg.startswith('handle '): elif msg == 'handle' or msg.startswith('handle '):
msg = msg.split(' ') msg = msg.split(' ')
if len(msg) < 2 or msg[1] == '': if len(msg) < 2 or msg[1] == '':
@ -234,15 +244,4 @@ while True:
print('No chat selected, use help for help') print('No chat selected, use help for help')
time.sleep(0.1) time.sleep(0.1)
# elif msg.startswith('send') or msg.startswith('s'):
# msg = msg.split(' ')
# if len(msg) < 3:
# print('send [recipient] [message]')
# else:
# im.send(imessage.iMessage(
# text=' '.join(msg[2:]),
# participants=[msg[1], user.handles[0]],
# #sender=user.handles[0]
# ))

View file

@ -28,6 +28,7 @@ logger = logging.getLogger("imessage")
NORMAL_NONCE = b"\x00" * 15 + b"\x01" # This is always used as the AES nonce NORMAL_NONCE = b"\x00" * 15 + b"\x01" # This is always used as the AES nonce
bundled_payloads = []
class BalloonBody: class BalloonBody:
"""Represents the special parts of message extensions etc.""" """Represents the special parts of message extensions etc."""
@ -257,20 +258,34 @@ class iMessageUser:
Returns None if no conforming notification is found Returns None if no conforming notification is found
""" """
def check_response(x): #def check_response(x):
if x[0] != 0x0A: #if x[0] != 0x0A:
return False #return False
if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest(): #if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
return False #return False
resp_body = apns._get_field(x[1], 3) #resp_body = apns._get_field(x[1], 3)
if resp_body is None: #if resp_body is None:
# logger.debug("Rejecting madrid message with no body") # logger.debug("Rejecting madrid message with no body")
return False #return False
resp_body = plistlib.loads(resp_body) #resp_body = plistlib.loads(resp_body)
if "P" not in resp_body: #if "P" not in resp_body:
# logger.debug(f"Rejecting madrid message with no payload : {resp_body}") # logger.debug(f"Rejecting madrid message with no payload : {resp_body}")
return False #return False
return True #return True
def check_response(x):
if x[0] != 0x0A:
return False
if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
return False
resp_body = apns._get_field(x[1], 3)
if resp_body is None:
return False
resp_body = plistlib.loads(resp_body)
if "c" not in resp_body or resp_body["c"] != 255:
return False
return True
payload = self.connection.incoming_queue.pop_find(check_response) payload = self.connection.incoming_queue.pop_find(check_response)
if payload is None: if payload is None:
@ -494,7 +509,6 @@ class iMessageUser:
raw = message.to_raw() raw = message.to_raw()
import base64 import base64
bundled_payloads = []
for participant in message.participants: for participant in message.participants:
participant = participant.lower() participant = participant.lower()
for push_token in self.USER_CACHE[participant]: for push_token in self.USER_CACHE[participant]:
@ -530,6 +544,7 @@ class iMessageUser:
"sP": message.sender, "sP": message.sender,
} }
body = plistlib.dumps(body, fmt=plistlib.FMT_BINARY) body = plistlib.dumps(body, fmt=plistlib.FMT_BINARY)
self.connection.send_message("com.apple.madrid", body, msg_id) self.connection.send_message("com.apple.madrid", body, msg_id)
@ -537,29 +552,29 @@ class iMessageUser:
# This code can check to make sure we got a success response, but waiting for the response is annoying, # This code can check to make sure we got a success response, but waiting for the response is annoying,
# so for now we just YOLO it and assume it worked # so for now we just YOLO it and assume it worked
# def check_response(x): #def check_response(x):
# if x[0] != 0x0A: #if x[0] != 0x0A:
# return False #return False
# if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest(): #if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
# return False #return False
# resp_body = apns._get_field(x[1], 3) #resp_body = apns._get_field(x[1], 3)
# if resp_body is None: #if resp_body is None:
# return False #return False
# resp_body = plistlib.loads(resp_body) #resp_body = plistlib.loads(resp_body)
# if "c" not in resp_body or resp_body["c"] != 255: #if "c" not in resp_body or resp_body["c"] != 255:
# return False #return False
# return True #return True
# num_recv = 0 num_recv = 0
# while True:
# if num_recv == len(bundled_payloads): while True:
# break if num_recv == len(bundled_payloads):
# payload = self.connection.incoming_queue.wait_pop_find(check_response) break
# if payload is None: payload = self.connection.incoming_queue.wait_pop_find(check_response)
# continue if payload is None:
continue
# resp_body = apns._get_field(payload[1], 3) resp_body = apns._get_field(payload[1], 3)
# resp_body = plistlib.loads(resp_body) resp_body = plistlib.loads(resp_body)
# logger.error(resp_body) logger.error(resp_body)
# num_recv += 1 num_recv += 1

View file

@ -6,4 +6,5 @@ srp
pbkdf2 pbkdf2
unicorn unicorn
rich rich
prompt_toolkit prompt_toolkit
trio