Skip to content

Commit 0e3da48

Browse files
committed
Merge remote-tracking branch 'origin/Ghidra_10.1'
2 parents d9788c0 + 3aa234e commit 0e3da48

File tree

12 files changed

+300
-45
lines changed

12 files changed

+300
-45
lines changed

Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/pty/PtySession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface PtySession {
2929
* @return the status code, if applicable and implemented
3030
* @throws InterruptedException if the wait is interrupted
3131
*/
32-
Integer waitExited() throws InterruptedException;
32+
int waitExited() throws InterruptedException;
3333

3434
/**
3535
* Take the greatest efforts to terminate the session (leader and descendants)

Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/pty/local/LocalProcessPtySession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public LocalProcessPtySession(Process process) {
3030
}
3131

3232
@Override
33-
public Integer waitExited() throws InterruptedException {
33+
public int waitExited() throws InterruptedException {
3434
return process.waitFor();
3535
}
3636

Ghidra/Debug/Debugger-agent-gdb/src/main/java/agent/gdb/pty/ssh/SshPtySession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public SshPtySession(Channel channel) {
2828
}
2929

3030
@Override
31-
public Integer waitExited() throws InterruptedException {
31+
public int waitExited() throws InterruptedException {
3232
// Doesn't look like there's a clever way to wait. So do the spin sleep :(
3333
while (!channel.isEOF()) {
3434
Thread.sleep(1000);

Ghidra/Debug/Debugger-agent-gdb/src/test/java/agent/gdb/pty/linux/LinuxPtyTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testSessionBash() throws IOException, InterruptedException {
6565
PtySession bash =
6666
pty.getChild().session(new String[] { DummyProc.which("bash") }, null);
6767
pty.getParent().getOutputStream().write("exit\n".getBytes());
68-
assertEquals(0, bash.waitExited().intValue());
68+
assertEquals(0, bash.waitExited());
6969
}
7070
}
7171

@@ -78,7 +78,7 @@ public void testForkIntoNonExistent() throws IOException, InterruptedException {
7878
* NOTE: Java subprocess dies with code 1 on unhandled exception. TODO: Is there a nice
7979
* way to distinguish whether the code is from java or the execed image?
8080
*/
81-
assertEquals(1, dies.waitExited().intValue());
81+
assertEquals(1, dies.waitExited());
8282
}
8383
}
8484

@@ -117,7 +117,7 @@ public Thread runExitCheck(int expected, PtySession session) {
117117
while (true) {
118118
try {
119119
assertEquals("Early exit with wrong code", expected,
120-
session.waitExited().intValue());
120+
session.waitExited());
121121
return;
122122
}
123123
catch (InterruptedException e) {
@@ -159,7 +159,7 @@ public void testSessionBashEchoTest() throws IOException, InterruptedException {
159159
assertTrue("Not 'exit 3' or 'BASH:exit 3': '" + line + "'",
160160
Set.of("BASH:exit 3", "exit 3").contains(line));
161161

162-
assertEquals(3, bash.waitExited().intValue());
162+
assertEquals(3, bash.waitExited());
163163
}
164164
}
165165

@@ -214,7 +214,7 @@ public void testSessionBashInterruptCat() throws IOException, InterruptedExcepti
214214
writer.flush();
215215
assertTrue(Set.of("BASH:exit 3", "exit 3").contains(reader.readLine()));
216216

217-
assertEquals(3, bash.waitExited().intValue());
217+
assertEquals(3, bash.waitExited());
218218
}
219219
}
220220
}

Ghidra/Debug/Debugger-agent-gdb/src/test/java/agent/gdb/pty/ssh/SshPtyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testSessionBash() throws IOException, InterruptedException {
8282
out.write("exit\n".getBytes("UTF-8"));
8383
out.flush();
8484
new StreamPumper(pty.getParent().getInputStream(), System.out).start();
85-
assertEquals(0, bash.waitExited().intValue());
85+
assertEquals(0, bash.waitExited());
8686
}
8787
}
8888
}

Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionDefinitionUpdatesScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void run() throws Exception {
4545
}
4646

4747
RecoveredClassUtils classUtils = new RecoveredClassUtils(currentProgram, currentLocation,
48-
state.getTool(), this, false, false, false, monitor);
48+
state.getTool(), this, false, false, false, false, monitor);
4949

5050
Namespace classNamespace = classUtils.getClassNamespace(currentAddress);
5151
if (classNamespace == null) {

Ghidra/Features/Decompiler/ghidra_scripts/ApplyClassFunctionSignatureUpdatesScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void run() throws Exception {
4545
}
4646

4747
RecoveredClassUtils classUtils = new RecoveredClassUtils(currentProgram, currentLocation,
48-
state.getTool(), this, false, false, false, monitor);
48+
state.getTool(), this, false, false, false, false, monitor);
4949

5050
Namespace classNamespace = classUtils.getClassNamespace(currentAddress);
5151
if (classNamespace == null) {

Ghidra/Features/Decompiler/ghidra_scripts/RecoverClassesFromRTTIScript.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,37 @@ public class RecoverClassesFromRTTIScript extends GhidraScript {
121121
// show shortened class template names in class structure field names
122122
private static final boolean USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS = true;
123123

124+
// replace defined existing class structures (ie pdb, fid, demangler, or other)with ones created by
125+
// this script and rename the existing ones with a _REPLACED suffix
126+
// NOTE: currently does not replace DWARF
127+
// NEW OPTION:
128+
private static final boolean REPLACE_EXISTING_CLASS_STRUCTURES = true;
129+
124130
private static final String CLASS_DATA_STRUCT_NAME = "_data";
125131

126132
private static final String CONSTRUCTOR_BOOKMARK = "CONSTRUCTOR";
127133
private static final String DESTRUCTOR_BOOKMARK = "DESTRUCTOR";
128134

129135
private static final String INDETERMINATE_BOOKMARK = "INDETERMINATE";
130136

137+
// If replacedClassStructuresOption is set to the following, no replaced structures will be removed
138+
// from the data type manager
139+
private static final int DO_NOT_REMOVE_REPLACED_CLASS_STRUCTURES = 0;
140+
141+
// If replacedClassStructuresOption is set to the following, only empty existing class structures
142+
// that were replaced by this script will be removed from the data type manager
143+
private static final int REMOVE_EMPTY_REPLACED_CLASS_STRUCTURES = 1;
144+
145+
// If replacedClassStructuresOption is set to the following, all existing class structures that
146+
// were replaced by this script, including non-emtpy ones, will be removed from the data type
147+
// manager
148+
private static final int REMOVE_ALL_REPLACED_CLASS_STRUCTURES = 2;
149+
150+
// NEW OPTION -
151+
// This option allows the user to decide whether and how to remove replaced existing class structures
152+
// using one of the above three flags
153+
int replacedClassStructuresOption = DO_NOT_REMOVE_REPLACED_CLASS_STRUCTURES;
154+
131155
boolean programHasRTTIApplied = false;
132156
boolean hasDebugSymbols;
133157
boolean isGcc = false;
@@ -162,6 +186,7 @@ public void run() throws Exception {
162186
recoverClassesFromRTTI = new RTTIWindowsClassRecoverer(currentProgram,
163187
currentLocation, state.getTool(), this, BOOKMARK_FOUND_FUNCTIONS,
164188
USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS, nameVfunctions, hasDebugSymbols,
189+
REPLACE_EXISTING_CLASS_STRUCTURES,
165190
monitor);
166191
}
167192
else if (isGcc()) {
@@ -182,6 +207,7 @@ else if (isGcc()) {
182207
recoverClassesFromRTTI = new RTTIGccClassRecoverer(currentProgram, currentLocation,
183208
state.getTool(), this, BOOKMARK_FOUND_FUNCTIONS,
184209
USE_SHORT_TEMPLATE_NAMES_IN_STRUCTURE_FIELDS, nameVfunctions, hasDebugSymbols,
210+
REPLACE_EXISTING_CLASS_STRUCTURES,
185211
monitor);
186212
}
187213
else {
@@ -275,6 +301,17 @@ else if (isGcc()) {
275301
showGraph(graph);
276302
}
277303

304+
if (replacedClassStructuresOption == REMOVE_EMPTY_REPLACED_CLASS_STRUCTURES) {
305+
println("Removing all empty replaced class structures from the data type manager");
306+
recoverClassesFromRTTI.removeReplacedClassStructures(recoveredClasses, false);
307+
}
308+
309+
if (replacedClassStructuresOption == REMOVE_ALL_REPLACED_CLASS_STRUCTURES) {
310+
println(
311+
"Removing all replaced class structures from the data type manager, including non-empty ones");
312+
recoverClassesFromRTTI.removeReplacedClassStructures(recoveredClasses, true);
313+
}
314+
278315

279316
decompilerUtils.disposeDecompilerInterface();
280317
}

Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIClassRecoverer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public class RTTIClassRecoverer extends RecoveredClassUtils {
4040
TaskMonitor monitor;
4141
boolean hasDebugSymbols;
4242

43+
4344
RTTIClassRecoverer(Program program, ProgramLocation location, PluginTool tool,
4445
FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates,
45-
boolean nameVfunctions, boolean hasDebugSymbols,
46+
boolean nameVfunctions, boolean hasDebugSymbols, boolean replaceClassStructures,
4647
TaskMonitor monitor) {
4748

4849
super(program, location, tool, api, createBookmarks, useShortTemplates, nameVfunctions,
50+
replaceClassStructures,
4951
monitor);
5052

5153
this.program = program;

Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RTTIGccClassRecoverer.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,19 @@ public class RTTIGccClassRecoverer extends RTTIClassRecoverer {
6969
new HashMap<RecoveredClass, Map<RecoveredClass, Long>>();
7070

7171
boolean isDwarfLoaded;
72+
boolean replaceClassStructs;
7273

7374
public RTTIGccClassRecoverer(Program program, ProgramLocation location, PluginTool tool,
7475
FlatProgramAPI api, boolean createBookmarks, boolean useShortTemplates,
75-
boolean nameVfunctions, boolean isDwarfLoaded, TaskMonitor monitor) {
76+
boolean nameVfunctions, boolean isDwarfLoaded, boolean replaceExistingClassStructures,
77+
TaskMonitor monitor) {
7678

7779
super(program, location, tool, api, createBookmarks, useShortTemplates, nameVfunctions,
80+
replaceExistingClassStructures,
7881
isDwarfLoaded,
7982
monitor);
8083
this.isDwarfLoaded = isDwarfLoaded;
84+
this.replaceClassStructs = replaceExistingClassStructures;
8185
}
8286

8387
@Override
@@ -2898,12 +2902,14 @@ private void processDataTypes(RecoveredClass recoveredClass)
28982902
Structure classStruct = createSimpleClassStructure(recoveredClass, vfPointerDataTypes);
28992903

29002904
// check for DWARF -- if none add c/d/etc to class
2905+
//TODO: if decide to replace dwarf data types then remove this check so the replaces
2906+
// in the following methods can replace the dwarf data types
29012907
if (!isDwarfLoaded) {
29022908

29032909
// Now that we have a class data type
29042910
// name constructor and destructor functions and put into the class namespace
29052911
addConstructorsToClassNamespace(recoveredClass, classStruct);
2906-
addDestructorsToClassNamespace(recoveredClass);
2912+
addDestructorsToClassNamespace(recoveredClass, classStruct);
29072913
// addNonThisDestructorsToClassNamespace(recoveredClass);
29082914
// addVbaseDestructorsToClassNamespace(recoveredClass);
29092915
// addVbtableToClassNamespace(recoveredClass);
@@ -2914,15 +2920,16 @@ private void processDataTypes(RecoveredClass recoveredClass)
29142920
// createIndeterminateInlineComments(recoveredClass);
29152921

29162922
// add label on constructor destructor functions that could not be determined which were which
2917-
createIndeterminateLabels(recoveredClass);
2923+
createIndeterminateLabels(recoveredClass, classStruct);
29182924
}
29192925

29202926
// This is done after the class structure is created and added to the dtmanager
29212927
// because if done before the class structures are created
29222928
// then empty classes will get auto-created in the wrong place
29232929
// when the vfunctions are put in the class
29242930

2925-
fillInAndApplyVftableStructAndNameVfunctions(recoveredClass, vfPointerDataTypes);
2931+
fillInAndApplyVftableStructAndNameVfunctions(recoveredClass, vfPointerDataTypes,
2932+
classStruct);
29262933

29272934
}
29282935

0 commit comments

Comments
 (0)