Commit graph

23 commits

Author SHA1 Message Date
sina
1f175b1fd9 restore Linux directory listing and apply address check to kernel functions 2026-10-04 21:46:13 +02:00
Claude
b451e6c810 Locate files next to the executable on Linux
`SetupPathForFileName` is the "find a file beside my binary" helper: it is how
the driver path, the hwdbg test/script files, the exported
`hyperdbg_u_setup_path_for_filename` and (now) the PCI ID database are all
resolved. On Linux it was a stub that printed an error and returned FALSE, so
every one of those lookups failed. Implementing it also removes the blocker that
kept two neighbouring helpers stubbed, so all three are done here.

install-linux.cpp — SetupPathForFileName:

A call-for-call port of the Windows body. `readlink("/proc/self/exe")` is the
`GetModuleFileName(GetModuleHandle(NULL), ...)` counterpart, `strrchr(..., '/')`
replaces `strrchr(..., '\\')` to strip the program name, and `access(path, F_OK)`
replaces the `CreateFile(..., OPEN_EXISTING)` probe behind `CheckFileExists`.

Two things it does that the Windows version does not:

- BufferLength is honoured on every write. `readlink` truncates silently, so a
  result that fills the buffer is rejected instead of being handed back as a
  valid-looking path to the wrong file, and the directory + '/' + name + NUL
  total is checked before appending. install.cpp gets the second half of this
  from StringCbCat, but its GetModuleFileName truncation is unchecked.

- Windows-style separators in FileName are normalized to '/'. The names come
  from shared headers and are spelled the Windows way —
  HWDBG_TEST_READ_INSTANCE_INFO_PATH ("..\\..\\..\\..\\hwdbg\\...") and
  PCI_ID_DATABASE_PATH ("constants\\pci.ids"). Normalizing here keeps those
  constants shared and keeps the #ifdef out of every call site. Only the
  appended part is rewritten, so a backslash inside a real Linux directory name
  survives.

common.cpp — ListDirectory:

opendir/readdir with fnmatch for the wildcard, mirroring how FindFirstFileA
applies the pattern to the file name. No fnmatch flag is passed, so a leading
'.' is unremarkable and "." / ".." match a bare "*", as they do in the Win32
walk; a missing directory throws the same std::runtime_error as the
INVALID_HANDLE_VALUE branch. One deliberate difference: the result is sorted,
since readdir returns entries in file-system order and the caller (eval.cpp's
script-engine test harness) is easier to compare across runs when the order is
stable.

pci-id.cpp — GetVendorById:

The Linux branch now builds the database path with SetupPathForFileName and
calls the same GetVendorByIdStr as Windows. It had been left Windows-only
because wrapping just the two Win32 calls would have left strrchr looking for a
'\\' and silently resolving against the cwd; the normalization above removes
that objection. !pcitree and !pcicam resolve vendor and device names on Linux
whenever constants/pci.ids is deployed next to the binary.

Verified by extracting SetupPathForFileName and the Linux ListDirectory branch
into a standalone harness built with -fsanitize=address,undefined: 20 probes
covering the separator normalization, both CheckFileExists outcomes, the
exact-fit and one-byte-short buffer boundaries, a buffer too small for the
executable path itself, the NULL/zero-length arguments, and the four
ListDirectory cases (filtering, sorting, empty match, missing directory). All
pass with no sanitizer diagnostics. The three modified files were also compiled
with the project's own Linux CMake build. The Windows build is untouched: every
change is inside a non-Windows branch or in a file that is not in the Windows
project.

The ledger in hyperdbg/linux/PORTING_STATUS.md is updated accordingly;
GetConfigFilePath stays open, as it is the same walk behind a PWCHAR
out-parameter and remains blocked on the wide-char work.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3C1DuhHtqK64eEkHjKCHM
2026-10-04 21:46:13 +02:00
Claude
578abcbeba Stop malformed command arguments from aborting the debugger
The remaining std::stoi() call sites in the user-mode helpers throw on
malformed and out-of-range input. None of the callers catch, and there is
no top-level handler, so a bad command argument terminates the process
instead of being rejected with an error message.

common/common.cpp:

- IsNumber() tested against the character set "[0123456789]", so the two
  square brackets were accepted as digits. It is used as the guard in
  front of stoi() by several callers, which turns the mistake into a
  crash: "[1]" passes validation and then throws std::invalid_argument.
  Removed the brackets from the set.

- ValidateIP() called stoi() on every octet. Together with the above,
  ".connect [1].2.3.4 50000" aborted the process; so did an octet long
  enough to overflow int, e.g. ".connect 99999999999.1.1.1". Replaced by
  a strtoul() range check, which saturates instead of throwing.

- CheckAddressCanonicality() compared with a strict "<" against the start
  of the higher-half canonical range, so the boundary address itself
  (0xFFFF800000000000 at a 48-bit VA width) was reported as user-mode.
  CheckAccessValidityAndSafety() would then probe a kernel address from
  user mode rather than refusing it.

- ListDirectory() called FindNextFileA() before consuming the match that
  FindFirstFileA() had already stored in FindData, so the first file of
  every listing was silently dropped. Turned into a do/while.

- isxdigit()/isdigit()/isspace() were handed a plain char; passing a
  negative value to the <ctype.h> functions is undefined behavior and
  trips the MSVC debug CRT on any input with a byte above 0x7f. Cast to
  UCHAR at the four call sites.

The same crash class at the call sites that use stoi() directly on user
input, all replaced with strtoul() so the existing range checks reject
the value instead of an exception escaping:

- connect.cpp (x2) and listen.cpp: TCP port validation.
- debug.cpp: serial baud rate.

Verified by extracting the affected functions from common.cpp and running
them under ASan/UBSan over a 316-probe corpus, before and after. The
baseline aborts with SIGABRT on three inputs; afterwards every probe
returns a defined result and exactly the seven intended lines differ.
The four modified files were also compiled with the project's own Linux
CMake build to confirm they build clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3C1DuhHtqK64eEkHjKCHM
2026-10-04 21:46:13 +02:00
Nikzad
2dfbf46e51 c/cpp files 2026-08-06 21:13:03 +03:30
sina
d4132ee7db fix UInt32 convesion for negative (signed) values 2026-07-21 16:57:26 +02:00
sina
39c4b2f127 update and cleanup CPUID 2026-07-21 15:12:04 +02:00
Sina Karvandi
6324c1d718
Merge pull request #650 from nikzad66/feature-cpuid-command
Feature cpuid command
2026-07-21 14:28:37 +02:00
Nikzad
632db21290 user: implement ucpuid command in user mode- Add ucpuid.cpp with leaf/sub-leaf decoding
- Implement CPUID command parser and dispatcher
- Add remote CPUID support via KdSendUserCpuidPacketToDebuggee()
- Implement response handler in kernel-listening.cpp
- Add proper validation for FunctionId and SubFunctionId
- Support hex and decimal input formats
2026-07-19 18:15:43 +03:30
Max Raulea
860f736bd2 Added guards and compilation flag in cmake 2026-07-19 11:11:09 +02:00
Max Raulea
dd38a30d22 New Platform functions and maybe missed CpuID wrapper function? 2026-07-19 11:05:12 +02:00
sina
aa18675760 update changelog and fix minor issues 2026-06-21 14:22:33 +02:00
maxraulea
9c3e0ed23b added Linux distinction and pragmas together with new platform functions 2026-06-10 16:29:35 +02:00
sina
1e49d3f05c refactor doxygen, variables, function names 5 2026-05-31 18:34:03 +02:00
sina
858434940a add CPU intrinsics for user mode 2026-05-05 23:46:12 +02:00
SinaKarvandi
74af42897f use debug privilege to fix symbol issue on 24h2 2025-01-08 23:39:49 +01:00
SinaKarvandi
0fe90f5a7b integrate new parser with the .script command 2024-08-10 22:30:05 +09:00
SinaKarvandi
4fc7d9d441 change code, condition and script parser 2024-07-30 19:38:50 +09:00
SinaKarvandi
760908f5e3 applying new parser to commands 4 2024-07-30 13:17:50 +09:00
SinaKarvandi
865111dd6a applying new parser to commands 2 2024-07-29 18:46:12 +09:00
SinaKarvandi
13c4355a16 applying new parser to commands 1 2024-07-29 18:06:54 +09:00
SinaKarvandi
49ed125e72 fix computation of stage register flip-flops 2024-06-25 17:01:52 +09:00
SinaKarvandi
9b4fbaeb61 change libhyperdbg SDK functions 2024-06-24 19:07:06 +09:00
SinaKarvandi
48c362255e build based on new libhyperdbg 2024-06-24 18:05:54 +09:00