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
2 changes: 2 additions & 0 deletions ARCHITECTURE/modules/loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Fixture C/assembly belongs to its behavioral OS owner; preparation to tooling.
and metadata consumed by patches, reports and debuggers (`QlLoader`).
- ELF maps load segments/interpreter and creates guest stack/auxv;
ELF driver loading uses a separate relocation/import path (`elf.py`).
In shellcode mode, loader and OS entry points identify the mapped code
start; `Qiling.entry_point` remains the optional `run(begin=...)` override.
- PE maps DLLs and records `import_symbols` consumed by Windows dispatch.
Optional disk caches use pickle (`QlPeCache`); cache contents are trusted
host artifacts, not safe arbitrary guest inputs.
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
This file details the changelog of Qiling Framework.

## Unreleased

* Initialize the ELF shellcode loader entry point so Qdb can attach without a manual address override (#1608).

------------------------------------
[Version 1.4.6]: August 4th, 2023

Expand Down
2 changes: 1 addition & 1 deletion qiling/loader/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run(self):
self.ql.mem.write(shellcode_base, self.ql.code)

self.ql.arch.regs.arch_sp = shellcode_base
self.ql.os.entry_point = shellcode_base
self.ql.os.entry_point = self.entry_point = shellcode_base
self.load_address = shellcode_base

return
Expand Down
22 changes: 21 additions & 1 deletion tests/test_qdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@

import sys
import unittest
from unittest.mock import patch

sys.path.append("..")
from qiling import Qiling
from qiling.const import QL_VERBOSE
from qiling.const import QL_ARCH, QL_OS, QL_VERBOSE
from qiling.debugger.qdb.qdb import QlQdb


class DebuggerTest(unittest.TestCase):

def test_qdb_linux_shellcode_entry_point(self):
for archtype in (QL_ARCH.X86, QL_ARCH.X8664):
with self.subTest(archtype=archtype):
code = b'\x90\x90'
ql = Qiling(code=code, archtype=archtype, ostype=QL_OS.LINUX,
verbose=QL_VERBOSE.OFF, console=False)

self.assertIsNone(ql.entry_point)

with patch.object(QlQdb, 'cmdloop') as cmdloop, patch.object(QlQdb, 'do_context'):
debugger = QlQdb(ql)

self.assertEqual(ql.loader.entry_point, ql.loader.load_address)
self.assertEqual(ql.loader.entry_point, ql.os.entry_point)
self.assertEqual(ql.mem.read(ql.loader.entry_point, len(code)), code)
self.assertEqual(debugger.cur_addr, ql.loader.entry_point)
cmdloop.assert_called_once_with()

def __test_common(self, vpath: str, rootfs: str, script: str) -> None:
"""Load a common setup for all test cases.
"""
Expand Down