Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ave9858 committed Apr 7, 2024
0 parents commit f824a73
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
76 changes: 76 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "shook"
version = "0.1.0"
edition = "2021"
rust-version = "1.77.1"

[lib]
crate-type = ["cdylib"]

[dependencies]
windows-sys = "0.52"

[profile.dev]
lto = true
opt-level = 1
panic = "abort"

[profile.release]
lto = true
panic = "abort"
strip = true
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2023-2024 asdcorp, Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ohook.rs

A rewrite of [ohook](https://github.com/asdcorp/ohook) in Rust for decreased size, easier building, and better reproducibility. For more information on ohook check the original repo.

## Building
Rust 1.77.1 and [Visual Studio Build Tools 2022 LTSC 17.6](https://download.visualstudio.microsoft.com/download/pr/a851fc84-7739-4b67-a7da-2c8564e30b38/b4133f16d790c3ee7325fff80c47094d94dff44b426b86db9013b200bb669ce2/vs_BuildTools.exe) running on Windows is required if you want to build binaries bit-for-bit identical to the release. To build x64, run `cargo build --release`, and for x86 run `cargo build --release --target i686-pc-windows-msvc`.

## License

The project is licensed under the terms of the MIT License.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
println!("cargo::rustc-cdylib-link-arg=/DEF:sppc.def");
println!("cargo::rustc-cdylib-link-arg=/Brepro");
println!("cargo::rustc-cdylib-link-arg=/emittoolversioninfo:no");
}
72 changes: 72 additions & 0 deletions sppc.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
LIBRARY sppc.dll
EXPORTS
;hooked function
SLGetLicensingStatusInformation = SLGetLicensingStatusInformationHook

;everything else
SLCallServer = SPPCS.SLCallServer
SLpAuthenticateGenuineTicketResponse = SPPCS.SLpAuthenticateGenuineTicketResponse
SLpBeginGenuineTicketTransaction = SPPCS.SLpBeginGenuineTicketTransaction
SLpClearActivationInProgress = SPPCS.SLpClearActivationInProgress
SLpDepositDownlevelGenuineTicket = SPPCS.SLpDepositDownlevelGenuineTicket
SLpDepositTokenActivationResponse = SPPCS.SLpDepositTokenActivationResponse
SLpGenerateTokenActivationChallenge = SPPCS.SLpGenerateTokenActivationChallenge
SLpGetGenuineBlob = SPPCS.SLpGetGenuineBlob
SLpGetGenuineLocal = SPPCS.SLpGetGenuineLocal
SLpGetLicenseAcquisitionInfo = SPPCS.SLpGetLicenseAcquisitionInfo
SLpGetMSPidInformation = SPPCS.SLpGetMSPidInformation
SLpGetMachineUGUID = SPPCS.SLpGetMachineUGUID
SLpGetTokenActivationGrantInfo = SPPCS.SLpGetTokenActivationGrantInfo
SLpIAActivateProduct = SPPCS.SLpIAActivateProduct
SLpIsCurrentInstalledProductKeyDefaultKey = SPPCS.SLpIsCurrentInstalledProductKeyDefaultKey
SLpProcessVMPipeMessage = SPPCS.SLpProcessVMPipeMessage
SLpSetActivationInProgress = SPPCS.SLpSetActivationInProgress
SLpTriggerServiceWorker = SPPCS.SLpTriggerServiceWorker
SLpVLActivateProduct = SPPCS.SLpVLActivateProduct
SLClose = SPPCS.SLClose
SLConsumeRight = SPPCS.SLConsumeRight
SLDepositMigrationBlob = SPPCS.SLDepositMigrationBlob
SLDepositOfflineConfirmationId = SPPCS.SLDepositOfflineConfirmationId
SLDepositOfflineConfirmationIdEx = SPPCS.SLDepositOfflineConfirmationIdEx
SLDepositStoreToken = SPPCS.SLDepositStoreToken
SLFireEvent = SPPCS.SLFireEvent
SLGatherMigrationBlob = SPPCS.SLGatherMigrationBlob
SLGatherMigrationBlobEx = SPPCS.SLGatherMigrationBlobEx
SLGenerateOfflineInstallationId = SPPCS.SLGenerateOfflineInstallationId
SLGenerateOfflineInstallationIdEx = SPPCS.SLGenerateOfflineInstallationIdEx
SLGetActiveLicenseInfo = SPPCS.SLGetActiveLicenseInfo
SLGetApplicationInformation = SPPCS.SLGetApplicationInformation
SLGetApplicationPolicy = SPPCS.SLGetApplicationPolicy
SLGetAuthenticationResult = SPPCS.SLGetAuthenticationResult
SLGetEncryptedPIDEx = SPPCS.SLGetEncryptedPIDEx
SLGetGenuineInformation = SPPCS.SLGetGenuineInformation
SLGetInstalledProductKeyIds = SPPCS.SLGetInstalledProductKeyIds
SLGetLicense = SPPCS.SLGetLicense
SLGetLicenseFileId = SPPCS.SLGetLicenseFileId
SLGetLicenseInformation = SPPCS.SLGetLicenseInformation
SLGetPKeyId = SPPCS.SLGetPKeyId
SLGetPKeyInformation = SPPCS.SLGetPKeyInformation
SLGetPolicyInformation = SPPCS.SLGetPolicyInformation
SLGetPolicyInformationDWORD = SPPCS.SLGetPolicyInformationDWORD
SLGetProductSkuInformation = SPPCS.SLGetProductSkuInformation
SLGetSLIDList = SPPCS.SLGetSLIDList
SLGetServiceInformation = SPPCS.SLGetServiceInformation
SLInstallLicense = SPPCS.SLInstallLicense
SLInstallProofOfPurchase = SPPCS.SLInstallProofOfPurchase
SLInstallProofOfPurchaseEx = SPPCS.SLInstallProofOfPurchaseEx
SLIsGenuineLocalEx = SPPCS.SLIsGenuineLocalEx
SLLoadApplicationPolicies = SPPCS.SLLoadApplicationPolicies
SLOpen = SPPCS.SLOpen
SLPersistApplicationPolicies = SPPCS.SLPersistApplicationPolicies
SLPersistRTSPayloadOverride = SPPCS.SLPersistRTSPayloadOverride
SLReArm = SPPCS.SLReArm
SLRegisterEvent = SPPCS.SLRegisterEvent
SLRegisterPlugin = SPPCS.SLRegisterPlugin
SLSetAuthenticationData = SPPCS.SLSetAuthenticationData
SLSetCurrentProductKey = SPPCS.SLSetCurrentProductKey
SLSetGenuineInformation = SPPCS.SLSetGenuineInformation
SLUninstallLicense = SPPCS.SLUninstallLicense
SLUninstallProofOfPurchase = SPPCS.SLUninstallProofOfPurchase
SLUnloadApplicationPolicies = SPPCS.SLUnloadApplicationPolicies
SLUnregisterEvent = SPPCS.SLUnregisterEvent
SLUnregisterPlugin = SPPCS.SLUnregisterPlugin
87 changes: 87 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
Loading

0 comments on commit f824a73

Please sign in to comment.