コード例 #1
0
ファイル: z3Result.cpp プロジェクト: EgoIncarnate/Triton
__uint Z3Result::getUintValue(void) const {
  __uint result = 0;

  if (!this->expr.is_int())
    throw std::runtime_error("getUintValue: The ast is not a numerical value");

  #if defined(__x86_64__) || defined(_M_X64)
  Z3_get_numeral_uint64(this->context, this->expr, &result);
  #endif
  #if defined(__i386) || defined(_M_IX86)
  Z3_get_numeral_uint(this->context, this->expr, &result);
  #endif

  return result;
}
コード例 #2
0
ファイル: solverEngine.cpp プロジェクト: djn3m0/Triton
std::list< std::pair<std::string, unsigned long long> > SolverEngine::getModel(std::string expr)
{
  std::list< std::pair<std::string, unsigned long long> > ret;
  std::stringstream   formula;
  z3::check_result    checkResult;
  z3::context         *ctx;
  z3::solver          *solver;
  
  /* First, set the QF_AUFBV flag */
  formula << smt2lib::init();
  
  /* Then, delcare all symbolic variables */
  formula << this->symEngine->getSmt2LibVarsDecl();

  /* And concat the user expression */
  formula << expr;

  /* Create the context and AST */
  ctx = new z3::context();
  Z3_ast ast = Z3_parse_smtlib2_string(*ctx, formula.str().c_str(), 0, 0, 0, 0, 0, 0);
  z3::expr eq(*ctx, ast);

  /* Create a solver and add the expression */
  solver = new z3::solver(*ctx);
  solver->add(eq);

  /* Check */
  checkResult = solver->check();

  /* Check if it is sat */
  if (checkResult == z3::sat){
    /* Get model */
    z3::model m = solver->get_model();
    /* Traversing the model */
    for (unsigned i = 0; i < m.size(); i++) {
      unsigned long long value = 0; 
      z3::func_decl v = m[i];
      Z3_get_numeral_uint64(*ctx, m.get_const_interp(v), &value);
      ret.push_back(make_pair(v.name().str(), value));
    }
  }

  delete solver;
  return ret;
}
コード例 #3
0
ファイル: api_numeral.cpp プロジェクト: angr/angr-z3
 Z3_bool Z3_API Z3_get_numeral_uint(Z3_context c, Z3_ast v, unsigned* u) {
     Z3_TRY;
     // This function invokes Z3_get_numeral_uint64, but it is still ok to add LOG command here because it does not return a Z3 object.
     LOG_Z3_get_numeral_uint(c, v, u);
     RESET_ERROR_CODE();
     CHECK_IS_EXPR(v, Z3_FALSE);
     if (!u) {
         SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
         return Z3_FALSE;
     }
     uint64_t l;
     if (Z3_get_numeral_uint64(c, v, &l) && (l <= 0xFFFFFFFF)) {
         *u = static_cast<unsigned>(l);
         return Z3_TRUE;
     }
     return Z3_FALSE;
     Z3_CATCH_RETURN(Z3_FALSE);
 }