Skip to content
Snippets Groups Projects
Commit 6f353f0f authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

1) change set of PSPATH to not overwrite previous settings, 2) name function...

1) change set of PSPATH to not overwrite previous settings, 2) name function with program entry point as "_start" 3) populate initial frame sizes
parent 91aa4fea
No related branches found
No related tags found
No related merge requests found
Pipeline #2530 passed
......@@ -664,6 +664,19 @@ int PopulateCFG::parseArgs(const vector<string> step_args)
return 0;
}
void PopulateCFG::rename_start(FileIR_t *firp)
{
for(auto f : firp->getFunctions())
{
const auto entry_point_insn = f->getEntryPoint();
if(!entry_point_insn) continue;
const auto entry_point_vo = entry_point_insn->getAddress()->getVirtualOffset();
if(entry_point_vo==elfiop->get_entry())
f->setName("_start");
}
}
int PopulateCFG::executeStep(IRDBObjects_t *const irdb_objects)
{
try
......@@ -688,6 +701,7 @@ int PopulateCFG::executeStep(IRDBObjects_t *const irdb_objects)
elfiop.reset(new exeio());
elfiop->load(string("readeh_tmp_file.exe"));
rename_start(firp);
fill_in_cfg(firp);
fill_in_scoops(firp);
detect_scoops_in_code(firp);
......
......@@ -48,6 +48,8 @@ class PopulateCFG : public IRDB_SDK::TransformStep_t
void fill_in_scoops(IRDB_SDK::FileIR_t *);
void detect_scoops_in_code(IRDB_SDK::FileIR_t *firp);
void fill_in_landing_pads(IRDB_SDK::FileIR_t *);
void rename_start(IRDB_SDK::FileIR_t *firp);
// helpers
void populate_instruction_map
......
......@@ -1048,6 +1048,7 @@ int executeStep(IRDBObjects_t *const irdb_objects)
// do eh_frame reading as required.
if(do_eh_frame)
read_ehframe(firp, elfiop);
setFrameSizes(firp);
fix_all_calls(firp,fix_all);
fix_other_pcrel(firp);
......@@ -1099,11 +1100,50 @@ bool possible_target(uintptr_t p, uintptr_t at, ibt_provenance_t prov)
}
std::string getStepName(void) const override
string getStepName(void) const override
{
return std::string("fix_calls");
}
void setFrameSizes(FileIR_t* firp)
{
for(auto func : firp->getFunctions())
{
if(func->getEntryPoint()==nullptr) continue;
const auto is_found_it=cfg_optimizer.find(func);
const auto is_found=(is_found_it!=end(cfg_optimizer));
if(!is_found)
/* build a cfg for this function */
cfg_optimizer[func]=shared_ptr<ControlFlowGraph_t>(move(ControlFlowGraph_t::factory(func)));
const auto cfg=cfg_optimizer[func].get();
const auto entry_block=cfg->getEntry();
auto pushes=0;
for(auto insn : entry_block->getInstructions())
{
const auto di=DecodedInstruction_t::factory(insn);
const auto mnemonic=di->getMnemonic();
if(mnemonic=="push")
pushes++;
if(mnemonic=="sub")
{
const auto hasop0 = di->hasOperand(0);
const auto op0_sp = hasop0 && (di->getOperand(0)->getString()=="rsp" || di->getOperand(0)->getString()=="esp");
const auto hasop1 = di->hasOperand(1);
const auto op1_const = hasop1 && di->getOperand(1)->isConstant();
if(op0_sp && op1_const)
{
func->setStackFrameSize(di->getOperand(1)->getConstant());
}
break;
}
}
}
}
}; // end class FixCalls_t
shared_ptr<TransformStep_t> curInvocation;
......
......@@ -76,15 +76,15 @@ class CreateFunctions_t
const auto cs_mode=
machine_type==mtAarch64 ? CS_MODE_LITTLE_ENDIAN :
file_class==ELF64 ? CS_MODE_64 :
file_class==ELF32 ? CS_MODE_32 :
throw std::runtime_error("Cannot handle ELF class");
file_class==ELF64 ? CS_MODE_64 :
file_class==ELF32 ? CS_MODE_32 :
throw std::runtime_error("Cannot handle ELF class");
const auto my_cs_arch =
machine_type == mtX86_64 ? CS_ARCH_X86 :
machine_type == mtI386 ? CS_ARCH_X86 :
machine_type == mtX86_64 ? CS_ARCH_X86 :
machine_type == mtI386 ? CS_ARCH_X86 :
machine_type == mtAarch64 ? CS_ARCH_ARM64 :
throw std::runtime_error("Cannot handle architecture");
throw std::runtime_error("Cannot handle architecture");
if (cs_open(my_cs_arch, cs_mode , &cshandle) != CS_ERR_OK)
{
......@@ -146,21 +146,30 @@ class CreateFunctions_t
auto unnamedFunctions=0U;
auto functions=0U;
const auto entryPointAddress=exeio.get_entry();
// set default names
for(const auto &func: sccs)
{
assert(func.begin() != func.end());
const auto first_range=*(func.begin());
const auto startAddr=first_range.first;
std::stringstream ss;
ss << "sub_" << hex << startAddr;
const auto name = ss.str();
functions++;
if(funcNames[func]=="") // destructive test OK, next line sets if empty.
if(entryPointAddress == startAddr)
{
unnamedFunctions++;
// override the elf entry point to be called _start
funcNames[func]="_start";
namedFunctions++;
}
else if(funcNames[func]=="") // destructive test OK, next line sets if empty.
{
std::stringstream ss;
ss << "sub_" << hex << startAddr;
const auto name = ss.str();
funcNames[func]=name;
unnamedFunctions++;
}
else
{
......
......@@ -8,7 +8,12 @@ export ZIPR_HOME=$PEASOUP_HOME/zipr
export ZIPR_SDK=$PEASOUP_HOME/zipr-sdk
export IRDB_SDK=$PEASOUP_HOME/irdb-sdk
export ZEST_RUNTIME=$PEASOUP_HOME/zest_runtime
export PSPATH=$PEASOUP_HOME/irdb-libs/plugins_install
# don't override pspath
if [[ -z $PSPATH ]]; then
export PSPATH=$PEASOUP_HOME/irdb-libs/plugins_install
fi
if [ -f manifest.txt ]; then
if [ -f $PS_INSTALL ]; then
......
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