1

Problem

Suppose I have a program in x86_64 assembler yasm (see below) that requests input from a user via SYS_read system service at some moment. This output is treated as byte-number further in the program. User easely could provide all numbers corresponding to the printable ASCII symbols i.e. from 0x20 to 0x7f (maybe some more). But how to provide 0x90 for example?

Possible solution for a few characters

I could use the following combination to provide the desired number:

<C-S-u> 0 0 9 0

But this solution may be tedious when it is necessary to enter many characters.

Program fragment

Here is that part of the program that responsible for the reading from STDIN.

readChar:
    mov     rax, SYS_read
    mov     rdi, STDIN
    lea     rsi, byte [rbp - 1] 
    mov     rdx, 1
    syscall
Community
  • 1
  • 1
LRDPRDX
  • 631
  • 1
  • 11
  • 23
  • 1
    Redirect input from a file you create with a hex editor. Or with bash `printf '\x90\x91' | ./my_program`. Try stuff with `printf '\x90' | hexdump -C` to check what bytes you're printing. – Peter Cordes Mar 20 '18 at 22:22
  • This gives segmentation fault. – LRDPRDX Mar 21 '18 at 03:50
  • Then your program has a bug, and you should debug it with GDB and `strace`. See the bottom of https://stackoverflow.com/tags/x86/info. – Peter Cordes Mar 21 '18 at 03:55
  • Sending binary data over a TTY is tricky, so piping input from something else is normal. But if you really want to use a TTY, see [Write non-ASCII characters to stdin of a progam on a tty (over ssh)](https://stackoverflow.com/questions/46329447/write-non-ascii-characters-to-stdin-of-a-progam-on-a-tty-over-ssh) for workarounds that might work for you, too (e.g. prepend a `^V` before every byte of what you paste) – Peter Cordes Mar 21 '18 at 03:57
  • @PeterCordes, seems you're right about a bug. I have tried it with minimal example and it worked. – LRDPRDX Mar 21 '18 at 05:38
  • Oh, I must include the newline `\n` character at the end of string, otherwise there is an infinte loop :) – LRDPRDX Mar 21 '18 at 05:47

0 Answers0