SHARE
TWEET

Untitled

a guest Sep 20th, 2015 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "plugin.h"
  2.  
  3. #define DEFAULT_DELAY 10
  4.  
  5. enum plugin_status plugin_start(const void *param)
  6. {
  7.     if(!param)
  8.         rb->splash(2*HZ, "Execute a USBScript file!");
  9.     const char *path = (const char*) param;
  10.     int fd = rb->open(path, O_RDONLY);
  11.  
  12.     int line = 0;
  13.  
  14.     int default_delay = DEFAULT_DELAY;
  15.  
  16.     while(1)
  17.     {
  18.         char instr_buf[256];
  19.         if(rb->read_line(fd, instr_buf, sizeof(instr_buf)) == 0)
  20.             return PLUGIN_OK;
  21.         ++line;
  22.  
  23.         char *tok = NULL, *save = NULL;
  24.         do {
  25.             tok = rb->strtok_r(instr_buf, " ", &save);
  26.  
  27.             if(rb->strcmp(tok, "GUI") == 0) {
  28.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_GUI);
  29.             }
  30.             else if(rb->strcmp(tok, "RGUI") == 0) {
  31.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_GUI);
  32.             }
  33.             else if(rb->strcmp(tok, "DELAY") == 0) {
  34.                 /* delay N 100ths of a sec */
  35.                 tok = rb->strtok_r(instr_buf, " ", &save);
  36.                 rb->sleep((HZ / 100) * rb->atoi(tok));
  37.             }
  38.             else if(rb->strcmp(tok, "CTRL")) {
  39.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_CONTROL);
  40.             }
  41.             else if(rb->strcmp(tok, "RCTRL")) {
  42.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_CONTROL);
  43.             }
  44.             else if(rb->strcmp(tok, "ALT")) {
  45.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_LEFT_ALT);
  46.             }
  47.             else if(rb->strcmp(tok, "RALT")) {
  48.                 rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, HID_KEYBOARD_RIGHT_ALT);
  49.             }
  50.             else if(rb->strcmp(tok, "DEFAULT_DELAY")) {
  51.                 /* sets time between instructions, 100ths of a second */
  52.                 tok = rb->strtok_r(instr_buf, " ", &save);
  53.                 default_delay = rb->atoi(tok) * (HZ / 100);
  54.             }
  55.            
  56.             rb->sleep(default_delay);
  57.         } while(tok);
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top