/osquery/tables/system/windows/cpu_info.cpp

https://github.com/facebook/osquery · C++ · 65 lines · 51 code · 6 blank · 8 comment · 2 complexity · a352f3a5dce5521e5dd59a42e2bce8cd MD5 · raw file

  1. /**
  2. * Copyright (c) 2014-present, The osquery authors
  3. *
  4. * This source code is licensed as defined by the LICENSE file found in the
  5. * root directory of this source tree.
  6. *
  7. * SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
  8. */
  9. #include <osquery/core/system.h>
  10. #include <osquery/core/tables.h>
  11. #include <osquery/logger/logger.h>
  12. #include <osquery/sql/sql.h>
  13. #include <osquery/utils/conversions/tryto.h>
  14. #include "osquery/core/windows/wmi.h"
  15. namespace osquery {
  16. namespace tables {
  17. QueryData genCpuInfo(QueryContext& context) {
  18. Row r;
  19. QueryData results;
  20. const WmiRequest wmiSystemReq("SELECT * FROM Win32_Processor");
  21. const std::vector<WmiResultItem>& wmiResults = wmiSystemReq.results();
  22. if (wmiResults.empty()) {
  23. LOG(WARNING) << "Error retreiving information from WMI.";
  24. return results;
  25. }
  26. for (const auto& data : wmiResults) {
  27. long number = 0;
  28. data.GetString("DeviceID", r["device_id"]);
  29. data.GetString("SocketDesignation", r["socket_designation"]);
  30. data.GetString("Name", r["model"]);
  31. data.GetString("Manufacturer", r["manufacturer"]);
  32. (data.GetLong("ProcessorType", number))
  33. ? r["processor_type"] = INTEGER(number)
  34. : r["processor_type"] = "-1";
  35. (data.GetLong("Availability", number)) ? r["availability"] = INTEGER(number)
  36. : r["availability"] = "-1";
  37. (data.GetLong("CpuStatus", number)) ? r["cpu_status"] = INTEGER(number)
  38. : r["cpu_status"] = "-1";
  39. (data.GetLong("NumberOfCores", number))
  40. ? r["number_of_cores"] = INTEGER(number)
  41. : r["number_of_cores"] = "-1";
  42. (data.GetLong("NumberOfLogicalProcessors", number))
  43. ? r["logical_processors"] = INTEGER(number)
  44. : r["logical_processors"] = "-1";
  45. (data.GetLong("AddressWidth", number))
  46. ? r["address_width"] = INTEGER(number)
  47. : r["address_width"] = "-1";
  48. (data.GetLong("CurrentClockSpeed", number))
  49. ? r["current_clock_speed"] = INTEGER(number)
  50. : r["current_clock_speed"] = "-1";
  51. (data.GetLong("MaxClockSpeed", number))
  52. ? r["max_clock_speed"] = INTEGER(number)
  53. : r["max_clock_speed"] = "-1";
  54. results.push_back(r);
  55. }
  56. return results;
  57. }
  58. } // namespace tables
  59. } // namespace osquery