Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Assembly 

Intel x86 NASM Using fgets

So I have a piece of code and I'm attempting to scan in a string with a call to fgets. It's not reading anything in and the return value is NULL. May someone tell me how I could check my error value or teach me how I should approach this?

My code goes something like this:

Code
...
push DWORD  0x0      ; STDIN is 0
push BYTE   0xA      ; Max size is 10
push DWORD  buf      ; load address of buffer for input
call _fgets
add  esp    0xC      ; reset stack pointer
cmp  eax,   0x0      ; check return value in eax
jz   err      ; jump to error address if NULL
...
char fgets ( char str, int num, FILE * stream ); http://www.cplusplus.com/reference/cstdio/fgets
push stream
push num
push str
call fgets
STDIN is not 0, STDIN is a maco and there is a function you can use to find the address of STDIN

Code
push eax
call ___iob_func      ; returns an array containing addresses of Files like stdio, stdout
push eax            ; STDIN is the first in the array that is returned giving it postion 0
push BYTE   0xA      ; Max size is 10
push DWORD  buf      ; load address of buffer for input
call _fgets
Shorter (but you need a modern assembler):
invoke crt_fgets, addr buffer, sizeof buffer, rv(crt___p__iob)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Assembly] by SIM-3149568May 19, 2020 03:36 AM 8 352 May 19, 2020 03:36 AM
Last Post: Jean-Jacques Rousseau
[Assembly] by RCEJan 12, 2020 08:58 AM 0 717 Jan 12, 2020 08:58 AM
Last Post: RCE
[Assembly] by friiz1337Jan 27, 2019 03:27 PM 10 560 Jan 27, 2019 03:27 PM
Last Post: friiz1337