Search in sources :

Example 6 with OffsetEntry

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

the class Utils method getOffsets.

/**
 * Gets the offsets of the string offsets.
 *
 * @param string the string
 * @return the offsets
 * @throws IOException the exception
 */
public static List<OffsetEntry> getOffsets(String string) throws IOException {
    if (string.endsWith(Constants.OFF_EXTENSION)) {
        string = FileUtils.getCleanOffsets(string);
    }
    string = string.toUpperCase();
    List<OffsetEntry> offsets = new ArrayList<>();
    for (String offsetString : string.split(Constants.OFFSET_STR_SEPARATOR)) {
        OffsetEntry entry = new OffsetEntry();
        String[] values = offsetString.split(Constants.OFFSET_CHAR_SEPARATOR);
        entry.setStart(Integer.parseInt(values[0], Constants.HEX_RADIX));
        if (values.length > 1) {
            entry.setEnd(Integer.parseInt(values[1], Constants.HEX_RADIX));
            if (values.length > 2) {
                for (int i = 2; i < values.length; i++) {
                    entry.getEndChars().add(values[i]);
                }
            }
        }
        offsets.add(entry);
    }
    return offsets;
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 7 with OffsetEntry

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

the class Utils method getHexOffsets.

/**
 * Get the OffsetEntries of the string.
 *
 * @param entries the entries
 * @return the hex offsets
 */
public static List<OffsetEntry> getHexOffsets(String entries) {
    List<OffsetEntry> entryList = new ArrayList<>();
    for (String entryStr : entries.replace(Constants.SPACE_STR, Constants.EMPTY).split(Constants.OFFSET_STR_SEPARATOR)) {
        OffsetEntry entry = null;
        if (entryStr.contains(Constants.OFFSET_CHAR_SEPARATOR)) {
            // 00001-00003 type init-end (inclusives)
            int[] numbers = hexStringListToIntList(entryStr.split(Constants.OFFSET_CHAR_SEPARATOR));
            entry = new OffsetEntry(numbers[0], numbers[1], null);
        } else {
            if (entryStr.contains(Constants.OFFSET_LENGTH_SEPARATOR)) {
                // 00001:00003 type init:length
                int[] numbers = hexStringListToIntList(entryStr.split(Constants.OFFSET_LENGTH_SEPARATOR));
                entry = new OffsetEntry(numbers[0], numbers[0] + numbers[1] - 1, null);
            } else {
                log("Invalid Offset entry!!!!! : " + entryStr);
            }
        }
        if (entry != null) {
            entryList.add(entry);
        }
    }
    return entryList;
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry)

Example 8 with OffsetEntry

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

the class UtilsTest method toFileString.

@Test
public void toFileString() {
    List<OffsetEntry> offEntries = new ArrayList<>();
    offEntries.add(new OffsetEntry(0, 1, Arrays.asList("FF", "00")));
    offEntries.add(new OffsetEntry(5, 10, Arrays.asList("01", "00")));
    Assert.assertEquals("00000000-00000001-FF-00,00000005-0000000A-01-00", Utils.toFileString(offEntries));
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) Test(org.junit.Test)

Example 9 with OffsetEntry

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

the class UtilsTest method getHexOffsets.

@Test
public void getHexOffsets() {
    String entries = "0-1,5:6";
    List<OffsetEntry> offEntries = new ArrayList<>();
    offEntries.add(new OffsetEntry(0, 1, null));
    offEntries.add(new OffsetEntry(5, 10, null));
    Assert.assertEquals(offEntries, Utils.getHexOffsets(entries));
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) Test(org.junit.Test)

Example 10 with OffsetEntry

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

the class HexTableTest method toAscii2.

@Test
public void toAscii2() {
    HexTable table = new HexTable(LINES);
    byte[] data = new byte[] { 0, 1, 2, 3, 4 };
    OffsetEntry entry = new OffsetEntry(0, 4, Collections.singletonList("FF"));
    String ascii = "@00000000-00000004-FF\n" + ";00000000{abc{ab}~04~}#011#005\n" + "abc{ab}~04~#005\n" + "|5\n";
    Assert.assertEquals(ascii, table.toAscii(data, entry, true));
    Assert.assertEquals(ascii, table.toAscii(data, entry, false));
}
Also used : OffsetEntry(com.wave.hextractor.pojo.OffsetEntry) Test(org.junit.Test)

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