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);
}
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();
}
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));
}
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));
}
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) {
}
}
Aggregations