Skip to content

Commit 6ccccf7

Browse files
committed
V1 of WinThread.teb
1 parent d05801d commit 6ccccf7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

windows/winobject/process.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ def set_token(self, token):
570570
class CurrentThread(Thread):
571571
"""The current thread"""
572572

573+
get_teb_code_by_bitness = {
574+
32: x86.assemble("mov eax, fs:[0x18]; ret"),
575+
64: x64.assemble("mov rax, gs:[0x30]; ret")
576+
577+
}
578+
573579
@property #It's not a fixedproperty because executing thread might change
574580
def tid(self):
575581
"""Thread ID
@@ -578,7 +584,14 @@ def tid(self):
578584
"""
579585
return winproxy.GetCurrentThreadId()
580586

587+
@utils.fixedproperty
588+
def teb_base(self):
589+
get_teb_base_code = self.get_teb_code_by_bitness[self.owner.bitness]
590+
return self.owner.execute(get_teb_base_code)
581591

592+
@property
593+
def teb(self):
594+
return TEB.from_address(self.teb_base)
582595

583596
@property
584597
def owner(self):
@@ -884,6 +897,10 @@ def teb_base(self):
884897
# TebBase->NtTib.ExceptionList = (PVOID)Teb32Base;
885898
return self.owner.read_dword(main_teb_addr)
886899

900+
@property
901+
def teb(self):
902+
return RemoteTEB(self.teb_base, target=self.owner)
903+
887904
@property
888905
def teb_syswow_base(self):
889906
"""The address of the thread's TEB64 for a SysWow64 process
@@ -895,6 +912,9 @@ def teb_syswow_base(self):
895912
# just return the main TEB
896913
return self._get_principal_teb_addr()
897914

915+
@property
916+
def teb_syswow(self):
917+
return TEB64.from_address(self.teb_syswow_base)
898918

899919

900920
def exit(self, code=0):
@@ -1321,6 +1341,14 @@ def apisetmap(self):
13211341
raise NotImplementedError("ApiSetMap does not exist prior to Windows 7")
13221342
return apisetmap.get_api_set_map_for_current_process(self.ApiSetMap)
13231343

1344+
# TEB enhanced, same bitness as PEB (current process)
1345+
class TEB(gdef.TEB):
1346+
def peb(self):
1347+
return ctypes.cast(self.ProcessEnvironmentBlock, ctypes.POINTER(PEB))[0]
1348+
1349+
class RemoteTEB(rctypes.RemoteStructure.from_structure(TEB)):
1350+
def peb(self):
1351+
return ctypes.cast(self.ProcessEnvironmentBlock, ctypes.POINTER(PEB))[0]
13241352

13251353
# Memory stuff
13261354

@@ -1435,6 +1463,7 @@ def apisetmap(self):
14351463

14361464

14371465

1466+
14381467
if CurrentProcess().bitness == 32:
14391468
class RemoteLoadedModule64(rctypes.transform_type_to_remote64bits(LoadedModule)):
14401469
@property

0 commit comments

Comments
 (0)