add some tokens, length1 token support
This commit is contained in:
@@ -129,4 +129,27 @@ supported tokens are listed below
|
|||||||
| cr3 | 0x004C | |
|
| cr3 | 0x004C | |
|
||||||
| cr4 | 0x004D | |
|
| cr4 | 0x004D | |
|
||||||
| cr8 | 0x004E | |
|
| cr8 | 0x004E | |
|
||||||
|
| hlt | 0x004F | |
|
||||||
|
| int3 | 0x0050 | |
|
||||||
|
| [ | 0x0051 | |
|
||||||
|
| ] | 0x0052 | |
|
||||||
|
| xor | 0x0053 | |
|
||||||
|
| inc | 0x0054 | |
|
||||||
|
| dec | 0x0055 | |
|
||||||
|
| mov | 0x0056 | |
|
||||||
|
| add | 0x0057 | |
|
||||||
|
| sub | 0x0058 | |
|
||||||
|
| call | 0x0059 | |
|
||||||
|
| ret | 0x005A | |
|
||||||
|
| cmp | 0x005B | |
|
||||||
|
| je | 0x005C | |
|
||||||
|
| jne | 0x005D | |
|
||||||
|
| jge | 0x005E | |
|
||||||
|
| jg | 0x005F | |
|
||||||
|
| jle | 0x0060 | |
|
||||||
|
| jl | 0x0061 | |
|
||||||
|
| + | 0x0062 | |
|
||||||
|
| - | 0x0063 | |
|
||||||
|
| * | 0x0064 | |
|
||||||
|
| / | 0x0065 | |
|
||||||
| | 0xFFFF | unrecognised token |
|
| | 0xFFFF | unrecognised token |
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ start:
|
|||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
|
|
||||||
identify_token:
|
identify_token:
|
||||||
|
cmp rsi, 1 ; if the token has length 1
|
||||||
|
je .start_length1 ; then enter the length 1 loop
|
||||||
|
|
||||||
cmp rsi, 2 ; if the token has length 2
|
cmp rsi, 2 ; if the token has length 2
|
||||||
je .start_length2 ; then enter the length 2 loop
|
je .start_length2 ; then enter the length 2 loop
|
||||||
|
|
||||||
@@ -58,6 +61,26 @@ identify_token:
|
|||||||
|
|
||||||
jmp .unrecognised ; else unrecognised
|
jmp .unrecognised ; else unrecognised
|
||||||
|
|
||||||
|
.start_length1
|
||||||
|
mov rcx, tokens.length1 ; rcx -> list of known tokens
|
||||||
|
|
||||||
|
.loop_length1
|
||||||
|
cmp rcx, tokens.length2 ; check if rcx still in the bounds of length1 tokens
|
||||||
|
jge .unrecognised ; if not, unrecognised
|
||||||
|
|
||||||
|
mov r10b, [rcx] ; known token
|
||||||
|
mov r11b, [rdi] ; token
|
||||||
|
cmp r10b, r11b ; if known token matches token
|
||||||
|
je .found_length1 ; exit loop
|
||||||
|
|
||||||
|
add rcx, 3 ; length of token + length of id
|
||||||
|
jmp .loop_length1
|
||||||
|
|
||||||
|
.found_length1
|
||||||
|
xor eax, eax ; make sure rest of rax is zeroed
|
||||||
|
mov ax, [rcx + 1] ; return id of token
|
||||||
|
ret
|
||||||
|
|
||||||
.start_length2
|
.start_length2
|
||||||
mov rcx, tokens.length2 ; rcx -> list of known tokens
|
mov rcx, tokens.length2 ; rcx -> list of known tokens
|
||||||
|
|
||||||
@@ -496,6 +519,22 @@ test_identify_token:
|
|||||||
mov rsi, .msg
|
mov rsi, .msg
|
||||||
call print
|
call print
|
||||||
|
|
||||||
|
; length1 token that exists
|
||||||
|
mov byte [TEST_ARENA_ADDR], "*"
|
||||||
|
mov rdi, TEST_ARENA_ADDR
|
||||||
|
mov rsi, 1
|
||||||
|
call identify_token
|
||||||
|
cmp ax, 0x0064
|
||||||
|
jne .fail
|
||||||
|
|
||||||
|
; length1 token that doesn't exist
|
||||||
|
mov byte [TEST_ARENA_ADDR], " "
|
||||||
|
mov rdi, TEST_ARENA_ADDR
|
||||||
|
mov rsi, 1
|
||||||
|
call identify_token
|
||||||
|
cmp ax, 0xFFFF
|
||||||
|
jne .fail
|
||||||
|
|
||||||
; length2 token that exists
|
; length2 token that exists
|
||||||
mov word [TEST_ARENA_ADDR], "sp"
|
mov word [TEST_ARENA_ADDR], "sp"
|
||||||
mov rdi, TEST_ARENA_ADDR
|
mov rdi, TEST_ARENA_ADDR
|
||||||
@@ -575,6 +614,19 @@ test_identify_token:
|
|||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
|
|
||||||
tokens:
|
tokens:
|
||||||
|
.length1
|
||||||
|
db "["
|
||||||
|
dw 0x0051
|
||||||
|
db "]"
|
||||||
|
dw 0x0052
|
||||||
|
db "+"
|
||||||
|
dw 0x0062
|
||||||
|
db "-"
|
||||||
|
dw 0x0063
|
||||||
|
db "*"
|
||||||
|
dw 0x0064
|
||||||
|
db "/"
|
||||||
|
dw 0x0065
|
||||||
.length2
|
.length2
|
||||||
db "r8"
|
db "r8"
|
||||||
dw 0x0008
|
dw 0x0008
|
||||||
@@ -624,6 +676,12 @@ tokens:
|
|||||||
dw 0x0048
|
dw 0x0048
|
||||||
db "ss"
|
db "ss"
|
||||||
dw 0x0049
|
dw 0x0049
|
||||||
|
db "je"
|
||||||
|
dw 0x005C
|
||||||
|
db "jg"
|
||||||
|
dw 0x005F
|
||||||
|
db "jl"
|
||||||
|
dw 0x0061
|
||||||
.length3
|
.length3
|
||||||
db "rax"
|
db "rax"
|
||||||
dw 0x0000
|
dw 0x0000
|
||||||
@@ -699,6 +757,30 @@ tokens:
|
|||||||
dw 0x004D
|
dw 0x004D
|
||||||
db "cr8"
|
db "cr8"
|
||||||
dw 0x004E
|
dw 0x004E
|
||||||
|
db "hlt"
|
||||||
|
dw 0x004F
|
||||||
|
db "xor"
|
||||||
|
dw 0x0053
|
||||||
|
db "inc"
|
||||||
|
dw 0x0054
|
||||||
|
db "dec"
|
||||||
|
dw 0x0055
|
||||||
|
db "mov"
|
||||||
|
dw 0x0056
|
||||||
|
db "add"
|
||||||
|
dw 0x0057
|
||||||
|
db "sub"
|
||||||
|
dw 0x0058
|
||||||
|
db "ret"
|
||||||
|
dw 0x005A
|
||||||
|
db "cmp"
|
||||||
|
dw 0x005B
|
||||||
|
db "jne"
|
||||||
|
dw 0x005D
|
||||||
|
db "jge"
|
||||||
|
dw 0x005E
|
||||||
|
db "jle"
|
||||||
|
dw 0x0060
|
||||||
.length4
|
.length4
|
||||||
db "r10d"
|
db "r10d"
|
||||||
dw 0x001A
|
dw 0x001A
|
||||||
@@ -736,6 +818,10 @@ tokens:
|
|||||||
dw 0x003E
|
dw 0x003E
|
||||||
db "r15b"
|
db "r15b"
|
||||||
dw 0x003F
|
dw 0x003F
|
||||||
|
db "int3"
|
||||||
|
dw 0x0050
|
||||||
|
db "call"
|
||||||
|
dw 0x0059
|
||||||
.length5
|
.length5
|
||||||
.end
|
.end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user