test calling through trampoline
This commit is contained in:
parent
7257abce71
commit
bf83e14d26
1 changed files with 53 additions and 0 deletions
|
|
@ -13,6 +13,11 @@ static int libFunctionDetour()
|
||||||
libFunctionDetourCounter++;
|
libFunctionDetourCounter++;
|
||||||
return 94;
|
return 94;
|
||||||
}
|
}
|
||||||
|
static int libFunctionDetourCallingReal()
|
||||||
|
{
|
||||||
|
libFunctionDetourCounter++;
|
||||||
|
return realLibFunction() + 94;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE( "Attaching custom function in dylib installs detour", "[attach][dylib]" )
|
TEST_CASE( "Attaching custom function in dylib installs detour", "[attach][dylib]" )
|
||||||
{
|
{
|
||||||
|
|
@ -48,6 +53,54 @@ TEST_CASE( "Attaching custom function in dylib installs detour", "[attach][dylib
|
||||||
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "We can call real function using the reassigned trampoline pointer", "[attach][dylib]" )
|
||||||
|
{
|
||||||
|
libFunctionCounter = 0;
|
||||||
|
libFunctionDetourCounter = 0;
|
||||||
|
|
||||||
|
REQUIRE( realLibFunction == libFunction );
|
||||||
|
REQUIRE( libFunction() == 42 );
|
||||||
|
REQUIRE( libFunctionCounter == 1 );
|
||||||
|
REQUIRE( libFunctionDetourCounter == 0 );
|
||||||
|
|
||||||
|
REQUIRE( detour_transaction_begin() == err_none );
|
||||||
|
CHECK( detour_attach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
||||||
|
|
||||||
|
CHECK( realLibFunction != libFunction );
|
||||||
|
CHECK( realLibFunction() == 42 );
|
||||||
|
CHECK( libFunctionCounter == 2 );
|
||||||
|
CHECK( libFunctionDetourCounter == 0 );
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
REQUIRE( detour_transaction_begin() == err_none );
|
||||||
|
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetour)) == err_none );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Detour function can call real function", "[attach][dylib]" )
|
||||||
|
{
|
||||||
|
libFunctionCounter = 0;
|
||||||
|
libFunctionDetourCounter = 0;
|
||||||
|
|
||||||
|
REQUIRE( realLibFunction == libFunction );
|
||||||
|
REQUIRE( libFunction() == 42 );
|
||||||
|
REQUIRE( libFunctionCounter == 1 );
|
||||||
|
REQUIRE( libFunctionDetourCounter == 0 );
|
||||||
|
|
||||||
|
REQUIRE( detour_transaction_begin() == err_none );
|
||||||
|
CHECK( detour_attach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetourCallingReal)) == err_none );
|
||||||
|
|
||||||
|
CHECK( realLibFunction != libFunction );
|
||||||
|
CHECK( libFunctionCounter == 1 );
|
||||||
|
CHECK( libFunctionDetourCounter == 0 );
|
||||||
|
CHECK( libFunction() == 94 + 42 );
|
||||||
|
CHECK( libFunctionCounter == 2 );
|
||||||
|
CHECK( libFunctionDetourCounter == 1 );
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
REQUIRE( detour_transaction_begin() == err_none );
|
||||||
|
CHECK( detour_detach_and_commit(reinterpret_cast<detour_func_t*>(&realLibFunction), reinterpret_cast<detour_func_t>(libFunctionDetourCallingReal)) == err_none );
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE( "Detaching custom function in dylib removes detour", "[detach][dylib]" )
|
TEST_CASE( "Detaching custom function in dylib removes detour", "[detach][dylib]" )
|
||||||
{
|
{
|
||||||
libFunctionCounter = 0;
|
libFunctionCounter = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue