Skip to content

Commit

Permalink
Fixed issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome committed Nov 5, 2020
1 parent 5a7271a commit 6229580
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
17 changes: 9 additions & 8 deletions evtx/evtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ func (ef *File) FetchChunk(offset int64) (Chunk, error) {

// Chunks returns a chan of all the Chunks found in the current file
// return (chan Chunk)
// TODO: need to be improved: the chunk do not need to be loaded into memory there
// we just need the header to sort them out. If we do so, do not need undordered chunks
func (ef *File) Chunks() (cc chan Chunk) {
ss := datastructs.NewSortedSlice(0, int(ef.Header.ChunkCount))
cc = make(chan Chunk)
Expand Down Expand Up @@ -373,10 +371,17 @@ func (ef *File) Events() (cgem chan *GoEvtxMap) {
go func() {
defer close(cgem)
for c := range ef.Chunks() {
for e := range c.Events() {
cgem <- e
cpc, err := ef.FetchChunk(c.Offset)
switch {
case err != nil && err != io.EOF:
panic(err)
case err == nil:
for ev := range cpc.Events() {
cgem <- ev
}
}
}

}()
return
}
Expand All @@ -392,10 +397,6 @@ func (ef *File) FastEvents() (cgem chan *GoEvtxMap) {
go func() {
defer close(chanQueue)
for pc := range ef.Chunks() {
// We have to create a copy here because otherwise cpc.EventsChan() fails
// I guess that because EventsChan takes a pointer to an object and that
// and thus the chan is taken on the pointer and since the object pointed
// changes -> kaboom
cpc, err := ef.FetchChunk(pc.Offset)
switch {
case err != nil && err != io.EOF:
Expand Down
29 changes: 18 additions & 11 deletions evtx/test/evtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/0xrawsec/golang-utils/datastructs"

"github.com/0xrawsec/golang-evtx/evtx"
"github.com/0xrawsec/golang-utils/log"
)
Expand Down Expand Up @@ -145,20 +147,25 @@ loop:
}

func TestParseAllEvents(t *testing.T) {
maxChunks := 1000
chunkCount := 0
ef, _ := evtx.Open(forwardedEvtxFile)
eventCnt := 0
recordIds := datastructs.NewSyncedSet()
ef, err := evtx.OpenDirty(sysmonFile)
if err != nil {
t.Logf("Failed at opening EVTX file: %s", err)
t.Fail()
}
log.Info(ef.Header)
for c := range ef.Chunks() {
//log.Info(c.Header)
if chunkCount >= maxChunks && maxChunks >= 0 {
break
}
for e := range c.Events() {
t.Log(string(evtx.ToJSON(e)))
for e := range ef.Events() {
if recordIds.Contains(e.EventRecordID()) {
t.Log("Event already processed")
t.Fail()
}
chunkCount++
//t.Log(string(evtx.ToJSON(e)))
recordIds.Add(e.EventRecordID())
eventCnt++

}
t.Logf("%d events parsed", eventCnt)
}

func TestParseChunk(t *testing.T) {
Expand Down

0 comments on commit 6229580

Please sign in to comment.