Skip to content

Commit c30f363

Browse files
author
Etienne Stalmans
committed
Attempt to fix parsing of rule action blocks. Previously I did not take into account that there could be more than one action block in a response.
This should fix that by checking the NoOfActions value and parsing out any action blocks associated with it. TODO: look into extended rules. these will still cause issues. need to find a away to identify that extended rules are returned
1 parent a07f8f0 commit c30f363

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

mapi/datastructs.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,16 +1899,24 @@ func (queryRows *RopQueryRowsResponse) Unmarshal(resp []byte, properties []Prope
18991899
//Unmarshal the ruleaction and then add it into the ValueArray again. messy
19001900
//or grab the action len, which is the second uint16 and use this to determine how much to read
19011901
//read ahead to get the length
1902-
_, pos = utils.ReadUint16(pos, resp)
1902+
noofActions := uint16(0)
1903+
noofActions, pos = utils.ReadUint16(pos, resp) //NoOfActions - this is 2bytes for normal rules, 4 for extended
1904+
utils.Info.Println("NoOfActttions: ", noofActions)
19031905
//read length but don't advance the buffer
1904-
l, _ := utils.ReadUint16(pos, resp)
1905-
//read the whole RuleAction into the valueArray, this means
1906-
pos -= 2 //reset the position
1907-
if pos+int(l+4) > len(resp) {
1908-
break
1909-
} else {
1910-
trow.ValueArray, pos = utils.ReadBytes(pos, int(l+4), resp)
1906+
trow.ValueArray = []byte{}
1907+
for x := 0; x < int(noofActions); x++ {
1908+
l, _ := utils.ReadUint16(pos, resp) //length is part of the RuleAction in an ActionBlock
1909+
//read the whole RuleAction into the valueArray, this means
1910+
pos -= 2 //reset the position
1911+
if pos+int(l+4) > len(resp) {
1912+
break
1913+
} else {
1914+
tk := []byte{}
1915+
tk, pos = utils.ReadBytes(pos, int(l+4), resp)
1916+
trow.ValueArray = append(trow.ValueArray, tk...)
1917+
}
19111918
}
1919+
//if NoOfActions > 1 read the rest of the actions
19121920
rows[k] = append(rows[k], trow)
19131921
}
19141922
}

ruler.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ func connect(c *cli.Context) error {
512512

513513
func printRules() error {
514514
//rules, er := mapi.DisplayRules()
515-
cols := make([]mapi.PropertyTag, 2)
515+
cols := make([]mapi.PropertyTag, 3)
516516
cols[0] = mapi.PidTagRuleName
517517
cols[1] = mapi.PidTagRuleID
518-
//cols[2] = mapi.PidTagRuleActions
518+
cols[2] = mapi.PidTagRuleActions
519519

520520
rows, er := mapi.FetchRules(cols)
521521

@@ -533,30 +533,31 @@ func printRules() error {
533533
}
534534
}
535535
maxwidth -= 10
536-
fmstr1 := fmt.Sprintf("%%-%ds | %%-16s \n", maxwidth)
537-
fmstr2 := fmt.Sprintf("%%-%ds | %%x \n", maxwidth)
538-
utils.Info.Printf(fmstr1, "Rule Name", "Rule ID")
539-
utils.Info.Printf("%s|%s\n", (strings.Repeat("-", maxwidth+1)), strings.Repeat("-", 18))
536+
fmstr1 := fmt.Sprintf("%%-%ds | %%-16s | %%-s \n", maxwidth)
537+
fmstr2 := fmt.Sprintf("%%-%ds | %%x | %%s\n", maxwidth)
538+
utils.Info.Printf(fmstr1, "Rule Name", "Rule ID", "Run Application")
539+
utils.Info.Printf("%s|%s|%s\n", (strings.Repeat("-", maxwidth+1)), strings.Repeat("-", 18), strings.Repeat("-", 18))
540540
for k := 0; k < int(rows.RowCount); k++ {
541541
clientSide := false
542542
clientApp := ""
543-
/*
544-
rd := mapi.RuleAction{}
545-
rd.Unmarshal(rows.RowData[k][2].ValueArray)
546-
if rd.ActionType == 0x05 {
547-
for _, a := range rd.ActionData.Conditions {
548-
if a.Tag[1] == 0x49 {
549-
clientSide = true
550-
clientApp = string(utils.FromUnicode(a.Value))
551-
break
552-
}
543+
544+
rd := mapi.RuleAction{}
545+
rd.Unmarshal(rows.RowData[k][2].ValueArray)
546+
if rd.ActionType == 0x05 {
547+
for _, a := range rd.ActionData.Conditions {
548+
if a.Tag[1] == 0x49 {
549+
clientSide = true
550+
clientApp = string(utils.FromUnicode(a.Value))
551+
break
553552
}
554553
}
555-
*/
554+
555+
}
556+
556557
if clientSide == true {
557558
utils.Info.Printf(fmstr2, string(utils.FromUnicode(rows.RowData[k][0].ValueArray)), rows.RowData[k][1].ValueArray, fmt.Sprintf("* %s", clientApp))
558559
} else {
559-
utils.Info.Printf(fmstr2, string(utils.FromUnicode(rows.RowData[k][0].ValueArray)), rows.RowData[k][1].ValueArray)
560+
utils.Info.Printf(fmstr2, string(utils.FromUnicode(rows.RowData[k][0].ValueArray)), rows.RowData[k][1].ValueArray, "")
560561
}
561562
}
562563
utils.Info.Println()

0 commit comments

Comments
 (0)