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 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.