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

@ -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 );
}