unixpickle / gobfuscate

Obfuscate Go binaries and packages
BSD 2-Clause "Simplified" License
1.45k stars 157 forks source link

Off By One Error When Removing DO NOT EDIT #34

Closed dli357 closed 4 years ago

dli357 commented 4 years ago

When replacing the "DO NOT EDIT" comments, the function removeDoNotEdit allocates one less character, thus slicing one of forward slashes off of the comment.

See lines 297-300 in symbols.go:

data := make([]byte, comment.End()-comment.Pos())
start := int(comment.Pos())
end := start + len(data)
data = content[start:end]

Instead, line 298 should be:

start := int(comment.Pos()) - 1

To reproduce, I tried obfuscating github.com/miekg/dns. There are some other issues there with parsing annotation tags in switch statements, but that should probably be its own separate issue.

This looks like the same problem experienced in #30