Skip to content
Snippets Groups Projects
Commit 54f83b3f authored by an7s's avatar an7s
Browse files

Add utility to mark functions safe

Former-commit-id: d72a8eab27599f6b0e49f2fbfa0f819b0221d4c8
parent 9ca07960
No related branches found
No related tags found
No related merge requests found
......@@ -287,6 +287,7 @@ libIRDB/test/fix_calls.cpp -text
libIRDB/test/generate_spri.cpp -text
libIRDB/test/ilr.cpp -text
libIRDB/test/list_programs.cpp -text
libIRDB/test/mark_functions_safe.cpp -text
libIRDB/test/pin_address.cpp -text
libIRDB/test/print_variant.cpp -text
libIRDB/test/read_ehframe.cpp -text
......
......@@ -36,11 +36,10 @@ if 'build_tools' not in myenv or myenv['build_tools'] is None or int(myenv['buil
install=myenv.Install("$SECURITY_TRANSFORMS_HOME/bin/", pgm)
Default(install)
# most programs go to $sectrans/bin
pgms='''print_variant list_programs create_variant create_variantir read_variantir clone
drop_variant generate_spri fill_in_cfg unfix_calls
find_strings build_callgraph build_preds rename_function pin_address
find_strings build_callgraph build_preds rename_function pin_address mark_functions_safe
'''
for i in Split(pgms):
print "Registering pgm: "+ i
......@@ -54,6 +53,3 @@ if 'build_tools' not in myenv or myenv['build_tools'] is None or int(myenv['buil
install=myenv.Install("$SECURITY_TRANSFORMS_HOME/plugins_install/", pgm)
Default(install)
/*
* Copyright (c) 2014-2015 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
#include <libIRDB-core.hpp>
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace libIRDB;
using namespace std;
Function_t* findFunction(FileIR_t* firp, string funcName)
{
assert(firp);
for(
set<Function_t*>::iterator it=firp->GetFunctions().begin();
it!=firp->GetFunctions().end();
++it
)
{
Function_t* func=*it;
if (!func) continue;
if (func->GetName() == funcName)
{
return func;
}
}
return NULL;
}
void mark_function_safe(FileIR_t* firp, const std::string& function_file)
{
assert(firp);
std::ifstream ffile(function_file);
std::string fn;
while (std::getline(ffile, fn))
{
cerr << "Want to mark: " << fn << " as safe" << endl;
Function_t *f = findFunction(firp, fn);
if (f)
{
cerr << "Found in IRDB: Marking " << f->GetName() << " as safe" << endl;
f->SetSafe(true);
}
}
firp->WriteToDB();
}
main(int argc, char* argv[])
{
if(argc!=3)
{
cerr<<"Usage: mark_function_safe <id> <file_with_functions_to_mark_safe>"<<endl;
exit(-1);
}
VariantID_t *pidp=NULL;
FileIR_t *firp=NULL;
string function_files(argv[2]);
/* setup the interface to the sql server */
pqxxDB_t pqxx_interface;
BaseObj_t::SetInterface(&pqxx_interface);
cout<<"Reading variant "<<string(argv[1])<<" from database." << endl;
try
{
pidp=new VariantID_t(atoi(argv[1]));
assert(pidp->IsRegistered()==true);
for(set<File_t*>::iterator it=pidp->GetFiles().begin(); it!=pidp->GetFiles().end(); ++it)
{
File_t* this_file=*it;
assert(this_file);
// only do main file for now
if(this_file!=pidp->GetMainFile())
continue;
// read the db
firp=new FileIR_t(*pidp,this_file);
// mark as safe
mark_function_safe(firp, function_files);
delete firp;
}
pqxx_interface.Commit();
}
catch (DatabaseError_t pnide)
{
cout<<"Unexpected database error: "<<pnide<<endl;
exit(-1);
}
cout<<"Done!"<<endl;
delete pidp;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment