Last active
August 29, 2015 14:11
-
-
Save bsmt/dda10ef7b210ec4dba0e to your computer and use it in GitHub Desktop.
Dirty hack to enable using skype as a shell with something like "/echo testing"
This file contains hidden or 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
//sudo cycript -p Skype | |
@import com.saurik.substrate.MS | |
var get = function(name) | |
{ | |
func_ = dlsym(RTLD_DEFAULT, name) | |
func = function() { var types = 'v', args = [], count = arguments.length; for (var i = 0; i != count; ++i) { types += '@'; args.push(arguments[i]); } new Functor(func_, types).apply(null, args); }; | |
return func | |
} | |
NSLog = get("NSLog"); | |
var send_message = function(msg) | |
{ | |
var delegate = choose(ChatInputTextView)[0].delegate; | |
delegate.inputText = msg; | |
[delegate postInputText]; | |
} | |
var path_for_command = function(cmd) // blocks | |
{ | |
var task = [[NSTask alloc] init]; | |
var pipe = [NSPipe pipe]; | |
[task setLaunchPath:@"/usr/bin/which"]; | |
[task setArguments:@[cmd]]; | |
[task setStandardOutput:pipe]; | |
[task launch]; | |
[task waitUntilExit]; | |
[task release]; | |
var ret = [[NSString alloc] initWithData:[[pipe fileHandleForReading] readDataToEndOfFile] encoding:4]; | |
return [ret stringByReplacingOccurrencesOfString:@"\n" withString:@""]; | |
} | |
var run_command = function(cmd) // blocks | |
{ | |
cmd = [cmd componentsSeparatedByString:@" "]; | |
var run = path_for_command(cmd[0]); | |
if (![[NSFileManager defaultManager] isExecutableFileAtPath:run]) | |
{ | |
return false; | |
} | |
var args = [cmd mutableCopy]; | |
[args removeObjectAtIndex:0]; | |
var out = [NSPipe pipe]; | |
var task = [[NSTask alloc] init]; | |
[task setLaunchPath:run]; | |
[task setArguments:args]; | |
[task setStandardOutput:out]; | |
[task launch]; | |
[task waitUntilExit]; | |
[task release]; | |
return [[NSString alloc] initWithData:[[out fileHandleForReading] readDataToEndOfFile] encoding:4]; | |
} | |
var hookPostInputText = function() | |
{ | |
var oldm = {}; | |
NSLog(@"Hooking [PanAmericanChatInputViewController postInputText]"); | |
MS.hookMessage(PanAmericanChatInputViewController, @selector(postInputText), function() { | |
var delegate = choose(ChatInputTextView)[0].delegate; | |
var msg = delegate.inputText; | |
if ([msg hasPrefix:@"/"]) | |
{ | |
msg = [msg substringFromIndex:1]; | |
if (!([msg hasPrefix:@"me"] || [msg hasPrefix:@"add"] || [msg hasPrefix:@"alertson"] || [msg hasPrefix:@"alertsoff"] || [msg hasPrefix:@"help"])) | |
{ | |
NSLog(@"Received a command: %@", msg); | |
var output = run_command(msg); | |
if (output) | |
{ | |
delegate.inputText = output; | |
} | |
else | |
{ | |
var notFoundAlert = [[NSAlert alloc] init]; | |
[notFoundAlert setMessageText: @"Sorry..."]; | |
[notFoundAlert setInformativeText:@"Command not found"]; | |
[notFoundAlert runModal]; | |
delegate.inputText = ""; | |
return; | |
} | |
} | |
} | |
return oldm->call(this); | |
}, oldm); | |
} | |
hookPostInputText() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment