-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored message parsing code. (#3)
Also ignore useless xmlns attributes.
- Loading branch information
Showing
7 changed files
with
233 additions
and
198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
module www.velocidex.com/golang/evtx | ||
|
||
require ( | ||
github.com/Velocidex/ordereddict v0.0.0-20191103011020-3b5a5f6957d4 | ||
github.com/Velocidex/ordereddict v0.0.0-20191106020901-97c468e5e403 | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 | ||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/mattn/go-sqlite3 v1.11.0 | ||
github.com/pkg/errors v0.8.1 | ||
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c // indirect | ||
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
www.velocidex.com/golang/go-pe v0.1.1-0.20191103232346-ac12e8190bb6 // indirect | ||
www.velocidex.com/golang/binparsergen v0.1.0 | ||
www.velocidex.com/golang/go-pe v0.1.1-0.20191103232346-ac12e8190bb6 | ||
) | ||
|
||
// replace www.velocidex.com/golang/go-pe => /home/mic/projects/go-pe/ | ||
//replace github.com/Velocidex/ordereddict => /home/mic/projects/ordereddict | ||
|
||
go 1.13 |
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,65 @@ | ||
package evtx | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
|
||
"github.com/Velocidex/ordereddict" | ||
) | ||
|
||
var ( | ||
expansion_re = regexp.MustCompile(`\%[0-9ntr]+`) | ||
system_root_re = regexp.MustCompile("(?i)%?SystemRoot%?") | ||
windir_re = regexp.MustCompile("(?i)%windir%") | ||
programfiles_re = regexp.MustCompile("(?i)%programfiles%") | ||
system32_re = regexp.MustCompile(`(?i)\\System32\\`) | ||
) | ||
|
||
func flatten(dict *ordereddict.Dict) []interface{} { | ||
result := []interface{}{} | ||
|
||
for _, k := range dict.Keys() { | ||
value, _ := dict.Get(k) | ||
|
||
switch t := value.(type) { | ||
case *ordereddict.Dict: | ||
result = append(result, flatten(t)...) | ||
default: | ||
result = append(result, value) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
func ExpandMessage(event_map *ordereddict.Dict, message string) string { | ||
data, pres := ordereddict.GetMap(event_map, "UserData") | ||
if !pres { | ||
data, pres = ordereddict.GetMap(event_map, "EventData") | ||
if !pres { | ||
return message | ||
} | ||
} | ||
expansions := flatten(data) | ||
|
||
return expansion_re.ReplaceAllStringFunc(message, func(match string) string { | ||
switch match { | ||
case "%n": | ||
return "\n" | ||
case "%r": | ||
return "" | ||
case "%t": | ||
return "\t" | ||
} | ||
|
||
number, _ := strconv.Atoi(match[1:]) | ||
|
||
// Regex expansions start at 1 | ||
number -= 1 | ||
if number >= 0 && number < len(expansions) { | ||
return fmt.Sprintf("%v", expansions[number]) | ||
} | ||
return match | ||
}) | ||
} |
Oops, something went wrong.