/
pushstr_array.asm
37 lines (32 loc) · 1009 Bytes
/
pushstr_array.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<% from pwnlib.shellcraft import thumb %>
<%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)} */
${thumb.pushstr(array_str)}
${thumb.push(0)} /* null terminate */
% for i,arg in enumerate(reversed(array)):
${thumb.mov(reg, offset + word_size*i - len(arg))}
add ${reg}, sp
${thumb.push(reg)} /* ${repr(arg)} */
<% offset -= len(arg) %>\
% endfor
${thumb.mov(reg,'sp')}