Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions qiling/loader/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __init__(self, ql: Qiling):
super().__init__(ql)

def run(self):
self.profile = self.ql.os.profile[f'OS{self.ql.arch.bits}']

if self.ql.code:
self.ql.mem.map(self.ql.os.entry_point, self.ql.os.code_ram_size, info="[shellcode_stack]")

Expand All @@ -79,11 +81,10 @@ def run(self):
self.ql.arch.regs.arch_sp = shellcode_base
self.ql.os.entry_point = shellcode_base
self.load_address = shellcode_base
self.mmap_address = self.profile.getint('mmap_address')

return

self.profile = self.ql.os.profile[f'OS{self.ql.arch.bits}']

# setup program stack
stack_address = self.profile.getint('stack_address')
stack_size = self.profile.getint('stack_size')
Expand Down
13 changes: 13 additions & 0 deletions tests/test_elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,19 @@ def test_memory_search(self):

del ql

def test_shellcode_mmap_address(self):
# a code-only instance has no ELF image to derive the mmap floor from;
# the loader still has to expose the profile value for the mmap syscall
from qiling.os.posix.syscall.mman import ql_syscall_mmap

ql = Qiling(code=b"\xCC", archtype=QL_ARCH.X8664, ostype=QL_OS.LINUX, verbose=QL_VERBOSE.OFF)
self.assertEqual(ql.loader.mmap_address, ql.os.profile.getint('OS64', 'mmap_address'))

addr = ql_syscall_mmap(ql, 0, 0x1000, 0x3, 0x22, -1, 0)
self.assertGreater(addr, 0)

del ql

def test_elf_linux_x8664_path_traversion(self):
ql = Qiling(["../examples/rootfs/x8664_linux/bin/path_traverse_static"], "../examples/rootfs/x8664_linux", verbose=QL_VERBOSE.DEBUG)

Expand Down