Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Delphi - WriteProcessMemory failed

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
FalkonZenX
How do I cheat?
Reputation: 0

Joined: 31 Mar 2007
Posts: 7
Location: Brasil

PostPosted: Sat Mar 05, 2011 3:44 pm    Post subject: Delphi - WriteProcessMemory failed Reply with quote

I using D7 code.

Code:

if (WriteProcessMemory(ProcessHandle, Ptr($00487340), @EnablingBytes, 1, NumberOfBytesWritten)) then
    begin
     Status := 'The memory was successfully modified.';
    end
   else
    begin
     Status := 'WriteProcessMemory failed.';
    end;
   CloseHandle(ProcessHandle);
   ShowMessage(Status);


Result:
WriteProcessMemory failed.


How to leave the editable memory?
Back to top
View user's profile Send private message MSN Messenger
Xblade Of Heaven
Master Cheater
Reputation: 0

Joined: 16 Oct 2005
Posts: 395
Location: DEAD

PostPosted: Sat Mar 05, 2011 3:57 pm    Post subject: Reply with quote

setdebugprivilege and VirtualProtectEx need for write in memory.

regards

_________________
Welcome to the Hell.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
FalkonZenX
How do I cheat?
Reputation: 0

Joined: 31 Mar 2007
Posts: 7
Location: Brasil

PostPosted: Sat Mar 05, 2011 5:05 pm    Post subject: Reply with quote

Setdebugprivilege = ok

For VirtualProtectEx
I am using


Code:
function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: thandle;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'Title Aplication');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_VM_WRITE, False, ProcessId);
  VirtualQueryEx(HandleWindow, @Address, mbi, 1);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if EditMemory($00487340,$90) = false then
...



Not Work Crying or Very sad
Back to top
View user's profile Send private message MSN Messenger
Krähne
Expert Cheater
Reputation: 0

Joined: 06 Jun 2010
Posts: 108
Location: Inside of my Kernel

PostPosted: Sun Mar 06, 2011 12:45 am    Post subject: Reply with quote

Try this:

In var declarations, declare this (lol):

Code:
Written: Cardinal;
PidHandle: integer;
PidID: integer;
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
Temp: Integer;
ProcessId: DWORD;
HandleWindow: THandle;
ThreadID: Cardinal;


Use this function for get the process id.
Code:
Function GetProcessID(Const ExeFileName: string; var ProcessId: integer;Const ProcessNo :Integer = 1): boolean;
begin
result := false;
temp:=1;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
 while integer(ContinueLoop) <> 0 do
  begin
   if (StrIComp(PChar(ExtractFileName(FProcessEntry32.szExeFile)), PChar(ExeFileName)) = 0)
     or (StrIComp(FProcessEntry32.szExeFile, PChar(ExeFileName)) = 0)  then
      begin
       If Temp = ProcessNo then
        begin
        ProcessId:= FProcessEntry32.th32ProcessID;
        result := true;
        break;
       end else inc(Temp);
      end;
     ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    end;
  CloseHandle(FSnapshotHandle);
end;


And use this for write the process memory.
Code:
Function WriteByte(Address: Cardinal; ChangeValues: Byte) : boolean;
Begin
Result := false;
 if GetProcessID('ProcessGame.extension', PidID, 1) = true then
  Begin
    PidHandle:= OpenProcess(PROCESS_ALL_ACCESS,False,PidId);
    Result := WriteProcessMemory(PidHandle, Pointer(Address), @ChangeValues, SizeOf(ChangeValues), Written);
    Closehandle(PidHandle);
  End;
End;


Finally... test it:
Code:
procedure TForm1.Button4Click(Sender: TObject);
begin
  if WriteByte($00487340,$90) = false then
     ShowMessage('WriteMemory Failed :(')
  else
     ShowMessage('WriteMemory sucess! :D');
end;


Hope this helps.
Gruß.
Back to top
View user's profile Send private message MSN Messenger
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sun Mar 06, 2011 1:32 pm    Post subject: Reply with quote

You shouldn't be making multiple threads for the same issue.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25778
Location: The netherlands

PostPosted: Sun Mar 06, 2011 2:19 pm    Post subject: Reply with quote

instead of
Code:

  VirtualQueryEx(HandleWindow, @Address, mbi, 1);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);

do

Code:

  VirtualProtectEx(HandleWindow, pointer(address), 4, PAGE_EXECUTE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, pointer(Address), @Value, 4, Write);
  VirtualProtectEx(HandleWindow, pointer(address), 4, oldprotect, @oldprotect);

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites