Advertisement
Josiahiscool73

python executor base as of jun 25 2025 7:33 am

Jun 25th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. import ctypes
  2. import ctypes.wintypes
  3. import psutil
  4. import struct
  5. import imgui
  6. import glfw
  7. import OpenGL.GL as gl
  8.  
  9. # --- PREVIOUS BACKEND CODE (Memory and Executor classes) ---
  10.  
  11. PROCESS_ALL_ACCESS = 0x1F0FFF
  12. MEM_COMMIT = 0x1000
  13. MEM_RESERVE = 0x2000
  14. PAGE_EXECUTE_READWRITE = 0x40
  15.  
  16. k32 = ctypes.WinDLL('kernel32', use_last_error=True)
  17.  
  18. k32.OpenProcess.argtypes = [ctypes.wintypes.DWORD, ctypes.wintypes.BOOL, ctypes.wintypes.DWORD]
  19. k32.OpenProcess.restype = ctypes.wintypes.HANDLE
  20. k32.ReadProcessMemory.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.LPCVOID, ctypes.wintypes.LPVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
  21. k32.ReadProcessMemory.restype = ctypes.wintypes.BOOL
  22. k32.WriteProcessMemory.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.LPVOID, ctypes.wintypes.LPCVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
  23. k32.WriteProcessMemory.restype = ctypes.wintypes.BOOL
  24. k32.VirtualAllocEx.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.LPVOID, ctypes.c_size_t, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD]
  25. k32.VirtualAllocEx.restype = ctypes.wintypes.LPVOID
  26.  
  27. OFFSETS = {
  28. "GetLuaState_ptr": 0x675AA38,
  29. "LuaVM_Load": 0xB503A0,
  30. "Luau_Execute": 0x26D4300,
  31. }
  32.  
  33. class Memory:
  34. def __init__(self, process_name="RobloxPlayerBeta.exe"):
  35. self.process_name = process_name
  36. self.pid = None
  37. self.handle = None
  38. self.base_address = None
  39. if not self._attach():
  40. raise Exception(f"could not attach to {self.process_name}. is it running?")
  41.  
  42. def _attach(self):
  43. for proc in psutil.process_iter(['pid', 'name']):
  44. if proc.info['name'] == self.process_name:
  45. self.pid = proc.info['pid']
  46. break
  47. if not self.pid: return False
  48. self.handle = k32.OpenProcess(PROCESS_ALL_ACCESS, False, self.pid)
  49. if not self.handle: return False
  50. for module in psutil.Process(self.pid).memory_maps():
  51. if module.path and self.process_name in module.path:
  52. self.base_address = int(module.addr, 16)
  53. break
  54. return self.base_address is not None
  55.  
  56. def read_u64(self, address):
  57. buffer = ctypes.create_string_buffer(8)
  58. bytes_read = ctypes.c_size_t(0)
  59. k32.ReadProcessMemory(self.handle, address, buffer, 8, ctypes.byref(bytes_read))
  60. return struct.unpack('<Q', buffer.raw)[0]
  61.  
  62. def read_u32(self, address):
  63. buffer = ctypes.create_string_buffer(4)
  64. bytes_read = ctypes.c_size_t(0)
  65. k32.ReadProcessMemory(self.handle, address, buffer, 4, ctypes.byref(bytes_read))
  66. return struct.unpack('<I', buffer.raw)[0]
  67.  
  68. def write_bytes(self, address, data):
  69. size = len(data)
  70. buffer = ctypes.create_string_buffer(data, size)
  71. bytes_written = ctypes.c_size_t(0)
  72. return k32.WriteProcessMemory(self.handle, address, buffer, size, ctypes.byref(bytes_written))
  73.  
  74. def allocate(self, size):
  75. return k32.VirtualAllocEx(self.handle, 0, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)
  76.  
  77. class Executor:
  78. def __init__(self, mem):
  79. self.mem = mem
  80. self.lua_state = None
  81. self.addr_luavm_load = self.mem.base_address + OFFSETS["LuaVM_Load"]
  82. self.addr_luau_execute = self.mem.base_address + OFFSETS["Luau_Execute"]
  83.  
  84. def get_lua_state(self):
  85. base = self.mem.base_address + OFFSETS["GetLuaState_ptr"]
  86. ptr1 = self.mem.read_u64(base)
  87. ptr2 = self.mem.read_u64(ptr1 + 0x1B8)
  88. ptr3 = self.mem.read_u64(ptr2 + 0x80)
  89. ptr4 = self.mem.read_u64(ptr3 + 0x3B0)
  90. final_ptr_address = ptr4 + 0x140 + 0x170 + 0x88
  91. encoded_ptr = self.mem.read_u64(final_ptr_address)
  92. xor_key = self.mem.read_u32(final_ptr_address + 0x4)
  93. encoded_ptr_as_u32 = encoded_ptr & 0xFFFFFFFF
  94. high = (xor_key ^ encoded_ptr_as_u32) << 32
  95. low = (encoded_ptr_as_u32 ^ xor_key)
  96. self.lua_state = high | low
  97. return self.lua_state
  98.  
  99. def execute(self, script):
  100. if not self.lua_state:
  101. return "lua state not found. inject first."
  102. script_bytes = script.encode('utf-8') + b'\x00'
  103. script_addr = self.mem.allocate(len(script_bytes))
  104. if not script_addr:
  105. return "failed to allocate memory."
  106. if not self.mem.write_bytes(script_addr, script_bytes):
  107. return "failed to write script to memory."
  108.  
  109. # as we said, this next part is the hard shit
  110. # we'd need to call LuaVM_Load and then Luau_Execute
  111.  
  112. return f"script written to {hex(script_addr)}. execution call is complex and not implemented."
  113.  
  114. # --- GUI CODE ---
  115.  
  116. def impl_glfw_init():
  117. if not glfw.init():
  118. print("could not initialize OpenGL context")
  119. exit(1)
  120.  
  121. # OS X supports only forward-compatible core profiles from 3.2
  122. glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
  123. glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
  124. glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
  125. glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)
  126.  
  127. window = glfw.create_window(700, 500, "Dolphin Executor", None, None)
  128. glfw.make_context_current(window)
  129.  
  130. if not window:
  131. glfw.terminate()
  132. print("could not initialize window")
  133. exit(1)
  134.  
  135. return window
  136.  
  137. def main():
  138. window = impl_glfw_init()
  139. imgui.create_context()
  140. from imgui.integrations.glfw import GlfwRenderer
  141. impl = GlfwRenderer(window)
  142.  
  143. # --- GUI state variables ---
  144. script_text = 'print("hello from dolphin executor")'
  145. status_message = "idle. press inject to start."
  146. injected = False
  147. executor_instance = None
  148.  
  149. while not glfw.window_should_close(window):
  150. glfw.poll_events()
  151. impl.process_inputs()
  152.  
  153. imgui.new_frame()
  154.  
  155. # --- main window ---
  156. imgui.set_next_window_size(700, 500)
  157. imgui.set_next_window_position(0, 0)
  158. imgui.begin("Main", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_TITLE_BAR)
  159.  
  160. # --- top buttons ---
  161. if imgui.button("Inject", width=100, height=30):
  162. try:
  163. mem = Memory()
  164. executor_instance = Executor(mem)
  165. ls = executor_instance.get_lua_state()
  166. status_message = f"injected successfully! L: {hex(ls)}"
  167. injected = True
  168. except Exception as e:
  169. status_message = f"error: {e}"
  170. injected = False
  171.  
  172. imgui.same_line()
  173.  
  174. # disable execute button if not injected
  175. if not injected:
  176. imgui.push_style_var(imgui.STYLE_ALPHA, 0.5)
  177. imgui.button("Execute", width=100, height=30)
  178. imgui.pop_style_var()
  179. else:
  180. if imgui.button("Execute", width=100, height=30):
  181. if executor_instance:
  182. status_message = executor_instance.execute(script_text)
  183.  
  184. imgui.separator()
  185.  
  186. # --- script textbox ---
  187. imgui.text("Script Editor")
  188. changed, script_text = imgui.input_text_multiline(
  189. "##script_editor",
  190. script_text,
  191. -1, # width, -1 = full width
  192. -50 # height, -50 = full height minus 50px
  193. )
  194.  
  195. # --- status bar ---
  196. imgui.separator()
  197. imgui.text("Status:")
  198. imgui.same_line()
  199. imgui.text_colored(status_message, 0.8, 0.8, 0.8) # light grey
  200.  
  201. imgui.end()
  202.  
  203. # --- rendering ---
  204. gl.glClearColor(0.1, 0.1, 0.1, 1)
  205. gl.glClear(gl.GL_COLOR_BUFFER_BIT)
  206. imgui.render()
  207. impl.render(imgui.get_draw_data())
  208. glfw.swap_buffers(window)
  209.  
  210. impl.shutdown()
  211. glfw.terminate()
  212.  
  213. if __name__ == "__main__":
  214. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement