I have the C source code of a keygen to generate "Master Codes" for Dell locked BIOSes.
Tried hard, hard to understand it, and got various results after many weeks of reading and asking.
However, there are many things that I don't know how to write them in C# code, which is my goal, for adventure and academic purposes.
For example, I say unsigned char outData[16] on C
In C# I rewrote this as follows:
byte* outData = stackalloc byte[16];
By this way, the byte values stored on C# are of the same size on RAM as a unsigned char on C (based on http://bytes.com/topic/c-sharp/answers/658913-unsigned-char)
Then I can do the following in C#:
int* testPointer = (int*) outData;
*testPointer = 0x67452301;
By doing that, I've modified the positions 0, 1, 2 and 3 of outData (byte is a quarter of a int on C# (8 bits vs 32 bits), same relation as unsigned char and int on C if I'm not wrong).
All the above thing of byte outData and testPointer thing could be done by this way on C:
unsigned char outData[16];
*(int *)(&outData[0]) = 0x67452301;
And then again, positions 1, 2, 3 and 4 of outData are changed (indexes starts from 1 in this case because it's C, not C#).
So, done technically, change values of a unsigned char with a 32 bit integer pointer, ported to C#, and it technically must give same results as on C.
Now, I want to change the values of outData from a function on C# via a 32 bit int pointer, but, I won't to give it as a parameter. So, only one solution, make outData a global variable. Then comes the big trouble... if i put outData as global, it must be contained in a class or a struct if it isn't in a method (variables on methods aren't and can't be globals as long as I know).
If I do that global outData thing via struct/class (only way as per I know), outData becomes a managed data type and it moves from here to there on RAM due to the GC (GarbageCollector), and using pointers to outData becomes a bigger trouble. So, here comes the fixed statement for help to put temporarily outData on a fixed place on RAM, but also with a trouble, casting is not allowed on fixed statements, and then I can't do this: int* testPointer = (int*) outData;, where outData has another block size than testPointer and casting is needed.
Said all the previous stuff, comes the real question. How can I change the values of outData from a function on C#, via a 32 bit int pointer? OR... What algorithm can I use to make these changes to outData whitout using pointers, and supposing that outData would become a standard value type that doesn't needs unsafe contexts?
Really would love much, much more answers for second question, because the real objective that I want to accomplish is port C code to C#, and use a OO (Object Oriented) paradigm.
I'm going crazy to trying to understand a algorithm to make those changes of values stored on RAM via pointers and using different block sizes, and just have a method to do this and be pointers-free to be ready to use on C# and others OO programming languages.
Anticipated thanks for any answer!
And, for reference, here is the complete C code of the program that I wanna port:
I've done around 40% porting, those C functions going to pointers, different block sizes and that stuff has been really a pain on the %*& for weeks!