-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOffsetToFunction.java
More file actions
57 lines (51 loc) · 1.86 KB
/
OffsetToFunction.java
File metadata and controls
57 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Given a properly formatted .txt file, it will assign function labels to any offset provided
//@author blu-dev
//@category Functions
//@keybinding
//@menupath
//@toolbar
import ghidra.app.script.GhidraScript;
import ghidra.program.model.util.*;
import ghidra.program.model.reloc.*;
import ghidra.program.model.data.*;
import ghidra.program.model.block.*;
import ghidra.program.model.symbol.*;
import ghidra.program.model.scalar.*;
import ghidra.program.model.mem.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.lang.*;
import ghidra.program.model.pcode.*;
import ghidra.program.model.address.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JFileChooser;
import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.nio.charset.*;
public class OffsetToFunction extends GhidraScript {
public void run() throws Exception {
//TODO Add User Code Here
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("txt files", "txt");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < lines.size(); i++) {
int colon = lines.get(i).indexOf(':');
String name = lines.get(i).substring(0, colon);
Address addr = parseAddress(lines.get(i).substring(colon + 1));
Function func = getFunctionAt(addr);
if (func == null) {
func = createFunction(addr, name);
if (func == null)
throw new RuntimeException("Unable to create function " + name + " at " + Long.toHexString(addr.getOffset()));
}
else {
func.setName(name, SourceType.DEFAULT);
}
}
}
}
}