use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.
the class StepBreakpointSetParser method parseSuccess.
@Override
public StepBreakpointSetReply parseSuccess(final int packetId, final int argumentCount) throws IOException {
final List<Pair<RelocatedAddress, Integer>> addresses = new ArrayList<>();
final int numberOfAddresses = parseInteger();
for (int i = 0; i < numberOfAddresses; i++) {
final RelocatedAddress address = new RelocatedAddress(parseAddress());
addresses.add(new Pair<RelocatedAddress, Integer>(address, parseInteger()));
}
return new StepBreakpointSetReply(packetId, 0, addresses);
}
use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.
the class AddressingModeTwoGenerator method generate.
public static Pair<String, String> generate(final long baseOffset, final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions, final IOperandTreeNode rootNode) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
Preconditions.checkNotNull(instructions, "Error: Argument instructions can't be null");
/**
* parse the OperandTree to see what type of operand we received
*
* This code is very verbose right now and due to this fact if a Bug is found in one type of
* the functions be sure to check both other functions if they are OK
*
*/
if (rootNode.getChildren().get(0).getValue().equals("!")) {
// matched pre- indexed
if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getType() == ExpressionType.IMMEDIATE_INTEGER)) {
// matched [ Rn , #imm ]!
return preIndexedImm(baseOffset, environment, instructions, rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue(), rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue());
} else if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getType() == ExpressionType.REGISTER)) {
// matched [ Rn, Rm ]!
return preIndexedReg(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue()));
} else {
// matched [ Rn, Rm, <shift>, #imm ]!
if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("LSL")) {
return preIndexedLSL(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("LSR")) {
return preIndexedLSR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("ASR")) {
return preIndexedASR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("ROR")) {
return preIndexedROR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("RRX")) {
return preIndexedRRX(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()));
} else {
throw new InternalTranslationException("Error: AddressOperandTypeTwo preIndexed shifter is not valid");
}
}
} else if (rootNode.getChildren().get(0).getValue().equals(",")) {
// matched post- indexed
if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(1).getType() == ExpressionType.IMMEDIATE_INTEGER)) {
// matched [ Rn ], #imm
return postIndexedImm(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getValue()));
} else if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(1).getType() == ExpressionType.REGISTER)) {
// matched [ Rn ], Rm
return postIndexedReg(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getValue()));
} else {
// matched [ Rn ], Rm, <shift>, #imm
if (rootNode.getChildren().get(0).getChildren().get(1).getValue().equals("LSL")) {
return postIndexedLSL(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(1).getValue().equals("LSR")) {
return postIndexedLSR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(1).getValue().equals("ASR")) {
return postIndexedASR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(1).getValue().equals("ROR")) {
return postIndexedROR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(1).getValue().equals("RRX")) {
return postIndexedRRX(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()));
} else {
throw new InternalTranslationException("Error: AddressOperandTypeTwo postIndexed shifter is not valid");
}
}
} else if (rootNode.getChildren().get(0).getValue().equals("[")) {
// matched offset
if (rootNode.getChildren().get(0).getChildren().get(0).getType() == ExpressionType.IMMEDIATE_INTEGER) {
return new Pair<String, String>(rootNode.getChildren().get(0).getChildren().get(0).getValue(), "");
} else if (rootNode.getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) {
return new Pair<String, String>((rootNode.getChildren().get(0).getChildren().get(0).getValue()), "");
} else if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getType() == ExpressionType.IMMEDIATE_INTEGER)) {
// matched [ Rn , #imm ]
return offsetImm(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue()));
} else if ((rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getType() == ExpressionType.REGISTER) && (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getType() == ExpressionType.REGISTER)) {
// matched [ Rn , Rm ]
return offsetReg(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue()));
} else {
// matched [ Rn , Rm, <shift>, #imm ]
if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("LSL")) {
return offsetLSL(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("LSR")) {
return offsetLSR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("ASR")) {
return offsetASR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("ROR")) {
return offsetROR(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(1).getValue()));
} else if (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getValue().equals("RRX")) {
return offsetRRX(baseOffset, environment, instructions, (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(0).getValue()), (rootNode.getChildren().get(0).getChildren().get(0).getChildren().get(1).getChildren().get(0).getValue()));
} else {
throw new InternalTranslationException("Error: AddressOperandTypeTwo offset shifter is not valid");
}
}
} else {
throw new InternalTranslationException("Error: AddressOperandTypeTwo rootNodeValue is not valid " + rootNode.getChildren().get(0).getValue() + " " + instruction.getMnemonic());
}
}
use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.
the class DebuggerTest method testlisteners0.
@Test
public void testlisteners0() throws DebugExceptionWrapper, MaybeNullException, ParserConfigurationException, SAXException, IOException {
mockDebugger.connect();
mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
mockDebugger.getProcessManager().setTargetInformation(new TargetInformation(5, Lists.newArrayList(new RegisterDescription("eax", 4, true), new RegisterDescription("ebx", 4, false)), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 12, 0, new ArrayList<DebuggerException>(), false, false, false)));
mockDebugger.connection.m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildProcessStartReply(CommonTestObjects.MEMORY_MODULE));
mockDebugger.getProcessManager().getThread(0).setCurrentAddress(new RelocatedAddress(new CAddress(0)));
mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.ECHO, CommonTestObjects.BP_ADDRESS_123_SET);
final ArrayList<Pair<RelocatedAddress, Integer>> list = new ArrayList<Pair<RelocatedAddress, Integer>>();
mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointSetReply(0, 0, list));
mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointSetReply(0, 0, list));
mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointsRemovedReply(0, 0, list));
mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointsRemovedReply(0, 0, list));
mockDebugger.connection.m_synchronizer.receivedEvent(new ExceptionOccurredReply(0, 0, 0, 0, new RelocatedAddress(new CAddress(0)), "Test exception"));
mockDebugger.connection.m_synchronizer.receivedEvent(new HaltReply(0, 0, 0));
mockDebugger.connection.m_synchronizer.receivedEvent(new HaltReply(0, 0, 1));
mockDebugger.connection.m_synchronizer.receivedEvent(new ListFilesReply(0, 0, RemoteFileSystem.parse("<foo></foo>".getBytes())));
mockDebugger.connection.m_synchronizer.receivedEvent(new ListFilesReply(0, 1, null));
mockDebugger.connection.m_synchronizer.receivedEvent(new ListProcessesReply(0, 0, ProcessList.parse("<foo></foo>".getBytes())));
mockDebugger.connection.m_synchronizer.receivedEvent(new ListProcessesReply(0, 1, null));
mockDebugger.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 0, new MemoryMap(new ArrayList<MemorySection>())));
mockDebugger.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 1, null));
mockDebugger.connection.m_synchronizer.receivedEvent(new ModuleLoadedReply(0, 0, new MemoryModule("XXX", "YYYXXX", new RelocatedAddress(new CAddress(0)), 0), new TargetProcessThread(123, ThreadState.SUSPENDED)));
mockDebugger.connection.m_synchronizer.receivedEvent(new ModuleUnloadedReply(0, 0, new MemoryModule("XXX", "YYYXXX", new RelocatedAddress(new CAddress(0)), 0)));
mockDebugger.connection.m_synchronizer.receivedEvent(new ProcessClosedReply(0, 0));
mockDebugger.connection.m_synchronizer.receivedEvent(new ReadMemoryReply(0, 0, new CAddress(0), new byte[8]));
mockDebugger.connection.m_synchronizer.receivedEvent(new ReadMemoryReply(0, 1, null, null));
mockDebugger.connection.m_synchronizer.receivedEvent(new RegistersReply(0, 0, new RegisterValues(new FilledList<ThreadRegisters>())));
mockDebugger.connection.m_synchronizer.receivedEvent(new RegistersReply(0, 1, null));
mockDebugger.connection.m_synchronizer.receivedEvent(new RequestTargetReply(0, 0));
mockDebugger.connection.m_synchronizer.receivedEvent(new RequestTargetReply(0, 1));
mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeReply(0, 0));
mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeReply(0, 1));
}
use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.
the class CPostgreSQLModuleContentTest method testCModuleContentConstructor.
@Test
public void testCModuleContentConstructor() throws LoadCancelledException, CouldntLoadDataException {
final CModule module = (CModule) getDatabase().getContent().getModules().get(0);
module.load();
final ListenerProvider<IModuleListener> listeners = new ListenerProvider<IModuleListener>();
final CCallgraph callgraph = module.getContent().getNativeCallgraph();
final IFilledList<INaviFunction> functions = new FilledList<INaviFunction>();
functions.add(module.getContent().getFunctionContainer().getFunctions().get(0));
final ICallgraphView nativeCallgraph = module.getContent().getViewContainer().getNativeCallgraphView();
final ImmutableList<IFlowgraphView> nativeFlowgraphs = module.getContent().getViewContainer().getNativeFlowgraphViews();
final List<INaviView> customViews = new ArrayList<INaviView>();
final ImmutableBiMap<INaviView, INaviFunction> viewFunctionMap = new ImmutableBiMap.Builder<INaviView, INaviFunction>().build();
new Pair<HashMap<INaviView, INaviFunction>, HashMap<INaviFunction, INaviView>>(null, null);
final IFilledList<TraceList> traces = new FilledList<TraceList>();
final SectionContainer sections = new SectionContainer(new SectionContainerBackend(getProvider(), module));
final TypeInstanceContainer instances = new TypeInstanceContainer(new TypeInstanceContainerBackend(getProvider(), module, module.getTypeManager(), sections), getProvider());
final CModuleContent moduleContent1 = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, sections, instances);
assertNotNull(moduleContent1);
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(null, null, null, null, null, null, null, null, null, null, sections, instances);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, null, null, null, null, null, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), null, null, null, null, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, null, null, null, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, null, null, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, null, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, null, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, null, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, null, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, null, null, null);
fail();
} catch (final NullPointerException e) {
}
try {
@SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, null, null);
fail();
} catch (final NullPointerException e) {
}
}
use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.
the class ZyGraphTest method createEdgeForAddedEdgeTests.
private Pair<CNaviViewEdge, com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge> createEdgeForAddedEdgeTests() {
final INaviViewNode source = m_view.getGraph().getNodes().get(0);
final INaviViewNode target = m_view.getGraph().getNodes().get(1);
final CNaviViewEdge edge = m_graph.getRawView().getContent().createEdge(source, target, EdgeType.ENTER_INLINED_FUNCTION);
final com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge cnn = searchEdge(getEdges(m_graph), edge);
return new Pair<CNaviViewEdge, com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge>(edge, cnn);
}
Aggregations