Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/zipr
  • whh8b/zipr
2 results
Show changes
Commits on Source (5)
......@@ -550,9 +550,9 @@ void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::HandleMemoryOperand(De
auto to1 = (DataScoop_t*) NULL;
// examine the memory operation to see if there's a pc-rel
if ((*the_arg)->isMemory() /*the_arg->Memory.DisplacementAddr!=0*/ &&
if ((*the_arg)->isMemory() &&
(*the_arg)->hasMemoryDisplacement() &&
(*the_arg)->getMemoryDisplacementEncodingSize() /*Memory.DisplacementSize*/==4
(*the_arg)->getMemoryDisplacementEncodingSize() == 4
)
{
......@@ -607,7 +607,6 @@ void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::HandleMemoryOperand(De
<<hex<<to1->getEnd()->getVirtualOffset()<<")"<<endl;
}
//ApplyAbsoluteMemoryRelocation(insn,to1);
absolute_refs_to_scoops.insert({insn,to1});
}
}
......@@ -644,13 +643,12 @@ void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::HandleMemoryOperand(De
template <class T_Sym, class T_Rela, class T_Rel, class T_Dyn, class T_Extractor>
void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::ApplyPcrelMemoryRelocation(Instruction_t* insn, DataScoop_t* to)
{
//DISASM disasm;
//Disassemble(insn,disasm);
const auto disasmp=DecodedInstruction_t::factory(insn);
const auto &disasm=*disasmp;
auto operands=disasm.getOperands();
#if 1 // don't change instructions that reference re-pinned scoops.
#if 1
// don't change instructions that reference re-pinned scoops.
// This was necessary because we were not getting the zipr_unpin_plugin
// to undo our changes to the instruction in the case of a re-pinned scoop.
// That problem is fixed, but it is more efficient and safer to
......@@ -689,7 +687,8 @@ void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::ApplyAbsoluteMemoryRel
const auto &disasm=*disasmp;
auto operands=disasm.getOperands();
#if 1 // don't change instructions that reference re-pinned scoops.
#if 1
// don't change instructions that reference re-pinned scoops.
// This was necessary because we were not getting the zipr_unpin_plugin
// to undo our changes to the instruction in the case of a re-pinned scoop.
// That problem is fixed, but it is more efficient and safer to
......@@ -707,11 +706,6 @@ void MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::ApplyAbsoluteMemoryRel
unsigned int disp_offset=disasm.getMemoryDisplacementOffset(the_arg->get(),insn) /*the_arg->Memory.DisplacementAddr-disasm.EIP*/;
unsigned int disp_size=(*the_arg)->getMemoryDisplacementEncodingSize() /*the_arg->Memory.DisplacementSize*/;
assert(0<disp_offset && disp_offset<=insn->getDataBits().size() - disp_size);
/*
Relocation_t* reloc=new Relocation_t(BaseObj_t::NOT_IN_DATABASE, 0, "absoluteptr_to_scoop",to);
insn->getRelocations().insert(reloc);
getFileIR()->getRelocations().insert(reloc);
*/
auto reloc=getFileIR()->addNewRelocation(insn,0, "absoluteptr_to_scoop",to);
(void)reloc; // just giving to the ir
......@@ -728,45 +722,6 @@ DataScoop_t* MoveGlobals_t<T_Sym, T_Rela, T_Rel, T_Dyn, T_Extractor>::DetectAnno
if (!m_use_stars)
return nullptr;
#if 0
/* this looks a whle lot like:
const auto AnnotIterPair = getAnnotations().equal_range(insn->getBaseID());
const auto it=find_if(AnnotIterPair.first, AnnotIterPair.second, [&](const pair<DatabaseID_t,MEDS_AnnotationBase_t*> p)
{
const auto annotation = dynamic_cast<MEDS_MemoryRangeAnnotation*>(p.second);
return (annotation!=nullptr && annotation->isValid() && annotation->isStaticGlobalRange());
};
if(auto_it==AnnotIterPair.second)
return nullptr;
cout << "Memory range annotation found: " << annotation->toString() << endl;
const auto StartAddr = annotation->getRangeMin();
const auto VirtualOffset = (IRDB_SDK::VirtualOffset_t) StartAddr;
return this->findScoopByAddress(VirtualOffset);
I'm not entirely sure it's the same, but I think it would be.
Good coding guidelines prefer using stuff from <algorithm> (i.e., find_if) instead re-writing, which is more
likely to be buggy with maintenance in the future.
*/
auto ReferencedScoop = (DataScoop_t*)nullptr;
auto AnnotIterPair = getAnnotations().equal_range(insn->getBaseID());
for (auto it = AnnotIterPair.first; it != AnnotIterPair.second; ++it)
{
auto annotation = dynamic_cast<MEDS_MemoryRangeAnnotation*>(it->second);
if (annotation)
{
cout << "Memory range annotation found: " << annotation->toString() << endl;
if (annotation->isValid() && (annotation->isStaticGlobalRange() || annotation->isSentinel()))
{
// Get the scoop at which the annotated range begins.
const auto StartAddr = annotation->getRangeMin();
const auto VirtualOffset = (IRDB_SDK::VirtualOffset_t) StartAddr;
ReferencedScoop = this->findScoopByAddress(VirtualOffset);
}
}
} // end for all annotations for this instruction ID
#endif
const auto dgsr_it = deep_global_static_ranges->find(insn);
const auto dgsr_found = dgsr_it != deep_global_static_ranges->end();
const auto sentinel_it = sentinels->find(insn);
......
......@@ -46,6 +46,8 @@ extern void read_ehframe(FileIR_t* firp, EXEIO::exeio* );
class FixCalls_t : public TransformStep_t
{
const bool opt_fix_no_func_target=false;
const bool opt_fix_no_target = false;
public:
......@@ -148,10 +150,10 @@ bool call_needs_fix(Instruction_t* insn)
return false;
}
auto target=insn->getTarget();
auto fallthru=insn->getFallthrough();
const auto target=insn->getTarget();
const auto fallthru=insn->getFallthrough();
string pattern;
// string pattern;
// this used to work because fill_in_indirects would mark IBTs
// while reading the ehframe, which perfectly corresponds to when
......@@ -173,8 +175,8 @@ bool call_needs_fix(Instruction_t* insn)
return true;
}
auto addr=fallthru->getAddress()->getVirtualOffset();
auto rangeiter=eh_frame_ranges.find(Range_t(addr,addr));
const auto addr=fallthru->getAddress()->getVirtualOffset();
const auto rangeiter=eh_frame_ranges.find(Range_t(addr,addr));
if(rangeiter != eh_frame_ranges.end()) // found an eh_frame addr entry for this call
{
in_ehframe++;
......@@ -192,7 +194,7 @@ bool call_needs_fix(Instruction_t* insn)
if(!target)
{
/* call 0's aren't to real locations */
auto disasm=DecodedInstruction_t::factory(insn);
const auto disasm=DecodedInstruction_t::factory(insn);
if(disasm->getOperand(0)->isConstant() && disasm->getAddress()==0)
{
return false;
......@@ -207,17 +209,19 @@ bool call_needs_fix(Instruction_t* insn)
cout<<"Needs fix: No target instruction"<< " address="
<<hex<<addr<<": "<<insn->getDisassembly()<<endl;
}
/* then we need to fix it */
return true;
// then we might need to fix it
// but typically, we don't fix it because it's not really a valid isntruction.
return opt_fix_no_target;
}
/* if the location after the call is marked as an IBT, then
/*
* if the location after the call is marked as an IBT, then
* this location might be used for walking the stack
*/
auto func=target->getFunction();
const auto func=target->getFunction();
/* if there's no function for this instruction */
if(!func)
......@@ -232,7 +236,7 @@ bool call_needs_fix(Instruction_t* insn)
}
target_not_in_function++;
/* we need to fix it */
return true;
return opt_fix_no_func_target;
}
......
......@@ -72,37 +72,15 @@ static bool isPartOfGroup(const cs_insn* the_insn, const x86_insn_group the_grp)
static bool isJmp(cs_insn* the_insn)
{
return isPartOfGroup(the_insn,X86_GRP_JUMP);
}
#if 0
class CapstoneHandle_t
{
public:
CapstoneHandle_t(FileIR_t* firp=NULL)
{
const auto width=FileIR_t::getArchitectureBitWidth();
const auto mode = (width==64) ? CS_MODE_64: CS_MODE_32;
auto err = cs_open(CS_ARCH_X86, mode, &handle);
if (err)
{
const auto s=string("Failed on cs_open() with error returned: ")+to_string(err)+"\n";
throw std::runtime_error(s);
}
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL);
}
inline csh getHandle() { return handle; }
const auto is_jmp_grp = isPartOfGroup(the_insn,X86_GRP_JUMP);
const auto is_loop =
the_insn->id == X86_INS_LOOP ||
the_insn->id == X86_INS_LOOPE ||
the_insn->id == X86_INS_LOOPNE ;
private:
csh handle;
};
static CapstoneHandle_t *cs_handle=NULL;
#endif
return is_jmp_grp || is_loop;
}
template<class type>
static inline type insnToImmedHelper(cs_insn* the_insn, csh handle)
......
Subproject commit 653c5df9d09af46808330375a87bab2414fc3a02
Subproject commit b7d340e26d8c80b09fc31e0c9bb1d5e9ff1b62c5
Subproject commit c129d094ee5dd1704ad6e47b6b59b957a9dbc19c
Subproject commit 59b7b90668bda12f5af1e302df4e8c906aaa2188