You are not logged in.
Pages: 1
Прога должна писать данные в память потока по заданному смещению, а вместо этого выдаёт "Access violation at address...". Что тут не так?
procedure TForm1.Button2Click(Sender: TObject);
var
PID: LongInt;
MAddr: LongInt;
const
Offset = 1578;
begin
PID := GetPID('gta_sa.exe');
if PID = 0 then
MessageBox(handle,pchar('Игра не запущена.'),pchar('Ошибка!'),16)
else
begin
MAddr := ReadMemoryInt($A8B42C, PID);
While MAddr <> 0 do
if ReadMemoryString(MAddr + 8, PID) = 'CRSPEED' then
begin
MAddr := ReadMemoryInt(MAddr + 16, PID);
inc(MAddr, Offset);
WriteMemoryByte(MAddr, 255, PID);
Exit;
end;
MAddr := ReadMemoryInt(MAddr, PID);
end;
MessageBox(handle,pchar('Поток CRSPEED не найден.'),pchar('Ошибка!'),16);
end;
end;
function GetPID(name: string): LongInt;
var
hSnapshot: THandle;
lppe: TProcessEntry32;
begin
Result := 0;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if hSnapshot = 0 then
exit;
lppe.dwSize := SizeOf(TProcessEntry32);
if Process32First(hSnapshot,lppe) then
repeat
if name = ExtractFileName(lppe.szExeFile) then
begin
Result := lppe.th32ProcessID;
break;
end;
until not Process32Next(hSnapshot,lppe);
CloseHandle(hSnapshot);
end;
function ReadMemoryInt(MainAddress, IDAgent: LongInt): LongInt;
var HandleWindow : LongInt;
ipBase: Pointer;
IpBuf: LongInt;
numberRead: DWORD;
begin
HandleWindow:=OpenProcess(PROCESS_VM_READ,False,IDAgent);
ipBase:=ptr(MainAddress);
ReadProcessMemory(HandleWindow, ipBase, Addr(ipbuf), 4, numberRead);
CloseHandle(HandleWindow);
Result := ipbuf;
end;
function ReadMemoryString(MainAddress, IDAgent: LongInt): PChar;
var HandleWindow : LongInt;
ipBase: Pointer;
IpBuf: PChar;
numberRead: DWORD;
begin
HandleWindow:=OpenProcess(PROCESS_VM_READ,False,IDAgent);
ipBase:=ptr(MainAddress);
ReadProcessMemory(HandleWindow, ipBase, Addr(ipbuf), 8, numberRead);
CloseHandle(HandleWindow);
Result := ipbuf;
end;
procedure WriteMemoryByte(MainAddress: LongInt; ipBuf: Byte ;IDAgent: LongInt);
var HandleWindow : LongInt;
ipBase: Pointer;
numberWrite: DWORD;
begin
HandleWindow:=OpenProcess(PROCESS_ALL_ACCESS,False,IDAgent);
ipBase:=ptr(MainAddress);
WriteProcessMemory(HandleWindow, ipBase, Addr(ipbuf), ipBuf, numberWrite);
CloseHandle(HandleWindow);
end;
Offline
Запусти свое приложение в режиме отладки, сделай трассировку (пошаговое исполнение команд) и узнай, на какой строчке происходит вылет.
Offline
@CraZZZy-GameRRR - перебирает все активные потоки:
procedure TForm1.Button1Click(Sender: TObject);
var
ProcessId, Process, BytesRead: Cardinal;
ActiveThread: Cardinal;
ThreadName: array [0..7] of AnsiChar;
begin
// ProcessId := StrToInt(Edit1.Text);
Process := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId);
if Process <> 0 then
begin
ReadProcessMemory(Process, Ptr($A8B42C), @ActiveThread, 4, BytesRead);
while ActiveThread <> 0 do
begin
ReadProcessMemory(Process, Ptr(ActiveThread + 8), @ThreadName, 8, BytesRead);
if ThreadName = 'bloodr' then
ShowMessage(IntToHex(ActiveThread, 8));
// Memo1.Lines.Add(ThreadName);
ReadProcessMemory(Process, Ptr(ActiveThread), @ActiveThread, 4, BytesRead);
end;
CloseHandle(Process);
end;
end;
Last edited by Sanchez (29-04-2010 09:44)
Offline
Sanchez, спасибо тебе большое!
Кстати, твой исходник намного компактней моего получился.
Offline
Интересно, тут кто-нибудь пишет на Си++, а то везде, куда ни глянь - Delphi...
Last edited by ~AquaZ~ (29-04-2010 11:27)
Offline
Pages: 1