FerrisBuellerYourMyHero Master Cheater
Reputation: 0
Joined: 14 Feb 2007 Posts: 401 Location: Inside your <kernel>
|
Posted: Mon Jan 12, 2009 1:13 pm Post subject: |
|
|
I do a similar thing as tombana wrote. Except I don't embed it as a resource and just as binary. I just use hex workshop because it already does it. But you could even write your own application that does it. Basically you select all the bytes and goto copy as-> C Source
it will give you an unsigned char array like this:
| Code: |
// Generated by BreakPoint Software's Hex Workshop v4.20
// http://www.hexworkshop.com
// http://www.bpsoft.com
//
// Source File: SomeDll.dll
// Time: 1/12/2009 1:00 PM
// Orig. Offset: 0 / 0x00000000
// Length: 156160 / 0x00026200 (bytes)
unsigned char rawData[156160] =
{
0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} ;
|
That isn't the whole thing I had to cut most if it out because its so big it wouldn't let me post it. But you can just copy that unsigned char array into your application and that binary will be embedded in the final executable. You can then just dump it to a file and call loadlibrary. (if its a dll) That's exactly what I did with my directx trainer, embed the .png images like that and you call D3DXCreateTextureFromFileInMemory()
| Code: |
FILE* f = fopen("SomeDll.dll", "wb");
fwrite(rawData, sizeof(rawData), 1, f);
fclose(f);
|
Its a good way to not be dependent on a dll or something being in the same folder as your application. Just recreate it as necessary.
I think my hex workshop trial is about to expire, so I quickly whipped up a freeware app that creates the unsigned char arrays from a binary file
| Code: |
#include <windows.h>
#include <stdio.h>
void CreateArray();
FILE* f = 0;
char* buff = 0;
char* filebuff = 0;
long filesize = 0;
int main()
{
SetConsoleTitleA("Binary Binder Array Maker");
buff = new char[260];
printf("Type the path to the file: ");
gets(buff);
f = fopen(buff, "rb");
if(!f)
{
printf("File path not valid!");
Sleep(3000);
return 0;
}
fseek(f, 0, SEEK_END);
filesize = ftell(f);
rewind(f);
filebuff = new char[filesize];
fread(filebuff, filesize, 1, f);
CreateArray();
printf("\n\nSuccessfully generated binary array!\nYou can now embed it in your application.");
Sleep(3000);
delete[] buff;
delete[] filebuff;
return 1;
}
void CreateArray()
{
BYTE x = 0, z = 0;
FILE* f2 = fopen("GeneratedArray.txt", "wb");
fwrite("// FerrisSoft\r\n", 15, 1, f2);
fwrite("// Source File: ", 16, 1, f2);
fwrite(buff, strlen(buff), 1, f2);
fwrite("\r\n", 2, 1, f2);
sprintf(buff, "// Size: %u bytes / 0x%p\r\n//<--\r\n", filesize, filesize);
fwrite(buff, strlen(buff), 1, f2);
sprintf(buff, "unsigned char BinaryData[%u] = \r\n{\r\n\t", filesize);
fwrite(buff, strlen(buff), 1, f2);
for(long i = 0; i < filesize; i++)
{
x = filebuff[i];
if(z == 16)
{
fwrite("\r\n\t", 3, 1, f2);
z = 0;
}
if(i == (filesize - 1))
{
sprintf(buff, "0x%02X\r\n};\r\n//-->", x);
fwrite(buff, strlen(buff), 1, f2);
}
else
{
sprintf(buff, "0x%02X, ", x);
fwrite(buff, strlen(buff), 1, f2);
}
z++;
}
}
|
As you can see it doesn't really take much to do it. To format it for use with other languages besides c/c++ would be pretty simple too, but I only have use for this in c.
_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!
 |
|