Search in sources :

Example 21 with Function

use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.

the class CallResolver method resolveFunctions.

private void resolveFunctions(final Module module) {
    if (!module.isLoaded()) {
        return;
    }
    final Map<Address, Function> functionMap = new HashMap<Address, Function>();
    for (final Function function : module.getFunctions()) {
        final Address rebasedAddress = target.getDebugger().toImagebase(module, function.getAddress());
        functionMap.put(rebasedAddress, function);
    }
    resolvedFunctions.put(module, functionMap);
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) HashMap(java.util.HashMap)

Example 22 with Function

use of com.google.security.zynamics.binnavi.API.disassembly.Function in project binnavi by google.

the class IndirectCallFinder method find.

/**
   * Returns information about all indirect call instructions of a module.
   * 
   * @param module The module whose indirect call instructions are found.
   * 
   * @return A list of indirect call information.
   */
public static List<IndirectCall> find(final Module module) {
    final Set<Address> importedFunctionCalls = getDirectFunctionCalls(module);
    final Map<Address, Function> functionMap = new HashMap<Address, Function>();
    for (final Function function : module.getFunctions()) {
        functionMap.put(function.getAddress(), function);
    }
    // TODO (timkornau): make sure to only include the call sides which we are willing to
    // take a look at depending on the architecture of the module.
    final String callMnemonics = // x86
    "'call', " + // MIPS
    "'bal', 'bgezal', 'bgezall', 'bltzal', 'bltzall', 'jal', 'jalr', " + // ARM
    "'bl', 'blx', " + // PowerPC
    "'bcctrl', 'bcctr'";
    final String registerOrdinal = String.valueOf(ExpressionType.Register.ordinal() + 1);
    final String dereferenceOrdinal = String.valueOf(ExpressionType.MemDeref.ordinal() + 1);
    final String query = "SELECT ft.address AS faddress, it.address AS iaddress " + " FROM " + TableNames.FUNCTIONS_TABLE + " AS ft " + " JOIN " + TableNames.FUNCTION_VIEWS_TABLE + " AS fvt ON ft.address = fvt.function " + " AND ft.module_id = fvt.module_id" + " JOIN " + TableNames.NODES_TABLE + " AS nt ON fvt.view_id = nt.view_id " + " JOIN " + TableNames.CODENODE_INSTRUCTIONS_TABLE + " AS cit ON nt.id = cit.node_id " + " AND cit.module_id = ft.module_id " + " JOIN " + TableNames.INSTRUCTIONS_TABLE + " AS it ON it.address = cit.address " + " AND it.module_id = cit.module_id" + " JOIN " + TableNames.OPERANDS_TABLE + " AS ot ON it.address = ot.address " + " AND it.module_id = ot.module_id" + " JOIN " + TableNames.EXPRESSION_TREE_MAPPING_TABLE + " AS etm ON ot.expression_tree_id = etm.tree_id " + " AND etm.module_id = ft.module_id" + " JOIN " + TableNames.EXPRESSION_TREE_TABLE + " AS et ON et.id = etm.tree_node_id " + " AND et.module_id = ft.module_id" + " WHERE ft.module_id = " + module.getId() + " and mnemonic in (" + callMnemonics + ") " + " AND (et.type in (" + registerOrdinal + ", " + dereferenceOrdinal + "))" + " GROUP BY faddress, iaddress";
    final List<IndirectCall> addresses = new ArrayList<IndirectCall>();
    try {
        final ResultSet resultSet = module.getDatabase().executeQuery(query);
        try {
            while (resultSet.next()) {
                final Address address = new Address(resultSet.getLong("iaddress"));
                if (importedFunctionCalls.contains(address)) {
                    continue;
                }
                final Address faddress = new Address(resultSet.getLong("faddress"));
                final Function function = functionMap.get(faddress);
                addresses.add(new IndirectCall(module, function, address));
            }
        } finally {
            resultSet.close();
        }
        return addresses;
    } catch (final SQLException exception) {
        exception.printStackTrace();
        return new ArrayList<IndirectCall>();
    }
}
Also used : Function(com.google.security.zynamics.binnavi.API.disassembly.Function) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Aggregations

Function (com.google.security.zynamics.binnavi.API.disassembly.Function)22 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)13 View (com.google.security.zynamics.binnavi.API.disassembly.View)13 Test (org.junit.Test)9 HashMap (java.util.HashMap)6 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)5 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)5 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)4 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)4 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)4 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)4 FunctionNode (com.google.security.zynamics.binnavi.API.disassembly.FunctionNode)3 BigInteger (java.math.BigInteger)3 Set (java.util.Set)3 Callgraph (com.google.security.zynamics.binnavi.API.disassembly.Callgraph)2 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)2 CouldntSaveDataException (com.google.security.zynamics.binnavi.API.disassembly.CouldntSaveDataException)2 FunctionEdge (com.google.security.zynamics.binnavi.API.disassembly.FunctionEdge)2 Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)2 BlockEdge (com.google.security.zynamics.binnavi.API.disassembly.BlockEdge)1