2025-10-01 23:04:46 +02:00
|
|
|
// Copyright (c) Lysann Tranvouez. All rights reserved.
|
2025-10-01 23:46:55 +02:00
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
|
|
#include <mach_detours.h>
|
|
|
|
|
|
|
|
|
|
#include "test_func.h"
|
|
|
|
|
|
|
|
|
|
static int testFunctionDetourCounter = 0;
|
|
|
|
|
int testFunctionDetour()
|
|
|
|
|
{
|
|
|
|
|
testFunctionDetourCounter++;
|
|
|
|
|
return 94;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "Overriding custom function" )
|
|
|
|
|
{
|
|
|
|
|
int (*realTestFunction)() = testFunction;
|
|
|
|
|
testFunctionCounter = 0;
|
|
|
|
|
testFunctionDetourCounter = 0;
|
|
|
|
|
|
|
|
|
|
REQUIRE( testFunction() == 42 );
|
|
|
|
|
REQUIRE( testFunctionCounter == 1 );
|
|
|
|
|
REQUIRE( testFunctionDetourCounter == 0 );
|
|
|
|
|
|
|
|
|
|
CHECK( detour_transaction_begin() == err_none );
|
|
|
|
|
CHECK( detour_attach(reinterpret_cast<detour_func_t*>(&realTestFunction), reinterpret_cast<detour_func_t>(testFunctionDetour)) == err_none );
|
|
|
|
|
CHECK( detour_transaction_commit() == err_none );
|
|
|
|
|
|
|
|
|
|
REQUIRE( realTestFunction != testFunction );
|
|
|
|
|
|
|
|
|
|
REQUIRE( testFunctionCounter == 1 );
|
|
|
|
|
REQUIRE( testFunctionDetourCounter == 0 );
|
|
|
|
|
REQUIRE( testFunction() == 94 );
|
|
|
|
|
REQUIRE( testFunctionCounter == 1 );
|
|
|
|
|
REQUIRE( testFunctionDetourCounter == 1 );
|
|
|
|
|
}
|