Created
March 10, 2018 02:08
-
-
Save avaidyam/18b7c3d0a15afade931d10a27ed53872 to your computer and use it in GitHub Desktop.
The decompiled and cleaned source for RegisterEventHotKey and SCRKeyboardRegisterForHotKeysWithConnection.
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
class HotInputDataUnknown1 { | |
0x4 | |
0x8 | |
0x10 | |
} | |
class HotInputData { | |
UInt32 unknown; // + 0x0 | |
UInt32 modifiers; // + 0x4 | |
UInt32 keyCode; // + 0x8 | |
UInt32 unknown2; // + 0xc | |
} | |
class HotButtonData { // size = 0x20 | |
0x0 | |
0x8 | |
0x10 | |
0x18 | |
} | |
OSStatus RegisterEventHotKey(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, | |
EventTargetRef inTarget, OptionBits inOptions, EventHotKeyRef *outRef) { | |
return RegisterEventHotInput(new HotInputData(0x0, inHotKeyModifiers, inHotKeyCode), inHotKeyID, inTarget, inOptions, outRef); | |
} | |
OSStatus RegisterEventHotInput(HotInputData const *hotInputData, EventHotKeyID inHotKeyID, | |
OpaqueEventTargetRef *inTarget, uint32_t inOptions, OpaqueEventHotKeyRef **outRef) { | |
if ((((inOptions | 0x1) == 0x1) && (inTarget != 0x0)) && (outRef != 0x0)) { | |
CGSHotkeyFlags cgsFlags = EventModifiersToCGSFlags(hotInputData->modifiers); | |
if (*GetHotKeyDict()::sHotKeys == NULL) | |
*GetHotKeyDict()::sHotKeys = CFDictionaryCreateMutable(0x0, 0x0, 0x0, 0x0); | |
CFDictionaryApplyFunction(*GetHotKeyDict()::sHotKeys, IsHotKey(void const*, void const*, void*), hotInputData->unknown); | |
if (hotInputData->unknown->0x10 == 0x0) { | |
HotButtonData *hotButton = new HotButtonData; | |
if (hotButton != NULL) { | |
hotButton->0x0 = hotInputData->unknown; | |
hotButton->0x4 = hotInputData->keyCode; | |
hotButton->0x10 = inHotKeyID; | |
hotButton->0x18 = inTarget; | |
OSStatus result = 0; | |
if (hotInputData->unknown == 0x2) { | |
result = CGSSetHotButtonWithExclusion(CGSMainConnectionID(), hotButton, 0x1, hotInputData->keyCode, | |
0x20, hotInputData->unknown2, 0x20, cgsFlags, inOptions & 0x1); | |
} else { | |
if (hotInputData->unknown != 0x0) { | |
rax = 0xffff; | |
rcx = hotInputData->unknown == 0x1 ? hotInputData->keyCode & 0xffff : 0xffff; | |
} else { | |
rax = hotInputData->keyCode & 0xffff; | |
rcx = 0xffff; | |
} | |
result = CGSSetHotKeyWithExclusion(CGSMainConnectionID(), hotButton, rdx, rcx, _, inOptions & 0x1); | |
} | |
if (result != 0x0) { | |
delete hotButton; | |
if (result == 0x3f3) | |
return eventHotKeyExistsErr; | |
else return eventInternalErr; | |
} else { | |
if (*GetHotKeyDict()::sHotKeys == NULL) | |
*GetHotKeyDict()::sHotKeys = CFDictionaryCreateMutable(0x0, 0x0, 0x0, 0x0); | |
CFDictionaryAddValue(*GetHotKeyDict()::sHotKeys, hotButton, hotButton); | |
return noErr; | |
} | |
} else return memFullErr; | |
} else return eventHotKeyExistsErr; | |
} | |
return paramErr; | |
} | |
OSStatus UnregisterEventHotKey(EventHotKeyRef inHotKey) { | |
if (inHotKey != 0x0) { | |
if (*GetHotKeyDict()::sHotKeys == NULL) | |
*GetHotKeyDict()::sHotKeys = CFDictionaryCreateMutable(0x0, 0x0, 0x0, 0x0); | |
if (CFDictionaryGetValue(*GetHotKeyDict()::sHotKeys, inHotKey) != 0x0) { | |
CGSRemoveHotKey(CGSMainConnectionID(), inHotKey); | |
if (*GetHotKeyDict()::sHotKeys == NULL) | |
*GetHotKeyDict()::sHotKeys = CFDictionaryCreateMutable(0x0, 0x0, 0x0, 0x0); | |
CFDictionaryRemoveValue(*GetHotKeyDict()::sHotKeys, inHotKey); | |
free(inHotKey); | |
return noErr; | |
} | |
} | |
rax = r14; | |
return paramErr; | |
} | |
void SCRKeyboardRegisterForHotKeysWithConnection(CGSConnectionID connection) { | |
if (__NumIsEnabled == false) { | |
__NumIsEnabled = true; | |
var_60 = *(int128_t *)0x2adf20; | |
var_50 = *(int128_t *)0x2adf30; | |
var_40 = *(int128_t *)0x2adf40; | |
CGSSetHotKeyWithExclusion(connection, 0x3e8, 0xffff, 0x52, 0x200000, 0x1); | |
CGSSetHotKeyType(connection, 0x3e8, 0x1); | |
for (int i = 0; i != 12; i++) { | |
int mod = i == 1 ? 0 : (i << 4) + i; | |
for (int j = 0; j != 17; j++) { | |
int uid; | |
do { | |
uid = j + mod; | |
if (j == 2) break; | |
CGSSetHotKeyWithExclusion(connection, uid, 0xffff, NULL?, NULL?, 0x1); | |
CGSSetHotKeyType(connection, uid, 0x1); | |
j++; | |
} while (true); | |
CGSSetHotKeyWithExclusion(connection, uid, 0xffff, *(int16_t *)(__SCRNumPadCharTable + j * 0x2) & 0xffff, *(int32_t *)(rbp + i * 0x4 + 0xffffffffffffffa0), true); | |
CGSSetHotKeyType(connection, uid, 0x1); | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment