0
I have an executable, created in Assembly language and compiled with NASM.
There is a way to obtain the value, in hexadecimal, of the bytes produced by the compiler, so that I can use them in a disassembler (ie, discover the OP codes generated)?
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);
}
						
try to better expose what you want, you have to be more specific, show what you’ve done in terms of code. " I need the code" is not a good way to start, here we help you solve problems you have to implement. See how to ask at help center
– Jorge B.
#include <stdio. h> #include <stdlib. h> #include <string. h> int main() { FILE *file; char *buffer; unsigned long fileLen; file = fopen( "test. o", "Rb"); if (!file) { printf("error 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);
– Erick
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); }
– Erick
this the code until the moment, it was in a bad format but I think that when passing to an editor will be more visible.
– Erick
I already edited your question and put the code there.
– Jorge B.