Commit 54812e2e authored by Jason Hiser's avatar Jason Hiser 🚜

updated license text to be right, and general formatting cleanups

parent 5cff0323
Pipeline #2675 passed with stages
in 11 minutes and 18 seconds
University of Virginia libEHP
University of Virginia IRDB Cookbook
Copyright 2017-2019 University of Virginia
This product includes software developed at
......
......@@ -13,19 +13,21 @@ This transform is only useful for demonstration and testing.
To build this, one must:
1. Download the IRDB's SDK and set the IRDB\_SDK environment variable appropriately. The IRDB SDK can be found [here](https://git.zephyr-software.com/opensrc/irdb-sdk).
1. Download the IRDB libraries and set IRDB\_LIBS environment variable appropriately. Documentation on obtaining the IRDB libraries is not yet available.
1. Download the IRDB SDK and set the IRDB\_SDK environment variable appropriately. The IRDB SDK can be found [here](https://git.zephyr-software.com/opensrc/irdb-sdk).
1. Download the IRDB libraries and set IRDB\_LIBS environment variable appropriately. Documentation on obtaining the IRDB libraries is not yet available.
1. Install g++ and scons.
1. Type `scons` to perform the build.
To use these transforms, one should:
1. set `PSPATH` to include `$COOKBOOK_HOME/plugins_install`, e.g. in `bash`:
1. Set the `PSPATH` environment variable to include `$COOKBOOK_HOME/plugins_install`, e.g. in `bash`:
```
export PSPATH=$PSPATH:$COOKBOOK_HOME/plugins_install
```
This can be achieved by `source set_env_vars` in bash, or the equivilent in your shell. Viewing `set_env_vars` is recommended.
1. Run run `ps_zipr.sh` with the proper step enabled, e.g.:
This step can be achieved by `source set_env_vars` in bash, or the equivilent in your shell. Reviewing `set_env_vars` is recommended for additional education.
1. Install and run `ps_zipr.sh` with the proper step enabled, e.g.:
/path/to/ps_zipr.sh --step stack_stamp /bin/ls ./ls.stamped
```
Documentation on obtaining ps_zipr is not yet available.
Documentation on obtaining, building and running ps_zipr is not yet available.
......@@ -32,12 +32,12 @@ irdb_env.Append(LIBPATH= Split(" $IRDB_LIBS " )) # this is
irdb_env.Replace(INSTALL_PATH=os.environ['PWD']+"/plugins_install" ) # this is where to place plugins.
#
# export the new environment for children subconstructs
# export the new environment for children sub-conscripts
#
Export('irdb_env')
#
# include the child sconscript files.
# include the children sconscript files.
#
dirs=Split("initialize_stack kill_deads stack_stamp")
libs = list()
......
......@@ -14,6 +14,10 @@
# limitations under the License.
#
#
# Scons is python based. We import OS to get at the environment.
#
import os
......@@ -23,11 +27,11 @@ import os
env=Environment()
#
# Include environment variables. These lines throw semi-readable errors if environment is not defined properly.
# Include environment variables. These lines throw semi-readable errors if the environment is not defined properly.
#
env.Replace(COOKBOOK_HOME=os.environ['COOKBOOK_HOME']) # add cookbook home var to env. for other scons files
env.Replace(IRDB_SDK=os.environ['IRDB_SDK']) # IRDB_SDK and IRDB_LIB by convention to find headers and libraries.
env.Replace(IRDB_LIBS=os.environ['IRDB_LIBS'])
env.Replace(IRDB_SDK= os.environ['IRDB_SDK'] ) # IRDB_SDK and IRDB_LIB by convention to find headers and libraries.
env.Replace(IRDB_LIBS= os.environ['IRDB_LIBS'] )
#
......@@ -44,14 +48,14 @@ env.Append(LINKFLAGS=" -Wl,-unresolved-symbols=ignore-in-shared-libs ") # irdb l
# if we are building in debug mode, use -g, else use -O
if int(env['debug']) == 1:
env.Append(CFLAGS=" -g ")
env.Append(CXXFLAGS=" -g ")
env.Append(LINKFLAGS=" -g ")
env.Append(CFLAGS= " -g ")
env.Append(CXXFLAGS= " -g ")
env.Append(LINKFLAGS= " -g ")
env.Append(SHLINKFLAGS=" -g ")
else:
env.Append(CFLAGS=" -O ")
env.Append(CXXFLAGS=" -O ")
env.Append(LINKFLAGS=" -O ")
env.Append(CFLAGS= " -O ")
env.Append(CXXFLAGS= " -O ")
env.Append(LINKFLAGS= " -O ")
env.Append(SHLINKFLAGS=" -O ")
......
......@@ -19,11 +19,15 @@
Import('irdb_env')
myenv=irdb_env.Clone()
#
# set input files and output program name
#
files=Glob( Dir('.').srcnode().abspath+"/*.cpp" )
pgm_name="initialize_stack.exe"
#
# build, install and return the program by default.
#
pgm=irdb_env.Program(pgm_name, files)
install=myenv.Install("$INSTALL_PATH/", pgm)
Default(install)
......
......@@ -59,17 +59,24 @@ InitStack_t::InitStack_t(FileIR_t *p_variantIR, const string& p_functions_filena
//
void InitStack_t::readFunctionsFromFile(const string &p_filename)
{
// get all functions for readability of the rest of the code
const auto &all_funcs=getFileIR()->getFunctions();
// open input file and check for successful open
ifstream functionsFile(p_filename); // can't use auto decl here because of lack of copy constructor in ifstream class
if (!functionsFile.is_open()) throw runtime_error("Cannot open "+p_filename);
// read each line of the input file.
auto line = string();
while(functionsFile >> line)
{
// locate a function with the name read from the file.
const auto func_it=find_if(ALLOF(all_funcs), [&](const Function_t* f)
{
return f->getName() == line;
});
// if found, log and insert it into the set to transform
if(func_it!=end(all_funcs))
{
auto f=*func_it;
......@@ -92,7 +99,7 @@ bool InitStack_t::execute()
for(auto f : m_funcs_to_init)
{
// todo: remove this
if (f->getName().substr(0, 1) == ".") continue; /* anh: ??? */
if (f->getName().substr(0, 1) == ".") continue;
initStack(f);
}
......
......@@ -41,10 +41,10 @@ namespace InitStack
public:
// construct an object
InitStack_t(
FileIR_t *p_variantIR, // the FileIR object to transform
FileIR_t *p_variantIR, // the FileIR object to transform
const string& p_function_filename, // the name of a file with functions to transform. "" -> no file and transform all functions
int init_value = 0, // the value to write when initializing the stack
bool p_verbose = false // use verbose logging?
bool p_verbose = false // use verbose logging?
);
// execute the transform
......
......@@ -37,8 +37,8 @@ void usage(char* p_name)
//
// The entry point for a stand-alone executable transform.
// Note: Thanos-enabled transforms are easier to write, faster to execute, and generally preferred,
// but stand-alone transforms may be useful if the transform has issues with memory leaks and/or memory errors.
// Note: Thanos-enabled transforms are easier to write, faster to execute, and generally preferred.
// Stand-alone transforms may be useful if the transform has issues with memory leaks and/or memory errors.
// Memory issues in a stand alone transform cannot affect correctness of other transforms.
//
int main(int argc, char **argv)
......@@ -120,7 +120,7 @@ int main(int argc, char **argv)
try
{
// Create and download the file's IR.
// Note: this is done differently than with thanos-enabled plugins
// Note: this is achieved differently with thanos-enabled plugins
auto firp = FileIR_t::factory(pidp.get(), this_file);
// sanity
......@@ -140,6 +140,8 @@ int main(int argc, char **argv)
// Stand alone trnasforms must manually write the IR back to the IRDB and commit the transactions
firp->writeToDB();
// and commit the the transaction to postgres
pqxx_interface->commit();
}
else
......
......@@ -23,7 +23,7 @@ using namespace std;
// constructor
KillDeads::KillDeads(FileIR_t *p_variantIR)
:
Transform_t(p_variantIR) // init transform class for insertAssembly and getFileIR
Transform_t(p_variantIR) // init Transform_t class for insertAssembly and getFileIR
{
// no other setup needed
}
......@@ -67,10 +67,10 @@ bool KillDeads::execute()
// find the dead registers for the instruction
const auto &regset=reg_map[insn];
// for each register that's dead
// for each register that is dead
for(auto reg : regset)
{
// if it's the x86 eflags register, kill it with a cmp instruction
// if it is the x86 eflags register, kill it with a cmp instruction
if (reg==rn_EFLAGS)
{
// for flags, do a random compare to change them
......@@ -81,7 +81,7 @@ bool KillDeads::execute()
killed_flags++;
}
// if it's an integer register
// if it is an integer register
if(is64bitRegister(reg) || is32bitRegister(reg) || is16bitRegister(reg) || is8bitRegister(reg))
{
// integer registers can be killed with a mov instruction
......
......@@ -32,7 +32,11 @@
class KillDeads : protected IRDB_SDK::Transform_t
{
public:
// construct the object, basically no parameters other than the IR to transform
KillDeads(IRDB_SDK::FileIR_t *p_variantIR);
// actually perform the transform
bool execute();
private:
......
......@@ -93,8 +93,10 @@ class KillDeadsDriver_t : public IRDB_SDK::TransformStep_t
}
private:
const string program_name = string("kill_deads");
int variantID = BaseObj_t::NOT_IN_DATABASE;
// data
const string program_name = string("kill_deads"); // constant program name
// methods
//
// optional: print using info for this transform.
......
......@@ -99,7 +99,6 @@ bool StackStamp_t::can_stamp(Function_t* f)
const auto target=insn->getTarget();
const auto icfs=insn->getIBTargets();
//
// Check to see if this is a "fixed" call. A fixed call is an x86 call instruction that's been split into a
// push/jmp pair. The push/jmp pair can be relocated to any address without changing the value pushed on the stack.
......@@ -183,7 +182,6 @@ bool StackStamp_t::can_stamp(Function_t* f)
}
};
//
// Hack alert!
// The yylex function is a problem in AWS so we return false. No additional detail is available.
......
......@@ -22,7 +22,7 @@
#include <memory>
//
// using a namespace for clarity
// using a namespace for code readability
//
namespace Stamper
{
......
......@@ -32,7 +32,7 @@ using namespace Stamper;
//
// A thanos-enabled driver to "stamp" (xor) return addresses on the stack
//
class StackStampDriver_t : public IRDB_SDK::TransformStep_t
class StackStampDriver_t : public TransformStep_t
{
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment