From 7694f5f10218d76626dd0e83e34c6efc5425910d Mon Sep 17 00:00:00 2001 From: lienjukaisim <154924955+lienjukaisim@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:15:10 +0200 Subject: [PATCH 1/4] SSV_INITLIB2 SSV_LireCartePS --- Cargo.lock | 32 +++++++++++++++++++++ Cargo.toml | 4 +-- clego/Cargo.toml | 1 + clego/src/SV_DLL_Win.rs | 63 +++++++++++++++++++++++++++++++++++++++++ clego/src/main.rs | 2 ++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 Cargo.lock create mode 100644 clego/src/SV_DLL_Win.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..905172f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,32 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "clego" +version = "0.1.0" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 761d36a..c25708d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] members = [ - "webapp", - "clego", - "tauri", + "clego" ] resolver = "2" diff --git a/clego/Cargo.toml b/clego/Cargo.toml index 495a5a2..a4fc835 100644 --- a/clego/Cargo.toml +++ b/clego/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +winapi = { version = "0.3.8", features = ["winuser","libloaderapi"] } diff --git a/clego/src/SV_DLL_Win.rs b/clego/src/SV_DLL_Win.rs new file mode 100644 index 0000000..ab96560 --- /dev/null +++ b/clego/src/SV_DLL_Win.rs @@ -0,0 +1,63 @@ +extern crate winapi; + +use winapi::um::libloaderapi::{ LoadLibraryA, GetProcAddress}; + +use std::ffi::{CString , c_void}; + +// Définissez une énumération pour les deux types possibles + + +//récupérer le handle sur la library +fn load_library(dll_path: &str)->*mut winapi::shared::minwindef::HINSTANCE__ { + let dll_path_c = CString::new(dll_path).expect("Chemin de DLL invalide"); + unsafe { + let h_module = LoadLibraryA(dll_path_c.as_ptr()); + h_module + } +} + +//SSV_INITLIB2 +fn ssv_initlib2(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , sesamini_path :String)->i32{ + // Résolution d'une fonction exportée ("SSV_InitLIB2") + let symbol_name = CString::new("SSV_InitLIB2").expect("Nom de symbole invalide"); + unsafe { + let function_ptr = GetProcAddress(dll_handle, symbol_name.as_ptr()); + + if function_ptr.is_null() { panic!("Échec de la résolution du symbole");} + + // Convertir le pointeur en une fonction Rust + type MyFunctionType = unsafe extern "C" fn(*const i8) -> i32; + let my_function: MyFunctionType = std::mem::transmute(function_ptr); + + let result = my_function( + CString::new(sesamini_path).unwrap().as_ptr() + ); +result +}} + +//SSV_LireCartePS +fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :String , NomRessourceLecteur :String , CodePorteurPS :String, + mut ZDonneesSortie: *mut c_void , mut TTailleDonneesSortie: usize)->i32{ + // Résolution d'une fonction exportée ("SSV_LireCartePS") + let symbol_name = CString::new("SSV_LireCartePS").expect("Nom de symbole invalide"); + unsafe { + let function_ptr = GetProcAddress(dll_handle, symbol_name.as_ptr()); + if function_ptr.is_null() { + panic!("Échec de la résolution du symbole"); + } + + // Convertir le pointeur en une fonction Rust + type MyFunctionType = unsafe extern "C" fn(*const i8, *const i8, *const i8, *mut *mut c_void, *mut usize) -> i32; + let my_function: MyFunctionType = std::mem::transmute(function_ptr); + + // appel de la fonction +ZDonneesSortie= std::ptr::null_mut(); +TTailleDonneesSortie=0; + let result = my_function(CString::new(NomRessourcePS).unwrap().as_ptr(), + CString::new(NomRessourceLecteur).unwrap().as_ptr(), + CString::new(CodePorteurPS).unwrap().as_ptr(), + &mut ZDonneesSortie, + &mut TTailleDonneesSortie); +result +} +} \ No newline at end of file diff --git a/clego/src/main.rs b/clego/src/main.rs index e7a11a9..1224355 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,3 +1,5 @@ +mod SV_DLL_Win; + fn main() { println!("Hello, world!"); } -- 2.45.2 From 16341eca8c09553b0ac0da8c99c06bdac4eeca66 Mon Sep 17 00:00:00 2001 From: lienjukaisim <154924955+lienjukaisim@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:30:48 +0200 Subject: [PATCH 2/4] test appel --- clego/src/SV_DLL_Win.rs | 6 +++--- clego/src/main.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/clego/src/SV_DLL_Win.rs b/clego/src/SV_DLL_Win.rs index ab96560..f0e0d33 100644 --- a/clego/src/SV_DLL_Win.rs +++ b/clego/src/SV_DLL_Win.rs @@ -8,7 +8,7 @@ use std::ffi::{CString , c_void}; //récupérer le handle sur la library -fn load_library(dll_path: &str)->*mut winapi::shared::minwindef::HINSTANCE__ { +pub fn load_library(dll_path: &str)->*mut winapi::shared::minwindef::HINSTANCE__ { let dll_path_c = CString::new(dll_path).expect("Chemin de DLL invalide"); unsafe { let h_module = LoadLibraryA(dll_path_c.as_ptr()); @@ -17,7 +17,7 @@ fn load_library(dll_path: &str)->*mut winapi::shared::minwindef::HINSTANCE__ { } //SSV_INITLIB2 -fn ssv_initlib2(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , sesamini_path :String)->i32{ +pub fn ssv_initlib2(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , sesamini_path :&str)->i32{ // Résolution d'une fonction exportée ("SSV_InitLIB2") let symbol_name = CString::new("SSV_InitLIB2").expect("Nom de symbole invalide"); unsafe { @@ -36,7 +36,7 @@ result }} //SSV_LireCartePS -fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :String , NomRessourceLecteur :String , CodePorteurPS :String, +pub fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :String , NomRessourceLecteur :String , CodePorteurPS :String, mut ZDonneesSortie: *mut c_void , mut TTailleDonneesSortie: usize)->i32{ // Résolution d'une fonction exportée ("SSV_LireCartePS") let symbol_name = CString::new("SSV_LireCartePS").expect("Nom de symbole invalide"); diff --git a/clego/src/main.rs b/clego/src/main.rs index 1224355..c6814b2 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,5 +1,13 @@ mod SV_DLL_Win; fn main() { - println!("Hello, world!"); -} + let my_handle:*mut winapi::shared::minwindef::HINSTANCE__ ; + my_handle = SV_DLL_Win::load_library("C:/Program Files/santesocial/fsv/1.40.14/lib/ssvw64.dll"); + + if my_handle.is_null() { + panic!("Échec du chargement de la DLL"); + } + +let result_ssv_initlib2=SV_DLL_Win::ssv_initlib2(my_handle,"C:/CLEGO_Files/SanteSociale/sesam.ini"); +println!("Résultat SSV_InitLIB2 : {}", result_ssv_initlib2); +} \ No newline at end of file -- 2.45.2 From 38da1e763c5bdaf5f747e729a21914344397a4ad Mon Sep 17 00:00:00 2001 From: lienjukaisim <154924955+lienjukaisim@users.noreply.github.com> Date: Tue, 16 Jul 2024 07:38:53 +0200 Subject: [PATCH 3/4] decode cps --- clego/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clego/src/main.rs b/clego/src/main.rs index c6814b2..7c7176e 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,8 +1,8 @@ mod SV_DLL_Win; fn main() { - let my_handle:*mut winapi::shared::minwindef::HINSTANCE__ ; - my_handle = SV_DLL_Win::load_library("C:/Program Files/santesocial/fsv/1.40.14/lib/ssvw64.dll"); + // let my_handle:*mut winapi::shared::minwindef::HINSTANCE__ ; + let my_handle = SV_DLL_Win::load_library("C:/Program Files/santesocial/fsv/1.40.14/lib/ssvw64.dll"); if my_handle.is_null() { panic!("Échec du chargement de la DLL"); -- 2.45.2 From a15bc646e8506f629da028508a61738a39d5c7fa Mon Sep 17 00:00:00 2001 From: lienjukaisim <154924955+lienjukaisim@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:02:22 +0200 Subject: [PATCH 4/4] decode CPS --- clego/src/CPS.rs | 94 +++++++++++++++++++++++++++++++++++++++++ clego/src/INSi.rs | 35 +++++++++++++++ clego/src/SV_DLL_Win.rs | 17 +++++--- clego/src/main.rs | 18 +++++++- 4 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 clego/src/CPS.rs create mode 100644 clego/src/INSi.rs diff --git a/clego/src/CPS.rs b/clego/src/CPS.rs new file mode 100644 index 0000000..499afa1 --- /dev/null +++ b/clego/src/CPS.rs @@ -0,0 +1,94 @@ +pub fn decode_zone_memoire( ZDonneesSortie: *mut std::ffi::c_void,TTailleDonneesSortie: usize){ + + println!("Taille sortie SSV_LireCartePS : {}", TTailleDonneesSortie); + println!("ZDonneesSortie: {:?}", ZDonneesSortie); + + // Convertir le pointeur en tranche de bytes + let bytes: &[u8] = unsafe { + std::slice::from_raw_parts(ZDonneesSortie as *const u8, TTailleDonneesSortie) + }; + + // Maintenant, vous pouvez accéder aux octets individuels dans `donnees` + for &octet in bytes { + println!("Octet: {}", octet); + } + + let mut current_pos_general = 0; + let mut current_groupe = 0; + let mut num_champ = 0; + + while current_pos_general < bytes.len() - 1 { + num_champ = 0; + current_groupe = 256 * bytes[current_pos_general] as i32 + bytes[current_pos_general + 1] as i32; + current_pos_general += 2; + + let longueur_groupe: usize; + if bytes[current_pos_general] < 128 { + longueur_groupe = bytes[current_pos_general] as usize; + } else { + let nbre_octets_longueur = bytes[current_pos_general] - 128; + longueur_groupe = (0..nbre_octets_longueur) + .fold(0, |acc, i| { + current_pos_general += 1; + acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize + }); + } + current_pos_general += 1; + + let mut current_pos_groupe = 0; + while current_pos_groupe < longueur_groupe { + num_champ += 1; + let longueur_champs: usize; + let nbre_octets_longueur: usize; + if bytes[current_pos_general] < 128 { + longueur_champs = bytes[current_pos_general] as usize; + nbre_octets_longueur = 1; + } else { + nbre_octets_longueur = bytes[current_pos_general] as usize - 128; + longueur_champs = (0..nbre_octets_longueur) + .fold(0, |acc, i| { + current_pos_general += 1; + current_pos_groupe += 1; + acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize + }); + } + + let mut bytes_champ = vec![0; longueur_champs]; + if longueur_champs > 0 { + bytes_champ.copy_from_slice(&bytes[current_pos_general + nbre_octets_longueur..current_pos_general + nbre_octets_longueur + longueur_champs]); + + match current_groupe { + 1 => match num_champ { + 1 => println!("Groupe1.Champ1: {}", String::from_utf8_lossy(&bytes_champ)), + 2 => println!("Groupe1.Champ2: {}", String::from_utf8_lossy(&bytes_champ)), + 3 => println!("Groupe1.Champ3: {}", String::from_utf8_lossy(&bytes_champ)), + 4 => println!("Groupe1.Champ4: {}", String::from_utf8_lossy(&bytes_champ)), + 5 => println!("Groupe1.Champ5: {}", String::from_utf8_lossy(&bytes_champ)), + 6 => println!("Groupe1.Champ6: {}", String::from_utf8_lossy(&bytes_champ)), + 7 => println!("Groupe1.Champ7: {}", String::from_utf8_lossy(&bytes_champ)), + 8 => println!("Groupe1.Champ8: {}", String::from_utf8_lossy(&bytes_champ)), + _ => (), + }, + 2 => match num_champ { + 1 => { + // Ajoutez votre logique pour Groupe2 ici + } + 2 => { + // Ajoutez votre logique pour Groupe2 ici + } + 3 => { + // Ajoutez votre logique pour Groupe2 ici + } + _ => (), + }, + _ => (), + } + } + + current_pos_general += longueur_champs + nbre_octets_longueur; + current_pos_groupe += longueur_champs + nbre_octets_longueur; + } + } +} + + diff --git a/clego/src/INSi.rs b/clego/src/INSi.rs new file mode 100644 index 0000000..6a8a960 --- /dev/null +++ b/clego/src/INSi.rs @@ -0,0 +1,35 @@ +// use std::ffi::CString; +// use std::ptr::null_mut; +// use winapi::um::libloaderapi::{LoadLibraryA, GetProcAddress, FreeLibrary}; +// use winapi::shared::minwindef::HMODULE; +// // use winapi::shared::winerror::ERROR_SUCCESS; +// // use winapi::um::errhandlingapi::GetLastError; +// use winapi::um::winnt::LPCSTR; +// use std::os::raw::c_void; + +// pub fn test() { +// unsafe { +// let dll_path = CString::new("F:/PAPILLON/Sources/CLEGO/CLEGO/bin/Debug/CLEGO.dll").expect("Échec de la création de CString"); +// let dll_handle: HMODULE = LoadLibraryA(dll_path.as_ptr()); + +// if dll_handle.is_null() { +// //let error_code = GetLastError(); +// println!("Erreur lors du chargement de la DLL.");// Code d'erreur : {}", error_code); +// return; +// } + +// let class_name = CString::new("PS_Class").expect("Échec de la création de CString"); +// let class_ptr: *mut c_void = GetProcAddress(dll_handle, class_name.as_ptr()) as *mut c_void; + +// if class_ptr.is_null() { +// // let error_code = GetLastError(); +// println!("Classe non trouvée.");// Code d'erreur : {}", error_code); +// FreeLibrary(dll_handle); +// return; +// } + +// // Convertissez class_ptr en une instance de classe Rust et appelez ses méthodes ici + +// FreeLibrary(dll_handle); +// } +// } diff --git a/clego/src/SV_DLL_Win.rs b/clego/src/SV_DLL_Win.rs index f0e0d33..ea10d93 100644 --- a/clego/src/SV_DLL_Win.rs +++ b/clego/src/SV_DLL_Win.rs @@ -36,8 +36,8 @@ result }} //SSV_LireCartePS -pub fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :String , NomRessourceLecteur :String , CodePorteurPS :String, - mut ZDonneesSortie: *mut c_void , mut TTailleDonneesSortie: usize)->i32{ +pub fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , NomRessourcePS :&str , NomRessourceLecteur :&str , CodePorteurPS :&str, + ZDonneesSortie: &mut *mut c_void , TTailleDonneesSortie: &mut usize)->i32{// mut ZDonneesSortie: *mut c_void , mut TTailleDonneesSortie: usize)->i32{ // Résolution d'une fonction exportée ("SSV_LireCartePS") let symbol_name = CString::new("SSV_LireCartePS").expect("Nom de symbole invalide"); unsafe { @@ -51,13 +51,18 @@ pub fn ssv_lirecarteps(dll_handle:*mut winapi::shared::minwindef::HINSTANCE__ , let my_function: MyFunctionType = std::mem::transmute(function_ptr); // appel de la fonction -ZDonneesSortie= std::ptr::null_mut(); -TTailleDonneesSortie=0; +//*ZDonneesSortie= std::ptr::null_mut();//ZDonneesSortie= std::ptr::null_mut(); +*TTailleDonneesSortie=0; + +println!("ZDonneesSortie: {:?}", ZDonneesSortie); + let result = my_function(CString::new(NomRessourcePS).unwrap().as_ptr(), CString::new(NomRessourceLecteur).unwrap().as_ptr(), CString::new(CodePorteurPS).unwrap().as_ptr(), - &mut ZDonneesSortie, - &mut TTailleDonneesSortie); +ZDonneesSortie, TTailleDonneesSortie); +// &mut TTailleDonneesSortie); + +println!("ZDonneesSortie: {:?}", ZDonneesSortie); result } } \ No newline at end of file diff --git a/clego/src/main.rs b/clego/src/main.rs index 7c7176e..a2ffec3 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,13 +1,27 @@ mod SV_DLL_Win; +mod INSi; +mod CPS; fn main() { - // let my_handle:*mut winapi::shared::minwindef::HINSTANCE__ ; - let my_handle = SV_DLL_Win::load_library("C:/Program Files/santesocial/fsv/1.40.14/lib/ssvw64.dll"); + + // INSi::test; + let my_handle = SV_DLL_Win::load_library("C:/Program Files/santesocial/fsv/1.40.14/lib/ssvw64.dll"); if my_handle.is_null() { panic!("Échec du chargement de la DLL"); } let result_ssv_initlib2=SV_DLL_Win::ssv_initlib2(my_handle,"C:/CLEGO_Files/SanteSociale/sesam.ini"); println!("Résultat SSV_InitLIB2 : {}", result_ssv_initlib2); + +let mut ZDonneesSortie: *mut std::ffi::c_void= std::ptr::null_mut(); +let mut TTailleDonneesSortie: usize=55; + +let result_ssv_lirecps = SV_DLL_Win::ssv_lirecarteps(my_handle, "HID Global OMNIKEY 3x21 Smart Card Reader 0","", "1234", +&mut ZDonneesSortie, &mut TTailleDonneesSortie); +println!("Résultat SSV_LireCartePS : {}", result_ssv_lirecps); +println!("Taille sortie SSV_LireCartePS : {}", TTailleDonneesSortie); +println!("ZDonneesSortie: {:?}", ZDonneesSortie); + +CPS::decode_zone_memoire(ZDonneesSortie,TTailleDonneesSortie) } \ No newline at end of file -- 2.45.2