GT-3481 - Gnu Demangler - Added build support for multiple demangler

versions
This commit is contained in:
dragonmacher 2020-01-27 17:21:03 -05:00
parent 54af47adab
commit 7e7cd5d9ae
44 changed files with 116 additions and 41 deletions

View File

@ -12,6 +12,12 @@ apply plugin: 'eclipse'
eclipse.project.name = 'GPL DemanglerGnu'
def v33_1 = "demangler_gnu_v2_33_1"
def v24 = "demangler_gnu_v2_24"
def srcVersion33_1 = "src/demangler_gnu_v2_33_1"
def srcVersion24 = "src/demangler_gnu_v2_24"
/****************************************************************************
* Defines the platforms we have to support in Ghidra. This model is used
* for all native builds and should be extended by each module as-needed.
@ -53,66 +59,130 @@ task zipBuildableSource(type:Zip) {
description "Collects the source files needed to build this module."
baseName project.name + "-src-for-build"
extension 'zip'
from (project.projectDir.toString() + "/src/demangler_gnu/c") {
into "/src/demangler_gnu"
//
// Version 2.33.1
//
from (project.projectDir.toString() + "/" + srcVersion33_1 + "c") {
into "/" + srcVersion33_1
}
from (project.projectDir.toString() + "/src/demangler_gnu/headers") {
into "/src/demangler_gnu"
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/headers") {
into "/" + srcVersion33_1
}
from (project.projectDir.toString() + "/src/demangler_gnu/build") {
into "/src/demangler_gnu"
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/build") {
into "/" + srcVersion33_1
}
from (project.projectDir.toString() + "/src/demangler_gnu/README.txt")
from (project.projectDir.toString() + "/" + srcVersion33_1 + "/README.txt")
//
// Version 2.24
//
from (project.projectDir.toString() + "/" + srcVersion24 + "c") {
into "/" + srcVersion24
}
from (project.projectDir.toString() + "/" + srcVersion24 + "/headers") {
into "/" + srcVersion24
}
from (project.projectDir.toString() + "/" + srcVersion24 + "/build") {
into "/" + srcVersion24
}
from (project.projectDir.toString() + "/" + srcVersion24 + "/README.txt")
}
model {
//
// Version 2.33.1
//
components {
demangler_gnu(NativeExecutableSpec) {
demangler_gnu_v2_33_1(NativeExecutableSpec) {
targetPlatform "win64"
targetPlatform "linux64"
targetPlatform "osx64"
sources {
c {
source {
srcDir "src/demangler_gnu/c"
srcDir srcVersion33_1 + "/c"
}
exportedHeaders {
srcDir "src/demangler_gnu/headers"
srcDir srcVersion33_1 + "/headers"
}
}
}
}
}
//
// Version 2.24
//
demangler_gnu_v2_24(NativeExecutableSpec) {
targetPlatform "win64"
targetPlatform "linux64"
targetPlatform "osx64"
sources {
c {
source {
srcDir srcVersion24 + "/c"
}
exportedHeaders {
srcDir srcVersion24 + "/headers"
}
}
}
}
}
}
model {
binaries {
/*
Note: 'all' will pass all binary output, which is each platform for each version
*/
all{ b ->
if (toolChain in Gcc) {
def version = b.getApplication().getName()
println "have binary: " + b
if (version.equals(v33_1)) {
if (toolChain in Gcc) {
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
else if (toolChain in VisualCpp) {
cCompiler.args "/D_CONSOLE"
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
else if (toolChain in Clang) {
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
}
else if (version.equals(v24)) {
if (toolChain in Gcc) {
cCompiler.args "-DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
else if (toolChain in VisualCpp) {
cCompiler.args "/D_CONSOLE"
cCompiler.args "/DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
else if (toolChain in Clang) {
cCompiler.args "-DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
}
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
if (targetPlatform.operatingSystem.linux) {
// linker.args "-static"
}
}
else if (toolChain in VisualCpp) {
cCompiler.args "/D_CONSOLE"
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
}
else if (toolChain in Clang) {
cCompiler.args "-DSTANDALONE_DEMANGLER"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
if (targetPlatform.operatingSystem.linux) {
// linker.args "-static"
}
}
}
}
}

View File

@ -7,5 +7,5 @@
Module.manifest||Public Domain||||END|
build.gradle||Public Domain||||END|
settings.gradle||Public Domain||||END|
src/demangler_gnu/README.txt||Public Domain||||END|
src/demangler_gnu_v2.24/README.txt||GHIDRA||||END|
src/demangler_gnu_v2_24/README.txt||Public Domain||||END|
src/demangler_gnu_v2_33_1/README.txt||Public Domain||||END|

View File

@ -24,6 +24,7 @@ import java.io.*;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.demangler.DemangledObject;
import ghidra.app.util.demangler.DemanglerOptions;
import ghidra.app.util.demangler.gnu.GnuDemanglerNativeProcess;
import ghidra.app.util.demangler.gnu.GnuDemanglerParser;
import ghidra.app.util.opinion.ElfLoader;
import ghidra.app.util.opinion.MachoLoader;
@ -42,7 +43,7 @@ public class DemangleElfWithOptionScript extends GhidraScript {
executableFormat);
return;
}
Symbol symbol = null;
if (currentAddress != null && (currentSelection == null || currentSelection.isEmpty())) {
symbol = getSymbolAt(currentAddress);
@ -95,7 +96,10 @@ public class DemangleElfWithOptionScript extends GhidraScript {
}
CompilerSpec compilerSpec = currentProgram.getCompilerSpec();
if (compilerSpec.getCompilerSpecID().getIdAsString().toLowerCase().indexOf("windows") == -1) {
if (compilerSpec.getCompilerSpecID()
.getIdAsString()
.toLowerCase()
.indexOf("windows") == -1) {
return true;
}
return false;
@ -111,9 +115,10 @@ public class DemangleElfWithOptionScript extends GhidraScript {
private Process createProcess(String executableName) throws Exception {
String demanglerName = GnuDemanglerNativeProcess.DEMANGLER_GNU;
OperatingSystem OS = Platform.CURRENT_PLATFORM.getOperatingSystem();
String demanglerExe =
(OS == OperatingSystem.WINDOWS) ? "demangler_gnu.exe" : "demangler_gnu";
(OS == OperatingSystem.WINDOWS) ? demanglerName + ".exe" : demanglerName;
File commandPath = Application.getOSFile("GnuDemangler", demanglerExe);
//

View File

@ -21,7 +21,7 @@ import ghidra.framework.Application;
import ghidra.framework.Platform;
public class GnuDemanglerNativeProcess {
private static final String DEMANGLER_GNU = "demangler_gnu";
public static final String DEMANGLER_GNU = "demangler_gnu_v2.33.1";
private static GnuDemanglerNativeProcess demanglerNativeProcess;