Skip to content

Commit

Permalink
GreenDao Helper Classes+Entity annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed May 28, 2020
1 parent eb950c2 commit 58be409
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 18 deletions.
11 changes: 10 additions & 1 deletion build.gradle
Expand Up @@ -10,9 +10,11 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin
}
}
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

repositories {
mavenCentral()
Expand All @@ -28,6 +30,7 @@ repositories {
dependencies {
implementation 'com.google.android.gms:play-services:4.+'
implementation 'org.roboguice:roboguice:2.0'
implementation 'org.greenrobot:greendao:3.3.0'
compile files('libs/nineoldandroids-2.4.0.jar')
//noinspection GradleCompatible
implementation 'com.android.support:support-v4:28.0.0'
Expand All @@ -49,7 +52,7 @@ dependencies {
//testImplementation 'androidx.test:core:1.2.0'

// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation "org.mockito:mockito-core:2.+"
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support.test:rules:1.0.2'
implementation 'com.android.support.test:runner:1.0.2'
Expand All @@ -61,10 +64,16 @@ dependencies {
implementation 'org.powermock:powermock-module-junit4:1.7.4'
implementation 'org.powermock:powermock-api-mockito:1.7.4'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'org.robolectric:robolectric:3.1'


}

greendao{
schemaVersion 1
// targetGenDir "src/db/"
}

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
Expand Down
50 changes: 45 additions & 5 deletions src/androidTest/java/hostage/logging/AttackRecordTest.java
Expand Up @@ -23,7 +23,7 @@ public class AttackRecordTest {
private String remoteIP;
private int remotePort;
private String externalIP;
private int wasInternalAttack;
private boolean wasInternalAttack;

@Before
public void setUp() {
Expand All @@ -36,8 +36,8 @@ public void setUp() {
localPort = 80;
remoteIP = "127.0.0.1";
remotePort = 3306;
externalIP = "127.0.0.1";
wasInternalAttack = 1;
externalIP = "127.0.1.1";
wasInternalAttack = true;


}
Expand All @@ -53,20 +53,60 @@ public void attackRecordParcelTest(){
parcel.writeString(remoteIP);
parcel.writeInt(remotePort);
parcel.writeString(externalIP);
parcel.writeInt(wasInternalAttack);
parcel.writeValue(wasInternalAttack);
parcel.writeString(bssid);
parcel.writeString(device);
parcel.writeLong(sync_id);

AttackRecord record = new AttackRecord(parcel);
System.out.println("meow");
System.out.println(record.getAttack_id());



/* assertTrue(record.getAttack_id() == 1234L);
assertTrue(record.getSync_id() == 1234L) ;
assertTrue(record.getLocalIP().equals("127.0.0.1"));
assertTrue(record.getLocalPort() == 80) ;
assertTrue(record.getRemoteIP().equals("127.0.0.1"));
assertTrue(record.getRemotePort() == 3306) ;
assertTrue(record.getExternalIP().equals("127.0.1.1"));
assertTrue(record.getWasInternalAttack()) ;
assertTrue(record.getBssid().equals("Test"));
assertTrue(record.getDevice().equals("TestDevice"));
assertTrue(record.getProtocol().equals("Http"));
*/

}



@Test
public void attackRecordTest(){


AttackRecord record = new AttackRecord();


record.setExternalIP(externalIP);
record.setAttack_id(attack_id);
record.setSync_id(sync_id);
record.setLocalIP(localIP);
record.setLocalPort(localPort);
record.setRemoteIP(remoteIP);
record.setRemotePort(remotePort);
record.setWasInternalAttack(wasInternalAttack);
record.setBssid(bssid);
record.setDevice(device);
record.setProtocol(protocol);

assertTrue(record.getAttack_id() == 1234L);
assertTrue(record.getSync_id() == 1234L) ;
assertTrue(record.getLocalIP().equals("127.0.0.1"));
assertTrue(record.getLocalPort() == 80) ;
assertTrue(record.getRemoteIP().equals("127.0.0.1"));
assertTrue(record.getRemotePort() == 3306) ;
assertTrue(record.getExternalIP().equals("127.0.0.1"));
assertTrue(record.getExternalIP().equals("127.0.1.1"));
assertTrue(record.getWasInternalAttack()) ;
assertTrue(record.getBssid().equals("Test"));
assertTrue(record.getDevice().equals("TestDevice"));
Expand Down
41 changes: 33 additions & 8 deletions src/de/tudarmstadt/informatik/hostage/logging/AttackRecord.java
Expand Up @@ -7,16 +7,21 @@
import android.os.Parcelable;
import android.preference.PreferenceManager;

import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
import org.greenrobot.greendao.annotation.Generated;

/**
* Holds all necessary information about a single attack.
*/
@Entity(nameInDb = "attack")
public class AttackRecord implements Parcelable, Serializable {

@Transient
private static final long serialVersionUID = 6111024905373724227L;

@Id(autoincrement = true)
private long attack_id;
private long sync_id;
private String bssid;
Expand All @@ -27,7 +32,7 @@ public class AttackRecord implements Parcelable, Serializable {
private String remoteIP;
private int remotePort;
private String externalIP;
private int wasInternalAttack; // 1 if attacker ip and local ip were in same subnet, else 0
private boolean wasInternalAttack= true;

public static final Parcelable.Creator<AttackRecord> CREATOR = new Parcelable.Creator<AttackRecord>() {
@Override
Expand All @@ -53,7 +58,7 @@ public AttackRecord(Parcel source) {
this.remoteIP = source.readString();
this.remotePort = source.readInt();
this.externalIP = source.readString();
this.wasInternalAttack = source.readInt();
this.wasInternalAttack = source.readByte() != 0;
this.bssid = source.readString();
this.device = source.readString();
this.sync_id = source.readLong();
Expand All @@ -77,6 +82,23 @@ public AttackRecord(boolean autoincrement){

}

@Generated(hash = 392632362)
public AttackRecord(long attack_id, long sync_id, String bssid, String device, String protocol,
String localIP, int localPort, String remoteIP, int remotePort, String externalIP,
boolean wasInternalAttack) {
this.attack_id = attack_id;
this.sync_id = sync_id;
this.bssid = bssid;
this.device = device;
this.protocol = protocol;
this.localIP = localIP;
this.localPort = localPort;
this.remoteIP = remoteIP;
this.remotePort = remotePort;
this.externalIP = externalIP;
this.wasInternalAttack = wasInternalAttack;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -91,7 +113,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(remoteIP);
dest.writeInt(remotePort);
dest.writeString(externalIP);
dest.writeInt(wasInternalAttack);
dest.writeByte((byte) (wasInternalAttack ? 1 : 0));
dest.writeString(bssid);
dest.writeString(device);
dest.writeLong(sync_id);
Expand Down Expand Up @@ -221,6 +243,9 @@ public void setExternalIP(String externalIP) {
this.externalIP = externalIP;
}

public boolean getWasInternalAttack() {return wasInternalAttack == 1;}
public void setWasInternalAttack(boolean b) {wasInternalAttack = b ? 1 : 0;}
public boolean getWasInternalAttack() {return wasInternalAttack;}

public void setWasInternalAttack(boolean wasInternalAttack) {
this.wasInternalAttack = wasInternalAttack;
}
}
16 changes: 16 additions & 0 deletions src/de/tudarmstadt/informatik/hostage/logging/MessageRecord.java
Expand Up @@ -7,11 +7,17 @@
import android.os.Parcelable;
import android.preference.PreferenceManager;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
import org.greenrobot.greendao.annotation.Generated;

/**
* Holds all necessary information about a single message exchanged during an attack.
*/
@Entity
public class MessageRecord implements Parcelable, Serializable{

private static final long serialVersionUID = -5936572995202342935L;
Expand All @@ -21,9 +27,11 @@ public enum TYPE {
}

// attack
@Id
private int id;
private long attack_id;
private long timestamp;
@Transient
private TYPE type;
private String packet;

Expand Down Expand Up @@ -64,6 +72,14 @@ public MessageRecord(Parcel source) {
this.packet = source.readString();
}

@Generated(hash = 1546530353)
public MessageRecord(int id, long attack_id, long timestamp, String packet) {
this.id = id;
this.attack_id = attack_id;
this.timestamp = timestamp;
this.packet = packet;
}


@Override
public int describeContents() {
Expand Down
17 changes: 16 additions & 1 deletion src/de/tudarmstadt/informatik/hostage/logging/NetworkRecord.java
Expand Up @@ -5,13 +5,18 @@
import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

/**
* Holds all necessary information about a single network.
*/
@Entity
public class NetworkRecord implements Parcelable, Serializable {

private static final long serialVersionUID = -1586629159904177836L;

@Id
private String bssid;
private String ssid;
private long timestampLocation;
Expand Down Expand Up @@ -45,6 +50,16 @@ public NetworkRecord(Parcel source) {
this.accuracy = source.readFloat();
}

@Generated(hash = 1853639091)
public NetworkRecord(String bssid, String ssid, long timestampLocation, double latitude, double longitude, float accuracy) {
this.bssid = bssid;
this.ssid = ssid;
this.timestampLocation = timestampLocation;
this.latitude = latitude;
this.longitude = longitude;
this.accuracy = accuracy;
}

@Override
public int describeContents() {
return 0;
Expand Down
@@ -1,20 +1,37 @@
package de.tudarmstadt.informatik.hostage.logging;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;

import java.io.Serializable;
import org.greenrobot.greendao.annotation.Generated;

/**
* Holds the Information a specific device gathered about a network identified by its BSSID.
* @author Lars Pandikow
*/
@Entity
public class SyncInfoRecord implements Serializable{

private static final long serialVersionUID = 7156818788190434192L;

@Id
private String deviceID;
private String BSSID;
private long number_of_attacks;
private long number_of_portscans;

@Generated(hash = 1640797190)
public SyncInfoRecord(String deviceID, String BSSID, long number_of_attacks,
long number_of_portscans) {
this.deviceID = deviceID;
this.BSSID = BSSID;
this.number_of_attacks = number_of_attacks;
this.number_of_portscans = number_of_portscans;
}
@Generated(hash = 1014952315)
public SyncInfoRecord() {
}

/**
* @return the deviceID
*/
Expand Down

0 comments on commit 58be409

Please sign in to comment.