|
@@ -2,6 +2,8 @@ package de.tudarmstadt.informatik.hostage.persistence;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
import android.content.Context;
|
|
@@ -15,16 +17,20 @@ import de.tudarmstadt.informatik.hostage.logging.MessageRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.NetworkRecord;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.SyncInfoRecord;
|
|
|
+import de.tudarmstadt.informatik.hostage.logging.MessageRecord.TYPE;
|
|
|
+import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.AttackEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.NetworkEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.PacketEntry;
|
|
|
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.ProfileEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncDeviceEntry;
|
|
|
import de.tudarmstadt.informatik.hostage.persistence.HostageDBContract.SyncInfoEntry;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.LogFilter;
|
|
|
|
|
|
public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
private static final String DATABASE_NAME = "hostage.db";
|
|
|
- private static final int DATABASE_VERSION = 1;
|
|
|
+ private static final int DATABASE_VERSION = 2;
|
|
|
private Context context;
|
|
|
|
|
|
static {
|
|
@@ -81,18 +87,29 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
syncInfoSQLBuilder.append(")");
|
|
|
SQL_CREATE_SYNC_INFO_ENTRIES = syncInfoSQLBuilder.toString();
|
|
|
|
|
|
-
|
|
|
+ StringBuilder profilSQLBuilder = new StringBuilder("CREATE TABLE ").append(ProfileEntry.TABLE_NAME).append("(");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ID).append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_NAME).append(" TEXT,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_DESCRIPTION ).append(" TEXT,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ICON).append(" TEXT,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ICON_NAME).append(" TEXT,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_EDITABLE).append(" INTEGER,");
|
|
|
+ profilSQLBuilder.append(ProfileEntry.COLUMN_NAME_PROFILE_ACTIVE).append(" INTEGER");
|
|
|
+ profilSQLBuilder.append(")");
|
|
|
+ SQL_CREATE_PROFIL_ENTRIES = profilSQLBuilder.toString();
|
|
|
}
|
|
|
|
|
|
private static final String SQL_CREATE_NETWORK_ENTRIES;
|
|
|
private static final String SQL_CREATE_ATTACK_ENTRIES;
|
|
|
private static final String SQL_CREATE_PACKET_ENTRIES;
|
|
|
+ private static final String SQL_CREATE_PROFIL_ENTRIES;
|
|
|
private static final String SQL_CREATE_SYNC_DEVICES_ENTRIES;
|
|
|
private static final String SQL_CREATE_SYNC_INFO_ENTRIES;
|
|
|
|
|
|
private static final String SQL_DELETE_PACKET_ENTRIES = "DROP TABLE IF EXISTS " + PacketEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_ATTACK_ENTRIES = "DROP TABLE IF EXISTS " + AttackEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_NETWORK_ENTRIES = "DROP TABLE IF EXISTS " + NetworkEntry.TABLE_NAME;
|
|
|
+ private static final String SQL_DELETE_PROFIL_ENTRIES = "DROP TABLE IF EXISTS " + ProfileEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_SYNC_DEVICES_ENTRIES = "DROP TABLE IF EXISTS " + SyncDeviceEntry.TABLE_NAME;
|
|
|
private static final String SQL_DELETE_SYNC_INFO_ENTRIES = "DROP TABLE IF EXISTS " + SyncInfoEntry.TABLE_NAME;
|
|
|
|
|
@@ -106,6 +123,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.execSQL(SQL_CREATE_NETWORK_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_ATTACK_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_PACKET_ENTRIES);
|
|
|
+ db.execSQL(SQL_CREATE_PROFIL_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_SYNC_DEVICES_ENTRIES);
|
|
|
db.execSQL(SQL_CREATE_SYNC_INFO_ENTRIES);
|
|
|
}
|
|
@@ -115,6 +133,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.execSQL(SQL_DELETE_SYNC_INFO_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_PACKET_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_ATTACK_ENTRIES);
|
|
|
+ db.execSQL(SQL_DELETE_PROFIL_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_NETWORK_ENTRIES);
|
|
|
db.execSQL(SQL_DELETE_SYNC_DEVICES_ENTRIES);
|
|
|
onCreate(db);
|
|
@@ -250,6 +269,31 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.close();
|
|
|
return result > 0;
|
|
|
}
|
|
|
+
|
|
|
+ public int numBssidSeen(String BSSID) {
|
|
|
+ String countQuery = "SELECT COUNT(*) FROM " + AttackEntry.TABLE_NAME + " WHERE "
|
|
|
+ + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(countQuery, null);
|
|
|
+ cursor.moveToFirst();
|
|
|
+ int result = cursor.getInt(0);
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int numBssidSeen(String protocol, String BSSID) {
|
|
|
+ String countQuery = "SELECT COUNT(*) FROM " + AttackEntry.TABLE_NAME
|
|
|
+ + " WHERE " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'"
|
|
|
+ + " AND " + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_BSSID + " = " + "'" + BSSID + "'";
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(countQuery, null);
|
|
|
+ cursor.moveToFirst();
|
|
|
+ int result = cursor.getInt(0);
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -437,6 +481,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ //TODO ADD AGAIN ?
|
|
|
/**
|
|
|
* Returns the {@link AttackRecord} with the given attack id from the database.
|
|
|
*
|
|
@@ -444,6 +489,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
* The attack id of the {@link Record};
|
|
|
* @return The {@link Record}.
|
|
|
*/
|
|
|
+ /*
|
|
|
public AttackRecord getRecordOfAttackId(long attack_id) {
|
|
|
String selectQuery = "SELECT * FROM " + AttackEntry.TABLE_NAME + " WHERE " + AttackEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id;
|
|
|
SQLiteDatabase db = this.getReadableDatabase();
|
|
@@ -458,7 +504,7 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
// return record list
|
|
|
db.close();
|
|
|
return record;
|
|
|
- }
|
|
|
+ } */
|
|
|
|
|
|
/**
|
|
|
* Gets a {@link AttackRecord} for every attack identified by its attack id.
|
|
@@ -757,6 +803,19 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
db.close();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Deletes all records from {@link #TABLE_RECORDS} with a specific Attack ID.
|
|
|
+ *
|
|
|
+ * @param attackID
|
|
|
+ * The Attack ID to match against.
|
|
|
+ */
|
|
|
+ public void deleteByAttackID(long attackID) {
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ db.delete(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
|
|
|
+ db.delete(PacketEntry.TABLE_NAME, PacketEntry.COLUMN_NAME_ATTACK_ID + " = ?", new String[] { String.valueOf(attackID) });
|
|
|
+ db.close();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Creates a {@link Record} from a Cursor. If the cursor does not show to a
|
|
|
* valid data structure a runtime exception is thrown.
|
|
@@ -795,5 +854,439 @@ public class HostageDBOpenHelper extends SQLiteOpenHelper {
|
|
|
|
|
|
return record;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a {@link Record} from a Cursor. If the cursor does not show to a
|
|
|
+ * valid data structure a runtime exception is thrown.
|
|
|
+ *
|
|
|
+ * @param cursor
|
|
|
+ * @return Returns the created {@link Record} .
|
|
|
+ */
|
|
|
+ private Record createRecord(Cursor cursor) {
|
|
|
+ Record record = new Record();
|
|
|
+ record.setId(Integer.parseInt(cursor.getString(0)));
|
|
|
+ record.setAttack_id(cursor.getLong(1));
|
|
|
+ record.setType(TYPE.valueOf(cursor.getString(2)));
|
|
|
+ record.setTimestamp(cursor.getLong(3));
|
|
|
+ record.setPacket(cursor.getString(4));
|
|
|
+ record.setProtocol(cursor.getString(5));
|
|
|
+ record.setExternalIP(cursor.getString(6));
|
|
|
+
|
|
|
+ record.setLocalIP(cursor.getString(7));
|
|
|
+ record.setLocalPort(Integer.parseInt(cursor.getString(8)));
|
|
|
+
|
|
|
+ record.setRemoteIP(cursor.getString(9));
|
|
|
+ record.setRemotePort(Integer.parseInt(cursor.getString(10)));
|
|
|
+
|
|
|
+ record.setBssid(cursor.getString(11));
|
|
|
+ record.setSsid(cursor.getString(12));
|
|
|
+ record.setLatitude(Double.parseDouble(cursor.getString(13)));
|
|
|
+ record.setLongitude(Double.parseDouble(cursor.getString(14)));
|
|
|
+ record.setAccuracy(Float.parseFloat(cursor.getString(15)));
|
|
|
+ record.setTimestampLocation(cursor.getLong(16));
|
|
|
+
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all received {@link Record Records} for the specified information in
|
|
|
+ * the LogFilter ordered by date.
|
|
|
+ *
|
|
|
+ * @return A ArrayList with all received {@link Record Records} for the
|
|
|
+ * LogFilter.
|
|
|
+ */
|
|
|
+ public ArrayList<Record> getRecordsForFilter(LogFilter filter) {
|
|
|
+ ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")";
|
|
|
+
|
|
|
+ // TIMESTAMPS
|
|
|
+ selectQuery = selectQuery + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
+ selectQuery = selectQuery + " < " + filter.getBelowTimestamp();
|
|
|
+ selectQuery = selectQuery + " AND " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
+ selectQuery = selectQuery + " > " + filter.getAboveTimestamp();
|
|
|
+
|
|
|
+ if (filter.getBSSIDs() != null && filter.getBSSIDs().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getBSSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_BSSID);
|
|
|
+ }
|
|
|
+ if (filter.getESSIDs() != null && filter.getESSIDs().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getESSIDQueryStatement(NetworkEntry.TABLE_NAME, NetworkEntry.COLUMN_NAME_SSID);
|
|
|
+ }
|
|
|
+ if (filter.getProtocols() != null && filter.getProtocols().size() > 0) {
|
|
|
+ selectQuery = selectQuery + " AND ";
|
|
|
+ selectQuery = selectQuery + filter.getProtocolsQueryStatement(AttackEntry.TABLE_NAME, AttackEntry.COLUMN_NAME_PROTOCOL);
|
|
|
+ }
|
|
|
+
|
|
|
+ selectQuery = selectQuery + " GROUP BY " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ATTACK_ID;
|
|
|
+
|
|
|
+ if (filter.getSorttype() == LogFilter.SortType.packet_timestamp) {
|
|
|
+ // DESC
|
|
|
+ selectQuery = selectQuery + " ORDER BY " + filter.getSorttype() + " DESC";
|
|
|
+ } else {
|
|
|
+ selectQuery = selectQuery + " ORDER BY " + filter.getSorttype();
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(selectQuery);
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ Record record = createRecord(cursor);
|
|
|
+ // Adding record to list
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ // return record list
|
|
|
+ db.close();
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Returns the Conversation of a specific attack id
|
|
|
+ *
|
|
|
+ * @param attack_id Tha attack id to match the query against.
|
|
|
+ *
|
|
|
+ * @return A arraylist with all {@link Record Records}s for an attack id.
|
|
|
+ */
|
|
|
+ public ArrayList<Record> getConversationForAttackID(long attack_id) {
|
|
|
+ ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")" + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id;
|
|
|
+
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ Record record = createRecord(cursor);
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ db.close();
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets a single {@link Record} with the given attack id from the database.
|
|
|
+ *
|
|
|
+ * @param attack_id
|
|
|
+ * The attack id of the {@link Record};
|
|
|
+ * @return The {@link Record}.
|
|
|
+ */
|
|
|
+ public Record getRecordOfAttackId(long attack_id) {
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")" + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ATTACK_ID + " = " + attack_id + " GROUP BY " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ID;
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+ Record record = null;
|
|
|
+
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ record = createRecord(cursor);
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ // return record list
|
|
|
+ db.close();
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets a single {@link Record} with the given ID from the database.
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * The ID of the {@link Record};
|
|
|
+ * @return The {@link Record}.
|
|
|
+ */
|
|
|
+ public Record getRecord(int id) {
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + PacketEntry.COLUMN_NAME_ATTACK_ID
|
|
|
+ + ")" + " WHERE " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_ID + " = " + id;
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+ Record record = null;
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ record = createRecord(cursor);
|
|
|
+ }
|
|
|
+
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+ // return contact
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all {@link Record Records} saved in the database.
|
|
|
+ *
|
|
|
+ * @return A ArrayList of all the {@link Record Records} in the Database.
|
|
|
+ */
|
|
|
+ public ArrayList<Record> getAllRecords() {
|
|
|
+ ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
+ // Select All Query
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")";
|
|
|
+
|
|
|
+ SQLiteDatabase db = this.getWritableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ Log.i("Database", "Start loop");
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ Log.i("Database", "Add Record");
|
|
|
+ Record record = createRecord(cursor);
|
|
|
+ // Adding record to list
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+ // return record list
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all non duplicate Records For the key BSSID.
|
|
|
+ *
|
|
|
+ * @return A ArrayList with received Records.
|
|
|
+ */
|
|
|
+ public ArrayList<String> getUniqueBSSIDRecords() {
|
|
|
+ return this.getUniqueDataEntryForKeyType(NetworkEntry.COLUMN_NAME_BSSID, NetworkEntry.TABLE_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all non duplicate Records For the key ESSID.
|
|
|
+ *
|
|
|
+ * @return A ArrayList with received Records.
|
|
|
+ */
|
|
|
+ public ArrayList<String> getUniqueESSIDRecords() {
|
|
|
+ return this.getUniqueDataEntryForKeyType(NetworkEntry.COLUMN_NAME_SSID, NetworkEntry.TABLE_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> getUniqueESSIDRecordsForProtocol(String protocol) {
|
|
|
+ return this.getUniqueIDForProtocol(NetworkEntry.COLUMN_NAME_SSID, protocol);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> getUniqueBSSIDRecordsForProtocol(String protocol) {
|
|
|
+ return this.getUniqueIDForProtocol(NetworkEntry.COLUMN_NAME_BSSID, protocol);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<String> getUniqueIDForProtocol(String id, String protocol) {
|
|
|
+ ArrayList<String> recordList = new ArrayList<String>();
|
|
|
+ String selectQuery = "SELECT DISTINCT " + id + " FROM " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID + ") " + " WHERE "
|
|
|
+ + AttackEntry.TABLE_NAME + "." + AttackEntry.COLUMN_NAME_PROTOCOL + " = " + "'" + protocol + "'" + " ORDER BY " + id; // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_ATTACK_INFO
|
|
|
+ // +
|
|
|
+ // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_BSSIDS
|
|
|
+ // +
|
|
|
+ // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_PORTS
|
|
|
+ // +
|
|
|
+
|
|
|
+ // ORDERED BY TIME
|
|
|
+ System.out.println(selectQuery);
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ String record = cursor.getString(0);
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ // return record list
|
|
|
+ db.close();
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all non duplicate Data Entry For a specific KeyType ( e.g. BSSIDs).
|
|
|
+ *
|
|
|
+ * @return A ArrayList with received Records.
|
|
|
+ */
|
|
|
+ public ArrayList<String> getUniqueDataEntryForKeyType(String keyType, String table) {
|
|
|
+ ArrayList<String> recordList = new ArrayList<String>();
|
|
|
+ // String selectQuery = "SELECT * FROM " + TABLE_RECORDS +
|
|
|
+ // " NATURAL JOIN " + TABLE_ATTACK_INFO + " NATURAL JOIN " +
|
|
|
+ // TABLE_BSSIDS + " NATURAL JOIN " + TABLE_PORTS;
|
|
|
+ String selectQuery = "SELECT DISTINCT " + keyType + " FROM " + table + " ORDER BY " + keyType; // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_ATTACK_INFO
|
|
|
+ // +
|
|
|
+ // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_BSSIDS
|
|
|
+ // +
|
|
|
+ // " NATURAL JOIN "
|
|
|
+ // +
|
|
|
+ // TABLE_PORTS
|
|
|
+ // +
|
|
|
+
|
|
|
+ // ORDERED BY TIME
|
|
|
+ System.out.println(selectQuery);
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ String record = cursor.getString(0);
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ // return record list
|
|
|
+ db.close();
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //TODO PROFILE DATABASE QUERIES - STILL NEEDED?
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves all the profiles from the database
|
|
|
+ *
|
|
|
+ * @return list of profiles
|
|
|
+ */
|
|
|
+ public List<Profile> getAllProfiles() {
|
|
|
+ List<Profile> profiles = new LinkedList<Profile>();
|
|
|
+
|
|
|
+ // Select All Query
|
|
|
+ String selectQuery = "SELECT * FROM " + ProfileEntry.TABLE_NAME;
|
|
|
+
|
|
|
+ SQLiteDatabase db = this.getWritableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ Profile profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(5) == 1);
|
|
|
+
|
|
|
+ if (cursor.getInt(6) == 1) {
|
|
|
+ profile.mActivated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ profile.mIconName = cursor.getString(4);
|
|
|
+
|
|
|
+ // Adding record to list
|
|
|
+ profiles.add(profile);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+ // return record list
|
|
|
+ return profiles;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Persists the given profile into the database
|
|
|
+ *
|
|
|
+ * @param profile
|
|
|
+ * the profile which should be persisted
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public long persistProfile(Profile profile) {
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+
|
|
|
+ ContentValues values = new ContentValues();
|
|
|
+
|
|
|
+ if (profile.mId != -1) {
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_ID, profile.mId);
|
|
|
+ }
|
|
|
+
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_NAME, profile.mLabel);
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_DESCRIPTION, profile.mText);
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_ICON, profile.mIconPath);
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_ICON_NAME, profile.mIconName);
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_ACTIVE, profile.mActivated);
|
|
|
+ values.put(ProfileEntry.COLUMN_NAME_PROFILE_EDITABLE, profile.mEditable);
|
|
|
+
|
|
|
+ return db.replace(ProfileEntry.TABLE_NAME, null, values);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * private static final String CREATE_PROFILE_TABLE = "CREATE TABLE " +
|
|
|
+ * TABLE_PROFILES + "(" + KEY_PROFILE_ID +
|
|
|
+ * " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_PROFILE_NAME + " TEXT," +
|
|
|
+ * KEY_PROFILE_DESCRIPTION + " TEXT," + KEY_PROFILE_ICON + " TEXT," +
|
|
|
+ * KEY_PROFILE_ICON_ID + " INTEGER," + KEY_PROFILE_EDITABLE + " INTEGER," +
|
|
|
+ * KEY_PROFILE_ACTIVE + " INTEGER" + ")";
|
|
|
+ */
|
|
|
+ public Profile getProfile(int id) {
|
|
|
+ String selectQuery = "SELECT * FROM " + ProfileEntry.TABLE_NAME + " WHERE " + ProfileEntry.TABLE_NAME + "." + ProfileEntry.COLUMN_NAME_PROFILE_ID + " = " + id;
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+ Profile profile = null;
|
|
|
+
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(5) == 1);
|
|
|
+
|
|
|
+ if (cursor.getInt(6) == 1) {
|
|
|
+ profile.mActivated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ profile.mIconName = cursor.getString(5);
|
|
|
+ }
|
|
|
+
|
|
|
+ cursor.close();
|
|
|
+ db.close();
|
|
|
+
|
|
|
+ // return contact
|
|
|
+ return profile;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteProfile(int id) {
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+
|
|
|
+ db.delete(ProfileEntry.TABLE_NAME, ProfileEntry.COLUMN_NAME_PROFILE_ID + "=?", new String[] { String.valueOf(id) });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets all received {@link Record Records} for every attack identified by
|
|
|
+ * its attack id and ordered by date.
|
|
|
+ *
|
|
|
+ * @return A ArrayList with all received {@link Record Records} for each
|
|
|
+ * attack id in the Database.
|
|
|
+ */
|
|
|
+ public ArrayList<Record> getAllReceivedRecordsOfEachAttack() {
|
|
|
+ ArrayList<Record> recordList = new ArrayList<Record>();
|
|
|
+ String selectQuery = "SELECT * FROM " + PacketEntry.TABLE_NAME + " NATURAL JOIN " + AttackEntry.TABLE_NAME + " JOIN " + NetworkEntry.TABLE_NAME + " USING " + "(" + NetworkEntry.COLUMN_NAME_BSSID
|
|
|
+ + ")" + " WHERE " + PacketEntry.COLUMN_NAME_TYPE + "='RECEIVE'" + " ORDER BY " + PacketEntry.TABLE_NAME + "." + PacketEntry.COLUMN_NAME_PACKET_TIMESTAMP;
|
|
|
+ SQLiteDatabase db = this.getReadableDatabase();
|
|
|
+ Cursor cursor = db.rawQuery(selectQuery, null);
|
|
|
+
|
|
|
+ // looping through all rows and adding to list
|
|
|
+ if (cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ Record record = createRecord(cursor);
|
|
|
+ // Adding record to list
|
|
|
+ recordList.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ // return record list
|
|
|
+ db.close();
|
|
|
+ return recordList;
|
|
|
+ }
|
|
|
|
|
|
}
|