Thread: writing lots of bytes

  1. #1
    Registered User
    Join Date
    Sep 2006

    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:

    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!

  2. #2
    Registered User
    Join Date
    Mar 2006
    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.

    Dude, what on earth is requiring you to write 14 MB of raw data just like that.
    #include <stdio.h>
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  3. #3
    Registered User
    Join Date
    Sep 2006
    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#]:
      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;
                if (!injected)
                    injected = true;
                    memHandler.WriteProcessMemory(0x40034C, hexToBytes("A344034000A14803400089900006400083F850740583C004EB05B800000000A348034000A144034000891A8942046A0051897208E97FDF1500"));
                    memHandler.WriteProcessMemory(0x55E2F9, hexToBytes("E94E20EAFF909090909090"));
    How would I do something similar in C++

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    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.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  2. reading a file into a block
    By mickey0 in forum C++ Programming
    Replies: 19
    Last Post: 05-03-2008, 05:53 AM
  3. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  4. Rendering 32-bit images - alpha is ignored
    By ulillillia in forum Windows Programming
    Replies: 59
    Last Post: 04-21-2007, 03:50 PM
  5. No. of bytes?
    By jnwk888hwq in forum C Programming
    Replies: 14
    Last Post: 11-08-2003, 02:00 PM