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 support for PE-DLL file formats #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/magic/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,18 @@ func Marc(raw []byte, limit uint32) bool {
// Field terminator is present.
return bytes.Contains(raw, []byte{0x1E})
}

// Microsoft PE dll
func Dll(raw []byte, limit uint32) bool {
l := len(raw)
if l < 0x40 {
return false
}
signoff := binary.LittleEndian.Uint32(raw[0x3c:])
if uint32(l) < signoff+0x18 {
return false
}
characteristics := binary.LittleEndian.Uint16(raw[signoff+0x16:])

return characteristics&0x2000 == 0x2000
}
1 change: 1 addition & 0 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ var files = map[string]string{
"xz.xz": "application/x-xz",
"zip.zip": "application/zip",
"zst.zst": "application/zstd",
"dll.dll": "application/vnd.microsoft.portable-executable-dll",
}

func TestDetect(t *testing.T) {
Expand Down
Binary file added testdata/dll.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ var (
shp = newMIME("application/octet-stream", ".shp", magic.Shp)
shx = newMIME("application/octet-stream", ".shx", magic.Shx, shp)
dbf = newMIME("application/x-dbf", ".dbf", magic.Dbf)
exe = newMIME("application/vnd.microsoft.portable-executable", ".exe", magic.Exe)
dll = newMIME("application/vnd.microsoft.portable-executable-dll", ".dll", magic.Dll)
exe = newMIME("application/vnd.microsoft.portable-executable", ".exe", magic.Exe, dll)
elf = newMIME("application/x-elf", "", magic.Elf, elfObj, elfExe, elfLib, elfDump)
elfObj = newMIME("application/x-object", "", magic.ElfObj)
elfExe = newMIME("application/x-executable", "", magic.ElfExe)
Expand Down