示例#1
0
 /**
  * Get the statement at a specific label. If there is no statement stored, attempts to disassemble
  * the instruction at the label's virtual address. If the address is outside of the file area,
  * logs an error and returns a Halt statement by default.
  *
  * @param label The label for which to get the statement
  * @return The statement object at label.
  */
 public final RTLStatement getStatement(RTLLabel label) {
   if (!statementMap.containsKey(label)) {
     AbsoluteAddress address = label.getAddress();
     Instruction instr = getInstruction(address);
     // If we did not get an instruction, add an artificial Halt for recovery
     if (instr == null) {
       RTLHalt halt = new RTLHalt();
       halt.setLabel(label);
       putStatement(halt);
       logger.error("ERROR: Replacing unknown instruction with HALT.");
       if (Options.debug.getValue())
         throw new DisassemblyException("Disassembly failed at " + address);
     } else {
       try {
         StatementSequence seq = arch.getRTLEquivalent(address, instr);
         for (RTLStatement s : seq) {
           putStatement(s);
         }
       } catch (Exception e) {
         logger.error("Error during translation of instruction to IL");
         e.printStackTrace();
         RTLStatement skip = new RTLSkip();
         skip.setLabel(label);
         skip.setNextLabel(new RTLLabel(new AbsoluteAddress(address.getValue() + 1)));
         putStatement(skip);
       }
       assert statementMap.containsKey(label) : "Disassembly did not produce label: " + label;
     }
   }
   return statementMap.get(label);
 }
  @Override
  public Set<Tuple<RTLNumber>> projectionFromConcretization(RTLExpression... expressions) {

    // Only concretize expression requests from transformerFactory
    // Warning: If this method is invoked with 2 parameters for other reasons, it will
    //          likely fail!
    if (expressions.length != 2) return null;

    // If not on trace, don't concretize
    if (isBot()) return null;

    RTLExpression condition = expressions[0];
    RTLExpression target = expressions[1];
    RTLNumber cCondition;
    RTLNumber cTarget;

    Set<Tuple<RTLNumber>> res = new FastSet<Tuple<RTLNumber>>();

    for (AbsoluteAddress successor : getNextPC()) {
      RTLNumber nextPC = successor.toNumericConstant();

      if (target instanceof RTLNumber) {
        // If target is a number, this is a direct jump, and maybe conditional

        cTarget = (RTLNumber) target;

        if (condition instanceof RTLNumber) {
          // Direct, unconditional jump
          cCondition = (RTLNumber) condition;
        } else if (target.equals(nextPC)) {
          // Conditional jump that is taken according to the trace
          cCondition = ExpressionFactory.TRUE;
        } else {
          // Conditional jump that is not taken
          cCondition = ExpressionFactory.FALSE;
        }

      } else {
        // Target is not a number, so this is an indirect jump

        assert (condition instanceof RTLNumber)
            : "There should be no conditional indirect jumps in x86!";
        cCondition = (RTLNumber) condition;
        cTarget = nextPC;
      }
      res.add(Tuple.create(cCondition, cTarget));
    }

    return res;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    return cur.equals(((TraceReplayState) obj).cur);
  }
示例#4
0
 /**
  * Get the string representation of the specified assembly instruction assuming it is located at
  * the given address.
  *
  * @param addr a virtual address
  * @param instr an assembly instruction
  * @return a string representation of the assembly code at the given address
  */
 public String getInstructionString(AbsoluteAddress addr, Instruction instr) {
   if (instr == null) return "NON_EXISTENT";
   return instr.toString(addr.getValue(), symbolFinder(addr));
 }
示例#5
0
 public boolean isStub(AbsoluteAddress a) {
   return a.getValue() >= StubProvider.STUB_BASE;
 }
示例#6
0
 @Override
 public String getSymbolFor(AbsoluteAddress va) {
   String symbol = symbols.get(va);
   if (symbol != null) return symbol;
   else return va.toString();
 }
 @Override
 public AbsoluteAddress getVirtualAddress(long fp) {
   return new AbsoluteAddress(baseAddress.getValue() + fp);
 }
 @Override
 public AbsoluteAddress getMaxAddress() {
   return new AbsoluteAddress(baseAddress.getValue() + inBuf.getSize());
 }
 @Override
 public long getFilePointer(AbsoluteAddress va) {
   return va.getValue() - baseAddress.getValue();
 }
 @Override
 public String getIdentifier() {
   return cur.toString();
 }
 @Override
 public int hashCode() {
   return cur.hashCode();
 }
 /**
  * Returns the number of the section the given virtual address is in.
  *
  * @param va the virtual address
  * @return the section number
  */
 protected final int getSectionNumber(AbsoluteAddress va) {
   return getSectionNumberByRVA(va.getValue() - getBaseAddress());
 }
 @Override
 public final long getFilePointer(AbsoluteAddress va) {
   long fp = getFilePointerFromRVA(va.getValue() - getBaseAddress());
   if (fp >= 0) return fp;
   else return -1;
 }