Skip to content

dyld Shared Cache improvements. #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 78 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3d26a75
Make build system more Kotlin-y.
nmggithub Jan 29, 2025
e040921
Revert Kotlin version to continue support for Jupyter.
nmggithub Jan 30, 2025
f8def3b
Pin our dependencies to our Kotlin version, use non-JDK8 standard lib…
nmggithub Feb 6, 2025
2c88df7
Initial DYLD loading proof-of-concept.
nmggithub Jan 22, 2025
b715968
fix typo
nmggithub Jan 23, 2025
10e269b
fix version string logic
nmggithub Jan 23, 2025
ef3d4da
klint fixes
nmggithub Jan 23, 2025
6f356a3
more ktlint fixes
nmggithub Jan 23, 2025
785c618
clarify value name
nmggithub Jan 23, 2025
e6e9e1f
put value in companion object
nmggithub Jan 23, 2025
fe083f5
extract out getComponentBytes function
nmggithub Jan 23, 2025
a206eeb
adjust offset constant to long
nmggithub Jan 23, 2025
9a16dbd
add function to get optimizations header
nmggithub Jan 23, 2025
84b2594
general optimizations
nmggithub Jan 23, 2025
0d05dd6
simplify component getting
nmggithub Jan 23, 2025
1cc7470
bring back actual root header offset
nmggithub Jan 23, 2025
726cbea
Convert rootHeader to throwing computed value.
nmggithub Jan 23, 2025
5f9ac39
Map shared content into each extracted cache component.
nmggithub Jan 26, 2025
1719ff9
Cleanup and add selector string repointing.
nmggithub Jan 27, 2025
bfd61b5
Rename cache extract loader class.
nmggithub Jan 27, 2025
98045f6
Remove fileSystem member variable.
nmggithub Jan 27, 2025
a2bb9b3
Remove unused opt-in.
nmggithub Jan 27, 2025
c464fce
Finish comment.
nmggithub Jan 27, 2025
26e57d4
Handle case with additional layer of indirection.
nmggithub Jan 27, 2025
7498df3
Allowing Ghidra to make optimizations to trampolines and revert previ…
nmggithub Jan 28, 2025
efa3941
Clarify comment.
nmggithub Jan 28, 2025
4c886b2
Some additional work (NOT STABLE).
nmggithub Jan 29, 2025
012c9ef
Separate out extractor logic.
nmggithub Jan 30, 2025
492a811
Rename reader and fix dumb typo.
nmggithub Jan 30, 2025
ce1a4e6
Make ktlint happy.
nmggithub Jan 30, 2025
84dc6b4
Fix incorrectly written segment commands.
nmggithub Jan 30, 2025
20b2182
Fix dumb math error.
nmggithub Jan 30, 2025
f5e8924
General cleanup and bug fixes.
nmggithub Jan 31, 2025
5f632b3
Even more cleanup and fixes.
nmggithub Jan 31, 2025
b573eea
This works, but I have to keep going.
nmggithub Jan 31, 2025
35817d6
Cleanup and start writing symbol table.
nmggithub Jan 31, 2025
046d1bf
Attempt #2 getting back up to speed.
nmggithub Feb 1, 2025
45f23db
Adjust comment.
nmggithub Feb 1, 2025
4af02ea
Properly handle null cases for getting DSC mappings.
nmggithub Feb 1, 2025
344013b
More cleanup for DSC byte provider.
nmggithub Feb 1, 2025
4a133c9
More adjustments (getting closer, hopefully!)
nmggithub Feb 1, 2025
d44f646
Write final parts of __LINKEDIT, make MVP.
nmggithub Feb 1, 2025
540c138
Hopefully make ktlint happy.
nmggithub Feb 1, 2025
915ed09
Offload changes so compiler is happy.
nmggithub Feb 1, 2025
73fdb1f
Some clean up.
nmggithub Feb 1, 2025
ded5718
Clean up and combine classes.
nmggithub Feb 2, 2025
3922c20
Fix up pointers in extractor.
nmggithub Feb 2, 2025
7a7ef00
Make universal binary loading logic more explicit.
nmggithub Feb 2, 2025
767f4eb
Cache extraction results for better performance.
nmggithub Feb 2, 2025
d89ed22
Re-include the executable format re-naming.
nmggithub Feb 2, 2025
a773651
Include ellipsis in message for side pointers.
nmggithub Feb 2, 2025
4c06f91
Extract out string repoints.
nmggithub Feb 2, 2025
66509ee
Cleanup, move fixups to memory helper layer.
nmggithub Feb 2, 2025
ee40995
Add dependency mapping layer and auto-map libobjc for macOS dylibs.
nmggithub Feb 3, 2025
5e32d76
Handle cases where the __LINKEDIT segment is in another file.
nmggithub Feb 3, 2025
23d7edf
Handled more cases where __LINKEDIT is in another file.
nmggithub Feb 3, 2025
56ecd67
Refactor and combine (mostly) into a single package.
nmggithub Feb 3, 2025
42c09f9
Change calculation order to be more readable.
nmggithub Feb 3, 2025
c390062
Adjust and comment the extraction logic.
nmggithub Feb 3, 2025
e68ea84
Remove unused segment map.
nmggithub Feb 3, 2025
b915b78
Fix segment section fixups.
nmggithub Feb 3, 2025
00d481e
Remove use of TaskMonitor for DSCExtractor
nmggithub Feb 3, 2025
3fd5697
Add documentation comment for the file-byteprovider map.
nmggithub Feb 3, 2025
5715e7e
Clean up comments.
nmggithub Feb 3, 2025
c4b9312
Remove unused code.
nmggithub Feb 3, 2025
a0a2d90
Remove unused variable.
nmggithub Feb 3, 2025
50af8f5
Move version string calculation to the filesystem layer.
nmggithub Feb 3, 2025
671d554
Map `libobjc` for all platforms.
nmggithub Feb 3, 2025
9f9295b
Map all dependencies.
nmggithub Feb 5, 2025
8e8d432
Cleanup, move debugging check to filesystem layer, add stub mapper.
nmggithub Feb 6, 2025
6475fc6
Fix race condition and explicitly return references instead of relyin…
nmggithub Feb 6, 2025
f7cc152
Map the ObjC optimizations into the program.
nmggithub Feb 6, 2025
cfdd462
Cleanup DSCHelper and map read-only data to cache-extracted dylibs.
nmggithub Feb 6, 2025
771502c
Adjust and fix mapping functions.
nmggithub Feb 6, 2025
16785d3
Attempt to map read-only data into program.
nmggithub Feb 7, 2025
6e3566b
Minor comment adjustment
nmggithub Feb 7, 2025
fc6da9a
Some logic adjustments
nmggithub Feb 8, 2025
ad7d40c
Remove dylib mapping code.
nmggithub Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions build.gradle

This file was deleted.

64 changes: 64 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// This cannot be used inside the `plugins` block, but can (and is) used elsewhere and
// should match the version used inside the `plugins` block.
val kotlinVersion = "1.9.23"

plugins {
kotlin("jvm") version "1.9.23"
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
id("idea")
}

// Builds a Ghidra Extension for a given Ghidra installation.
//
// An absolute path to the Ghidra installation directory must be supplied either by setting the
// GHIDRA_INSTALL_DIR environment variable or Gradle project property:
//
// > export GHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
// > gradle
//
// or
//
// > gradle -PGHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
//
// Gradle should be invoked from the directory of the project to build. Please see the
// 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.

// ----------------------START "DO NOT MODIFY" SECTION------------------------------
val ghidraInstallDir: String? = System.getenv("GHIDRA_INSTALL_DIR") ?: project.findProperty("GHIDRA_INSTALL_DIR") as String?

if (ghidraInstallDir != null) {
apply(from = File(ghidraInstallDir).canonicalPath + "/support/buildExtension.gradle")
} else {
throw GradleException("GHIDRA_INSTALL_DIR is not defined!")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib", kotlinVersion))
testImplementation(kotlin("test", kotlinVersion))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.3")
testImplementation("org.json:json:20240303")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.3")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.10.3")
}

kotlin {
jvmToolchain(21)
}

tasks.test {
useJUnitPlatform()
}

sourceSets {
main {
kotlin {
srcDirs("ghidra_scripts")
}
}
}
// ----------------------END "DO NOT MODIFY" SECTION-------------------------------
10 changes: 0 additions & 10 deletions settings.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
}
rootProject.name = "GhidraApple"
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class SelectorTrampolineAnalyzer : AbstractAnalyzer(NAME, DESCRIPTION, AnalyzerT
val trampolineFunctions =
program.functionManager
.getFunctions(set, true)
.filter { isPlausibleTrampoline(it) }.toList()
.filter { isPlausibleTrampoline(it) }
.toList()

monitor.maximum = trampolineFunctions.size.toLong()

Expand All @@ -83,8 +84,7 @@ class SelectorTrampolineAnalyzer : AbstractAnalyzer(NAME, DESCRIPTION, AnalyzerT
it.addTag(TRAMPOLINE_TAG)
it.symbol.setNamespace(stubNamespace)
}
findAllSelectors(program, trampolineFunctions, monitor, log).forEach {
(func, selector) ->
findAllSelectors(program, trampolineFunctions, monitor, log).forEach { (func, selector) ->
applySelectorToFunction(func, selector)
}
return true
Expand Down Expand Up @@ -129,7 +129,9 @@ class SelectorTrampolineAnalyzer : AbstractAnalyzer(NAME, DESCRIPTION, AnalyzerT
}

val callOp =
results.highFunction.pcodeOps.iterator().asSequence()
results.highFunction.pcodeOps
.iterator()
.asSequence()
.singleOrNull { it.opcode == PcodeOp.CALLIND || it.opcode == PcodeOp.CALL }
if (callOp != null) {
val selAddress = getConstantFromVarNode(callOp.inputs[2]).getOrNull()?.toDefaultAddressSpace(program)
Expand Down Expand Up @@ -221,7 +223,5 @@ class SelectorTrampolineAnalyzer : AbstractAnalyzer(NAME, DESCRIPTION, AnalyzerT
return getStubsSegment(program) != null
}

private fun getStubsSegment(program: Program): MemoryBlock? {
return program.memory.getBlock("__objc_stubs")
}
private fun getStubsSegment(program: Program): MemoryBlock? = program.memory.getBlock("__objc_stubs")
}
Loading