Esempio n. 1
0
    def run(self, ctx):
        engctx = ctx.getEnginesContext()
        if not engctx:
            print('Back-end engines not initialized')
            return

        projects = engctx.getProjects()
        if not projects:
            print('There is no opened project')
            return

        # get the first unit available
        units = RuntimeProjectUtil.findUnitsByType(projects[0], None, False)
        if not units:
            print('No unit available')
            return

        unit = units[0]
        print('Unit: %s' % unit)

        # retrieve the formatter, which is a producer of unit representations
        formatter = unit.getFormatter()

        # create a table document
        columnLabels = Arrays.asList('Key', 'Value', 'Comment')
        rows = ArrayList()
        rows.add(
            TableRow(Arrays.asList(Cell('foo'), Cell('bar'), Cell('none'))))
        rows.add(
            TableRow(
                Arrays.asList(Cell('type'), Cell('integer'), Cell('unset'))))
        extraDoc = StaticTableDocument(columnLabels, rows)
        extraPres0 = UnitRepresentationAdapter(101, 'Demo Table', False,
                                               extraDoc)

        # create a tree document
        columnLabels = Arrays.asList('Key', 'Value')
        root = KVNode('foo', 'bar')
        roots = Arrays.asList(root)
        root.addChild(KVNode('quantified', 'self'))
        root.addChild(KVNode('galaxy', 'milky way'))
        node = KVNode('black hole', '42')
        node.setClassId(ItemClassIdentifiers.INFO_DANGEROUS)
        root.addChild(node)
        extraDoc = StaticTreeDocument(roots, columnLabels, -1)
        extraPres1 = UnitRepresentationAdapter(102, 'Demo Tree', False,
                                               extraDoc)

        # add the newly created presentations to our unit, and notify clients
        # the second argument indicates that the presentation should be persisted when saving the project
        formatter.addPresentation(extraPres0, True)
        formatter.addPresentation(extraPres1, True)
        unit.notifyListeners(JebEvent(J.UnitChange))
Esempio n. 2
0
    def run(self, ctx):
        prj = ctx.getMainProject()
        assert prj, 'Need a project'

        # pick the first interactive unit
        unit = prj.findUnit(IInteractiveUnit)
        assert unit, 'Need a unit'
        print('Unit: %s' % unit)

        # retrieve the formatter, which is a producer of unit representations
        formatter = unit.getFormatter()

        # create an extra document (text document), wrap it in a representtion
        lines = ArrayList()
        lines.add(
            Line(
                'There are two hard problems in computer science: cache invalidation, naming things, and off-by-one errors.'
            ))
        lines.add(Line('   - Phil Karlton (and others)'))
        extraDoc = StaticTextDocument(lines)
        extraPres = UnitRepresentationAdapter(100, 'Quotes', False, extraDoc)

        # add the newly created representation to our unit, and notify clients
        # the second argument indicates that the presentation should be persisted when saving the project
        formatter.addPresentation(extraPres, True)
        unit.notifyGenericChange()
Esempio n. 3
0
    def run(self, ctx):
        prj = ctx.getMainProject()
        unit = prj.findUnit(IInteractiveUnit)
        print('Unit: %s' % unit)

        # retrieve the formatter, which is a producer of unit representations
        formatter = unit.getFormatter()

        # create a table document
        columnLabels = Arrays.asList('Key', 'Value', 'Comment')
        rows = ArrayList()
        rows.add(
            TableRow(Arrays.asList(Cell('foo'), Cell('bar'), Cell('none'))))
        rows.add(
            TableRow(
                Arrays.asList(Cell('type'), Cell('integer'), Cell('unset'))))
        extraDoc = StaticTableDocument(columnLabels, rows)
        extraPres0 = UnitRepresentationAdapter(101, 'Demo Table', False,
                                               extraDoc)

        # create a tree document
        columnLabels = Arrays.asList('Key', 'Value')
        root = KVNode('foo', 'bar')
        roots = Arrays.asList(root)
        root.addChild(KVNode('quantified', 'self'))
        root.addChild(KVNode('galaxy', 'milky way'))
        node = KVNode('black hole', '42')
        node.setClassId(ItemClassIdentifiers.INFO_DANGEROUS)
        root.addChild(node)
        extraDoc = StaticTreeDocument(roots, columnLabels, -1)
        extraPres1 = UnitRepresentationAdapter(102, 'Demo Tree', False,
                                               extraDoc)

        # add the newly created presentations to our unit, and notify clients
        # the second argument indicates that the presentation should be persisted when saving the project
        formatter.addPresentation(extraPres0, True)
        formatter.addPresentation(extraPres1, True)
        UnitUtil.notifyGenericChange(unit)
Esempio n. 4
0
    def run(self, ctx):
        engctx = ctx.getEnginesContext()
        if not engctx:
            print('Back-end engines not initialized')
            return

        projects = engctx.getProjects()
        if not projects:
            print('There is no opened project')
            return

        # get the first unit available
        units = RuntimeProjectUtil.findUnitsByType(projects[0], None, False)
        if not units:
            print('No unit available')
            return

        unit = units[0]
        print('Unit: %s' % unit)

        # retrieve the formatter, which is a producer of unit representations
        formatter = unit.getFormatter()

        # create an extra document (text document), wrap it in a representtion
        lines = ArrayList()
        lines.add(
            Line(
                'There are two hard problems in computer science: cache invalidation, naming things, and off-by-one errors.'
            ))
        lines.add(Line('   - Phil Karlton (and others)'))
        extraDoc = StaticTextDocument(lines)
        extraPres = UnitRepresentationAdapter(100, 'Quotes', False, extraDoc)

        # add the newly created representation to our unit, and notify clients
        # the second argument indicates that the presentation should be persisted when saving the project
        formatter.addPresentation(extraPres, True)
        unit.notifyListeners(JebEvent(J.UnitChange))
Esempio n. 5
0
    def run(self, ctx):
        self.documentName = 'Comments Table'
        engctx = ctx.getEnginesContext()
        if not engctx:
            print('Back-end engines not initialized')
            return

        projects = engctx.getProjects()
        if not projects:
            print('There is no opened project')
            return

        prj = projects[0]
        print('Decompiling code units of %s...' % prj)

        units = RuntimeProjectUtil.findUnitsByType(prj, None, False)

        if not units:
            print('No unit exists')
            return

        targetUnit = units[0]  # Get the top-level unit
        formatter = targetUnit.getFormatter()  # Get the formatter of the unit

        # Set table column names
        columnLabels = Arrays.asList('Unit Name', 'Address', 'Comment')

        # Add comments to the arraylist rows
        self.rows = ArrayList()
        for unit in units:
            self.addCommentsToDoc(unit)

        # Create the table doc
        tableDoc = StaticTableDocument(columnLabels, self.rows)

        # Delete the old table doc and add the new table doc to presentations
        newId = 2  # Set the initial table doc Id (Do not use 1! 1 is default number used by "source")
        for i, document in enumerate(
                formatter.getPresentations()):  # Find the old table doc
            if (self.documentName == document.getLabel()):
                newId = document.getId(
                ) + 1  # Adding 1 to the old table doc Id as the Id of the new doc (avoid the collision)
                formatter.removePresentation(
                    i)  # Delete the old table doc from presentations
                break
        adapter = UnitRepresentationAdapter(newId, self.documentName, False,
                                            tableDoc)  # Get the new adapter
        formatter.addPresentation(
            adapter, True)  # Add the new table doc to presentations

        # Jump to the table doc fragment in the top-level unit
        views = ctx.getViews(
            targetUnit)  # Get all views of target unit(top-level unit)
        if not views:
            ctx.displayMessageBox('Warning', 'Please open the top-level unit',
                                  None, None)  # Show the value directly
            return

        targetView = views.get(0)

        fragments = targetView.getFragments(
        )  # Get all fragments of target view
        if not fragments:
            ctx.displayMessageBox('Warning', 'No fragment exists', None, None)
            return

        targetFragment = targetView.getFragments().get(
            fragments.size() - 1)  # Get the table doc just created
        # targetView.setActiveFragment(targetFragment)
        ctx.openView(targetUnit)  # Open target Unit(top-level unit)
        targetUnit.notifyListeners(JebEvent(J.UnitChange))