Пример #1
0
      static PyObject* Instruction_getOperands(PyObject* self, PyObject* noarg) {
        triton::arch::ImmediateOperand  imm;
        triton::arch::MemoryOperand     mem;
        triton::arch::RegisterOperand   reg;
        triton::arch::Instruction*      inst;
        triton::uint32                  opSize;
        PyObject*                       operands;

        inst     = PyInstruction_AsInstruction(self);
        opSize   = inst->operands.size();
        operands = xPyList_New(opSize);

        for (triton::uint32 index = 0; index < opSize; index++) {
          PyObject* obj = nullptr;

          if (inst->operands[index].getType() == triton::arch::OP_IMM) {
            imm = inst->operands[index].getImm();
            obj = PyImmediateOperand(imm);
          }
          else if (inst->operands[index].getType() == triton::arch::OP_MEM) {
            mem = inst->operands[index].getMem();
            obj = PyMemoryOperand(mem);
          }
          else if (inst->operands[index].getType() == triton::arch::OP_REG) {
            reg = inst->operands[index].getReg();
            obj = PyRegisterOperand(reg);
          }
          else
            continue;

          PyList_SetItem(operands, index, obj);
        }

        return operands;
      }
Пример #2
0
static PyObject *SmtAstNode_getChilds(PyObject *self, PyObject *noarg) {
  PyObject *childs;
  smt2lib::smtAstAbstractNode *node = PySmtAstNode_AsSmtAstNode(self);

  uint64 size = node->getChilds().size();
  childs = xPyList_New(size);
  uint64 index = 0;
  for ( ; index < size; index++)
    PyList_SetItem(childs, index, PySmtAstNode(node->getChilds()[index]));

  return childs;
}
Пример #3
0
static PyObject *Triton_getSymExprs(PyObject *self, PyObject *noargs) {
  PyObject                          *ret;
  std::vector<SymbolicExpression *> exprs;
  uint64                            numberOfExprs = 0;

  exprs = ap.getExpressions();
  numberOfExprs = exprs.size();
  ret = xPyList_New(numberOfExprs);
  for (uint64 index = 0; index < numberOfExprs; index++)
    PyList_SetItem(ret, index, PySymbolicExpression(exprs[index]));

  return ret;
}
Пример #4
0
static PyObject *Triton_getSymVars(PyObject *self, PyObject *noArg) {
  std::vector<SymbolicVariable *> symVars;
  std::vector<SymbolicVariable *>::iterator it;
  PyObject *symVarsList;

  symVars = ap.getSymVars();
  symVarsList = xPyList_New(symVars.size());

  Py_ssize_t index = 0;
  for (it = symVars.begin(); it != symVars.end(); it++){
    PyList_SetItem(symVarsList, index, PySymbolicVariable(*it));
    index += 1;
  }

  return symVarsList;
}
Пример #5
0
      static PyObject* Instruction_getSymbolicExpressions(PyObject* self, PyObject* noarg) {
        triton::arch::Instruction*  inst;
        triton::uint32              exprSize;
        PyObject*                   symExprs;

        inst     = PyInstruction_AsInstruction(self);
        exprSize = inst->symbolicExpressions.size();
        symExprs = xPyList_New(exprSize);

        for (triton::uint32 index = 0; index < exprSize; index++) {
          PyObject* obj = nullptr;
          obj = PySymbolicExpression(inst->symbolicExpressions[index]);
          PyList_SetItem(symExprs, index, obj);
        }

        return symExprs;
      }
Пример #6
0
static PyObject *Triton_getTaintedExpressions(PyObject *self, PyObject *noarg) {
  PyObject                                  *ret;
  std::list<SymbolicExpression *>           exprs;
  std::list<SymbolicExpression *>::iterator it;
  uint64                                    index = 0;
  uint64                                    numberOfExprs = 0;

  exprs = ap.getTaintedExpressions();
  numberOfExprs = exprs.size();
  ret = xPyList_New(numberOfExprs);
  for (it = exprs.begin(); it != exprs.end(); it++) {
    PyList_SetItem(ret, index, PySymbolicExpression(*it));
    index++;
  }

  return ret;
}
Пример #7
0
static PyObject *Instruction_getSymbolicExpressions(PyObject *self, PyObject *noarg) {
  std::list<SymbolicExpression*> symExpressions;
  std::list<SymbolicExpression*>::iterator it;

  if (PyInstruction_AsIns(self) != nullptr) {
    symExpressions = PyInstruction_AsIns(self)->getSymbolicExpressions();
  }

  PyObject *SEList = xPyList_New(symExpressions.size());
  Py_ssize_t index = 0;
  for (it = symExpressions.begin() ; it != symExpressions.end(); it++) {
    PyObject *PySE = PySymbolicExpression(*it);
    PyList_SetItem(SEList, index, PySE);
    index++;
  }

  return SEList;
}
Пример #8
0
static PyObject *Triton_getPathConstraints(PyObject *self, PyObject *noargs) {
  PyObject                        *ppc;
  std::list<uint64>               pc;
  std::list<uint64>::iterator     it;
  Py_ssize_t                      size = 0;

  pc    = ap.getPathConstraints();
  size  = pc.size();
  ppc   = xPyList_New(size);

  Py_ssize_t index = 0;
  for (it = pc.begin(); it != pc.end(); it++){
    PyList_SetItem(ppc, index, Py_BuildValue("k", *it));
    index += 1;
  }

  return ppc;
}
Пример #9
0
static PyObject *Instruction_getOperands(PyObject *self, PyObject *noarg) {
  std::vector<TritonOperand> operands;
  std::vector<TritonOperand>::iterator it;

  if (PyInstruction_AsIns(self) != nullptr)
    operands = PyInstruction_AsIns(self)->getOperands();
  else
    operands = PyInstruction_AsIrb(self)->getOperands();

  PyObject *OperandList = xPyList_New(operands.size());
  Py_ssize_t index = 0;

  for (it = operands.begin() ; it != operands.end(); it++) {
    PyObject *operand = PyOperand(*it);
    PyList_SetItem(OperandList, index, operand);
    index++;
  }
  return OperandList;
}
Пример #10
0
      static PyObject* PathConstraint_getBranchConstraints(PyObject* self, PyObject* noarg) {
        try {
          PyObject* ret = nullptr;
          std::vector<std::tuple<bool, triton::__uint, triton::ast::AbstractNode*>>& branches = PyPathConstraint_AsPathConstraint(self)->getBranchConstraints();

          ret = xPyList_New(branches.size());
          for (triton::uint32 index = 0; index != branches.size(); index++) {
            PyObject* dict = xPyDict_New();
            PyDict_SetItem(dict, PyString_FromString("taken"),      PyBool_FromLong(std::get<0>(branches[index])));
            PyDict_SetItem(dict, PyString_FromString("target"),     PyLong_FromUint(std::get<1>(branches[index])));
            PyDict_SetItem(dict, PyString_FromString("constraint"), PyAstNode(std::get<2>(branches[index])));
            PyList_SetItem(ret, index, dict);
          }

          return ret;
        }
        catch (const std::exception& e) {
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
        }
      }
Пример #11
0
      static PyObject* PathConstraint_getBranchConstraints(PyObject* self, PyObject* noarg) {
        try {
          PyObject* ret = nullptr;
          const auto& branches = PyPathConstraint_AsPathConstraint(self)->getBranchConstraints();

          ret = xPyList_New(branches.size());
          for (triton::usize index = 0; index != branches.size(); index++) {
            PyObject* dict = xPyDict_New();
            xPyDict_SetItem(dict, PyString_FromString("isTaken"),    PyBool_FromLong(std::get<0>(branches[index])));
            xPyDict_SetItem(dict, PyString_FromString("srcAddr"),    PyLong_FromUint64(std::get<1>(branches[index])));
            xPyDict_SetItem(dict, PyString_FromString("dstAddr"),    PyLong_FromUint64(std::get<2>(branches[index])));
            xPyDict_SetItem(dict, PyString_FromString("constraint"), PyAstNode(std::get<3>(branches[index])));
            PyList_SetItem(ret, index, dict);
          }

          return ret;
        }
        catch (const triton::exceptions::Exception& e) {
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
        }
      }
Пример #12
0
static PyObject *Triton_getModels(PyObject *self, PyObject *args)
{
  PyObject                        *node = nullptr;
  PyObject                        *limit;
  PyObject                        *modelsList;
  std::vector<std::list<Smodel>>  models;
  uint64                          limit_c = 0;
  uint64                          modelsSize = 0;

  /* Extract arguments */
  PyArg_ParseTuple(args, "O|O", &node, &limit);

  if (node == nullptr || !PySmtAstNode_Check(node))
    return PyErr_Format(PyExc_TypeError, "getModels(): expected a SmtAstNode as first argument");

  if (!PyLong_Check(limit) && !PyInt_Check(limit))
    return PyErr_Format(PyExc_TypeError, "getModels(): expected a limit (integer) as second argument");

  limit_c = PyLong_AsLong(limit);
  if (limit_c == 0)
    return PyErr_Format(PyExc_TypeError, "getModels(): The limit must be greater than 0");

  /* Get models */
  models        = ap.getModels(PySmtAstNode_AsSmtAstNode(node), limit_c);
  modelsSize    = models.size();
  modelsList    = xPyList_New(modelsSize);

  for (uint64 index = 0; index < modelsSize; index++){
    std::list<Smodel> model = models[index];
    std::list<Smodel>::iterator it;
    /* Craft the model dictionary */
    PyObject *modelDict = xPyDict_New();
    for (it = model.begin() ; it != model.end(); it++)
      PyDict_SetItemString(modelDict, it->getName().c_str(), Py_BuildValue("k", it->getValue()));

    PyList_SetItem(modelsList, index, modelDict);
  }

  return modelsList;
}