Last active
December 2, 2015 16:46
-
-
Save Noitidart/ff19ae88500a649c1ef9 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-CF_QueryWorkspaceLockedInterval - Every one second it checks if workstaiton is locked. It looks like as soon as screensaver turns on, even if the require password delay is not "immedietly" the CGSSessionScreenIsLocked property is 1/true.(Mac OS X) (jsctypes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof myint == 'undefined') { | |
var myint = null; | |
} | |
function doit(){ | |
if (myint === null) { | |
myint = setInterval(function() { | |
Cu.import('resource://gre/modules/ctypes.jsm'); | |
var lib = { | |
CoreGraphics: '/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics', | |
CoreFoundation: '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation' | |
}; | |
for (var l in lib) { | |
lib[l] = ctypes.open(lib[l]); | |
} | |
//start mactypes | |
var Boolean = ctypes.unsigned_char; | |
var UniChar = ctypes.jschar; // uint16 with automatic conversion | |
//end mactypes | |
//start CoreFoundationTypes | |
var __CFBoolean = new ctypes.StructType('__CFBoolean'); | |
var CFBooleanRef = __CFBoolean.ptr; | |
var CFTypeRef = ctypes.void_t.ptr; | |
var __CFString = new ctypes.StructType('__CFString'); | |
var CFStringRef = __CFString.ptr; | |
var CFIndex = ctypes.long; | |
var __CFAllocator = new ctypes.StructType('__CFAllocator'); | |
var CFAllocatorRef = __CFAllocator.ptr; | |
//end CoreFoundationTypes | |
//dictionary functionality | |
var __CFDictionary = new ctypes.StructType('__CFDictionary'); | |
var CFDictionaryRef = __CFDictionary.ptr; | |
var CFDictionaryGetValue = lib.CoreFoundation.declare('CFDictionaryGetValue', ctypes.default_abi, ctypes.void_t.ptr/*returns CFTypeRef*/, CFDictionaryRef, ctypes.void_t.ptr/*CFStringRef*/); | |
//end dictionary functionality | |
//string functionality | |
var CFStringCreateWithCharacters = lib.CoreFoundation.declare('CFStringCreateWithCharacters', ctypes.default_abi, CFStringRef, CFAllocatorRef, UniChar.ptr, CFIndex); | |
//end string functionality | |
var CFBooleanGetValue = lib.CoreFoundation.declare('CFBooleanGetValue', ctypes.default_abi, Boolean, CFBooleanRef); | |
//common declares | |
var CFRelease = lib.CoreFoundation.declare('CFRelease', ctypes.default_abi, ctypes.void_t, CFTypeRef); | |
function makeCFStr(input) { //input is just a js string so like `var input = 'blah';` | |
return CFStringCreateWithCharacters(null, input, input.length); | |
} | |
//end common declares | |
var CGSessionCopyCurrentDictionary = lib.CoreGraphics.declare('CGSessionCopyCurrentDictionary', ctypes.default_abi, CFDictionaryRef); | |
var CGSessionDict = CGSessionCopyCurrentDictionary(); | |
//console.log(uneval(CGSessionDict)); | |
if (CGSessionDict.isNull()) { | |
console.error('CGSessionDict is null'); | |
} else { | |
var kCGSSessionOnConsoleKey_str = 'CGSSessionScreenIsLocked'; | |
var kCGSSessionOnConsoleKey = CFStringCreateWithCharacters(null, kCGSSessionOnConsoleKey_str, kCGSSessionOnConsoleKey_str.length); //works // i figured it should be a string because of: https://github.com/JuliaEichler/Mac_OSX_SDKs/blob/392649d7112884481a94b8cd1f601f3a5edae999/MacOSX10.6.sdk/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Headers/CGSession.h#L38 here they are making CFSTR of a text string | |
var kCGSSessionOnConsoleKey_val = CFDictionaryGetValue(CGSessionDict, kCGSSessionOnConsoleKey); | |
//console.log('kCGSSessionOnConsoleKey_val:', kCGSSessionOnConsoleKey_val, uneval(kCGSSessionOnConsoleKey_val)); //printing `"kCGSSessionOnConsoleKey_val:" CData { } "ctypes.voidptr_t(ctypes.UInt64("0x7fff7a13b7f0"))"` | |
if (kCGSSessionOnConsoleKey_val.isNull()) { | |
console.log('CFDictionaryGetValue isNull so the key is not present in the dictionary, I am guesing'); | |
} else { | |
var kCGSSessionOnConsoleKey_val_casted = ctypes.cast(kCGSSessionOnConsoleKey_val, CFBooleanRef); //we know its a boolean so cast it | |
//console.log('kCGSSessionOnConsoleKey_val_casted:', uneval(kCGSSessionOnConsoleKey_val_casted)); | |
var kCGSSessionOnConsoleKey_val_casted_valInDict = CFBooleanGetValue(kCGSSessionOnConsoleKey_val_casted); | |
console.log('kCGSSessionOnConsoleKey_val_casted_valInDict:', kCGSSessionOnConsoleKey_val_casted_valInDict); | |
} | |
CFRelease(kCGSSessionOnConsoleKey); //do release on things made with CFStringCreateWithCharacters per https://github.com/philikon/osxtypes/blob/master/examples/content/iphoto.js#L89 | |
CFRelease(CGSessionDict); //apple docs say to release dictionary's | |
} | |
for (var l in lib) { | |
lib[l].close(); | |
} | |
}, 1000); | |
} else { | |
clearInterval(myint); | |
myint = null; | |
} | |
} | |
doit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1
CGSSessionScreenIsLocked
is1
(true)CFDictionaryGetValue
returnsnull
Rev2
CFRelease
ing the dictionarying, this is proper cleanup, otherwise leak i guessRev3
Rev4
myint === undefined
was not working, had to change that totypeof myint == 'undefined'
Rev5
CF_
to name of file and gist meaning its CoreFoundation