mach-detours/tests/test_system_function.cpp

26 lines
874 B
C++
Raw Permalink Normal View History

2025-10-02 22:41:33 +02:00
// 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 );
}