Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/SmbiosExtractor.mm

  • Property svn:executable set to *
1//
2// SmbiosExtractor.mm
3// ChameleonPrefPane
4//
5// Created by Rekursor on 11-11-27.
6//
7
8#import "SmbiosExtractor.h"
9#include "ShellProcess.h"
10#include "string_util.h"
11#include "smbios.h"
12
13@implementation SmbiosExtractor
14
15@synthesize smString;
16@synthesize bufSize;
17-(id) init
18{
19self = [super init];
20if (self!=nil)
21{
22buffer = nil;
23bufSize=0;
24[ self extractSmBios];
25}
26
27return self;
28}
29
30-(void) cleanup
31{
32if (buffer!=nil)
33{
34delete [] buffer;
35buffer = nil;
36bufSize=0;
37smString = nil;
38}
39
40if (smString!=nil)
41{
42[smString release];
43smString = nil;
44}
45
46}
47
48-(void) dealloc
49{
50[self cleanup ];
51[super dealloc];
52}
53
54-(NSString*) description
55{
56return smString;
57}
58
59-(NSUInteger) extractSmBios
60{
61
62const char* SmbiosCmd = "ioreg -lw0 | grep \"\\\"SMBIOS\\\" = <\"";
63const char* SmbiosTag = "\"SMBIOS\" = <";
64ShellProcess p(SmbiosCmd);
65char line[8192]="";
66const size_t tagLen= strlen(SmbiosTag);
67
68if (p.get_line(line, sizeof(line)) )
69{
70const char * p = strstr(line, SmbiosTag)+ tagLen;
71std::string s = trim(p, " \t\r\n>");
72NSLog(@"Found SMBIOS (%d) [%s]", s.length(), s.c_str() );
73[self cleanup];
74self.smString = [NSString stringWithUTF8String:s.c_str()];
75bufSize = s.length()/2;
76buffer = new UInt8[bufSize];
77for(size_t pos =0; pos < bufSize; pos++)
78{
79buffer[pos] = (HexToDec(s[pos*2])*16 + HexToDec(s[pos*2+1]));
80}
81
82decodeSMBIOSTable(buffer, buffer+bufSize);
83}
84return 0;
85}
86
87-(NSString*) stringFrom:(NSUInteger) start withLen:(NSUInteger) len
88{
89return [smString substringWithRange: NSMakeRange(start*2, len) ];
90}
91
92-(UInt8) ByteFrom:(NSUInteger) position
93{
94return position < bufSize ? buffer[position]: 0;
95}
96
97@end
98

Archive Download this file

Revision: 378