push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,205 @@
# Build settings based on the upstream Xcode project.
# See: https://github.com/apple-oss-distributions/dyld/blob/main/dyld.xcodeproj/project.pbxproj
# Project settings
project(
'dyld',
'c', 'cpp',
default_options : { 'cpp_std': 'c++20' },
version : '@version@'
)
add_project_arguments(
# Prevent build failures due to these targets not being defined
'-DTARGET_OS_BRIDGE=0',
'-DTARGET_OS_EXCLAVEKIT=0',
# Enable support for arm64 variants
'-DSUPPORT_ARCH_arm64e=1',
'-DSUPPORT_ARCH_arm64_32=1',
# Per base.xcconfig
'-Wmost',
'-Wimplicit-fallthrough',
'-Wno-unknown-pragmas',
'-Wno-assume',
'-Wformat-nonliteral',
'-Wno-vla-extension',
'-Wundef-prefix=SUPPORT_',
language : [ 'c', 'cpp' ],
)
# Dependencies
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
llvm_dep = dependency('llvm')
openssl_dep = dependency('openssl', version : '>=3.0')
common_inc = [
'common',
'dyld',
'include',
'mach_o',
]
# Internal dependencies
corecrypto = static_library(
'corecrypto',
include_directories : [
common_inc,
'compat',
],
sources : [
'compat/corecrypto/ccdigest.c',
'compat/corecrypto/ccsha1.c',
'compat/corecrypto/ccsha2.c',
],
)
corecrypto_dep = declare_dependency(
dependencies : [ openssl_dep ],
include_directories : 'compat',
link_with : corecrypto,
)
lsl = static_library(
'lsl',
cpp_args : [
# Required for `_COMM_PAGE_CPU_CAPABILITIES64` in <System/machine/cpu_capabilities.h>
'-DPRIVATE',
],
include_directories : [
common_inc,
'cache-builder',
'cache_builder',
'libdyld',
'lsl',
],
sources : [
'lsl/Allocator.cpp',
'lsl/CRC32c.cpp',
'lsl/PVLEInt64.cpp',
],
)
lsl_dep = declare_dependency(
include_directories : [ 'lsl' ],
link_with : lsl,
)
# These files need to be built with `BUILDING_LIBDYLD` not `BUILDING_DYLDINFO`.
# `dyld_info` cant just link against `libdyld` because the symbols it needs are not publicly exported.
# Building `libdyld` as a static archive doesnt work because it results in internal error when linking with ld64.
libminidyld = static_library(
'minidyld',
cpp_args : [
# Required for `openbyid_np` in <System/sys/fsgetpath.h>
'-DPRIVATE',
'-DBUILDING_LIBDYLD=1',
],
dependencies : [ corecrypto_dep, lsl_dep ],
include_directories : [
common_inc,
'cache-builder',
'cache_builder',
'libdyld',
'libdyld_introspection',
],
sources : [
'common/CachePatching.cpp',
'common/MachOLayout.cpp',
'common/MachOLoaded.cpp',
'libdyld/CrashReporterAnnotations.c',
'mach_o/ChainedFixups.cpp',
'mach_o/GradedArchitectures.cpp',
],
)
libdsc_extractor = shared_library(
'dsc_extractor',
cpp_args : [ '-DBUILDING_SHARED_CACHE_EXTRACTOR=1' ],
dependencies : [ corecrypto_dep, lsl_dep ],
include_directories : [
common_inc,
'cache-builder',
'cache_builder',
],
install : true,
link_args : [ '-Wl,-exported_symbol,_dyld_shared_cache_extract_dylibs_progress' ],
link_with : [ libminidyld ],
name_prefix : '',
name_suffix : 'bundle',
sources : [
'common/DyldSharedCache.cpp',
'common/MachOFile.cpp',
'other-tools/dsc_extractor.cpp',
'other-tools/dsc_iterator.cpp',
'common/MachOLayout.cpp',
'common/Diagnostics.cpp',
],
)
# Binaries
executable(
'dsc_extractor',
install : true,
link_args : [ '-Wl,-exported_symbol,_dyld_shared_cache_extract_dylibs_progress' ],
link_with : [ libdsc_extractor ],
sources : [ 'other-tools/dsc_extractor_bin.cpp' ],
)
executable(
'dyld_info',
cpp_args : [
'-DBUILDING_DYLDINFO=1',
'-DBUILDING_FOR_TOOLCHAIN=1',
],
dependencies : [
corecrypto_dep,
llvm_dep,
lsl_dep,
],
include_directories : [
common_inc,
'cache-builder',
'cache_builder',
],
install : true,
link_args : [ '-Wl,-weak-lLTO' ],
link_with : [ libminidyld ],
sources : [
'cache-builder/FileUtils.cpp',
'common/Diagnostics.cpp',
'common/DyldSharedCache.cpp',
'common/MachOAnalyzer.cpp',
'common/MachOFile.cpp',
'common/MetadataVisitor.cpp',
'common/SwiftVisitor.cpp',
'mach_o/Architecture.cpp',
'mach_o/Archive.cpp',
'mach_o/BindOpcodes.cpp',
'mach_o/ChainedFixups.cpp',
'mach_o/CompactUnwind.cpp',
'mach_o/Error.cpp',
'mach_o/ExportsTrie.cpp',
'mach_o/Fixups.cpp',
'mach_o/FunctionStarts.cpp',
'mach_o/Header.cpp',
'mach_o/Image.cpp',
'mach_o/Instructions.cpp',
'mach_o/LoggingStub.cpp',
'mach_o/Misc.cpp',
'mach_o/NListSymbolTable.cpp',
'mach_o/ObjC.cpp',
'mach_o/Platform.cpp',
'mach_o/Policy.cpp',
'mach_o/RebaseOpcodes.cpp',
'mach_o/SplitSeg.cpp',
'mach_o/Symbol.cpp',
'mach_o/Universal.cpp',
'mach_o/Version32.cpp',
'mach_o/Version64.cpp',
'other-tools/dyld_info.cpp',
],
)
install_man('doc/man/man1/dyld_info.1')

View File

@@ -0,0 +1,171 @@
{
lib,
apple-sdk_12,
ld64,
mkAppleDerivation,
cmake,
llvmPackages,
openssl,
pkg-config,
stdenvNoCC,
fetchurl,
}:
let
# libdyld needs CrashReporterClient.h, which is hard to find, but WebKit2 has it.
# Fetch it directly because the Darwin stdenv bootstrap cant depend on fetchgit.
crashreporter_h = fetchurl {
url = "https://raw.githubusercontent.com/apple-oss-distributions/WebKit2/WebKit2-7605.1.33.0.2/Platform/spi/Cocoa/CrashReporterClientSPI.h";
hash = "sha256-0ybVcwHuGEdThv0PPjYQc3SW0YVOyrM3/L9zG/l1Vtk=";
};
launchd = apple-sdk_12.sourceRelease "launchd";
Libc = apple-sdk_12.sourceRelease "Libc";
libplatform = apple-sdk_12.sourceRelease "libplatform";
libpthread = apple-sdk_12.sourceRelease "libpthread";
xnu = apple-sdk_12.sourceRelease "xnu";
privateHeaders = stdenvNoCC.mkDerivation {
name = "dyld-deps-private-headers";
buildCommand = ''
mkdir -p "$out/include/System"
for dir in arm i386 machine; do
mkdir -p "$out/include/$dir"
for file in '${xnu}/osfmk/'$dir/*; do
name=$(basename "$file")
# Skip copying `endian.h` because it conflicts with the SDK, breaking the build on x86_64-darwin.
test "$name" != endian.h && cp -r "$file" "$out/include/$dir/$name"
done
ln -s "$out/include/$dir" "$out/include/System/$dir"
done
install -D -m644 -t "$out/include/System" \
'${Libc}/stdlib/FreeBSD/atexit.h'
mkdir -p "$out/include/System/sys"
substitute '${xnu}/bsd/sys/fsgetpath.h' "$out/include/System/sys/fsgetpath.h" \
--replace-fail '#ifdef __APPLE_API_PRIVATE' '#if 1'
install -D -m644 -t "$out/include" \
'${libplatform}/private/_simple.h' \
'${Libc}/darwin/libc_private.h' \
'${Libc}/darwin/subsystem.h' \
'${ld64.src}/src/ld/cs_blobs.h' \
'${launchd}/liblaunch/vproc_priv.h'
substitute '${crashreporter_h}' "$out/include/CrashReporterClient.h" \
--replace-fail 'USE(APPLE_INTERNAL_SDK)' '1' \
--replace-fail '#import <CrashReporterClient.h>' '#include <stdint.h>' \
--replace-fail '#else' '#define CRSetCrashLogMessage2 CRSetCrashLogMessage'
install -D -m644 -t "$out/include/pthread" \
'${libpthread}/private/pthread/spinlock_private.h' \
'${libpthread}/private/pthread/tsd_private.h'
install -D -m644 -t "$out/include/os" \
'${xnu}/libsyscall/os/tsd.h' \
'${xnu}/libkern/os/atomic_private.h' \
'${xnu}/libkern/os/atomic_private_arch.h' \
'${xnu}/libkern/os/atomic_private_impl.h' \
'${xnu}/libkern/os/base_private.h' \
'${libplatform}/private/os/lock_private.h'
substituteInPlace "$out/include/os/lock_private.h" \
--replace-fail ', bridgeos(4.0)' ""
# This file is part of ld-prime, which is unhelpfully not included in the dyld source release.
# Fortunately, nothing in it is actually needed to build `dyld_info` and `dsc_extractor`.
touch "$out/include/File.h"
'';
};
in
mkAppleDerivation {
releaseName = "dyld";
outputs = [
"out"
"lib"
"man"
];
propagatedBuildOutputs = [ ];
xcodeHash = "sha256-NfaENSF699xjc+eKtOm1RyXUCMD6xTaJ5+9arLllqyw=";
patches = [
# Disable use of private kdebug API
./patches/0001-Disable-kdebug-trace.patch
# dyld_info requires `startsWith`, but its not normally built for `dyld_info`.
./patches/0002-Provide-startsWith-for-dyld_info.patch
# dyld_info tries to weakly link against libLTO using this macro.
./patches/0003-Add-weaklinking_h.patch
# The LLVMOpInfoCallback args comment out one of the args. Fix that for compatibility with nixpkgs LLVM.
./patches/0004-Fix-llvm-op-info-callback-args.patch
# Some private headers depend on corecrypto, which we cant use.
# Use the headers from the ld64 port, which delegates to OpenSSL.
./patches/0005-Add-OpenSSL-based-CoreCrypto-digest-functions.patch
# `dsc_extractor` builds a dylib, but it includes a program that can perform cache extraction.
# This extracts just the driver into a file to make building the actual program easier.
./patches/0006-Add-dsc_extractor_bin_cpp.patch
];
postPatch = ''
substituteInPlace include/mach-o/dyld.h \
--replace-fail '#ifdef __DRIVERKIT_19_0' "#if 0" \
--replace-fail ', bridgeos(5.0)' "" \
--replace-fail 'DYLD_EXCLAVEKIT_UNAVAILABLE' "" \
--replace-fail '__API_UNAVAILABLE(ios, tvos, watchos) __API_UNAVAILABLE(bridgeos)' ""
substituteInPlace include/mach-o/dyld_priv.h \
--replace-fail ', bridgeos(3.0)' ""
substituteInPlace include/mach-o/dyld_process_info.h \
--replace-fail '__API_UNAVAILABLE(ios, tvos, watchos) __API_UNAVAILABLE(bridgeos)' ""
substituteInPlace include/mach-o/utils_priv.h \
--replace-fail 'SPI_AVAILABLE(macos(15.0), ios(18.0), tvos(18.0), watchos(11.0))' ""
substituteInPlace libdyld/utils.cpp \
--replace-fail 'DYLD_EXCLAVEKIT_UNAVAILABLE' ""
cat <<EOF > libdyld/CrashReporterAnnotations.c
#include <CrashReporterClient.h>
struct crashreporter_annotations_t gCRAnnotations
__attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
= { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
EOF
# Fix header includes
substituteInPlace libdyld_introspection/dyld_introspection.cpp \
--replace-fail 'dyld_introspection.h' 'mach-o/dyld_introspection.h'
substituteInPlace dyld/Loader.h \
--replace-fail 'dyld_priv.h' 'mach-o/dyld_priv.h'
# Remove unused header include (since the compat shims dont provide it).
substituteInPlace other-tools/dsc_extractor.cpp \
--replace-fail '#include <CommonCrypto/CommonHMAC.h>' ""
# Specify path to `dsc_extractor.bundle` for `dlopen`
substituteInPlace other-tools/dsc_extractor_bin.cpp \
--subst-var lib
'';
env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
buildInputs = [
apple-sdk_12 # Needed for `PLATFORM_FIRMWARE` and `PLATFORM_SEPOS` defines in `mach-o/loader.h`.
llvmPackages.llvm
openssl
];
nativeBuildInputs = [
cmake # CMake is required for Meson to find LLVM as a dependency.
pkg-config
];
dontUseCmakeConfigure = true;
meta.description = "Dyld-related commands for Darwin";
}

View File

@@ -0,0 +1,108 @@
diff --git a/dyld/Tracing.h b/dyld/Tracing.h
index 1e6e3027d9..bac62cf72d 100644
--- a/dyld/Tracing.h
+++ b/dyld/Tracing.h
@@ -31,29 +31,25 @@
#include <mach-o/loader.h>
#include <TargetConditionals.h>
#include "Defines.h"
-#if TARGET_OS_EXCLAVEKIT
- #define KDBG_CODE(a, b, c) (c)
- #define DBG_DYLD_UUID (5)
- #define DBG_DYLD_UUID_MAP_A (0)
- #define DBG_DYLD_UUID_MAP_B (1)
- #define DBG_DYLD_UUID_MAP_32_A (2)
- #define DBG_DYLD_UUID_MAP_32_B (3)
- #define DBG_DYLD_UUID_MAP_32_C (4)
- #define DBG_DYLD_UUID_UNMAP_A (5)
- #define DBG_DYLD_UUID_UNMAP_B (6)
- #define DBG_DYLD_UUID_UNMAP_32_A (7)
- #define DBG_DYLD_UUID_UNMAP_32_B (8)
- #define DBG_DYLD_UUID_UNMAP_32_C (9)
- #define DBG_DYLD_UUID_SHARED_CACHE_A (10)
- #define DBG_DYLD_UUID_SHARED_CACHE_B (11)
- #define DBG_DYLD_UUID_SHARED_CACHE_32_A (12)
- #define DBG_DYLD_UUID_SHARED_CACHE_32_B (13)
- #define DBG_DYLD_UUID_SHARED_CACHE_32_C (14)
- #define DBG_DYLD_AOT_UUID_MAP_A (15)
- #define DBG_DYLD_AOT_UUID_MAP_B (16)
-#else
- #include <sys/kdebug_private.h>
-#endif
+#define KDBG_CODE(a, b, c) (c)
+#define DBG_DYLD_UUID (5)
+#define DBG_DYLD_UUID_MAP_A (0)
+#define DBG_DYLD_UUID_MAP_B (1)
+#define DBG_DYLD_UUID_MAP_32_A (2)
+#define DBG_DYLD_UUID_MAP_32_B (3)
+#define DBG_DYLD_UUID_MAP_32_C (4)
+#define DBG_DYLD_UUID_UNMAP_A (5)
+#define DBG_DYLD_UUID_UNMAP_B (6)
+#define DBG_DYLD_UUID_UNMAP_32_A (7)
+#define DBG_DYLD_UUID_UNMAP_32_B (8)
+#define DBG_DYLD_UUID_UNMAP_32_C (9)
+#define DBG_DYLD_UUID_SHARED_CACHE_A (10)
+#define DBG_DYLD_UUID_SHARED_CACHE_B (11)
+#define DBG_DYLD_UUID_SHARED_CACHE_32_A (12)
+#define DBG_DYLD_UUID_SHARED_CACHE_32_B (13)
+#define DBG_DYLD_UUID_SHARED_CACHE_32_C (14)
+#define DBG_DYLD_AOT_UUID_MAP_A (15)
+#define DBG_DYLD_AOT_UUID_MAP_B (16)
#include "Defines.h"
@@ -111,24 +107,10 @@
uint64_t value() const { return _value; }
private:
void prepare(uint32_t code) {
-#if !TARGET_OS_EXCLAVEKIT
- if (_str) {
- _value = kdebug_trace_string(code, 0, _str);
- if (_value == (uint64_t)-1) _value = 0;
- }
-#endif
}
void destroy(uint32_t code) {
-#if !TARGET_OS_EXCLAVEKIT
- if (_str && _value) {
- kdebug_trace_string(code, _value, nullptr);
- }
-#endif
}
friend class ScopedTimer;
- friend uint64_t kdebug_trace_dyld_duration_start(uint32_t code, kt_arg data1, kt_arg data2, kt_arg data3);
- friend void kdebug_trace_dyld_duration_end(uint64_t pair_id, uint32_t code, kt_arg data4, kt_arg data5, kt_arg data6);
- friend void kdebug_trace_dyld_marker(uint32_t code, kt_arg data1, kt_arg data2, kt_arg data3, kt_arg data4);
uint64_t _value;
const char* _str;
};
@@ -168,29 +150,6 @@
uint64_t current_trace_id = 0;
};
-#if !TARGET_OS_EXCLAVEKIT
-VIS_HIDDEN
-void kdebug_trace_dyld_image(const uint32_t code, const char* path, const uuid_t* uuid_bytes,
- const fsobj_id_t fsobjid, const fsid_t fsid, const void* load_addr,
- uint32_t cpusubtype);
-#endif
-
-VIS_HIDDEN
-void kdebug_trace_dyld_cache(uint64_t fsobjid, uint64_t fsid, uint64_t sharedCacheBaseAddress,
- const uint8_t sharedCacheUUID[16]);
-
-VIS_HIDDEN
-bool kdebug_trace_dyld_enabled(uint32_t code);
-
-VIS_HIDDEN
-void kdebug_trace_dyld_marker(uint32_t code, kt_arg data1, kt_arg data2, kt_arg data3, kt_arg data4);
-
-VIS_HIDDEN
-uint64_t kdebug_trace_dyld_duration_start(uint32_t code, kt_arg data1, kt_arg data2, kt_arg data3);
-
-VIS_HIDDEN
-void kdebug_trace_dyld_duration_end(uint64_t trace_id, uint32_t code, kt_arg data4, kt_arg data5, kt_arg data6);
-
VIS_HIDDEN
void syntheticBacktrace(const char *reason, bool enableExternally=false);

View File

@@ -0,0 +1,20 @@
diff --git a/common/MachOFile.cpp b/common/MachOFile.cpp
index 3e7b95bcfe..265ae7c475 100644
--- a/common/MachOFile.cpp
+++ b/common/MachOFile.cpp
@@ -2493,7 +2493,14 @@
}
#endif // BUILDING_APP_CACHE_UTIL || BUILDING_DYLDINFO
-#if BUILDING_CACHE_BUILDER || BUILDING_CACHE_BUILDER_UNIT_TESTS
+#if BUILDING_DYLDINFO || BUILDING_CACHE_BUILDER || BUILDING_CACHE_BUILDER_UNIT_TESTS
+
+#if BUILDING_DYLDINFO
+static bool startsWith(const char* buffer, const char* valueToFind) {
+ return strncmp(buffer, valueToFind, strlen(valueToFind)) == 0;
+}
+#endif
+
static bool platformExcludesPrebuiltClosure_macOS(const char* path) {
// We no longer support ROSP, so skip all paths which start with the special prefix
if ( startsWith(path, "/System/Library/Templates/Data/") )

View File

@@ -0,0 +1,34 @@
diff --git a/include/SoftLinking/WeakLinking.h b/include/SoftLinking/WeakLinking.h
new file mode 100644
index 0000000000..82755e2a43
--- /dev/null
+++ b/include/SoftLinking/WeakLinking.h
@@ -1,0 +1,28 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#define WEAK_LINK_FORCE_IMPORT(sym) extern __attribute__((weak_import)) __typeof__(sym) sym

View File

@@ -0,0 +1,13 @@
diff --git a/other-tools/dyld_info.cpp b/other-tools/dyld_info.cpp
index 2de4978ba5..2ce27257d9 100644
--- a/other-tools/dyld_info.cpp
+++ b/other-tools/dyld_info.cpp
@@ -991,7 +991,7 @@
return ((SymbolicatedImage*)di)->lookupSymbol(referencePC, referenceValue, *referenceType, *referenceName);
}
-static int printDumpOpInfoCallback(void* di, uint64_t pc, uint64_t offset, uint64_t opSize, /* uint64_t instSize, */
+static int printDumpOpInfoCallback(void* di, uint64_t pc, uint64_t offset, uint64_t opSize, uint64_t instSize,
int tagType, void* tagBuf)
{
return ((SymbolicatedImage*)di)->opInfo(pc, offset, opSize, tagType, tagBuf);

View File

@@ -0,0 +1,370 @@
From 36767c7345161baf0ab125f95c8557f8e24f25db Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Tue, 9 Apr 2024 19:28:17 -0400
Subject: [PATCH 7/8] Add OpenSSL-based CoreCrypto digest functions
---
compat/CommonCrypto/CommonDigest.h | 6 +++
compat/CommonCrypto/CommonDigestSPI.c | 21 +++++++++++
compat/CommonCrypto/CommonDigestSPI.h | 14 +++++++
compat/corecrypto/api_defines.h | 10 +++++
compat/corecrypto/ccdigest.c | 53 +++++++++++++++++++++++++++
compat/corecrypto/ccdigest.h | 27 ++++++++++++++
compat/corecrypto/ccdigest_private.h | 19 ++++++++++
compat/corecrypto/ccsha1.c | 22 +++++++++++
compat/corecrypto/ccsha1.h | 9 +++++
compat/corecrypto/ccsha2.c | 22 +++++++++++
compat/corecrypto/ccsha2.h | 9 +++++
11 files changed, 212 insertions(+)
create mode 100644 compat/CommonCrypto/CommonDigest.h
create mode 100644 compat/CommonCrypto/CommonDigestSPI.c
create mode 100644 compat/CommonCrypto/CommonDigestSPI.h
create mode 100644 compat/corecrypto/api_defines.h
create mode 100644 compat/corecrypto/ccdigest.c
create mode 100644 compat/corecrypto/ccdigest.h
create mode 100644 compat/corecrypto/ccdigest_private.h
create mode 100644 compat/corecrypto/ccsha1.c
create mode 100644 compat/corecrypto/ccsha1.h
create mode 100644 compat/corecrypto/ccsha2.c
create mode 100644 compat/corecrypto/ccsha2.h
diff --git a/compat/CommonCrypto/CommonDigest.h b/compat/CommonCrypto/CommonDigest.h
new file mode 100644
index 0000000..a60eba7
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigest.h
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
diff --git a/compat/CommonCrypto/CommonDigestSPI.c b/compat/CommonCrypto/CommonDigestSPI.c
new file mode 100644
index 0000000..41269fc
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigestSPI.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "CommonDigestSPI.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <corecrypto/ccsha2.h>
+
+void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest) {
+ if (type != kCCDigestSHA256) {
+ abort();
+ }
+ const struct ccdigest_info* di = ccsha256_di();
+
+ ccdigest_di_decl(_di, ctx);
+ ccdigest_init(di, ctx);
+ ccdigest_update(di, ctx, count, bytes);
+ ccdigest_final(di, ctx, digest);
+}
diff --git a/compat/CommonCrypto/CommonDigestSPI.h b/compat/CommonCrypto/CommonDigestSPI.h
new file mode 100644
index 0000000..172742a
--- /dev/null
+++ b/compat/CommonCrypto/CommonDigestSPI.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <stdint.h>
+
+#include <corecrypto/ccdigest.h>
+#include <CodeSigningTypes.h>
+
+
+#define kCCDigestNone 0
+#define kCCDigestSHA1 8
+#define kCCDigestSHA256 10
+
+EXTERN_C void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest);
diff --git a/compat/corecrypto/api_defines.h b/compat/corecrypto/api_defines.h
new file mode 100644
index 0000000..13d1e7a
--- /dev/null
+++ b/compat/corecrypto/api_defines.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#ifdef __cplusplus
+#define EXTERN_C extern "C"
+#else
+#define EXTERN_C
+#endif
diff --git a/compat/corecrypto/ccdigest.c b/compat/corecrypto/ccdigest.c
new file mode 100644
index 0000000..e29dcb8
--- /dev/null
+++ b/compat/corecrypto/ccdigest.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccdigest.h"
+#include "ccdigest_private.h"
+
+#include <stdlib.h>
+
+#include <openssl/err.h>
+
+
+struct ccdigest_context* _ccdigest_context_new(void)
+{
+ struct ccdigest_context* ctx = malloc(sizeof(struct ccdigest_context));
+ ctx->context = EVP_MD_CTX_new();
+ return ctx;
+}
+
+struct ccdigest_info* _ccdigest_newprovider(const char* name)
+{
+ struct ccdigest_info* di = malloc(sizeof(struct ccdigest_info));
+ di->provider = EVP_MD_fetch(NULL, name, NULL);
+ return di;
+}
+
+void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx)
+{
+ if (!EVP_DigestInit_ex2(ctx->context, di->provider, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
+
+void ccdigest_update(
+ const struct ccdigest_info* _di,
+ struct ccdigest_context* ctx,
+ size_t count,
+ const void* bytes
+)
+{
+ if (!EVP_DigestUpdate(ctx->context, bytes, count)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
+
+void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest)
+{
+ if (!EVP_DigestFinal_ex(ctx->context, digest, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+}
diff --git a/compat/corecrypto/ccdigest.h b/compat/corecrypto/ccdigest.h
new file mode 100644
index 0000000..9af2394
--- /dev/null
+++ b/compat/corecrypto/ccdigest.h
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "api_defines.h"
+
+
+struct ccdigest_info;
+struct ccdigest_context;
+
+EXTERN_C struct ccdigest_context* _ccdigest_context_new(void);
+
+#define ccdigest_di_decl(_di, ctxvar) \
+ struct ccdigest_context* (ctxvar) = _ccdigest_context_new()
+
+EXTERN_C void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx);
+EXTERN_C void ccdigest_update(
+ const struct ccdigest_info* _di,
+ struct ccdigest_context* ctx,
+ size_t count,
+ const void* bytes
+);
+EXTERN_C void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest);
diff --git a/compat/corecrypto/ccdigest_private.h b/compat/corecrypto/ccdigest_private.h
new file mode 100644
index 0000000..0ea9759
--- /dev/null
+++ b/compat/corecrypto/ccdigest_private.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include "api_defines.h"
+
+#include <openssl/evp.h>
+
+
+struct ccdigest_info {
+ EVP_MD* provider;
+};
+
+struct ccdigest_context {
+ EVP_MD_CTX* context;
+};
+
+EXTERN_C struct ccdigest_info* _ccdigest_newprovider(const char* name);
diff --git a/compat/corecrypto/ccsha1.c b/compat/corecrypto/ccsha1.c
new file mode 100644
index 0000000..e02b2b6
--- /dev/null
+++ b/compat/corecrypto/ccsha1.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccsha1.h"
+
+#include <assert.h>
+
+#include <cs_blobs.h>
+
+#include "ccdigest_private.h"
+
+
+static struct ccdigest_info* di = NULL;
+
+const struct ccdigest_info* ccsha1_di(void)
+{
+ if (!di) {
+ di = _ccdigest_newprovider("SHA-1");
+ assert(EVP_MD_get_size(di->provider) == CS_SHA1_LEN);
+ }
+ return di;
+}
diff --git a/compat/corecrypto/ccsha1.h b/compat/corecrypto/ccsha1.h
new file mode 100644
index 0000000..8e3f85f
--- /dev/null
+++ b/compat/corecrypto/ccsha1.h
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <corecrypto/ccdigest.h>
+
+
+EXTERN_C const struct ccdigest_info* ccsha1_di(void);
diff --git a/compat/corecrypto/ccsha2.c b/compat/corecrypto/ccsha2.c
new file mode 100644
index 0000000..6504503
--- /dev/null
+++ b/compat/corecrypto/ccsha2.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#include "ccsha2.h"
+
+#include <assert.h>
+
+#include <cs_blobs.h>
+
+#include "ccdigest_private.h"
+
+
+static struct ccdigest_info* di = NULL;
+
+const struct ccdigest_info* ccsha256_di(void)
+{
+ if (!di) {
+ di = _ccdigest_newprovider("SHA-256");
+ assert(EVP_MD_get_size(di->provider) == CS_SHA256_LEN);
+ }
+ return di;
+}
diff --git a/compat/corecrypto/ccsha2.h b/compat/corecrypto/ccsha2.h
new file mode 100644
index 0000000..9f30e03
--- /dev/null
+++ b/compat/corecrypto/ccsha2.h
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: APSL-2.0
+// CoreCrypto compatibility shims written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <corecrypto/ccdigest.h>
+
+#define CCSHA256_OUTPUT_SIZE 32
+
+EXTERN_C const struct ccdigest_info* ccsha256_di(void);
-diff --git a/compat/corecrypto/ccdigest.c b/compat/corecrypto/ccdigest.c
index e29dcb8..3949861 100644
--- a/compat/corecrypto/ccdigest.c
+++ b/compat/corecrypto/ccdigest.c
@@ -23,6 +23,12 @@ struct ccdigest_info* _ccdigest_newprovider(const char* name)
return di;
}
+void ccdigest_di_clear(const struct ccdigest_info* di, struct ccdigest_context* ctx)
+{
+ EVP_MD_CTX_free(ctx->context);
+ ctx->context = EVP_MD_CTX_new();
+}
+
void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx)
{
if (!EVP_DigestInit_ex2(ctx->context, di->provider, NULL)) {
diff --git a/compat/corecrypto/ccdigest.h b/compat/corecrypto/ccdigest.h
index 9af2394..d693fb7 100644
--- a/compat/corecrypto/ccdigest.h
+++ b/compat/corecrypto/ccdigest.h
@@ -17,6 +17,7 @@ EXTERN_C struct ccdigest_context* _ccdigest_context_new(void);
#define ccdigest_di_decl(_di, ctxvar) \
struct ccdigest_context* (ctxvar) = _ccdigest_context_new()
+EXTERN_C void ccdigest_di_clear(const struct ccdigest_info* _di, struct ccdigest_context* ctx);
EXTERN_C void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx);
EXTERN_C void ccdigest_update(
const struct ccdigest_info* _di,
diff --git a/compat/corecrypto/ccsha2.c b/compat/corecrypto/ccsha2.c
index 6504503..ed4de54 100644
--- a/compat/corecrypto/ccsha2.c
+++ b/compat/corecrypto/ccsha2.c
@@ -20,3 +20,12 @@ const struct ccdigest_info* ccsha256_di(void)
}
return di;
}
+
+const struct ccdigest_info* ccsha384_di(void)
+{
+ if (!di) {
+ di = _ccdigest_newprovider("SHA-384");
+ assert(EVP_MD_get_size(di->provider) == CS_SHA384_LEN);
+ }
+ return di;
+}
diff --git a/compat/corecrypto/ccsha2.h b/compat/corecrypto/ccsha2.h
index 9f30e03..bee18e8 100644
--- a/compat/corecrypto/ccsha2.h
+++ b/compat/corecrypto/ccsha2.h
@@ -5,6 +5,9 @@
#include <corecrypto/ccdigest.h>
#define CCSHA256_OUTPUT_SIZE 32
+#define CCSHA384_OUTPUT_SIZE 48
+#define CS_SHA384_LEN CCSHA384_OUTPUT_SIZE
EXTERN_C const struct ccdigest_info* ccsha256_di(void);
+EXTERN_C const struct ccdigest_info* ccsha384_di(void);

View File

@@ -0,0 +1,39 @@
diff --git a/other-tools/dsc_extractor_bin.cpp b/other-tools/dsc_extractor_bin.cpp
new file mode 100644
index 0000000000..2f26fbe4db
--- /dev/null
+++ b/other-tools/dsc_extractor_bin.cpp
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: APSL-2.0
+
+#include <stdio.h>
+#include <stddef.h>
+#include <dlfcn.h>
+
+
+typedef int (*extractor_proc)(const char* shared_cache_file_path, const char* extraction_root_path,
+ void (^progress)(unsigned current, unsigned total));
+
+int main(int argc, const char* argv[])
+{
+ if ( argc != 3 ) {
+ fprintf(stderr, "usage: dsc_extractor <path-to-cache-file> <path-to-device-dir>\n");
+ return 1;
+ }
+
+ void* handle = dlopen("@lib@/lib/dsc_extractor.bundle", RTLD_LAZY);
+ if ( handle == NULL ) {
+ fprintf(stderr, "dsc_extractor.bundle could not be loaded\n");
+ return 1;
+ }
+
+ extractor_proc proc = (extractor_proc)dlsym(handle, "dyld_shared_cache_extract_dylibs_progress");
+ if ( proc == NULL ) {
+ fprintf(stderr, "dsc_extractor.bundle did not have dyld_shared_cache_extract_dylibs_progress symbol\n");
+ return 1;
+ }
+
+ int result = (*proc)(argv[1], argv[2], ^(unsigned c, unsigned total) { printf("%d/%d\n", c, total); } );
+ fprintf(stderr, "dyld_shared_cache_extract_dylibs_progress() => %d\n", result);
+ return 0;
+}