initial commit

This commit is contained in:
Ave
2024-04-06 23:33:58 +00:00
commit f824a732f9
10 changed files with 494 additions and 0 deletions

87
src/lib.rs Normal file
View File

@ -0,0 +1,87 @@
#![no_std]
mod sppcs;
mod win32;
use core::{ffi::c_void, ptr::null_mut};
use win32::{LocalFree, StrStrNIW, SL_LICENSING_STATUS};
use win32::{SLGetLicensingStatusInformation, SLGetProductSkuInformation};
use windows_sys::{
core::{GUID, PCWSTR},
w,
};
unsafe fn is_grace_period_product(hslc: *const c_void, pproductskuid: *const GUID) -> bool {
let mut p_buffer = null_mut();
let mut cb_size = 0;
if SLGetProductSkuInformation(
hslc,
pproductskuid,
w!("Name"),
null_mut(),
&mut cb_size,
&mut p_buffer,
) != 0
{
LocalFree(p_buffer as *mut c_void);
return false;
}
if !StrStrNIW(p_buffer as *const u16, w!("Grace"), cb_size).is_null() {
LocalFree(p_buffer as *mut c_void);
return true;
}
LocalFree(p_buffer as *mut c_void);
false
}
#[no_mangle]
unsafe extern "system" fn SLGetLicensingStatusInformationHook(
hslc: *const c_void,
pappid: *const GUID,
pproductskuid: *const GUID,
pwszrightname: PCWSTR,
pnstatuscount: *mut u32,
pplicensingstatus: *mut *mut SL_LICENSING_STATUS,
) -> i32 {
let result = SLGetLicensingStatusInformation(
hslc,
pappid,
pproductskuid,
pwszrightname,
pnstatuscount,
pplicensingstatus,
);
if result != 0 {
return result;
}
for i in 0..(*pnstatuscount as usize) {
let status = (*pplicensingstatus).add(i);
if (*status).eStatus == 0 {
continue;
}
if is_grace_period_product(hslc, &(*status).SkuId) {
continue;
}
(*status).eStatus = 1;
(*status).dwGraceTime = 0;
(*status).dwTotalGraceDays = 0;
(*status).hrReason = 0;
(*status).qwValidityExpiration = 0;
}
result
}
#[no_mangle]
extern "system" fn _DllMainCRTStartup(_: *const u8, _: u32, _: *const u8) -> u32 {
1
}
#[cfg(not(test))]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
panic!()
}

132
src/sppcs.rs Normal file
View File

@ -0,0 +1,132 @@
#![allow(non_snake_case)]
#[no_mangle]
fn SLCallServer() {}
#[no_mangle]
fn SLpAuthenticateGenuineTicketResponse() {}
#[no_mangle]
fn SLpBeginGenuineTicketTransaction() {}
#[no_mangle]
fn SLpClearActivationInProgress() {}
#[no_mangle]
fn SLpDepositDownlevelGenuineTicket() {}
#[no_mangle]
fn SLpDepositTokenActivationResponse() {}
#[no_mangle]
fn SLpGenerateTokenActivationChallenge() {}
#[no_mangle]
fn SLpGetGenuineBlob() {}
#[no_mangle]
fn SLpGetGenuineLocal() {}
#[no_mangle]
fn SLpGetLicenseAcquisitionInfo() {}
#[no_mangle]
fn SLpGetMSPidInformation() {}
#[no_mangle]
fn SLpGetMachineUGUID() {}
#[no_mangle]
fn SLpGetTokenActivationGrantInfo() {}
#[no_mangle]
fn SLpIAActivateProduct() {}
#[no_mangle]
fn SLpIsCurrentInstalledProductKeyDefaultKey() {}
#[no_mangle]
fn SLpProcessVMPipeMessage() {}
#[no_mangle]
fn SLpSetActivationInProgress() {}
#[no_mangle]
fn SLpTriggerServiceWorker() {}
#[no_mangle]
fn SLpVLActivateProduct() {}
#[no_mangle]
fn SLClose() {}
#[no_mangle]
fn SLConsumeRight() {}
#[no_mangle]
fn SLDepositMigrationBlob() {}
#[no_mangle]
fn SLDepositOfflineConfirmationId() {}
#[no_mangle]
fn SLDepositOfflineConfirmationIdEx() {}
#[no_mangle]
fn SLDepositStoreToken() {}
#[no_mangle]
fn SLFireEvent() {}
#[no_mangle]
fn SLGatherMigrationBlob() {}
#[no_mangle]
fn SLGatherMigrationBlobEx() {}
#[no_mangle]
fn SLGenerateOfflineInstallationId() {}
#[no_mangle]
fn SLGenerateOfflineInstallationIdEx() {}
#[no_mangle]
fn SLGetActiveLicenseInfo() {}
#[no_mangle]
fn SLGetApplicationInformation() {}
#[no_mangle]
fn SLGetApplicationPolicy() {}
#[no_mangle]
fn SLGetAuthenticationResult() {}
#[no_mangle]
fn SLGetEncryptedPIDEx() {}
#[no_mangle]
fn SLGetGenuineInformation() {}
#[no_mangle]
fn SLGetInstalledProductKeyIds() {}
#[no_mangle]
fn SLGetLicense() {}
#[no_mangle]
fn SLGetLicenseFileId() {}
#[no_mangle]
fn SLGetLicenseInformation() {}
#[no_mangle]
fn SLGetPKeyId() {}
#[no_mangle]
fn SLGetPKeyInformation() {}
#[no_mangle]
fn SLGetPolicyInformation() {}
#[no_mangle]
fn SLGetPolicyInformationDWORD() {}
#[no_mangle]
fn SLGetSLIDList() {}
#[no_mangle]
fn SLGetServiceInformation() {}
#[no_mangle]
fn SLInstallLicense() {}
#[no_mangle]
fn SLInstallProofOfPurchase() {}
#[no_mangle]
fn SLInstallProofOfPurchaseEx() {}
#[no_mangle]
fn SLIsGenuineLocalEx() {}
#[no_mangle]
fn SLLoadApplicationPolicies() {}
#[no_mangle]
fn SLOpen() {}
#[no_mangle]
fn SLPersistApplicationPolicies() {}
#[no_mangle]
fn SLPersistRTSPayloadOverride() {}
#[no_mangle]
fn SLReArm() {}
#[no_mangle]
fn SLRegisterEvent() {}
#[no_mangle]
fn SLRegisterPlugin() {}
#[no_mangle]
fn SLSetAuthenticationData() {}
#[no_mangle]
fn SLSetCurrentProductKey() {}
#[no_mangle]
fn SLSetGenuineInformation() {}
#[no_mangle]
fn SLUninstallLicense() {}
#[no_mangle]
fn SLUninstallProofOfPurchase() {}
#[no_mangle]
fn SLUnloadApplicationPolicies() {}
#[no_mangle]
fn SLUnregisterEvent() {}
#[no_mangle]
fn SLUnregisterPlugin() {}

72
src/win32.rs Normal file
View File

@ -0,0 +1,72 @@
use core::ffi::c_void;
use windows_sys::core::{GUID, PCWSTR};
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct SL_LICENSING_STATUS {
pub SkuId: GUID,
pub eStatus: i32,
pub dwGraceTime: u32,
pub dwTotalGraceDays: u32,
pub hrReason: i32,
pub qwValidityExpiration: u64,
}
#[cfg_attr(
target_arch = "x86",
link(name = "sppcs", kind = "raw-dylib", import_name_type = "undecorated")
)]
#[cfg_attr(not(target_arch = "x86"), link(name = "sppcs", kind = "raw-dylib"))]
extern "system" {
pub fn SLGetLicensingStatusInformation(
hslc: *const c_void,
pappid: *const GUID,
pproductskuid: *const GUID,
pwszrightname: PCWSTR,
pnstatuscount: *mut u32,
pplicensingstatus: *mut *mut SL_LICENSING_STATUS,
) -> i32;
}
#[cfg_attr(
target_arch = "x86",
link(name = "sppcs", kind = "raw-dylib", import_name_type = "undecorated")
)]
#[cfg_attr(not(target_arch = "x86"), link(name = "sppcs", kind = "raw-dylib"))]
extern "system" {
pub fn SLGetProductSkuInformation(
hslc: *const c_void,
pproductskuid: *const GUID,
pwszvaluename: PCWSTR,
pedatatype: *mut u32,
pcbvalue: *mut u32,
ppbvalue: *mut *mut u8,
) -> i32;
}
#[cfg_attr(
target_arch = "x86",
link(
name = "KERNEL32",
kind = "raw-dylib",
import_name_type = "undecorated"
)
)]
#[cfg_attr(not(target_arch = "x86"), link(name = "KERNEL32", kind = "raw-dylib"))]
extern "system" {
pub fn LocalFree(hmem: *mut c_void) -> *mut c_void;
}
#[cfg_attr(
target_arch = "x86",
link(name = "SHLWAPI", kind = "raw-dylib", import_name_type = "undecorated")
)]
#[cfg_attr(not(target_arch = "x86"), link(name = "SHLWAPI", kind = "raw-dylib"))]
extern "system" {
pub fn StrStrNIW(
pszfirst: ::windows_sys::core::PCWSTR,
pszsrch: ::windows_sys::core::PCWSTR,
cchmax: u32,
) -> ::windows_sys::core::PWSTR;
}