Skip to content

Commit

Permalink
OrcLib: SystemDetail: add GetOrcSystemType
Browse files Browse the repository at this point in the history
It stores the user's specified value and fallback on host's
  • Loading branch information
fabienfl-orc committed Jun 4, 2024
1 parent 41346e5 commit 69f96b0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/OrcCommand/Command/FastFind/FastFind_Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ HRESULT Main::Run()
pStructuredOutput->WriteNamed(L"os", strSystemDescr.c_str());

std::wstring strSystemRole;
if (SUCCEEDED(SystemDetails::GetSystemType(strSystemRole)))
if (SUCCEEDED(SystemDetails::GetOrcSystemType(strSystemRole)))
pStructuredOutput->WriteNamed(L"role", strSystemRole.c_str());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ CommandMessage::Message WolfExecution::SetCommandFromConfigItem(const ConfigItem
const wstring& requiredSystemTypes = item[WOLFLAUNCHER_COMMAND_SYSTEMTYPE];
wstring strProductType;

if (FAILED(hr = SystemDetails::GetSystemType(strProductType)))
if (FAILED(hr = SystemDetails::GetOrcSystemType(strProductType)))
{
Log::Error("Failed to retrieve system product type [{}]", SystemError(hr));
return nullptr;
Expand Down
6 changes: 5 additions & 1 deletion src/OrcCommand/UtilitiesMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ void UtilitiesMain::PrintCommonParameters(Orc::Text::Tree& root)
SystemDetails::GetSystemType(systemType);
PrintValue(root, L"System type", systemType);

std::wstring orcSystemType;
SystemDetails::GetOrcSystemType(orcSystemType);
PrintValue(root, L"DFIR-Orc system type", orcSystemType);

PrintValue(root, L"System tags", boost::join(SystemDetails::GetSystemTags(), ", "));

std::wstring logFileName(Text::kEmptyW);
Expand Down Expand Up @@ -223,7 +227,7 @@ void UtilitiesMain::Configure(int argc, const wchar_t* argv[])

if (!systemType.empty())
{
SystemDetails::SetSystemType(systemType);
SystemDetails::SetOrcSystemType(systemType);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/OrcLib/CommandAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ HRESULT CommandAgent::ApplyPattern(
auto s6 = std::regex_replace(s5, r_TimeStamp, strTimeStamp);

wstring strSystemType;
SystemDetails::GetSystemType(strSystemType);
SystemDetails::GetOrcSystemType(strSystemType);
auto s7 = std::regex_replace(s6, r_SystemType, strSystemType);

std::swap(s7, output);
Expand Down
2 changes: 1 addition & 1 deletion src/OrcLib/OutputSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ OutputSpec::ApplyPattern(const std::wstring& strPattern, const std::wstring& str
SystemDetails::GetTimeStamp(strTimeStamp);

wstring strSystemType;
SystemDetails::GetSystemType(strSystemType);
SystemDetails::GetOrcSystemType(strSystemType);

strFileName = fmt::vformat(
fmt::wstring_view(strPattern),
Expand Down
27 changes: 27 additions & 0 deletions src/OrcLib/SystemDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct SystemDetailsBlock
std::optional<std::wstring> strOrcComputerName;
std::optional<std::wstring> strOrcFullComputerName;
std::optional<std::wstring> strProductType;
std::optional<std::wstring> strOrcProductType;
std::optional<BYTE> wProductType;
std::wstring strUserName;
std::wstring strUserSID;
Expand Down Expand Up @@ -105,6 +106,32 @@ HRESULT SystemDetails::GetSystemType(std::wstring& strProductType)
return S_OK;
}

HRESULT Orc::SystemDetails::SetOrcSystemType(std::wstring strProductType)
{
HRESULT hr = E_FAIL;
if (FAILED(hr = LoadSystemDetails()))
return hr;

if (!strProductType.empty())
g_pDetailsBlock->strOrcProductType.emplace(std::move(strProductType));

return S_OK;
}

HRESULT SystemDetails::GetOrcSystemType(std::wstring& strProductType)
{
HRESULT hr = E_FAIL;
if (FAILED(hr = LoadSystemDetails()))
return hr;

if (g_pDetailsBlock->strOrcProductType.has_value())
{
strProductType = g_pDetailsBlock->strOrcProductType.value();
return S_OK;
}

return GetSystemType(strProductType);
}

bool SystemDetails::IsKnownWindowsBuild(uint32_t build)
{
Expand Down
3 changes: 3 additions & 0 deletions src/OrcLib/SystemDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class SystemDetails
static HRESULT GetSystemType(std::wstring& strSystemType);
static HRESULT GetSystemType(BYTE& systemType);

static HRESULT SetOrcSystemType(std::wstring strSystemType);
static HRESULT GetOrcSystemType(std::wstring& strSystemType);

static bool IsKnownWindowsBuild(uint32_t build);
static void GetTagsFromBuildId(uint32_t ProductType, uint32_t build, SystemTags& tags);

Expand Down

0 comments on commit 69f96b0

Please sign in to comment.