flat assembler
Message board for the users of flat assembler.
Index
> Linux > 1st program, random password generator |
Author |
|
revolution 05 Feb 2024, 16:15
The code is fine.
I would recommend is to use lea for the addresses. Code: lea rdi, [filename] |
|||
05 Feb 2024, 16:15 |
|
redsock 06 Feb 2024, 21:09
Well done re: 32 bit register usage.
On all of my x86_64 Linux distributions, your code and data segments will always start well inside 32 bit space so where you have things like Code: mov rdi, filename Code: lea rdi, [filename] Code: mov edi, filename lea edi, [filename] Also, starting with Linux kernel version 3.17 (released 2014-10-05) there is the getrandom syscall which would simplify some of your program. In <asm/unistd_64.h> this is syscall number 318. Cheers |
|||
06 Feb 2024, 21:09 |
|
Feryno 08 Feb 2024, 04:43
Well done, nice and clean code! Use the LEA for addresses as guys already suggested you. IIRC before checking input args you can add something like this just after the _start:
Code: _start: mov ecx,[rsp+8*0] ; argc count of input arguments if ecx = 1 then there is only a pointer to your executable (qword [rsp+8*1]), this is useful for obtaining path and executable name, to check whether it was executed using your filename or whether executing using some symbolic link which has different name and path if ecx = 2 them there is the pointer to your executable (qword [rsp + 8*1]) and the first arg (qword [rsp+8*2]) and so on... you can check args only upto qword [rsp + rcx*8], do not touch anything higher in the rsp using the qword [rsp+8*x] formula as there could be something else (you can grab bogus or ascii string instead of pointer) or there could be no stack anymore and accessing not present memory may cause pagefault... this is just a habit for a good practice the stack on executable entrypoint looks like this: [rsp+8*0]=N argc, N is at least 1 everytime because argv0 [rsp+8*1] argv1 the name of the executable [rsp+8*2] argv2 1st param after executable (if any) [rsp+8*3] argv3 2nd param after executable (if any) ... [rsp+8*N] argvN Nth param after executable qword [rsp+8*(N+1)]=0 end of argv [rsp+8*(N+2)] envp environment ... qword [rsp+8*(...)]=0 end of envp |
|||
08 Feb 2024, 04:43 |
|
user71 20 May 2024, 17:06
2nd program, deltree
I wanted to make a useful program as an exercise.
|
|||||||||||
20 May 2024, 17:06 |
|
user71 31 Dec 2024, 20:49
This simple program adds or removes the UTF-8 byte order mark.
|
|||||||||||
31 Dec 2024, 20:49 |
|
macomics 31 Dec 2024, 21:12
Code: macro writeznl string*, stream* { ;FIND LENGTH local .newline;, .again, .length mov rsi, string ; mov rsi, string cmp byte [rsi], 0 ; cmp byte [rdi], 0 jz .newline call strlen ; lea rdx, [rsi - 1] ; mov rdx, rdi ;.again: ; inc rdx ; cmp byte [rdx], 0 ; jnz .again ; jz .length ; inc rdx ; jmp .again ;.length: ;PRINT STRING ; mov eax, 1 ;write syscall sub rdx, rsi ;length sub rdx, rdi ;length ; mov rsi, rdi ;address of string ; mov eax, 1 ;write syscall mov edi, stream ;fd 1 is stdout, 2 is stderr ; mov eax, 1 ;write syscall ; syscall call sc_write ;ADD A NEWLINE: .newline: mov edi, stream ;fd 1 is stdout, 2 is stderr call newline } strlen: ; in rsi = string, out rdx = "&string[index] === 0" lea rdx, [rsi - 1] ; mov rdx, rdi @@: inc rdx cmp byte [rdx], 0 jnz @b ; jz .length retn sc_write: ; in edx = length, rsi = string, edi = stream; out eax = result mov eax, 1 ;write syscall syscall retn newline: ; in edi = stream; dirty {rdx, rsi}; out eax = result ; mov di, 10 ; push rdi push 1 pop rdx ; mov edx, 1 ;length lea rsi, [@f] ; mov rsi, rsp ;address ; mov edi, edx ; mov edi, 1 ;stdout ; mov eax, edx ; mov eax, 1 ;write syscall ; syscall ; pop rdi ; add rsp, 2 call sc_write retn @@: db 10 |
|||
31 Dec 2024, 21:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.