use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class ViewTest method setUp.
@SuppressWarnings("deprecation")
@Before
public void setUp() throws LoadCancelledException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, FileReadException, CouldntLoadDataException {
ConfigManager.instance().read();
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final CTagManager internalTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, m_provider))), TagType.VIEW_TAG, m_provider);
m_viewTagManager = new TagManager(internalTagManager);
final Database database = new Database(new MockDatabase());
internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, m_provider);
internalModule.load();
module = new Module(database, internalModule, tagManager, m_viewTagManager);
final Calendar cal = Calendar.getInstance();
cal.setTime(module.getModificationDate());
cal.add(Calendar.DATE, 1);
m_modificationDate = cal.getTime();
m_creationDate = new Date();
final ITreeNode<CTag> tag = internalTagManager.addTag(internalTagManager.getRootTag(), "foo");
final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, internalModule);
final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, m_creationDate, m_modificationDate, 1, 2, Sets.newHashSet(tag.getObject()), new HashSet<CTag>(), false);
m_view = new View(module, internalView, tagManager, m_viewTagManager);
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class PostgreSQLFunctionsLoader method parseFunctionInformation.
/**
* This function parses a {@link ResultSet result set} from a database query and generates a
* {@link List} of {@link INaviFunction} from it.
*
* @param resultSet The {@link ResultSet} in which the result from the database query is stored.
* @param provider The {@link SQLProvider} to access the database with.
* @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
* associated.
*
* @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
* resultSet}.
*
* @throws SQLException if the {@link ResultSet} could not be parsed.
* @throws CouldntLoadDataException if the associated comments could not be loaded from the
* database.
*/
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
final List<INaviFunction> functions = Lists.newArrayList();
final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
try {
while (resultSet.next()) {
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
final String name = resultSet.getString("name");
final String originalName = resultSet.getString("original_name");
Integer globalCommentId = resultSet.getInt("global_comment");
if (resultSet.wasNull()) {
globalCommentId = null;
}
final String description = resultSet.getString("description");
final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
final String parentModuleName = resultSet.getString("parent_module_name");
final int parentModuleId = resultSet.getInt("parent_module_id");
final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
final Integer nodeCount = resultSet.getInt("bbcount");
final Integer edgeCount = resultSet.getInt("edgeCount");
final Integer indegree = resultSet.getInt("incount");
final Integer outdegree = resultSet.getInt("outcount");
Integer stackFrameId = resultSet.getInt("stack_frame");
if (resultSet.wasNull()) {
stackFrameId = null;
}
Integer prototypeId = resultSet.getInt("prototype");
if (resultSet.wasNull()) {
prototypeId = null;
}
final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
if (stackFrameId != null) {
module.getTypeManager().setStackFrame(stackFrame);
}
final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
if (globalCommentId != null) {
commentIdToFunction.put(globalCommentId, function);
}
functions.add(function);
}
} finally {
resultSet.close();
}
if (!commentIdToFunction.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
}
}
return functions;
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class TypeInstanceContainerBackend method loadTypeInstanceReference.
/**
* Load a single type instance reference from the database.
*
* @param typeInstanceId the id of the {@link TypeInstanceReference reference}.
* @param address The address of the {@link INaviInstruction instruction} where the
* {@link TypeInstanceReference reference} is associated.
* @param position The {@link OperandTree operand tree} position in the {@link INaviInstruction
* instruction} the {@link TypeInstanceReference reference} is associated to.
* @param expressionId The {@link OperandTreeNode operand tree node} id within the
* {@link OperandTree operand tree}.
*
* @return The {@link TypeInstanceReference} loaded from the database.
* @throws CouldntLoadDataException
*/
public TypeInstanceReference loadTypeInstanceReference(final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
Preconditions.checkNotNull(address, "Error: address argument can not be null");
Preconditions.checkNotNull(position, "Error: position argument can not be null");
Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstanceId, address, position, expressionId);
final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
final INaviView view = module.getContent().getViewContainer().getView(rawReference.getViewId());
final TypeInstanceReference reference = new TypeInstanceReference(new CAddress(address), position, Optional.<INaviOperandTreeNode>absent(), typeInstance, view);
referenceLookup.put(new InstanceReferenceLookup(new CAddress(address), position, expressionId), reference);
return reference;
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class CViewContainer method delete.
private void delete(final INaviView view) {
final INaviView currentStoredView = m_customViews.get(m_customViews.indexOf(view));
m_customViews.remove(currentStoredView);
viewIdView.remove(view.getConfiguration().getId());
currentStoredView.removeListener(m_viewListener);
for (final IModuleListener listener : m_listeners) {
try {
listener.deletedView(m_module, currentStoredView);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.
the class CDataflowViewCreator method create.
/**
* Creates a new dataflow view.
*
* @param container The container in which the dataflow view is created.
* @param view The normal view that provides the control-flow information.
*
* @return The created dataflow view.
*
* @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
*/
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
for (final CCodeNode codeNode : view.getBasicBlocks()) {
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instructions.put(instruction.getAddress(), instruction);
}
}
final ReilFunction function = view.getContent().getReilCode();
final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
for (final OperandGraphNode operandGraphNode : operandGraph) {
final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (instructionMap.containsKey(instruction)) {
nodeMap.put(operandGraphNode, instructionMap.get(instruction));
continue;
}
final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(operandGraphNode, codeNode);
instructionMap.put(instruction, codeNode);
}
for (final OperandGraphEdge edge : operandGraph.getEdges()) {
final INaviCodeNode source = nodeMap.get(edge.getSource());
final INaviCodeNode target = nodeMap.get(edge.getTarget());
if (source.equals(target)) {
continue;
}
dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
}
return dfView;
}
Aggregations