xref: /freebsd/contrib/file/magic/Magdir/javascript (revision c8e7f78a3d28ff6e6223ed136ada8e1e2f34965e)
1
2#------------------------------------------------------------------------------
3# $File: javascript,v 1.5 2023/01/12 00:02:16 christos Exp $
4# javascript:  magic for javascript and node.js scripts.
5#
60	string/tw	#!/bin/node		Node.js script executable
7!:mime application/javascript
80	string/tw	#!/usr/bin/node		Node.js script executable
9!:mime application/javascript
100	string/tw	#!/bin/nodejs		Node.js script executable
11!:mime application/javascript
120	string/tw	#!/usr/bin/nodejs	Node.js script executable
13!:mime application/javascript
140	string/t		#!/usr/bin/env\ node	Node.js script executable
15!:mime application/javascript
160	string/t		#!/usr/bin/env\ nodejs	Node.js script executable
17!:mime application/javascript
18
19# JavaScript
20# The strength is increased to beat the C++ & HTML rules
210	search	"use\x20strict"	JavaScript source
22!:strength +30
23!:mime	application/javascript
24!:ext 	js
250	search	'use\x20strict'	JavaScript source
26!:strength +30
27!:mime	application/javascript
28!:ext 	js
290	regex	module(\\.|\\[["'])exports.*=	JavaScript source
30!:strength +30
31!:mime	application/javascript
32!:ext 	js
330	regex	\^(const|var|let).*=.*require\\(	JavaScript source
34!:strength +30
35!:mime	application/javascript
36!:ext 	js
370	regex	\^export\x20(function|class|default|const|var|let|async)\x20	JavaScript source
38!:strength +30
39!:mime	application/javascript
40!:ext 	js
410	regex	\\((async\x20)?function[(\x20]	JavaScript source
42!:strength +30
43!:mime	application/javascript
44!:ext 	js
450	regex	\^(import|export).*\x20from\x20	JavaScript source
46!:strength +30
47!:mime	application/javascript
48!:ext 	js
490	regex	\^(import|export)\x20["']\\./	JavaScript source
50!:strength +30
51!:mime	application/javascript
52!:ext 	js
530	regex	\^require\\(["']	JavaScript source
54!:strength +30
55!:mime	application/javascript
56!:ext 	js
570	regex	typeof.*[!=]==	JavaScript source
58!:strength +30
59!:mime	application/javascript
60!:ext 	js
61
62# React Native minified JavaScript
630	search/128	__BUNDLE_START_TIME__=	React Native minified JavaScript
64!:strength +30
65!:mime	application/javascript
66!:ext	bundle/jsbundle
67
68# Hermes by Facebook https://hermesengine.dev/
69# https://github.com/facebook/hermes/blob/master/include/hermes/\
70# BCGen/HBC/BytecodeFileFormat.h#L24
710	lequad		0x1F1903C103BC1FC6	Hermes JavaScript bytecode
72>8	lelong		x			\b, version %d
73
74# v8 JavaScript engine bytecode
75# From: Alexandre Iooss <erdnaxe@crans.org>
76# URL:	https://v8.dev/docs/ignition
77# Note: used in bytenode and NW.js protected source code
78# V8 bytecode extraction was added in NodeJS v5.7.0 (V8 4.6.85.31).
79# Version information is provided for some v8 versions found in NodeJS releases.
802	uleshort		=0xC0DE
81>0	ulelong^0xC0DE0000	>0
82# Reservation table starts at 40
83>>40	ulelong&0xFFFFFF00	=0x80000000
84# Stub keys present
85>>>24	ulelong			>0
86>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
87>>>>4	ulelong			=0xEE4BF478	version 5.1.281.111,
88>>>>4	ulelong			=0xC4A0100C	version 5.5.372.43,
89>>>>8	ulelong			x		source size: %u bytes,
90>>>>12	ulelong			x		cpu features: %#08X,
91>>>>16	ulelong			x		flag hash: %#08X,
92>>>>20	ulelong			x		%u reservations,
93>>>>28	ulelong			x		payload size: %u bytes,
94>>>>32	ulelong			x		checksum1: %#08X,
95>>>>36	ulelong			x		checksum2: %#08X
96# No stub keys
97>>>24	ulelong			=0
98>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
99>>>>4	ulelong			=0x54F0AD81	version 6.2.414.46,
100>>>>4	ulelong			=0X7D1BF182	version 6.2.414.54,
101>>>>4	ulelong			=0x35BA122E	version 6.2.414.77,
102>>>>4	ulelong			=0X9319F9C2	version 6.2.414.78,
103>>>>4	ulelong			=0xB1240060	version 6.6.346.32,
104>>>>4	ulelong			=0x2B757060	version 6.7.288.46,
105>>>>4	ulelong			=0x09D147AA	version 6.7.288.49,
106>>>>4	ulelong			=0xF4D4F48A	version 6.8.275.32,
107>>>>4	ulelong			=0xD3961326	version 7.0.276.38,
108>>>>8	ulelong			x		source size: %u bytes,
109>>>>12	ulelong			x		cpu features: %#08X,
110>>>>16	ulelong			x		flag hash: %#08X,
111>>>>20	ulelong			x		%u reservations,
112>>>>28	ulelong			x		payload size: %u bytes,
113>>>>32	ulelong			x		checksum1: %#08X,
114>>>>36	ulelong			x		checksum2: %#08X
115# Reservation table starts at 32
116>>32	ulelong&0xFFFFFF00	=0x80000000
117# Second checksum present
118>>>28	ulelong			>0
119>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
120>>>>4	ulelong			=0x21DDF627	version 7.4.288.21,
121>>>>4	ulelong			=0x1FC9FE84	version 7.4.288.27,
122>>>>4	ulelong			=0x60A99E8B	version 7.5.288.22,
123>>>>4	ulelong			=0x4F665E90	version 7.6.303.29,
124>>>>4	ulelong			=0xC7ACFCDE	version 7.7.299.11,
125>>>>4	ulelong			=0x7F641D8F	version 7.7.299.13,
126>>>>4	ulelong			=0xFD9A4F2E	version 7.8.279.17,
127>>>>4	ulelong			=0x3A845324	version 7.8.279.23,
128>>>>4	ulelong			=0xFF52FEAF	version 7.9.317.25,
129>>>>8	ulelong			x		source size: %u bytes,
130>>>>12	ulelong			x		flag hash: %#08X,
131>>>>16	ulelong			x		%u reservations,
132>>>>20	ulelong			x		payload size: %u bytes,
133>>>>24	ulelong			x		checksum1: %#08X,
134>>>>28	ulelong			x		checksum2: %#08X
135# No second checksum
136>>>28	ulelong			=0
137>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
138>>>>4	ulelong			=0x8725E0F8	version 8.1.307.30,
139>>>>4	ulelong			=0x09ED1289	version 8.1.307.31,
140>>>>4	ulelong			=0xA5728C87	version 8.3.110.9,
141>>>>4	ulelong			=0xB45C5D30	version 8.4.371.23,
142>>>>4	ulelong			=0xED9C278B	version 8.4.371.19,
143>>>>4	ulelong			=0xD27BFF42	version 8.6.395.16,
144>>>>8	ulelong			x		source size: %u bytes,
145>>>>12	ulelong			x		flag hash: %#08X,
146>>>>16	ulelong			x		%u reservations,
147>>>>20	ulelong			x		payload size: %u bytes,
148>>>>24	ulelong			x		payload checksum: %#08X
149# No reservation table and code starts at 24
150>>32	ulelong		=0
151>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
152>>>4	ulelong			=0x9A6F0B0F	version 9.0.257.17,
153>>>4	ulelong			=0x271D5D1E	version 9.0.257.24,
154>>>4	ulelong			=0x4EEA75DF	version 9.0.257.25,
155>>>4	ulelong			=0x80809479	version 9.1.269.36,
156>>>4	ulelong			=0x55C46F65	version 9.1.269.38,
157>>>4	ulelong			=0x8A9C758A	version 9.2.230.21,
158>>>4	ulelong			=0x9712F0E1	version 9.3.345.16,
159>>>4	ulelong			=0x29593715	version 9.4.146.19,
160>>>4	ulelong			=0xCD991825	version 9.4.146.24,
161>>>4	ulelong			=0xACDD64EE	version 9.4.146.26,
162>>>4	ulelong			=0xC96B4CD5	version 9.5.172.21,
163>>>4	ulelong			=0xBCCE4578	version 9.5.172.25,
164>>>4	ulelong			=0xA2EEA077	version 9.6.180.15,
165>>>4	ulelong			=0xFD350011	version 10.1.124.8,
166>>>4	ulelong			=0xBEF4028F	version 10.2.154.13,
167>>>4	ulelong			=0xAF632352	version 10.2.154.4,
168>>>8	ulelong			x		source size: %u bytes,
169>>>12	ulelong			x		flag hash: %#08X,
170>>>16	ulelong			x		payload size: %u bytes,
171>>>20	ulelong			x		payload checksum: %#08X
172