From f0711346ca533a2c7e7c6a2eced6a9fdfb1013db Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Tue, 23 Jul 2024 14:06:28 +0200 Subject: [PATCH] fix: adapt the clego setup to windows --- Cargo.lock | 25 +++----- clego/.gitignore | 5 +- clego/lib/ssvw64.lib | Bin 0 -> 2104 bytes clego/src/CPS.rs | 94 ------------------------------- clego/src/INSi.rs | 35 ------------ clego/src/SV_DLL_Win.rs | 68 ---------------------- clego/src/main.rs | 28 +-------- clego/src/ssv_headers_c/make.bat | 5 +- 8 files changed, 18 insertions(+), 242 deletions(-) create mode 100644 clego/lib/ssvw64.lib delete mode 100644 clego/src/CPS.rs delete mode 100644 clego/src/INSi.rs delete mode 100644 clego/src/SV_DLL_Win.rs diff --git a/Cargo.lock b/Cargo.lock index 905172f..206bb6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,27 +6,18 @@ version = 3 name = "clego" version = "0.1.0" dependencies = [ - "winapi", + "dotenv", + "libc", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "dotenv" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "libc" +version = "0.2.155" 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" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" diff --git a/clego/.gitignore b/clego/.gitignore index 33da66d..5c052ec 100644 --- a/clego/.gitignore +++ b/clego/.gitignore @@ -3,4 +3,7 @@ # Ignore .env files .env -.env.build \ No newline at end of file +.env.build + +# Ignore exploitation files - only usefull for local debugging on windows +lib/*.exp diff --git a/clego/lib/ssvw64.lib b/clego/lib/ssvw64.lib new file mode 100644 index 0000000000000000000000000000000000000000..13cbd5a9e64e27005c0cc1330e6d2e10e663592a GIT binary patch literal 2104 zcmcIlPj6B|5dT4eDlrDdgYi$qq>1%{?c+gdV$ACw8%Zf8K)t>K4_Xph8bCdIX*l@_ zyqGj5eg%*H0ET$*=%JsZ2kXq+-S?+bg#Pvq4f@C#Kle^t0fa^eT0|>Q&@Cgt(7jw1-*mFp9XqvgL;&!QGuD>j=m2$<( zcFFAZ-oDG|FwMeFKL6)A-U|hBTzR!q*fiHyDk~_LUz@qZRzIIx)#&Ti!I9|`F_Uj~ z8*9~WzfmlERJ>A0t8>_F?Oj$9!ikYdxyVEanvEdP4gn`&;G6`tSzt($AVUaYL=Zqw z?q>XPIqu0I9A3FQIi4e+az$QfE=h&OtFj@Il(gDyf!4pOM_*QTv>UYsGx+lHQ!^R> zt`R0Yl2)VkW^b-6IKZII2gOKgAhw!pS=D}ZPE$vBX!DKcnH0 zNxKr3KjK9W{yUJB9Fri5v`({U-B`z~5=~!r?igzjw5#N+?HT(wx=Ji@ 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 deleted file mode 100644 index 6a8a960..0000000 --- a/clego/src/INSi.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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 deleted file mode 100644 index ea10d93..0000000 --- a/clego/src/SV_DLL_Win.rs +++ /dev/null @@ -1,68 +0,0 @@ -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 -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()); - h_module - } -} - -//SSV_INITLIB2 -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 { - 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 -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 { - 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();//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(), -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 a2ffec3..9a9a1e9 100644 --- a/clego/src/main.rs +++ b/clego/src/main.rs @@ -1,27 +1,5 @@ -mod SV_DLL_Win; -mod INSi; -mod CPS; +mod ssvlib_demo; fn main() { - - // 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 + ssvlib_demo::demo(); +} diff --git a/clego/src/ssv_headers_c/make.bat b/clego/src/ssv_headers_c/make.bat index 96a9f49..e58f940 100644 --- a/clego/src/ssv_headers_c/make.bat +++ b/clego/src/ssv_headers_c/make.bat @@ -9,8 +9,8 @@ if "%1"=="/clean" ( goto clean ) -@REM rem Set the environment for the x64 platform -@REM call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 +rem Set the environment for the x64 platform +call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 rem Create a ssvw64.lib file from the ssvw64.def file lib /def:ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64 @@ -21,6 +21,7 @@ exit /b 0 :clean del %LIB_DIR%\*.lib +del %LIB_DIR%\*.exp rem Clean complete pause