Remove windows-sys dependency and code cleanup

This affects the source code only, output binary hashes remain the same.
This commit is contained in:
Ave 2024-04-12 00:44:51 +00:00
parent 6d7c85fb2c
commit 044af0e99d
7 changed files with 141 additions and 199 deletions

71
Cargo.lock generated
View File

@ -4,73 +4,4 @@ version = 3
[[package]]
name = "shook"
version = "0.1.0"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
[[package]]
name = "windows_i686_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
[[package]]
name = "windows_i686_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
version = "0.1.1"

View File

@ -1,21 +1,27 @@
[package]
name = "shook"
version = "0.1.0"
description = "A rust implementation of ohook"
repository = "https://github.com/massgravel/ohook-rs"
license = "MIT"
edition = "2021"
rust-version = "1.77.1"
name = "shook"
version = "0.1.1"
description = "A rust implementation of ohook"
keywords = [
"activator",
"office",
"ohook",
]
categories = [
"no-std",
"no-std::no-alloc",
]
license = "MIT"
repository = "https://github.com/massgravel/ohook-rs"
[lib]
crate-type = ["cdylib"]
[dependencies]
windows-sys = "0.52"
[profile.dev]
lto = true
opt-level = 1
lto = true
panic = "abort"
[profile.release]

View File

@ -4,46 +4,46 @@ 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,
use win32::{
Guid, LocalFree, SLGetLicensingStatusInformation, SLGetProductSkuInformation, StrStrNIW,
SL_LICENSING_STATUS,
};
unsafe fn is_grace_period_product(hslc: *const c_void, pproductskuid: *const GUID) -> bool {
const GRACE: [u16; 6] = [0x47, 0x72, 0x61, 0x63, 0x65, 0x00];
const NAME: [u16; 5] = [0x4e, 0x61, 0x6d, 0x65, 0x00];
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"),
NAME.as_ptr(),
null_mut(),
&mut cb_size,
&mut p_buffer,
) != 0
{
LocalFree(p_buffer as *mut c_void);
LocalFree(p_buffer.cast());
return false;
}
if !StrStrNIW(p_buffer as *const u16, w!("Grace"), cb_size).is_null() {
LocalFree(p_buffer as *mut c_void);
if !StrStrNIW(p_buffer.cast(), GRACE.as_ptr(), cb_size).is_null() {
LocalFree(p_buffer.cast());
return true;
}
LocalFree(p_buffer as *mut c_void);
LocalFree(p_buffer.cast());
false
}
#[no_mangle]
unsafe extern "system" fn SLGetLicensingStatusInformationHook(
hslc: *const c_void,
pappid: *const GUID,
pproductskuid: *const GUID,
pwszrightname: PCWSTR,
pappid: *const Guid,
pproductskuid: *const Guid,
pwszrightname: *const u16,
pnstatuscount: *mut u32,
pplicensingstatus: *mut *mut SL_LICENSING_STATUS,
) -> i32 {

View File

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

View File

@ -1,11 +1,20 @@
// Mostly copied from windows-sys
use core::ffi::c_void;
use windows_sys::core::{GUID, PCWSTR};
#[repr(C)]
pub struct Guid {
pub data1: u32,
pub data2: u16,
pub data3: u16,
pub data4: [u8; 8],
}
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct SL_LICENSING_STATUS {
pub SkuId: GUID,
pub SkuId: Guid,
pub eStatus: i32,
pub dwGraceTime: u32,
pub dwTotalGraceDays: u32,
@ -21,9 +30,9 @@ pub struct SL_LICENSING_STATUS {
extern "system" {
pub fn SLGetLicensingStatusInformation(
hslc: *const c_void,
pappid: *const GUID,
pproductskuid: *const GUID,
pwszrightname: PCWSTR,
pappid: *const Guid,
pproductskuid: *const Guid,
pwszrightname: *const u16,
pnstatuscount: *mut u32,
pplicensingstatus: *mut *mut SL_LICENSING_STATUS,
) -> i32;
@ -37,8 +46,8 @@ extern "system" {
extern "system" {
pub fn SLGetProductSkuInformation(
hslc: *const c_void,
pproductskuid: *const GUID,
pwszvaluename: PCWSTR,
pproductskuid: *const Guid,
pwszvaluename: *const u16,
pedatatype: *mut u32,
pcbvalue: *mut u32,
ppbvalue: *mut *mut u8,
@ -64,9 +73,5 @@ extern "system" {
)]
#[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;
pub fn StrStrNIW(pszfirst: *const u16, pszsrch: *const u16, cchmax: u32) -> *mut u16;
}