⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opcodeframe.java

📁 JPC: x86 PC Hardware Emulator. 牛津大学开发的一个纯JAVA的x86系统结构硬件模拟器。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {                int addr = Integer.valueOf(address, 16).intValue();                showAddress(addr);                setSelectedAddress(addr);            }            catch (Exception e) {}        }    }    /**     * find a code block that has a matching string ID and return its address. on fail return endAddress     */    private int findCodeBlockID(String codeBlockID, int startAddress, int endAddress)    {        int startRow = startAddress & AddressSpace.BLOCK_MASK;        startAddress = startAddress & AddressSpace.INDEX_MASK;                for(int baseAddress = startAddress; (baseAddress < (endAddress - AddressSpace.BLOCK_SIZE)); baseAddress += AddressSpace.BLOCK_SIZE)        {            Memory mem = null;            try            {                mem = MemoryViewer.getReadMemoryBlockAt(linearMemory, baseAddress);                mem.getByte(0);            }            catch (Exception e)             {                mem = LinearMemoryViewer.translateLinearAddress(physicalMemory, processor, baseAddress);            }                        if (mem != null)            {                for(int row = startRow; (row < AddressSpace.BLOCK_SIZE);  row++)                {                    CodeBlock cb = null;                    try                    {// 			cb = mem.queryCodeBlockAt(row);			cb = null;                        if (cb instanceof SpanningCodeBlock)                            cb = null;                    }                    catch (Exception e)                     {                        cb = null;                    }                                        if ((cb != null) && (cb.toString().equals(codeBlockID)))                        return baseAddress + row;                }            }            startRow = 0;        }        return endAddress;    }    public void frameClosed()    {        JPC.getInstance().objects().removeObject(this);    }    public void PCCreated()    {        refreshDetails();    }    public void PCDisposed()    {        nextInstructionAddress = 0;        pc = null;        linearMemory = null;        physicalMemory = null;        codeModel.fireTableDataChanged();        model.fireTableDataChanged();    }        public void executionStarted() {}    public void executionStopped()     {        refreshDetails();    }    public void setVisible(boolean value)    {        super.setVisible(value);        if (value)            refreshDetails();    }    public void refreshDetails()    {        int selected = getSelectedAddress();        breakpoints =  (BreakpointsFrame) JPC.getObject(BreakpointsFrame.class);        codeBlocks = (CodeBlockRecord) JPC.getObject(CodeBlockRecord.class);        linearMemory = (LinearAddressSpace) JPC.getObject(LinearAddressSpace.class);        physicalMemory = (PhysicalAddressSpace) JPC.getObject(PhysicalAddressSpace.class);        pc = (PC) JPC.getObject(PC.class);                processor = (Processor) JPC.getObject(Processor.class);        if (processor == null)            nextInstructionAddress = 0;        else            nextInstructionAddress = processor.getInstructionPointer();        if (!isVisible())            return;                    codeModel.setBaseAddress(codeModel.baseAddress);        if (trackInstructions.getState())        {            showAddress(nextInstructionAddress);            setSelectedAddress(nextInstructionAddress);            currentIndex = codeBlocks.getTraceLength();        }        else            setSelectedAddress(selected);    }    public int getSelectedAddress()    {        int selectedAddress = memoryBlockTable.getSelectedRow();        if (selectedAddress < 0)            return -1;        selectedAddress *= AddressSpace.BLOCK_SIZE;        return selectedAddress + Math.max(0, codeBlockTable.getSelectedRow());    }    public void setSelectedAddress(int address)    {        int blockRow = address >>> AddressSpace.INDEX_SHIFT;        int offset = (address & AddressSpace.BLOCK_MASK);        memoryBlockTable.setRowSelectionInterval(blockRow, blockRow);        codeBlockTable.setRowSelectionInterval(offset, offset);    }    public void showAddress(int address)    {        int blockRow = address >>> AddressSpace.INDEX_SHIFT;        int offset = (address & AddressSpace.BLOCK_MASK);        Rectangle rect = memoryBlockTable.getCellRect(blockRow, 0, true);        memoryBlockTable.scrollRectToVisible(rect);        memoryBlockTable.setRowSelectionInterval(blockRow, blockRow);        codeModel.setBaseAddress(address & AddressSpace.INDEX_MASK);        rect = codeBlockTable.getOverlayRect(offset, 20);        codeBlockTable.scrollRectToVisible(rect);    }    class MemoryBlockTableModel extends BasicTableModel    {        MemoryBlockTableModel()        {            super(new String[]{"Block", "Type"}, new int[]{80, 60});        }        public int getRowCount()        {            if (linearMemory == null)                return 0;            return (int) (linearMemory.getSize() / AddressSpace.BLOCK_SIZE);        }        public Object getValueAt(int row, int column)        {            int address = (int) (((long) row)*AddressSpace.BLOCK_SIZE);            if (column == 0)                return MemoryViewPanel.zeroPadHex(address, 8);            else            {                Memory mem = MemoryViewer.getReadMemoryBlockAt(linearMemory, address);                if (!linearMemory.isPagingEnabled())                    mem = MemoryViewer.getReadMemoryBlockAt(physicalMemory, address);                if (mem == null)                    return "";                else if (mem instanceof PhysicalAddressSpace.MapWrapper)                    return "MAPPED";                else if (mem instanceof PhysicalAddressSpace.UnconnectedMemoryBlock)                    return "---";                else if (mem instanceof LinearAddressSpace.PageFaultWrapper)                {                    ProcessorException pe = ((LinearAddressSpace.PageFaultWrapper) mem).getFault();                    return pe.getClass().getName();                }                else                    return "DATA";            }        }    }    class CodeBlockModel extends BasicTableModel    {        int baseAddress;        CodeBlockModel()        {            super(new String[]{"Address", "Raw Bytes", "uCode", "X86 Length", "X86 Count"}, new int[]{80, 80, 330, 80, 80});            baseAddress = 0;        }        public int getRowCount()        {            if (linearMemory == null)                return 0;            return AddressSpace.BLOCK_SIZE;        }        void setBaseAddress(int addr)        {            baseAddress = addr;            codeBlockTable.recalculateBlockPositions();            fireTableDataChanged();        }        public Object getValueAt(int row, int column)        {            int address = baseAddress + row;            Memory mem = null;            try            {                mem = MemoryViewer.getReadMemoryBlockAt(linearMemory, address);                mem.getByte(0);            }            catch (Exception e)             {                mem = LinearMemoryViewer.translateLinearAddress(physicalMemory, processor, address);            }            CodeBlock cb = null;            try            {// 		cb = mem.queryCodeBlockAt(row);		cb = null;		if (cb instanceof SpanningCodeBlock)                {//                     if (processor.isProtectedMode())//                         ((SpanningCodeBlock) cb).setAddress(linearMemory, address, processor.cs.getDefaultSizeFlag());//                     else//                         ((SpanningCodeBlock) cb).setAddress(physicalMemory, address, processor.cs.getDefaultSizeFlag());                }            }            catch (Exception e) {}            switch (column)            {            case 0:                return MemoryViewPanel.zeroPadHex(address, 8);            case 1:                if (mem == null)                    return "";                byte b = mem.getByte(row);                return MemoryViewPanel.zeroPadHex(0xFF & b, 2);            case 2:                if (mem == null)                    return "Not present";		if (cb == null)		    return "";                return cb;            case 3:                if (cb == null)                    return null;                return cb.getX86Length();            case 4:                if (cb == null)                    return null;                return cb.getX86Count();            default:                return null;            }        }    }    class CellRenderer extends DefaultTableCellRenderer    {        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)        {            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);            setFont(f);            setHorizontalAlignment(JLabel.LEFT);            setBackground(Color.white);            setForeground(Color.black);            if (isSelected)                setBackground(Color.yellow);                        int address = codeModel.baseAddress + row;            if (nextInstructionAddress == address)            {                setBackground(Color.magenta);                setForeground(Color.white);            }            if ((column == 0) && (breakpoints != null))            {                if (breakpoints.isBreakpoint((int) address))                    setBackground(Color.orange);            }            if (value instanceof CodeBlock)                setText(value.toString());            return this;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -