-
writing lots of bytes
I need to writeprocessmemory ALOT of bytes. I'm talking around 14 megs worth. What is the best way of doing this?
I know the typical way, like this:
Code:
BYTE whatever[4] = {0x62, 0x62, 0x62, 0x62};
WriteProcessMemory(hand,(void*)0x40404040, &whatever,4, &bytes);
No way am I going through a trillion bytes and adding 0x to each one, haha. I've googled but no luck. I have all the bytes I need, I can just copy and paste them. Any help would be appreciated! Thanks!
-
Put them into a file and extract them at runtime?
Or you can write a script, or even another program, to add the 0xen for you. :rolleyes:
Dude, what on earth is requiring you to write 14 MB of raw data just like that.
-
Don't ask lol, it's a long story. I should make a program do that for me, that would be a challenge. Plus, I'd have to figure out how many bytes it is exactly. But I rather find a way to do something like this[c#]:
Code:
public static byte[] hexToBytes(string hexString)
{
if (hexString.StartsWith("0x"))
hexString = hexString.Substring(2);
hexString = System.Text.RegularExpressions.Regex.Replace(hexString, "[^a-fA-F0-9]", "");
if (hexString.Length % 2 != 0)
hexString = hexString.Substring(0, hexString.Length - 1);
int length = hexString.Length / 2;
byte[] buf = new byte[length];
for (int i = 0; i < length; i++)
buf[i] = byte.Parse(hexString.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
return buf;
}
Code:
if (!injected)
{
injected = true;
memHandler.WriteProcessMemory(0x40034C, hexToBytes("A344034000A14803400089900006400083F850740583C004EB05B800000000A348034000A144034000891A8942046A0051897208E97FDF1500"));
memHandler.WriteProcessMemory(0x55E2F9, hexToBytes("E94E20EAFF909090909090"));
}
How would I do something similar in C++
-
Pretty much the same way, but it's still absurd. Create a file on disk that contains the binary data you want to write, then read it in in chunks and write it to the other process. It's faaaar superior than any solution using hardcoded values in any form.