Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * SHT.cpp
- *
- * Created on: 29.01.2016
- * Author: armised
- */
- #include <sstream>
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <string.h>
- #include <unistd.h>
- using namespace std;
- int ghi = 0;
- bool replace(std::string& str, const std::string& from, const std::string& to) { size_t start_pos = str.find(from); if(start_pos == std::string::npos) return false; str.replace(start_pos, from.length(), to); return true; }
- bool is_file_exist(const char *fileName) { std::ifstream infile(fileName); return infile.good(); }
- int main(int argc, char* argv[])
- {
- char path[256];
- getcwd(path, 256);
- char rawin[256];
- string exit =rawin;
- cout << "SHT Shell - Version 1.0.3\nBereit Befehle entgegen zu nehmen.\n";
- while (true)
- {
- system("echo -e \"\\e[36m\\c\"");
- cout << path << "-§ ";
- cin.getline(rawin, 256);
- system("echo -e \"\\e[00m\\c\"");
- //cin >> rawin;
- //cout << rawin << endl;
- string in = rawin;
- string args[90];
- int i = 0;
- stringstream ssin(in);
- while (ssin.good() && i < 90)
- {
- ssin >> args[i];
- ++i;
- }
- string xstr = "/system/bin/"+args[0];
- if (args[0] == "print")
- {
- int ix;
- int argv = sizeof(args)/sizeof(*args);
- for(int ix = 1; ix < argv; ix++)
- {
- cout << args[ix] << " ";
- }
- cout << endl;
- }
- else if (args[0] == "exit")
- {
- string ans;
- cout << "Wollen sie die Shell wirklich stoppen?\n[j/n]: ";
- cin >> ans;
- if (ans == "j" || ans == "J")
- {
- cout << "Shuttding down...\nBB ;)" << endl;
- system("shutdown -s 1");
- return 0;
- }
- else
- {
- cout << "Vorgang vom User abgebrochen.\n";
- }
- }
- else if (args[0] == "list")
- {
- system("ls");
- }
- else if (args[0] == "cd")
- {
- string x = args[1].c_str();
- const char* f = x.c_str();
- if (chdir(f) != 0)
- {
- cout << "Das angegebene Verzeichnis konnte nicht gefunden werden\noder sie besitzen keine Berechtigung dazu.\n";
- }
- else
- {
- char xpath[256];
- getcwd(xpath, 256);
- getcwd(path, 256);
- cout << "Du befindest dich jetzt in: " << xpath << endl;
- }
- }
- else if(args[0] == "mf")
- {
- string f = args[1];
- const char *x = f.c_str();
- ofstream file;
- file.open(x);
- file << "New File";
- file.close();
- if (::ghi == 0)
- {
- cout << "Hinweis: Sie können nur eine Datei pro Kommando erstellen.\n";
- ::ghi++;
- }
- }
- else if(args[0] == "cls")
- {
- int li = 0;
- while ( li <= 300)
- {
- cout << " " << endl;
- li++;
- }
- }
- else if(args[0] == "md")
- {
- if(!mkdir(args[1].c_str(), 0755))
- {
- cout << "Das Verzeichnis "+args[1]+" wirde erfolgreich erstellt!" << endl;
- }
- else
- {
- cout << "Unbekannter Error beim erstellen aufgetreten!" << endl;
- }
- }
- else if(args[0] == "help")
- {
- cout << "Zurzeit gibt es folgende Befehle:\n\nexit - Beendet die Shell\ncls - Löscht die Bildschirmausgabe\nmf - Erstellt eine neue Datei\nmd - Erstellt einen neuen Ordner\ndel - Kann Dateien und Ordner löschen\nmov - Verschiebt Dateien\nlist - Listet alle Dateien im aktuellen Verzeichnis auf\nprint - Gibt eine Zeile Text aus\nwhoami - Gibt den aktuellen User aus." << endl;
- }
- if(args[0] == "del")
- {
- string answer;
- cout << "Sind Sie sich sicher? [J/N]: ";
- cin >> answer;
- if (answer == "j" || answer == "J")
- {
- remove(args[1].c_str());
- cout << endl;
- }
- else if (answer == "n" || answer == "N")
- {
- cout << "Vorgang vom User abgebrochen.\n";
- }
- else
- {
- cout << "Ungueltige Eingabe: " << answer << endl;
- }
- }
- else if(args[0] == "mov")
- {
- try
- {
- rename(args[1].c_str(), args[2].c_str());
- }
- catch(int ex)
- {
- cout << "Datei oder Ordner nicht gefunden!" << endl;
- }
- }
- else if(args[0] == "shell")
- {
- //#define NELEMS(args) (sizeof(args) / (sizeof(args[0]))
- string cmd = "";
- strncat(cmd.c_str(), args);
- system(cmd.c_str());
- }
- else if(args[0] == "whoami")
- {
- cout << "User: " << getuid() << endl;
- }
- else if(args[0] == "")
- {
- cout << "Bestanden!" << endl;
- }
- /*else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }
- else if(args[0].find("") == 0)
- {
- }*/
- else
- {
- //cout << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment