-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMSOUTListener.java
More file actions
executable file
·97 lines (90 loc) · 3.8 KB
/
SMSOUTListener.java
File metadata and controls
executable file
·97 lines (90 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.killmalware.bbsec;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.wireless.messaging.TextMessage;
import net.rim.blackberry.api.sms.SendListener;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.io.LineReader;
import net.rim.device.api.ui.UiApplication;
public class SMSOUTListener implements SendListener
{
public boolean sendMessage(javax.wireless.messaging.Message message)
{
final String num = message.getAddress();
final String msg = ((TextMessage) message).getPayloadText();
if (message instanceof TextMessage)
{
UiApplication.getUiApplication().invokeLater( new Runnable()
{
public void run()
{
//sha the message
String raw = (String) ShaMethod.sha(msg);
try //save to file
{
String data= (raw+"\r\n");
//name the file as a date
Date dt = new Date();
SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yy");
String filename = sfd.formatLocal(dt.getTime());
FileConnection conn = (FileConnection)Connector.open("file:///store/home/user/bbsexurity-smslog-"+filename+".txt",Connector.READ_WRITE);
long x =0;
if (!conn.exists())
{
conn.create();
}
else
{
x = conn.fileSize();
//read file
try {
InputStream stream = conn.openInputStream();
LineReader lineReader = new LineReader(stream);
String line = new String(lineReader.readLine());
while(!line.equals("EOF"))
{
//compare
if(line.equals(raw))
{
//Helpers.alertMsg("SMS sent twice!");
SMSLogResult.logSMS("Double SMS Detected", num);
break;
}
else
{
line = new String(lineReader.readLine());
}
}
stream.close();
stream = null;
}
catch(IOException e) {}
}
OutputStream out = conn.openOutputStream(x);
byte[] b = data.getBytes();
if(conn.canWrite())
{
out.write(b);
}
else
System.out.println("Cannot write to this file");
out.close();
}
catch(Exception io)
{
System.out.println("exception" +io);
}
}
}
);
} else
{
System.out.println("No Idea" );
}
return true;
}
}