From b32c70934964b3da0d6d1fe917c69653e5e65d84 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Tue, 29 Jan 2019 15:44:15 -0500
Subject: [PATCH] revised edt tests to work with irdb-sdk

Former-commit-id: c27b08f85e91e3c01c8336779ba997f6c89dcce6
---
 libElfDep/test/SConscript     |  2 ++
 libElfDep/test/edt.cpp        | 18 ++++++++----------
 libElfDep/test/edt.hpp        |  4 ++--
 libElfDep/test/edt_driver.cpp | 29 +++++++++++++----------------
 4 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/libElfDep/test/SConscript b/libElfDep/test/SConscript
index e457589bc..332192d32 100644
--- a/libElfDep/test/SConscript
+++ b/libElfDep/test/SConscript
@@ -9,10 +9,12 @@ myenv=env.Clone()
 myenv.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME'])
 myenv.Replace(ZIPR_HOME=os.environ['ZIPR_HOME'])
 myenv.Replace(ZIPR_SDK=os.environ['ZIPR_SDK'])
+myenv.Replace(IRDB_SDK=os.environ['IRDB_SDK'])
 myenv.Replace(ZIPR_INSTALL=os.environ['ZIPR_INSTALL'])
 myenv.Replace(CXXFLAGS = " -g -std=c++11 -Wall ")
 
 cpppath=''' 
+	 $IRDB_SDK/include 
 	 $SECURITY_TRANSFORMS_HOME/include 
 	 $SECURITY_TRANSFORMS_HOME/libIRDB/include 
 	 $SECURITY_TRANSFORMS_HOME/libMEDSannotation/include 
diff --git a/libElfDep/test/edt.cpp b/libElfDep/test/edt.cpp
index 77cff3e41..5aba58362 100644
--- a/libElfDep/test/edt.cpp
+++ b/libElfDep/test/edt.cpp
@@ -1,11 +1,11 @@
 
 #include "edt.hpp"
 #include <libElfDep.hpp>
-#include "Rewrite_Utility.hpp"
+#include <Rewrite_Utility.hpp>
 #include <algorithm> 
 
 using namespace libTransform;
-using namespace libIRDB;
+using namespace IRDB_SDK;
 using namespace std;
 using namespace IRDBUtility;
 using namespace ElfDep_Tester;
@@ -23,7 +23,7 @@ ElfDep_Tester_t::ElfDep_Tester_t(FileIR_t* firp)
 int ElfDep_Tester_t::execute()
 {
 	// insert the PLT and GOT entries needed
-	auto ed=ElfDependencies_t(getFileIR());
+	auto ed=libIRDB::ElfDependencies_t(getFileIR());
 	(void)ed.appendLibraryDepedencies("libelf_dep_test.so");
 	auto edpcb=ed.appendPltEntry("elf_dep_test_callback");
 	auto edvar=ed.appendGotEntry("elf_dep_test_var");
@@ -32,11 +32,11 @@ int ElfDep_Tester_t::execute()
 
 
 	// find the insertion point.
-	const auto &all_funcs=getFileIR()->GetFunctions();
-	const auto main_func_it=find_if(ALLOF(all_funcs), [&](const Function_t* f) { return f->GetName()=="main";});
+	const auto &all_funcs=getFileIR()->getFunctions();
+	const auto main_func_it=find_if(ALLOF(all_funcs), [&](const Function_t* f) { return f->getName()=="main";});
 	assert(main_func_it!=all_funcs.end());		
 	const auto main_func=*main_func_it;
-	auto insert_loc=main_func->GetEntryPoint();
+	auto insert_loc=main_func->getEntryPoint();
 
 
 	// insert the instrumentation
@@ -61,10 +61,8 @@ int ElfDep_Tester_t::execute()
 
 
 	// map the load to point at the GOT entry.
-	auto got_reloc=new Relocation_t(BaseObj_t::NOT_IN_DATABASE, edvar_offset, "pcrel", edvar_scoop);
-	getFileIR()->GetRelocations().insert(got_reloc);
-	got_insn->GetRelocations().insert(got_reloc);
-
+	auto got_reloc=getFileIR()->addNewRelocation(got_insn, edvar_offset, "pcrel", edvar_scoop);
+	(void)got_reloc; // just give to IR
 
 	return 0;
 }
diff --git a/libElfDep/test/edt.hpp b/libElfDep/test/edt.hpp
index 32ec20779..10ed68b5c 100644
--- a/libElfDep/test/edt.hpp
+++ b/libElfDep/test/edt.hpp
@@ -1,14 +1,14 @@
 
 #include <string>
 #include <set>
-#include <libIRDB-core.hpp>
+#include <irdb-core>
 #include <transform.hpp>
 
 namespace ElfDep_Tester
 {
 
 using namespace libTransform;
-using namespace libIRDB;
+using namespace IRDB_SDK;
 using namespace std;
 
 
diff --git a/libElfDep/test/edt_driver.cpp b/libElfDep/test/edt_driver.cpp
index 6a9133c25..52d836f47 100644
--- a/libElfDep/test/edt_driver.cpp
+++ b/libElfDep/test/edt_driver.cpp
@@ -2,11 +2,11 @@
 #include <fstream>
 #include <string>
 #include "edt.hpp"
-#include <libIRDB-core.hpp>
+#include <irdb-core>
 #include <getopt.h>
 
 using namespace std;
-using namespace libIRDB;
+using namespace IRDB_SDK;
 using namespace ElfDep_Tester;
 
 void usage(string programName)
@@ -21,8 +21,7 @@ int main(int argc, char **argv)
 	char *strtolError = NULL;
 	int transformExitCode = 0;
 	int variantID = -1; 
-	VariantID_t *pidp = NULL;
-	pqxxDB_t pqxx_interface;
+	auto pqxx_interface=pqxxDB_t::factory();
 	int exit_code=0;
 
 	/*
@@ -69,21 +68,21 @@ int main(int argc, char **argv)
 
 
 	/* setup the interface to the sql server */
-	BaseObj_t::SetInterface(&pqxx_interface);
+	BaseObj_t::setInterface(pqxx_interface.get());
 
-	pidp=new VariantID_t(variantID);
-	assert(pidp && pidp->IsRegistered()==true);
+	auto pidp=VariantID_t::factory(variantID);
+	assert(pidp && pidp->isRegistered()==true);
 
-	for(set<File_t*>::iterator it=pidp->GetFiles().begin();
-	    it!=pidp->GetFiles().end();
+	for(set<File_t*>::iterator it=pidp->getFiles().begin();
+	    it!=pidp->getFiles().end();
 		++it)
 	{
 		try 
 		{
 			/* read the IR from the DB */
 			File_t* this_file = *it;
-			FileIR_t *firp = new FileIR_t(*pidp, this_file);
-			cout<<"Transforming "<<this_file->GetURL()<<endl;
+			auto firp = FileIR_t::factory(pidp.get(), this_file);
+			cout<<"Transforming "<<this_file->getURL()<<endl;
 			assert(firp && pidp);
 
 
@@ -91,7 +90,7 @@ int main(int argc, char **argv)
 			 * Create a transformation and then
 			 * invoke its execution.
 			 */
-				auto ed=ElfDep_Tester_t(firp);
+				auto ed=ElfDep_Tester_t(firp.get());
 				transformExitCode = ed.execute();
 			/*
 			 * If everything about the transformation
@@ -102,9 +101,8 @@ int main(int argc, char **argv)
 			{
 				if(getenv("MG_NOUPDATE")==NULL)
 				{
-					firp->WriteToDB();
+					firp->writeToDB();
 				}
-				delete firp;
 			}
 			else
 			{
@@ -129,8 +127,7 @@ int main(int argc, char **argv)
 			exit(1);
 		}
 	}
-	pqxx_interface.Commit();
-	delete pidp;
+	pqxx_interface->commit();
 
 	return exit_code;
 }
-- 
GitLab