Skip to content
Snippets Groups Projects
Commit 716d86d8 authored by whh8b's avatar whh8b
Browse files

Deleting files that should be in arch-specific directory.


Former-commit-id: b6f0535a3f33d92f07e0bdf18d71e1d0315e86d1
parent a070d807
No related branches found
No related tags found
No related merge requests found
......@@ -995,15 +995,12 @@ tools/cookbook/SConscript -text
tools/cookbook/SConstruct -text
tools/cookbook/checkwhitelist.hpp -text
tools/cookbook/checkwhitelistdriver.cpp -text
tools/cookbook/cookbook.cpp -text
tools/cookbook/cookbook.hpp -text
tools/cookbook/functioncall.hpp -text
tools/cookbook/functioncalldriver.cpp -text
tools/cookbook/instructioncount.cpp -text
tools/cookbook/instructioncount.hpp -text
tools/cookbook/instructioncountdriver.cpp -text
tools/cookbook/logdriver.cpp -text
tools/cookbook/syscall.cpp -text
tools/cookbook/syscall.hpp -text
tools/cookbook/syscalldriver.cpp -text
tools/cookbook/whitelist.hpp -text
......
#include "cookbook.hpp"
#include <assert.h>
using namespace libTransform;
void CookbookTransform::addCookbookCallback(Instruction_t *original,
string callback)
{
Instruction_t *start = NULL;
Instruction_t *rsp_save = NULL;
Instruction_t *rsp_restore = NULL;
Instruction_t *orig = NULL;
Instruction_t *call = NULL;
start = addNewAssembly("nop");
rsp_save = allocateNewInstruction(
original->GetAddress()->GetFileID(), original->GetFunction());
start->SetFallthrough(rsp_save);
/*
* Now, insert the "start" instruction
* before the original instruction. We
* will chain the remainder of our new
* instructions from start.
*
* This function returns a new Instruction_t
* for the original instruction which we
* want to use from now on.
*/
orig = carefullyInsertBefore(original, start);
start->SetFallthrough(rsp_save);
/*
* Use the so-called Red Zone
* for the invocation of the callback
* function.
*/
setAssembly(rsp_save, "lea rsp, [rsp-128]");
/*
* Call the callback.
*/
call = allocateNewInstruction(original->GetAddress()->GetFileID(),
original->GetFunction());
setAssembly(call, "call 0");
call->SetComment("call " + callback + " before original.");
addCallbackHandler64(call, callback, 2);
/*
* Chain the rsp save operation
* to the call.
*/
rsp_save->SetFallthrough(call);
/*
* Restore rsp to its previous location.
*/
rsp_restore = addNewAssembly(call, "lea rsp, [rsp+128]");
/*
* Finish the chain:
* call -> rsp restore
* rsp restore -> original instruction
*/
call->SetFallthrough(rsp_restore);
rsp_restore->SetFallthrough(orig);
}
#include "instructioncount.hpp"
#include <assert.h>
using namespace libTransform;
InstructionCount::InstructionCount(VariantID_t *p_variantID, FileIR_t *p_variantIR, set<std::string> *p_filteredFunctions) : Transform(p_variantID, p_variantIR, p_filteredFunctions)
{
}
int InstructionCount::execute()
{
for(
set<Function_t*>::const_iterator itf=getFileIR()->GetFunctions().begin();
itf!=getFileIR()->GetFunctions().end();
++itf
)
{
Function_t* func=*itf;
for(
set<Instruction_t*>::const_iterator it=func->GetInstructions().begin();
it!=func->GetInstructions().end();
++it)
{
Instruction_t* insn = *it;
if(insn&& insn->GetAddress())
{
if (insn!=NULL&&insn->GetFallthrough()!=NULL)
{
string count_instruction = string("count_instruction");
Instruction_t *start = NULL;
Instruction_t *rsp_save = NULL;
Instruction_t *rsp_restore = NULL;
Instruction_t *orig = NULL;
Instruction_t *call = NULL;
start = addNewAssembly("nop");
rsp_save = allocateNewInstruction(
insn->GetAddress()->GetFileID(), insn->GetFunction());
start->SetFallthrough(rsp_save);
/*
* Now, insert the "start" instruction
* before the original instruction. We
* will chain the remainder of our new
* instructions from start.
*
* This function returns a new Instruction_t
* for the original instruction which we
* want to use from now on.
*/
orig = carefullyInsertBefore(insn, start);
start->SetFallthrough(rsp_save);
/*
* Use the so-called Red Zone
* for the invocation of the callback
* function.
*/
setAssembly(rsp_save, "lea rsp, [rsp-128]");
/*
* Call the callback.
*/
call = allocateNewInstruction(insn->GetAddress()->GetFileID(),
insn->GetFunction());
setAssembly(call, "call 0");
call->SetComment("call " + count_instruction + " before original.");
addCallbackHandler64(call, count_instruction, 2);
/*
* Chain the rsp save operation
* to the call.
*/
rsp_save->SetFallthrough(call);
/*
* Restore rsp to its previous location.
*/
rsp_restore = addNewAssembly(call, "lea rsp, [rsp+128]");
/*
* Finish the chain:
* call -> rsp restore
* rsp restore -> original instruction
*/
call->SetFallthrough(rsp_restore);
rsp_restore->SetFallthrough(orig);
}
}
}
}
return 0;
}
#include "syscall.hpp"
#include <assert.h>
using namespace libTransform;
SyscallPlay::SyscallPlay(VariantID_t *p_variantID, FileIR_t *p_variantIR, set<std::string> *p_filteredFunctions) : CookbookTransform(p_variantID, p_variantIR, p_filteredFunctions)
{
}
int SyscallPlay::execute()
{
for(
set<Function_t*>::const_iterator itf=getFileIR()->GetFunctions().begin();
itf!=getFileIR()->GetFunctions().end();
++itf
)
{
Function_t* func=*itf;
for(
set<Instruction_t*>::const_iterator it=func->GetInstructions().begin();
it!=func->GetInstructions().end();
++it)
{
Instruction_t* insn = *it;
if(insn /*&& insn->GetAddress()*/)
{
if (insn!=NULL&&insn->GetFallthrough()!=NULL)
{
string syscall_callback = string("syscall_callback");
unsigned char dbs[2] = {0,};
dbs[0] = insn->GetDataBits()[0];
dbs[1] = insn->GetDataBits()[1];
/*
* syscall is two byte instruction
* on x64.
*/
if (dbs[0] == 0x0f && dbs[1] == 0x05 )
{
addCookbookCallback(insn, syscall_callback);
}
}
}
}
}
return 0;
}
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