VirusTotal is a web service that performs url/file scan with some virus scanners. It provides some very simple public API, so that we can automate the file submission and report checking process. There was not a Java class to do this task, so that I decided to code it.
I'm working on the possibility to upload a file and scan it. I let you updated...

>> You can find the whole code here [JVirusTotal]. You can look at the following example for further information.

JVirusTotal vt = new JVirusTotal(your_API_key);
String url = "http://www.x.x";

// submit an URL
vt.submitScanURL(url);

// retrieve an URL scan report
vt.retrieveURLscan(url);

// retrieve a file scan report
vt.retrieveFilescan(getMD5Sum(new URL(url)));

The following class is used to get the MD5 hash of a file, by giving its URL.

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class md5 {
	/**
	 * it calculates the md5sum
	 * 
	 * @param url file url
	 * @return md5sum
	 */
	public static String getMD5Sum(URL url) {
		MessageDigest digest = null;
				
		try {
			digest = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
			
		byte[] buffer = new byte[8192];
		int read = 0;
		String output = "";

		InputStream is = null;
		
		try {
			is = url.openStream();

			while( (read = is.read(buffer)) > 0) {
				digest.update(buffer, 0, read);
			}		
			byte[] md5sum = digest.digest();
			BigInteger bigInt = new BigInteger(1, md5sum);
			output = bigInt.toString(16);
		}
		catch(IOException e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
			} catch(IOException e) {
				e.printStackTrace();
			}
		}
			
		return output;
	}
	
	public static void main (String[] s) throws MalformedURLException{
		System.out.println(getMD5Sum(new URL("http://www.x.x")));
	}
}

L'idea principale è quella di realizzare un grabber di gesture realizzabili sullo schermo del nostro device. Ad ogni movimento delle dita sullo schermo potrebbe corrispondere l'apertura di una specifica applicazione. Nel caso di seguito è possibile scorrere un dito dall'alto a sinistra dello schermo sino al basso a destra per fare in modo che una applicazione a scelta venga avviata. L'immagine di seguito potrà chiarire;

Parte del codice deriva dallo screenlocker di lindi, il quale blocca lo schermo sino a quando una gesture verticale (dall'alto al basso) viene rilevata.
In touchscreen_gesture.c viene usato EVIOCGRAB mediante I/O asincrono per evitare che lo schermo venga bloccato durante l'esecuzione (vedasi ioctl(...)) e la matematica delle operazioni diviene leggermente più complessa. Giustamente occorre verificare che gli eventi legati alla coordinata x non assumano valori costanti e che questi siano crescenti.

[C] Download source code: touchscreen_gesture.c ~ Do you need help?

Evito di trattare nel dettaglio la matematica delle operazioni. In pratica lo schermo riceve degli eventi tra cui le coordinate x ed y del mouse (del dito nel nostro caso) e touchscreen_gesture.c controlla ciclicamente la storia degli eventi ricevuti. Qualora la gesture dovesse matchare con quella mostrata sopra verrà aperta una finestra con zenity. E' possibile modificare il comando da eseguire a seguito della gesture, vedasi la riga relativa all'execlp(...). Il risultato a seguito della gesture è il seguente mostrato:



Compilazione:
gcc -c touchscreen_gesture.c
gcc -o touchscreen_gesture touchscreen_gesture.o

Uso:
./touchscreen_gesture /dev/input/touchscreen0




Main Pages

Twitter