Skip to content
This repository was archived by the owner on Apr 25, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example
69 changes: 69 additions & 0 deletions example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include "lib/smbios_parse.h"

void print_smbios_entry(SMBEntryPoint* e);
void print_smbios_data(SMBByte* data, size_t len);

int main(int argc, const char * argv[]) {

CFDataRef dataRef;
io_service_t service = MACH_PORT_NULL;
mach_port_t myMasterPort;

IOMasterPort(MACH_PORT_NULL, &myMasterPort);
service = IOServiceGetMatchingService(myMasterPort, IOServiceMatching("AppleSMBIOS"));
if (!service) {
printf("No \"AppleSMBIOS\" IOService in IORegistry.\n");
return -1;
}


// Retrieve and Parse SMBIOS Entry Point data

dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(service,
CFSTR("SMBIOS-EPS"), kCFAllocatorDefault, kNilOptions);

if (!dataRef) {
printf("Unable to retrieve SMBIOS entry point!\n");
return -1;
} else print_smbios_entry((SMBEntryPoint *) CFDataGetBytePtr(dataRef));


// Retrieve and Parse SMBIOS Data

dataRef = (CFDataRef) IORegistryEntryCreateCFProperty(service,
CFSTR("SMBIOS"), kCFAllocatorDefault, kNilOptions);

if (!dataRef) {
printf("Unable to retrieve SMBIOS data!\n");
return -1;
} else print_smbios_data((SMBByte*) CFDataGetBytePtr(dataRef), (size_t)CFDataGetLength(dataRef));

return 0;
}

void print_smbios_entry(struct SMBEntryPoint* e){
printf("Address of SMBIOS Entry Point: %p.\n", e);
printf("Version information:\n");
printf("\t- Major Version: %d\n", e->majorVersion);
printf("\t- Minor Version: %d\n", e->minorVersion);
printf("\t- Entry Point Length: %d\n", e->entryPointLength);
printf("\t- Max Structure Size: %d\n\n", e->maxStructureSize);
}

void print_smbios_data(SMBByte* data, size_t len){
printf("Address of SMBIOS Data: %p.\n", data);

smbios_parse(data, len);

// Although, always check any returned pointers - don't assume they're GOOD
SMBValue *val = smbios_search(kSMBTypeProcessorInformation);
if (val != NULL) {
SMBProcessorInformation *procInfo = (SMBProcessorInformation *)val->structure;
printf("Socket Description: %hhu\n", procInfo->socketDesignation);
}

// Clear up and free that mem.
smbios_destroy();
}
Loading