Skip to content

Commit

Permalink
Merge pull request #5 from trietend/patch-1
Browse files Browse the repository at this point in the history
Allow to process huge files
  • Loading branch information
huettenhain authored Mar 18, 2023
2 parents 018ee78 + f727bdf commit 4658abd
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions DhrakeInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.util.Scanner;

import org.apache.commons.io.FileUtils;

Expand Down Expand Up @@ -211,8 +214,8 @@ private void overrideStrCatN(String name, DataType LPTSTR) {

private boolean importSymbolsFromIDC() {
File idc;
List<String> idcLineList;
String[] lines;
int progress = 0;
int linecount = 0;

monitor.setMessage("loading symbols from IDC");

Expand All @@ -221,40 +224,51 @@ private boolean importSymbolsFromIDC() {
} catch (CancelledException e) {
return false;
}
try {
idcLineList = FileUtils.readLines(idc, StandardCharsets.UTF_8);
Pattern pattern = Pattern.compile("^\\s*MakeNameEx\\((?:0x)?([A-Fa-f0-9]+),\\s*\"([^\"]*)\",\\s*([xA-Fa-f0-9]+)\\);\\s*$");


try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(idc)); Scanner sc = new Scanner(inputStream, "UTF-8");) {

//count lines
while (sc.hasNextLine()) {
sc.nextLine();
linecount++;
}
monitor.setMaximum(linecount);
} catch (IOException e) {
this.logMsg("file not found: %s", idc.toPath());
return false;
}
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(idc)); Scanner sc = new Scanner(inputStream, "UTF-8");) {

lines = idcLineList.toArray(new String[]{});
Pattern pattern = Pattern.compile(
"^\\s*MakeNameEx\\((?:0x)?([A-Fa-f0-9]+),\\s*\"([^\"]*)\",\\s*([xA-Fa-f0-9]+)\\);\\s*$");
monitor.setMaximum(lines.length);
for (int k=0; k < lines.length; k++) {
monitor.setProgress(k);
if (!lines[k].contains("MakeNameEx"))
continue;
Matcher match = pattern.matcher(lines[k]);
if (!match.matches())
continue;
Integer offset = Integer.parseUnsignedInt(match.group(1), 16);
Address entryPoint = this.toAddr(offset);
String functionName = match.group(2);
monitor.setMessage(functionName);
if (functionName.strip().length() > 0) {
try {
this.renameSymbol(entryPoint, functionName);
} catch (InvalidInputException e) {
this.logMsg("renaming failed for: %s", functionName);
while (sc.hasNextLine()) {
String line = sc.nextLine();

monitor.setProgress(progress++);
if (!line.contains("MakeNameEx"))
continue;
Matcher match = pattern.matcher(line);
if (!match.matches())
continue;
Integer offset = Integer.parseUnsignedInt(match.group(1), 16);
Address entryPoint = this.toAddr(offset);
String functionName = match.group(2);
monitor.setMessage(functionName);
if (functionName.strip().length() > 0) {
try {
this.renameSymbol(entryPoint, functionName);
} catch (InvalidInputException e) {
this.logMsg("renaming failed for: %s", functionName);
}
}
}
}

} catch (IOException e) {
this.logMsg("file not found: %s", idc.toPath());
return false;
}
return true;
}

}
private void repairStringCompareFunctions() {
try {
monitor.setMessage("reparing known function signatures");
Expand Down

0 comments on commit 4658abd

Please sign in to comment.