Debian Codegraph @

matchers/application.go

raw symbols SCIP
1 package matchers
2
3 var (
4 TypeWasm = newType("wasm", "application/wasm")
5 TypeDex = newType("dex", "application/vnd.android.dex")
6 TypeDey = newType("dey", "application/vnd.android.dey")
7 )
8
9 var Application = Map{
10 TypeWasm: Wasm,
11 TypeDex: Dex,
12 TypeDey: Dey,
13 }
14
15 // Wasm detects a Web Assembly 1.0 filetype.
16 func Wasm(buf []byte) bool {
17 // WASM has starts with `\0asm`, followed by the version.
18 // http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
19 return len(buf) >= 8 &&
20 buf[0] == 0x00 && buf[1] == 0x61 &&
21 buf[2] == 0x73 && buf[3] == 0x6D &&
22 buf[4] == 0x01 && buf[5] == 0x00 &&
23 buf[6] == 0x00 && buf[7] == 0x00
24 }
25
26 // Dex detects dalvik executable(DEX)
27 func Dex(buf []byte) bool {
28 // https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic
29 return len(buf) > 36 &&
30 // magic
31 buf[0] == 0x64 && buf[1] == 0x65 && buf[2] == 0x78 && buf[3] == 0x0A &&
32 // file sise
33 buf[36] == 0x70
34 }
35
36 // Dey Optimized Dalvik Executable(ODEX)
37 func Dey(buf []byte) bool {
38 return len(buf) > 100 &&
39 // dey magic
40 buf[0] == 0x64 && buf[1] == 0x65 && buf[2] == 0x79 && buf[3] == 0x0A &&
41 // dex
42 Dex(buf[40:100])
43 }