Skip to content

Commit

Permalink
Rework build.gradle
Browse files Browse the repository at this point in the history
Download XZ for Java from Maven. Also clean up the build.gradle
somewhat.
  • Loading branch information
al3xtjames committed Jul 31, 2020
1 parent b53ce04 commit c634a7d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist/
gradle.properties
*.dll
*.dylib
*.jar
*.so
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,46 @@ PRF file in **File -> Parse C Source**. Build the updated data type library
by selecting **Parse to File...**. Overwrite the original data type libraries
in `data` and rebuild the plugin.

### Related projects
These are some interesting projects related to UEFI reversing:
- [efiXplorer][3] - IDA plugin for UEFI firmware analysis and reverse
engineering automation
- [Ghidra-EFI-Byte-Code-Processor][4] - EFI Byte Code (EBC) processor module
for Ghidra

## License
Apache 2.0, with some exceptions:

- `src/efidecompress/c/efidecompress.c`: BSD

## Credits
`src/efidecompress/c/efidecompress.c` is a lightly modified version of
[Decompress.c][4] from uefi-firmware-parser (which itself is derived from
[the original in EDK2 BaseTools][5]).
[Decompress.c][5] from uefi-firmware-parser (which itself is derived from
[the original in EDK2 BaseTools][6]).

`lib/xz-1.8.jar` is taken from the [XZ for Java][6] project.
`lib/xz-1.8.jar` is taken from the [XZ for Java][7] project.

The IFD FS loader in `src/main/java/firmware/ifd` used the parser from
[UEFITool][7] as a reference.
[UEFITool][8] as a reference.

The GUID database in `data/guids.csv` is taken from [UEFITool][8].
The GUID database in `data/guids.csv` is taken from [UEFITool][9].

The UEFI data type libraries in `data/uefi_*.gdt` were generated with
`data/gen_prf.sh`, which is partially based off the UEFI parser definition
from [a Ghidra pull request by wrffrz][9]. These data type libraries use
headers from [EDK2 MdePkg][10].
from [a Ghidra pull request by wrffrz][10]. These data type libraries use
headers from [EDK2 MdePkg][11].

[GhidraVitaLoader by xerpi][11] was used as a reference for some parts of the
[GhidraVitaLoader by xerpi][12] was used as a reference for some parts of the
UEFI helper script.

[1]: https://ghidra-sre.org/
[2]: https://summerofcode.withgoogle.com/projects/#6413737605464064
[3]: https://github.com/danse-macabre/ida-efitools
[4]: https://github.com/theopolis/uefi-firmware-parser/blob/21106baf019db9dcd046a3c01ee7b32212de45a5/uefi_firmware/compression/Tiano/Decompress.c
[5]: https://github.com/tianocore/edk2/blob/2e351cbe8e190271b3716284fc1076551d005472/BaseTools/Source/C/Common/Decompress.c
[6]: https://tukaani.org/xz/java.html
[7]: https://github.com/LongSoft/UEFITool
[8]: https://github.com/LongSoft/UEFITool/blob/f863caac9df1c5258e9bcc0441a695b6a3bbaf7c/common/guids.csv
[9]: https://github.com/NationalSecurityAgency/ghidra/pull/501#issuecomment-498374810
[10]: https://github.com/tianocore/edk2/tree/d21e5dbbbf11589113d39619b3e01eb1e8966819/MdePkg/Include
[11]: https://github.com/xerpi/GhidraVitaLoader
[3]: https://github.com/binarly-io/efiXplorer
[4]: https://github.com/meromwolff/Ghidra-EFI-Byte-Code-Processor
[5]: https://github.com/theopolis/uefi-firmware-parser/blob/21106baf019db9dcd046a3c01ee7b32212de45a5/uefi_firmware/compression/Tiano/Decompress.c
[6]: https://github.com/tianocore/edk2/blob/2e351cbe8e190271b3716284fc1076551d005472/BaseTools/Source/C/Common/Decompress.c
[7]: https://tukaani.org/xz/java.html
[8]: https://github.com/LongSoft/UEFITool
[9]: https://github.com/LongSoft/UEFITool/blob/f863caac9df1c5258e9bcc0441a695b6a3bbaf7c/common/guids.csv
[10]: https://github.com/NationalSecurityAgency/ghidra/pull/501#issuecomment-498374810
[11]: https://github.com/tianocore/edk2/tree/d21e5dbbbf11589113d39619b3e01eb1e8966819/MdePkg/Include
[12]: https://github.com/xerpi/GhidraVitaLoader
112 changes: 63 additions & 49 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,97 @@
// application.gradle.version property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
// for the correction version of Gradle to use for the Ghidra installation you specify.

apply plugin: 'c'
model {
platforms {
x64 {
architecture "x86_64"
}
}
import org.apache.tools.ant.taskdefs.condition.Os

//----------------------START "DO NOT MODIFY" SECTION------------------------------
def ghidraInstallDir

if (System.env.GHIDRA_INSTALL_DIR) {
ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR
}
else if (project.hasProperty("GHIDRA_INSTALL_DIR")) {
ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR")
}

if (ghidraInstallDir) {
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
}
else {
throw new GradleException("GHIDRA_INSTALL_DIR is not defined!")
}
//----------------------END "DO NOT MODIFY" SECTION-------------------------------

apply plugin: "c"
model {
components {
efidecompress(NativeLibrarySpec) {
targetPlatform 'x64'

sources {
c {
source {
srcDir 'src/efidecompress/c'
include 'efidecompress.c'
srcDir "src/efidecompress/c"
include "efidecompress.c"
}
}
}

binaries.all {
cCompiler.args '-DCONFIG_JNI'
cCompiler.args "-DCONFIG_JNI"
if (targetPlatform.operatingSystem.macOsX) {
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
cCompiler.args '-mmacosx-version-min=10.9'
linker.args '-mmacosx-version-min=10.9'
cCompiler.args "-I", "${System.properties['java.home']}/include"
cCompiler.args "-I", "${System.properties['java.home']}/include/darwin"
cCompiler.args "-mmacosx-version-min=10.9"
linker.args "-mmacosx-version-min=10.9"
} else if (targetPlatform.operatingSystem.linux) {
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
cCompiler.args '-D_FILE_OFFSET_BITS=64'
cCompiler.args "-I", "${System.properties['java.home']}/include"
cCompiler.args "-I", "${System.properties['java.home']}/include/linux"
cCompiler.args "-D_FILE_OFFSET_BITS=64"
} else if (targetPlatform.operatingSystem.windows) {
cCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}\\include"
cCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}\\include\\win32"
cCompiler.args "-I${System.properties['java.home']}\\include"
cCompiler.args "-I${System.properties['java.home']}\\include\\win32"
}
}
}
}
}

import org.apache.tools.ant.taskdefs.condition.Os;
repositories {
mavenCentral()
}

configurations {
toCopy
}

dependencies {
toCopy group: "org.tukaani", name: "xz", version: "1.8"
}

task copyLibraries(type: Copy, dependsOn: "efidecompressSharedLibrary") {
copy {
from configurations.toCopy into "lib"
}

task copyLibrary(type: Copy) {
if (Os.isFamily(Os.FAMILY_MAC)) {
from file("$buildDir/libs/efidecompress/shared/libefidecompress.dylib") into "$projectDir/os/osx64"
from "$buildDir/libs/efidecompress/shared/libefidecompress.dylib" into "os/osx64"
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
from file("$buildDir/libs/efidecompress/shared/libefidecompress.so") into "$projectDir/os/linux64"
from "$buildDir/libs/efidecompress/shared/libefidecompress.so" into "os/linux64"
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
from file("$buildDir\\libs\\efidecompress\\shared\\efidecompress.dll") into "$projectDir\\os\\win64"
from "$buildDir/libs/efidecompress/shared/efidecompress.dll" into "os/win64"
}
}

copyLibrary.dependsOn 'efidecompressSharedLibrary'

//----------------------START "DO NOT MODIFY" SECTION------------------------------
def ghidraInstallDir
buildExtension.dependsOn "copyLibraries"

if (System.env.GHIDRA_INSTALL_DIR) {
ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR
}
else if (project.hasProperty("GHIDRA_INSTALL_DIR")) {
ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR")
}
task cleanLibraries(type: Delete) {
delete fileTree("lib").matching {
include "*.jar"
}

if (ghidraInstallDir) {
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/support/buildExtension.gradle"
}
else {
throw new GradleException("GHIDRA_INSTALL_DIR is not defined!")
delete fileTree("os").matching {
include "osx64/*.dylib"
include "linux64/*.so"
include "win64/*.dll"
}
}
//----------------------END "DO NOT MODIFY" SECTION-------------------------------

buildExtension.dependsOn 'copyLibrary'

clean {
delete "$projectDir/os/linux64/libefidecompress.so"
delete "$projectDir/os/osx64/libefidecompress.dylib"
delete "$projectDir/os/win64/efidecompress.dll"
}
clean.dependsOn "cleanLibraries"
Binary file removed lib/xz-1.8.jar
Binary file not shown.

0 comments on commit c634a7d

Please sign in to comment.