From 0ed4d10d31e6b8e8545939ced00551502d064f87 Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Wed, 9 Dec 2009 02:52:08 -0500 Subject: [PATCH] initial import --- Ambien.cpp | 132 +++++++ Ambien.h | 48 +++ Ambien.xcodeproj/project.pbxproj | 322 ++++++++++++++++++ English.lproj/InfoPlist.strings | Bin 0 -> 484 bytes Info.plist | 43 +++ Installer Package.pmdoc/01ambien-contents.xml | 1 + Installer Package.pmdoc/01ambien.xml | 1 + Installer Package.pmdoc/index.xml | 13 + 8 files changed, 560 insertions(+) create mode 100644 Ambien.cpp create mode 100644 Ambien.h create mode 100644 Ambien.xcodeproj/project.pbxproj create mode 100644 English.lproj/InfoPlist.strings create mode 100644 Info.plist create mode 100644 Installer Package.pmdoc/01ambien-contents.xml create mode 100644 Installer Package.pmdoc/01ambien.xml create mode 100644 Installer Package.pmdoc/index.xml diff --git a/Ambien.cpp b/Ambien.cpp new file mode 100644 index 0000000..f6d7710 --- /dev/null +++ b/Ambien.cpp @@ -0,0 +1,132 @@ +/* + File: Ambien.h + Program: Ambien + Original author: Michael Roßberg + mick@binaervarianz.de + Rewritten by: Joshua Wise + jwise@andrew.cmu.edu + Description: Ambien is a kernel extension to disable sleep-on-clamshell. + + Ambien is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Ambien is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Ambien; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "Ambien.h" +#include +#include +#include + +#define super IOService + +OSDefineMetaClassAndStructors(Ambien, IOService); + +bool Ambien::init(OSDictionary* properties) +{ + IOLog("Ambien.kext for Mac OS X Leopard, by Joshua Wise\n"); + + _workLoop = 0; + if (super::init(properties) == false) { + IOLog("Ambien::init: super::init failed\n"); + return false; + } + + return true; +} + +bool Ambien::start(IOService* provider) +{ + static IOPMPowerState states[] = + { + {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0} + }; + + if (!super::start(provider)) { + IOLog("Ambien::start: super::start failed\n"); + return false; + } + + PMinit(); + provider->joinPMtree(this); + if (registerPowerDriver(this, states, 2) != IOPMNoErr) + { + IOLog("Ambien::start: registerPowerDriver returned error -- uh-oh!\n"); + return false; + } + + return true; +} + +void Ambien::stop(IOService* provider) +{ + if (_workLoop) + { + _workLoop->release(); + _workLoop = 0; + } + + PMstop(); + super::stop(provider); + IOLog("Ambien: your sleep schedule is back to you!\n"); +} + +IOReturn Ambien::setPowerState(unsigned long which, IOService *dev) +{ + if (which == 0) + { + IOLog("Ambien::setPowerState: system going to sleep\n"); + } else { + IOLog("Ambien::setPowerState: system is awake\n"); + } + + return kIOPMAckImplied; +} + +void Ambien::free() +{ + super::free(); + return; +} + +IOWorkLoop* Ambien::getWorkLoop() +{ + if (!_workLoop) + _workLoop = IOWorkLoop::workLoop(); + + return _workLoop; +} + +IOReturn Ambien::message(UInt32 type, IOService *provider, void *arg) +{ + unsigned int argi = (unsigned int)arg; + + if (type == kIOPMMessageClamshellStateChange) + { + IOPMrootDomain *root = NULL; + + IOLog("Ambien::message: kIOPMMessageClamshellStateChange: lid is %s, sleep bit is %d (arg %08x)\n", + (argi & kClamshellStateBit) ? "closed" : "open", + !!(argi & kClamshellSleepBit), argi); + + root = getPMRootDomain(); + if (!root) + { + IOLog("Ambien::message: failed to get PM root?\n"); + return 0; + } + root->receivePowerNotification((argi & kClamshellStateBit) ? kIOPMPreventSleep : kIOPMAllowSleep); + } else + IOLog("Ambien::message: unknown type %08x (so I won't worry about it)\n", (unsigned int)type); + return super::message(type, provider, arg); +} diff --git a/Ambien.h b/Ambien.h new file mode 100644 index 0000000..2c83bfd --- /dev/null +++ b/Ambien.h @@ -0,0 +1,48 @@ +/* + File: Ambien.h + Program: Ambien + Original author: Michael Roßberg + mick@binaervarianz.de + Rewritten by: Joshua Wise + jwise@andrew.cmu.edu + Description: Ambien is a kernel extension to disable sleep-on-clamshell. + + Ambien is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Ambien is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Ambien; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include + +class Ambien : public IOService { + OSDeclareDefaultStructors(Ambien); + +public: + // driver startup and shutdown + virtual bool init(OSDictionary * = 0); + virtual bool start(IOService* provider); + virtual void stop(IOService* provider); + virtual void free(); + + virtual IOWorkLoop* getWorkLoop(); + virtual IOReturn message(UInt32 type, IOService *provider, void *arg); + virtual IOReturn setPowerState(unsigned long which, IOService *dev); + +private: + + IOWorkLoop* _workLoop; + IONotifier *notifier; + +}; \ No newline at end of file diff --git a/Ambien.xcodeproj/project.pbxproj b/Ambien.xcodeproj/project.pbxproj new file mode 100644 index 0000000..cbce367 --- /dev/null +++ b/Ambien.xcodeproj/project.pbxproj @@ -0,0 +1,322 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 42; + objects = { + +/* Begin PBXBuildFile section */ + 42E2EB6D1004514E00EC9679 /* Ambien.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A224C3EFF42367911CA2CB7 /* Ambien.h */; }; + 42E2EB6F1004514E00EC9679 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; + 42E2EB711004514E00EC9679 /* Ambien.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */; settings = {ATTRIBUTES = (); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 1A224C3EFF42367911CA2CB7 /* Ambien.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ambien.h; sourceTree = ""; }; + 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ambien.cpp; sourceTree = ""; }; + 423F076210CF8E2B00F3AA10 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 42E2EB7A1004514E00EC9679 /* Ambien.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Ambien.kext; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 42E2EB721004514E00EC9679 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 089C166AFE841209C02AAC07 /* Insomnia */ = { + isa = PBXGroup; + children = ( + 423F076210CF8E2B00F3AA10 /* Info.plist */, + 247142CAFF3F8F9811CA285C /* Source */, + 089C167CFE841241C02AAC07 /* Resources */, + 19C28FB6FE9D52B211CA2CBB /* Products */, + ); + name = Insomnia; + sourceTree = ""; + }; + 089C167CFE841241C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 089C167DFE841241C02AAC07 /* InfoPlist.strings */, + ); + name = Resources; + sourceTree = ""; + }; + 19C28FB6FE9D52B211CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 42E2EB7A1004514E00EC9679 /* Ambien.kext */, + ); + name = Products; + sourceTree = ""; + }; + 247142CAFF3F8F9811CA285C /* Source */ = { + isa = PBXGroup; + children = ( + 1A224C3EFF42367911CA2CB7 /* Ambien.h */, + 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */, + ); + name = Source; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 42E2EB6C1004514E00EC9679 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 42E2EB6D1004514E00EC9679 /* Ambien.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 42E2EB6A1004514E00EC9679 /* Ambien kext */ = { + isa = PBXNativeTarget; + buildConfigurationList = 42E2EB751004514E00EC9679 /* Build configuration list for PBXNativeTarget "Ambien kext" */; + buildPhases = ( + 42E2EB6B1004514E00EC9679 /* ShellScript */, + 42E2EB6C1004514E00EC9679 /* Headers */, + 42E2EB6E1004514E00EC9679 /* Resources */, + 42E2EB701004514E00EC9679 /* Sources */, + 42E2EB721004514E00EC9679 /* Frameworks */, + 42E2EB731004514E00EC9679 /* Rez */, + 42E2EB741004514E00EC9679 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Ambien kext"; + productInstallPath = "$(SYSTEM_LIBRARY_DIR)/Extensions"; + productName = nosleep; + productReference = 42E2EB7A1004514E00EC9679 /* Ambien.kext */; + productType = "com.apple.product-type.kernel-extension.iokit"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 089C1669FE841209C02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 42E2EB58100450B500EC9679 /* Build configuration list for PBXProject "Ambien" */; + compatibilityVersion = "Xcode 2.4"; + hasScannedForEncodings = 1; + mainGroup = 089C166AFE841209C02AAC07 /* Insomnia */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 42E2EB6A1004514E00EC9679 /* Ambien kext */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 42E2EB6E1004514E00EC9679 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 42E2EB6F1004514E00EC9679 /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXRezBuildPhase section */ + 42E2EB731004514E00EC9679 /* Rez */ = { + isa = PBXRezBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXRezBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 42E2EB6B1004514E00EC9679 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPreprocess\";\nif [ -x \"$script\" ]; then\n . \"$script\"\nfi"; + }; + 42E2EB741004514E00EC9679 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPostprocess\";\nif [ -x \"$script\" ]; then\n . \"$script\"\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 42E2EB701004514E00EC9679 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 42E2EB711004514E00EC9679 /* Ambien.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 089C167DFE841241C02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C167EFE841241C02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 42E2EB52100450B500EC9679 /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Development; + }; + 42E2EB53100450B500EC9679 /* Deployment */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Deployment; + }; + 42E2EB54100450B500EC9679 /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Default; + }; + 42E2EB761004514E00EC9679 /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions"; + KERNEL_MODULE = YES; + LIBRARY_SEARCH_PATHS = ""; + MODULE_IOKIT = YES; + MODULE_NAME = com.joshuawise.kexts.Insomnia; + MODULE_VERSION = 1.0.0d1; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + OTHER_REZFLAGS = ""; + PRODUCT_NAME = Ambien; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = kext; + ZERO_LINK = YES; + }; + name = Development; + }; + 42E2EB771004514E00EC9679 /* Deployment */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = YES; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions"; + KERNEL_MODULE = YES; + LIBRARY_SEARCH_PATHS = ""; + MODULE_IOKIT = YES; + MODULE_NAME = org.binaervarianz.driver.insomnia; + MODULE_VERSION = 1.0.0d1; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + OTHER_REZFLAGS = ""; + PRODUCT_NAME = Insomnia; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = kext; + ZERO_LINK = NO; + }; + name = Deployment; + }; + 42E2EB781004514E00EC9679 /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ""; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions"; + KERNEL_MODULE = YES; + LIBRARY_SEARCH_PATHS = ""; + MODULE_IOKIT = YES; + MODULE_NAME = org.binaervarianz.driver.insomnia; + MODULE_VERSION = 1.0.0d1; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + OTHER_REZFLAGS = ""; + PRODUCT_NAME = Insomnia; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = kext; + }; + name = Default; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 42E2EB58100450B500EC9679 /* Build configuration list for PBXProject "Ambien" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 42E2EB52100450B500EC9679 /* Development */, + 42E2EB53100450B500EC9679 /* Deployment */, + 42E2EB54100450B500EC9679 /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; + 42E2EB751004514E00EC9679 /* Build configuration list for PBXNativeTarget "Ambien kext" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 42E2EB761004514E00EC9679 /* Development */, + 42E2EB771004514E00EC9679 /* Deployment */, + 42E2EB781004514E00EC9679 /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; +/* End XCConfigurationList section */ + }; + rootObject = 089C1669FE841209C02AAC07 /* Project object */; +} diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings new file mode 100644 index 0000000000000000000000000000000000000000..5ff46edfb38a0440ad30ed42fd67459bba0ff90f GIT binary patch literal 484 zcmb7=OAoQ6d@?oi*Xs)lEU<7uG2E~rCv zk!JX(R7X8-6+A<4m{mz*h>;ZoRu6t`kJ!#Zk{#8u}r)l9xdY$CPVIXMD$5@= + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + Ambien + CFBundleIconFile + + CFBundleIdentifier + com.joshuawise.kexts.Ambien + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + KEXT + CFBundleSignature + ???? + CFBundleVersion + 0.9.0 + IOKitPersonalities + + Ambien + + CFBundleIdentifier + com.joshuawise.kexts.Ambien + IOClass + Ambien + IOMatchCategory + IODefaultMatchCategory + IONameMatch + IOPMrootDomain + IOProviderClass + IOService + + + OSBundleLibraries + + com.apple.kernel.iokit + 6.0 + + + diff --git a/Installer Package.pmdoc/01ambien-contents.xml b/Installer Package.pmdoc/01ambien-contents.xml new file mode 100644 index 0000000..8ee7a8b --- /dev/null +++ b/Installer Package.pmdoc/01ambien-contents.xml @@ -0,0 +1 @@ +owner \ No newline at end of file diff --git a/Installer Package.pmdoc/01ambien.xml b/Installer Package.pmdoc/01ambien.xml new file mode 100644 index 0000000..29c0707 --- /dev/null +++ b/Installer Package.pmdoc/01ambien.xml @@ -0,0 +1 @@ +com.joshuawise.ambien.ambien.pkg1/Users/joshua/Insomnia/build/Development/Ambien.kext/System/Library/ExtensionsparentrequireAuthorizationpostInstallextraFilesversioninstallToidentifier01ambien-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$ \ No newline at end of file diff --git a/Installer Package.pmdoc/index.xml b/Installer Package.pmdoc/index.xml new file mode 100644 index 0000000..bb8f3e9 --- /dev/null +++ b/Installer Package.pmdoc/index.xml @@ -0,0 +1,13 @@ +Ambien/Users/joshua/Insomnia/Ambien.pkgcom.joshuawiseAmbien is a kernel extension that prevents your MacBook from sleeping when the lid (or in Apple parlance, "clamshell") is closed. You may still sleep the machine by going to the Apple menu and clicking 'sleep' (or however you would normally put the machine to sleep), as long as the lid is open. (If the system is already asleep, closing the lid will not wake it.)/Users/joshua/bg.pngcom.joshuawise.kexts.Ambienabsolute-pathcom.joshuawise.kexts.Ambiencomponent01ambien.xmlpreinstallActions.actionsproperties.systemDomainproperties.anywhereDomainproperties.customizeOptionextraFilesproperties.titledescriptionpostinstallActions.actions \ No newline at end of file -- 2.39.2