Skip to content

Commit

Permalink
shellcraft: fix and optimize itoa
Browse files Browse the repository at this point in the history
Fixes #2073
  • Loading branch information
Arusekk committed Aug 7, 2022
1 parent 0533ba0 commit b825e97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 6 additions & 7 deletions pwnlib/shellcraft/templates/amd64/itoa.asm
Expand Up @@ -35,14 +35,16 @@ assert v in registers.amd64
${mov('rdi', buffer)}
${mov('rax', v)}
push rax /* save for later */
${mov('rcx', 10)}
${size_loop}:
${mov('rdx', 0)}
${mov('rcx', 10)}
div rcx
inc rdi
stosb
test rax, rax
jnz ${size_loop}
dec rdi
## null terminate
std
stosb
## Now we begin the actual division process
pop rax
${itoa_loop}:
Expand All @@ -54,7 +56,4 @@ ${size_loop}:
dec rdi
test rax, rax
jnz ${itoa_loop}
## null terminate
${mov('rdx', 0)}
mov BYTE PTR [rdi], dl
inc rdi
cld
11 changes: 5 additions & 6 deletions pwnlib/shellcraft/templates/i386/itoa.asm
Expand Up @@ -36,14 +36,16 @@ assert v in registers.i386
${mov('edi', buffer)}
${mov('eax', v)}
push eax /* save for later */
${mov('ecx', 10)}
${size_loop}:
${mov('edx', 0)}
${mov('ecx', 10)}
div ecx
inc edi
test eax, eax
jnz ${size_loop}
dec edi
## null terminate
std
stosb
## Now we begin the actual division process
pop eax
${itoa_loop}:
Expand All @@ -55,7 +57,4 @@ ${size_loop}:
dec edi
test eax, eax
jnz ${itoa_loop}
## null terminate
${mov('edx', 0)}
mov BYTE PTR [edi], dl
inc edi
cld

0 comments on commit b825e97

Please sign in to comment.