fix: adapt the clego setup to windows
This commit is contained in:
parent
6d25806549
commit
f0711346ca
25
Cargo.lock
generated
25
Cargo.lock
generated
@ -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"
|
||||
|
5
clego/.gitignore
vendored
5
clego/.gitignore
vendored
@ -3,4 +3,7 @@
|
||||
|
||||
# Ignore .env files
|
||||
.env
|
||||
.env.build
|
||||
.env.build
|
||||
|
||||
# Ignore exploitation files - only usefull for local debugging on windows
|
||||
lib/*.exp
|
||||
|
BIN
clego/lib/ssvw64.lib
Normal file
BIN
clego/lib/ssvw64.lib
Normal file
Binary file not shown.
@ -1,94 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
// }
|
||||
// }
|
@ -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
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
ssvlib_demo::demo();
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user