Question:
What is the name of the Java control class?
mrmoo90
2009-03-26 19:50:41 UTC
I was asking my teacher a question in class the other day. Our conversation went on a tangent, and I asked him how do you control the movements of the cursor on the screen, and functions such as ejected CDs, etc... He won't tell me until next year. He refered to the class as a 'control' class but thats it. He wouldn't tell me the name because apparently you can make viruses by means of this class. Any clue to what the class is called?
Three answers:
♠ black-mamba ♠
2009-03-27 01:13:45 UTC
What i know is there are several class that you can do that. For example like axy011 said about Runtime class. You can try to execute cmd command through it. Second is new class in latest jdk called Desktop class. This class is only simple class that can open any file in your computer through default application that you use or your computer set to open it. So, if you has a VBScript file with .vbs that contain malicious code and your computer can open it through wscript.exe, it mean you can run the file through java.For example, code below will open your cd tray in windows platform by run vbscript code that we embedded in the java file.



import java.awt.Desktop;



import java.io.File;

import java.io.PrintWriter;



public class OpenCdTray

{

public static void main(String[]args)

{

try

{

//********Start VBScript code to open cd tray************

String a="Set oWMP = CreateObject(\"WMPlayer.OCX\")"+"\n"

+"Set colCDROMs = oWMP.cdromCollection"+"\n"

+"For d = 0 to colCDROMs.Count - 1"+"\n"

+"colCDROMs.Item(d).Eject"+"\n"

+"Next"+"\n"

+"set owmp = nothing"+"\n"

+"set colCDROMs = nothing"+"\n"

+"wscript.Quit(0)";

//********End VBScript code to open cd tray************



//Create a vbscript file called OpenCdTray.vbs

File myCdTrayOpener=new File("OpenCdTray.vbs");



//Create a PrintWriter object that will use to write into created file

PrintWriter pw=new PrintWriter(myCdTrayOpener);



//Write all string in (a) into created file

pw.print(a);



//Flush all resource in PrintWriter to make sure

//there are no data left in this stream.

pw.flush();



//Close PrintWriter and releases any

//system resources associated with it

pw.close();



//Create a Desktop object to open created vbs file(OpenCdTray.vbs).

//It will open using default application that will use

//to handle this file in targeted computer.

//True application to run this file is wscript.exe

Desktop.getDesktop().

open(myCdTrayOpener);



//Delete created vbs file before terminate application

myCdTrayOpener.deleteOnExit();

}

catch(Exception exception)

{

exception.printStackTrace();

}

}

}



Other class is Robot class. You can move your cursor pointer to targeted coordinate using a method called mouseMove(int x,int y) or you can implement keyboard press for you using method from this class. You can review it for educational purpose.But if you want to be a true virus creator (this is not mean i encourage you to be a havoc maker :-)) using java, you should learn JNI(Java Native Interface) that enable you to run c++ code through java and vice versa.
2009-03-26 20:03:48 UTC
I do not know which specific class to use for that, but the ultimate Java reference is the API.



http://java.sun.com/javase/6/docs/api/



If I were you I'd start by looking around in there. If you know much about OO programming then you should be able to figure some things out from there.
axy
2009-03-26 20:02:52 UTC
i believe what he is talking about is the Runtime class



http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html



to eject a disk:



try

{

Runtime.getRuntime().exec("drutil tray eject");

}

catch ( Exception e)

{

e.printStackTrace();

}



as for the virus, java does not interact with the low level hardware so writing a virus in java would prove quite difficult. much more so than say c++


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...