|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "os/exec" |
| 7 | +) |
| 8 | + |
| 9 | +//Reading executer.go |
| 10 | +// This file flows in building blocks, initially constructing the arguments that are passed. |
| 11 | +// Then the struct that is used to execute a command |
| 12 | +// The code that enables execution of the given struct |
| 13 | + |
| 14 | +// argsUpdater ... Updates the slice of arguments that are passed with the command to be executed. |
| 15 | +// if there are less than 4 arguments (ie, a path to an image, -o, and an offset (with no inode)) |
| 16 | +// Then the arguments are updated and the inode string is appended. Otherwise, just update the inode |
| 17 | +// value to the requested one. |
| 18 | +func argsUpdater(arguments []string, inode string) []string { |
| 19 | + if len(arguments) < 4 { |
| 20 | + arguments = append(arguments, inode) |
| 21 | + } |
| 22 | + arguments[3] = inode |
| 23 | + return arguments |
| 24 | +} |
| 25 | + |
| 26 | +// argsUpdaterRecover ... Updates the slice of arguments that are passed with the command to be executed. |
| 27 | +// if there are less than 5 arguments (ie, a path to an image, -o, an offset, -d and no inode) |
| 28 | +// Then the arguments are updated and the inode string is appended. Otherwise, just update the inode |
| 29 | +// value to the requested one. |
| 30 | +func argsUpdaterRecover(arguments []string, inode string, carveunallocated bool) []string { |
| 31 | + if len(arguments) < 6 { |
| 32 | + arguments = append(arguments, inode, "a") |
| 33 | + } |
| 34 | + if carveunallocated { |
| 35 | + arguments[5] = "e" |
| 36 | + } else { |
| 37 | + arguments[5] = "a" |
| 38 | + } |
| 39 | + arguments[4] = inode |
| 40 | + return arguments |
| 41 | +} |
| 42 | + |
| 43 | +// executeFLS ... Pass the command to be executed and its arguments as a slice of strings. |
| 44 | +// fills an item object with the current items for fls, for icat and tsk_recover it writes to a file. |
| 45 | +func executeFLS(args []string) bool { |
| 46 | + cmdStruct := exec.Command("fls", args...) |
| 47 | + cmdOutput := commandExecuter(cmdStruct) |
| 48 | + |
| 49 | + // Only attempt to populate the directory if the output of the fls command run contains stuff. |
| 50 | + if len(cmdOutput) > 0 { |
| 51 | + directory.populate(cmdOutput) |
| 52 | + return true |
| 53 | + } |
| 54 | + |
| 55 | + return false |
| 56 | +} |
| 57 | + |
| 58 | +// executeCarvers ... Pass the command to be executed and its arguments as a slice of strings. |
| 59 | +// Writes a directory or file and its mft information to a file specified by itemname. |
| 60 | +// Returns true on successful completion, false if no cases are met. |
| 61 | +func executeCarvers(cmd string, args []string, itemname string) bool { |
| 62 | + switch cmd { |
| 63 | + case "icat": |
| 64 | + icatstruct := exec.Command(cmd, args...) |
| 65 | + writeCmdToFile(itemname, icatstruct) |
| 66 | + istatstruct := exec.Command(cmd, args...) |
| 67 | + writeCmdToFile(itemname+".mft", istatstruct) |
| 68 | + return true |
| 69 | + case "tsk_recover": |
| 70 | + recoverstruct := exec.Command(cmd, args...) |
| 71 | + writeCmdToFile(itemname, recoverstruct) |
| 72 | + return true |
| 73 | + } |
| 74 | + return false |
| 75 | +} |
| 76 | + |
| 77 | +// commandExecuter ... Executes a command on the host given a command structure and |
| 78 | +// returns the output as a string. |
| 79 | +func commandExecuter(cmdstruct *exec.Cmd) string { |
| 80 | + // Define vars that will be used to store output and error of running the command. |
| 81 | + var ( |
| 82 | + cmdOutput []byte |
| 83 | + cmdErr error |
| 84 | + ) |
| 85 | + if cmdOutput, cmdErr = cmdstruct.Output(); cmdErr != nil { |
| 86 | + fmt.Fprintln(os.Stderr, cmdErr) |
| 87 | + os.Exit(1) |
| 88 | + } |
| 89 | + return string(cmdOutput) |
| 90 | +} |
0 commit comments