testing system function override
This commit is contained in:
parent
1fbdb703eb
commit
5d833e2928
4 changed files with 28 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
add_executable(mach_detours_tests
|
add_executable(mach_detours_tests
|
||||||
test_dylib_function.cpp
|
test_dylib_function.cpp
|
||||||
test_local_function.cpp
|
test_local_function.cpp
|
||||||
|
test_system_function.cpp
|
||||||
test_transaction.cpp
|
test_transaction.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ static int libFunctionDetour()
|
||||||
return 94;
|
return 94;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Overriding custom function in dylib", "[dylib]" )
|
TEST_CASE( "Overriding custom function in dylib", "[attach][detach][dylib]" )
|
||||||
{
|
{
|
||||||
libFunctionCounter = 0;
|
libFunctionCounter = 0;
|
||||||
libFunctionDetourCounter = 0;
|
libFunctionDetourCounter = 0;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ int localFunctionDetour()
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Overriding local function", "[local][attach]" )
|
TEST_CASE( "Overriding local function", "[attach][local]" )
|
||||||
{
|
{
|
||||||
localFunctionCounter = 0;
|
localFunctionCounter = 0;
|
||||||
localFunctionDetourCounter = 0;
|
localFunctionDetourCounter = 0;
|
||||||
|
|
|
||||||
25
tests/test_system_function.cpp
Normal file
25
tests/test_system_function.cpp
Normal 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 );
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue