Skip to content

Commit

Permalink
Fix statically linking PDB import plugin for demo builds
Browse files Browse the repository at this point in the history
  • Loading branch information
emesare committed Jan 25, 2025
1 parent 26ed2cd commit e19a72a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 21 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"plugins/dwarf/shared",
"plugins/idb_import",
"plugins/pdb-ng",
"plugins/pdb-ng/demo",
"plugins/warp"
]

Expand All @@ -24,5 +25,15 @@ binaryninja = { path = "rust" }
binaryninjacore-sys = { path = "rust/binaryninjacore-sys" }

[profile.release]
lto = true
lto = "thin"
debug = "full"

# Disable LTO on demo builds, it will export `rust_eh_personality`
[profile.release-demo]
inherits = "release"
lto = false

# Disable LTO on demo builds, it will export `rust_eh_personality`
[profile.dev-demo]
inherits = "dev"
lto = false
44 changes: 29 additions & 15 deletions plugins/pdb-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ file(GLOB_RECURSE API_SOURCES CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/../../rust/src/*.rs)

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target)
if(DEMO)
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/dev-demo)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --profile=dev-demo)
else()
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target)
endif()
else()
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release)
if(DEMO)
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release-demo)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --profile=release-demo)
else()
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release)
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release)
endif()
endif()

if(FORCE_COLORED_OUTPUT)
Expand Down Expand Up @@ -60,11 +70,21 @@ set(RUSTUP_COMMAND ${RUSTUP_PATH} run ${CARGO_STABLE_VERSION} cargo)
if(APPLE)
if(UNIVERSAL)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE_NAME})
if(DEMO)
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/dev-demo/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/dev-demo/${OUTPUT_FILE_NAME})
else()
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE_NAME})
endif()
else()
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE_NAME})
if(DEMO)
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release-demo/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release-demo/${OUTPUT_FILE_NAME})
else()
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE_NAME})
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE_NAME})
endif()
endif()

add_custom_command(
Expand All @@ -86,12 +106,6 @@ if(APPLE)
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES}
)
else()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/debug/${OUTPUT_FILE_NAME})
else()
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/release/${OUTPUT_FILE_NAME})
endif()

add_custom_command(
OUTPUT ${OUTPUT_FILE_PATH}
COMMAND ${CMAKE_COMMAND} -E env
Expand All @@ -100,7 +114,7 @@ if(APPLE)
COMMAND ${CMAKE_COMMAND} -E env
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR}
${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES}
COMMAND ${CMAKE_COMMAND} -E copy ${LIB_PATH} ${OUTPUT_FILE_PATH}
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE_NAME} ${OUTPUT_FILE_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES}
)
Expand Down
7 changes: 3 additions & 4 deletions plugins/pdb-ng/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ path = "../src/lib.rs"

[dependencies]
anyhow = "^1.0"
binaryninja = {path = "../../../"}
home = "^0.5.5"
binaryninja = { workspace = true, features = ["demo"]}
binaryninjacore-sys.workspace = true
itertools = "^0.11"
log = "0.4"
pdb = { git = "https://github.com/Vector35/pdb-rs", branch = "master" }
cab = "^0.4"
pdb = { git = "https://github.com/Vector35/pdb-rs", rev = "6016177" }
regex = "1"

[features]
Expand Down
3 changes: 3 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ rust-version = "1.83.0"
[features]
# This is used when statically linking to prevent exporting CorePluginABIVersion and UiPluginABIVersion.
no_exports = []
# Add this if you want to support the demo version of the product.
# This will disable certain functions that do not exist in the demo build.
demo = ["no_exports"]

[dependencies]
log = { version = "0.4", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/src/collaboration/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ pub struct ConnectionOptions {
pub password: Option<String>,
/// Provide this if you want to authenticate with a token.
///
/// If you do not have a token you can use [ConnectionOptions::self].
/// If you do not have a token you can use [ConnectionOptions::with_password].
pub token: Option<String>,
}

Expand Down
6 changes: 6 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,18 @@ pub fn license_count() -> i32 {
/// If not set the normal license retrieval will occur:
/// 1. Check the BN_LICENSE environment variable
/// 2. Check the Binary Ninja user directory for license.dat
#[cfg(not(feature = "demo"))]
pub fn set_license<S: BnStrCompatible + Default>(license: Option<S>) {
let license = license.unwrap_or_default().into_bytes_with_nul();
let license_slice = license.as_ref();
unsafe { BNSetLicense(license_slice.as_ptr() as *const c_char) }
}

#[cfg(feature = "demo")]
pub fn set_license<S: BnStrCompatible + Default>(_license: Option<S>) {
panic!("Cannot set license in demo mode!");
}

pub fn product() -> BnString {
unsafe { BnString::from_raw(BNGetProduct()) }
}
Expand Down

0 comments on commit e19a72a

Please sign in to comment.