Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complex lib target for private member fn hooking
This is slightly more complex than the basic target, because the private member function to be hooked / called makes use of `this`. That means an actual instance of the class must be constructed and setup according to the calling convention of the private function before the call can be made.
- Loading branch information
Showing
6 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/app/app_basic | ||
/app/app_complex | ||
/target/libtarget_basic.so | ||
/target/libtarget_complex.so | ||
/hooks/call_private_basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include "target_complex.hpp" | ||
|
||
int main(int argc, char **argv) { | ||
if(argc < 2) { | ||
std::cout << "Usage: " << argv[0] << " <integer>" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
int input = std::atoi(argv[1]); | ||
Target t = Target(); | ||
t.maybe_say(input); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
// Complex target with private member function | ||
// which *does* reference `this` to access private | ||
// member initialized by constructor. | ||
|
||
class Target { | ||
public: | ||
void maybe_say(int num); | ||
Target(); | ||
~Target(); | ||
|
||
private: | ||
void say_something(); | ||
const char *message; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include "target_complex.hpp" | ||
|
||
void __attribute__((__noinline__)) Target::say_something() { | ||
std::cout << this->message << std::endl; | ||
} | ||
|
||
void Target::maybe_say(int num) { | ||
if(num == std::rand()) { | ||
this->say_something(); | ||
} | ||
} | ||
|
||
Target::Target() { | ||
this->message = "This is really something!"; | ||
} | ||
|
||
Target::~Target() { | ||
this->message = NULL; | ||
} |