pwntools
pwntools copied to clipboard
error on relative jump MIPS
The error occurs when the bne instruction is used. I have tried setting the vma but get a different error. The error occures on ubuntu 20
[ERROR] Shellcode contains relocations:
Relocation section '.rel.shellcode' at offset 0x168 contains 1 entry:
Offset Info Type Sym.Value Sym. Name
00000024 0000000a R_MIPS_PC16
[ERROR] An error occurred while assembling:
1: .section .shellcode,"awx"
2: .global _start
3: .global __start
4: _start:
5: __start:
6: .set mips2
7: .set noreorder
8: li $t0, 2576980377
9: nop
10: li $t2, 4129
11: addiu $t2,$t2, -4097
12: lw $t3, -4097($t1)
13: xor $t4, $t3, $t0
14: sw $t4, -4097($t1)
15: addiu $t2,$t2, -4
16: bne $t2, $t0, -0x4
17: addiu $a2,$a2,4097
Traceback (most recent call last):
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 709, in asm
log.error('Shellcode contains relocations:\n%s' % relocs)
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/log.py", line 424, in error
raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: Shellcode contains relocations:
Relocation section '.rel.shellcode' at offset 0x168 contains 1 entry:
Offset Info Type Sym.Value Sym. Name
00000024 0000000a R_MIPS_PC16
Traceback (most recent call last):
File "encoder_creator.py", line 49, in <module>
enc_size = len(asm("".join(encoder),vma=0x00000))
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/context/__init__.py", line 1457, in setter
return function(*a, **kw)
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 723, in asm
log.exception("An error occurred while assembling:\n%s" % lines)
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/asm.py", line 709, in asm
log.error('Shellcode contains relocations:\n%s' % relocs)
File "/home/r66/.local/lib/python3.8/site-packages/pwnlib/log.py", line 424, in error
raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: Shellcode contains relocations:
Relocation section '.rel.shellcode' at offset 0x168 contains 1 entry:
Offset Info Type Sym.Value Sym. Name
00000024 0000000a R_MIPS_PC16
used a loop: label instead of hardcoding offset
if you want to hardcode an offset, you need to specify it relatively — beginning of current instruction can be retrieved with the dot symbol (.) in GNU as (and probably many other modern assemblers; older ones like NASM/yasm used $ for this purpose).