Files
HexwellandClaude Fable 5 971296f174 refactor: separate libhijacker headers from shared contracts
source/include mixed libhijacker's private implementation headers (util.hpp
with its hand-rolled UniquePtr/String/Vector, plus kernel/, elf/, dbg/,
hijacker/) with genuinely cross-module contracts, and the whole directory was
pulled in as -isystem, so any module could reach libhijacker internals and
every warning in those headers was suppressed.

Move the libhijacker-private headers to source/libhijacker/include and expose
it as a PUBLIC include directory, so the two modules that actually use it —
util for hijacker.hpp, shellui for SHA-1 — now declare that dependency.

Split sha1.hpp: the public-domain SHA-1 goes to third_party/sha1, while
NID_KEY, Sha1 and genSha1 (which needed libhijacker's StringView) move into
the nid.hpp that uses them. shellui only ever wanted the plain digest.

Drop source/include's SYSTEM marker now that it holds only first-party
contracts. That surfaced problems -isystem had been hiding:

  * 68 format-string mismatches in dbg.hpp, printing uintptr_t with %llx
  * freebsd-helper.h redefining PROT_* and TRACEBUF over the SDK's
  * ini.h's header-only helpers declared static rather than static inline

The GNU extensions that TYPE_BEGIN/TYPE_FIELD rely on are now silenced per
header instead of by the blanket -isystem.

Also drop three redundant util.hpp includes (bootstrapper, shellui) that
referenced none of its symbols, and fix backtrace.hpp being included through
relative ../include paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 20:13:50 +08:00

80 lines
2.0 KiB
C++

#pragma once
extern "C" {
#include <stdint.h>
}
#include "dbg.hpp"
template <typename T>
class ProcessReference {
uintptr_t addr;
int pid;
public:
ProcessReference() = default;
ProcessReference(int pid, uintptr_t addr) : addr(addr), pid(pid) {}
ProcessReference(const ProcessReference &rhs) : addr(rhs.addr), pid(rhs.pid) {}
ProcessReference(ProcessReference&&) noexcept = delete;
ProcessReference &operator=(const ProcessReference &rhs) {
addr = rhs.addr;
pid = rhs.pid;
return *this;
}
ProcessReference &operator=(ProcessReference&&) noexcept = delete;
ProcessReference &operator=(T value) {
dbg::write(pid, addr, &value, sizeof(value));
return *this;
}
~ProcessReference() noexcept = default;
operator T() const {
T value;
dbg::read(pid, addr, &value, sizeof(T));
return value;
}
};
template <>
class ProcessReference<bool> {
uintptr_t addr;
int pid;
public:
ProcessReference(int pid, uintptr_t addr) : addr(addr), pid(pid) {}
ProcessReference(const ProcessReference &rhs) : addr(rhs.addr), pid(rhs.pid) {}
ProcessReference(ProcessReference&&) noexcept = delete;
ProcessReference &operator=(const ProcessReference &rhs) {
addr = rhs.addr;
pid = rhs.pid;
return *this;
}
ProcessReference &operator=(bool value) {
dbg::write(pid, addr, &value, sizeof(value));
return *this;
}
ProcessReference &operator=(ProcessReference&&) noexcept = delete;
~ProcessReference() noexcept = default;
explicit operator bool() const {
bool value; // NOLINT(cppcoreguidelines-init-variables)
dbg::read(pid, addr, &value, sizeof(bool));
return value;
}
};
template <typename T>
class ProcessPointer {
uintptr_t addr;
int pid;
public:
ProcessPointer() : addr(), pid() {}
ProcessPointer(int pid, uintptr_t addr) : addr(addr), pid(pid) {}
ProcessReference<T> operator*() const { return {pid, addr}; }
T get() const {
T value{};
dbg::read(pid, addr, &value, sizeof(T));
return value;
}
uintptr_t address() const { return addr; }
};