locked
how to inject my exe into another process in c# ?

    السؤال

  • hi
    my app get an exe file and save to memory as byte[] . now i want to inject it to another exe file .
    How to do that ??
    09/جمادى الثانية/1427 12:02 م

الإجابات

  •  Hamed_1983 wrote:
    hi
    i want to get an exe file and convert it to byte[] and save it to memory . then i run another exe and inject byte[] exe to that exe file .
    thanks ..
    bye..


    I'd figure you can use a memory stream to do that.

    FileStream obj_FS = File.OpenRead("c:\\yserver.txt");
    MemoryStream obj_MS = new MemoryStream();

    while(obj_FS.Position < obj_FS.Length)
    {
    obj_MS.WriteByte(Convert.ToByte(obj_FS.ReadByte()));
    }

    byte[] obj_Byt;
    obj_Byt = obj_MS.ToArray();

    File.WriteAllBytes("c:\\test.txt", obj_Byt);

    This takes yserver.txt, copys it byte for byte, and writes the byte[] into test.txt
    :)


    Please note that Convert.ToByte may not be the fastest method, I'm kinda new at dealing with stuff liek this, and obj_FS.ReadByte() returns an integer... so I just handled it quickly.
    10/جمادى الثانية/1427 12:47 ص

جميع الردود

  • are you able to explain more about "inject it to another exe file" - how do you mean?

    do you mean you want to make multiple exe files of the same byte[]?

    09/جمادى الثانية/1427 05:25 م
  • hi
    i want to get an exe file and convert it to byte[] and save it to memory . then i run another exe and inject byte[] exe to that exe file .
    thanks ..
    bye..
    09/جمادى الثانية/1427 09:02 م
  •  Hamed_1983 wrote:
    hi
    i want to get an exe file and convert it to byte[] and save it to memory . then i run another exe and inject byte[] exe to that exe file .
    thanks ..
    bye..


    I'd figure you can use a memory stream to do that.

    FileStream obj_FS = File.OpenRead("c:\\yserver.txt");
    MemoryStream obj_MS = new MemoryStream();

    while(obj_FS.Position < obj_FS.Length)
    {
    obj_MS.WriteByte(Convert.ToByte(obj_FS.ReadByte()));
    }

    byte[] obj_Byt;
    obj_Byt = obj_MS.ToArray();

    File.WriteAllBytes("c:\\test.txt", obj_Byt);

    This takes yserver.txt, copys it byte for byte, and writes the byte[] into test.txt
    :)


    Please note that Convert.ToByte may not be the fastest method, I'm kinda new at dealing with stuff liek this, and obj_FS.ReadByte() returns an integer... so I just handled it quickly.
    10/جمادى الثانية/1427 12:47 ص