41 lines
No EOL
903 B
C++
41 lines
No EOL
903 B
C++
// Copyright (c) Lysann Tranvouez. All rights reserved.
|
|
|
|
#include <cassert>
|
|
#include <cstring>
|
|
|
|
#include "mach_detours.h"
|
|
|
|
char* (*real_strerror)(int errno) = strerror;
|
|
|
|
static int counter = 0;
|
|
|
|
char* my_strerror(const int errno)
|
|
{
|
|
counter++;
|
|
return real_strerror(errno);
|
|
}
|
|
|
|
int main(int argc, const char* argv[])
|
|
{
|
|
counter = 0;
|
|
strerror(0);
|
|
assert(counter == 0);
|
|
|
|
detour_transaction_begin();
|
|
detour_attach(reinterpret_cast<detour_func_t*>(&real_strerror), reinterpret_cast<detour_func_t>(my_strerror));
|
|
detour_transaction_commit();
|
|
|
|
assert(counter == 0);
|
|
strerror(0);
|
|
assert(counter == 1);
|
|
|
|
detour_transaction_begin();
|
|
detour_detach(reinterpret_cast<detour_func_t*>(&real_strerror), reinterpret_cast<detour_func_t>(my_strerror));
|
|
detour_transaction_commit();
|
|
|
|
assert(counter == 1);
|
|
strerror(0);
|
|
assert(counter == 1);
|
|
|
|
return 0;
|
|
} |