Skip to content

Commit

Permalink
GP-0 GNU Demangler process startup improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidra1 committed Jun 7, 2024
1 parent b54a7e8 commit db8da86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private boolean doDemangle(Demangler demangler, Program program, TaskMonitor mon
// tell a mangled from a non-mangled symbol.
// Msg.debug(this, "Unable to demangle name: " + mangled);
}
catch (Exception e) {
catch (Exception e) { e.printStackTrace();
// Demangler IndexOutOfBoundsException that we're not sure how to fix
setStatusMsg("Unable to demangle symbol: " + mangled + " at " + addr + ". Message: " +
e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import generic.jar.ResourceFile;
import ghidra.app.util.demangler.*;
import ghidra.app.util.opinion.ElfLoader;
Expand Down Expand Up @@ -106,8 +108,12 @@ else if (mangled.startsWith("__Z")) {
try {

GnuDemanglerNativeProcess process = getNativeProcess(options);
String demangled = process.demangle(mangled).trim();
if (mangled.equals(demangled) || demangled.length() == 0) {
String demangled = process.demangle(mangled);
if (demangled == null) {
throw new DemangledException(false);
}
demangled = demangled.trim();
if (demangled.length() == 0 || mangled.equals(demangled)) {
throw new DemangledException(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -166,35 +165,30 @@ private void createProcess() throws IOException {

String[] command = buildCommand();
IOException exc = null;
String err = "";
isDisposed = true;
try {
process = Runtime.getRuntime().exec(command);
// Give process time to load and report possible error
process.waitFor(200, TimeUnit.MILLISECONDS);
InputStream in = process.getInputStream();
OutputStream out = process.getOutputStream();
reader = new BufferedReader(new InputStreamReader(in));
writer = new PrintWriter(out);
isDisposed = !process.isAlive();
if (isDisposed) {
err = new String(process.getErrorStream().readAllBytes());
process.destroy();
process = null;
}

checkForError(command);

isDisposed = false;
}
catch (IOException e) {
exc = e;
}
catch (InterruptedException e) {
// ignore
}
finally {
if (isDisposed) {
if (process != null) {
process.destroy();
}
if (!getAndSetErrorDisplayed()) {
String errorDetail = err;
String errorDetail = "";
if (exc != null) {
errorDetail = exc.getMessage() + "\n" + errorDetail;
errorDetail = exc.getMessage();
}
errorDetail = "GNU Demangler executable may not be compatible with your system and may need to be rebuilt.\n" +
"(see InstallationGuide.html, 'Building Native Components').\n\n" +
Expand All @@ -207,8 +201,6 @@ private void createProcess() throws IOException {
throw exc;
}
}

checkForError(command);

String key = getKey(applicationName, options);
processesByName.put(key, this);
Expand Down

0 comments on commit db8da86

Please sign in to comment.