/
pushstr.asm
39 lines (33 loc) · 1.05 KB
/
pushstr.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
38
39
<% from pwnlib.util import lists, packing, fiddling %>
<% from pwnlib.shellcraft.arm import push %>
<% from pwnlib.shellcraft import pretty %>
<% import six %>
<%page args="string, append_null = True, register='r7'"/>
<%docstring>
Pushes a string onto the stack.
Args:
string (str): The string to push.
append_null (bool): Whether to append a single NULL-byte before pushing.
register (str): Temporary register to use. By default, R7 is used.
Examples:
>>> print(shellcraft.arm.pushstr("Hello!").rstrip())
/* push b'Hello!\x00A' */
movw r7, #0x4100216f & 0xffff
movt r7, #0x4100216f >> 16
push {r7}
movw r7, #0x6c6c6548 & 0xffff
movt r7, #0x6c6c6548 >> 16
push {r7}
</%docstring>
<%
if isinstance(string, six.text_type):
string = string.encode('utf-8')
if append_null:
string += b'\x00'
while len(string) % 4:
string += b'\x41'
%>\
/* push ${pretty(string, False)} */
% for word in packing.unpack_many(string, 32)[::-1]:
${push(word, register)}
% endfor