Skip to content

Commit

Permalink
Changed back authentication for smc binary to checkSum method (codesi…
Browse files Browse the repository at this point in the history
…gn check was causing issues on some mac)

Reset-Feature to reset fans back to factory defaults, delete settings and favorites
  • Loading branch information
hholtmann committed Oct 30, 2014
1 parent 62059ed commit c78366c
Show file tree
Hide file tree
Showing 18 changed files with 1,036 additions and 78 deletions.
1 change: 1 addition & 0 deletions Classes/FanControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
- (IBAction)closePreferences:(id)sender;
- (IBAction)savePreferences:(id)sender;
- (IBAction)updateCheck:(id)sender;
- (IBAction)resetSettings:(id)sender;

- (void)init_statusitem;

Expand Down
40 changes: 40 additions & 0 deletions Classes/FanControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,46 @@ - (IBAction)updateCheck:(id)sender{
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}


-(void)performReset
{
NSFileManager *fileManager = [NSFileManager defaultManager];

NSError *error;
NSString *machinesPath = [[fileManager applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"];
[fileManager removeItemAtPath:machinesPath error:&error];
if (error) {
NSLog(@"Error deleting %@",machinesPath);
}
error = nil;

NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:domainName];


NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Shutdown required",nil)
defaultButton:NSLocalizedString(@"OK",nil) alternateButton:nil otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"Please shutdown your computer now to return to default fan settings.",nil)];
NSModalResponse code=[alert runModal];
if (code == NSAlertDefaultReturn) {
[[NSApplication sharedApplication] terminate:self];
}
}

- (IBAction)resetSettings:(id)sender
{
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Reset Settings",nil)
defaultButton:NSLocalizedString(@"Yes",nil) alternateButton:NSLocalizedString(@"No",nil) otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"Do you want to reset smcFanControl to default settings? Favorites will be deleted and fans will return to default speed.",nil)];
NSModalResponse code=[alert runModal];
if (code == NSAlertDefaultReturn) {
[self performReset];
} else if (code == NSAlertAlternateReturn) {

}

}

- (IBAction)visitHomepage:(id)sender{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.eidac.de/products"]];
}
Expand Down
70 changes: 43 additions & 27 deletions Classes/smcWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#import "smcWrapper.h"
#import <CommonCrypto/CommonDigest.h>

NSString * const smc_checksum=@"4c9919172e1111c660f12015a7324767";

NSArray *allSensors;

Expand All @@ -37,34 +37,40 @@ +(void)cleanUp{
SMCClose(conn);
}


+(float)readTempSensors
{
float retValue;
SMCVal_t val;
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:@"TSensor"];
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
for (NSString *sensor in allSensors) {
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
if (retValue>0 && floor(retValue) != 129 ) {
[[NSUserDefaults standardUserDefaults] setObject:sensor forKey:@"TSensor"];
[[NSUserDefaults standardUserDefaults] synchronize];
break;
}
}
}
return retValue;
}

+(float) get_maintemp{
float retValue;
NSRange range_pro=[[MachineDefaults computerModel] rangeOfString:@"MacPro"];
if (range_pro.length > 0) {
retValue = [smcWrapper get_mptemp];
} else {

SMCVal_t val;
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:@"TSensor"];
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
for (NSString *sensor in allSensors) {
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
if (retValue>0 && floor(retValue) != 129 ) {
[[NSUserDefaults standardUserDefaults] setObject:sensor forKey:@"TSensor"];
[[NSUserDefaults standardUserDefaults] synchronize];
break;
}
}
if (retValue<=0 || floor(retValue) == 129 ) {
retValue = [smcWrapper readTempSensors];
}
} else {
retValue = [smcWrapper readTempSensors];
}

return retValue;
return retValue;
}


Expand Down Expand Up @@ -187,17 +193,27 @@ + (BOOL)validateSMC:(NSString*)path
return true;
}

+ (NSString*)createCheckSum:(NSString*)path {
NSData *d=[NSData dataWithContentsOfMappedFile:path];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5((void *)[d bytes], [d length], result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}

//call smc binary with setuid rights and apply
// The smc binary is given root permissions in FanControl.m with the setRights method.
+(void)setKey_external:(NSString *)key value:(NSString *)value{
NSString *launchPath = [[NSBundle mainBundle] pathForResource:@"smc" ofType:@""];

//first check if it's the right binary (security)
// MW: Disabled smc binary checksum. This should be re-enabled in an official release.
if (![smcWrapper validateSMC:launchPath]) {
NSLog(@"smcFanControl: Security Error: smc-binary is not the distributed one");
return;
}
NSString *checksum=[smcWrapper createCheckSum:launchPath];
if (![checksum isEqualToString:smc_checksum]) {
NSLog(@"smcFanControl: Security Error: smc-binary is not the distributed one");
return;
}
NSArray *argsArray = @[@"-k",key,@"-w",value];
NSTask *task;
task = [[NSTask alloc] init];
Expand Down
6 changes: 3 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>smcFanControl</string>
<key>CFBundleGetInfoString</key>
<string>smcFanControl 2.5, Hendrik Holtmann (GPL)</string>
<string>smcFanControl 2.5.2, Hendrik Holtmann (GPL)</string>
<key>CFBundleIconFile</key>
<string>smcfancontrol_v2</string>
<key>CFBundleIdentifier</key>
Expand All @@ -19,11 +19,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.5.1</string>
<string>2.5.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.5.1</string>
<string>2.5.2</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
Expand Down
10 changes: 9 additions & 1 deletion Ressources/Dutch.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@

"Donate over Paypal" = "Donate over Paypal";

"smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated." = "smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated.";
"smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated." = "smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated.";

"Do you want to reset smcFanControl to default settings? Favorites will be deleted and fans will return to default speed." = "Do you want to reset smcFanControl to default settings?\nFavorites will be deleted and fans will return to default speed.";

"Please shutdown your computer now to return to default fan settings." = "Please shutdown your computer now to return to default fan settings.";

"Reset Settings" = "Reset Settings";

"Shutdown required" = "Shutdown required";
Loading

0 comments on commit c78366c

Please sign in to comment.