diff options
author | Nicholas Tay <nick@windblume.net> | 2023-10-23 21:34:30 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2023-10-23 21:36:14 +1100 |
commit | cd646947074a1793d2d9d7ba556853f92be0bab2 (patch) | |
tree | 6893288dff3b161c0de2db8be4ab7d786123d4d7 | |
parent | 28dfc3448c1eb127834d26b308a0b2e985be79c8 (diff) | |
download | pasmgen-cd646947074a1793d2d9d7ba556853f92be0bab2.tar.gz pasmgen-cd646947074a1793d2d9d7ba556853f92be0bab2.tar.bz2 pasmgen-cd646947074a1793d2d9d7ba556853f92be0bab2.zip |
Factor non-linux parts out
Diffstat (limited to '')
-rw-r--r-- | constants.inc | 11 | ||||
-rw-r--r-- | pasmgen-linux.asm | 75 | ||||
-rw-r--r-- | pasmgen.asm | 134 | ||||
-rw-r--r-- | pasmgen.inc | 55 |
4 files changed, 141 insertions, 134 deletions
diff --git a/constants.inc b/constants.inc new file mode 100644 index 0000000..52885f8 --- /dev/null +++ b/constants.inc @@ -0,0 +1,11 @@ +usage db "usage: passmgen [<triplet#> <symbol#> <number#>]", 10 +usage_len = $ - usage + +numbers db "0123456789" +numbers_len = $ - numbers +vowels db "aeiou" +vowels_len = $ - vowels +consonants db "bcdfghjklmnpqrstvwxyz" +consonants_len = $ - consonants +symbols db "!@#$%&()-=_+[]{}\\|;<>/?." +symbols_len = $ - symbols diff --git a/pasmgen-linux.asm b/pasmgen-linux.asm new file mode 100644 index 0000000..56113e6 --- /dev/null +++ b/pasmgen-linux.asm @@ -0,0 +1,75 @@ +format ELF64 executable + +segment readable executable + +main: + ;; No arg preload case + cmp [rsp], word 1 + jne argparse + + mov r8, qword 3 + mov r9, qword 2 + mov r10, qword 3 + + jmp generate + +argparse: + ;; Check args (need 3) + cmp [rsp], word 3 + jle fail + + ;; load arg1 + mov r8, [rsp+16] + mov r8, [r8] + and r8, 0xFF + sub r8, 48 + + ;; load arg2 + mov r9, [rsp+24] + mov r9, [r9] + and r9, 0xFF + sub r9, 48 + + ;; load arg3 + mov r10, [rsp+32] + mov r10, [r10] + and r10, 0xFF + sub r10, 48 + + jmp generate + +ok: + ;; Write + mov rdi, 1 ;; stdout + mov rdx, rsi + mov rsi, out_buf + mov rax, 0x01 + syscall + + ;; Exit (code 0) + mov rdi, 0 + mov rax, 0x3c + syscall + +fail: + ;; Write + mov rdi, 1 ;; stdout + mov rsi, usage + mov rdx, usage_len + mov rax, 0x01 + syscall + + ;; Exit 1 + mov rdi, 1 + mov rax, 0x3c + syscall + + +include 'pasmgen.inc' + + +segment readable writeable + +include 'constants.inc' + +out_buf rb 64 diff --git a/pasmgen.asm b/pasmgen.asm deleted file mode 100644 index ffcce2c..0000000 --- a/pasmgen.asm +++ /dev/null @@ -1,134 +0,0 @@ -format ELF64 executable - -macro genclass class, class_len -{ - ;; Generate 16 bits (smallest) of randomness from the cpu - rdrand ax - - ;; Modulo into len range to index in - xor rdx, rdx - mov rbx, class_len - div bx - - ;; Save output letter into out_buf, bump rcx - add rdx, class - mov rdx, [rdx] - mov [rcx], rdx - inc rcx - - inc rsi -} - -segment readable executable - -entry main -main: - ;; No arg preload case - cmp [rsp], word 1 - jne argparse - - mov r8, qword 3 - mov r9, qword 2 - mov r10, qword 3 - - jmp generate - -argparse: - ;; Check args (need 3) - cmp [rsp], word 3 - jle fail - - ;; load arg1 - mov r8, [rsp+16] - mov r8, [r8] - and r8, 0xFF - sub r8, 48 - - ;; load arg2 - mov r9, [rsp+24] - mov r9, [r9] - and r9, 0xFF - sub r9, 48 - - ;; load arg3 - mov r10, [rsp+32] - mov r10, [r10] - and r10, 0xFF - sub r10, 48 - -generate: - ;; Store which output byte we're up to in rcx - mov rcx, out_buf - ;; Store chars generated in rsi - xor rsi, rsi - -tripleter: - genclass consonants, consonants_len - genclass vowels, vowels_len - genclass consonants, consonants_len - dec r8 - test r8, r8 - jnz tripleter -symboler: - genclass symbols, symbols_len - dec r9 - test r9, r9 - jnz symboler -numberer: - genclass numbers, numbers_len - dec r10 - test r10, r10 - jnz numberer - - ;; Append new line to string - mov [rcx], word 10 - inc rsi - - ;; Special case to caps the first character - xor rax, rax - mov al, byte [out_buf] - sub al, 32 - mov rbx, out_buf - mov [rbx], al - - ;; Write - mov rdi, 1 ;; stdout - mov rdx, rsi - mov rsi, out_buf - mov rax, 0x01 - syscall - - ;; Exit (code 0) - mov rdi, 0 - mov rax, 0x3c - syscall - -fail: - ;; Write - mov rdi, 1 ;; stdout - mov rsi, usage - mov rdx, usage_len - mov rax, 0x01 - syscall - - ;; Exit 1 - mov rdi, 1 - mov rax, 0x3c - syscall - - -segment readable writeable - -usage db "usage: passmgen [<triplet#> <symbol#> <number#>]", 10 -usage_len = $ - usage - -numbers db "0123456789" -numbers_len = $ - numbers -vowels db "aeiou" -vowels_len = $ - vowels -consonants db "bcdfghjklmnpqrstvwxyz" -consonants_len = $ - consonants -symbols db "!@#$%&()-=_+[]{}\\|;<>/?." -symbols_len = $ - symbols - -out_buf rb 64 diff --git a/pasmgen.inc b/pasmgen.inc new file mode 100644 index 0000000..95fadb7 --- /dev/null +++ b/pasmgen.inc @@ -0,0 +1,55 @@ +macro genclass class, class_len +{ + ;; Generate 16 bits (smallest) of randomness from the cpu + rdrand ax + + ;; Modulo into len range to index in + xor rdx, rdx + mov rbx, class_len + div bx + + ;; Save output letter into out_buf, bump rcx + add rdx, class + mov rdx, [rdx] + mov [rcx], rdx + inc rcx + + inc rsi +} + +generate: + ;; Store which output byte we're up to in rcx + mov rcx, out_buf + ;; Store chars generated in rsi + xor rsi, rsi + +tripleter: + genclass consonants, consonants_len + genclass vowels, vowels_len + genclass consonants, consonants_len + dec r8 + test r8, r8 + jnz tripleter +symboler: + genclass symbols, symbols_len + dec r9 + test r9, r9 + jnz symboler +numberer: + genclass numbers, numbers_len + dec r10 + test r10, r10 + jnz numberer + + ;; Append new line to string + mov [rcx], word 10 + inc rsi + + ;; Special case to caps the first character + xor rax, rax + mov al, byte [out_buf] + sub al, 32 + mov rbx, out_buf + mov [rbx], al + + jmp ok |