Skip to content

Commit

Permalink
1. When we find potential indexing variable with table stride being 1…
Browse files Browse the repository at this point in the history
…, we need to make sure that we have already found the table base to declare this variable as the table index.

2. Add constants multiplication in AST simplification
  • Loading branch information
mxz297 committed Aug 24, 2017
1 parent 74cf2a7 commit 0969620
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
30 changes: 20 additions & 10 deletions parseAPI/src/IndirectASTVisitor.C
Expand Up @@ -295,18 +295,28 @@ AST::Ptr JumpTableFormatVisitor::visit(DataflowAPI::RoseAST *ast) {
ast->val().op == ROSEOperation::shiftLOp ||
ast->val().op == ROSEOperation::rotateLOp) && memoryReadLayer > 0) {
if (ast->child(0)->getID() == AST::V_ConstantAST && ast->child(1)->getID() == AST::V_VariableAST) {
findIndex = true;
numOfVar++;
VariableAST::Ptr varAst = boost::static_pointer_cast<VariableAST>(ast->child(1));
index = varAst->val().reg;
return AST::Ptr();
ConstantAST::Ptr constAst = boost::static_pointer_cast<ConstantAST>(ast->child(0));
if (!((ast->val().op == ROSEOperation::uMultOp || ast->val().op == ROSEOperation::sMultOp) &&
!findTableBase &&
constAst->val().val == 1)) {
findIndex = true;
numOfVar++;
VariableAST::Ptr varAst = boost::static_pointer_cast<VariableAST>(ast->child(1));
index = varAst->val().reg;
return AST::Ptr();
}
}
if (ast->child(1)->getID() == AST::V_ConstantAST && ast->child(0)->getID() == AST::V_VariableAST) {
findIndex = true;
numOfVar++;
VariableAST::Ptr varAst = boost::static_pointer_cast<VariableAST>(ast->child(0));
index = varAst->val().reg;
return AST::Ptr();
ConstantAST::Ptr constAst = boost::static_pointer_cast<ConstantAST>(ast->child(1));
if (!((ast->val().op == ROSEOperation::uMultOp || ast->val().op == ROSEOperation::sMultOp) &&
!findTableBase &&
constAst->val().val == 1)) {
findIndex = true;
numOfVar++;
VariableAST::Ptr varAst = boost::static_pointer_cast<VariableAST>(ast->child(0));
index = varAst->val().reg;
return AST::Ptr();
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions parseAPI/src/IndirectAnalyzer.C
Expand Up @@ -58,8 +58,6 @@ static bool IsVariableArgumentFormat(AST::Ptr t, AbsRegion &index) {
}

bool IndirectControlFlowAnalyzer::NewJumpTableAnalysis(std::vector<std::pair< Address, Dyninst::ParseAPI::EdgeTypeEnum > >& outEdges) {
// if (block->last() == 0x55121c) dyn_debug_parsing=1; else dyn_debug_parsing=0;

parsing_printf("Apply indirect control flow analysis at %lx\n", block->last());
parsing_printf("Looking for thunk\n");

Expand Down
21 changes: 6 additions & 15 deletions parseAPI/src/SymbolicExpression.C
Expand Up @@ -109,21 +109,7 @@ AST::Ptr SymbolicExpression::SimplifyRoot(AST::Ptr ast, Address addr, bool keepM
size_t size = child1->val().size + child0->val().size;
return ConstantAST::create(Constant(val,size));
}
if (roseAST->child(1)->getID() == AST::V_ConstantAST) {
ConstantAST::Ptr child1 = boost::static_pointer_cast<ConstantAST>(roseAST->child(1));
if (child1->val().val == 0) {
return roseAST->child(0);
}
}
if (roseAST->child(0)->getID() == AST::V_VariableAST && roseAST->child(1)->getID() == AST::V_VariableAST) {
VariableAST::Ptr child0 = boost::static_pointer_cast<VariableAST>(roseAST->child(0));
VariableAST::Ptr child1 = boost::static_pointer_cast<VariableAST>(roseAST->child(1));
if (child0->val() == child1->val()) {
return roseAST->child(0);
}
}
break;

return roseAST->child(0);
}
case ROSEOperation::addOp:
// We simplify the addition as much as we can
Expand Down Expand Up @@ -167,6 +153,11 @@ AST::Ptr SymbolicExpression::SimplifyRoot(AST::Ptr ast, Address addr, bool keepM
break;
case ROSEOperation::sMultOp:
case ROSEOperation::uMultOp:
if (roseAST->child(0)->getID() == AST::V_ConstantAST && roseAST->child(1)->getID() == AST::V_ConstantAST) {
ConstantAST::Ptr child0 = boost::static_pointer_cast<ConstantAST>(roseAST->child(0));
ConstantAST::Ptr child1 = boost::static_pointer_cast<ConstantAST>(roseAST->child(1));
return ConstantAST::create(Constant(child0->val().val * child1->val().val, 64));
}
if (roseAST->child(0)->getID() == AST::V_ConstantAST) {
ConstantAST::Ptr child0 = boost::static_pointer_cast<ConstantAST>(roseAST->child(0));
if (child0->val().val == 1 && !keepMultiOne) return roseAST->child(1);
Expand Down

0 comments on commit 0969620

Please sign in to comment.