Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from ctypes import *
  2. import sys
  3.  
  4.  
  5. if "linux" in sys.platform:
  6.     OFFSET ={
  7.         'PhysicalObjectIndex': 0x10 # <- TODO
  8.  
  9.     }
  10.  
  11.     POINTERSIZE = 8
  12. elif "win" in sys.platform:
  13.     OFFSET ={
  14.         'PhysicalObjectIndex': 0x10
  15.  
  16.     }
  17.     POINTERSIZE = 4
  18.  
  19.  
  20.  
  21.  
  22. def pointerWalk(start, *offsets):
  23.     ptr = start
  24.     for offset in offsets:
  25.         if ptr == 0:
  26.             raise Exception('Attempt to dereference null!')
  27.  
  28.         ptr += offset
  29.         ptr = c_void_p.from_address(ptr).value
  30.  
  31.     return ptr
  32.  
  33.  
  34. def getPhysicalObjectEngineAddress(pythonObject):
  35.     if not hasattr(pythonObject, 'token'):
  36.         raise Exception('Token missing from object!')
  37.  
  38.     tokenPythonAddress = id(pythonObject.token)
  39.     return pointerWalk(tokenPythonAddress, 4 + POINTERSIZE, 0, 4)
  40.  
  41.  
  42. def getObjectId(obj):
  43.     engineobj = getPhysicalObjectEngineAddress(obj)
  44.     if engineobj == 0:
  45.         raise Exception('object is null')
  46.  
  47.  
  48.     return c_int32.from_address(engineobj + OFFSET['PhysicalObjectIndex']).value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement