working on windows.alpc + fix in current_process.threads

This commit is contained in:
Clement Rouault
2017-08-04 17:18:41 +02:00
parent aa22f1515d
commit d1cadf062a
5 changed files with 18 additions and 8 deletions
+10 -7
View File
@@ -8,20 +8,23 @@ PORT_NAME = r"\RPC Control\YOLOPORT"
def alpc_server():
server = windows.alpc.AlpcServer(PORT_NAME) # NtAlpcCreatePort
print("[SERV] PORT CREATED")
attrs, msg = server.wait_data() # NtAlpcSendWaitReceivePort (send_msg = None)
msg = server.recv() # NtAlpcSendWaitReceivePort (send_msg = None)
print("[SERV] Message type = {0:#x}".format(msg.u2.s2.Type))
print("[SERV] Received data: <{0}>".format(msg.data))
if msg.u2.s2.Type & LPC_CONNECTION_REQUEST:
if msg.type & 0xfff & LPC_CONNECTION_REQUEST:
print("[SERV] Connection request")
msg.data = "WOKAY"
server.accept_connection(msg) # NtAlpcAcceptConnectPort
attrs, msg = server.wait_data() # NtAlpcSendWaitReceivePort (send_msg = None)
msg = server.recv() # NtAlpcSendWaitReceivePort (send_msg = None)
print("[SERV] Received message")
print("[SERV] Message type = {0:#x}".format(msg.u2.s2.Type))
if msg.u2.s2.Type & LPC_REQUEST:
if msg.type & 0xfff & LPC_REQUEST:
print("[SERV] ALPC request: <{0}>".format(msg.data))
# Copy MessageId + NtAlpcSendWaitReceivePort
server.reply(msg, "REQUEST '{0}' DONE".format(msg.data))
# 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)
server.send(msg)
def alpc_client():
@@ -29,7 +32,7 @@ def alpc_client():
connect_response = client.connect_to_port(PORT_NAME, "COUCOU") # NtAlpcConnectPort
print("[CLIENT] Connected: {0}".format(connect_response.data))
print("[CLIENT] Send Message <POUET>")
attr, response = client.send_receive("POUET") # NtAlpcSendWaitReceivePort
response = client.send_receive("POUET") # NtAlpcSendWaitReceivePort
print("[CLIENT] Server response: <{0}>".format(response.data))
+1
View File
@@ -314,6 +314,7 @@ class AlpcClient(AlpcTransportBase):
else:
raise ValueError("Don't know how to send <{0!r}> as connect message".format(connect_message))
windows.utils.print_ctypes_struct(port_attr, "port_attr_connect", hexa=True)
receive_attr = MessageAttribute.with_all_attributes()
winproxy.NtAlpcConnectPort(handle, port_name_unicode, obj_attr, port_attr, flags, None, send_msg, buffersize, send_msg_attr, receive_attr, timeout)
# If send_msg is not None, it contains the ClientId.UniqueProcess : PID of the server :)
+4
View File
@@ -75,6 +75,10 @@ class WindowsTestCase(unittest.TestCase):
# Re-set the handle to be able to kill it
calc._handle = save_handle
@check_for_gc_garbage
def test_current_process_threads(self):
# Had a bug with WinThread and CurrentProcess.name (which was non-existant)
self.assertTrue([repr(t) for t in windows.current_process.threads])
@check_for_gc_garbage
def test_pop_calc_32(self):
+1 -1
View File
@@ -394,7 +394,7 @@ class FirewallRule(cominterfaces.INetFwRule):
return icmp_type_and_code.value
def __repr__(self):
return '<{0} "{1}">'.format(type(self).__name__, self.name)
return u'<{0} "{1}">'.format(type(self).__name__, self.name)
class Network(object):
NetFwPolicy2 = windows.com.IID.from_string("E2B3C97F-6AE1-41AC-817A-F6F92166D7DD")
+2
View File
@@ -761,6 +761,8 @@ class CurrentProcess(Process):
allocator = native_exec.native_function.allocator
name = "CurrentProcess" # Used by Winthread for __repr__
# Use RtlGetCurrentPeb ?
def get_peb_builtin(self):
if self.get_peb is not None: