Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Jan 27, 2024
1 parent 8ea00bd commit b5d6c3c
Show file tree
Hide file tree
Showing 6 changed files with 3,206 additions and 1,990 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ native/bncsutil/build/CMakeFiles
**/node_modules
**/.DS_Store
./.idea
.idea
48 changes: 20 additions & 28 deletions native/Cargo.lock

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

6 changes: 3 additions & 3 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ name = "bncsutil_node"
crate-type = ["cdylib"]

[build-dependencies]
neon-build = "0.4.0"
neon-build = "0.10.1"
cmake = "0.1"

[dependencies]
neon = "0.4.0"
neon = "0.10.1"
libc = "0.2"
gmp = "0.3.1"
# gmp-mpfr-sys = "1.6.2"
65 changes: 65 additions & 0 deletions native/src/bncs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ extern {
mpqNumber: ::std::os::raw::c_int,
checksum: *mut ::std::os::raw::c_ulong,
) -> ::std::os::raw::c_int;
pub fn kd_quick(
cd_key: *const ::std::os::raw::c_char,
client_token: u32,
server_token: u32,
public_value: *mut u32,
product: *mut u32,
hash_buffer: *mut ::std::os::raw::c_char,
buffer_len: usize,
) -> ::std::os::raw::c_int;
}

pub fn version() -> u64 {
Expand Down Expand Up @@ -127,6 +136,42 @@ pub fn check_revision_flat(value: String, file1: &Path, file2: &Path, file3: &Pa
}
}

// { CDKey: 'FFFFFFFFFFFFFFFFFFFFFFFFFF', clientToken: 130744796, serverToken: 1655005115 } { publicValue: 10992493, product: 5650, hash: '0 0 0 0 0 0 0 0' }
pub fn keydecode_quick(cd_key: String, client_token: u32, server_token: u32) -> (u32, u32, Vec<u8>) {
unsafe {
let cd_key_str = CString::new(cd_key).unwrap();
let mut public_value: u32 = 0;
let mut product: u32 = 0;
let mut hash_buffer_vec : Vec<i8> = vec![0i8; 20];
let hash_buffer_slice = hash_buffer_vec.as_mut_slice();
let hash_buffer_ptr = hash_buffer_slice.as_mut_ptr();

let status = kd_quick(
cd_key_str.as_ptr(),
client_token,
server_token,
&mut public_value,
&mut product,
hash_buffer_ptr,
20 as usize
);

if status == 0 {
panic!("Failed to kd_quick")
}

let hash_buffer_char_vec: Vec<u8> = hash_buffer_slice.iter().map(|&c| c as u8).collect();

// let hash_buffer_string = String::from_utf8(hash_buffer_char_vec).expect("Failed to convert hash to string");

(
public_value,
product,
hash_buffer_char_vec
)
}
}

#[cfg(test)]
mod bncs_tests {
use super::*;
Expand Down Expand Up @@ -167,4 +212,24 @@ mod bncs_tests {

assert_eq!(check_revision(value, files, 1), 3796461076 as u32)
}

// {
// CDKey: 'FFFFFFFFFFFFFFFFFFFFFFFFFF',
// clientToken: 130744796,
// serverToken: 2115470359 } {
// publicValue: 10992493,
// product: 5650, hash: '81 78 135 115 190 107 211 30 62 86 64 112 162 230 136 132 198 76 8 165
#[test]
fn test_keydecode_quick() {
let cd_key = String::from("FFFFFFFFFFFFFFFFFFFFFFFFFF");
let client_token: u32 = 130744796;
let server_token: u32 = 2115470359;
let result_vec: Vec<u8> = vec![81, 78, 135, 115, 190, 107, 211, 30, 62, 86, 64, 112, 162, 230, 136, 132, 198, 76, 8, 165];
// let result_hash = String::from("0 0 0 0 0 0 0 0");
let (public_value, product, hash) = keydecode_quick(cd_key, client_token, server_token);

println!("jkeycode qucik {:?} {:?} {:?}", public_value, product, hash);

assert_eq!((public_value, product, hash), (10992493 as u32, 5650 as u32, result_vec))
}
}
Loading

0 comments on commit b5d6c3c

Please sign in to comment.