testing system function override

This commit is contained in:
Lysann Tranvouez 2025-10-02 22:41:33 +02:00
parent 1fbdb703eb
commit 5d833e2928
4 changed files with 28 additions and 2 deletions

View file

@ -3,6 +3,7 @@
add_executable(mach_detours_tests
test_dylib_function.cpp
test_local_function.cpp
test_system_function.cpp
test_transaction.cpp
)

View file

@ -14,7 +14,7 @@ static int libFunctionDetour()
return 94;
}
TEST_CASE( "Overriding custom function in dylib", "[dylib]" )
TEST_CASE( "Overriding custom function in dylib", "[attach][detach][dylib]" )
{
libFunctionCounter = 0;
libFunctionDetourCounter = 0;

View file

@ -18,7 +18,7 @@ int localFunctionDetour()
return 12;
}
TEST_CASE( "Overriding local function", "[local][attach]" )
TEST_CASE( "Overriding local function", "[attach][local]" )
{
localFunctionCounter = 0;
localFunctionDetourCounter = 0;

View file

@ -0,0 +1,25 @@
// Copyright (c) Lysann Tranvouez. All rights reserved.
#include <catch2/catch_test_macros.hpp>
#include <mach_detours.h>
char* (*realStrerror)(int) = strerror;
char* strerrorDetour(int errno)
{
return (char *)"strerrorOverride";
}
TEST_CASE( "Overriding system function", "[attach][system]" )
{
REQUIRE( std::string_view(strerror( 0 )) == "Undefined error: 0" );
REQUIRE( detour_transaction_begin() == err_none );
REQUIRE( detour_attach_and_commit(reinterpret_cast<detour_func_t*>(&realStrerror), reinterpret_cast<detour_func_t>(strerrorDetour)) == err_none );
CHECK( std::string_view(strerror( 0 )) == "strerrorOverride" );
// clean up
CHECK( detour_transaction_begin() == err_none );
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realStrerror), reinterpret_cast<detour_func_t>(strerrorDetour)) == err_none );
}