Skip to content

Instantly share code, notes, and snippets.

@bsmt
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save bsmt/dda10ef7b210ec4dba0e to your computer and use it in GitHub Desktop.

Select an option

Save bsmt/dda10ef7b210ec4dba0e to your computer and use it in GitHub Desktop.

Revisions

  1. bsmt revised this gist Dec 18, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -45,8 +45,7 @@ var run_command = function(cmd) // blocks
    [task launch];
    [task waitUntilExit];
    [task release];
    var ret = [[NSString alloc] initWithData:[[out fileHandleForReading] readDataToEndOfFile] encoding:4];
    return [ret stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return [[NSString alloc] initWithData:[[out fileHandleForReading] readDataToEndOfFile] encoding:4];
    }
    var hookPostInputText = function()
    {
  2. bsmt revised this gist Dec 18, 2014. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -65,21 +65,19 @@ var hookPostInputText = function()
    if (output)
    {
    delegate.inputText = output;
    return oldm->call(this);
    }
    else
    {
    var notFoundAlert = [[NSAlert alloc] init];
    [notFoundAlert setMessageText: @"Sorry..."];
    [notFoundAlert setInformativeText:@"Command not found"];
    [notFoundAlert runModal];
    delegate.inputText = "";
    return;
    }
    }
    }
    else
    {
    return oldm->call(this);
    }
    return oldm->call(this);
    }, oldm);
    }
    hookPostInputText()
  3. bsmt revised this gist Dec 18, 2014. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@ var run_command = function(cmd) // blocks
    [args removeObjectAtIndex:0];
    var out = [NSPipe pipe];
    var task = [[NSTask alloc] init];
    [task setLaunchPath:run]; // wrong
    [task setLaunchPath:run];
    [task setArguments:args];
    [task setStandardOutput:out];
    [task launch];
    @@ -57,22 +57,29 @@ var hookPostInputText = function()
    var msg = delegate.inputText;
    if ([msg hasPrefix:@"/"])
    {
    msg = [msg stringByReplacingOccurrencesOfString:@"/" withString:@""];
    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;
    return oldm->call(this);
    }
    else
    {
    delegate.inputText = "Command not found";
    var notFoundAlert = [[NSAlert alloc] init];
    [notFoundAlert setMessageText: @"Sorry..."];
    [notFoundAlert setInformativeText:@"Command not found"];
    [notFoundAlert runModal];
    }
    }
    }
    return oldm->call(this);
    else
    {
    return oldm->call(this);
    }
    }, oldm);
    }
    hookPostInputText()
  4. bsmt revised this gist Dec 17, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -50,10 +50,10 @@ var run_command = function(cmd) // blocks
    }
    var hookPostInputText = function()
    {
    var delegate = choose(ChatInputTextView)[0].delegate;
    var oldm = {};
    NSLog(@"Hooking [%@ postInputText]", delegate.className);
    MS.hookMessage(delegate.class, @selector(postInputText), function() {
    NSLog(@"Hooking [PanAmericanChatInputViewController postInputText]");
    MS.hookMessage(PanAmericanChatInputViewController, @selector(postInputText), function() {
    var delegate = choose(ChatInputTextView)[0].delegate;
    var msg = delegate.inputText;
    if ([msg hasPrefix:@"/"])
    {
    @@ -72,7 +72,7 @@ var hookPostInputText = function()
    }
    }
    }
    return oldm->call(this);
    return oldm->call(this);
    }, oldm);
    }
    hookPostInputText()
  5. bsmt revised this gist Dec 17, 2014. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,6 @@ var get = function(name)
    }
    NSLog = get("NSLog");

    var chatViewController = chatBoxDelegate.delegate
    var conversations = choose(SKConversation)

    var send_message = function(msg)
    {
    var delegate = choose(ChatInputTextView)[0].delegate;
    @@ -78,3 +75,4 @@ var hookPostInputText = function()
    return oldm->call(this);
    }, oldm);
    }
    hookPostInputText()
  6. bsmt created this gist Dec 17, 2014.
    80 changes: 80 additions & 0 deletions infest.cy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    //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 chatViewController = chatBoxDelegate.delegate
    var conversations = choose(SKConversation)

    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]; // wrong
    [task setArguments:args];
    [task setStandardOutput:out];
    [task launch];
    [task waitUntilExit];
    [task release];
    var ret = [[NSString alloc] initWithData:[[out fileHandleForReading] readDataToEndOfFile] encoding:4];
    return [ret stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    }
    var hookPostInputText = function()
    {
    var delegate = choose(ChatInputTextView)[0].delegate;
    var oldm = {};
    NSLog(@"Hooking [%@ postInputText]", delegate.className);
    MS.hookMessage(delegate.class, @selector(postInputText), function() {
    var msg = delegate.inputText;
    if ([msg hasPrefix:@"/"])
    {
    msg = [msg stringByReplacingOccurrencesOfString:@"/" withString:@""];
    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
    {
    delegate.inputText = "Command not found";
    }
    }
    }
    return oldm->call(this);
    }, oldm);
    }