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' 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 * 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. * for all native builds and should be extended by each module as-needed.
@ -54,65 +60,129 @@ task zipBuildableSource(type:Zip) {
baseName project.name + "-src-for-build" baseName project.name + "-src-for-build"
extension 'zip' 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") { from (project.projectDir.toString() + "/" + srcVersion33_1 + "/headers") {
into "/src/demangler_gnu" into "/" + srcVersion33_1
} }
from (project.projectDir.toString() + "/src/demangler_gnu/build") { from (project.projectDir.toString() + "/" + srcVersion33_1 + "/build") {
into "/src/demangler_gnu" 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 { model {
//
// Version 2.33.1
//
components { components {
demangler_gnu(NativeExecutableSpec) { demangler_gnu_v2_33_1(NativeExecutableSpec) {
targetPlatform "win64" targetPlatform "win64"
targetPlatform "linux64" targetPlatform "linux64"
targetPlatform "osx64" targetPlatform "osx64"
sources { sources {
c { c {
source { source {
srcDir "src/demangler_gnu/c" srcDir srcVersion33_1 + "/c"
} }
exportedHeaders { 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 { model {
binaries { binaries {
all{ b ->
if (toolChain in Gcc) {
cCompiler.args "-DSTANDALONE_DEMANGLER" /*
cCompiler.args "-DHAVE_STDLIB_H" Note: 'all' will pass all binary output, which is each platform for each version
cCompiler.args "-DHAVE_STRING_H" */
if (targetPlatform.operatingSystem.linux) { all{ b ->
// linker.args "-static"
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 (toolChain in VisualCpp) { else if (version.equals(v24)) {
cCompiler.args "/D_CONSOLE" if (toolChain in Gcc) {
cCompiler.args "-DSTANDALONE_DEMANGLER" cCompiler.args "-DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STDLIB_H" cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H" cCompiler.args "-DHAVE_STRING_H"
} }
else if (toolChain in Clang) { else if (toolChain in VisualCpp) {
cCompiler.args "-DSTANDALONE_DEMANGLER" cCompiler.args "/D_CONSOLE"
cCompiler.args "-DHAVE_STDLIB_H" cCompiler.args "/DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STRING_H" cCompiler.args "-DHAVE_STDLIB_H"
if (targetPlatform.operatingSystem.linux) { cCompiler.args "-DHAVE_STRING_H"
// linker.args "-static" }
else if (toolChain in Clang) {
cCompiler.args "-DMAIN_CPLUS_DEM"
cCompiler.args "-DHAVE_STDLIB_H"
cCompiler.args "-DHAVE_STRING_H"
} }
} }
} }
} }
} }

View File

@ -7,5 +7,5 @@
Module.manifest||Public Domain||||END| Module.manifest||Public Domain||||END|
build.gradle||Public Domain||||END| build.gradle||Public Domain||||END|
settings.gradle||Public Domain||||END| settings.gradle||Public Domain||||END|
src/demangler_gnu/README.txt||Public Domain||||END| src/demangler_gnu_v2_24/README.txt||Public Domain||||END|
src/demangler_gnu_v2.24/README.txt||GHIDRA||||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.script.GhidraScript;
import ghidra.app.util.demangler.DemangledObject; import ghidra.app.util.demangler.DemangledObject;
import ghidra.app.util.demangler.DemanglerOptions; import ghidra.app.util.demangler.DemanglerOptions;
import ghidra.app.util.demangler.gnu.GnuDemanglerNativeProcess;
import ghidra.app.util.demangler.gnu.GnuDemanglerParser; import ghidra.app.util.demangler.gnu.GnuDemanglerParser;
import ghidra.app.util.opinion.ElfLoader; import ghidra.app.util.opinion.ElfLoader;
import ghidra.app.util.opinion.MachoLoader; import ghidra.app.util.opinion.MachoLoader;
@ -95,7 +96,10 @@ public class DemangleElfWithOptionScript extends GhidraScript {
} }
CompilerSpec compilerSpec = currentProgram.getCompilerSpec(); CompilerSpec compilerSpec = currentProgram.getCompilerSpec();
if (compilerSpec.getCompilerSpecID().getIdAsString().toLowerCase().indexOf("windows") == -1) { if (compilerSpec.getCompilerSpecID()
.getIdAsString()
.toLowerCase()
.indexOf("windows") == -1) {
return true; return true;
} }
return false; return false;
@ -111,9 +115,10 @@ public class DemangleElfWithOptionScript extends GhidraScript {
private Process createProcess(String executableName) throws Exception { private Process createProcess(String executableName) throws Exception {
String demanglerName = GnuDemanglerNativeProcess.DEMANGLER_GNU;
OperatingSystem OS = Platform.CURRENT_PLATFORM.getOperatingSystem(); OperatingSystem OS = Platform.CURRENT_PLATFORM.getOperatingSystem();
String demanglerExe = String demanglerExe =
(OS == OperatingSystem.WINDOWS) ? "demangler_gnu.exe" : "demangler_gnu"; (OS == OperatingSystem.WINDOWS) ? demanglerName + ".exe" : demanglerName;
File commandPath = Application.getOSFile("GnuDemangler", demanglerExe); File commandPath = Application.getOSFile("GnuDemangler", demanglerExe);
// //

View File

@ -21,7 +21,7 @@ import ghidra.framework.Application;
import ghidra.framework.Platform; import ghidra.framework.Platform;
public class GnuDemanglerNativeProcess { 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; private static GnuDemanglerNativeProcess demanglerNativeProcess;