mscfb
mscfb copied to clipboard
Add HasVBA function in file.go
Add function HasVBA in file.go in order to test if there is VBA Code in it.
thanks for this Peter, I'll take a look
Hi Peter thanks again for this pull request. I'd like to keep the footprint of mscfb as small as possible & it seems like this might make more sense as a function in a dedicated VBA package. What do you think about adding this as a func to your own go-vba package instead?? Then would be trivial to combine with mscfb. Few suggestions for tweaks to your func:
// HasVBA: Checks if this file contains VBA code
// Returns true/false and offset to start decoding VBA
func HasVBA(rdr io.Reader) (bool, int64) {
var (
marker = []byte("\x00Attribut")
mlen = len(marker)
cur int
offset int64
size = 4 * 1024
buff = make([]byte, size)
)
for nr, _ := rdr.Read(buff); nr > 0; nr, _ = rdr.Read(buff) {
for i, b := range buff[:nr] {
if b == marker[cur] {
cur++
if cur == mlen {
return true, offset + int64(i) - 3
}
} else {
cur = 0
}
}
offset += int64(nr)
}
return false, -1
}