26#include "pcdogs_blueprint_test_rows.h"
28#define STABLE_SIGNATURE_COUNT \
29 (sizeof(DTTR_PCDOGS_SIGNATURES) / sizeof(*DTTR_PCDOGS_SIGNATURES))
30#define STABLE_FUNCTION_COUNT \
31 (sizeof(DTTR_PCDOGS_FUNCTIONS) / sizeof(*DTTR_PCDOGS_FUNCTIONS))
32#define UNSTABLE_SIGNATURE_COUNT \
33 (sizeof(DTTR_PCDOGS_UNSTABLE_SIGNATURES) / sizeof(*DTTR_PCDOGS_UNSTABLE_SIGNATURES))
34#define UNSTABLE_FUNCTION_COUNT \
35 (sizeof(DTTR_PCDOGS_UNSTABLE_FUNCTIONS) / sizeof(*DTTR_PCDOGS_UNSTABLE_FUNCTIONS))
44 const DTTR_TestPEImage *image
54 "required %s %s resolved %zu times in %s (%s); expected exactly one match",
65 "required %s %s did not resolve in %s (%s)",
79 const DTTR_TestPEImage *image,
82 DTTR_TestDecodedInstruction decoded = {0};
84 assert_true(decoded.instruction.length > 0);
89 "required %s %s did not decode in %s at 0x%08X",
101 const DTTR_TestPEImage *image
116 size_t fixture_index,
117 const DTTR_TestBinaryFixture *fixture,
119 const DTTR_TestPEImage *image,
153 const DTTR_TestPEImage *image
157 "blueprint function",
165 "blueprint function %s match offset outside %s: match=0x%08X offset=%d",
178 for (
size_t imm_idx = 0; imm_idx < 2; imm_idx++) {
179 if (!decoded->instruction.raw.imm[imm_idx].size
180 || !decoded->instruction.raw.imm[imm_idx].is_relative) {
184 const uint8_t rel_size = (uint8_t)(decoded->instruction.raw.imm[imm_idx].size
186 if (rel_size != 4u) {
190 if ((
size_t)decoded->instruction.raw.imm[imm_idx].offset + rel_size
191 > decoded->instruction.length) {
203 const DTTR_TestPEImage *image,
207 if (patch_size == 0u) {
213 "blueprint hook %s patch window outside %s at 0x%08X size=%u",
221 size_t decoded_size = 0;
222 while (decoded_size < patch_size) {
223 DTTR_TestDecodedInstruction decoded = {0};
225 assert_true(decoded.instruction.length > 0);
228 "blueprint hook %s has unsupported relative immediate in %s at 0x%08X",
231 (
unsigned)(site + decoded_size)
235 decoded_size += decoded.instruction.length;
241 if (decoded->instruction.raw.imm[0].size) {
242 return (uint32_t)decoded->instruction.raw.imm[0].value.u;
252 const DTTR_TestPEImage *image,
258 uintptr_t rva = site;
259 for (
size_t decoded_count = 0; decoded_count < 2048u; decoded_count++) {
260 DTTR_TestDecodedInstruction decoded = {0};
263 "blueprint function %s decode failed in %s while scanning for ABI RET "
272 assert_true(decoded.instruction.length > 0);
273 if (decoded.instruction.mnemonic == ZYDIS_MNEMONIC_JMP) {
277 if (decoded.instruction.mnemonic == ZYDIS_MNEMONIC_RET) {
279 if (actual != expected) {
281 "blueprint function %s ABI cleanup mismatch in %s at 0x%08X: "
282 "expected %u got %u",
294 rva += decoded.instruction.length;
295 if (rva >= image->image_size) {
300 fail_msg(
"blueprint function %s has no decoded RET in %s", fn->
name, fixture->id);
307 const DTTR_TestPEImage *image
316 fail_msg(
"blueprint hotpatch function %s has no pre-entry slot", fn->
name);
326 size_t fixture_index,
327 const DTTR_TestBinaryFixture *fixture,
329 const DTTR_TestPEImage *image,
bool dttr_test_signed_range_valid(uintptr_t base, int32_t offset, size_t size, size_t total)
bool dttr_test_fixture_required(DTTR_TestFixtureMask required, size_t fixture_index)
bool dttr_test_zydis_decode32_at(const DTTR_TestPEImage *image, uintptr_t rva, DTTR_TestDecodedInstruction *out)
uintptr_t dttr_test_offset_site(uintptr_t base, int32_t offset)
bool dttr_test_range_valid(size_t offset, size_t size, size_t total)
const DTTR_BackendState * state
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
static const DTTR_TestCase TEST_CASES[]
DTTR_PCDOGS_T_Calling_Convention
@ DTTR_PCDOGS_HOOK_HOTPATCH
static uintptr_t pcdogs_sigscan(const DTTR_TestPEImage *image, const uint8_t *sig, const char *mask)
Scan a fixture image with the same signature format used by SDK symbol rows.
DTTR_TestBinaryFixture DTTR_TestPCDOGSFixture
bool pcdogs_fixtures_available()
Report whether all PCDOGS binary fixtures are available for signature tests.
bool pcdogs_for_each_fixture(DTTR_TestPEFixtureVisitor visitor, void *userdata)
Visit each available PCDOGS fixture image for signature and ABI checks.
static size_t pcdogs_sigscan_count(const DTTR_TestPEImage *image, const uint8_t *sig, const char *mask)
Count signature matches in a fixture image.
#define DTTR_TEST_PCDOGS_SIG_NOT_FOUND
static void dttr_test_require_available(bool available)
#define DTTR_TEST_MAIN(TESTS)
#define STABLE_FUNCTION_COUNT
static void assert_blueprint_function_resolved(const DTTR_TestPCDOGSFixture *fixture, const blueprint_function *fn, const DTTR_TestPEImage *image)
static void test_blueprint_functions_resolve_and_match_abi(void **state)
#define UNSTABLE_FUNCTION_COUNT
static bool instruction_has_unsupported_reloc(const DTTR_TestDecodedInstruction *decoded)
static uint32_t ret_stack_bytes(const DTTR_TestDecodedInstruction *decoded)
static void assert_patch_window_decodes(const DTTR_TestPCDOGSFixture *fixture, const blueprint_function *fn, const DTTR_TestPEImage *image, uintptr_t site, uint32_t patch_size)
static bool assert_signatures_for_fixture(size_t fixture_index, const DTTR_TestBinaryFixture *fixture, const char *path, const DTTR_TestPEImage *image, void *userdata)
#define STABLE_SIGNATURE_COUNT
static bool assert_blueprint_functions_for_fixture(size_t fixture_index, const DTTR_TestBinaryFixture *fixture, const char *path, const DTTR_TestPEImage *image, void *userdata)
static void assert_decodes_at(const DTTR_TestPCDOGSFixture *fixture, const char *kind, const char *name, const DTTR_TestPEImage *image, uintptr_t rva)
#define UNSTABLE_SIGNATURE_COUNT
static void assert_signature_resolved(const DTTR_TestPCDOGSFixture *fixture, const blueprint_signature *sig, const DTTR_TestPEImage *image)
static uintptr_t require_sigscan(const DTTR_TestPCDOGSFixture *fixture, const char *kind, const char *name, const uint8_t *sig, const char *mask, const DTTR_TestPEImage *image)
static void test_expected_pcdogs_signatures_resolve(void **state)
static void assert_abi_return_matches(const DTTR_TestPCDOGSFixture *fixture, const blueprint_function *fn, const DTTR_TestPEImage *image, uintptr_t site)
static uintptr_t blueprint_function_site(const DTTR_TestPCDOGSFixture *fixture, const blueprint_function *fn, const DTTR_TestPEImage *image)
DTTR_PCDOGS_T_Hook_Kind hook_kind
uint32_t stack_param_bytes
DTTR_TestFixtureMask required
uint32_t entry_patch_size
DTTR_PCDOGS_T_Calling_Convention calling_convention
DTTR_TestFixtureMask required