From bd739d7205b51381dd17a3fc7fedcc4b40a598c3 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 1 Sep 2021 14:58:37 -0400 Subject: [PATCH] finished 01, now just need to write readme --- 00/README.md | 15 +- 00/hexcompile | Bin 632 -> 632 bytes 01/in00 | 390 ++++++++++++++++++++++---------------------- 01/in01 | 13 +- 01/instructions.txt | 63 +++++++ instructions.txt | 12 +- 6 files changed, 283 insertions(+), 210 deletions(-) create mode 100644 01/instructions.txt diff --git a/00/README.md b/00/README.md index 3be7e5c..25dc1ae 100644 --- a/00/README.md +++ b/00/README.md @@ -25,7 +25,7 @@ it even smaller if you wanted to. Let's take a look at what's inside (`od -t x1 00 10 00 00 00 00 00 00 48 b8 6d 02 40 00 00 00 00 00 48 89 c7 31 c0 48 89 c6 48 b8 02 00 00 00 00 00 00 00 0f 05 48 b8 72 02 40 00 00 00 00 00 -48 89 c7 48 b8 41 00 00 00 00 00 00 00 48 89 c6 +48 89 c7 48 b8 41 02 00 00 00 00 00 00 48 89 c6 48 b8 ed 01 00 00 00 00 00 00 48 89 c2 48 b8 02 00 00 00 00 00 00 00 0f 05 48 b8 03 00 00 00 00 00 00 00 48 89 c7 48 89 c2 48 b8 6a 02 40 00 00 @@ -179,18 +179,19 @@ Now we open our output file: - `48 b8 72 02 40 00 00 00 00 00` `mov rax, 0x400272` - `48 89 c7` `mov rdi, rax` -- `48 b8 41 00 00 00 00 00 00 00` `mov rax, 0x41` +- `48 b8 41 02 00 00 00 00 00 00` `mov rax, 0x41` - `48 89 c6` `mov rsi, rax` - `48 b8 ed 01 00 00 00 00 00 00` `mov rax, 0o755` - `48 89 c2` `mov rdx, rax` - `48 b8 02 00 00 00 00 00 00 00` `mov rax, 2` - `0f 05` `syscall` -In C, this is `open("out00", O_WRONLY|O_CREAT, 0755)`. This is quite similar -to our first call, with two important differences: first, we specify `0x41` as -the second argument. This tells Linux that we are writing to the file -(`O_WRONLY = 0x01`), and that we want to create it if it doesn't exist -(`O_CREAT = 0x40`). Secondly, we are setting the third argument this time. It +In C, this is `open("out00", O_WRONLY|O_CREAT|O_TRUNC, 0755)`. This is quite +similar to our first call, with two important differences: first, we specify +`0x241` as the second argument. This tells Linux that we are writing to the +file (`O_WRONLY = 0x01`), that we want to create it if it doesn't exist +(`O_CREAT = 0x40`), and that we want to delete any previous contents it had +(`O_TRUNC = 0x200`). Secondly, we are setting the third argument this time. It specifies the permissions our file is created with (`0o755` means user read/write/execute, group/other read/execute). This is not very important to the actual execution of the program, so don't worry if you don't know what it diff --git a/00/hexcompile b/00/hexcompile index 6aeed4881152dc07d3db083ec7fd26ba564744a7..f4c575e39394a3043809d98057c402ff4c326de6 100755 GIT binary patch delta 12 Ucmeyt@`GiC - shr rax, cl +>I - shr rax, imm8 +]C - sar rax, cl +]I - sar rax, imm8 +-S - sub rsp, imm32 +cm - cmp rax, rbx +te - test rax, rax +jm - jmp rel32 +je - je rel32 +jn - jne rel32 +jl - jl rel32 +jb - jb rel32 +ja - ja rel32 +cl - call rax +re - ret +sy - syscall diff --git a/instructions.txt b/instructions.txt index ca2fc0e..cc997b6 100644 --- a/instructions.txt +++ b/instructions.txt @@ -21,10 +21,6 @@ mov r10, rax (for syscalls) >49 89 c2 xchg rax, rbx >48 93 -mov qword [rsp], rax ->48 89 04 24 -mov rax, qword [rsp] ->48 8b 04 24 mov qword [rbx], rax >48 89 03 mov rax, qword [rbx] @@ -41,6 +37,10 @@ mov byte [rbx], al >88 03 mov al, byte [rbx] >8a 03 +mov qword [rsp], rax +>48 89 04 24 +mov rax, qword [rsp] +>48 8b 04 24 neg rax >48 f7 d8 add rax, rbx @@ -89,10 +89,10 @@ jl rel32 >0f 8c REL32 jg rel32 >0f 8f REL32 -ja rel32 ->0f 87 REL32 jb rel32 >0f 82 REL32 +ja rel32 +>0f 87 REL32 call rax >ff d0 ret