Skip to content

Commit

Permalink
Fix windows stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Mar 2, 2024
1 parent 5db7b66 commit 05f4512
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
7 changes: 1 addition & 6 deletions Payload_Type/thanatos/agent/ffiwrappers/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ impl FfiError {
#[cfg(target_os = "windows")]
pub fn os_error() -> Self {
use windows::Win32::Foundation::GetLastError;

if let Err(e) = unsafe { GetLastError() } {
Self::from_windows_error(e)
} else {
Self::OsError(0)
}
Self::OsError(unsafe { GetLastError().0 as i32 })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use base_profile::msg::checkin::{checkin_data::PlatformInfo, CheckinData};

#[cfg(target_os = "windows")]
pub fn get_checkininfo() -> CheckinData {
use crate::{native, os::windows, proto::checkin::WindowsInfo};
use crate::{native, os::windows};
use base_profile::msg::checkin::WindowsInfo;

CheckinInfo {
uuid,
CheckinData {
user: windows::username().ok(),
host: windows::hostname().ok(),
domain: windows::domain().ok(),
Expand Down
2 changes: 1 addition & 1 deletion Payload_Type/thanatos/agent/thanatos/src/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ffiwrappers::windows::{processthreadsapi::token::CurrentToken, sysinfoapi};
mod platform;
pub use platform::{build_number, product};

use crate::proto::checkin::Architecture;
use base_profile::msg::checkin::Architecture;

pub fn username() -> Result<String, ThanatosError> {
ffiwrappers::windows::username().map_err(ThanatosError::FFIError)
Expand Down
67 changes: 31 additions & 36 deletions Payload_Type/thanatos/agent/thanatos/src/os/windows/platform.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
use ffiwrappers::windows::sysinfoapi::{OsVersionInfo, ProductType};
use ffiwrappers::windows::sysinfoapi::OsVersionInfo;

use crate::proto::checkin::windows_info::Product;
use base_profile::msg::checkin::windows_info::Product;

macro_rules! product_mapping {
macro_rules! map_product {
($v:ident, $($field:ident),*) => {
match $v {
ffiwrappers::windows::sysinfoapi::ProductType::Other(o) => $crate::proto::checkin::windows_info::Product::Other(o),
$(ffiwrappers::windows::sysinfoapi::ProductType::$field => $crate::proto::checkin::windows_info::Product::ProductType($crate::proto::checkin::WindowsProductType::$field.into()),)*
ffiwrappers::windows::sysinfoapi::ProductType::Other(o) => base_profile::msg::checkin::windows_info::Product::Other(o),
$(ffiwrappers::windows::sysinfoapi::ProductType::$field => base_profile::msg::checkin::windows_info::Product::ProductType(base_profile::msg::checkin::WindowsProductType::$field.into()),)*
}
};
}

impl From<ProductType> for Product {
fn from(value: ProductType) -> Self {
product_mapping!(
value,
Core,
Professional,
Education,
Enterprise,
ProWorkstation,
ProForEducation,
EnterpriseEvaluation,
DatacenterServer,
DatacenterEvaluationServer,
DatacenterServerCore,
DatacenterServerCoreV,
DatacenterServerV,
EnterpriseServer,
EnterpriseServerCore,
EnterpriseServerCoreV,
EnterpriseServerV,
HomeBasic,
StandardServer,
StandardEvaluationServer,
StandardServerCore,
StandardServerCoreV,
StandardServerV
)
}
}

pub fn build_number() -> u32 {
let osversion = OsVersionInfo::new();
osversion.build_number()
}

pub fn product() -> Product {
let osversion = OsVersionInfo::new();
osversion.product_type().into()
let product_type = osversion.product_type();
map_product!(
product_type,
Core,
Professional,
Education,
Enterprise,
ProWorkstation,
ProForEducation,
EnterpriseEvaluation,
DatacenterServer,
DatacenterEvaluationServer,
DatacenterServerCore,
DatacenterServerCoreV,
DatacenterServerV,
EnterpriseServer,
EnterpriseServerCore,
EnterpriseServerCoreV,
EnterpriseServerV,
HomeBasic,
StandardServer,
StandardEvaluationServer,
StandardServerCore,
StandardServerCoreV,
StandardServerV
)
}

0 comments on commit 05f4512

Please sign in to comment.