-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from jamf/stuartjash_v004
v004 - proc parser
- Loading branch information
Showing
9 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// ProcessParser.swift | ||
// aftermath | ||
// | ||
// Created by Stuart Ashenbrenner on 9/6/22. | ||
// | ||
|
||
import Foundation | ||
|
||
class ProcessParser: AftermathModule { | ||
|
||
let collectionDir: String | ||
let storylineFile: URL | ||
|
||
init(collectionDir: String, storylineFile: URL) { | ||
self.collectionDir = collectionDir | ||
self.storylineFile = storylineFile | ||
} | ||
|
||
func parseProcessDump() { | ||
|
||
let procPathRaw = "\(self.collectionDir)/Processes/process_dump.txt" | ||
do { | ||
|
||
let data = try String(contentsOf: URL(fileURLWithPath: procPathRaw), encoding: .utf8) | ||
let line = data.components(separatedBy: "\n") | ||
|
||
for ind in 1...line.count - 1 { | ||
let splitLine = line[ind].components(separatedBy: " ") | ||
|
||
guard let date = splitLine[safe: 0] else { continue } | ||
guard let time = splitLine[safe: 1] else { continue } | ||
guard let zone = splitLine[safe: 2] else { continue } | ||
let unformattedDate = date + "T" + time + zone // 2022-09-02T17:16:58 +0000 | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.locale = Locale(identifier: "en_US") | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" // 2022-09-02T17:16:58+0000 | ||
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) | ||
|
||
var info = "" | ||
for i in 3...splitLine.count - 1 { | ||
info = info.appending(" " + splitLine[i]) | ||
} | ||
|
||
sanatizeInfo(&info) | ||
|
||
guard let dateZone = dateFormatter.date(from: unformattedDate) else { continue } | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" | ||
let formattedDate = dateFormatter.string(from: dateZone) | ||
let text = "\(formattedDate), PROCESS, \(info)" | ||
self.addTextToFile(atUrl: self.storylineFile, text: text) | ||
} | ||
} catch { | ||
print("Error parsing process dump raw file: \(error)") | ||
} | ||
} | ||
|
||
fileprivate func sanatizeInfo(_ info: inout String) { | ||
info = info.replacingOccurrences(of: ",", with: "") | ||
info = info.replacingOccurrences(of: "\"", with: "") | ||
} | ||
|
||
func run() { | ||
self.log("Parsing process collection...") | ||
parseProcessDump() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters