Skip to content

Commit

Permalink
Add MIPS pushstr_array
Browse files Browse the repository at this point in the history
Example resulting state:

$ shellcraft mips.pushstr_array '$t1' '["hello", "world", "boss!"]' -d --after
...
pwndbg> telescope $t1 4
00:0000| t1 sp  0x76ffec7c --> 0x76ffec8c <-- 'hello'
01:0004|        0x76ffec80 --> 0x76ffec92 <-- 'world'
02:0008|        0x76ffec84 --> 0x76ffec98 <-- 'boss!'
03:000c|        0x76ffec88 <-- 0x0
  • Loading branch information
zachriggle committed Aug 24, 2016
1 parent ea94ee4 commit 6376d07
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pwnlib/shellcraft/templates/mips/pushstr_array.asm
@@ -0,0 +1,38 @@
<% from pwnlib.shellcraft import mips %>
<%docstring>
Pushes an array/envp-style array of pointers onto the stack.

Arguments:
reg(str):
Destination register to hold the pointer.
array(str,list):
Single argument or list of arguments to push.
NULL termination is normalized so that each argument
ends with exactly one NULL byte.
</%docstring>
<%page args="reg, array"/>
<%
if isinstance(array, (str)):
array = [array]

array_str = ''

# Normalize all of the arguments' endings
array = [arg.rstrip('\x00') + '\x00' for arg in array]
array_str = ''.join(array)

word_size = 4
offset = len(array_str) + word_size

%>\
/* push argument array ${repr(array)} */
${mips.pushstr(array_str)}
${mips.mov(reg, 0)}
${mips.push(reg)} /* null terminate */
% for i,arg in enumerate(reversed(array)):
${mips.mov(reg, offset + word_size*i - len(arg))}
add ${reg}, $sp
${mips.push(reg)} /* ${repr(arg)} */
<% offset -= len(arg) %>\
% endfor
${mips.mov(reg,'$sp')}

0 comments on commit 6376d07

Please sign in to comment.