Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdlib.h>
#include <fstream>
#include <libIRDB-core.hpp>
#include <libgen.h>
#include "scfi_instr.hpp"
using namespace std;
using namespace libIRDB;
#define BINARY_NAME "a.ncexe"
#define SHARED_OBJECTS_DIR "shared_objects"
void usage(char* name)
{
cerr<<"Usage: "<<name<<" <variant_id>\n";
}
int main(int argc, char **argv)
{
if(argc != 2)
{
usage(argv[0]);
exit(1);
}
string programName(argv[0]);
int variantID = atoi(argv[1]);
VariantID_t *pidp=NULL;
/* setup the interface to the sql server */
pqxxDB_t pqxx_interface;
BaseObj_t::SetInterface(&pqxx_interface);
pidp=new VariantID_t(variantID);
assert(pidp->IsRegistered()==true);
cout<<"ret_shadow_stack.exe started\n";
bool one_success = false;
for(set<File_t*>::iterator it=pidp->GetFiles().begin();
it!=pidp->GetFiles().end();
++it)
{
File_t* this_file = *it;
FileIR_t *firp = new FileIR_t(*pidp, this_file);
cout<<"Transforming "<<this_file->GetURL()<<endl;
assert(firp && pidp);
try
{
SCFI_Instrument scfii(firp);
int success=scfii.execute();
if (success)
{
cout<<"Writing changes for "<<this_file->GetURL()<<endl;
one_success = true;
firp->WriteToDB();
delete firp;
}
else
{
cout<<"Skipping (no changes) "<<this_file->GetURL()<<endl;
}
}
catch (DatabaseError_t pnide)
{
cerr << programName << ": Unexpected database error: " << pnide << "file url: " << this_file->GetURL() << endl;
}
catch (...)
{
cerr << programName << ": Unexpected error file url: " << this_file->GetURL() << endl;
}
} // end file iterator
// if any integer transforms for any files succeeded, we commit
if (one_success)
{
cout<<"Commiting changes...\n";
pqxx_interface.Commit();
}
return 0;
}