Skip to content

Commit c9dbb55

Browse files
Merge pull request #91 from CERTCC/z3mac
Improve Z3 support on ARM Macs
2 parents 5b08ff1 + 1f0f12e commit c9dbb55

File tree

4 files changed

+68
-35
lines changed

4 files changed

+68
-35
lines changed

.github/workflows/release_on_tag.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
- name: Unzip Ghidra ${{ matrix.ghidra_version }}
3838
run: 7z x 3rdparty/ghidra_${{ matrix.ghidra_version }}_*.zip -o3rdparty/
3939

40+
# ejs: Ummm, macro anyone?
41+
4042
- name: Download Z3 for Linux x64 (glibc)
4143
uses: robinraju/[email protected]
4244
with:
@@ -74,7 +76,20 @@ jobs:
7476
cp z3-4.12.1-x64-osx-10.16/bin/*.dylib ${{ github.workspace }}/os/mac_x86_64/
7577
rm z3-4.12.1-x64-osx-10.16.zip
7678
rm -r z3-4.12.1-x64-osx-10.16/
77-
79+
80+
- name: Download Z3 for MacOS arm64
81+
uses: robinraju/[email protected]
82+
with:
83+
repository: "Z3Prover/z3"
84+
tag: "z3-4.12.1"
85+
fileName: "z3-4.12.1-arm64-osx-11.0.zip"
86+
- name: Unzip Z3 for MacOS arm64
87+
run: |
88+
7z x z3-4.12.1-arm64-osx-11.0.zip
89+
cp z3-4.12.1-arm64-osx-11.0/bin/*.dylib ${{ github.workspace }}/os/mac_arm_64/
90+
rm z3-4.12.1-arm64-osx-11.0.zip
91+
rm -r z3-4.12.1-arm64-osx-11.0/
92+
7893
- name: Set up Gradle
7994
uses: gradle/gradle-build-action@v2
8095
with:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Current Release
22

3+
## 241204
4+
- Improvements:
5+
* Include Z3 for ARM Macs
6+
* Stream-line build system a bit
7+
38
## 241119
49
- Bugfixes:
510
* Fix bad performance of Disassembly Improvements in specific situations (#81)

build.gradle

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ else {
7777

7878
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
7979

80+
// Technically we probably should not be doing this, but we need to know which platform we're on.
81+
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/GPL/nativePlatforms.gradle"
82+
def ghidraPlatformName = getCurrentPlatformName()
83+
8084
// change this to set the version of Z3 we're using
8185
String z3Version = "4.12.1"
8286

@@ -151,7 +155,6 @@ task printGhidraDir {
151155
println 'Using Ghidra install directory ' + ghidraInstallDir
152156
println 'Using Java ' + targetCompatibility + ' for Ghidra ' + ghidraVersion
153157
println 'Using AUTOCATS test directory ' + autocatsDir
154-
println 'Targeting '+ os.getDisplayName() + ' (' + System.properties['os.name'].toLowerCase() + '-' + System.getProperty('os.arch') + ')'
155158
}
156159

157160
task copyToLib(type: Copy) {
@@ -284,11 +287,16 @@ tasks.clean.dependsOn(tasks.cmakeClean)
284287
// slow because LTO. So we dynamically decide whether to set tasks.cmakeBuild as
285288
// a dependency depending on whether z3 appears to be built.
286289
task buildZ3 {
287-
if (!(file('build/cmake/z3/linux-amd64/libz3.so').exists() ||
288-
file('build/cmake/z3/windows-amd64/libz3.dll').exists() ||
289-
file('build/cmake/z3/osx-amd64/libz3.dylib').exists())) {
290+
if (fileTree("build/cmake/z3").matching {
291+
include "*-*/libz3.so"
292+
include "*-*/libz3.dll"
293+
include "*-*/libz3.dylib"
294+
include "*-*/libz3java.so"
295+
include "*-*/libz3java.dll"
296+
include "*-*/libz3java.dylib"
297+
}.isEmpty()) {
290298
dependsOn(tasks.cmakeBuild)
291-
}
299+
}
292300
}
293301

294302
tasks.build.dependsOn(tasks.buildZ3)
@@ -305,37 +313,31 @@ project.getTasks().matching(
305313
}
306314
);
307315

308-
if (os.isLinux()) {
309-
task copyZ3toOsLinux(type: Copy) {
310-
from ("build/cmake/z3/linux-amd64/libz3.so")
311-
from ("build/cmake/z3/linux-amd64/libz3java.so")
312-
into "os/linux_x86_64"
313-
}
314-
315-
copyZ3toOsLinux.dependsOn(tasks.buildZ3)
316-
copyToLib.dependsOn(copyZ3toOsLinux)
317-
}
316+
task copyZ3(type: Copy) {
317+
from ("build/cmake/z3") {
318+
include "*-*/libz3.so"
319+
include "*-*/libz3.dll"
320+
include "*-*/libz3.dylib"
321+
include "*-*/libz3java.so"
322+
include "*-*/libz3java.dll"
323+
include "*-*/libz3java.dylib"
318324

319-
if (os.isWindows()) {
320-
task copyZ3toOsWin(type: Copy) {
321-
from ("build/cmake/z3/windows-amd64/libz3.dll")
322-
from ("build/cmake/z3/windows-amd64/libz3java.dll")
323-
into "os/win_x86_64"
324325
}
325-
326-
copyZ3toOsWin.dependsOn(tasks.buildZ3)
327-
copyToLib.dependsOn(copyZ3toOsWin)
328-
}
326+
into "os/${ghidraPlatformName}"
329327

330-
if (os.isMacOsX()) {
331-
task copyZ3toOsMac(type: Copy) {
332-
from ("build/cmake/z3/osx-amd64/libz3.dylib")
333-
from ("build/cmake/z3/osx-amd64/libz3java.dylib")
334-
into "os/mac_x86_64"
328+
// https://stackoverflow.com/a/45635959
329+
// Flatten the hierarchy by setting the path
330+
// of all files to their respective basename
331+
eachFile {
332+
path = name
335333
}
336-
337-
copyZ3toOsMac.dependsOn(tasks.buildZ3)
338-
copyToLib.dependsOn(copyZ3toOsMac)
334+
335+
// Flattening the hierarchy leaves empty directories,
336+
// do not copy those
337+
includeEmptyDirs = false
338+
339+
copyZ3.dependsOn(tasks.buildZ3)
340+
copyToLib.dependsOn(copyZ3)
339341
}
340342

341343
// END: cmake z3 build section
@@ -453,12 +455,20 @@ testlogger {
453455

454456
test {
455457

458+
def osDir = file("${ghidraInstallDir}/Ghidra/Extensions/kaiju/os/")
459+
460+
// Automatically find the os dir names.
461+
def osDirNames =
462+
osDir.listFiles()
463+
.findAll { it.isDirectory() }
464+
.collect { file(osDir.name + "/" + it.name )}
465+
.join(':')
466+
456467
jvmArgs = ['-Djava.awt.headless=true',
457468
// add-exports needed prior to Ghidra 10.3 to address sun.awt not exported in JDK 17+
458469
'--add-exports=java.desktop/sun.awt=ALL-UNNAMED',
459470
// add the kaiju os directories to load z3 library to run tests
460-
'-Djava.library.path=' + ghidraInstallDir + '/Ghidra/Extensions/kaiju/lib/:'+ ghidraInstallDir + '/Ghidra/Extensions/kaiju/os/linux_x86_64/:' + ghidraInstallDir + '/Ghidra/Extensions/kaiju/os/mac_x86_64/:' + ghidraInstallDir + '/Ghidra/Extensions/kaiju/os/win_x86_64/']
461-
471+
'-Djava.library.path=' + ghidraInstallDir + '/Ghidra/Extensions/kaiju/lib/:' + osDirNames]
462472
useJUnitPlatform()
463473

464474
maxHeapSize = '2G'

os/mac_arm_64/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The "os/mac_arm_64" directory is intended to hold macOS (OS X) native binaries
2+
which this module is dependent upon. This directory may be eliminated for a specific
3+
module if native binaries are not provided for the corresponding platform.

0 commit comments

Comments
 (0)