use of com.wave.hextractor.object.HexTable in project hextractor by sewave.
the class HexViewer method view.
/**
* New HexViewer with inputFile and tableFile.
*
* @param inputFile the input file
* @param tableFile the table file
* @throws IOException the exception
*/
public static void view(String inputFile, String tableFile) throws IOException {
Utils.log("Viewing Hex file \"" + inputFile + "\"\n with table file: \"" + tableFile + "\".");
new HexViewer(Files.readAllBytes(Paths.get(inputFile)), inputFile, new HexTable(tableFile), tableFile);
}
use of com.wave.hextractor.object.HexTable in project hextractor by sewave.
the class FileUtils method searchRelative8Bits.
/**
* Generates a table file for the input string if found on the rom.
*
* @param firstFile .
* @param outFilePrefix .
* @param searchString .
* @throws IOException the exception
*/
public static void searchRelative8Bits(String firstFile, String outFilePrefix, String searchString) throws IOException {
Utils.log("Searching relative string \"" + searchString + "\"\n in \"" + firstFile + "\" " + "\n Generating table files from \"" + outFilePrefix + ".001\"");
List<TableSearchResult> hexTables = searchRelative8Bits(Files.readAllBytes(Paths.get(firstFile)), searchString);
int tablesFound = 1;
List<HexTable> usedTables = new ArrayList<>();
for (TableSearchResult t : hexTables) {
if (!usedTables.contains(t.getHexTable())) {
writeFileAscii(outFilePrefix + "." + Utils.fillLeft(valueOf(tablesFound), 3), t.getHexTable().toAsciiTable());
usedTables.add(t.getHexTable());
}
tablesFound++;
}
}
use of com.wave.hextractor.object.HexTable in project hextractor by sewave.
the class FileUtils method insertAsciiAsHex.
/**
* Insert ascii as hex.
*
* @param firstFile the first file
* @param secondFile the second file
* @param thirdFile the third file
* @throws IOException the exception
*/
public static void insertAsciiAsHex(String firstFile, String secondFile, String thirdFile) throws IOException {
Utils.log("Inserting ascii file \"" + secondFile + "\"\n using table \"" + firstFile + FILES_SEPARATOR + thirdFile + "\".");
HexTable hexTable = new HexTable(firstFile);
String input = getAsciiFile(secondFile);
byte[] outFileBytes = Files.readAllBytes(Paths.get(thirdFile));
String[] lines = input.split(Constants.S_NEWLINE);
int totalBytesWritten = 0;
int line = 0;
while (line < lines.length) {
if (lines[line] != null && lines[line].contains(Constants.ADDR_STR)) {
// Read entry
OffsetEntry entry = new OffsetEntry(lines[line]);
line++;
// Read content (including end)
StringBuilder content = new StringBuilder();
// Put lines not starting with |
while (!lines[line].contains(Constants.S_MAX_BYTES)) {
if (lines[line] != null && lines[line].length() > 0 && !lines[line].contains(Constants.S_COMMENT_LINE)) {
content.append(lines[line]);
if (lines[line].contains(Constants.S_STR_NUM_CHARS)) {
content.append(Constants.S_NEWLINE);
}
}
line++;
}
// End line
content.append(lines[line]).append(Constants.S_NEWLINE);
// Process
byte[] hex = hexTable.toHex(content.toString(), entry);
if (Utils.isDebug()) {
Utils.log(" TO OFFSET: " + Utils.intToHexString(entry.getStart(), Constants.HEX_ADDR_SIZE));
}
System.arraycopy(hex, 0, outFileBytes, entry.getStart(), hex.length);
totalBytesWritten += hex.length;
}
line++;
}
Utils.log("TOTAL BYTES WRITTEN: " + Utils.fillLeft(valueOf(totalBytesWritten), Constants.HEX_ADDR_SIZE) + " / " + Utils.intToHexString(totalBytesWritten, Constants.HEX_ADDR_SIZE) + " Hex");
Files.write(Paths.get(thirdFile), outFileBytes);
}
use of com.wave.hextractor.object.HexTable in project hextractor by sewave.
the class FileUtils method searchAllStrings.
/**
* Searches all the strings on the rom for the given table.
*
* @param tableFile the table file
* @param dataFile the data file
* @param numIgnoredChars the num ignored chars
* @param endChars the end chars
* @param dictFile the dict file
* @throws IOException the exception
*/
public static void searchAllStrings(String tableFile, String dataFile, int numIgnoredChars, String endChars, String dictFile) throws IOException {
String extractFile = dataFile + Constants.EXTRACT_EXTENSION;
Utils.log("Extracting all strings from \"" + dataFile + FILES_SEPARATOR + extractFile + "\" and \"" + extractFile + Constants.OFFSET_EXTENSION + "\" \n " + "using \"" + tableFile + "\" \n numIgnoredChars: " + numIgnoredChars + "\n endChars: " + endChars + "\n dictionary: " + dictFile);
searchAllStrings(new HexTable(tableFile), Files.readAllBytes(Paths.get(dataFile)), numIgnoredChars, endChars, dictFile, dataFile + Constants.EXTRACT_EXTENSION);
}
use of com.wave.hextractor.object.HexTable in project hextractor by sewave.
the class HexViewer method view.
/**
* New empty HexViewer.
*/
public static void view() {
Utils.log("Viewing Hex file empty with table file ascii.");
new HexViewer(new byte[MAX_COLS_AND_ROWS * MAX_COLS_AND_ROWS], DEFAULT_HEXFILE, new HexTable(0), DEFAULT_TABLE);
}
Aggregations