Skip to content

Commit a951135

Browse files
committed
shellblocks: src: print: Jump over printed string
1 parent b961ad6 commit a951135

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

shellblocks/src/print.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
.global start
44
start:
5+
// Save $ra
56
addiu $sp, -4
67
sw $ra, 0($sp)
8+
9+
// Get $pc using bal
710
bal code
811
nop
912
code:
@@ -16,9 +19,18 @@ code:
1619
jalr $v0
1720
nop
1821

22+
// Restore $ra
1923
lw $ra, 0($sp)
2024
addiu $sp, 4
2125
nop
2226

27+
// Jump over the printed string, to ensure we can run
28+
// another primitive after this one.
29+
b end_of_code
30+
2331
print_string:
2432
.asciiz PRINT_STRING
33+
.align 2
34+
35+
end_of_code:
36+
nop

tests/test_print.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ def test_print_reaches_end(
128128
stack_address
129129
)
130130

131-
end_of_code = shellcode.find(string_to_print.encode())
132-
133-
print_mu.emu_start(shellcode_address, shellcode_address + end_of_code)
131+
print_mu.emu_start(shellcode_address, shellcode_address + len(shellcode))
134132

135133
assert (stack_address + 0x2000) == print_mu.reg_read(UC_MIPS_REG_29)
136134

@@ -157,6 +155,4 @@ def test_print_is_pic(
157155
stack_address
158156
)
159157

160-
end_of_code = shellcode.find(string_to_print.encode())
161-
162-
print_mu.emu_start(shellcode_run_addr, shellcode_run_addr + end_of_code)
158+
print_mu.emu_start(shellcode_run_addr, shellcode_run_addr + len(shellcode))

0 commit comments

Comments
 (0)