diff --git a/ARCHITECTURE/modules/loaders.md b/ARCHITECTURE/modules/loaders.md index ae3bdd419..2adc4de40 100644 --- a/ARCHITECTURE/modules/loaders.md +++ b/ARCHITECTURE/modules/loaders.md @@ -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. diff --git a/ChangeLog b/ChangeLog index 84070a4c9..15a8760d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/qiling/loader/elf.py b/qiling/loader/elf.py index a5a8ac6fe..ba18203c3 100644 --- a/qiling/loader/elf.py +++ b/qiling/loader/elf.py @@ -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 diff --git a/tests/test_qdb.py b/tests/test_qdb.py index 8498d6c82..f477e88ca 100644 --- a/tests/test_qdb.py +++ b/tests/test_qdb.py @@ -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. """