0

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.

  • How do you *copy the NOP from stdout and paste it*? – Pablo Nov 02 '22 at 00:47
  • 1
    Aside: int main( **int** argc, char *argv[]) – Avi Berger Nov 02 '22 at 00:50
  • @Pablo I highlight the character printed to my terminal with my house and right click and click 'copy', then i right click and click 'paste' – professional pro Nov 02 '22 at 01:02
  • I don't think that NOP (which coding is that, that is beyond ascii) is a printable character so you terminal emulator might replace it with other printable characters and that's what you are copying, see paxdiablo's answer. What you should do, is execute `./your_first_program | gdb ./your_second_program` and then read from `stdin`. – Pablo Nov 02 '22 at 01:07

1 Answers1

2

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.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953