Navigation

News
Blog
Dokumente
Webapplikationen
Projekte
Hacks
Download
Forum
Partner
Banner
Links
Changelog
Impressum


Willkommen 38.103.63.62

Aktuelle Virenmeldungen:


Neuesten 3 Dokus:


Partner:

www.netzwerkinfos.com
www.sco-world.de
www.hakin9.org/de

schon Partner...?



JSH - The Java Shell


The Source Code is shown below:

Code:
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class JSH {
/**
* Author: daniel baier alias duddits
* Licens: GPL
* Requirements: JRE 1.5 for running and the JDK 1.5 for compiling
* Version: 0.05 alpha release
*/

public JSH() {
}

// entspricht dem Tree Befehl unter Windows --> Rekursive Lösung
public void tree(String start) {
File f = new File(start);
File[] h = f.listFiles();
for (int i = 0; i < h.length; i++) {

if (h[i].isDirectory()) {
start = h[i].toString();
System.out.println(h[i]);
tree(start);
}
}
}

// entspricht dem Dir Befehl unter Windows
public void dir(String start) {
File f = new File(start);
File[] h = f.listFiles();
for (int i = 0; i < h.length; i++) {
System.out.println(h[i]);
}

}

// entspricht dem Dir Befehl unter Windows
public void dirtrue(String start) {
File f = new File(start);
File[] h = f.listFiles();
for (int i = 0; i < h.length; i++) {
if (h[i].isDirectory()) {
System.out.println(h[i]);
}
}

}

// listet alle Dateien im aktuellen Verzeichnis auf
public void lsfile(String start) {
File f = new File(start);
File[] h = f.listFiles();
for (int i = 0; i < h.length; i++) {
if (h[i].isFile()) {
System.out.println(h[i]);
}
}

}

// listet alle Dateien im aktuellen Verzeichnis auf
public void lsall(String start) {
File f = new File(start);
File[] h = f.listFiles();
for (int i = 0; i < h.length; i++) {
if (h[i].isFile() || h[i].isDirectory() || h[i].isHidden() ) {
System.out.println(h[i]);
}
}

}

// sl(sizeList) bestimmt die Größe eines Verzeichnisses
public long getDirSize(File dir) {

long size = 0;
File[] files = dir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
size += getDirSize(files[i]); // Gesamtgröße des
// Verzeichnisses
// aufaddieren
} else {
size += files[i].length(); // Größe der Datei aufaddieren
}
}
}
return size;
}

// entspricht dem mkdir Befehl unter Windows
public void mkdir(String start, String startort) {
File f = new File(startort + start);
f.mkdir();

}

// Methode die, die Version und den Autor der Shell wiedergibt
public void ver() {
System.out
.println("\tJSH 0.1 alpha release\n\tdeveloped by duddits alias daniel baier\n\tfor more informations visit my website http://www.remoteshell-security.com");
}

// Gibt Informationen zum System aus
public static void sysinfo() {
Enumeration props = System.getProperties().propertyNames();
System.out.println("Systemproperties:\n");
while (props.hasMoreElements()) {
String prop = props.nextElement().toString();
System.out.print(prop + ":");
System.out.print(" ");
System.out.println(System.getProperty(prop));
}
}

// Methode die, die den Konsolen-Bildschirm leert
public void cls() {
for (int i = 0; i < 40; i++)
System.out.print("\n");
}

// minimale Version des date Kommandos unter Windows
public void date() {
DateFormat df = new SimpleDateFormat("d. MMMM yyyy", Locale.GERMANY);
Date today = new Date();
DateFormat tf = new SimpleDateFormat("HH.mm", Locale.GERMANY);

String time = "Heute ist der " + df.format(today) + " und es ist "
+ tf.format(today) + " Uhr";
System.out.println(time);

}

// entspricht dem cat Befehl unter Linux
public void cat(String start, String startort) {
try {
File file;
if (startort.equals("/")) {
file = new File("/" + start);
} else {
file = new File(startort + "/" + start);
}

FileReader fr;

fr = new FileReader(file);
String s = "";
int x = 0;
while ((x = fr.read()) != -1) {
s += (char) x;
}
System.out.println(s);

} catch (IOException ioex) {
System.out.println("Fehler beim Lesen der Datei " + start);
}

}

// entspricht dem cat Befehl unter Linux zum schreiben einer Datei
public void catwr(String start, String startort) {
try {
String s;
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
File file;
if (startort.equals("/")) {
file = new File("/" + start);
} else {
file = new File(startort + "/" + start);
}
FileWriter fw;
boolean notexit = true;
fw = new FileWriter(file);
while (notexit) {
s = br.readLine();
if (s.equals("<0>")) {
notexit = false;
break;
}
fw.write(s + "\n");
}
fw.flush();
fw.close();
} catch (IOException ioex) {
System.out.println("Fehler beim Schreiben der Datei " + start);
}

}

// entspricht dem cd Befehl unter Windows
public String cd(String start, File currentDir) {
File fullPath = new File(currentDir.getAbsolutePath());
String sparent = fullPath.getAbsoluteFile().toString();
return sparent + "/" + start;

}

@SuppressWarnings("unchecked")
public static void main(String[] args) {
JSH ws = new JSH();
System.out
.println("\tJSH 0.1 alpha release\n\tdeveloped by duddits alias daniel baier");
try {

boolean exit = true;
String s;
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String startort = "/";
while (exit) {

File f = new File(startort);
System.out.print(f.getAbsolutePath() + "> ");
s = br.readLine();

// Shell beendet sich, wenn exit eingegeben wird
if (s.equals("exit")) {
exit = false;
}else if (s.equals(null) || s.equals("cmd") || s.equals("")) {

} else if (s.equals("ls")) {
ws.dir(startort);
} else if (s.equals("ls -a")) {
ws.lsall(startort);
}else if (s.equals("ls -f")) {
ws.lsfile(startort);
}else if (s.equals("ls -d")) {
ws.dirtrue(startort);
} else if (s.equals("dir")) {
ws.dirtrue(startort);
} else if (s.equals("date")) {
ws.date();
} else if (s.equals("sysinfo")) {
sysinfo();
} else if (s.equals("cls")) {
ws.cls();
} else if (s.equals("version")) {
ws.ver();
} else if (s.equals("tree")) {
ws.tree(startort);
} else if (s.equals("sl")) {
System.out
.println("Syntaxfehler.\nUsing: sl <file/path/directory>");
} else if (s.equals("cd")) {
System.out.println("Syntaxfehler.\nUsing: cd <path>");
} else if (s.equals("cat")) {
System.out.println("Syntaxfehler.\nUsing: cat <file>");
} else if (s.equals("cat -h") || s.equals("cat -help")
|| s.equals("cat /?")) {
System.out
.println("Hilfeausgabe von cat.\nUsing: cat <file>");
System.out
.println("Cat ist ein Shell-Buildin\nEs gibt drei Moeglichkeiten cat zu verwenden:");
System.out
.println("cat <file> --> zum lesen einer einfachen Datei");
System.out
.println("cat > <file> --> zum schreiben in die Datei <file>. Abruchkommando ist ein leere Zeile");
} else if (s.equals("mkdir")) {
System.out
.println("Syntaxfehler.\nUsing: mkdir <verzeichnisname>");
} else {

String z1, z2;
z1 = s;
Pattern pmkdir = Pattern.compile("^mkdir\\s");
Pattern pcd = Pattern.compile("^cd\\s");
Pattern pcat = Pattern.compile("^cat\\s");
Pattern pcat1 = Pattern.compile("^cat >\\s");
Pattern psl = Pattern.compile("^sl\\s");
Pattern psl1 = Pattern.compile("^sl -h\\s");
Matcher mmkdir = pmkdir.matcher(z1);
Matcher mcd = pcd.matcher(z1);
Matcher msl = psl.matcher(z1);
Matcher msl1 = psl1.matcher(z1);
Matcher mcat = pcat.matcher(z1);
Matcher mcat1 = pcat1.matcher(z1);
String[] teile = pmkdir.split(z1);
String[] teile1 = pcd.split(z1);
String[] teile2 = pcat.split(z1);
String[] teile3 = pcat1.split(z1);
String[] teile4 = psl.split(z1);
String[] teile5 = psl1.split(z1);

z2 = s;
Pattern pstring = Pattern.compile("\\s");
String[] plist = pstring.split(z2);

if (mmkdir.find()) {
ws.mkdir(teile[1], startort);
} else if (mcat.find()) {
if (mcat1.find()) {
System.out
.println("To stop writing in the file, please enter after return <0>");
ws.catwr(teile3[1], startort);
} else {
ws.cat(teile2[1], startort);
}
} else if (msl.find()) {

if (msl1.find()) {
File fl1 = new File(teile5[1]);
long humansizem = ws.getDirSize(fl1)
/ (1024 * 1024);
long humansizeg = ws.getDirSize(fl1)
/ (1024 * 1024 * 1024);
if (humansizem < 1024) {
System.out.println("The size of " + teile5[1]
+ " takes " + humansizem + " MB");
} else {
System.out.println("The size of " + teile5[1]
+ " takes " + humansizeg + " GB");
}

} else {
File fl = new File(teile4[1]);
System.out.println("The size of " + teile4[1]
+ " takes " + ws.getDirSize(fl) + " Bytes");
}
} else if (mcd.find()) {
try {
String cds = ws.cd(teile1[1], new File(startort));
startort = cds;
} catch (Exception verz) {
System.out.println("Path " + teile1[1]
+ " not found.");
}
} else {
try {
LinkedList slist = new LinkedList();
for (int i = 0; i < plist.length; i++) {
slist.add(plist[i]);
}

ProcessBuilder builder = new ProcessBuilder(slist);
builder.directory(new File(startort));
Process p = builder.start();
Scanner se = new Scanner(p.getInputStream());
if (!se.hasNext()) {
Scanner sa = new Scanner(p.getErrorStream());
while (sa.hasNext()) {
System.out.println(sa.nextLine());
}
}
while (se.hasNext()) {
System.out.println(se.nextLine());
}
} catch (Exception err) {
// err.printStackTrace();
System.out.println(f.getAbsolutePath()
+ "> Befehl " + s
+ " konnte nicht gefunden werden");
}

}
}
}

} catch (Exception io) {
io.printStackTrace();
}

}

}



Copyright © 2006 Daniel Baier: Alle Rechte vorbehalten