Last active
January 21, 2017 03:04
-
-
Save joshwatson/661d763f35f545bb6ee0f37731a79ec7 to your computer and use it in GitHub Desktop.
Binary Ninja IL Example: Navigating to a Virtual Function Based on an Indirect Call
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
// Simple virtual function example, based on http://www.cplusplus.com/doc/tutorial/polymorphism/ | |
// compiled with: | |
// x86_64 -> g++ virtual-test.cpp -o virtual-test | |
// arm -> arm-linux-gnueabi-g++ virtual-test.cpp -o virtual-test-arm | |
#include <iostream> | |
using namespace std; | |
class Polygon { | |
protected: | |
int width, height; | |
public: | |
void set_values (int a, int b) | |
{ width=a; height=b; } | |
virtual int area () | |
{ return 0; } | |
virtual int sides () | |
{ return 0; } | |
}; | |
class Rectangle: public Polygon { | |
public: | |
int area () | |
{ return width * height; } | |
int sides () | |
{ return 4; } | |
}; | |
class Triangle: public Polygon { | |
public: | |
int area () | |
{ return (width * height / 2); } | |
int sides () | |
{ return 3; } | |
}; | |
void printArea(Polygon* poly) | |
{ | |
cout << poly->area() << endl; | |
} | |
void printSides(Polygon* poly) | |
{ | |
cout << poly->sides() << endl; | |
} | |
int main () { | |
Rectangle rect; | |
Triangle trgl; | |
Polygon poly; | |
Polygon * ppoly1 = ▭ | |
Polygon * ppoly2 = &trgl; | |
Polygon * ppoly3 = &poly; | |
ppoly1->set_values(4,5); | |
ppoly2->set_values(4,5); | |
ppoly3->set_values(4,5); | |
printArea(ppoly1); | |
printSides(ppoly1); | |
printArea(ppoly2); | |
printArea(ppoly3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment