mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
Rename JumpTable mostcommon
This commit is contained in:
parent
ad005086ab
commit
6a3d7cd03e
3 changed files with 15 additions and 15 deletions
|
@ -610,8 +610,8 @@ void Funcdata::installSwitchDefaults(void)
|
||||||
PcodeOp *indop = jt->getIndirectOp();
|
PcodeOp *indop = jt->getIndirectOp();
|
||||||
BlockBasic *ind = indop->getParent();
|
BlockBasic *ind = indop->getParent();
|
||||||
// Mark any switch blocks default edge
|
// Mark any switch blocks default edge
|
||||||
if (jt->getMostCommon() != -1) // If a mostcommon was found
|
if (jt->getDefaultBlock() != -1) // If a default case is present
|
||||||
ind->setDefaultSwitch(jt->getMostCommon());
|
ind->setDefaultSwitch(jt->getDefaultBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1193,7 +1193,7 @@ bool JumpBasic::foldInOneGuard(Funcdata *fd,GuardRecord &guard,JumpTable *jump)
|
||||||
indpath = 1 - indpath; // get actual path to indirect block
|
indpath = 1 - indpath; // get actual path to indirect block
|
||||||
BlockBasic *guardtarget = (BlockBasic *)cbranchblock->getOut(1-indpath);
|
BlockBasic *guardtarget = (BlockBasic *)cbranchblock->getOut(1-indpath);
|
||||||
bool change = false;
|
bool change = false;
|
||||||
uint4 pos;
|
int4 pos;
|
||||||
|
|
||||||
// Its possible the guard branch has been converted between the switch recovery and now
|
// Its possible the guard branch has been converted between the switch recovery and now
|
||||||
if (cbranchblock->sizeOut() != 2) return false; // In which case, we can't fold it in
|
if (cbranchblock->sizeOut() != 2) return false; // In which case, we can't fold it in
|
||||||
|
@ -1218,7 +1218,7 @@ bool JumpBasic::foldInOneGuard(Funcdata *fd,GuardRecord &guard,JumpTable *jump)
|
||||||
// is a good indicator that there are none
|
// is a good indicator that there are none
|
||||||
uintb val = ((indpath==0)!=(cbranch->isBooleanFlip())) ? 0 : 1;
|
uintb val = ((indpath==0)!=(cbranch->isBooleanFlip())) ? 0 : 1;
|
||||||
fd->opSetInput(cbranch,fd->newConstant(cbranch->getIn(0)->getSize(),val),1);
|
fd->opSetInput(cbranch,fd->newConstant(cbranch->getIn(0)->getSize(),val),1);
|
||||||
jump->setMostCommonBlock(pos); // A guard branch must be most common
|
jump->setDefaultBlock(pos); // A guard branch generally targets the default case
|
||||||
guard.clear();
|
guard.clear();
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
|
@ -2003,9 +2003,9 @@ Varnode *JumpAssisted::foldInNormalization(Funcdata *fd,PcodeOp *indop)
|
||||||
bool JumpAssisted::foldInGuards(Funcdata *fd,JumpTable *jump)
|
bool JumpAssisted::foldInGuards(Funcdata *fd,JumpTable *jump)
|
||||||
|
|
||||||
{
|
{
|
||||||
int4 origVal = jump->getMostCommon();
|
int4 origVal = jump->getDefaultBlock();
|
||||||
jump->setLastAsMostCommon(); // Default case is always the last block
|
jump->setLastAsMostCommon(); // Default case is always the last block
|
||||||
return (origVal != jump->getMostCommon());
|
return (origVal != jump->getDefaultBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
JumpModel *JumpAssisted::clone(JumpTable *jt) const
|
JumpModel *JumpAssisted::clone(JumpTable *jt) const
|
||||||
|
@ -2148,7 +2148,7 @@ JumpTable::JumpTable(Architecture *g,Address ad)
|
||||||
origmodel = (JumpModel *)0;
|
origmodel = (JumpModel *)0;
|
||||||
indirect = (PcodeOp *)0;
|
indirect = (PcodeOp *)0;
|
||||||
switchVarConsume = ~((uintb)0);
|
switchVarConsume = ~((uintb)0);
|
||||||
mostcommon = -1;
|
defaultBlock = -1;
|
||||||
lastBlock = -1;
|
lastBlock = -1;
|
||||||
maxtablesize = 1024;
|
maxtablesize = 1024;
|
||||||
maxaddsub = 1;
|
maxaddsub = 1;
|
||||||
|
@ -2169,7 +2169,7 @@ JumpTable::JumpTable(const JumpTable *op2)
|
||||||
origmodel = (JumpModel *)0;
|
origmodel = (JumpModel *)0;
|
||||||
indirect = (PcodeOp *)0;
|
indirect = (PcodeOp *)0;
|
||||||
switchVarConsume = ~((uintb)0);
|
switchVarConsume = ~((uintb)0);
|
||||||
mostcommon = -1;
|
defaultBlock = -1;
|
||||||
lastBlock = op2->lastBlock;
|
lastBlock = op2->lastBlock;
|
||||||
maxtablesize = op2->maxtablesize;
|
maxtablesize = op2->maxtablesize;
|
||||||
maxaddsub = op2->maxaddsub;
|
maxaddsub = op2->maxaddsub;
|
||||||
|
@ -2265,7 +2265,7 @@ int4 JumpTable::getIndexByBlock(const FlowBlock *bl,int4 i) const
|
||||||
void JumpTable::setLastAsMostCommon(void)
|
void JumpTable::setLastAsMostCommon(void)
|
||||||
|
|
||||||
{
|
{
|
||||||
mostcommon = lastBlock;
|
defaultBlock = lastBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is used to add address targets from guard branches if they are
|
/// This is used to add address targets from guard branches if they are
|
||||||
|
@ -2312,7 +2312,7 @@ void JumpTable::switchOver(const FlowInfo &flow)
|
||||||
lastBlock = block2addr.back().blockPosition; // Out-edge of last address in table
|
lastBlock = block2addr.back().blockPosition; // Out-edge of last address in table
|
||||||
sort(block2addr.begin(),block2addr.end());
|
sort(block2addr.begin(),block2addr.end());
|
||||||
|
|
||||||
mostcommon = -1; // There is no "mostcommon"
|
defaultBlock = -1; // There is no default case initially
|
||||||
int4 maxcount = 1; // If the maxcount is less than 2
|
int4 maxcount = 1; // If the maxcount is less than 2
|
||||||
vector<IndexPair>::const_iterator iter = block2addr.begin();
|
vector<IndexPair>::const_iterator iter = block2addr.begin();
|
||||||
while(iter != block2addr.end()) {
|
while(iter != block2addr.end()) {
|
||||||
|
@ -2326,7 +2326,7 @@ void JumpTable::switchOver(const FlowInfo &flow)
|
||||||
iter = nextiter;
|
iter = nextiter;
|
||||||
if (count > maxcount) {
|
if (count > maxcount) {
|
||||||
maxcount = count;
|
maxcount = count;
|
||||||
mostcommon = curPos;
|
defaultBlock = curPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2368,7 +2368,7 @@ void JumpTable::trivialSwitchOver(void)
|
||||||
for(uint4 i=0;i<parent->sizeOut();++i)
|
for(uint4 i=0;i<parent->sizeOut();++i)
|
||||||
block2addr.push_back(IndexPair(i,i)); // Addresses corresponds exactly to out-edges of switch block
|
block2addr.push_back(IndexPair(i,i)); // Addresses corresponds exactly to out-edges of switch block
|
||||||
lastBlock = parent->sizeOut()-1;
|
lastBlock = parent->sizeOut()-1;
|
||||||
mostcommon = -1; // There is no "mostcommon"
|
defaultBlock = -1; // Trivial case does not have default case
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The addresses that the raw BRANCHIND op might branch to itself are recovered,
|
/// The addresses that the raw BRANCHIND op might branch to itself are recovered,
|
||||||
|
|
|
@ -510,7 +510,7 @@ class JumpTable {
|
||||||
Address opaddress; ///< Absolute address of the BRANCHIND jump
|
Address opaddress; ///< Absolute address of the BRANCHIND jump
|
||||||
PcodeOp *indirect; ///< CPUI_BRANCHIND linked to \b this jump-table
|
PcodeOp *indirect; ///< CPUI_BRANCHIND linked to \b this jump-table
|
||||||
uintb switchVarConsume; ///< Bits of the switch variable being consumed
|
uintb switchVarConsume; ///< Bits of the switch variable being consumed
|
||||||
int4 mostcommon; ///< The out-edge corresponding to the most common address in the address table
|
int4 defaultBlock; ///< The out-edge corresponding to the \e default switch destination (-1 = undefined)
|
||||||
int4 lastBlock; ///< Block out-edge corresponding to last entry in the address table
|
int4 lastBlock; ///< Block out-edge corresponding to last entry in the address table
|
||||||
uint4 maxtablesize; ///< Maximum table size we allow to be built (sanity check)
|
uint4 maxtablesize; ///< Maximum table size we allow to be built (sanity check)
|
||||||
uint4 maxaddsub; ///< Maximum ADDs or SUBs to normalize
|
uint4 maxaddsub; ///< Maximum ADDs or SUBs to normalize
|
||||||
|
@ -534,7 +534,7 @@ public:
|
||||||
int4 getStage(void) const { return recoverystage; } ///< Return what stage of recovery this jump-table is in.
|
int4 getStage(void) const { return recoverystage; } ///< Return what stage of recovery this jump-table is in.
|
||||||
int4 numEntries(void) const { return addresstable.size(); } ///< Return the size of the address table for \b this jump-table
|
int4 numEntries(void) const { return addresstable.size(); } ///< Return the size of the address table for \b this jump-table
|
||||||
uintb getSwitchVarConsume(void) const { return switchVarConsume; } ///< Get bits of switch variable consumed by \b this table
|
uintb getSwitchVarConsume(void) const { return switchVarConsume; } ///< Get bits of switch variable consumed by \b this table
|
||||||
int4 getMostCommon(void) const { return mostcommon; } ///< Get the out-edge corresponding to the most common address table entry
|
int4 getDefaultBlock(void) const { return defaultBlock; } ///< Get the out-edge corresponding to the \e default switch destination
|
||||||
const Address &getOpAddress(void) const { return opaddress; } ///< Get the address of the BRANCHIND for the switch
|
const Address &getOpAddress(void) const { return opaddress; } ///< Get the address of the BRANCHIND for the switch
|
||||||
PcodeOp *getIndirectOp(void) const { return indirect; } ///< Get the BRANCHIND PcodeOp
|
PcodeOp *getIndirectOp(void) const { return indirect; } ///< Get the BRANCHIND PcodeOp
|
||||||
void setIndirectOp(PcodeOp *ind) { opaddress = ind->getAddr(); indirect = ind; } ///< Set the BRANCHIND PcodeOp
|
void setIndirectOp(PcodeOp *ind) { opaddress = ind->getAddr(); indirect = ind; } ///< Set the BRANCHIND PcodeOp
|
||||||
|
@ -546,7 +546,7 @@ public:
|
||||||
int4 getIndexByBlock(const FlowBlock *bl,int4 i) const;
|
int4 getIndexByBlock(const FlowBlock *bl,int4 i) const;
|
||||||
Address getAddressByIndex(int4 i) const { return addresstable[i]; } ///< Get the i-th address table entry
|
Address getAddressByIndex(int4 i) const { return addresstable[i]; } ///< Get the i-th address table entry
|
||||||
void setLastAsMostCommon(void); ///< Set the most common jump-table target to be the last address in the table
|
void setLastAsMostCommon(void); ///< Set the most common jump-table target to be the last address in the table
|
||||||
void setMostCommonBlock(uint4 bl) { mostcommon = bl; } ///< Set the most common jump-table target by out-edge
|
void setDefaultBlock(int4 bl) { defaultBlock = bl; } ///< Set out-edge of the switch destination considered to be \e default
|
||||||
void setLoadCollect(bool val) { collectloads = val; } ///< Set whether LOAD records should be collected
|
void setLoadCollect(bool val) { collectloads = val; } ///< Set whether LOAD records should be collected
|
||||||
void addBlockToSwitch(BlockBasic *bl,uintb lab); ///< Force a given basic-block to be a switch destination
|
void addBlockToSwitch(BlockBasic *bl,uintb lab); ///< Force a given basic-block to be a switch destination
|
||||||
void switchOver(const FlowInfo &flow); ///< Convert absolute addresses to block indices
|
void switchOver(const FlowInfo &flow); ///< Convert absolute addresses to block indices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue