mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Fix alpc sample py3 (#45)
* ReAdded AF_ flags removed by mistake from ctypes_generation * Adapt ALPC samples to python3 (fix #44) --------- Co-authored-by: clement rouault <clement.rouault@exatrack.com>
This commit is contained in:
@@ -90,5 +90,11 @@
|
||||
#define AF_FIREFOX 19 /* FireFox */
|
||||
#define AF_UNKNOWN1 20 /* Somebody is using this! */
|
||||
#define AF_BAN 21 /* Banyan */
|
||||
#define AF_ATM 22
|
||||
#define AF_INET6 23
|
||||
#define AF_CLUSTER 24
|
||||
#define AF_12844 25
|
||||
#define AF_IRDA 26
|
||||
#define AF_NETDES 28
|
||||
|
||||
#define AF_MAX 22
|
||||
@@ -3120,4 +3120,10 @@ WinDef
|
||||
.. autodata:: AF_FIREFOX
|
||||
.. autodata:: AF_UNKNOWN1
|
||||
.. autodata:: AF_BAN
|
||||
.. autodata:: AF_ATM
|
||||
.. autodata:: AF_INET6
|
||||
.. autodata:: AF_CLUSTER
|
||||
.. autodata:: AF_12844
|
||||
.. autodata:: AF_IRDA
|
||||
.. autodata:: AF_NETDES
|
||||
.. autodata:: AF_MAX
|
||||
|
||||
@@ -19,8 +19,8 @@ def full_alpc_server():
|
||||
msg = server.recv()
|
||||
print("[SERV] == Message received ==")
|
||||
if msg.type & 0xfff == LPC_CONNECTION_REQUEST:
|
||||
print(" * ALPC connection request: <{0}>".format(msg.data))
|
||||
msg.data = "Connection message response"
|
||||
print(" * ALPC connection request: <{0}>".format(msg.data.decode()))
|
||||
msg.data = b"Connection message response"
|
||||
server.accept_connection(msg, port_context=PORT_CONTEXT)
|
||||
else:
|
||||
raise ValueError("Expected connection")
|
||||
@@ -33,7 +33,7 @@ def full_alpc_server():
|
||||
# print("[SERV] RECV Message Valid ATTRS = {0:#x}".format(msg.attributes.ValidAttributes))
|
||||
# print("[SERV] RECV Message ATTRS = {0:#x}".format(msg.attributes.AllocatedAttributes))
|
||||
if msg.type & 0xfff == LPC_REQUEST:
|
||||
print(" * ALPC request: <{0}>".format(msg.data))
|
||||
print(" * ALPC request: <{0}>".format(msg.data.decode()))
|
||||
print(" * view_is_valid <{0}>".format(msg.view_is_valid))
|
||||
if msg.view_is_valid:
|
||||
print(" * message view attribute:")
|
||||
@@ -69,20 +69,20 @@ def full_alpc_server():
|
||||
# We can reply by to way:
|
||||
# - Send the same message with modified data
|
||||
# - Recreate a Message and copy the MessageId
|
||||
msg.data = "REQUEST '{0}' DONE".format(msg.data)
|
||||
msg.data = "REQUEST '{0}' DONE".format(msg.data.decode()).encode()
|
||||
sys.stdout.flush()
|
||||
server.send(msg)
|
||||
else:
|
||||
print ValueError("Unexpected message type <{0}>".format(msg.type & 0xfff))
|
||||
print(ValueError("Unexpected message type <{0}>".format(msg.type & 0xfff)))
|
||||
|
||||
|
||||
def send_message_with_handle(client):
|
||||
print ""
|
||||
print("")
|
||||
print("[Client] == Sending a message with a handle ==")
|
||||
|
||||
# Craft a file with some data
|
||||
f = tempfile.NamedTemporaryFile()
|
||||
f.write("Tempfile data <3")
|
||||
f.write(b"Tempfile data <3")
|
||||
f.seek(0)
|
||||
|
||||
# New message with a Handle
|
||||
@@ -92,11 +92,11 @@ def send_message_with_handle(client):
|
||||
msg.handle_attribute.Handle = windows.utils.get_handle_from_file(f)
|
||||
msg.handle_attribute.ObjectType = 0
|
||||
msg.handle_attribute.DesiredAccess = 0
|
||||
msg.data = "some message with a file"
|
||||
msg.data = b"some message with a file"
|
||||
client.send_receive(msg)
|
||||
|
||||
def send_message_with_view(client):
|
||||
print ""
|
||||
print("")
|
||||
print("[Client] == Sending a message with a view ==")
|
||||
|
||||
# Create View
|
||||
@@ -110,8 +110,8 @@ def send_message_with_view(client):
|
||||
msg.view_attribute.ViewBase = view.ViewBase
|
||||
msg.view_attribute.SectionHandle = view.SectionHandle
|
||||
msg.view_attribute.ViewSize = 0x4000
|
||||
msg.data = "some message with a view"
|
||||
windows.current_process.write_memory(view.ViewBase, "The content of the view :)\x00")
|
||||
msg.data = b"some message with a view"
|
||||
windows.current_process.write_memory(view.ViewBase, b"The content of the view :)\x00")
|
||||
client.send_receive(msg)
|
||||
|
||||
def alpc_client():
|
||||
@@ -121,20 +121,20 @@ def alpc_client():
|
||||
# You can create a non-connected AlpcClient and send a custom
|
||||
# 'AlpcMessage' for complexe alpc port connection.
|
||||
connect_message = windows.alpc.AlpcMessage()
|
||||
connect_message.data = "Connection request client message"
|
||||
connect_message.data = b"Connection request client message"
|
||||
print("[CLIENT] == Connecting to port ==")
|
||||
connect_response = client.connect_to_port(PORT_NAME, connect_message)
|
||||
print("[CLIENT] Connected with response: <{0}>".format(connect_response.data))
|
||||
print("[CLIENT] Connected with response: <{0}>".format(connect_response.data.decode()))
|
||||
|
||||
# AlpcClient send/recv/send_receive methods accept both string or
|
||||
# AlpcMessage for complexe message.
|
||||
print""
|
||||
print("")
|
||||
print("[CLIENT] == Sending a message ==")
|
||||
msg = windows.alpc.AlpcMessage()
|
||||
msg.data = "Complex Message 1"
|
||||
print(" * Sending Message <{0}>".format(msg.data))
|
||||
msg.data = b"Complex Message 1"
|
||||
print(" * Sending Message <{0}>".format(msg.data.decode()))
|
||||
response = client.send_receive(msg)
|
||||
print("[CLIENT] Server response: <{0}>".format(response.data))
|
||||
print("[CLIENT] Server response: <{0}>".format(response.data.decode()))
|
||||
print("[CLIENT] RESP Message Valid ATTRS = {0}".format(response.valid_attributes))
|
||||
|
||||
send_message_with_handle(client)
|
||||
|
||||
@@ -12,20 +12,20 @@ def alpc_server():
|
||||
|
||||
msg = server.recv() # Wait for a message
|
||||
print("[SERV] Message type = {0:#x}".format(msg.type))
|
||||
print("[SERV] Received data: <{0}>".format(msg.data))
|
||||
print("[SERV] Received data: <{0}>".format(msg.data.decode()))
|
||||
assert msg.type & 0xfff == LPC_CONNECTION_REQUEST # Check that message is a connection request
|
||||
print("[SERV] Connection request")
|
||||
server.accept_connection(msg)
|
||||
|
||||
msg = server.recv() # Wait for a real message
|
||||
print ""
|
||||
print("[SERV] Received message: <{0}>".format(msg.data))
|
||||
print("")
|
||||
print("[SERV] Received message: <{0}>".format(msg.data.decode()))
|
||||
print("[SERV] Message type = {0:#x}".format(msg.type))
|
||||
assert msg.type & 0xfff == LPC_REQUEST
|
||||
# We can reply by two ways:
|
||||
# - Send the same message with modified data
|
||||
# - Recreate a Message and copy the MessageId
|
||||
msg.data = "REQUEST '{0}' DONE".format(msg.data)
|
||||
msg.data = u"REQUEST '{0}' DONE".format(msg.data.decode()).encode()
|
||||
server.send(msg)
|
||||
|
||||
|
||||
@@ -36,15 +36,15 @@ def alpc_client():
|
||||
client = windows.alpc.AlpcClient(PORT_NAME)
|
||||
print("[CLIENT] Connected: {0}".format(client))
|
||||
# Send a message / wait for the response
|
||||
response = client.send_receive("Hello world !")
|
||||
print("[CLIENT] Response: <{0}>".format(response.data))
|
||||
response = client.send_receive(b"Hello world !")
|
||||
print("[CLIENT] Response: <{0}>".format(response.data.decode()))
|
||||
# You can also send message without waiting for a response with 'client.send'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
proc = multiprocessing.Process(target=alpc_server, args=())
|
||||
proc.start()
|
||||
import time; time.sleep(0.5)
|
||||
import time; time.sleep(1)
|
||||
alpc_client()
|
||||
print("BYE")
|
||||
proc.terminate()
|
||||
@@ -38,10 +38,13 @@ windef = set(['ABOVE_NORMAL_PRIORITY_CLASS',
|
||||
'ADS_RIGHT_SYNCHRONIZE',
|
||||
'ADS_RIGHT_WRITE_DAC',
|
||||
'ADS_RIGHT_WRITE_OWNER',
|
||||
'AF_12844',
|
||||
'AF_APPLETALK',
|
||||
'AF_ATM',
|
||||
'AF_BAN',
|
||||
'AF_CCITT',
|
||||
'AF_CHAOS',
|
||||
'AF_CLUSTER',
|
||||
'AF_DATAKIT',
|
||||
'AF_DECnet',
|
||||
'AF_DLI',
|
||||
@@ -50,11 +53,14 @@ windef = set(['ABOVE_NORMAL_PRIORITY_CLASS',
|
||||
'AF_HYLINK',
|
||||
'AF_IMPLINK',
|
||||
'AF_INET',
|
||||
'AF_INET6',
|
||||
'AF_IPX',
|
||||
'AF_IRDA',
|
||||
'AF_ISO',
|
||||
'AF_LAT',
|
||||
'AF_MAX',
|
||||
'AF_NETBIOS',
|
||||
'AF_NETDES',
|
||||
'AF_NS',
|
||||
'AF_OSI',
|
||||
'AF_PUP',
|
||||
|
||||
@@ -3125,4 +3125,10 @@ AF_VOICEVIEW = make_flag("AF_VOICEVIEW", 18)
|
||||
AF_FIREFOX = make_flag("AF_FIREFOX", 19)
|
||||
AF_UNKNOWN1 = make_flag("AF_UNKNOWN1", 20)
|
||||
AF_BAN = make_flag("AF_BAN", 21)
|
||||
AF_ATM = make_flag("AF_ATM", 22)
|
||||
AF_INET6 = make_flag("AF_INET6", 23)
|
||||
AF_CLUSTER = make_flag("AF_CLUSTER", 24)
|
||||
AF_12844 = make_flag("AF_12844", 25)
|
||||
AF_IRDA = make_flag("AF_IRDA", 26)
|
||||
AF_NETDES = make_flag("AF_NETDES", 28)
|
||||
AF_MAX = make_flag("AF_MAX", 22)
|
||||
|
||||
Reference in New Issue
Block a user