__INTERNAL_fmt: Improve %check_formatted_len for arrays, check and insert '(null) byte per byte (instead of byte,qword,byte)
This commit is contained in:
@@ -194,10 +194,12 @@ __INTERNAL_fmt:
|
|||||||
jmp .insertString
|
jmp .insertString
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
%macro check_formatted_len 2 ;check_format_len [return_label] [offset]
|
%macro check_formatted_len 2 ;check_format_len [return_label] [length offset]
|
||||||
test rbx, rbx
|
test rbx, rbx
|
||||||
jz %%checkBufferLen
|
jz %%checkBufferLen
|
||||||
cmp r11, rbx
|
mov rax, r11
|
||||||
|
add rax, %2
|
||||||
|
cmp rax, rbx
|
||||||
jae .wrapup
|
jae .wrapup
|
||||||
jmp .flushReturn_%1
|
jmp .flushReturn_%1
|
||||||
%%checkBufferLen:
|
%%checkBufferLen:
|
||||||
@@ -260,6 +262,7 @@ __INTERNAL_fmt:
|
|||||||
cmp byte [rdi], EOS
|
cmp byte [rdi], EOS
|
||||||
je .wrapup
|
je .wrapup
|
||||||
check_formatted_len 0,1
|
check_formatted_len 0,1
|
||||||
|
;.flushReturn_0:
|
||||||
cmp byte [rdi], '\'
|
cmp byte [rdi], '\'
|
||||||
je .asciiReplacement
|
je .asciiReplacement
|
||||||
cmp byte [rdi], '%'
|
cmp byte [rdi], '%'
|
||||||
@@ -286,6 +289,7 @@ __INTERNAL_fmt:
|
|||||||
jmp .invalidReplacement
|
jmp .invalidReplacement
|
||||||
.replaceAscii:
|
.replaceAscii:
|
||||||
check_formatted_len 1, 1
|
check_formatted_len 1, 1
|
||||||
|
;.flushReturn_1:
|
||||||
write_format_data byte,r10,r8b
|
write_format_data byte,r10,r8b
|
||||||
add rdi, 2
|
add rdi, 2
|
||||||
inc r10
|
inc r10
|
||||||
@@ -443,18 +447,43 @@ __INTERNAL_fmt:
|
|||||||
.insertString:
|
.insertString:
|
||||||
test rsi, rsi
|
test rsi, rsi
|
||||||
jnz .doInsertString
|
jnz .doInsertString
|
||||||
check_formatted_len 2, 7
|
check_formatted_len 2, 1
|
||||||
|
;.flushReturn_2:
|
||||||
write_format_data byte,r10,'('
|
write_format_data byte,r10,'('
|
||||||
write_format_data qword,r10+1,'null'
|
inc r10
|
||||||
write_format_data byte,r10+5,')'
|
inc r11
|
||||||
add r10, 6
|
check_formatted_len 21, 1
|
||||||
add r11, 6
|
;.flushReturn_21:
|
||||||
|
write_format_data byte,r10,'n'
|
||||||
|
inc r10
|
||||||
|
inc r11
|
||||||
|
check_formatted_len 22, 1
|
||||||
|
;.flushReturn_22:
|
||||||
|
write_format_data byte,r10,'u'
|
||||||
|
inc r10
|
||||||
|
inc r11
|
||||||
|
check_formatted_len 23, 1
|
||||||
|
;.flushReturn_23:
|
||||||
|
write_format_data byte,r10,'l'
|
||||||
|
inc r10
|
||||||
|
inc r11
|
||||||
|
check_formatted_len 24, 1
|
||||||
|
;.flushReturn_24:
|
||||||
|
write_format_data byte,r10,'l'
|
||||||
|
inc r10
|
||||||
|
inc r11
|
||||||
|
check_formatted_len 25, 1
|
||||||
|
;.flushReturn_25:
|
||||||
|
write_format_data byte,r10,')'
|
||||||
|
inc r10
|
||||||
|
inc r11
|
||||||
jmp .endInsertString
|
jmp .endInsertString
|
||||||
|
|
||||||
.doInsertString:
|
.doInsertString:
|
||||||
cmp byte [rsi], EOS
|
cmp byte [rsi], EOS
|
||||||
je .endInsertString
|
je .endInsertString
|
||||||
check_formatted_len 3, 1
|
check_formatted_len 3, 1
|
||||||
|
;.flushReturn_3:
|
||||||
mov r8b, byte [rsi]
|
mov r8b, byte [rsi]
|
||||||
write_format_data byte,r10,r8b
|
write_format_data byte,r10,r8b
|
||||||
inc rsi
|
inc rsi
|
||||||
@@ -512,13 +541,23 @@ __INTERNAL_fmt:
|
|||||||
xor r10, r10
|
xor r10, r10
|
||||||
.flush_ret:
|
.flush_ret:
|
||||||
cmp r9b, 0
|
cmp r9b, 0
|
||||||
je .flushReturn_0
|
je .flushReturn_0 ;.process
|
||||||
cmp r9b, 1
|
cmp r9b, 1
|
||||||
je .flushReturn_1
|
je .flushReturn_1 ;.replaceAscii
|
||||||
cmp r9b, 2
|
cmp r9b, 2
|
||||||
je .flushReturn_2
|
je .flushReturn_2 ;.insertString "(null)
|
||||||
|
cmp r9b, 21
|
||||||
|
je .flushReturn_21 ;...
|
||||||
|
cmp r9b, 22
|
||||||
|
je .flushReturn_22 ;...
|
||||||
|
cmp r9b, 23
|
||||||
|
je .flushReturn_23 ;...
|
||||||
|
cmp r9b, 24
|
||||||
|
je .flushReturn_24 ;...
|
||||||
|
cmp r9b, 25
|
||||||
|
je .flushReturn_25 ;...
|
||||||
cmp r9b, 3
|
cmp r9b, 3
|
||||||
je .flushReturn_3
|
je .flushReturn_3 ;.doInsertString
|
||||||
|
|
||||||
.wrapup:
|
.wrapup:
|
||||||
test rbx, rbx
|
test rbx, rbx
|
||||||
|
@@ -422,11 +422,7 @@ section .rodata
|
|||||||
addTest(fgetmod2, "fgetmod(statbuff2)")
|
addTest(fgetmod2, "fgetmod(statbuff2)")
|
||||||
fgetmodStr db "\t- File permissions of file '%s': %04o\n",EOS
|
fgetmodStr db "\t- File permissions of file '%s': %04o\n",EOS
|
||||||
|
|
||||||
fmt_str db "%s",EOS
|
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
fmt_out resb 5
|
|
||||||
fmt_over resb 64
|
|
||||||
inputBuffer_4 resb 4
|
inputBuffer_4 resb 4
|
||||||
inputBuffer_32 resb 32
|
inputBuffer_32 resb 32
|
||||||
strBuff1 resb 64
|
strBuff1 resb 64
|
||||||
@@ -1665,16 +1661,6 @@ _start:
|
|||||||
sub rcx, r14
|
sub rcx, r14
|
||||||
call printf
|
call printf
|
||||||
|
|
||||||
lea rdi, [rel fmt_out]
|
|
||||||
mov rsi, 5
|
|
||||||
lea rdx, [rel fmt_str]
|
|
||||||
xor rcx, rcx
|
|
||||||
call format
|
|
||||||
lea rdi, [rel fmt_out]
|
|
||||||
call puts
|
|
||||||
lea rdi, [rel fmt_over]
|
|
||||||
call puts
|
|
||||||
|
|
||||||
;--- exit()
|
;--- exit()
|
||||||
xor rdi, rdi
|
xor rdi, rdi
|
||||||
call exit
|
call exit
|
||||||
|
Reference in New Issue
Block a user