Начинающий
-
Автор темы
- #1
данный код вызывает ошибку
Сообщение = Failed to write DLL to process memory. Error code: 0
Источник = C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py
Трассировка стека:
File "C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py", line 58, in inject_dll
File "C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py", line 96, in <module> (Current frame)
Exception: Failed to write DLL to process memory. Error code: 0
import ctypes
import subprocess
import time
import os
import tkinter as tk
from tkinter import messagebox as tkMessageBox
def find_steam():
possible_locations = [
r"C:\Program Files (x86)\Steam\steam.exe",
r"C:\Program Files\Steam\steam.exe",
r"D:\Steam\steam.exe" # Add other possible locations here if needed
]
for location in possible_locations:
if os.path.exists(location):
return location
return None
def run_steam():
steam_location = find_steam()
if steam_location:
print("Steam.exe found at:", steam_location)
subprocess.Popen(steam_location, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
print("Steam.exe not found. Please make sure Steam is installed in the default location.")
def run_counter_strike_2():
try:
cs2_process = subprocess.Popen(r"D:\Steam\steamapps\common\Counter-Strike Global Offensive\game\bin\win64\cs2.exe", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return cs2_process.pid
except FileNotFoundError:
print("File 'cs2.exe' not found.")
except Exception as e:
print("An error occurred while trying to run Counter-Strike 2:", e)
return None
import ctypes.util
def inject_dll(process_id, dll_path):
# Загрузить DLL
dll_buffer = bytearray(open(dll_path, "rb").read())
# Получить дескриптор процесса игры
PROCESS_VM_OPERATION = 0x0008
PROCESS_VM_WRITE = 0x0020
process_handle = ctypes.windll.kernel32.OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, False, process_id)
# Выделить память в процессе игры для DLL
dll_address = ctypes.windll.kernel32.VirtualAllocEx(process_handle, 0, len(dll_buffer), 0x3000, 0x40)
# Преобразовать dll_buffer в bytes
c_dll_buffer = (ctypes.c_char * len(dll_buffer)).from_buffer(dll_buffer)
# Записать DLL в выделенную память
written = ctypes.windll.kernel32.WriteProcessMemory(process_handle, dll_address, c_dll_buffer, len(dll_buffer), None)
if not written:
error_code = ctypes.get_last_error()
raise Exception(f"Failed to write DLL to process memory. Error code: {error_code}")
# Получить адрес функции CreateThread в ядре
kernel32 = ctypes.windll.LoadLibrary(ctypes.util.find_library("kernel32"))
create_thread_address = kernel32.GetProcAddress(kernel32._handle, b"CreateThread")
# Создать удаленный поток для загрузки DLL
thread_handle = ctypes.windll.kernel32.CreateRemoteThread(process_handle, None, 0, create_thread_address, dll_address, 0, None)
if thread_handle == 0:
error_code = ctypes.get_last_error()
raise Exception(f"Failed to create remote thread. Error code: {error_code}")
# Дождаться завершения удаленного потока
ctypes.windll.kernel32.WaitForSingleObject(thread_handle, -1)
# Закрыть дескрипторы
ctypes.windll.kernel32.CloseHandle(process_handle)
ctypes.windll.kernel32.CloseHandle(thread_handle)
if name == "main":
print("Running Steam...")
run_steam()
print("Waiting for Steam to launch...")
time.sleep(5) # Wait for 5 seconds
root = tk.Tk()
root.withdraw() # Hide the main window
user_confirmation = tkMessageBox.askokcancel("Confirmation", "Click OK when Steam is fully launched.", icon='info', parent=root)
if user_confirmation:
print("Launching Counter-Strike 2...")
cs2_process_id = run_counter_strike_2()
if cs2_process_id:
print("Counter-Strike 2 PID:", cs2_process_id)
# Инжектировать DLL
dll_path = "C:\\Users\\Nikita\\Downloads\\memordial.dll"
inject_dll(cs2_process_id, dll_path)
else:
print("User cancelled.")
Сообщение = Failed to write DLL to process memory. Error code: 0
Источник = C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py
Трассировка стека:
File "C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py", line 58, in inject_dll
File "C:\Users\Nikita\Desktop\PythonApplication4\PythonApplication4\PythonApplication4.py", line 96, in <module> (Current frame)
Exception: Failed to write DLL to process memory. Error code: 0
import ctypes
import subprocess
import time
import os
import tkinter as tk
from tkinter import messagebox as tkMessageBox
def find_steam():
possible_locations = [
r"C:\Program Files (x86)\Steam\steam.exe",
r"C:\Program Files\Steam\steam.exe",
r"D:\Steam\steam.exe" # Add other possible locations here if needed
]
for location in possible_locations:
if os.path.exists(location):
return location
return None
def run_steam():
steam_location = find_steam()
if steam_location:
print("Steam.exe found at:", steam_location)
subprocess.Popen(steam_location, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
print("Steam.exe not found. Please make sure Steam is installed in the default location.")
def run_counter_strike_2():
try:
cs2_process = subprocess.Popen(r"D:\Steam\steamapps\common\Counter-Strike Global Offensive\game\bin\win64\cs2.exe", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return cs2_process.pid
except FileNotFoundError:
print("File 'cs2.exe' not found.")
except Exception as e:
print("An error occurred while trying to run Counter-Strike 2:", e)
return None
import ctypes.util
def inject_dll(process_id, dll_path):
# Загрузить DLL
dll_buffer = bytearray(open(dll_path, "rb").read())
# Получить дескриптор процесса игры
PROCESS_VM_OPERATION = 0x0008
PROCESS_VM_WRITE = 0x0020
process_handle = ctypes.windll.kernel32.OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, False, process_id)
# Выделить память в процессе игры для DLL
dll_address = ctypes.windll.kernel32.VirtualAllocEx(process_handle, 0, len(dll_buffer), 0x3000, 0x40)
# Преобразовать dll_buffer в bytes
c_dll_buffer = (ctypes.c_char * len(dll_buffer)).from_buffer(dll_buffer)
# Записать DLL в выделенную память
written = ctypes.windll.kernel32.WriteProcessMemory(process_handle, dll_address, c_dll_buffer, len(dll_buffer), None)
if not written:
error_code = ctypes.get_last_error()
raise Exception(f"Failed to write DLL to process memory. Error code: {error_code}")
# Получить адрес функции CreateThread в ядре
kernel32 = ctypes.windll.LoadLibrary(ctypes.util.find_library("kernel32"))
create_thread_address = kernel32.GetProcAddress(kernel32._handle, b"CreateThread")
# Создать удаленный поток для загрузки DLL
thread_handle = ctypes.windll.kernel32.CreateRemoteThread(process_handle, None, 0, create_thread_address, dll_address, 0, None)
if thread_handle == 0:
error_code = ctypes.get_last_error()
raise Exception(f"Failed to create remote thread. Error code: {error_code}")
# Дождаться завершения удаленного потока
ctypes.windll.kernel32.WaitForSingleObject(thread_handle, -1)
# Закрыть дескрипторы
ctypes.windll.kernel32.CloseHandle(process_handle)
ctypes.windll.kernel32.CloseHandle(thread_handle)
if name == "main":
print("Running Steam...")
run_steam()
print("Waiting for Steam to launch...")
time.sleep(5) # Wait for 5 seconds
root = tk.Tk()
root.withdraw() # Hide the main window
user_confirmation = tkMessageBox.askokcancel("Confirmation", "Click OK when Steam is fully launched.", icon='info', parent=root)
if user_confirmation:
print("Launching Counter-Strike 2...")
cs2_process_id = run_counter_strike_2()
if cs2_process_id:
print("Counter-Strike 2 PID:", cs2_process_id)
# Инжектировать DLL
dll_path = "C:\\Users\\Nikita\\Downloads\\memordial.dll"
inject_dll(cs2_process_id, dll_path)
else:
print("User cancelled.")
Вложения
-
139.4 KB Просмотры: 32
Последнее редактирование: