forked from Velocidex/go-yara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_yara34.go
31 lines (27 loc) · 821 Bytes
/
rule_yara34.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright © 2015-2019 Hilko Bengen <bengen@hilluzination.de>
// All rights reserved.
//
// Use of this source code is governed by the license that can be
// found in the LICENSE file.
// +build yara3.3 yara3.4
package yara
// #include <yara.h>
import "C"
import (
"reflect"
"unsafe"
)
// Data returns the blob of data associated with the string match.
func (m *Match) Data() []byte {
tmpbuf := []byte{}
// Use unsafe instead of C.GoBytes to avoid "cgo argument has Go
// pointer to Go pointer" panic (see
// https://github.com/hillu/go-yara/issues/5)
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&tmpbuf))
hdr.Data = uintptr(*(*unsafe.Pointer)(unsafe.Pointer(&(m.cptr.anon0))))
hdr.Len = int(m.cptr.length)
hdr.Cap = int(m.cptr.length)
buf := make([]byte, len(tmpbuf))
copy(buf, tmpbuf)
return buf
}