// Copyright (c) Lysann Tranvouez. All rights reserved. #include #include 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(&realStrerror), reinterpret_cast(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(&realStrerror), reinterpret_cast(strerrorDetour)) == err_none ); }