Skip to content

Commit

Permalink
Auto-install Frida devkits (#5)
Browse files Browse the repository at this point in the history
* bump bindgen to 0.57

* automatically download and use the frida devkit

This makes the library really usable in other packages

* remove the devkit download from the github workflow

make sure cd .. happens irrespective of if the download and build line
fails

* remove static requirement for libfrida-XXX

* formatting

* Deduplicate build.rs code by creating frida-build; Introduce feature flag 'autodownload'

* Add FRIDA_VERSION file

* formatting

* changed autodownload to auto-download; removed frida-core.h

* update FRIDA_VERSION to 14.2.13
  • Loading branch information
s1341 committed Mar 7, 2021
1 parent 36834a4 commit 4e96b4f
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 58,609 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -14,7 +14,8 @@ jobs:
toolchain: stable
override: true
- run: |
cd frida-gum-sys && wget https://github.com/frida/frida/releases/download/14.2.13/frida-gum-devkit-14.2.13-linux-x86_64.tar.xz -O frida-gum.tar.xz && tar xJvf frida-gum.tar.xz && cd ..
cd frida-gum-sys && wget https://github.com/frida/frida/releases/download/14.2.13/frida-gum-devkit-14.2.13-linux-x86_64.tar.xz -O frida-gum.tar.xz && tar xJvf frida-gum.tar.xz
cd ..
cd frida-sys && wget https://github.com/frida/frida/releases/download/14.2.13/frida-core-devkit-14.2.13-linux-x86_64.tar.xz -O frida-core.tar.xz && tar xJvf frida-core.tar.xz
- run: rustup component add rustfmt clippy
- uses: actions-rs/cargo@v1
Expand Down
1 change: 1 addition & 0 deletions FRIDA_VERSION
@@ -0,0 +1 @@
14.2.13
8 changes: 8 additions & 0 deletions frida-build/Cargo.toml
@@ -0,0 +1,8 @@
[package]
name = "frida-build"
version = "0.1.1"
authors = ["meme <keegan@sdf.org>"]
edition = "2018"
license = "wxWindows"
repository = "https://github.com/meme/frida-rust"
description = "Build scripts for Frida rust bindings"
73 changes: 73 additions & 0 deletions frida-build/src/lib.rs
@@ -0,0 +1,73 @@
use std::env;
use std::path::Path;
use std::process::Command;

pub fn download_and_use_devkit(kind: &str, version: &str) {
let mut target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

if target_arch == "aarch64" {
target_arch = "arm64".to_string();
}

let cwd = env::current_dir().unwrap().to_string_lossy().to_string();

let devkit = format!(
"{}/frida-{}-devkit-{}-{}-{}",
env::var("CARGO_MANIFEST_DIR").unwrap(),
kind,
version,
env::var("CARGO_CFG_TARGET_OS").unwrap(),
target_arch
);
let devkit_path = Path::new(&devkit);
let devkit_tar = format!("{}.tar.xz", devkit);

let out_dir_path = Path::new(&cwd);

if !devkit_path.is_dir() {
if !Path::new(&devkit_tar).is_file() {
println!(
"cargo:warning=Frida {} devkit not found, downloading...",
kind
);
// Download devkit
Command::new("wget")
.arg("-c")
.arg(format!(
"https://github.com/frida/frida/releases/download/{}/frida-{}-devkit-{}-{}-{}.tar.xz",
version,
kind,
version,
env::var("CARGO_CFG_TARGET_OS").unwrap(),
target_arch))
.arg("-O")
.arg(&devkit_tar)
.status()
.unwrap();
}
Command::new("tar")
.current_dir(&out_dir_path)
.arg("-xvf")
.arg(&devkit_tar)
.status()
.unwrap();
Command::new("mv")
.current_dir(&out_dir_path)
.arg(format!("libfrida-{}.a", kind))
.arg(format!(
"libfrida-{}-{}-{}.a",
kind,
env::var("CARGO_CFG_TARGET_OS").unwrap(),
target_arch
))
.status()
.unwrap();
}

println!(
"cargo:rustc-link-lib=frida-{}-{}-{}",
kind,
env::var("CARGO_CFG_TARGET_OS").unwrap(),
target_arch
);
}
4 changes: 3 additions & 1 deletion frida-gum-sys/Cargo.toml
Expand Up @@ -8,12 +8,14 @@ repository = "https://github.com/meme/frida-rust"
description = "Rust generated bindings for Frida Gum"

[features]
auto-download = ["frida-build"]
event-sink = ["cc"]
invocation-listener = ["cc"]

[build-dependencies]
bindgen = "0.53.1"
bindgen = "0.57.0"
cc = { version = "1.0", optional = true }
frida-build = { path = "../frida-build", version = "0.1.1", optional = true }

[badges]
maintenance = { status = "experimental" }
9 changes: 9 additions & 0 deletions frida-gum-sys/build.rs
Expand Up @@ -3,6 +3,9 @@ extern crate bindgen;
use std::env;
use std::path::PathBuf;

#[cfg(feature = "auto-download")]
use frida_build::download_and_use_devkit;

fn main() {
#[cfg(feature = "event-sink")]
{
Expand All @@ -21,7 +24,12 @@ fn main() {
env::var("CARGO_MANIFEST_DIR").unwrap()
);

#[cfg(feature = "auto-download")]
download_and_use_devkit("gum", include_str!("../FRIDA_VERSION").trim());
#[cfg(not(feature = "auto-download"))]
println!("cargo:rustc-link-lib=frida-gum");

#[cfg(not(target = "android"))]
println!("cargo:rustc-link-lib=pthread");

let bindings = bindgen::Builder::default()
Expand All @@ -41,6 +49,7 @@ fn main() {
#[cfg(feature = "event-sink")]
cc::Build::new()
.file("event_sink.c")
.opt_level(3)
.warnings_into_errors(true)
.compile("event_sink");

Expand Down
2 changes: 2 additions & 0 deletions frida-gum/Cargo.toml
Expand Up @@ -8,9 +8,11 @@ repository = "https://github.com/meme/frida-rust"
description = "Rust bindings for Frida Gum"

[features]
auto-download = ["frida-gum-sys/auto-download"]
event-sink = ["frida-gum-sys/event-sink"]
invocation-listener = ["frida-gum-sys/invocation-listener"]


[dependencies]
frida-gum-sys = { path = "../frida-gum-sys", version = "0.2.0" }
num = "0.3.1"
Expand Down
6 changes: 5 additions & 1 deletion frida-sys/Cargo.toml
Expand Up @@ -7,8 +7,12 @@ license = "wxWindows"
repository = "https://github.com/meme/frida-rust"
description = "Rust generated bindings for Frida"

[features]
auto-download = ["frida-build"]

[build-dependencies]
bindgen = "0.53.1"
bindgen = "0.57.0"
frida-build = { path = "../frida-build", version = "0.1.1", optional = true }

[badges]
maintenance = { status = "experimental" }
10 changes: 10 additions & 0 deletions frida-sys/build.rs
Expand Up @@ -3,14 +3,24 @@ extern crate bindgen;
use std::env;
use std::path::PathBuf;

#[cfg(feature = "auto-download")]
use frida_build::download_and_use_devkit;

fn main() {
println!(
"cargo:rustc-link-search={}",
env::var("CARGO_MANIFEST_DIR").unwrap()
);

#[cfg(feature = "auto-download")]
download_and_use_devkit("core", include_str!("../FRIDA_VERSION").trim());

#[cfg(not(feature = "auto-download"))]
println!("cargo:rustc-link-lib=frida-core");

#[cfg(not(target = "android"))]
println!("cargo:rustc-link-lib=pthread");
#[cfg(not(target = "android"))]
println!("cargo:rustc-link-lib=resolv");

let bindings = bindgen::Builder::default()
Expand Down

0 comments on commit 4e96b4f

Please sign in to comment.