58
58
* https://trustedcomputinggroup.org/pc-client-platform-tpm-profile-ptp-specification/
59
59
*/
60
60
61
+ #if defined(__APPLE__ )
62
+ #include <Carbon/Carbon.h>
63
+ #endif
64
+
61
65
#include <stdio.h>
62
66
#include <string.h>
63
67
#include <strings.h>
@@ -79,6 +83,7 @@ static const char *bad_index = "<BAD INDEX>";
79
83
80
84
#define FLAG_NO_FILE_OFFSET (1 << 0)
81
85
#define FLAG_STOP_AT_EOT (1 << 1)
86
+ #define FLAG_FROM_API (1 << 2)
82
87
83
88
#define SYS_FIRMWARE_DIR "/sys/firmware/dmi/tables"
84
89
#define SYS_ENTRY_FILE SYS_FIRMWARE_DIR "/smbios_entry_point"
@@ -4727,7 +4732,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
4727
4732
if (num )
4728
4733
printf ("%u structures occupying %u bytes.\n" ,
4729
4734
num , len );
4730
- if (!(opt .flags & FLAG_FROM_DUMP ))
4735
+ if (!(flags & FLAG_FROM_API ) && !( opt .flags & FLAG_FROM_DUMP ))
4731
4736
printf ("Table at 0x%08llX.\n" ,
4732
4737
(unsigned long long )base );
4733
4738
}
@@ -4758,6 +4763,61 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
4758
4763
else
4759
4764
buf = mem_chunk (base , len , devmem );
4760
4765
4766
+ #ifdef __APPLE__
4767
+ // read tables returned by API call
4768
+ if (flags & FLAG_FROM_API )
4769
+ {
4770
+ mach_port_t masterPort ;
4771
+ CFMutableDictionaryRef properties = NULL ;
4772
+ io_service_t service = MACH_PORT_NULL ;
4773
+ CFDataRef dataRef ;
4774
+
4775
+ IOMasterPort (MACH_PORT_NULL , & masterPort );
4776
+ service = IOServiceGetMatchingService (masterPort ,
4777
+ IOServiceMatching ("AppleSMBIOS" ));
4778
+ if (service == MACH_PORT_NULL )
4779
+ {
4780
+ fprintf (stderr , "AppleSMBIOS service is unreachable, sorry.\n" );
4781
+ return ;
4782
+ }
4783
+
4784
+ if (kIOReturnSuccess != IORegistryEntryCreateCFProperties (service ,
4785
+ & properties , kCFAllocatorDefault , kNilOptions ))
4786
+ {
4787
+ fprintf (stderr , "No data in AppleSMBIOS IOService, sorry.\n" );
4788
+ return ;
4789
+ }
4790
+
4791
+ if (!CFDictionaryGetValueIfPresent (properties , CFSTR ( "SMBIOS" ),
4792
+ (const void * * )& dataRef ))
4793
+ {
4794
+ fprintf (stderr , "SMBIOS property data is unreachable, sorry.\n" );
4795
+ return ;
4796
+ }
4797
+
4798
+ len = CFDataGetLength (dataRef );
4799
+ if ((buf = malloc (sizeof (u8 ) * len )) == NULL )
4800
+ {
4801
+ perror ("malloc" );
4802
+ return ;
4803
+ }
4804
+
4805
+ CFDataGetBytes (dataRef , CFRangeMake (0 , len ), (UInt8 * )buf );
4806
+
4807
+ if (NULL != dataRef )
4808
+ CFRelease (dataRef );
4809
+
4810
+ /*
4811
+ * This CFRelease throws 'Segmentation fault: 11' since macOS 10.12, if
4812
+ * the compiled binary is not signed with an Apple developer profile.
4813
+ */
4814
+ if (NULL != properties )
4815
+ CFRelease (properties );
4816
+
4817
+ IOObjectRelease (service );
4818
+ }
4819
+ #endif // __APPLE__
4820
+
4761
4821
if (buf == NULL )
4762
4822
{
4763
4823
fprintf (stderr , "Failed to read table, sorry.\n" );
@@ -5052,6 +5112,55 @@ int main(int argc, char * const argv[])
5052
5112
goto done ;
5053
5113
}
5054
5114
5115
+ #if defined(__APPLE__ )
5116
+ mach_port_t masterPort ;
5117
+ io_service_t service = MACH_PORT_NULL ;
5118
+ CFDataRef dataRef ;
5119
+
5120
+ if (!(opt .flags & FLAG_QUIET ))
5121
+ printf ("Getting SMBIOS data from Apple SMBIOS service.\n" );
5122
+
5123
+ IOMasterPort (MACH_PORT_NULL , & masterPort );
5124
+ service = IOServiceGetMatchingService (masterPort ,
5125
+ IOServiceMatching ("AppleSMBIOS" ));
5126
+ if (service == MACH_PORT_NULL )
5127
+ {
5128
+ fprintf (stderr , "AppleSMBIOS service is unreachable, sorry." );
5129
+ ret = 1 ;
5130
+ goto exit_free ;
5131
+ }
5132
+
5133
+ dataRef = (CFDataRef ) IORegistryEntryCreateCFProperty (service ,
5134
+ CFSTR ("SMBIOS-EPS" ), kCFAllocatorDefault , kNilOptions );
5135
+
5136
+ if (dataRef == NULL )
5137
+ {
5138
+ fprintf (stderr , "SMBIOS entry point is unreachable, sorry.\n" );
5139
+ ret = 1 ;
5140
+ goto exit_free ;
5141
+ }
5142
+
5143
+ if ((buf = malloc (0x20 )) == NULL )
5144
+ {
5145
+ perror ("malloc" );
5146
+ ret = 1 ;
5147
+ goto exit_free ;
5148
+ }
5149
+
5150
+ CFDataGetBytes (dataRef , CFRangeMake (0 , 0x20 ), (UInt8 * )buf );
5151
+
5152
+ if (NULL != dataRef )
5153
+ CFRelease (dataRef );
5154
+ IOObjectRelease (service );
5155
+
5156
+ if (smbios_decode (buf , NULL , FLAG_FROM_API ))
5157
+ {
5158
+ found ++ ;
5159
+ goto done ;
5160
+ }
5161
+
5162
+ #endif // __APPLE__
5163
+
5055
5164
/*
5056
5165
* First try reading from sysfs tables. The entry point file could
5057
5166
* contain one of several types of entry points, so read enough for
0 commit comments