Skip to content

Commit e19a72a

Browse files
committed
Fix statically linking PDB import plugin for demo builds
1 parent 26ed2cd commit e19a72a

File tree

7 files changed

+67
-21
lines changed

7 files changed

+67
-21
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ members = [
1616
"plugins/dwarf/shared",
1717
"plugins/idb_import",
1818
"plugins/pdb-ng",
19+
"plugins/pdb-ng/demo",
1920
"plugins/warp"
2021
]
2122

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

2627
[profile.release]
27-
lto = true
28+
lto = "thin"
2829
debug = "full"
30+
31+
# Disable LTO on demo builds, it will export `rust_eh_personality`
32+
[profile.release-demo]
33+
inherits = "release"
34+
lto = false
35+
36+
# Disable LTO on demo builds, it will export `rust_eh_personality`
37+
[profile.dev-demo]
38+
inherits = "dev"
39+
lto = false

plugins/pdb-ng/CMakeLists.txt

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ file(GLOB_RECURSE API_SOURCES CONFIGURE_DEPENDS
1515
${PROJECT_SOURCE_DIR}/../../rust/src/*.rs)
1616

1717
if(CMAKE_BUILD_TYPE MATCHES Debug)
18-
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug)
19-
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target)
18+
if(DEMO)
19+
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/dev-demo)
20+
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --profile=dev-demo)
21+
else()
22+
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug)
23+
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target)
24+
endif()
2025
else()
21-
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release)
22-
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release)
26+
if(DEMO)
27+
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release-demo)
28+
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --profile=release-demo)
29+
else()
30+
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release)
31+
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release)
32+
endif()
2333
endif()
2434

2535
if(FORCE_COLORED_OUTPUT)
@@ -60,11 +70,21 @@ set(RUSTUP_COMMAND ${RUSTUP_PATH} run ${CARGO_STABLE_VERSION} cargo)
6070
if(APPLE)
6171
if(UNIVERSAL)
6272
if(CMAKE_BUILD_TYPE MATCHES Debug)
63-
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE_NAME})
64-
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE_NAME})
73+
if(DEMO)
74+
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/dev-demo/${OUTPUT_FILE_NAME})
75+
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/dev-demo/${OUTPUT_FILE_NAME})
76+
else()
77+
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE_NAME})
78+
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE_NAME})
79+
endif()
6580
else()
66-
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE_NAME})
67-
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE_NAME})
81+
if(DEMO)
82+
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release-demo/${OUTPUT_FILE_NAME})
83+
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release-demo/${OUTPUT_FILE_NAME})
84+
else()
85+
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE_NAME})
86+
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE_NAME})
87+
endif()
6888
endif()
6989

7090
add_custom_command(
@@ -86,12 +106,6 @@ if(APPLE)
86106
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES}
87107
)
88108
else()
89-
if(CMAKE_BUILD_TYPE MATCHES Debug)
90-
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/debug/${OUTPUT_FILE_NAME})
91-
else()
92-
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/release/${OUTPUT_FILE_NAME})
93-
endif()
94-
95109
add_custom_command(
96110
OUTPUT ${OUTPUT_FILE_PATH}
97111
COMMAND ${CMAKE_COMMAND} -E env
@@ -100,7 +114,7 @@ if(APPLE)
100114
COMMAND ${CMAKE_COMMAND} -E env
101115
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR}
102116
${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES}
103-
COMMAND ${CMAKE_COMMAND} -E copy ${LIB_PATH} ${OUTPUT_FILE_PATH}
117+
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE_NAME} ${OUTPUT_FILE_PATH}
104118
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
105119
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES}
106120
)

plugins/pdb-ng/demo/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ path = "../src/lib.rs"
99

1010
[dependencies]
1111
anyhow = "^1.0"
12-
binaryninja = {path = "../../../"}
13-
home = "^0.5.5"
12+
binaryninja = { workspace = true, features = ["demo"]}
13+
binaryninjacore-sys.workspace = true
1414
itertools = "^0.11"
1515
log = "0.4"
16-
pdb = { git = "https://github.com/Vector35/pdb-rs", branch = "master" }
17-
cab = "^0.4"
16+
pdb = { git = "https://github.com/Vector35/pdb-rs", rev = "6016177" }
1817
regex = "1"
1918

2019
[features]

rust/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ rust-version = "1.83.0"
88
[features]
99
# This is used when statically linking to prevent exporting CorePluginABIVersion and UiPluginABIVersion.
1010
no_exports = []
11+
# Add this if you want to support the demo version of the product.
12+
# This will disable certain functions that do not exist in the demo build.
13+
demo = ["no_exports"]
1114

1215
[dependencies]
1316
log = { version = "0.4", features = ["std"] }

rust/src/collaboration/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ pub struct ConnectionOptions {
910910
pub password: Option<String>,
911911
/// Provide this if you want to authenticate with a token.
912912
///
913-
/// If you do not have a token you can use [ConnectionOptions::self].
913+
/// If you do not have a token you can use [ConnectionOptions::with_password].
914914
pub token: Option<String>,
915915
}
916916

rust/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,18 @@ pub fn license_count() -> i32 {
476476
/// If not set the normal license retrieval will occur:
477477
/// 1. Check the BN_LICENSE environment variable
478478
/// 2. Check the Binary Ninja user directory for license.dat
479+
#[cfg(not(feature = "demo"))]
479480
pub fn set_license<S: BnStrCompatible + Default>(license: Option<S>) {
480481
let license = license.unwrap_or_default().into_bytes_with_nul();
481482
let license_slice = license.as_ref();
482483
unsafe { BNSetLicense(license_slice.as_ptr() as *const c_char) }
483484
}
484485

486+
#[cfg(feature = "demo")]
487+
pub fn set_license<S: BnStrCompatible + Default>(_license: Option<S>) {
488+
panic!("Cannot set license in demo mode!");
489+
}
490+
485491
pub fn product() -> BnString {
486492
unsafe { BnString::from_raw(BNGetProduct()) }
487493
}

0 commit comments

Comments
 (0)