Search in sources :

Example 6 with HexTable

use of com.wave.hextractor.object.HexTable in project hextractor by sewave.

the class FileUtilsTest method insertAsciiAsHex.

@Test
public void insertAsciiAsHex() throws IOException {
    File tableFile = File.createTempFile("table", "insertAsciiAsHex.tbl");
    tableFile.deleteOnExit();
    HexTable table = new HexTable(0);
    FileUtils.writeFileAscii(tableFile.getAbsolutePath(), table.toAsciiTable());
    String asciiFile = "@00000000-00000004-FF\n" + ";00008BB4{abcd~FF~}#028#022\n" + "abcd~FF~#005\n" + "|5";
    File asciiDataFile = File.createTempFile("origin", "insertAsciiAsHex.tst");
    asciiDataFile.deleteOnExit();
    FileUtils.writeFileAscii(asciiDataFile.getAbsolutePath(), asciiFile);
    File hexFile = File.createTempFile("dest", "insertAsciiAsHex.tst");
    hexFile.deleteOnExit();
    byte[] empty = new byte[5];
    Files.write(hexFile.toPath(), empty);
    FileUtils.insertAsciiAsHex(tableFile.getAbsolutePath(), asciiDataFile.getAbsolutePath(), hexFile.getAbsolutePath());
    byte[] data = { 0x61, 0x62, 0x63, 0x64, (byte) 0xFF };
    Assert.assertArrayEquals(data, Files.readAllBytes(hexFile.toPath()));
}
Also used : File(java.io.File) HexTable(com.wave.hextractor.object.HexTable) Test(org.junit.Test)

Example 7 with HexTable

use of com.wave.hextractor.object.HexTable in project hextractor by sewave.

the class FileUtilsTest method insertHex4To3Data.

@Test
public void insertHex4To3Data() throws IOException {
    byte[] data = { 0x28, (byte) 0xA2, (byte) 0x8A };
    byte[] dest = new byte[6];
    File dataFile = File.createTempFile("data", "insertHex4To3Data.tst");
    dataFile.deleteOnExit();
    Files.write(dataFile.toPath(), data);
    File tableFile = File.createTempFile("table", "insertHex4To3Data.tbl");
    tableFile.deleteOnExit();
    HexTable table = new HexTable(0);
    table.addToTable((byte) 0x0A, "¿");
    table.addToTable((byte) 0x00, "·");
    FileUtils.writeFileAscii(tableFile.getAbsolutePath(), table.toAsciiTable());
    File extFile = File.createTempFile("result", "insertHex4To3Data.ext");
    extFile.deleteOnExit();
    System.setProperty("logLevel", "DEBUG");
    FileUtils.extractAscii3To4Data(tableFile.getAbsolutePath(), dataFile.getAbsolutePath(), extFile.getAbsolutePath(), "0-3-FF");
    File outFile = File.createTempFile("out", "insertHex4To3Data.ext");
    outFile.deleteOnExit();
    Files.write(outFile.toPath(), dest);
    FileUtils.insertHex4To3Data(tableFile.getAbsolutePath(), extFile.getAbsolutePath(), outFile.getAbsolutePath());
    Assert.assertArrayEquals(data, Arrays.copyOfRange(Files.readAllBytes(outFile.toPath()), 0, data.length));
}
Also used : File(java.io.File) HexTable(com.wave.hextractor.object.HexTable) Test(org.junit.Test)

Example 8 with HexTable

use of com.wave.hextractor.object.HexTable in project hextractor by sewave.

the class FileUtilsTest method extractAscii3To4Data.

@Test
public void extractAscii3To4Data() throws IOException {
    byte[] data = { 40, 41, 42, 43, 44, 45 };
    File dataFile = File.createTempFile("data", "extractAscii3To4Data.tst");
    dataFile.deleteOnExit();
    Files.write(dataFile.toPath(), data);
    File tableFile = File.createTempFile("table", "extractAscii3To4Data.tbl");
    tableFile.deleteOnExit();
    HexTable table = new HexTable(0);
    FileUtils.writeFileAscii(tableFile.getAbsolutePath(), table.toAsciiTable());
    File extFile = File.createTempFile("result", "extractAscii3To4Data.ext");
    extFile.deleteOnExit();
    System.setProperty("logLevel", "DEBUG");
    FileUtils.extractAscii3To4Data(tableFile.getAbsolutePath(), dataFile.getAbsolutePath(), extFile.getAbsolutePath(), "0-6-FF");
    String decompStr = ";~0A~~02~$*~0A~20-~00~~00~\n" + "~0A~~02~$*~0A~20-~00~~00~@00000000:00000006";
    Assert.assertEquals(decompStr, FileUtils.getAsciiFile(extFile.getAbsolutePath()));
    System.setProperty("logLevel", "");
}
Also used : File(java.io.File) HexTable(com.wave.hextractor.object.HexTable) Test(org.junit.Test)

Example 9 with HexTable

use of com.wave.hextractor.object.HexTable in project hextractor by sewave.

the class UtilsTest method getTextArea.

@Test
public void getTextArea() {
    HexTable table = new HexTable(0);
    byte[] bytes = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45 };
    Assert.assertEquals("ABCD", Utils.getTextArea(1, 4, bytes, table));
}
Also used : HexTable(com.wave.hextractor.object.HexTable) Test(org.junit.Test)

Example 10 with HexTable

use of com.wave.hextractor.object.HexTable in project hextractor by sewave.

the class HexViewer method reloadTableFile.

/**
 * Reload table file.
 *
 * @param selectedFile the selected file
 */
private void reloadTableFile(File selectedFile) {
    tableFile = selectedFile;
    try {
        hexTable = new HexTable(tableFile.getAbsolutePath());
    } catch (Exception e1) {
        Utils.logException(e1);
    }
    refreshAll();
}
Also used : IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) HexTable(com.wave.hextractor.object.HexTable)

Aggregations

HexTable (com.wave.hextractor.object.HexTable)15 Test (org.junit.Test)5 File (java.io.File)4 OffsetEntry (com.wave.hextractor.pojo.OffsetEntry)3 TableSearchResult (com.wave.hextractor.pojo.TableSearchResult)2 IOException (java.io.IOException)1 BadLocationException (javax.swing.text.BadLocationException)1