| 17 | #define WINDOWSKILL_VERSION "1.1.4" |
| 18 | |
| 19 | int main(int argc,char *argv[]) |
| 20 | { |
| 21 | DWORD signal_type; |
| 22 | DWORD signal_pid; |
| 23 | char* endptr; |
| 24 | |
| 25 | cout << "Windows Kill " << WINDOWSKILL_VERSION << " | Windows Kill Library "<< WINDOWSKILLLIBRARY_VERSION << endl; |
| 26 | |
| 27 | if (argc == 1) { |
| 28 | cout << "Not enough argument. Use -h for help." << endl; |
| 29 | return 0; |
| 30 | } |
| 31 | else if (argc == 2) { |
| 32 | if (strcmp(argv[1], "-h") == 0) { |
| 33 | cout << "You should give the signal type and the pid to send the signal.\n" |
| 34 | << "Example: windows-kill -SIGINT 1234\n" |
| 35 | << "-l\t List of available signals type." << endl; |
| 36 | } |
| 37 | else if (strcmp(argv[1], "-l") == 0) { |
| 38 | cout << "Availabe Signal Types\n" |
| 39 | << "\t(1) (SIGBREAK) : CTR + Break\n" |
| 40 | << "\t(2) (SIGINT) : CTR + C\n" << endl; |
| 41 | } |
| 42 | else { |
| 43 | cout << "Not enough argument. Use -h for help." << endl; |
| 44 | } |
| 45 | return 0; |
| 46 | } |
| 47 | else if (argc == 3) { |
| 48 | if (strcmp(argv[1], "-1") == 0 || strcmp(argv[1], "-SIGBREAK") == 0) { |
| 49 | signal_type = SIGNAL_TYPE_CTRL_BREAK; |
| 50 | } |
| 51 | else if (strcmp(argv[1], "-2") == 0 || strcmp(argv[1], "-SIGINT") == 0) { |
| 52 | signal_type = SIGNAL_TYPE_CTRL_C; |
| 53 | } |
| 54 | else { |
| 55 | cout << "Signal type " << argv[1] << " not supported. Use -h for help." << endl; |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | signal_pid = strtoul(argv[2], &endptr, 10); |
| 60 | |
| 61 | if ((endptr == argv[1]) || (*endptr != '\0')) { |
| 62 | cout << "Invalid pid: " << argv[2] << endl; |
| 63 | return 0; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | try { |
| 68 | sendSignal(signal_pid, signal_type); |
| 69 | cout << "Signal sent successfuly. type: " << signal_type << " | pid: " << signal_pid << "\n"; |
| 70 | } |
| 71 | catch (const invalid_argument& exception) { |
| 72 | if (strcmp(exception.what(), "ESRCH") == 0) { |
| 73 | cout << "Error: Pid dosen't exist." << endl; |
| 74 | } |
| 75 | else if(strcmp(exception.what(), "EINVAL") == 0){ |
| 76 | cout << "Error: Invalid signal type." << endl; |
nothing calls this directly
no test coverage detected