MCPcopy Index your code
hub / github.com/codeyourweb/irma / MemoryAnalysisRoutine

Function MemoryAnalysisRoutine

procsmemory.go:26–67  ·  view source on GitHub ↗

MemoryAnalysisRoutine analyse processes memory every 5 seconds

(pDump string, pQuarantine string, pKill bool, pNotifications bool, pVerbose bool, pInfiniteLoop bool, rules *yara.Rules)

Source from the content-addressed store, hash-verified

24
25// MemoryAnalysisRoutine analyse processes memory every 5 seconds
26func MemoryAnalysisRoutine(pDump string, pQuarantine string, pKill bool, pNotifications bool, pVerbose bool, pInfiniteLoop bool, rules *yara.Rules) {
27 for {
28 // list process information and memory
29 procs := ListProcess(pVerbose)
30
31 // analyze process memory and executable
32 for _, proc := range procs {
33 // dump processes memory and quit the program
34 if len(pDump) > 0 {
35 if err := WriteProcessMemoryToFile(pDump, proc.ProcessName+fmt.Sprint(proc.PID)+".dmp", proc.MemoryDump); err != nil && pVerbose {
36 logMessage(LOG_ERROR, "[ERROR]", err)
37 }
38 }
39
40 // parsing kill queue
41 if StringInSlice(proc.ProcessPath, killQueue) && pKill {
42 logMessage(LOG_INFO, "[INFO]", "KILLING PID", proc.PID)
43 KillProcessByID(proc.PID, pVerbose)
44 } else {
45 // analyzing process memory and cleaning memory buffer
46 MemoryAnalysis(&proc, pQuarantine, pKill, pNotifications, pVerbose, rules)
47 proc.MemoryDump = nil
48
49 // analyzing process executable
50 FileAnalysis(proc.ProcessPath, pQuarantine, pKill, pNotifications, pVerbose, rules, "MEMORY")
51 }
52 }
53
54 if len(pDump) > 0 {
55 logMessage(LOG_INFO, "[INFO] Processes memory dump completed - Exiting program.")
56 os.Exit(0)
57 }
58
59 killQueue = nil
60 if !pInfiniteLoop {
61 wg.Done()
62 break
63 } else {
64 time.Sleep(5 * time.Second)
65 }
66 }
67}
68
69// ListProcess try to get all running processes and dump their memory, return a ProcessInformation slice
70func ListProcess(verbose bool) (procsInfo []ProcessInformation) {

Callers 1

mainFunction · 0.85

Calls 7

ListProcessFunction · 0.85
WriteProcessMemoryToFileFunction · 0.85
logMessageFunction · 0.85
StringInSliceFunction · 0.85
KillProcessByIDFunction · 0.85
MemoryAnalysisFunction · 0.85
FileAnalysisFunction · 0.85

Tested by

no test coverage detected