Skip to content

Commit

Permalink
CoreOffset utility to generate SMCProcessor's CoreOffset plist sectio…
Browse files Browse the repository at this point in the history
…n from SMC dumps
  • Loading branch information
Michael Belyaev committed Nov 30, 2018
1 parent 0d93946 commit d4fabfb
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sensors/SMCBatteryManager/BatteryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool BatteryManager::probe() {
dict->release();

if (!acpi) {
SYSLOG("alsd", "failed to wait for acpi");
SYSLOG("bmgr", "failed to wait for acpi");
return false;
}

Expand Down
108 changes: 108 additions & 0 deletions Tools/CoreOffset/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// main.swift
// CoreOffset
//
// Created by гык-sse2 on 29/11/2018.
// Copyright © 2018 vit9696. All rights reserved.
//

import Foundation

var dict = [String : Any]()
var models = [String : String]()

let DocsDir = URL(fileURLWithPath: CommandLine.arguments[1], isDirectory: true)

let SMCDumpsDir = DocsDir.appendingPathComponent("SMCDumps", isDirectory: true)

for name in try! FileManager.default.contentsOfDirectory(atPath: SMCDumpsDir.path){
let content = try! String.init(contentsOfFile: SMCDumpsDir.appendingPathComponent(name).path)
let model = (name as NSString).deletingPathExtension

if content.contains("TC0C") || content.contains("TC0c") {
dict[model] = 0
}
else if content.contains("TC1C") || content.contains("TC1c") {
dict[model] = 1
}
else {
dict[model] = "No core temperature"
}
}

let MacModels = DocsDir.appendingPathComponent("MacModels.txt")
let models_txt = try! String.init(contentsOfFile: MacModels.path)
for line in models_txt.split(separator: "\n") {
let words = line.split(separator: " ")
if words.count >= 2 {
models[String(words[0])] = String(words[1])
}
}


let SMCDatabaseDir = DocsDir.appendingPathComponent("SMCDatabase", isDirectory: true)

for boardID in try! FileManager.default.contentsOfDirectory(atPath: SMCDatabaseDir.path) {
let content = try! String.init(contentsOfFile: SMCDatabaseDir.appendingPathComponent(boardID, isDirectory: true).appendingPathComponent("main.txt").path)
let bid = (boardID as NSString).deletingPathExtension
let model = models[bid] ?? bid
if content.contains("TC0C") || content.contains("TC0c") {
dict[model] = 0
}
else if content.contains("TC1C") || content.contains("TC1c") {
dict[model] = 1
}
else {
dict[model] = "No core temperature"
}
}


let iStat = DocsDir.appendingPathComponent("iStat.txt")
let iStatContent = try! String.init(contentsOfFile: iStat.path)
var model = ""
var has0 = false
var has1 = false

for line in iStatContent.split(separator: "\n") {
if line.starts(with: "Dumping ") {
if model != "" {
if has0 {
dict[model] = 0
}
else if (has1) {
dict[model] = 1
}
else {
dict[model] = "No core temperature"
}
}
model = String(line.split(separator: " ")[1])
has0 = false
has1 = false
}
else if line.contains("TC0C") || line.contains("TC0c") {
has0 = true
}
else if line.contains("TC1C") || line.contains("TC1c") {
has1 = true
}
}


if model != "" {
if has0 {
dict[model] = 0
}
else if (has1) {
dict[model] = 1
}
else {
dict[model] = "No core temperature"
}
}



let plist = try PropertyListSerialization.data(fromPropertyList: dict, format: PropertyListSerialization.PropertyListFormat.xml, options: 0)
print(String.init(data: plist, encoding: String.Encoding.utf8)!)
146 changes: 146 additions & 0 deletions VirtualSMC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
35262A2020D42D9A00109064 /* SMCLightSensor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35262A1F20D42D9A00109064 /* SMCLightSensor.cpp */; };
352D134320D1AC7000DAFCCD /* SMCSMBusController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 352D133F20D18CEB00DAFCCD /* SMCSMBusController.cpp */; };
352D134420D1AC7400DAFCCD /* SMCSMBusController.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 352D134020D18CEB00DAFCCD /* SMCSMBusController.hpp */; };
35A795E521B0597F005F2F6C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35A795E421B0597F005F2F6C /* main.swift */; };
35A7B40D20CC337F00DAF347 /* SMCBatteryManager.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 35A7B40C20CC337F00DAF347 /* SMCBatteryManager.hpp */; };
35A7B40F20CC337F00DAF347 /* SMCBatteryManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35A7B40E20CC337F00DAF347 /* SMCBatteryManager.cpp */; };
35AB9A6120ECC51F001FBD53 /* ACPIBattery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35AB9A5F20ECC51F001FBD53 /* ACPIBattery.cpp */; };
Expand Down Expand Up @@ -186,6 +187,15 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
35A795E021B0597F005F2F6C /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
CE09E8BD1FFD20DB0010A9CA /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -231,6 +241,8 @@
352D133F20D18CEB00DAFCCD /* SMCSMBusController.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SMCSMBusController.cpp; sourceTree = "<group>"; };
352D134020D18CEB00DAFCCD /* SMCSMBusController.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SMCSMBusController.hpp; sourceTree = "<group>"; };
352D134520D2E39C00DAFCCD /* IOSMBusController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOSMBusController.h; sourceTree = "<group>"; };
35A795E221B0597F005F2F6C /* CoreOffset */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CoreOffset; sourceTree = BUILT_PRODUCTS_DIR; };
35A795E421B0597F005F2F6C /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
35A7B40A20CC337F00DAF347 /* SMCBatteryManager.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SMCBatteryManager.kext; sourceTree = BUILT_PRODUCTS_DIR; };
35A7B40C20CC337F00DAF347 /* SMCBatteryManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SMCBatteryManager.hpp; sourceTree = "<group>"; };
35A7B40E20CC337F00DAF347 /* SMCBatteryManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SMCBatteryManager.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -375,6 +387,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
35A795DF21B0597F005F2F6C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
35A7B40720CC337F00DAF347 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -460,6 +479,7 @@
35262A1B20D42D9A00109064 /* SMCLightSensor.kext */,
CEA5AAB72129AF3A0001F426 /* libaistat.dylib */,
ABA30FDA21336FFB00256A25 /* SMCSuperIO.kext */,
35A795E221B0597F005F2F6C /* CoreOffset */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -532,6 +552,14 @@
path = SMCLightSensor;
sourceTree = "<group>";
};
35A795E321B0597F005F2F6C /* CoreOffset */ = {
isa = PBXGroup;
children = (
35A795E421B0597F005F2F6C /* main.swift */,
);
path = CoreOffset;
sourceTree = "<group>";
};
35A7B40B20CC337F00DAF347 /* SMCBatteryManager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -752,6 +780,7 @@
CEA5F65720B991BD008E6E8A /* Tools */ = {
isa = PBXGroup;
children = (
35A795E321B0597F005F2F6C /* CoreOffset */,
CE335ADB2096738A00C60A5F /* rtcread */,
CE3BD6921F48BE1900A03466 /* smcread */,
CEC803941FFD206E008544A7 /* smc-fuzzer */,
Expand Down Expand Up @@ -933,6 +962,23 @@
productReference = 35262A1B20D42D9A00109064 /* SMCLightSensor.kext */;
productType = "com.apple.product-type.kernel-extension";
};
35A795E121B0597F005F2F6C /* CoreOffset */ = {
isa = PBXNativeTarget;
buildConfigurationList = 35A795E921B0597F005F2F6C /* Build configuration list for PBXNativeTarget "CoreOffset" */;
buildPhases = (
35A795DE21B0597F005F2F6C /* Sources */,
35A795DF21B0597F005F2F6C /* Frameworks */,
35A795E021B0597F005F2F6C /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = CoreOffset;
productName = CoreOffset;
productReference = 35A795E221B0597F005F2F6C /* CoreOffset */;
productType = "com.apple.product-type.tool";
};
35A7B40920CC337F00DAF347 /* SMCBatteryManager */ = {
isa = PBXNativeTarget;
buildConfigurationList = 35A7B41320CC337F00DAF347 /* Build configuration list for PBXNativeTarget "SMCBatteryManager" */;
Expand Down Expand Up @@ -1061,6 +1107,7 @@
1C748C1E1C21952C0024EED2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1010;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = vit9696;
TargetAttributes = {
Expand All @@ -1072,6 +1119,10 @@
DevelopmentTeam = P5ZFLGLAFT;
ProvisioningStyle = Automatic;
};
35A795E121B0597F005F2F6C = {
CreatedOnToolsVersion = 10.1;
ProvisioningStyle = Automatic;
};
35A7B40920CC337F00DAF347 = {
CreatedOnToolsVersion = 10.0;
DevelopmentTeam = P5ZFLGLAFT;
Expand Down Expand Up @@ -1129,6 +1180,7 @@
CE09E8BE1FFD20DB0010A9CA /* smc-fuzzer */,
CE335AD92096738A00C60A5F /* rtcread */,
CEA5AAB62129AF3A0001F426 /* aistat */,
35A795E121B0597F005F2F6C /* CoreOffset */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -1197,6 +1249,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
35A795DE21B0597F005F2F6C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
35A795E521B0597F005F2F6C /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
35A7B40620CC337F00DAF347 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1639,6 +1699,82 @@
};
name = Release;
};
35A795E621B0597F005F2F6C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
35A795E721B0597F005F2F6C /* Sanitize */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
};
name = Sanitize;
};
35A795E821B0597F005F2F6C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
};
name = Release;
};
35A7B41120CC337F00DAF347 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -2733,6 +2869,16 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
35A795E921B0597F005F2F6C /* Build configuration list for PBXNativeTarget "CoreOffset" */ = {
isa = XCConfigurationList;
buildConfigurations = (
35A795E621B0597F005F2F6C /* Debug */,
35A795E721B0597F005F2F6C /* Sanitize */,
35A795E821B0597F005F2F6C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
35A7B41320CC337F00DAF347 /* Build configuration list for PBXNativeTarget "SMCBatteryManager" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down

0 comments on commit d4fabfb

Please sign in to comment.