@@ -899,7 +899,9 @@ def teb_base(self):
899899
900900 @property
901901 def teb (self ):
902- return RemoteTEB (self .teb_base , target = self .owner )
902+ if self .owner .bitness == 32 :
903+ return RemoteTEB32 (self .teb_base , target = self .owner )
904+ return RemoteTEB64 (self .teb_base , target = self .owner )
903905
904906 @property
905907 def teb_syswow_base (self ):
@@ -914,7 +916,7 @@ def teb_syswow_base(self):
914916
915917 @property
916918 def teb_syswow (self ):
917- return TEB64 .from_address (self .teb_syswow_base )
919+ return RemoteTEB64 .from_address (self .teb_syswow_base )
918920
919921
920922 def exit (self , code = 0 ):
@@ -1222,8 +1224,6 @@ def exit(self, code=0):
12221224 return winproxy .TerminateProcess (self .handle , code )
12231225
12241226
1225-
1226-
12271227def transform_ctypes_fields (struct , replacement ):
12281228 return [(name , replacement .get (name , type )) for name , type in struct ._fields_ ]
12291229
@@ -1266,11 +1266,6 @@ def pe(self):
12661266 return pe_parse .GetPEFile (self .baseaddr )
12671267
12681268
1269- class LIST_ENTRY_PTR (PVOID ):
1270- def TO_LDR_ENTRY (self ):
1271- return LDR_DATA_TABLE_ENTRY .from_address (self .value - sizeof (PVOID ) * 2 )
1272-
1273-
12741269class PEB (gdef .PEB ):
12751270 """The PEB (Process Environment Block) of the current process"""
12761271
@@ -1305,13 +1300,13 @@ def modules(self):
13051300 :type: [:class:`LoadedModule`] -- List of loaded modules
13061301 """
13071302 res = []
1308- list_entry_ptr = ctypes . cast ( self .Ldr .contents .InMemoryOrderModuleList .Flink , LIST_ENTRY_PTR )
1309- current_dll = list_entry_ptr . TO_LDR_ENTRY ( )
1303+ first_flink = self .Ldr .contents .InMemoryOrderModuleList .Flink [ 0 ]
1304+ current_dll = first_flink . get_real_struct ( LoadedModule , LoadedModule . InMemoryOrderLinks )
13101305 while current_dll .DllBase :
13111306 res .append (current_dll )
1312- list_entry_ptr = ctypes . cast ( current_dll .InMemoryOrderLinks .Flink , LIST_ENTRY_PTR )
1313- current_dll = list_entry_ptr . TO_LDR_ENTRY ( )
1314- return [ LoadedModule . from_address ( addressof ( LDR )) for LDR in res ]
1307+ next_flink = current_dll .InMemoryOrderLinks .Flink [ 0 ]
1308+ current_dll = next_flink . get_real_struct ( LoadedModule , LoadedModule . InMemoryOrderLinks )
1309+ return res
13151310
13161311 @staticmethod
13171312 def _extract_environment (env_block_addr , target ):
@@ -1341,15 +1336,6 @@ def apisetmap(self):
13411336 raise NotImplementedError ("ApiSetMap does not exist prior to Windows 7" )
13421337 return apisetmap .get_api_set_map_for_current_process (self .ApiSetMap )
13431338
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 ]
1352-
13531339# Memory stuff
13541340
13551341class EPSAPI_WORKING_SET_BLOCK_BASE (object ):
@@ -1461,10 +1447,24 @@ def apisetmap(self):
14611447 raise NotImplementedError ("ApiSetMap for remote process not implemented yet" )
14621448
14631449
1450+ # TEB enhanced, same bitness as PEB (current process)
1451+ class TEB (gdef .TEB ):
1452+ @property
1453+ def peb (self ):
1454+ return ctypes .cast (self .ProcessEnvironmentBlock , ctypes .POINTER (PEB ))[0 ]
14641455
1465-
1456+ # mote TEB enhanced, same bitness as PEB (current process)
1457+ class RemoteTEB (rctypes .RemoteStructure .from_structure (TEB )):
1458+ @property
1459+ def peb (self ):
1460+ ctypes_peb = self .ProcessEnvironmentBlock .value
1461+ return RemotePEB (ctypes_peb , self ._target )
14661462
14671463if CurrentProcess ().bitness == 32 :
1464+ RemoteLoadedModule32 = RemoteLoadedModule
1465+ RemotePEB32 = RemotePEB
1466+ RemoteTEB32 = RemoteTEB
1467+
14681468 class RemoteLoadedModule64 (rctypes .transform_type_to_remote64bits (LoadedModule )):
14691469 @property
14701470 def pe (self ):
@@ -1479,7 +1479,6 @@ class RemotePEB64(rctypes.transform_type_to_remote64bits(PEB)):
14791479 def ptr_flink_to_remote_module (self , ptr_value ):
14801480 return RemoteLoadedModule64 (ptr_value - ctypes .sizeof (rctypes .c_void_p64 ) * 2 , self ._target )
14811481
1482-
14831482 @property
14841483 def exe (self ):
14851484 """The executable of the process, as pointed by PEB.ImageBaseAddress
@@ -1512,7 +1511,17 @@ def environment(self):
15121511
15131512 apisetmap = RemotePEB .apisetmap
15141513
1514+ class RemoteTEB64 (rctypes .transform_type_to_remote64bits (TEB )):
1515+ @property
1516+ def peb (self ):
1517+ ctypes_peb = self .ProcessEnvironmentBlock .value
1518+ return RemotePEB64 (ctypes_peb , self ._target )
1519+
1520+
15151521if CurrentProcess ().bitness == 64 :
1522+ RemoteLoadedModule64 = RemoteLoadedModule
1523+ RemotePEB64 = RemotePEB
1524+ RemoteTEB64 = RemoteTEB
15161525
15171526 class RemoteLoadedModule32 (rctypes .transform_type_to_remote32bits (LoadedModule )):
15181527 @property
@@ -1558,4 +1567,10 @@ def environment(self):
15581567 # TODO: Tests
15591568 return self ._extract_environment (self .ProcessParameters .contents .Environment , self ._target )
15601569
1561- apisetmap = RemotePEB .apisetmap
1570+ apisetmap = RemotePEB .apisetmap
1571+
1572+ class RemoteTEB32 (rctypes .transform_type_to_remote32bits (TEB )):
1573+ @property
1574+ def peb (self ):
1575+ ctypes_peb = self .ProcessEnvironmentBlock .value
1576+ return RemotePEB32 (ctypes_peb , self ._target )
0 commit comments