Home > Blockchain >  Cannot print NOP ('\x90') in terminal
Cannot print NOP ('\x90') in terminal

Time:11-02

I have a C program that writes a NOP character to stdout:

#include <stdio.h>

int main(char *argc, char *argv[]) {

    fwrite("\x90", 1, sizeof(char), stdout);

    return 0;
}

I also have another program that takes input, which i am runnning in gdb (so i can view the stack).

After running the first program i copy the NOP from stdout and paste it in GDB as input for the second program.

When viewing the stack i always get this value:

0x00bdbfef

When it should be

0x00000090

Why is this? The problem also seems to occur with python but i cannot pinpoint why.

CodePudding user response:

The utf-8 sequence ef bf bd (keeping in mind the byte reversal of larger data types in some architectures) is the replacement-character code point, the diamond with a question mark within.

Most likely your terminal is unable to render 90 so it gives you that instead. And, when you mark and copy that character elsewhere, that's what it is.

  • Related