This commit is contained in:
JJTech0130 2023-07-29 13:57:20 -04:00
parent 3c72c3d56e
commit c90448f658
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
3 changed files with 368 additions and 115 deletions

83
demo.py
View file

@ -108,44 +108,61 @@ with open("config.json", "w") as f:
im = imessage.iMessageUser(conn, user) im = imessage.iMessageUser(conn, user)
# Create a thread to take user input # while True:
INPUT_QUEUE = apns.IncomingQueue() # i = im.receive()
# if i is not None:
# print(f"Got message {i}")
imsg = imessage.iMessage()
imsg.sender = user.handles[0]
imsg.participants = ["mailto:jjtech@jjtech.dev"]
imsg.text = "Hello world!"
def input_thread(): time.sleep(1)
while True: im.send(imsg)
from prompt_toolkit import prompt
try: for i in range(10):
msg = prompt('>> ') z = im.receive()
except: if z is not None:
msg = 'quit' print(f"Got message {z}")
INPUT_QUEUE.append(msg) time.sleep(1)
# # Create a thread to take user input
# INPUT_QUEUE = apns.IncomingQueue()
threading.Thread(target=input_thread, daemon=True).start() # def input_thread():
# while True:
# from prompt_toolkit import prompt
# try:
# msg = prompt('>> ')
# except:
# msg = 'quit'
# INPUT_QUEUE.append(msg)
# threading.Thread(target=input_thread, daemon=True).start()
while True: # while True:
msg = im.receive() # msg = im.receive()
if msg is not None: # if msg is not None:
print(f"Got message {msg}") # print(f"Got message {msg}")
if len(INPUT_QUEUE) > 0: # if len(INPUT_QUEUE) > 0:
msg = INPUT_QUEUE.pop() # msg = INPUT_QUEUE.pop()
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) [recipiant] [message]: send a message') # print('send (s) [recipiant] [message]: send a message')
elif msg == 'quit' or msg == 'q': # elif msg == 'quit' or msg == 'q':
break # break
elif msg.startswith('send') or msg.startswith('s'): # elif msg.startswith('send') or msg.startswith('s'):
msg = msg.split(' ') # msg = msg.split(' ')
if len(msg) < 3: # if len(msg) < 3:
print('send [recipiant] [message]') # print('send [recipiant] [message]')
else: # else:
imsg = imessage.iMessage() # imsg = imessage.iMessage()
imsg.text = ' '.join(msg[2:]) # imsg.text = ' '.join(msg[2:])
imsg.participants = [msg[1], user.handles[0]] # imsg.participants = [msg[1], user.handles[0]]
imsg.sender = user.handles[0] # imsg.sender = user.handles[0]
im.send(imsg) # im.send(imsg)

View file

@ -219,7 +219,9 @@ def pretty_print_payload(
if topic == "com.apple.madrid": if topic == "com.apple.madrid":
print(f" {bcolors.FAIL}Madrid{bcolors.ENDC}", end="") print(f" {bcolors.FAIL}Madrid{bcolors.ENDC}", end="")
orig_payload = payload
payload = plistlib.loads(_get_field(payload[1], 3)) payload = plistlib.loads(_get_field(payload[1], 3))
# print(payload) # print(payload)
if "cT" in payload and False: if "cT" in payload and False:
# It's HTTP over APNs # It's HTTP over APNs
@ -248,9 +250,29 @@ def pretty_print_payload(
if b"plist" in body: if b"plist" in body:
body = plistlib.loads(body) body = plistlib.loads(body)
print(f" {bcolors.FAIL}Body{bcolors.ENDC}: {body}", end="") print(f" {bcolors.FAIL}Body{bcolors.ENDC}: {body}", end="")
if not "cT" in payload: #if not "cT" in payload:
for key in payload: for key in payload:
print(f" {bcolors.OKBLUE}{key}{bcolors.ENDC}: {payload[key]}") print(f" {bcolors.OKBLUE}{key}{bcolors.ENDC}: {payload[key]}")
if 'dtl' in payload:
print("OVERRIDE DTL")
payload['dtl'][0].update({'sT': b64decode("jJ86jTYbv1mGVwO44PyfuZ9lh3o56QjOE39Jk8Z99N8=")})
# Re-serialize the payload
payload = plistlib.dumps(payload, fmt=plistlib.FMT_BINARY)
# Construct APNS message
# Get the original fields except 3
fields = orig_payload[1]
fields = [field for field in fields if field[0] != 3]
# Add the new field
fields.append((3, payload))
payload = apns._serialize_payload(0xA, fields)
# Use the override payload
#print(payload, orig_payload)
#print(payload == orig_payload)
return payload
print() print()

File diff suppressed because one or more lines are too long