i want to inject an assembler code inside of a program.
Right now im only trying something simple:
[bits 64]
;[org 0x11e5]
global _start
_start:
jmp 0x1040
It works if i use ORG
directive for specify the address where the injected code is being executed.
As this is some kind of execise from my school i have seen other projects doing it without ORG
directive, but for some reason (i suppose version, OS, architecture...) if i write jmp 0x1040
when i compile with nasm test.s
the hex code generated doesn't specify 0x1040
it specify a relative path from where the code is to 0x1040
(this is the reason it works using ORG
directive).
My thought is to perform a direct jump instead of a indirect, i thought the solution was jmp far
but it didn't work and i'm not sure if my implementation was correct:
[bits 64]
;[org 0x11e5]
global _start
_start:
jmp far 0x1040
My main question would be how to perform the jmp without using ORG
directive.
EDIT:
After inject this assembly code to address 0x11e5
as new entrypoint:
[bits 64]
global _start
_start:
mov rax, 0x1040
jmp rax
output from objdump -d infected_bin
Infected address:
...
11e5: b8 40 10 00 00 mov $0x1040,%eax
11ea: ff e0 jmpq *%rax
...
Address to jump:
0000000000001040 <_start>:
1040: f3 0f 1e fa endbr64
1044: 31 ed xor %ebp,%ebp
1046: 49 89 d1 mov %rdx,%r9
1049: 5e pop %rsi
...