Skip to content

Commit

Permalink
adding example and fix to parsing of double/float types!
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Feb 5, 2022
1 parent fc0d458 commit f7df3c1
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 75 deletions.
162 changes: 127 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ $ python -m venv env
$ source env/bin/activate
```

Compile the example

```bash
cd example
make
```

Then you can run Smeagle Python pointing at a binary.

```bash
$ python smeagle.py libtest.so
$ python smeagle.py example/libmath-v1.so
```
```
{
"library": "/home/vanessa/Desktop/Code/smeagle-python/libtest.so",
"library": "/home/vanessa/Desktop/Code/smeagle-python/example/libmath-v1.so",
"locations": [
{
"name": "_init",
"size": 27,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -34,6 +42,7 @@ $ python smeagle.py libtest.so
{
"name": "sub_401020",
"size": 13,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -45,6 +54,7 @@ $ python smeagle.py libtest.so
{
"name": "sub_40102d",
"size": 3,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -54,8 +64,20 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_401030",
"size": 15,
"name": "__cxa_finalize",
"size": 11,
"direction": "unknown"
},
{
"name": "deregister_tm_clones",
"size": 41,
"direction": "unknown",
"parameters": []
},
{
"name": "sub_401069",
"size": 7,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -65,8 +87,9 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_40103f",
"size": 1,
"name": "register_tm_clones",
"size": 57,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -76,21 +99,21 @@ $ python smeagle.py libtest.so
]
},
{
"name": "__cxa_finalize",
"size": 11
},
{
"name": "__printf_chk",
"size": 11
},
{
"name": "deregister_tm_clones",
"size": 41,
"parameters": []
"name": "sub_4010a9",
"size": 7,
"direction": "unknown",
"parameters": [
{
"type": "int",
"size": 32,
"location": "rax"
}
]
},
{
"name": "sub_401089",
"size": 7,
"name": "__do_global_dtors_aux",
"size": 54,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -100,8 +123,9 @@ $ python smeagle.py libtest.so
]
},
{
"name": "register_tm_clones",
"size": 57,
"name": "sub_4010e5",
"size": 3,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -111,8 +135,9 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_4010c9",
"name": "sub_4010e9",
"size": 7,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -122,8 +147,9 @@ $ python smeagle.py libtest.so
]
},
{
"name": "__do_global_dtors_aux",
"size": 54,
"name": "frame_dummy",
"size": 9,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -133,8 +159,9 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_401105",
"size": 3,
"name": "sub_4010f9",
"size": 1,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -144,9 +171,25 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_401109",
"size": 7,
"name": "_ZN11MathLibrary10Arithmetic3AddEdd",
"size": 30,
"direction": "export",
"parameters": [
{
"type": "void *",
"size": 64,
"location": "rdi"
},
{
"type": "double",
"size": 64,
"location": "xmm0"
},
{
"type": "double",
"size": 64,
"location": "xmm1"
},
{
"type": "int",
"size": 32,
Expand All @@ -155,9 +198,25 @@ $ python smeagle.py libtest.so
]
},
{
"name": "frame_dummy",
"size": 9,
"name": "_ZN11MathLibrary10Arithmetic8SubtractEdd",
"size": 30,
"direction": "export",
"parameters": [
{
"type": "void *",
"size": 64,
"location": "rdi"
},
{
"type": "double",
"size": 64,
"location": "xmm0"
},
{
"type": "double",
"size": 64,
"location": "xmm1"
},
{
"type": "int",
"size": 32,
Expand All @@ -166,9 +225,25 @@ $ python smeagle.py libtest.so
]
},
{
"name": "sub_401119",
"size": 7,
"name": "_ZN11MathLibrary10Arithmetic8MultiplyEdd",
"size": 30,
"direction": "export",
"parameters": [
{
"type": "void *",
"size": 64,
"location": "rdi"
},
{
"type": "double",
"size": 64,
"location": "xmm0"
},
{
"type": "double",
"size": 64,
"location": "xmm1"
},
{
"type": "int",
"size": 32,
Expand All @@ -177,9 +252,25 @@ $ python smeagle.py libtest.so
]
},
{
"name": "_Z7bigcallllllln",
"size": 54,
"name": "_ZN11MathLibrary10Arithmetic6DivideEdd",
"size": 30,
"direction": "export",
"parameters": [
{
"type": "void *",
"size": 64,
"location": "rdi"
},
{
"type": "double",
"size": 64,
"location": "xmm0"
},
{
"type": "double",
"size": 64,
"location": "xmm1"
},
{
"type": "int",
"size": 32,
Expand All @@ -190,6 +281,7 @@ $ python smeagle.py libtest.so
{
"name": "_fini",
"size": 13,
"direction": "unknown",
"parameters": [
{
"type": "int",
Expand All @@ -200,8 +292,8 @@ $ python smeagle.py libtest.so
}
]
}
```

Not perfect yet (I need to parse types recursively) but wow that was easy and I got
really far in an afternoon!

Expand Down
5 changes: 5 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
g++ -g -Wall -fPIC -shared -o libmath-v1.so MathLibrary.cpp
g++ -g -Wall -fPIC -shared -o libmath-v2.so MathLibraryChanged.cpp
g++ -g -Wall -o math-client MathClient.cpp -I . -L. libmath-v1.so

22 changes: 22 additions & 0 deletions example/MathClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// MathClient.cpp
// compile with: cl /EHsc MathClient.cpp /link MathLibrary.lib

#include <iostream>
#include "MathLibrary.h"

int main()
{
double a = 7.4;
int b = 99;

std::cout << "a + b = " <<
MathLibrary::Arithmetic::Add(a, b) << std::endl;
std::cout << "a - b = " <<
MathLibrary::Arithmetic::Subtract(a, b) << std::endl;
std::cout << "a * b = " <<
MathLibrary::Arithmetic::Multiply(a, b) << std::endl;
std::cout << "a / b = " <<
MathLibrary::Arithmetic::Divide(a, b) << std::endl;

return 0;
}
28 changes: 28 additions & 0 deletions example/MathLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// MathLibrary.cpp
// compile with: cl /c /EHsc MathLibrary.cpp
// post-build command: lib MathLibrary.obj

#include "MathLibrary.h"

namespace MathLibrary
{
double Arithmetic::Add(double a, double b)
{
return a + b;
}

double Arithmetic::Subtract(double a, double b)
{
return a - b;
}

double Arithmetic::Multiply(double a, double b)
{
return a * b;
}

double Arithmetic::Divide(double a, double b)
{
return a / b;
}
}
21 changes: 21 additions & 0 deletions example/MathLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// MathLibrary.h
#pragma once

namespace MathLibrary
{
class Arithmetic
{
public:
// Returns a + b
static double Add(double a, double b);

// Returns a - b
static double Subtract(double a, double b);

// Returns a * b
static double Multiply(double a, double b);

// Returns a / b
static double Divide(double a, double b);
};
}

0 comments on commit f7df3c1

Please sign in to comment.