Skip to content

Commit ab6b092

Browse files
committed
Bundle Redis
1 parent 290c0f5 commit ab6b092

13 files changed

Lines changed: 1476 additions & 77 deletions

File tree

AdversaryLabSwift.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
460CF7DA20758D2C00FB3723 /* redis-server in Resources */ = {isa = PBXBuildFile; fileRef = 460CF7D220758D2C00FB3723 /* redis-server */; };
11+
460CF7DD2076AFDA00FB3723 /* RedisServerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460CF7DC2076AFDA00FB3723 /* RedisServerController.swift */; };
12+
460CF7E62076C3D800FB3723 /* LaunchRedisServerScript.sh in Resources */ = {isa = PBXBuildFile; fileRef = 460CF7E52076C3D800FB3723 /* LaunchRedisServerScript.sh */; };
13+
460CF7E82076C76D00FB3723 /* ShutdownRedisServerScript.sh in Resources */ = {isa = PBXBuildFile; fileRef = 460CF7E72076C76D00FB3723 /* ShutdownRedisServerScript.sh */; };
14+
460CF7EA2076EB0800FB3723 /* redis.conf in Resources */ = {isa = PBXBuildFile; fileRef = 460CF7E92076EB0800FB3723 /* redis.conf */; };
15+
460CF7EC2076F75A00FB3723 /* redis-cli in Resources */ = {isa = PBXBuildFile; fileRef = 460CF7EB2076F75A00FB3723 /* redis-cli */; };
1016
46175B6920253F86009311D6 /* FakeConnectionGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46175B6820253F86009311D6 /* FakeConnectionGenerator.swift */; };
1117
46175B6C202CE3DB009311D6 /* Entropy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46175B6B202CE3DB009311D6 /* Entropy.swift */; };
1218
46175B75202D2CDE009311D6 /* ConnectionInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46175B74202D2CDE009311D6 /* ConnectionInspector.swift */; };
@@ -124,6 +130,12 @@
124130

125131
/* Begin PBXFileReference section */
126132
46037C7A200FDB5100FC368F /* AdversaryLabSwiftPackage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = AdversaryLabSwiftPackage.xcodeproj; path = ../AdversaryLabSwiftPackage/AdversaryLabSwiftPackage.xcodeproj; sourceTree = "<group>"; };
133+
460CF7D220758D2C00FB3723 /* redis-server */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = "redis-server"; sourceTree = "<group>"; };
134+
460CF7DC2076AFDA00FB3723 /* RedisServerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedisServerController.swift; sourceTree = "<group>"; };
135+
460CF7E52076C3D800FB3723 /* LaunchRedisServerScript.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = LaunchRedisServerScript.sh; sourceTree = "<group>"; };
136+
460CF7E72076C76D00FB3723 /* ShutdownRedisServerScript.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = ShutdownRedisServerScript.sh; sourceTree = "<group>"; };
137+
460CF7E92076EB0800FB3723 /* redis.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = redis.conf; sourceTree = "<group>"; };
138+
460CF7EB2076F75A00FB3723 /* redis-cli */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = "redis-cli"; sourceTree = "<group>"; };
127139
46175B6820253F86009311D6 /* FakeConnectionGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeConnectionGenerator.swift; sourceTree = "<group>"; };
128140
46175B6B202CE3DB009311D6 /* Entropy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Entropy.swift; sourceTree = "<group>"; };
129141
46175B74202D2CDE009311D6 /* ConnectionInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionInspector.swift; sourceTree = "<group>"; };
@@ -196,6 +208,7 @@
196208
children = (
197209
46175B6820253F86009311D6 /* FakeConnectionGenerator.swift */,
198210
46175B74202D2CDE009311D6 /* ConnectionInspector.swift */,
211+
460CF7DC2076AFDA00FB3723 /* RedisServerController.swift */,
199212
);
200213
path = Controllers;
201214
sourceTree = "<group>";
@@ -212,6 +225,11 @@
212225
4651A14420083BF700037D31 = {
213226
isa = PBXGroup;
214227
children = (
228+
460CF7E72076C76D00FB3723 /* ShutdownRedisServerScript.sh */,
229+
460CF7E52076C3D800FB3723 /* LaunchRedisServerScript.sh */,
230+
460CF7E92076EB0800FB3723 /* redis.conf */,
231+
460CF7D220758D2C00FB3723 /* redis-server */,
232+
460CF7EB2076F75A00FB3723 /* redis-cli */,
215233
CA727CD32050A3580051A01B /* README.md */,
216234
4651A1A62009401F00037D31 /* AdversaryLabSwiftTests */,
217235
4651A14F20083BF700037D31 /* AdversaryLabSwift */,
@@ -460,7 +478,12 @@
460478
files = (
461479
CA727CD42050A3580051A01B /* README.md in Resources */,
462480
4651A15520083BF700037D31 /* Assets.xcassets in Resources */,
481+
460CF7E62076C3D800FB3723 /* LaunchRedisServerScript.sh in Resources */,
463482
4651A15820083BF700037D31 /* Main.storyboard in Resources */,
483+
460CF7E82076C76D00FB3723 /* ShutdownRedisServerScript.sh in Resources */,
484+
460CF7EC2076F75A00FB3723 /* redis-cli in Resources */,
485+
460CF7DA20758D2C00FB3723 /* redis-server in Resources */,
486+
460CF7EA2076EB0800FB3723 /* redis.conf in Resources */,
464487
);
465488
runOnlyForDeploymentPostprocessing = 0;
466489
};
@@ -489,6 +512,7 @@
489512
46175B75202D2CDE009311D6 /* ConnectionInspector.swift in Sources */,
490513
46175B6C202CE3DB009311D6 /* Entropy.swift in Sources */,
491514
46175B78202D4545009311D6 /* PacketLengths.swift in Sources */,
515+
460CF7DD2076AFDA00FB3723 /* RedisServerController.swift in Sources */,
492516
46175B7A202D466A009311D6 /* Timing.swift in Sources */,
493517
CAA6C98320642A2D00EE8DF1 /* KnownProtocols.swift in Sources */,
494518
46175B6920253F86009311D6 /* FakeConnectionGenerator.swift in Sources */,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

AdversaryLabSwift.xcodeproj/xcuserdata/Lita.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,70 +37,6 @@
3737
landmarkType = "7">
3838
</BreakpointContent>
3939
</BreakpointProxy>
40-
<BreakpointProxy
41-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
42-
<BreakpointContent
43-
shouldBeEnabled = "No"
44-
ignoreCount = "0"
45-
continueAfterRunningActions = "No"
46-
filePath = "AdversaryLabSwiftPackage/.build/checkouts/Redshot.git--1606376773459246887/Sources/RedShot/RedisSocket.swift"
47-
timestampString = "544055825.267658"
48-
startingColumnNumber = "9223372036854775807"
49-
endingColumnNumber = "9223372036854775807"
50-
startingLineNumber = "55"
51-
endingLineNumber = "55"
52-
landmarkName = "send(_:)"
53-
landmarkType = "7">
54-
<Locations>
55-
<Location
56-
shouldBeEnabled = "No"
57-
ignoreCount = "0"
58-
continueAfterRunningActions = "No"
59-
symbolName = "RedShot.RedisSocket.send(Foundation.Data) throws -&gt; ()"
60-
moduleName = "RedShot"
61-
usesParentBreakpointCondition = "Yes"
62-
urlString = "file:///Users/Lita/Dev/AdversaryLabSwift/AdversaryLabSwiftPackage/.build/checkouts/Redshot.git--1606376773459246887/Sources/RedShot/RedisSocket.swift"
63-
timestampString = "543950067.492148"
64-
startingColumnNumber = "9223372036854775807"
65-
endingColumnNumber = "9223372036854775807"
66-
startingLineNumber = "55"
67-
endingLineNumber = "55"
68-
offsetFromSymbolStart = "217">
69-
</Location>
70-
<Location
71-
shouldBeEnabled = "No"
72-
ignoreCount = "0"
73-
continueAfterRunningActions = "No"
74-
symbolName = "closure #1 (Swift.Optional&lt;Swift.Error&gt;) -&gt; () in RedShot.RedisSocket.send(Foundation.Data) throws -&gt; ()"
75-
moduleName = "RedShot"
76-
usesParentBreakpointCondition = "Yes"
77-
urlString = "file:///Users/Lita/Dev/AdversaryLabSwift/AdversaryLabSwiftPackage/.build/checkouts/Redshot.git--1606376773459246887/Sources/RedShot/RedisSocket.swift"
78-
timestampString = "543950067.496508"
79-
startingColumnNumber = "9223372036854775807"
80-
endingColumnNumber = "9223372036854775807"
81-
startingLineNumber = "58"
82-
endingLineNumber = "58"
83-
offsetFromSymbolStart = "18">
84-
</Location>
85-
</Locations>
86-
</BreakpointContent>
87-
</BreakpointProxy>
88-
<BreakpointProxy
89-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
90-
<BreakpointContent
91-
shouldBeEnabled = "No"
92-
ignoreCount = "0"
93-
continueAfterRunningActions = "No"
94-
filePath = "AdversaryLabSwiftPackage/.build/checkouts/Redshot.git--1606376773459246887/Sources/RedShot/RedisSocket.swift"
95-
timestampString = "544055825.267749"
96-
startingColumnNumber = "9223372036854775807"
97-
endingColumnNumber = "9223372036854775807"
98-
startingLineNumber = "58"
99-
endingLineNumber = "58"
100-
landmarkName = "send(_:)"
101-
landmarkType = "7">
102-
</BreakpointContent>
103-
</BreakpointProxy>
10440
<BreakpointProxy
10541
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
10642
<BreakpointContent

AdversaryLabSwift.xcodeproj/xcuserdata/Lita.xcuserdatad/xcschemes/AdversaryLabSwift.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0920"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -76,7 +75,6 @@
7675
buildConfiguration = "Debug"
7776
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7877
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
79-
language = ""
8078
launchStyle = "0"
8179
useCustomWorkingDirectory = "NO"
8280
ignoresPersistentStateOnLaunch = "NO"

AdversaryLabSwift/AppDelegate.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,31 @@
99
import Cocoa
1010

1111
@NSApplicationMain
12-
class AppDelegate: NSObject, NSApplicationDelegate {
13-
14-
15-
16-
func applicationDidFinishLaunching(_ aNotification: Notification) {
17-
// Insert code here to initialize your application
12+
class AppDelegate: NSObject, NSApplicationDelegate
13+
{
14+
15+
func applicationWillBecomeActive(_ notification: Notification)
16+
{
17+
// Launch Redis Server
18+
print("Launching Redis Server!")
19+
RedisServerController.sharedInstance.launchRedisServer()
20+
}
21+
22+
func applicationDidFinishLaunching(_ aNotification: Notification)
23+
{
24+
1825
}
1926

20-
func applicationWillTerminate(_ aNotification: Notification) {
21-
// Insert code here to tear down your application
27+
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
28+
// Quit Redis Server
29+
print("TERMINATE Redis Server. 🤖")
30+
RedisServerController.sharedInstance.shutdownRedisServer()
31+
sleep(1)
32+
return NSApplication.TerminateReply.terminateNow
33+
}
34+
func applicationWillTerminate(_ aNotification: Notification)
35+
{
36+
2237
}
2338

2439

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//
2+
// RedisServerController.swift
3+
// AdversaryLabSwift
4+
//
5+
// Created by Adelita Schule on 4/5/18.
6+
// Copyright © 2018 Operator Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class RedisServerController: NSObject
12+
{
13+
static let sharedInstance = RedisServerController()
14+
15+
var redisProcess:Process!
16+
17+
func launchRedisServer()
18+
{
19+
let bundle = Bundle.main
20+
21+
guard let redisPath = bundle.path(forResource: "redis-server", ofType: nil)
22+
else
23+
{
24+
print("Unable to launch Redis server. Could not find terraform executable.")
25+
return
26+
}
27+
28+
guard let redisConfigPath = bundle.path(forResource: "redis", ofType: "conf")
29+
else
30+
{
31+
print("Unable to launch Redis server. Could not find terraform executable.")
32+
return
33+
}
34+
35+
guard let path = bundle.path(forResource: "LaunchRedisServerScript", ofType: "sh")
36+
else
37+
{
38+
print("Unable to launch Redis server. Could not find the script.")
39+
return
40+
}
41+
42+
print("\n👇👇 Running Script 👇👇:\n")
43+
print("Path 🚶‍♀️: \n\(path)\n")
44+
print("Arguments: \n\(redisPath)\n\(redisConfigPath)\n")
45+
runRedisScript(path: path, arguments: [redisPath, redisConfigPath])
46+
{
47+
(hasCompleted) in
48+
49+
print("🚀 Launch Redis Server Script Complete 🚀")
50+
}
51+
}
52+
53+
func shutdownRedisServer()
54+
{
55+
if redisProcess != nil
56+
{
57+
if redisProcess.isRunning
58+
{
59+
redisProcess.terminate()
60+
}
61+
}
62+
63+
guard let path = Bundle.main.path(forResource: "ShutdownRedisServerScript", ofType: "sh")
64+
else
65+
{
66+
print("Unable to shutdown Redis server. Could not find the script.")
67+
return
68+
}
69+
70+
guard let redisPath = Bundle.main.path(forResource: "redis-cli", ofType: nil)
71+
else
72+
{
73+
print("Unable to launch Redis server. Could not find terraform executable.")
74+
return
75+
}
76+
77+
print("\n👇👇 Running Script 👇👇:\n")
78+
print("Path 🚶‍♀️: \n\(path)\n")
79+
80+
runRedisScript(path: path, arguments: [redisPath])
81+
{
82+
(taskCompleted) in
83+
84+
print("Server has been 🤖 TERMINATED 🤖")
85+
}
86+
}
87+
88+
func runRedisScript(path: String, arguments: [String]?, completion:@escaping (_ completion:Bool) -> Void)
89+
{
90+
let processQueue = DispatchQueue.global(qos: .background)
91+
processQueue.async
92+
{
93+
print("🚀🚀🚀🚀🚀🚀🚀")
94+
self.redisProcess = Process()
95+
self.redisProcess.launchPath = path
96+
97+
if let arguments = arguments
98+
{
99+
self.redisProcess.arguments = arguments
100+
}
101+
102+
self.redisProcess.terminationHandler =
103+
{
104+
(task) in
105+
106+
//Main Thread Stuff Here If Needed
107+
DispatchQueue.main.async(execute:
108+
{
109+
print("Redis Script Has Terminated.")
110+
completion(true)
111+
})
112+
}
113+
self.redisProcess.launch()
114+
}
115+
}
116+
}
117+

AdversaryLabSwiftTests/AdversaryLabSwiftTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class AdversaryLabSwiftTests: XCTestCase
3030
goTo(urlPath: "https://github.com")
3131
goTo(urlPath: "https://www.clcboats.com")
3232
goTo(urlPath: "https://imgur.com")
33-
goTo(urlPath: "https://www.nasa.gov")
34-
goTo(urlPath: "https://hyperboleandahalf.blogspot.com")
33+
goTo(urlPath: "https://www.cooksillustrated.com")
34+
goTo(urlPath: "https://www.npr.org")
3535
goTo(urlPath: "https://store.dftba.com")
3636
goTo(urlPath: "https://www.livescience.com/countdowns")
3737
}

LaunchRedisServerScript.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "*******Launch Redis Server"
4+
"$1" "$2"

ShutdownRedisServerScript.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "Shutdown Redis Server*******"
4+
"$1" shutdown

0 commit comments

Comments
 (0)