Solved

Type Conversions

Posted on 2003-10-22
5
251 Views
Last Modified: 2010-04-05
Ok Im Rather New To Delphi So I Ask Of Your Help.

Im Trying To Log Functions Parameters To File By Hooking It, But i aint too sure how to format pointers and hex data into a string.


Heres the function  def...
 
HANDLE hProcess,  // handle to process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // pointer to buffer to write data to
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten  // actual number of bytes written

handle = cardinal?
dword = cardinal?
lpvoid = pointer?
lpdword = pdword?

 
i tried..

FmtStr(TheParams,'%d, %.x, %.x, %d, %d', [hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten]);

but still crashes :/




Thanks.
0
Comment
Question by:JuleZzZ
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9604193
handle = THandle
dword = DWord
lpvoid = pointer
lpdword = Pointer

 
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 9604242
Almost correct.
LPDWORD = PDWORD
Most of these pointer types are declared in Windows.pas
0
 

Author Comment

by:JuleZzZ
ID: 9604266
ok got it workin... changed pointer to cardinal.. :E

np
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 500 total points
ID: 9604583
That is not a good idea. Stay with pointer types where pointer types are expected.
Better typecast in your FmtStr

FmtStr(TheParams,'%d, %.x, %.x, %d, %d', [DWORD(hProcess), DWORD(lpBaseAddress), DWORD(lpBuffer), nSize, lpNumberOfBytesWritten]);

Aha. I see another bug. Most probably the source of your crash.
lpNumberOfBytesWritten is in C a pointer to a variable where the write call stores the number of bytes written.
The correct conversion for the write function is therefore
"var NumberOfBytesWritten: Cardinal"
You can stay with your conversion, but then you have to call it like this:

var
  NumberOfBytesWritten: DWORD;
begin
  write( ... , @NumberOfBytesWritten);
0
 

Author Comment

by:JuleZzZ
ID: 9611454
nice one. explained just about everything i needed to know


Thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question