File tree 1 file changed +38
-0
lines changed
pwnlib/shellcraft/templates/mips
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 th at 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' )}
You can’t perform that action at this time.
0 commit comments