flat assembler
Message board for the users of flat assembler.

Index > Linux > [solved] print to STDOUT acts strangely.

Author
Thread Post new topic Reply to topic
ntos



Joined: 06 Jul 2023
Posts: 18
ntos 23 Jul 2023, 13:48
Hi,
Here is the code:
Code:
 format ELF64 executable 3

segment readable executable
entry main
main:
    ;write your code here
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    xor rdx, rdx
    mov rdx, var2
    syscall
    
    mov rdi, 0
    mov rax, 60
    syscall   
    
segment readable writable
msg db 'hello world!', 10, 0
var2 dw 2

    


AFAIK rdx contains the length of the string, but I loaded it with var2 and the code still produced the correct string hello world!. Why?
Post 23 Jul 2023, 13:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20571
Location: In your JS exploiting you and your system
revolution 23 Jul 2023, 14:28
RDX contains the address of var2, so it might be 0x4010ef or similar.

Try this;
Code:
;...
    mov rdx, var2 - msg
    syscall    
Post 23 Jul 2023, 14:28
View user's profile Send private message Visit poster's website Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 23 Jul 2023, 15:37
By the way, can I ask a related question? Can I use exit_group syscall next time instead of exit syscall, since :

https://man7.org/linux/man-pages/man2/exit_group.2.html wrote:
Since glibc 2.3, this is the system call invoked when the
_exit(2) wrapper function is called.


I saw @revolution used exit_group in his programs.
Post 23 Jul 2023, 15:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20571
Location: In your JS exploiting you and your system
revolution 23 Jul 2023, 15:46
I recommend to always use exit_group unless you really know what you are doing and actually want the obscure non-exiting behaviour of exit.
Post 23 Jul 2023, 15:46
View user's profile Send private message Visit poster's website Reply with quote
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 23 Jul 2023, 15:52
revolution wrote:
I recommend to always use exit_group unless you really know what you are doing and actually want the obscure non-exiting behaviour of exit.


Thanks for the recommendation.
Post 23 Jul 2023, 15:52
View user's profile Send private message Reply with quote
ntos



Joined: 06 Jul 2023
Posts: 18
ntos 23 Jul 2023, 22:07
revolution wrote:
RDX contains the address of var2, so it might be 0x4010ef or similar.

Try this;
Code:
;...
    mov rdx, var2 - msg
    syscall    


thanks. Very Happy
Post 23 Jul 2023, 22:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.