Skip to content

Commit c6898a4

Browse files
committed
Add definition of TEB + tests on offset of generated ctypes
1 parent 13c2842 commit c6898a4

6 files changed

Lines changed: 63 additions & 27 deletions

File tree

ctypes_generation/definitions/structures/teb_peb.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ typedef struct _NT_TIB {
204204
PVOID SubSystemTib;
205205
union {
206206
PVOID FiberData;
207-
// ULONG Version; // Sub-union break remotectypes generation for now -> Ignore this field until fixed
207+
ULONG Version;
208208
};
209209
PVOID ArbitraryUserPointer;
210210
struct _NT_TIB *Self;

tests/test_generated_def.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ def assert_struct_offset(struct, field, offset):
1212
if windows.current_process.bitness == 32:
1313
PEB32 = windows.generated_def.PEB
1414
PEB64 = rctypes.transform_type_to_remote64bits(windows.generated_def.PEB)
15-
15+
1616
TEB32 = windows.generated_def.TEB
1717
TEB64 = rctypes.transform_type_to_remote64bits(windows.generated_def.TEB)
18-
18+
1919
NT_TIB32 = windows.generated_def.NT_TIB
2020
NT_TIB64 = rctypes.transform_type_to_remote64bits(windows.generated_def.NT_TIB)
21-
21+
2222
SYSTEM_PROCESS_INFORMATION32 = windows.generated_def.SYSTEM_PROCESS_INFORMATION
2323
SYSTEM_PROCESS_INFORMATION64 = rctypes.transform_type_to_remote64bits(windows.generated_def.SYSTEM_PROCESS_INFORMATION)
2424
else:
2525
PEB32 = rctypes.transform_type_to_remote32bits(windows.generated_def.PEB)
2626
PEB64 = windows.generated_def.PEB
27-
27+
2828
TEB32 = rctypes.transform_type_to_remote32bits(windows.generated_def.TEB)
2929
TEB64 = windows.generated_def.TEB
30-
30+
3131
NT_TIB32 = rctypes.transform_type_to_remote32bits(windows.generated_def.NT_TIB)
3232
NT_TIB64 = windows.generated_def.NT_TIB
33-
33+
3434
SYSTEM_PROCESS_INFORMATION32 = rctypes.transform_type_to_remote32bits(windows.generated_def.SYSTEM_PROCESS_INFORMATION)
3535
SYSTEM_PROCESS_INFORMATION64 = windows.generated_def.SYSTEM_PROCESS_INFORMATION
3636

@@ -75,7 +75,7 @@ def test_nt_tib32_fields():
7575
assert_nt_tib_offset("StackLimit", 8)
7676
assert_nt_tib_offset("SubSystemTib", 0xc)
7777
assert_nt_tib_offset("FiberData", 0x10)
78-
# assert_nt_tib_offset("Version", 0x14)
78+
assert_nt_tib_offset("Version", 0x10)
7979
assert_nt_tib_offset("ArbitraryUserPointer", 0x14)
8080
assert_nt_tib_offset("Self", 0x18) # Important !
8181

@@ -86,7 +86,7 @@ def test_nt_tib64_fields():
8686
assert_nt_tib_offset("StackLimit", 0x10)
8787
assert_nt_tib_offset("SubSystemTib", 0x18)
8888
assert_nt_tib_offset("FiberData", 0x20)
89-
# assert_nt_tib_offset("Version", 0x28)
89+
assert_nt_tib_offset("Version", 0x20)
9090
assert_nt_tib_offset("ArbitraryUserPointer", 0x28)
9191
assert_nt_tib_offset("Self", 0x30) # Important !
9292

windows/generated_def/meta.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12730,6 +12730,7 @@
1273012730
'NET_DISPLAY_USER',
1273112731
'NPBITMAP',
1273212732
'NPRGBTRIPLE',
12733+
'NT_TIB',
1273312734
'OBJECTS_AND_NAME_A',
1273412735
'OBJECTS_AND_NAME_W',
1273512736
'OBJECTS_AND_SID',
@@ -15117,6 +15118,7 @@
1511715118
'RtlDosPathNameToNtPathName_U',
1511815119
'RtlEqualUnicodeString',
1511915120
'RtlGetCompressionWorkSpaceSize',
15121+
'RtlGetCurrentPeb',
1512015122
'RtlGetUnloadEventTraceEx',
1512115123
'RtlInitString',
1512215124
'RtlInitUnicodeString',

windows/generated_def/winfuncs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,11 @@
17351735
FreeLibraryPrototype = WINFUNCTYPE(BOOL, HMODULE)
17361736
FreeLibraryParams = ((1, 'hLibModule'),)
17371737

1738+
#def RtlGetCurrentPeb():
1739+
# return RtlGetCurrentPeb.ctypes_function()
1740+
RtlGetCurrentPebPrototype = WINFUNCTYPE(PVOID)
1741+
RtlGetCurrentPebParams = ()
1742+
17381743
#def RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData):
17391744
# return RegQueryValueExA.ctypes_function(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)
17401745
RegQueryValueExAPrototype = WINFUNCTYPE(LSTATUS, HKEY, LPCSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD)

windows/generated_def/winstructs.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,8 @@ class _ATTACH_VIRTUAL_DISK_PARAMETERS(Structure):
19021902
PATTACH_VIRTUAL_DISK_PARAMETERS = POINTER(_ATTACH_VIRTUAL_DISK_PARAMETERS)
19031903

19041904
# Self referencing struct tricks
1905-
class _INTERNET_BUFFERSA(Structure): pass
1905+
class _INTERNET_BUFFERSA(Structure):
1906+
pass
19061907
INTERNET_BUFFERSA = _INTERNET_BUFFERSA
19071908
LPINTERNET_BUFFERSA = POINTER(_INTERNET_BUFFERSA)
19081909
_INTERNET_BUFFERSA._fields_ = [
@@ -1919,7 +1920,8 @@ class _INTERNET_BUFFERSA(Structure): pass
19191920
]
19201921

19211922
# Self referencing struct tricks
1922-
class _INTERNET_BUFFERSW(Structure): pass
1923+
class _INTERNET_BUFFERSW(Structure):
1924+
pass
19231925
INTERNET_BUFFERSW = _INTERNET_BUFFERSW
19241926
LPINTERNET_BUFFERSW = POINTER(_INTERNET_BUFFERSW)
19251927
_INTERNET_BUFFERSW._fields_ = [
@@ -2453,7 +2455,8 @@ class _IP_INTERFACE_INFO(Structure):
24532455
PIP_INTERFACE_INFO = POINTER(_IP_INTERFACE_INFO)
24542456

24552457
# Self referencing struct tricks
2456-
class _DNS_CACHE_ENTRY(Structure): pass
2458+
class _DNS_CACHE_ENTRY(Structure):
2459+
pass
24572460
DNS_CACHE_ENTRY = _DNS_CACHE_ENTRY
24582461
PDNS_CACHE_ENTRY = POINTER(_DNS_CACHE_ENTRY)
24592462
_DNS_CACHE_ENTRY._fields_ = [
@@ -2982,7 +2985,9 @@ class _ANON__DNSRECORDA_SUB_UNION_2(Union):
29822985
]
29832986

29842987
# Self referencing struct tricks
2985-
class _DnsRecordA(Structure): pass
2988+
class _DnsRecordA(Structure):
2989+
_anonymous_ = ("Flags","Data")
2990+
29862991
DNS_RECORDA = _DnsRecordA
29872992
PDNS_RECORDA = POINTER(_DnsRecordA)
29882993
_DnsRecordA._fields_ = [
@@ -3092,7 +3097,9 @@ class _ANON__DNSRECORDW_SUB_UNION_2(Union):
30923097
]
30933098

30943099
# Self referencing struct tricks
3095-
class _DnsRecordW(Structure): pass
3100+
class _DnsRecordW(Structure):
3101+
_anonymous_ = ("Flags","Data")
3102+
30963103
DNS_RECORDW = _DnsRecordW
30973104
PDNS_RECORDW = POINTER(_DnsRecordW)
30983105
_DnsRecordW._fields_ = [
@@ -3171,7 +3178,8 @@ class IP_ADDRESS_STRING(Structure):
31713178
PIP_MASK_STRING = POINTER(IP_ADDRESS_STRING)
31723179

31733180
# Self referencing struct tricks
3174-
class _IP_ADDR_STRING(Structure): pass
3181+
class _IP_ADDR_STRING(Structure):
3182+
pass
31753183
IP_ADDR_STRING = _IP_ADDR_STRING
31763184
PIP_ADDR_STRING = POINTER(_IP_ADDR_STRING)
31773185
_IP_ADDR_STRING._fields_ = [
@@ -3182,7 +3190,8 @@ class _IP_ADDR_STRING(Structure): pass
31823190
]
31833191

31843192
# Self referencing struct tricks
3185-
class _IP_ADAPTER_INFO(Structure): pass
3193+
class _IP_ADAPTER_INFO(Structure):
3194+
pass
31863195
IP_ADAPTER_INFO = _IP_ADAPTER_INFO
31873196
PIP_ADAPTER_INFO = POINTER(_IP_ADAPTER_INFO)
31883197
_IP_ADAPTER_INFO._fields_ = [
@@ -3877,7 +3886,8 @@ class _SHFILEOPSTRUCTA(Structure):
38773886
SHFILEOPSTRUCTA = _SHFILEOPSTRUCTA
38783887

38793888
# Self referencing struct tricks
3880-
class _LIST_ENTRY(Structure): pass
3889+
class _LIST_ENTRY(Structure):
3890+
pass
38813891
LIST_ENTRY = _LIST_ENTRY
38823892
PLIST_ENTRY = POINTER(_LIST_ENTRY)
38833893
PRLIST_ENTRY = POINTER(_LIST_ENTRY)
@@ -4917,23 +4927,31 @@ class _PEB(Structure):
49174927
PPEB = POINTER(_PEB)
49184928

49194929
# Self referencing struct tricks
4920-
class _EXCEPTION_REGISTRATION_RECORD(Structure): pass
4930+
class _EXCEPTION_REGISTRATION_RECORD(Structure):
4931+
pass
49214932

49224933
_EXCEPTION_REGISTRATION_RECORD._fields_ = [
49234934
("Next", POINTER(_EXCEPTION_REGISTRATION_RECORD)),
49244935
("Handler", PVOID),
49254936
]
49264937

4938+
class _ANON__NT_TIB_SUB_UNION_1(Union):
4939+
_fields_ = [
4940+
("FiberData", PVOID),
4941+
("Version", ULONG),
4942+
]
4943+
49274944
# Self referencing struct tricks
4928-
class _NT_TIB(Structure): pass
4945+
class _NT_TIB(Structure):
4946+
_anonymous_ = ("anon_01",)
49294947

4948+
NT_TIB = _NT_TIB
49304949
_NT_TIB._fields_ = [
49314950
("ExceptionList", POINTER(_EXCEPTION_REGISTRATION_RECORD)),
49324951
("StackBase", PVOID),
49334952
("StackLimit", PVOID),
49344953
("SubSystemTib", PVOID),
4935-
("FiberData", PVOID),
4936-
("Version", ULONG),
4954+
("anon_01", _ANON__NT_TIB_SUB_UNION_1),
49374955
("ArbitraryUserPointer", PVOID),
49384956
("Self", POINTER(_NT_TIB)),
49394957
]
@@ -6555,7 +6573,8 @@ class _OSVERSIONINFOEXW(Structure):
65556573
RTL_OSVERSIONINFOEXW = _OSVERSIONINFOEXW
65566574

65576575
# Self referencing struct tricks
6558-
class _EXCEPTION_RECORD(Structure): pass
6576+
class _EXCEPTION_RECORD(Structure):
6577+
pass
65596578
EXCEPTION_RECORD = _EXCEPTION_RECORD
65606579
PEXCEPTION_RECORD = POINTER(_EXCEPTION_RECORD)
65616580
_EXCEPTION_RECORD._fields_ = [
@@ -8753,7 +8772,8 @@ class _CERT_SIMPLE_CHAIN(Structure):
87538772
PCERT_SIMPLE_CHAIN = POINTER(_CERT_SIMPLE_CHAIN)
87548773

87558774
# Self referencing struct tricks
8756-
class _CERT_CHAIN_CONTEXT(Structure): pass
8775+
class _CERT_CHAIN_CONTEXT(Structure):
8776+
pass
87578777
CERT_CHAIN_CONTEXT = _CERT_CHAIN_CONTEXT
87588778
PCCERT_CHAIN_CONTEXT = POINTER(_CERT_CHAIN_CONTEXT)
87598779
PCERT_CHAIN_CONTEXT = POINTER(_CERT_CHAIN_CONTEXT)
@@ -11118,7 +11138,9 @@ class _ANON__TRUSTEE_A_SUB_UNION_1(Union):
1111811138
]
1111911139

1112011140
# Self referencing struct tricks
11121-
class _TRUSTEE_A(Structure): pass
11141+
class _TRUSTEE_A(Structure):
11142+
_anonymous_ = ("anon_01",)
11143+
1112211144
PTRUSTEEA = POINTER(_TRUSTEE_A)
1112311145
PTRUSTEE_A = POINTER(_TRUSTEE_A)
1112411146
TRUSTEEA = _TRUSTEE_A
@@ -11152,7 +11174,9 @@ class _ANON__TRUSTEE_W_SUB_UNION_1(Union):
1115211174
]
1115311175

1115411176
# Self referencing struct tricks
11155-
class _TRUSTEE_W(Structure): pass
11177+
class _TRUSTEE_W(Structure):
11178+
_anonymous_ = ("anon_01",)
11179+
1115611180
PTRUSTEEW = POINTER(_TRUSTEE_W)
1115711181
PTRUSTEE_W = POINTER(_TRUSTEE_W)
1115811182
TRUSTEEW = _TRUSTEE_W
@@ -12564,7 +12588,8 @@ class sockaddr_in(Structure):
1256412588

1256512589

1256612590
# Self referencing struct tricks
12567-
class addrinfoW(Structure): pass
12591+
class addrinfoW(Structure):
12592+
pass
1256812593
ADDRINFOW = addrinfoW
1256912594
PADDRINFOW = POINTER(addrinfoW)
1257012595
addrinfoW._fields_ = [
@@ -12639,7 +12664,8 @@ class _WSAPROTOCOL_INFOW(Structure):
1263912664
WSAPROTOCOL_INFOW = _WSAPROTOCOL_INFOW
1264012665

1264112666
# Self referencing struct tricks
12642-
class addrinfo(Structure): pass
12667+
class addrinfo(Structure):
12668+
pass
1264312669
ADDRINFOA = addrinfo
1264412670
PADDRINFOA = POINTER(addrinfo)
1264512671
addrinfo._fields_ = [

windows/winproxy/apis/ntdll.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class NtdllProxy(ApiProxy):
1010

1111

1212
# Process
13+
@NtdllProxy(error_check=fail_on_zero)
14+
def RtlGetCurrentPeb():
15+
return RtlGetCurrentPeb.ctypes_function()
1316

1417
@NtdllProxy()
1518
def NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId):

0 commit comments

Comments
 (0)