Réponse acceptée !
Voici quelque chose. C'est pas très propre mais ça fonctionne:
#include <io.h>
#include<stdlib.h>
int main(void)
{
FILE *rfile, *wfile;
BYTE *buffer;
char *towrite, *c, *d;
int len, count;
rfile = fopen("c:\\test.exe", "rb"); if(!rfile) return 0;
len = _lseek(rfile->_file, 0, SEEK_END); count = len;
buffer = (BYTE*)malloc(len); if(!buffer) goto exitCLOSERFILE;
towrite = (char*)malloc(len*3); if(!towrite) goto exitFREEBUFFER;
d = buffer; c = towrite;
_lseek(rfile->_file, 0, SEEK_SET);
if(fread(buffer, 1, len, rfile) != len) goto exitFREEALLBUF;
while(count > 0)
{
char tmp[9];
itoa((int)*d, tmp, 16);
if(tmp[1] == 0)
{
tmp[1] = tmp[0];
tmp[0] = '0';
}
*c = tmp[0]; *(c+1) = tmp[1];
*(c+2) = ' ';
count--; d++; c+=3;
}
wfile = fopen("c:\\test.txt", "w"); if(!wfile) goto exitFREEALLBUF;
fwrite(towrite, 1, len*3, wfile);
fclose(wfile);
exitFREEALLBUF:
free(towrite);
exitFREEBUFFER:
free(buffer);
exitCLOSERFILE:
fclose(rfile);
system("pause");
return 0;
}
C++ (@++)