Adds bin2str() and printf() format specifier %b
This commit is contained in:
@@ -4,6 +4,7 @@ extern strlen
|
||||
extern dec2str
|
||||
extern udec2str
|
||||
extern hex2str
|
||||
extern bin2str
|
||||
|
||||
section .rodata
|
||||
mNL db NL
|
||||
@@ -68,6 +69,7 @@ puts:
|
||||
; %u Unsigned integer, printed as decimal
|
||||
; %x Unsigned integer, printed as hexadecimal number (lowercase)
|
||||
; %X Unsigned integer, printed as hexadecimal number (uppercase)
|
||||
; %b Unsigned integer, printed as binary number
|
||||
; %s String
|
||||
; <!> Unsupported specifiers are printed as-is
|
||||
; <!> For all specifiers (except %%) an argument is expected. Mismatch between arguments given and specifiers provided will lead to issues
|
||||
@@ -132,6 +134,8 @@ printf:
|
||||
je .rep_x
|
||||
cmp byte [rdi + 1], 'X'
|
||||
je .rep_x
|
||||
cmp byte [rdi + 1], 'b'
|
||||
je .rep_b
|
||||
cmp byte [rdi + 1], 's'
|
||||
je .rep_s
|
||||
|
||||
@@ -214,6 +218,28 @@ printf:
|
||||
pop rdi
|
||||
jmp .insertString
|
||||
|
||||
;--- '%b' ---;
|
||||
.rep_b:
|
||||
cmp rdx, 4
|
||||
ja .b_fromStack
|
||||
mov rsi, [printfArgs + SIZE_QWORD * rdx]
|
||||
jmp .convertBin
|
||||
.b_fromStack:
|
||||
mov rsi, [rbp + RBP_OFFSET_CALLER + ((rdx-5) * SIZE_QWORD)]
|
||||
.convertBin:
|
||||
sub rsp, SIZE_QWORD
|
||||
push rax
|
||||
push rdx
|
||||
push rdi
|
||||
mov rdi, rsi
|
||||
call bin2str
|
||||
mov rsi, rax
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rax
|
||||
add rsp, SIZE_QWORD
|
||||
jmp .insertString
|
||||
|
||||
;--- '%s' ---;
|
||||
.rep_s:
|
||||
cmp rdx, 4
|
||||
|
Reference in New Issue
Block a user