Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions .github/workflows/build_native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data/

# Files
extendify.log
.DS_Store

# Nix
result
Expand Down
25 changes: 25 additions & 0 deletions LICENSE-redhook
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2015, Geoffrey Thomas <geofft@ldpreload.com>.
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.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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).
9 changes: 9 additions & 0 deletions crates/extendify-native/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
37 changes: 37 additions & 0 deletions crates/extendify-native/src/unix/dyld.rs
Original file line number Diff line number Diff line change
@@ -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 }
};
}
5 changes: 5 additions & 0 deletions crates/extendify-native/src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 25 additions & 0 deletions docs/install/macos.md
Original file line number Diff line number Diff line change
@@ -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_<arch>.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_<arch>.dylib /Applications/Spotify.app
```
63 changes: 37 additions & 26 deletions nix/cef.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}"
63 changes: 29 additions & 34 deletions nix/spotify-extendify.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
};
}
Loading