diff --git a/.github/workflows/build_native.yml b/.github/workflows/build_native.yml index a436be1..d6ebcff 100644 --- a/.github/workflows/build_native.yml +++ b/.github/workflows/build_native.yml @@ -24,14 +24,14 @@ jobs: output: extendify_native target: windows_aarch64 extension: .dll - # - os: macos-latest - # output: libextendify_native - # target: macos_arm64 - # extension: .dylib - # - os: macos-26-intel - # output: libextendify_native - # target: macos_intel - # extension: .dylib + - os: macos-latest + output: libextendify_native + target: macos_arm64 + extension: .dylib + - os: macos-26-intel + output: libextendify_native + target: macos_intel + extension: .dylib runs-on: ${{ matrix.os }} permissions: diff --git a/.gitignore b/.gitignore index 8f03a8b..b04450d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ data/ # Files extendify.log +.DS_Store # Nix result diff --git a/LICENSE-redhook b/LICENSE-redhook new file mode 100644 index 0000000..69c60d6 --- /dev/null +++ b/LICENSE-redhook @@ -0,0 +1,25 @@ +Copyright (c) 2015, Geoffrey Thomas . +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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT +HOLDER OR 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. \ No newline at end of file diff --git a/README.md b/README.md index 9b07b07..10a2b48 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ An easy to install and use mod for the desktop and browser versions of Spotify! - [Windows (x64, arm64)](/docs/install/windows.md) - [Linux (x64)](/docs/install/linux.md) -- ~~MacOS (Intel, ARM)~~ Coming soon! +- [MacOS (ARM, Intel)](/docs/install/macos.md) - [Chrome](/docs/install/chrome.md) ### Installation Guide: @@ -25,3 +25,7 @@ You can find our guide on how to install Extendify [here](/docs/install)! ### Developing: A guide on how to contribute and develop for Extendify is located [here](/docs/develop)! + +### Licenses: + +- `crates/extendify-native/src/unix/preload.rs` is licensed under the [BSD 2-Clause "Simplified" License](/LICENSE-redhook). diff --git a/crates/extendify-native/build.rs b/crates/extendify-native/build.rs index 76de1ae..ce852bb 100644 --- a/crates/extendify-native/build.rs +++ b/crates/extendify-native/build.rs @@ -7,12 +7,21 @@ fn main() { format!("{}/cef", manifest_dir) }); + #[cfg(not(target_os = "macos"))] println!("cargo:rustc-link-search=native={}/Release", cef_path); + #[cfg(target_os = "windows")] println!("cargo:rustc-link-lib=libcef"); #[cfg(target_os = "linux")] println!("cargo:rustc-link-lib=dylib=cef"); + #[cfg(target_os = "macos")] + { + println!("cargo:rustc-link-search=framework={}/Release", cef_path); + println!("cargo:rustc-link-lib=framework=Chromium Embedded Framework"); + println!("cargo:rustc-link-arg=-Wl,-rpath,{}/Release", cef_path); + } + let builder = bindgen::Builder::default() .header("wrapper.h") .clang_arg(format!("-I{}", cef_path)) diff --git a/crates/extendify-native/src/unix/dyld.rs b/crates/extendify-native/src/unix/dyld.rs new file mode 100644 index 0000000..f593d29 --- /dev/null +++ b/crates/extendify-native/src/unix/dyld.rs @@ -0,0 +1,37 @@ +// https://github.com/geofft/redhook/blob/master/src/dyld_insert_libraries.rs + +#[macro_export] +macro_rules! extern_c_overrides { + (unsafe fn $c_api:ident/$real_api:ident ($($param_name:ident : $param_type:ty),* ) -> $return_type:ty $override_body:block) => { + pub mod $c_api { + #[allow(non_camel_case_types)] + pub struct $c_api { + _new: *const (), + _old: *const (), + } + + #[used] + #[allow(non_upper_case_globals)] + #[unsafe(link_section="__DATA,__interpose")] + pub static mut $c_api: $c_api = $c_api { + _new: super::$real_api as *const (), + _old: super::$c_api as *const (), + }; + } + + unsafe extern "C" { + pub fn $c_api ( $($param_name : $param_type),* ) -> $return_type; + } + + pub unsafe extern "C" fn $real_api ( $($param_name : $param_type),* ) -> $return_type { + ::std::panic::catch_unwind(|| unsafe { + let $real_api = $c_api; + $override_body + }).unwrap_or_else(|_| unsafe { $real_api ( $($param_name),* ) }) + } + }; + + (unsafe fn $c_api:ident/$real_api:ident ( $($param_name:ident : $param_type:ty),* ) $override_body:block) => { + extern_c_overrides! { unsafe fn $c_api/$real_api ( $($param_name : $param_type),* ) -> () $override_body } + }; +} diff --git a/crates/extendify-native/src/unix/mod.rs b/crates/extendify-native/src/unix/mod.rs index b92e310..8b61b13 100644 --- a/crates/extendify-native/src/unix/mod.rs +++ b/crates/extendify-native/src/unix/mod.rs @@ -7,9 +7,14 @@ use crate::cef::{ use crate::vtable_hooks::GET_REQ_HANDLER_OG; use crate::{log, vtable_hooks}; +#[cfg(target_os = "linux")] #[macro_use] mod preload; +#[cfg(target_os = "macos")] +#[macro_use] +mod dyld; + extern_c_overrides! { unsafe fn cef_browser_view_create/real_cef_browser_view_create( client: *mut _cef_client_t, diff --git a/docs/install/README.md b/docs/install/README.md index e564e61..108ee1c 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -4,4 +4,5 @@ There are separate installation guides for each platform we ship Extendify on: - [Windows](./windows.md) - [Linux](./linux.md) +- [MacOS](./macos.md) - [Chrome](./chrome.md) diff --git a/docs/install/macos.md b/docs/install/macos.md new file mode 100644 index 0000000..fb086b4 --- /dev/null +++ b/docs/install/macos.md @@ -0,0 +1,25 @@ +## Install: MacOS + +MacOS injection works through the `DYLD_INSERT_LIBRARIES` environment variable. +This variable loads specified `.dylib` (dynamic library) files into the process, +which Extendify uses to inject into the web contents. + +You can download our `.dylib` file depending on your architecture: +- [ARM](https://github.com/extendify-mod/extendify/releases/download/native/macos_arm64.dylib) +- [Intel](https://github.com/extendify-mod/extendify/releases/download/native/macos_intel.dylib) + +In order to relax constraints on `.dylib` loading to allow `DYLD_INSERT_LIBRARIES` to function, +the Spotify binary has to be modified to disable the [Hardened Runtime](https://developer.apple.com/documentation/security/hardened-runtime). +The following command ad-hoc signs and removes the runtime restriction flag on the Spotify binary. + +```bash +codesign --force --sign - --preserve-metadata=identifier,entitlements,requirements,launch-constraints,library-constraints /Applications/Spotify.app/Contents/MacOS/Spotify +``` + +Whenever you run the Spotify app (specifically, the binary at `Spotify.app/Contents/MacOS/Spotify`), +prefix your command with `DYLD_INSERT_LIBRARIES=path/to/macos_.dylib`, +or provide it in some other way. For example, it can be used with the `open` command: + +```bash +open --env DYLD_INSERT_LIBRARIES=path/to/macos_.dylib /Applications/Spotify.app +``` diff --git a/nix/cef.nix b/nix/cef.nix index 0f8f0e8..fb41854 100644 --- a/nix/cef.nix +++ b/nix/cef.nix @@ -3,8 +3,10 @@ fetchurl, stdenv, stdenvNoCC, -}: let - selectSystem = attrs: +}: +let + selectSystem = + attrs: attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system ${stdenv.hostPlatform.system}"); platformString = selectSystem { @@ -20,31 +22,40 @@ aarch64-darwin = "sha256-Q94fht0yAkwAIqv29I1ZkpaS7WiYvJIcHWFcmBSvqHw="; }; in - if stdenv.hostPlatform.isLinux - then - cef-binary.override { - inherit version gitRevision chromiumVersion srcHashes; - } - else if stdenv.hostPlatform.system == "aarch64-darwin" - then - stdenvNoCC.mkDerivation { - name = "darwin-cef"; +if stdenv.hostPlatform.isLinux then + cef-binary.override { + inherit + version + gitRevision + chromiumVersion + srcHashes + ; + } +else if stdenv.hostPlatform.system == "aarch64-darwin" then + stdenvNoCC.mkDerivation { + nativeBuildInputs = [ stdenv.cc ]; + name = "darwin-cef"; - src = fetchurl { - url = "https://cef-builds.spotifycdn.com/cef_binary_${version}+g${gitRevision}+chromium-${chromiumVersion}_${platformString}_minimal.tar.bz2"; - hash = srcHashes.${stdenv.hostPlatform.system}; - }; + src = fetchurl { + url = "https://cef-builds.spotifycdn.com/cef_binary_${version}+g${gitRevision}+chromium-${chromiumVersion}_${platformString}_minimal.tar.bz2"; + hash = srcHashes.${stdenv.hostPlatform.system}; + }; - dontBuild = true; - dontConfigure = true; + dontBuild = true; + dontConfigure = true; - unpackPhase = '' - tar --strip-components=1 -xjf $src - ''; + unpackPhase = '' + tar --strip-components=1 -xjf $src + ''; - installPhase = '' - mkdir -p $out - cp -r ./* $out/ - ''; - } - else throw "Unsupported system: ${stdenv.hostPlatform.system}" + installPhase = '' + mkdir -p $out + cp -r ./* $out/ + + ${stdenv.cc.targetPrefix}install_name_tool \ + -id '@rpath/Chromium Embedded Framework.framework/Chromium Embedded Framework' \ + "$out/Release/Chromium Embedded Framework.framework/Chromium Embedded Framework" + ''; + } +else + throw "Unsupported system: ${stdenv.hostPlatform.system}" diff --git a/nix/spotify-extendify.nix b/nix/spotify-extendify.nix index fbeee5a..7c5586e 100644 --- a/nix/spotify-extendify.nix +++ b/nix/spotify-extendify.nix @@ -5,42 +5,37 @@ makeWrapper, self, lib, -}: let - exe = - if stdenv.isDarwin - then "Applications/Spotify.app/MacOS/Spotify" - else "bin/spotify"; - preloadVar = - if stdenv.isDarwin - then "DYLD_INSERT_LIBRARIES" - else "LD_PRELOAD"; +}: +let + exe = if stdenv.isDarwin then "Applications/Spotify.app/Contents/MacOS/Spotify" else "bin/spotify"; + preloadVar = if stdenv.isDarwin then "DYLD_INSERT_LIBRARIES" else "LD_PRELOAD"; in - symlinkJoin { - name = "spotify-extendify"; - inherit (spotify) version; +symlinkJoin { + name = "spotify-extendify"; + inherit (spotify) version; - paths = [ - spotify - self.packages.${stdenv.hostPlatform.system}.extendify-native - ]; + paths = [ + spotify + self.packages.${stdenv.hostPlatform.system}.extendify-native + ]; - buildInputs = [makeWrapper]; + buildInputs = [ makeWrapper ]; - postBuild = '' - wrapProgram $out/${exe} \ - --set ${preloadVar} $out/lib/libextendify_native.so - ''; + postBuild = '' + wrapProgram $out/${exe} \ + --set ${preloadVar} $out/lib/libextendify_native.so + ''; - meta = { - mainProgram = "spotify"; - description = spotify.meta.description + "(patched with Extendify)"; - homepage = "https://github.com/extendify-mod/extendify"; - # wtf is the license - # license = lib.licenses.gpl3; - maintainers = [lib.maintainers.fazzi]; - platforms = [ - "x86_64-linux" - "aarch64-darwin" - ]; - }; - } + meta = { + mainProgram = "spotify"; + description = spotify.meta.description + "(patched with Extendify)"; + homepage = "https://github.com/extendify-mod/extendify"; + # wtf is the license + # license = lib.licenses.gpl3; + maintainers = [ lib.maintainers.fazzi ]; + platforms = [ + "x86_64-linux" + "aarch64-darwin" + ]; + }; +}