Search in sources :

Example 31 with CAddress

use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.

the class CGotoAddressField method buildAddressSelectionPopUp.

/**
 * In the case of multiple modules zoom to address does not work therefore the user must select in
 * which module to search.
 */
private void buildAddressSelectionPopUp() {
    final CAddressSelectionDialog dlg = new CAddressSelectionDialog(m_parent, m_modules);
    dlg.setVisible(true);
    final INaviModule result = dlg.getSelectionResult();
    final IAddress address = new CAddress(Long.parseLong(getText(), 16));
    ZyZoomHelpers.zoomToAddress(m_graph, address, result, true);
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 32 with CAddress

use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.

the class CCodeNodeMenu method addImmediateOperandMenu.

private void addImmediateOperandMenu(final COperandTreeNode node, final SectionContainer sections, final INaviModule module) {
    add(new CIntegerOperandMenu(node, node.getReplacement()));
    final long address = Long.parseLong(node.getValue());
    final List<Section> containingSections = sections.findSections(new CAddress(address));
    if (containingSections.size() == 1) {
        add(new GotoSectionAction(containingSections.get(0), address, module));
    } else if (containingSections.size() > 1) {
        add(new GotoSectionMenu(containingSections, address, module));
    }
    addSeparator();
}
Also used : Section(com.google.security.zynamics.binnavi.disassembly.types.Section) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 33 with CAddress

use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.

the class StosGenerator method generate.

/**
 * Translates a STOS instruction to REIL code.
 *
 * @param environment A valid translation environment.
 * @param operandSize Size of the operands of the STOS instruction.
 * @param instructions The generated REIL code will be added to this list
 *
 * @throws InternalTranslationException if any of the arguments are null the passed instruction is
 *         not an STOS instruction
 */
@Override
public void generate(final ITranslationEnvironment environment, final long baseOffset, final OperandSize operandSize, final List<ReilInstruction> instructions) throws InternalTranslationException {
    Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
    Preconditions.checkNotNull(instructions, "Error: Argument instructions can't be null");
    Preconditions.checkArgument(baseOffset >= 0, "Error: Argument offset can't be less than 0");
    long offset = baseOffset;
    final int previousInstructions = (int) (baseOffset % 0x100);
    final OperandSize archSize = environment.getArchitectureSize();
    final OperandSize resultSize = TranslationHelpers.getNextSize(archSize);
    String maskedEax = null;
    final String ediChange = String.valueOf(operandSize.getByteSize());
    final String mask = String.valueOf(TranslationHelpers.getAllBitsMask(operandSize));
    final String truncateMask = String.valueOf(TranslationHelpers.getAllBitsMask(archSize));
    if (operandSize != archSize) {
        maskedEax = environment.getNextVariableString();
        instructions.add(ReilHelpers.createAnd(offset, archSize, "eax", archSize, mask, archSize, maskedEax));
        offset++;
    } else {
        maskedEax = "eax";
    }
    final String addResult = environment.getNextVariableString();
    final String subResult = environment.getNextVariableString();
    // Store EAX to [EDI]
    instructions.add(ReilHelpers.createStm(offset, operandSize, maskedEax, archSize, "edi"));
    // Update EDI depending on the value of the DF
    final String jmpGoal = String.format("%d.%d", ReilHelpers.toNativeAddress(new CAddress(baseOffset)).toLong(), previousInstructions + 5 + (operandSize != archSize ? 1 : 0));
    final String jmpGoal2 = String.format("%d.%d", ReilHelpers.toNativeAddress(new CAddress(baseOffset)).toLong(), previousInstructions + 7 + (operandSize != archSize ? 1 : 0));
    instructions.add(ReilHelpers.createJcc(offset + 1, OperandSize.BYTE, Helpers.DIRECTION_FLAG, OperandSize.ADDRESS, jmpGoal));
    instructions.add(ReilHelpers.createAdd(offset + 2, archSize, "edi", archSize, ediChange, resultSize, addResult));
    instructions.add(ReilHelpers.createAnd(offset + 3, resultSize, addResult, archSize, truncateMask, archSize, "edi"));
    instructions.add(ReilHelpers.createJcc(offset + 4, OperandSize.BYTE, "1", OperandSize.ADDRESS, jmpGoal2));
    instructions.add(ReilHelpers.createSub(offset + 5, archSize, "edi", archSize, ediChange, resultSize, subResult));
    instructions.add(ReilHelpers.createAnd(offset + 6, resultSize, subResult, archSize, truncateMask, archSize, "edi"));
    instructions.add(ReilHelpers.createNop(offset + 7));
}
Also used : OperandSize(com.google.security.zynamics.reil.OperandSize) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 34 with CAddress

use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.

the class BreakpointHelpersTest method setUp.

@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
    final Database apiDatabase = new Database(database);
    final SQLProvider mockProvider = new MockSqlProvider();
    final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
    final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
    final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
    final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
    final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
    final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
    m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    m_module.load();
    m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
    m_mockDebugger.connect();
    m_debugger = new Debugger(m_mockDebugger);
    final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
    m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
    final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
    final INaviView naviView = new MockView(mockProvider);
    final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
    final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
    m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
    m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
    setM_functionNode(m_view.createFunctionNode(apiFunction));
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) View(com.google.security.zynamics.binnavi.API.disassembly.View) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 35 with CAddress

use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.

the class BreakpointHelpersTest method testGetEchoBreakpointsNode.

@Test
public void testGetEchoBreakpointsNode() {
    assertTrue(BreakpointHelpers.getEchoBreakpoints(m_debugger, m_node).isEmpty());
    m_debugger.getBreakpointManager().getNative().addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x1234)))));
    final List<Address> breakpoints = BreakpointHelpers.getEchoBreakpoints(m_debugger, m_node);
    assertEquals(1, breakpoints.size());
    assertEquals(0x1234, breakpoints.get(0).toLong());
    try {
        BreakpointHelpers.getEchoBreakpoints(null, m_node);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        BreakpointHelpers.getEchoBreakpoints(m_debugger, (CodeNode) null);
        fail();
    } catch (final NullPointerException exception) {
    }
}
Also used : BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)315 Test (org.junit.Test)221 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)60 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)55 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)51 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)48 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)47 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)47 ArrayList (java.util.ArrayList)46 Date (java.util.Date)46 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)45 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)40 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)32 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)29 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)28 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)27 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)27 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)26 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)24 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)24