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 and float [Solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
MeLLo
Advanced Cheater
Reputation: 0

Joined: 22 Oct 2005
Posts: 60

PostPosted: Wed Feb 11, 2009 7:47 am    Post subject: [Delphi] WriteProcessMemory and float [Solved] Reply with quote

I can use WriteProcessMemory, but if i try to use a float value it writes 0 as value, what should i do to write float values to the memory?

here is my code
Code:
function wpm(processo:string; data,endereco:integer; valor:real):boolean; stdcall; export;
begin
result:=false;
if GetID(processo) then
  begin
    Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
    WriteProcessMemory(Pidhandle, Pointer(endereco), @valor, Data, Written);
    closehandle(Pidhandle);
    result:=true;
  end;
end;


Thanks in advance and sory for my poor english.


Last edited by MeLLo on Thu Feb 12, 2009 8:36 am; edited 1 time in total
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Wed Feb 11, 2009 8:52 am    Post subject: Re: [Delphi] WriteProcessMemory and float Reply with quote

MeLLo wrote:
I can use WriteProcessMemory, but if i try to use a float value it writes 0 as value, what should i do to write float values to the memory?

here is my code
Code:
function wpm(processo:string; data,endereco:integer; valor:real):boolean; stdcall; export;
begin
result:=false;
if GetID(processo) then
  begin
    Pidhandle := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
    WriteProcessMemory(Pidhandle, Pointer(endereco), @valor, Data, Written);
    closehandle(Pidhandle);
    result:=true;
  end;
end;


Thanks in advance and sory for my poor english.


I dont understand this. So must be another version of delphi but....

Why is it data? it should be sizeof(valor)
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Wed Feb 11, 2009 11:00 am    Post subject: Reply with quote

Code:
Remove stdcall;
Replace Pointer with Ptr()
Check if PidHandle (no such thing) != INVALID_HANDLE_VALUE
Replace Begin/End with Try/Finally
Back to top
View user's profile Send private message
MeLLo
Advanced Cheater
Reputation: 0

Joined: 22 Oct 2005
Posts: 60

PostPosted: Wed Feb 11, 2009 1:36 pm    Post subject: Reply with quote

Justr tryed, but i had the same results, sometimes i can change the value, but it doesn't change to the value i want.

But thanks for the help, if i manage to find the problem i'll post the solution here.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Wed Feb 11, 2009 2:09 pm    Post subject: Reply with quote

Open calc, (Dec) and type the Float (in Delphi it's Extended, but i rather use Double) and convert it to Hex, then use $ with it.

leave feedback! (just a theory)

Edit: post your @Buffer source, maybe you did something wrong.
Back to top
View user's profile Send private message
MeLLo
Advanced Cheater
Reputation: 0

Joined: 22 Oct 2005
Posts: 60

PostPosted: Wed Feb 11, 2009 4:21 pm    Post subject: Reply with quote

man, i'll try the hex, but the code is ok.
i can write 4 bytes 8 bytes, 2 bytes, 1byte with no problem.

may i ask u a favor? could u try to use writeprocessmemory with a float value an see with ce if it worked.

Because its weird, i try with a float, i get 0 or a weird number. If i get an address with a float value in ce, then change the type to 4 bytes and use that value, i can change the value just fine with my code (using integer not real...)

Man... thanks for the help.
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Wed Feb 11, 2009 5:47 pm    Post subject: Reply with quote

You do know that float numbers are bigger than 4 bytes right?
Back to top
View user's profile Send private message
MeLLo
Advanced Cheater
Reputation: 0

Joined: 22 Oct 2005
Posts: 60

PostPosted: Wed Feb 11, 2009 6:49 pm    Post subject: Reply with quote

Sure do.
That's why i think it's weird... because with 4 bytes it works fine, but once i try more bytes and float a a value... i cant get the right value.
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Wed Feb 11, 2009 9:28 pm    Post subject: Reply with quote

define endereco at the top to float
Back to top
View user's profile Send private message AIM Address MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Wed Feb 11, 2009 11:43 pm    Post subject: Reply with quote

dnsi0 wrote:
You do know that float numbers are bigger than 4 bytes right?


Since when? Floats are 4 bytes in length, and doubles (which is probably what you are thinking about) are 8 bytes in length.
Back to top
View user's profile Send private message
MeLLo
Advanced Cheater
Reputation: 0

Joined: 22 Oct 2005
Posts: 60

PostPosted: Thu Feb 12, 2009 6:56 am    Post subject: Reply with quote

Just solved the problem.
It was an easy one, the fact is that delphi uses single for floats of 32 bits and double for floats of 64 bits... (so single = 4 bytes, double = 8 bytes).

So... i just had to change the real type to single.

Thanks for the help.
Back to top
View user's profile Send private message
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