diff --git a/ctypes_generation/definitions/structures/winstruct_alpc.txt b/ctypes_generation/definitions/structures/winstruct_alpc.txt deleted file mode 100644 index f6862f2..0000000 --- a/ctypes_generation/definitions/structures/winstruct_alpc.txt +++ /dev/null @@ -1,276 +0,0 @@ - -typedef enum _ALPC_PORT_INFORMATION_CLASS -{ - AlpcBasicInformation, - AlpcPortInformation, - AlpcAssociateCompletionPortInformation, - AlpcConnectedSIDInformation, - AlpcServerInformation, - AlpcMessageZoneInformation, - AlpcRegisterCompletionListInformation, - AlpcUnregisterCompletionListInformation, - AlpcAdjustCompletionListConcurrencyCountInformation, - AlpcRegisterCallbackInformation, - AlpcCompletionListRundownInformation, - AlpcWaitForPortReferences, - MaxAlpcPortInfoClass -} ALPC_PORT_INFORMATION_CLASS; - -typedef enum _ALPC_MESSAGE_INFORMATION_CLASS -{ - AlpcMessageSidInformation, - AlpcMessageTokenModifiedIdInformation, - MaxAlpcMessageInfoClass, - AlpcMessageHandleInformation, -} ALPC_MESSAGE_INFORMATION_CLASS, *PALPC_MESSAGE_INFORMATION_CLASS; - -typedef struct _ALPC_PORT_ATTRIBUTES32 -{ - ULONG Flags; - SECURITY_QUALITY_OF_SERVICE SecurityQos; - SIZE_T MaxMessageLength; - SIZE_T MemoryBandwidth; - SIZE_T MaxPoolUsage; - SIZE_T MaxSectionSize; - SIZE_T MaxViewSize; - SIZE_T MaxTotalSectionSize; - ULONG DupObjectTypes; -} ALPC_PORT_ATTRIBUTES32, *PALPC_PORT_ATTRIBUTES32; - - -typedef struct _ALPC_PORT_ATTRIBUTES64 -{ - ULONG Flags; - SECURITY_QUALITY_OF_SERVICE SecurityQos; - SIZE_T MaxMessageLength; - SIZE_T MemoryBandwidth; - SIZE_T MaxPoolUsage; - SIZE_T MaxSectionSize; - SIZE_T MaxViewSize; - SIZE_T MaxTotalSectionSize; - ULONG DupObjectTypes; - ULONG Reserved; -} ALPC_PORT_ATTRIBUTES64, *PALPC_PORT_ATTRIBUTES64; - -typedef struct _ALPC_MESSAGE_ATTRIBUTES -{ - ULONG AllocatedAttributes; - ULONG ValidAttributes; -} ALPC_MESSAGE_ATTRIBUTES, *PALPC_MESSAGE_ATTRIBUTES; - - -typedef union _PORT_MESSAGE32_TMP_UNION -{ - ULONG ClientViewSize; - ULONG CallbackId; -} PORT_MESSAGE_TMP_UNION; - -typedef union _PORT_MESSAGE64_TMP_UNION -{ - ULONGLONG ClientViewSize; - ULONG CallbackId; -} PORT_MESSAGE_TMP_UNION; - - -typedef struct _PORT_MESSAGE_TMP_SUBSTRUCT_S1 -{ - CSHORT DataLength; - CSHORT TotalLength; -} _PORT_MESSAGE_TMP_SUBSTRUCT_S1; - - -typedef union _PORT_MESSAGE_TMP_UNION_U1 -{ - ULONG Length; - _PORT_MESSAGE_TMP_SUBSTRUCT_S1 s1; -} _PORT_MESSAGE_TMP_UNION_U1; - - -typedef struct _PORT_MESSAGE_TMP_SUBSTRUCT_S2 -{ - CSHORT Type; - CSHORT DataInfoOffset; -} _PORT_MESSAGE_TMP_SUBSTRUCT_S2; - - -typedef union _PORT_MESSAGE_TMP_UNION_U2 -{ - ULONG ZeroInit; - _PORT_MESSAGE_TMP_SUBSTRUCT_S2 s2; -} _PORT_MESSAGE_TMP_UNION_U2; - - -typedef struct _PORT_MESSAGE32 -{ - _PORT_MESSAGE_TMP_UNION_U1 u1; - _PORT_MESSAGE_TMP_UNION_U2 u2; - CLIENT_ID32 ClientId; - ULONG MessageId; - _PORT_MESSAGE32_TMP_UNION tmp_union; -} PORT_MESSAGE32, *PPORT_MESSAGE32; - -typedef struct _PORT_MESSAGE64 -{ - _PORT_MESSAGE_TMP_UNION_U1 u1; - _PORT_MESSAGE_TMP_UNION_U2 u2; - CLIENT_ID64 ClientId; - ULONG MessageId; - _PORT_MESSAGE64_TMP_UNION tmp_union; -} PORT_MESSAGE64, *PPORT_MESSAGE64; - - -typedef struct _ALPC_SERVER_INFORMATION_TMP_IN -{ - HANDLE ThreadHandle; -} ALPC_SERVER_INFORMATION_TMP_IN; - -typedef struct _ALPC_SERVER_INFORMATION_TMP_OUT -{ - BOOLEAN ThreadBlocked; - HANDLE ConnectedProcessId; - UNICODE_STRING ConnectionPortName; -} ALPC_SERVER_INFORMATION_TMP_OUT; - -typedef union ALPC_SERVER_INFORMATION -{ - ALPC_SERVER_INFORMATION_TMP_IN In; - ALPC_SERVER_INFORMATION_TMP_OUT Out; -} ALPC_SERVER_INFORMATION; - - -typedef struct _ALPC_CONTEXT_ATTR -{ - PVOID PortContext; - PVOID MessageContext; - ULONG Sequence; - ULONG MessageId; - ULONG CallbackId; -} ALPC_CONTEXT_ATTR, *PALPC_CONTEXT_ATTR; - -typedef struct _ALPC_CONTEXT_ATTR32 -{ - ULONG PortContext; - ULONG MessageContext; - ULONG Sequence; - ULONG MessageId; - ULONG CallbackId; -} ALPC_CONTEXT_ATTR32, *PALPC_CONTEXT_ATTR32; - -typedef struct _ALPC_CONTEXT_ATTR64 -{ - ULONGLONG PortContext; - ULONGLONG MessageContext; - ULONG Sequence; - ULONG MessageId; - ULONG CallbackId; -} ALPC_CONTEXT_ATTR64, *PALPC_CONTEXT_ATTR64; - - -typedef struct _ALPC_HANDLE_ATTR -{ - ULONG Flags; - HANDLE Handle; - ULONG ObjectType; - ACCESS_MASK DesiredAccess; -} ALPC_HANDLE_ATTR, *PALPC_HANDLE_ATTR; - -typedef struct _ALPC_HANDLE_ATTR32 -{ - ULONG Flags; - ULONG Handle; - ULONG ObjectType; - ACCESS_MASK DesiredAccess; -} ALPC_HANDLE_ATTR32, *PALPC_HANDLE_ATTR32; - - -typedef struct _ALPC_HANDLE_ATTR64 -{ - ULONG Flags; - ULONGLONG Handle; - ULONG ObjectType; - ACCESS_MASK DesiredAccess; -} ALPC_HANDLE_ATTR64, *PALPC_HANDLE_ATTR64; - - -typedef struct _ALPC_SECURITY_ATTR -{ - ULONG Flags; - PSECURITY_QUALITY_OF_SERVICE QoS; - ALPC_HANDLE ContextHandle; -} ALPC_SECURITY_ATTR, *PALPC_SECURITY_ATTR; - -typedef struct _ALPC_SECURITY_ATTR32 -{ - ULONG Flags; - ULONG QoS; - ULONG ContextHandle; -} ALPC_SECURITY_ATTR32, *PALPC_SECURITY_ATTR32; - - -typedef struct _ALPC_SECURITY_ATTR64 -{ - ULONGLONG Flags; - ULONGLONG QoS; - ULONGLONG ContextHandle; -} ALPC_SECURITY_ATTR64, *PALPC_SECURITY_ATTR64; - -typedef struct _ALPC_DATA_VIEW_ATTR -{ - ULONG Flags; - ALPC_HANDLE SectionHandle; - PVOID ViewBase; - PVOID ViewSize; -} ALPC_DATA_VIEW_ATTR, *PALPC_DATA_VIEW_ATTR; - -typedef struct _ALPC_DATA_VIEW_ATTR32 -{ - ULONG Flags; - ULONG SectionHandle; - ULONG ViewBase; - ULONG ViewSize; -} ALPC_DATA_VIEW_ATTR32, *PALPC_DATA_VIEW_ATTR32; - - -typedef struct _ALPC_DATA_VIEW_ATTR64 -{ - ULONG Flags; - ULONGLONG SectionHandle; - ULONGLONG ViewBase; - ULONGLONG ViewSize; -} ALPC_DATA_VIEW_ATTR64, *PALPC_DATA_VIEW_ATTR64; - - -typedef struct _ALPC_TOKEN_ATTR -{ - ULONGLONG TokenId; - ULONGLONG AuthenticationId; - ULONGLONG ModifiedId; -} ALPC_TOKEN_ATTR, *PALPC_TOKEN_ATTR; - - -typedef struct _ALPC_DIRECT_ATTR -{ - HANDLE Event; -} ALPC_DIRECT_ATTR, *PALPC_DIRECT_ATTR; - -typedef struct _ALPC_DIRECT_ATTR32 -{ - ULONG Event; -} ALPC_DIRECT_ATTR32, *PALPC_DIRECT_ATTR32; - -typedef struct _ALPC_DIRECT_ATTR64 -{ - ULONGLONG Event; -} ALPC_DIRECT_ATTR64, *PALPC_DIRECT_ATTR64; - - -typedef struct _ALPC_WORK_ON_BEHALF_ATTR -{ - ULONGLONG Ticket; -} ALPC_WORK_ON_BEHALF_ATTR, *PALPC_WORK_ON_BEHALF_ATTR; - -typedef struct _RPC_IF_ID { - IID Uuid; - USHORT VersMajor; - USHORT VersMinor; -} RPC_IF_ID; diff --git a/samples/rpc/uac.py b/samples/rpc/uac.py index 41d8e27..83bdce8 100644 --- a/samples/rpc/uac.py +++ b/samples/rpc/uac.py @@ -52,12 +52,12 @@ iid = client.bind(UAC_UIID) # Marshalling parameters. parameters = RAiLaunchAdminProcessParameters.pack([ - params.target + "\x00", # Application Path - params.cmdline + "\x00", # Commandline + params.target, # Application Path + params.cmdline, # Commandline params.uacflags, # UAC-Request Flag params.creationflags, # dwCreationFlags - "\x00", # StartDirectory - "WinSta0\\Default\x00", # Station + "", # StartDirectory + "WinSta0\\Default", # Station # Startup Info (None, # Title 0, # dwX diff --git a/windows/rpc/ndr.py b/windows/rpc/ndr.py index a3025d5..5c3ac11 100644 --- a/windows/rpc/ndr.py +++ b/windows/rpc/ndr.py @@ -100,6 +100,7 @@ class NdrSID(object): class NdrVaryingCString(object): @classmethod def pack(cls, data): + """Pack string ``data``. append ``\\x00`` if not present at the end of the string""" if data is None: return None if not data.endswith('\x00'): @@ -112,6 +113,7 @@ class NdrVaryingCString(object): class NdrWString(object): @classmethod def pack(cls, data): + """Pack string ``data``. append ``\\x00`` if not present at the end of the string""" if data is None: return None if not data.endswith('\x00'): @@ -134,6 +136,7 @@ class NdrWString(object): class NdrCString(object): @classmethod def pack(cls, data): + """Pack string ``data``. append ``\\x00`` if not present at the end of the string""" if data is None: return None if not data.endswith('\x00'): @@ -168,7 +171,7 @@ class NdrHyper(object): @classmethod def unpack(self, stream): - stream.align(4) + stream.align(8) return stream.partial_unpack("".format(self, name)) + # Emulate the WindowsError that would be triggered in 'adjust_privileges' ? + raise ValueError("{0} has no privilege <{1}>".format(self, name)) return self.adjust_privileges(privs) def __repr__(self): diff --git a/windows/winproxy/apiproxy.py b/windows/winproxy/apiproxy.py index 8131e01..ffce0bd 100644 --- a/windows/winproxy/apiproxy.py +++ b/windows/winproxy/apiproxy.py @@ -82,7 +82,13 @@ class ApiProxy(object): def generate_ctypes_function(): try: - c_prototyped = prototype((self.func_name, getattr(ctypes.windll, self.APIDLL)), params) + api_dll = ctypes.windll[self.APIDLL] + except WindowsError as e: + if e.winerror == gdef.ERROR_BAD_EXE_FORMAT: + e.strerror = e.strerror.replace("%1", "<{0}>".format(self.APIDLL)) + raise + try: + c_prototyped = prototype((self.func_name, api_dll), params) except (AttributeError, WindowsError): raise ExportNotFound(self.func_name, self.APIDLL) if self.error_check is not None: