![]() |
#1 |
Senior Member
Join Date: Aug 2005
Posts: 121
|
Hex Strings and lpBuffer
When using System::Call 'Kernel32::ReadFile(i r0, i r2, i r1, *i .r3, i 0)', $2 is a lpBuffer, a pointer to the buffer that receives the data read from a file. Is it possible to pass a hexadecimal string to a buffer like $2, instead of creating a file, writing the hexadecimal string to the file, reading the file to fill the $2 buffer and erasing the file to do what I want?
|
![]() |
![]() |
![]() |
#2 |
Senior Member
Join Date: Feb 2007
Location: Rijeka, Croatia
Posts: 225
|
There may be a more elegant way than how I do it, but here's a working example:
code: PostEnd: |
![]() |
![]() |
![]() |
#3 |
Senior Member
Join Date: Aug 2005
Posts: 121
|
Thank you, I will try it
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Join Date: Aug 2005
Posts: 121
|
It works fine, but is pretty slow with big strings.
|
![]() |
![]() |
![]() |
#5 |
Senior Member
Join Date: Feb 2007
Location: Rijeka, Croatia
Posts: 225
|
Well, one System call for every byte of data, you can't expect turbo performance if you need to process more than a few KB. It's not appropriate for that. Maybe someone knows a way to fill the buffer in a single pass, I don't, apart from the one you know as well - ReadFile. I don't know what your goal is, is it patching of some sort? A FileWriteByte loop should be faster than my example, no buffer required. Vpatch would be a perfect solution, if applicable.
[Edit] Did some testing: a FileWriteByte variant turned out approx. 3x faster for the same input/output. PostEnd: Last edited by aerDNA; 2nd July 2013 at 19:09. |
![]() |
![]() |
![]() |
#6 |
Senior Member
Join Date: Feb 2007
Location: Rijeka, Croatia
Posts: 225
|
You're processing a load of 511B chunks because of maxstrlen, that's what the question about iterating through gflags in that other thread was about, right? Packing it all up in a binary file you'd extract at runtime and load with ReadFile really would be way faster and 'cleaner'.
PostEnd: |
![]() |
![]() |
![]() |
#7 |
Senior Member
Join Date: Aug 2005
Posts: 121
|
Yes, that's correct. I am now getting the data as a resource.
|
![]() |
![]() |
![]() |
#8 |
Senior Member
Join Date: Feb 2007
Location: Rijeka, Croatia
Posts: 225
|
RCData? Nice solution.
PostEnd: |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|