diff --git a/CHANGELOG.md b/CHANGELOG.md index d7c6519..d7a3ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,11 @@ This is the latest version introduces the use of the module and its features.
-## v0.2.1 [2023-04-10] +## v0.2.1 [2023-04-11] ### Features +- [#24](https://github.com/BarcaWebCloud/bscan/pull/24): New features for windows. Gratitude @ahsouza! - [#23](https://github.com/BarcaWebCloud/bscan/pull/23): New features for windows. Gratitude @ahsouza! ### Bugs @@ -26,7 +27,13 @@ This is the latest version introduces the use of the module and its features. Add features for **Windows** platform: -- **Get All Programs And Resources Installed** +- **Get All Programs And Resources Installed** [only Windows on moment] +- **Get Account Login ID And Name** [only Windows on moment] +- **Get Path Services on Windows** [only Windows on moment] +- **Get Path Boot Directory** [only Windows on moment] +- **Get Last Drive** [only Windows on moment] +- **Get Product Identification With Code, Name, Version And ID** [only Windows on moment] +- **Get System Status** [only Windows on moment] - **Fixed bugs to methods OS on Windows platform** diff --git a/include/swares/scan_os.h b/include/swares/scan_os.h index a2d93df..7272967 100644 --- a/include/swares/scan_os.h +++ b/include/swares/scan_os.h @@ -56,6 +56,20 @@ namespace bscan { std::string user(); std::string log(); std::string envvariables(); + std::string accountname(); + std::string accountloginid(); + std::string type(); + std::string fulltype(); + std::string servicepath(); + std::string bootdir(); + std::string boottempdir(); + std::string bootlastdrive(); + std::string productidentificationcode(); + std::string productidentificationname(); + std::string productidentificationversion(); + std::string pathsystemdriver(); + std::string productidentificationuuid(); + std::string status(); std::string kernel(); [[nodiscard]] bool is32bit() const; [[nodiscard]] bool is64bit() const; @@ -89,6 +103,20 @@ namespace bscan { static std::string getUser(); static std::string getLog(); static std::string getEnvVariables(); + static std::string getAccountName(); + static std::string getAccountLoginID(); + static std::string getType(); + static std::string getFullType(); + static std::string getServicePath(); + static std::string getBootDir(); + static std::string getBootTempDir(); + static std::string getBootLastDrive(); + static std::string getProductIdentificationCode(); + static std::string getProductIdentificationName(); + static std::string getProductIdentificationVersion(); + static std::string getPathSystemDriver(); + static std::string getProductIdentificationUUID(); + static std::string getStatus(); static std::string getKernel(); static bool getIs32bit(); static bool getIs64bit(); @@ -123,6 +151,20 @@ namespace bscan { std::string _user; std::string _log; std::string _envvariables; + std::string _accountname; + std::string _accountloginid; + std::string _type; + std::string _fulltype; + std::string _servicepath; + std::string _bootdir; + std::string _boottempdir; + std::string _bootlastdrive; + std::string _productidentificationcode; + std::string _productidentificationname; + std::string _productidentificationversion; + std::string _pathsystemdriver; + std::string _productidentificationuuid; + std::string _status; std::string _kernel; bool _32bit = false; bool _64bit = false; diff --git a/src/libs/info/scan_os.cpp b/src/libs/info/scan_os.cpp index 3c46276..8c2a8cf 100644 --- a/src/libs/info/scan_os.cpp +++ b/src/libs/info/scan_os.cpp @@ -50,6 +50,138 @@ namespace bscan { return _version; } + std::string OS::hostname() { + if (_hostname.empty()) { + _hostname = getHostname(); + } + return _hostname; + } + + std::string OS::domainname() { + if (_domainname.empty()) { + _domainname = getDomainName(); + } + return _domainname; + } + + std::string OS::uptime() { + if (_uptime.empty()) { + _uptime = getUptime(); + } + return _uptime; + } + + std::string OS::homedir() { + if (_homedir.empty()) { + _homedir = listHomeDir(); + } + return _homedir; + } + + std::string OS::recentitems() { + if (_recentitems.empty()) { + _recentitems = listRecentItems(); + } + return _recentitems; + } + + std::string OS::programfiles() { + if (_programfiles.empty()) { + _programfiles = listProgramFiles(); + } + return _programfiles; + } + + std::string OS::documents() { + if (_documents.empty()) { + _documents = listDocuments(); + } + return _documents; + } + + std::string OS::personaldocuments() { + if (_personaldocuments.empty()) { + _personaldocuments = listPersonalDocuments(); + } + return _personaldocuments; + } + + std::string OS::publicdocuments() { + if (_publicdocuments.empty()) { + _publicdocuments = listPublicDocuments(); + } + return _publicdocuments; + } + + std::string OS::searcheseverywhere() { + if (_searcheseverywhere.empty()) { + _searcheseverywhere = listSearchesEverywhere(); + } + return _searcheseverywhere; + } + + std::string OS::desktop() { + if (_desktop.empty()) { + _desktop = listDesktop(); + } + return _desktop; + } + + std::string OS::downloads() { + if (_downloads.empty()) { + _downloads = listDownloads(); + } + return _downloads; + } + + std::string OS::musics() { + if (_musics.empty()) { + _musics = listMusics(); + } + return _musics; + } + + std::string OS::videos() { + if (_videos.empty()) { + _videos = listVideos(); + } + return _videos; + } + + std::string OS::startmenu() { + if (_startmenu.empty()) { + _startmenu = listStartMenu(); + } + return _startmenu; + } + + std::string OS::imagescam() { + if (_imagescam.empty()) { + _imagescam = getImagesCAM(); + } + return _imagescam; + } + + std::string OS::imagessaved() { + if (_imagessaved.empty()) { + _imagessaved = getImagesSaved(); + } + return _imagessaved; + } + + std::string OS::images() { + if (_images.empty()) { + _images = getImages(); + } + return _images; + } + + std::string OS::historypowershell() { + if (_historypowershell.empty()) { + _historypowershell = getHistoryPowerShell(); + } + return _historypowershell; + } std::vector OS::programsandresources() { if (_programsandresources.empty()) { @@ -58,6 +190,111 @@ namespace bscan { return _programsandresources; } + std::string OS::envvariables() { + if (_envvariables.empty()) { + _envvariables = getEnvVariables(); + } + return _envvariables; + } + + std::string OS::accountname() { + if (_accountname.empty()) { + _accountname = getAccountName(); + } + return _accountname; + } + + std::string OS::accountloginid() { + if (_accountloginid.empty()) { + _accountloginid = getAccountLoginID(); + } + return _accountloginid; + } + + std::string OS::type() { + if (_type.empty()) { + _type = getType(); + } + return _type; + } + + std::string OS::fulltype() { + if (_fulltype.empty()) { + _fulltype = getFullType(); + } + return _fulltype; + } + + std::string OS::servicepath() { + if (_servicepath.empty()) { + _servicepath = getServicePath(); + } + return _servicepath; + } + + std::string OS::bootdir() { + if (_bootdir.empty()) { + _bootdir = getBootDir(); + } + return _bootdir; + } + + std::string OS::boottempdir() { + if (_boottempdir.empty()) { + _boottempdir = getBootTempDir(); + } + return _boottempdir; + } + + std::string OS::bootlastdrive() { + if (_bootlastdrive.empty()) { + _bootlastdrive = getBootLastDrive(); + } + return _bootlastdrive; + } + + std::string OS::productidentificationcode() { + if (_productidentificationcode.empty()) { + _productidentificationcode = getProductIdentificationCode(); + } + return _productidentificationcode; + } + + std::string OS::productidentificationname() { + if (_productidentificationname.empty()) { + _productidentificationname = getProductIdentificationName(); + } + return _productidentificationname; + } + + std::string OS::productidentificationversion() { + if (_productidentificationversion.empty()) { + _productidentificationversion = getProductIdentificationVersion(); + } + return _productidentificationversion; + } + + std::string OS::pathsystemdriver() { + if (_pathsystemdriver.empty()) { + _pathsystemdriver = getPathSystemDriver(); + } + return _pathsystemdriver; + } + + std::string OS::productidentificationuuid() { + if (_productidentificationuuid.empty()) { + _productidentificationuuid = getProductIdentificationUUID(); + } + return _productidentificationuuid; + } + + std::string OS::status() { + if (_status.empty()) { + _status = getStatus(); + } + return _status; + } + std::string OS::kernel() { if (_kernel.empty()) { _kernel = getKernel(); diff --git a/src/libs/info/windows/scan_os.cpp b/src/libs/info/windows/scan_os.cpp index cb11f00..2c34f41 100644 --- a/src/libs/info/windows/scan_os.cpp +++ b/src/libs/info/windows/scan_os.cpp @@ -41,6 +41,7 @@ #include #include #include "WMIwrapper.h" +#pragma comment(lib, "wbemuuid.lib") #include "swares/scan_datasource.h" #include "config.h" #include "utils/directory.h" @@ -311,16 +312,14 @@ namespace bscan { } std::string OS::getHostname() { - char *content = 0; - std::string hostname; - - content = getenv("COMPUTERNAME"); - if (content != 0) { - hostname = content; - content = 0; + std::vector vendor{}; + wmi::queryWMI("WIN32_Account", "Domain", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; } - - return std::string(lower(hostname)); + std::wstring tmp(ret); + return lower({tmp.begin(), tmp.end()}); } std::string OS::getUser() { @@ -670,10 +669,178 @@ namespace bscan { } return std::string(env_res); } - + + std::string OS::getAccountName() { + SetConsoleCP(1252); + SetConsoleOutputCP(1252); + + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystem", "UserName", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + std::string delimiter = "\\"; + std::vector val = split({tmp.begin(), tmp.end()}, delimiter); + + return val[1]; + } + + std::string OS::getAccountLoginID() { + std::vector vendor{}; + wmi::queryWMI("WIN32_LogonSession", "LogonId", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getType() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystem", "PrimaryOwnerName", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getFullType() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystem", "BootupState", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getStatus() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystem", "Status", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getServicePath() { + std::vector vendor{}; + wmi::queryWMI("WIN32_BaseService", "PathName", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getBootDir() { + std::vector vendor{}; + wmi::queryWMI("WIN32_BootConfiguration", "BootDirectory", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getBootTempDir() { + std::vector vendor{}; + wmi::queryWMI("WIN32_BootConfiguration", "TempDirectory", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getBootLastDrive() { + std::vector vendor{}; + wmi::queryWMI("WIN32_BootConfiguration", "LastDrive", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getProductIdentificationCode() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystemProduct", "IdentifyingNumber", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getProductIdentificationName() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystemProduct", "Name", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getProductIdentificationVersion() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystemProduct", "Version", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getProductIdentificationUUID() { + std::vector vendor{}; + wmi::queryWMI("WIN32_ComputerSystemProduct", "UUID", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + + std::string OS::getPathSystemDriver() { + std::vector vendor{}; + wmi::queryWMI("WIN32_SystemDriver", "PathName", vendor); + auto ret = vendor[0]; + if (!ret) { + return ""; + } + std::wstring tmp(ret); + + return {tmp.begin(), tmp.end()}; + } + std::string OS::getKernel() { return ""; } - bool OS::getIs64bit() { BOOL bWow64Process = FALSE; return IsWow64Process(GetCurrentProcess(), &bWow64Process) && bWow64Process;