I have an executable, created in Assembly language and compiled with NASM.
Is there a way to get the value, in hexadecimal, of the bytes produced by the compiler, so that I can use them in a disassembler (ie discover the generated OP codes)?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE *file;
char *buffer;
unsigned long fileLen;
file = fopen( "teste.o", "rb");
if (!file) {
printf("erro\n");
}
fseek(file, 0, SEEK_END);
fileLen=ftell(file);
fseek(file, 0, SEEK_SET);
buffer=(char *)malloc(fileLen+1);
if (!buffer) {
fprintf(stderr, "Memory error!");
fclose(file);
return 0;
}
fread(buffer, fileLen, 1, file);
fclose(file);
for (unsigned int c=0;c<fileLen;c++) {
printf("%.2hhx ", buffer[c]);
if (c % 4 == 3) {
printf(" ");
}
if (c % 16 == 15) {
printf("\n");
}
}
printf("\n");
free(buffer);
}