Skip to content

Commit

Permalink
Major update.
Browse files Browse the repository at this point in the history
- Some tests now replace 1337 characters for better matching
- Added an analyzer tab to test if a message would be blocked by Message Guard
- Replaced regex lookups with 'contains'.
- Misc changes and fixes.
  • Loading branch information
jdgregson committed Sep 19, 2022
1 parent 989667e commit 3a0295e
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 277 deletions.
2 changes: 2 additions & 0 deletions src/Message Guard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
AB6F664727B67941001DBA61 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF78D3A27B1FB270002B523 /* ContentView.swift */; };
ABA0B77128D2FE620072E902 /* MessageFilterExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF78D6827B1FBD70002B523 /* MessageFilterExtension.swift */; };
ABF78D3927B1FB270002B523 /* Message_GuardApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF78D3827B1FB270002B523 /* Message_GuardApp.swift */; };
ABF78D3D27B1FB2D0002B523 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ABF78D3C27B1FB2D0002B523 /* Assets.xcassets */; };
ABF78D4027B1FB2D0002B523 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ABF78D3F27B1FB2D0002B523 /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -333,6 +334,7 @@
files = (
AB6F664727B67941001DBA61 /* ContentView.swift in Sources */,
ABF78D3927B1FB270002B523 /* Message_GuardApp.swift in Sources */,
ABA0B77128D2FE620072E902 /* MessageFilterExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
159 changes: 141 additions & 18 deletions src/Message Guard/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ struct ContentView: View {
Image(systemName: "gearshape.fill")
Text("Setup")
}
AnalyzeView()
.tabItem {
Image(systemName: "text.magnifyingglass")
Text("Analyze")
}
}
}
}

struct TitleView<Content: View>: View {
let test = getLeetVariations(initialString: "tttt")
let content: Content

init(@ViewBuilder content: () -> Content) {
Expand Down Expand Up @@ -63,22 +69,22 @@ struct AboutView: View {
}
VStack(alignment: .leading) {
Label("Messages sent from email addresses (Email to Text)", systemImage: "envelope")
.padding(.bottom, 2)
.padding(.bottom, 2.0)
Label("Messages containing URLs with risky TLDs, such as .ru", systemImage: "link")
.padding(.bottom, 2)
.padding(.bottom, 2.0)
Label("Messages containing IP addresses", systemImage: "number")
.padding(.bottom, 2)
Label("Messages from full phone numbers (as opposed to SMS shortcodes) which mention popular banks", systemImage: "building.columns")
.padding(.bottom, 2)
Label("Messages containing common phishing ohrases", systemImage: "exclamationmark.bubble")
.padding(.bottom, 2)
.padding(.bottom, 2.0)
Label("Messages containing popular bank names which were not sent using an SMS shortcode", systemImage: "building.columns")
.padding(.bottom, 2.0)
Label("Messages containing common phishing phrases", systemImage: "exclamationmark.bubble")
.padding(.bottom, 2.0)
}
.padding(.all)
}
VStack {
GroupBox(label: Label("IMPORTANT", systemImage: "exclamationmark.triangle")) {
Text("Message Guard cannot filter messages from senders that are in your contacts or senders that you have replied to, as iOS does not send messages from known senders to message filters.")

}
}
VStack {
Expand Down Expand Up @@ -110,34 +116,34 @@ struct SetupView: View {
Text("To enable Message Guard:")
Spacer()
}
.padding(.bottom, 1)
.padding(.bottom, 1.0)
VStack(alignment: .leading) {
Label("Open Settings", systemImage: "1.circle.fill")
.padding(.bottom, 1)
.padding(.bottom, 1.0)
Label("Tap \"Messages\"", systemImage: "2.circle.fill")
.padding(.bottom, 1)
.padding(.bottom, 1.0)
Label("Tap \"Unknown & Spam\"", systemImage: "3.circle.fill")
.padding(.bottom, 1)
.padding(.bottom, 1.0)
Label("Enable \"Filter Unknown Senders\"", systemImage: "4.circle.fill")
.padding(.bottom, 1)
.padding(.bottom, 1.0)
Label("Under \"SMS FILTERING,\" select \"Message Guard\"", systemImage: "5.circle.fill")
}
}
.padding(.top, 2)
.padding(.top, 2.0)
}
GroupBox(label: Label("Filter a Sender", systemImage: "person.fill.xmark")) {
VStack(alignment: .leading) {
Text("To filter messages from a sender, make sure the sender is not in your contacts, delete any messages from and to the sender, and do not reply to messages from the sender. Replying to a sender tells Apple that you are interested in hearing from the sender and iOS will stop filtering messages from the sender through Message Guard.")
.padding(.bottom, 1)
Text("To filter messages from a sender, make sure the sender is not in your contacts, delete any messages from and to the sender, and do not reply to messages from the sender. Replying to a sender tells Apple that you are interested in receiving messages from the sender and iOS will stop filtering messages from the sender through Message Guard.")
.padding(.bottom, 1.0)
Text("If you want to stop receiving all messages from a given sender, blocking the sender would be a safer approach.")
}
.padding(.top, 2)
.padding(.top, 2.0)
}
GroupBox(label: Label("Stop Filtering a Sender", systemImage: "person.fill.checkmark")) {
VStack(alignment: .leading) {
Text("To prevent Message Guard from filtering any messages from a sender, you can add the sender to your contacts, or reply to a message from them two or more times. This will cause iOS to stop filtering messages from the sender through Message Guard.")
}
.padding(.top, 2)
.padding(.top, 2.0)
}
}
.padding(.all)
Expand All @@ -146,6 +152,123 @@ struct SetupView: View {
}
}

struct AnalyzeView: View {
@State private var messageSender = ""
@State private var messageBody = ""
@State var resultColor = Color(wordName: "red")
@State var resultImage = ""
@State var resultText = ""
@State var resultDetail = ""

var body: some View {
let messageSenderBinding = Binding<String>(get: {
self.messageSender
}, set: {
self.messageSender = $0
resultImage = ""
resultText = ""
resultDetail = ""
})

let messageBodyBinding = Binding<String>(get: {
self.messageBody
}, set: {
self.messageBody = $0
resultImage = ""
resultText = ""
resultDetail = ""
})

TitleView {
ScrollView {
VStack(alignment: .leading) {
VStack {
VStack {
Text("You can use the fields below to check if a message would be blocked by Message Guard and why it would be blocked.")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, 1.0)
Text("Some Message Guard filters consider both the sender and the message body, so be sure to include both for a more accurate analysis.")
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.bottom, 15.0)
VStack {
TextField("Sender", text: messageSenderBinding)
.padding(.leading, 4.0)
.frame(width: .infinity, height: 30.0)
.foregroundColor(.gray)
.overlay(
RoundedRectangle(cornerRadius: 7.0)
.stroke(.primary, lineWidth: 1.0)
)
TextEditor(text: messageBodyBinding)
.frame(width: .infinity, height: 200.0)
.foregroundColor(.gray)
.overlay(
RoundedRectangle(cornerRadius: 7.0)
.stroke(.primary, lineWidth: 1.0)
)
.padding(.bottom)
Button("Analyze")
{
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to:nil, from:nil, for:nil)
let results = analyzeMessage(messageBody: messageBody, messageSender: messageSender)
if (results.count > 0) {
resultColor = Color(wordName: "red")
resultImage = "x.circle.fill"
resultText = "This message is blocked by Message Guard."
resultDetail = "The message is blocked due to the following:\n" +
results.joined(separator: "\n")
} else {
resultColor = Color(wordName: "green")
resultImage = "checkmark.circle.fill"
resultText = "This message is not blocked by Message Guard."
resultDetail = ""
}
}
.padding(.all)
.background(Color(hex: 0x14b7f1))
.foregroundColor(.white)
.cornerRadius(7.0)
HStack {
Image(systemName: resultImage).foregroundColor(resultColor)
Text(resultText)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.top, 15.0)
Text(resultDetail)
.multilineTextAlignment(.leading)
.padding(.top, 5.0)
}
}
}
.padding(.all)
}
.onTapGesture {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to:nil, from:nil, for:nil)
}
}
}
}

extension Color {
init(hex: Int, opacity: Double = 1.0) {
let red = Double((hex & 0xff0000) >> 16) / 255.0
let green = Double((hex & 0xff00) >> 8) / 255.0
let blue = Double((hex & 0xff) >> 0) / 255.0
self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity)
}
}

extension Color {
init?(wordName: String) {
switch wordName {
case "red": self = .red
case "green": self = .green
default: return nil
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
Expand Down
Loading

0 comments on commit 3a0295e

Please sign in to comment.