flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution
Quote: char * fgets ( char * str, int num, FILE * stream ); |
|||
![]() |
|
sandman_1
Thanks for your reply but could you elaborate more?
I know how to use fgets and it should return the same address to where it wrote to on success, which it does per check Ollydbg. Am I overlooking something? |
|||
![]() |
|
revolution
Quote: ... until (num-1) characters have been read or either a newline or a the End-of-File is reached ... |
|||
![]() |
|
sandman_1
Thanks for pointing that out. It makes sense now why it doesn't work. When the program is ran, the output shows the cursor a couple of lines below where it should be like there are a couple of returns and then a linefeed. Anyway, I will check it out.
|
|||
![]() |
|
sandman_1
Ok got it to work with fgetc.
Code: mov esi, [memalloc] write_char: cinvoke fgetc, [fileopen] cmp eax, -1 je done mov byte [esi], al inc esi jmp write_char done: mov byte [esi], 0 I am still baffled about the whole file still being printed in memory with the old code. It as if fgets loaded the whole file in a buffer for some reason and then worked on it, weird. Anyone want to add anything like a better way to do this besides using fgetc and a loop? Suggestions? |
|||
![]() |
|
revolution
sandman_1 wrote: I am still baffled about the whole file still being printed in memory with the old code. It as if fgets loaded the whole file in a buffer for some reason and then worked on it, weird. In general, you should not be accessing buffers from other code unless you like to get all sorts of strange errors and/or crashes when msvcrt.dll next changes. It is also not guaranteed that the memory block msvcrt.dll allocates will always be directly after your block, don't rely on such behaviour. sandman_1 wrote: Anyone want to add anything like a better way to do this besides using fgetc and a loop? Suggestions? Quote: size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); |
|||
![]() |
|
sandman_1
Thanks for the info. I will heed your advice.
Good idea! I will try using that instead in my code, thank you. |
|||
![]() |
|
sandman_1
Fread worked like a charm but the setup code to use it is about the same as the loop I made. But there is only one function call so it is more efficient compared to several fgetc's. Thanks again for your suggestion...
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.