osquery-1/osquery/tables/system/darwin/acpi_tables.cpp

68 lines
1.6 KiB
C++
Raw Normal View History

2015-01-16 05:37:02 +00:00
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
2015-05-12 06:31:13 +00:00
* LICENSE file in the root directory of this source tree. An additional grant
2015-01-16 05:37:02 +00:00
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
2015-01-20 22:52:07 +00:00
#include <osquery/hash.h>
2015-01-16 05:37:02 +00:00
#include <osquery/tables.h>
#include "osquery/core/conversions.h"
namespace osquery {
namespace tables {
#define kIOACPIClassName_ "AppleACPIPlatformExpert"
2015-01-19 00:20:50 +00:00
#define kIOACPIPropertyName_ "ACPI Tables"
2015-01-16 05:37:02 +00:00
void genACPITable(const void *key, const void *value, void *results) {
Row r;
r["name"] = stringFromCFString((CFStringRef)key);
auto data = (CFDataRef)value;
auto length = CFDataGetLength(data);
2015-01-18 21:01:20 +00:00
r["size"] = INTEGER(length);
2015-01-20 22:52:07 +00:00
r["md5"] =
osquery::hashFromBuffer(HASH_TYPE_MD5, CFDataGetBytePtr(data), length);
2015-01-16 05:37:02 +00:00
((QueryData *)results)->push_back(r);
}
QueryData genACPITables(QueryContext& context) {
QueryData results;
auto matching = IOServiceMatching(kIOACPIClassName_);
if (matching == nullptr) {
// No ACPI platform expert service found.
return {};
}
auto service = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
if (service == 0) {
return {};
}
2015-01-19 00:20:50 +00:00
CFTypeRef table = IORegistryEntryCreateCFProperty(
service, CFSTR(kIOACPIPropertyName_), kCFAllocatorDefault, 0);
2015-01-16 05:37:02 +00:00
if (table == nullptr) {
2015-01-19 00:20:50 +00:00
IOObjectRelease(service);
2015-01-16 05:37:02 +00:00
return {};
}
CFDictionaryApplyFunction((CFDictionaryRef)table, genACPITable, &results);
2015-01-19 00:20:50 +00:00
CFRelease(table);
2015-01-16 05:37:02 +00:00
IOObjectRelease(service);
return results;
}
}
}