From af46e8c7e7eecce2b1caa9c175145e44f33f39ad Mon Sep 17 00:00:00 2001 From: Antti Kupila Date: Fri, 8 Feb 2019 10:46:08 +0100 Subject: [PATCH] detect wasm file type --- fixtures/sample.wasm | Bin 0 -> 78 bytes match_test.go | 1 + matchers/application.go | 20 ++++++++++++++++++++ matchers/matchers.go | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 fixtures/sample.wasm create mode 100644 matchers/application.go diff --git a/fixtures/sample.wasm b/fixtures/sample.wasm new file mode 100644 index 0000000000000000000000000000000000000000..a2e9ad6acbc70204dba743dd5064f0afab5a6e38 GIT binary patch literal 78 zcmZQbEY4+QU|?Y6U`k-DXGmaRV3K5H&&(~zFDfbKh0v)f@oA-b$qWq4OpJ`|f{eVW U6(DJtFe4WSBO8OGmH-1c0JS<1egFUf literal 0 HcmV?d00001 diff --git a/match_test.go b/match_test.go index f3e7efd..66dbb6d 100644 --- a/match_test.go +++ b/match_test.go @@ -47,6 +47,7 @@ func TestMatchFile(t *testing.T) { {"pptx"}, {"xlsx"}, {"mov"}, + {"wasm"}, } for _, test := range cases { diff --git a/matchers/application.go b/matchers/application.go new file mode 100644 index 0000000..f482062 --- /dev/null +++ b/matchers/application.go @@ -0,0 +1,20 @@ +package matchers + +var ( + TypeWasm = newType("wasm", "application/wasm") +) + +var Application = Map{ + TypeWasm: Wasm, +} + +// Wasm detects a Web Assembly 1.0 filetype. +func Wasm(buf []byte) bool { + // WASM has starts with `\0asm`, followed by the version. + // http://webassembly.github.io/spec/core/binary/modules.html#binary-magic + return len(buf) >= 8 && + buf[0] == 0x00 && buf[1] == 0x61 && + buf[2] == 0x73 && buf[3] == 0x6D && + buf[4] == 0x01 && buf[5] == 0x00 && + buf[6] == 0x00 && buf[7] == 0x00 +} diff --git a/matchers/matchers.go b/matchers/matchers.go index e9462df..20d74d0 100644 --- a/matchers/matchers.go +++ b/matchers/matchers.go @@ -47,5 +47,5 @@ func register(matchers ...Map) { func init() { // Arguments order is intentional // Archive files will be checked last due to prepend above in func NewMatcher - register(Archive, Document, Font, Audio, Video, Image) + register(Archive, Document, Font, Audio, Video, Image, Application) }