Search in sources :

Example 1 with OffsetEntry

use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.

the class HexViewer method refreshSelection.

/**
 * Refresh selection.
 */
private void refreshSelection() {
    hexTextArea.setCaretPosition(asciiTextArea.getCaretPosition() * Constants.HEX_VALUE_SIZE);
    Highlighter highlighterHex = hexTextArea.getHighlighter();
    highlighterHex.removeAllHighlights();
    try {
        highlighterHex.addHighlight(hexTextArea.getCaretPosition(), hexTextArea.getCaretPosition() + Constants.HEX_VALUE_SIZE - 1, BLUE_PAINTER);
    } catch (BadLocationException e1) {
    // Do nothing
    }
    Highlighter highlighterAscii = asciiTextArea.getHighlighter();
    highlighterAscii.removeAllHighlights();
    try {
        highlighterAscii.addHighlight(asciiTextArea.getCaretPosition(), asciiTextArea.getCaretPosition() + 1, BLUE_PAINTER);
        for (OffsetEntry entry : offEntries) {
            drawOffsetEntry(entry, highlighterAscii, LGRAY_PAINTER, ORANGE_PAINTER);
        }
        if (currEntry.getStart() > 0 && currEntry.getStart() - offset >= 0) {
            highlighterAscii.addHighlight(currEntry.getStart() - offset, currEntry.getStart() - offset + 1, YELLOW_PAINTER);
        }
        if (currEntry.getEnd() > 0 && currEntry.getEnd() - offset >= 0) {
            highlighterAscii.addHighlight(currEntry.getEnd() - offset, currEntry.getEnd() - offset + 1, ORANGE_PAINTER);
        }
    } catch (BadLocationException e1) {
        Utils.log("Bad location.");
    }
    offsetLabelValue.setText(getOffsetLabelValue());
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 2 with OffsetEntry

use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.

the class HexViewer method createFrame.

/**
 * Creates the frame.
 */
private void createFrame() {
    setVisible(false);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setLookAndFeel();
    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    createMenu();
    JPanel firstRow = new JPanel();
    firstRow.setLayout(new FlowLayout());
    JPanel secondRow = new JPanel();
    secondRow.setLayout(new FlowLayout(FlowLayout.LEADING));
    add(firstRow);
    add(secondRow);
    offsetsTextArea = new JTextArea(visibleRows, Constants.HEX_ADDR_SIZE + HEX_STARTS.length() + Constants.SPACE_STR.length());
    offsetsTextArea.setPreferredSize(DIMENSION_0_0);
    offsetsTextArea.setLineWrap(true);
    offsetsTextArea.setBackground(Color.BLACK);
    offsetsTextArea.setForeground(Color.WHITE);
    offsetsTextArea.setEditable(false);
    offsetsTextArea.setDisabledTextColor(Color.WHITE);
    offsetsTextArea.setEnabled(false);
    offsetsTextArea.setFont(BASE_FONT);
    firstRow.add(offsetsTextArea);
    offsetsTextArea.setText(getVisibleOffsets(offset, visibleColumns, visibleRows));
    hexTextArea = new JTextArea(visibleRows, visibleColumns * Constants.HEX_VALUE_SIZE);
    hexTextArea.setLineWrap(true);
    hexTextArea.setBackground(Color.BLACK);
    hexTextArea.setForeground(Color.WHITE);
    hexTextArea.setEditable(false);
    hexTextArea.setDisabledTextColor(Color.WHITE);
    hexTextArea.setEnabled(false);
    hexTextArea.setCaretColor(Color.GRAY);
    hexTextArea.setFont(BASE_FONT);
    firstRow.add(hexTextArea);
    hexTextArea.setText(Utils.getHexAreaFixedWidth(offset, getViewSize(), fileBytes, visibleColumns));
    asciiTextArea = new JTextArea(visibleRows, visibleColumns);
    asciiTextArea.setLineWrap(true);
    asciiTextArea.setBackground(Color.BLACK);
    asciiTextArea.setForeground(Color.WHITE);
    asciiTextArea.setDisabledTextColor(Color.WHITE);
    asciiTextArea.setEnabled(false);
    asciiTextArea.setEditable(false);
    asciiTextArea.setCaretColor(Color.GRAY);
    asciiTextArea.setFont(BASE_FONT);
    firstRow.add(asciiTextArea);
    asciiTextArea.setText(Utils.getTextArea(offset, getViewSize(), fileBytes, hexTable));
    resultsWindow = new JFrame(rb.getString(KeyConstants.KEY_SEARCH_RESULT_TITLE));
    resultsWindow.setLayout(new FlowLayout());
    searchResults = new JList<>(new TableSearchResult[0]);
    searchResults.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    searchResults.setLayoutOrientation(JList.VERTICAL);
    searchResults.setVisibleRowCount(8);
    searchResults.setFont(new Font(Font.MONOSPACED, Font.PLAIN, SEARCHRES_FONT_SIZE));
    JScrollPane listScroller = new JScrollPane(searchResults);
    listScroller.setPreferredSize(SEARCH_RES_DIMENSION);
    resultsWindow.add(listScroller);
    resultsWindow.pack();
    resultsWindow.setResizable(Boolean.FALSE);
    createNewPrjWin();
    vsb = new JScrollBar();
    firstRow.add(vsb);
    JLabel offsetLabel = new JLabel(rb.getString(KeyConstants.KEY_OFFSET_LABEL));
    secondRow.add(offsetLabel);
    offsetLabelValue = new JTextField(getOffsetLabelValue(), OFFSET_LABEL_LENGTH);
    offsetLabelValue.setEnabled(false);
    secondRow.add(offsetLabelValue);
    offsetLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    offsetLabelValue.setAlignmentX(Component.LEFT_ALIGNMENT);
    offEntries = new ArrayList<>();
    currEntry = new OffsetEntry();
    currEntry.setStart(-1);
    currEntry.setEnd(-1);
    createSearchAllWin();
    setResizable(Boolean.FALSE);
    addAllListeners();
    pack();
    vsb.setPreferredSize(new Dimension((int) vsb.getPreferredSize().getWidth(), (int) (getSize().getHeight() * 0.85)));
    refreshViewMode();
    setIcons();
    setVisible(true);
    refreshAll();
}
Also used : TableSearchResult(com.wave.hextractor.pojo.TableSearchResult) OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 3 with OffsetEntry

use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.

the class FileUtils method insertHex4To3Data.

/**
 * Inserts ascii as hex from a 4 to 3 data.
 */
public static void insertHex4To3Data(String table, String inputFile, String outputFile) throws IOException {
    Utils.log("Inserting ascii as hex 4 to 3 from \"" + inputFile + FILES_SEPARATOR + outputFile + "\"\n using table: \"" + table + "\"");
    byte[] outFileBytes = Files.readAllBytes(Paths.get(outputFile));
    HexTable hexTable = new HexTable(table);
    for (String entry : Utils.removeCommentsAndJoin(getAsciiFile(inputFile))) {
        String[] entryDataAndOffset = entry.split(Constants.ADDR_STR);
        OffsetEntry offEntry = OffsetEntry.fromHexRange(entryDataAndOffset[1]);
        byte[] compData = Utils.getCompressed4To3Data(hexTable.toHex(entryDataAndOffset[0]));
        System.arraycopy(compData, 0, outFileBytes, offEntry.getStart(), compData.length);
    }
    Files.write(Paths.get(outputFile), outFileBytes);
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) HexTable(com.wave.hextractor.object.HexTable)

Example 4 with OffsetEntry

use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.

the class FileUtils method extractHexData.

/**
 * Extracts HEX data from the inputFile to the outputFile</br>
 * using the entries.
 * @param inputFile .
 * @param outputFile .
 * @param entries .
 * @throws IOException .
 */
public static void extractHexData(String inputFile, String outputFile, String entries) throws IOException {
    Utils.log("Extracting hex from \"" + inputFile + FILES_SEPARATOR + outputFile + "\"" + "\n using \"" + entries + "\"");
    StringBuilder hexDataString = new StringBuilder();
    byte[] inputFileBytes = Files.readAllBytes(Paths.get(inputFile));
    for (OffsetEntry entry : Utils.getHexOffsets(entries)) {
        hexDataString.append(entry.getHexComment());
        hexDataString.append(Constants.S_NEWLINE);
        hexDataString.append(entry.getHexString(inputFileBytes));
        hexDataString.append(entry.getHexTarget());
        hexDataString.append(Constants.S_NEWLINE);
    }
    writeFileAscii(outputFile, hexDataString.toString());
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 5 with OffsetEntry

use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.

the class FileUtils method extractAscii3To4Data.

/**
 * Extracts Ascii data on packed 3 bytes to 4 characters</br>
 * using the entries.
 * @param inputFile .
 * @param outputFile .
 * @param entries .
 * @throws IOException .
 */
public static void extractAscii3To4Data(String table, String inputFile, String outputFile, String entries) throws IOException {
    Utils.log("Extracting ascii 3 to 4 from \"" + inputFile + FILES_SEPARATOR + outputFile + "\" \n using \"" + entries + "\" and table: \"" + table + "\"");
    StringBuilder dataString = new StringBuilder();
    byte[] inputFileBytes = Files.readAllBytes(Paths.get(inputFile));
    HexTable hexTable = new HexTable(table);
    for (OffsetEntry entry : Utils.getOffsets(entries)) {
        byte[] origData = Arrays.copyOfRange(inputFileBytes, entry.getStart(), entry.getEnd() + 1);
        byte[] expData = Utils.getExpanded3To4Data(origData);
        byte[] compData = Utils.getCompressed4To3Data(expData);
        if (Utils.isDebug()) {
            Utils.log("Original data     " + entry.getHexTarget() + " - " + Utils.getHexArea(0, origData.length, origData));
            Utils.log("Expanded data     " + entry.getHexTarget() + " - " + Utils.getHexArea(0, expData.length, expData));
            Utils.log("Recompressed data " + entry.getHexTarget() + " - " + Utils.getHexArea(0, compData.length, compData));
        }
        if (!Arrays.equals(origData, compData)) {
            Utils.log("ERROR! RECOMPRESSED DATA IS DIFFERENT!!!");
        }
        String line = hexTable.toAscii(expData, false, true);
        dataString.append(Constants.COMMENT_LINE);
        dataString.append(line);
        dataString.append(Constants.S_NEWLINE);
        dataString.append(line);
        dataString.append(entry.getHexTarget());
        dataString.append(Constants.S_NEWLINE);
    }
    writeFileAscii(outputFile, dataString.toString());
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) HexTable(com.wave.hextractor.object.HexTable)

Aggregations

OffsetEntry (com.wave.hextractor.pojo.OffsetEntry)20 Test (org.junit.Test)5 HexTable (com.wave.hextractor.object.HexTable)3 TableSearchResult (com.wave.hextractor.pojo.TableSearchResult)1 File (java.io.File)1 BadLocationException (javax.swing.text.BadLocationException)1 DefaultHighlighter (javax.swing.text.DefaultHighlighter)1 Highlighter (javax.swing.text.Highlighter)1