0

hey guys im working on a project where i have to generate an executable containing the byte array of another executable, basicly my program loads a executable and stores all of the corresponding bytes in an array and then i give codedom the source of the executable im going to build and then im looping through the bytearray containing the executable and adding it to the new bytearray in the codedom source before compiling with codedom

is there an easier way to pass a bytearray from program1 to the source of program2 before compiling program2 ?

i should mention that i have split the source into 3 parts so that i could add the bytearray :S to the source string O.o

i have looked over the finished code and there's nothing wrong with it but when im compiling it with codedom i get the folloing error

Error: C\Users\*myname*\AppData\Local\Temp\ycfx9ffp.0.cs(1,246) : error CS0031: Constant value '197185' cannot be converted to a 'byte'

and i have no idea how to debug that string lol :S

this is the loop im using to add bytes to the source:

foreach(byte mybyte in stryker)
        {
            if (mybyte != stryker[stryker.Length - 1])
                part2 += mybyte + ", ";
            else
                part2 += mybyte;
        }
        string source = part1 + part2 + part3;
Paze
  • 49
  • 7
  • The error is telling you that you can't convert a Cont value to a byte sounds like you need to look in your code and change that Const variable to a non constant value.. the code below does not seem to support the errror but perhaps you should show where `stryker` is defined in your code for starters.. – MethodMan Jan 07 '13 at 19:30

2 Answers2

1

This part:

if (mybyte != stryker[stryker.Length - 1])
                part2 += mybyte + ", ";

seems to assume that the bytes in "stryker" are unique - that is, that the last value (stryker[stryker.Length - 1]) doesn't appear anywhere else.

Is that the case?

  • `197185` looks exactly like the values of two bytes that should be separated by a comma. – svick Jan 07 '13 at 20:34
  • look forget about that code i posted :P i can see the problem and the way im approching it is not possible, bassicly i need to transfer one array to the codedom executable :P get it ? my byte array(stryker) needs to be transferred to the new executable compiled by codedom :S – Paze Jan 07 '13 at 21:39
1

As 500 pointed out, your code won't work correctly if there is a byte in the byte array that is the same as the last byte, which is very likely.

Probably the easiest way to fix your code is to use a library method to combine the bytes:

part2 = string.Join(", ", stryker);

Bu having a byte array inside source code doesn't sound like a good idea to me. I think you should use embedded resources instead.

svick
  • 236,525
  • 50
  • 385
  • 514
  • well yea there are tons of bytes that is the same as the last byte in the array lol :P i really just need to compile a populated array into codedom :S is that possible ? – Paze Jan 07 '13 at 21:00