Search in sources :

Example 41 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.

the class InstructionTest method testCreate.

@Test
public void testCreate() throws CouldntLoadDataException, LoadCancelledException {
    final SQLProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final Database database = new Database(new MockDatabase());
    final CTagManager mockTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Root", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider);
    final TagManager nodeTagManager = new TagManager(mockTagManager);
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
    final List<Operand> operands = new ArrayList<Operand>();
    final OperandExpression ex2 = OperandExpression.create(module, "eax", ExpressionType.Register);
    final OperandExpression ex4 = OperandExpression.create(module, "ebx", ExpressionType.Register);
    operands.add(Operand.create(module, ex2));
    operands.add(Operand.create(module, ex4));
    final Instruction instruction = Instruction.create(module, new Address(0x123), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32");
    assertEquals(0x123, instruction.getAddress().toLong());
    assertEquals(null, instruction.getComment());
    assertArrayEquals(new byte[] { 1, 2, 3 }, instruction.getData());
    assertEquals("mov", instruction.getMnemonic());
    assertEquals(2, instruction.getOperands().size());
    assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
    assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
    assertEquals("123  mov eax, ebx", instruction.toString());
}
Also used : CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 42 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.

the class ModuleFactory method get.

public static Module get() {
    final MockSqlProvider provider = new MockSqlProvider();
    final Date creationDate = new Date();
    final Date modificationDate = new Date();
    final CModule internalModule = new CModule(123, "Name", "Comment", creationDate, modificationDate, "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    final TagManager nodeTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database db = new Database(new MockDatabase());
    return new Module(db, internalModule, nodeTagManager, viewTagManager);
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule)

Example 43 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.

the class ModuleHelpersTest method testGetFunction_1.

@Test
public void testGetFunction_1() {
    final Database database = new Database(new MockDatabase());
    @SuppressWarnings("unused") final MockModule mockModule = new MockModule();
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    try {
        internalModule.load();
    } catch (final CouldntLoadDataException exception) {
        CUtilityFunctions.logException(exception);
    } catch (final LoadCancelledException exception) {
        CUtilityFunctions.logException(exception);
    }
    @SuppressWarnings("unused") final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
    assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, 0x123));
    assertNull(ModuleHelpers.getFunction(module, 0x1235));
    try {
        ModuleHelpers.getFunction(null, -1);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        ModuleHelpers.getFunction(module, -1);
        fail();
    } catch (final IllegalArgumentException e) {
    }
}
Also used : MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 44 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.

the class ModuleHelpersTest method testGetFunction_3.

@Test
public void testGetFunction_3() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    new CFunctionContainer(mockModule, Lists.<INaviFunction>newArrayList(parentFunction));
    CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), parentFunction);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, "Mock Function"));
    assertNull(ModuleHelpers.getFunction(module, ""));
    try {
        ModuleHelpers.getFunction(null, (String) null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        ModuleHelpers.getFunction(module, (String) null);
        fail();
    } catch (final NullPointerException e) {
    }
}
Also used : MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CFunctionContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CFunctionContainer) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 45 with CModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.

the class ModuleTest method testConstructor.

@Test
public void testConstructor() {
    final MockSqlProvider provider = new MockSqlProvider();
    final Date creationDate = new Date();
    final Date modificationDate = new Date();
    final CModule internalModule = new CModule(123, "Name", "Comment", creationDate, modificationDate, "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    final TagManager nodeTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database db = new Database(new MockDatabase());
    final Module module = new Module(db, internalModule, nodeTagManager, viewTagManager);
    assertEquals("Name", module.getName());
    assertEquals("Comment", module.getDescription());
    assertNotSame(creationDate, module.getCreationDate());
    assertNotSame(modificationDate, module.getModificationDate());
    assertTrue(creationDate.equals(module.getCreationDate()));
    assertTrue(modificationDate.equals(module.getModificationDate()));
    assertEquals(db, module.getDatabase());
    assertNotNull(module.getDebugger());
    assertEquals(0x555, module.getFilebase().toLong());
    assertEquals(0x666, module.getImagebase().toLong());
    assertEquals("12345678123456781234567812345678", module.getMD5());
    assertEquals("1234567812345678123456781234567812345678", module.getSHA1());
    assertEquals("Module 'Name'", module.toString());
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Aggregations

CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)57 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)47 Date (java.util.Date)46 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)40 Test (org.junit.Test)36 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)23 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)23 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)22 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)19 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)16 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)14 Before (org.junit.Before)14 ArrayList (java.util.ArrayList)12 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)11 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)9 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)8 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)8 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)7 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)7 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)6