Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HasVBA function in file.go #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

phaag
Copy link

@phaag phaag commented Feb 17, 2020

Add function HasVBA in file.go in order to test if there is VBA Code in it.

@richardlehane
Copy link
Owner

thanks for this Peter, I'll take a look

@richardlehane
Copy link
Owner

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants