Skip to content

Commit 6376d07

Browse files
committed
Add MIPS pushstr_array
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
1 parent ea94ee4 commit 6376d07

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<% from pwnlib.shellcraft import mips %>
2+
<%docstring>
3+
Pushes an array/envp-style array of pointers onto the stack.
4+
5+
Arguments:
6+
reg(str):
7+
Destination register to hold the pointer.
8+
array(str,list):
9+
Single argument or list of arguments to push.
10+
NULL termination is normalized so that each argument
11+
ends with exactly one NULL byte.
12+
</%docstring>
13+
<%page args="reg, array"/>
14+
<%
15+
if isinstance(array, (str)):
16+
array = [array]
17+
18+
array_str = ''
19+
20+
# Normalize all of the arguments' endings
21+
array = [arg.rstrip('\x00') + '\x00' for arg in array]
22+
array_str = ''.join(array)
23+
24+
word_size = 4
25+
offset = len(array_str) + word_size
26+
27+
%>\
28+
/* push argument array ${repr(array)} */
29+
${mips.pushstr(array_str)}
30+
${mips.mov(reg, 0)}
31+
${mips.push(reg)} /* null terminate */
32+
% for i,arg in enumerate(reversed(array)):
33+
${mips.mov(reg, offset + word_size*i - len(arg))}
34+
add ${reg}, $sp
35+
${mips.push(reg)} /* ${repr(arg)} */
36+
<% offset -= len(arg) %>\
37+
% endfor
38+
${mips.mov(reg,'$sp')}

0 commit comments

Comments
 (0)