xref: /freebsd/contrib/file/magic/Magdir/javascript (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1
2#------------------------------------------------------------------------------
3# $File: javascript,v 1.7 2024/11/10 14:48:55 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++ but lose to HTML rules,
21# because javascript is embedded in hmtl files typically
220	search	"use\x20strict"	JavaScript source
23!:strength +20
24!:mime	application/javascript
25!:ext 	js
260	search	'use\x20strict'	JavaScript source
27!:strength +20
28!:mime	application/javascript
29!:ext 	js
300	regex	module(\\.|\\[["'])exports.*=	JavaScript source
31!:strength +20
32!:mime	application/javascript
33!:ext 	js
340	regex	\^(const|var|let).*=.*require\\(	JavaScript source
35!:strength +20
36!:mime	application/javascript
37!:ext 	js
380	regex	\^export\x20(function|class|default|const|var|let|async)\x20	JavaScript source
39!:strength +20
40!:mime	application/javascript
41!:ext 	js
420	regex	\\((async\x20)?function[(\x20]	JavaScript source
43!:strength +20
44!:mime	application/javascript
45!:ext 	js
460	regex	\^(import|export).*\x20from\x20	JavaScript source
47!:strength +20
48!:mime	application/javascript
49!:ext 	js
500	regex	\^(import|export)\x20["']\\./	JavaScript source
51!:strength +20
52!:mime	application/javascript
53!:ext 	js
540	regex	typeof.*[!=]==	JavaScript source
55!:strength +20
56!:mime	application/javascript
57!:ext 	js
58
59# React Native minified JavaScript
600	search/128	__BUNDLE_START_TIME__=	React Native minified JavaScript
61!:strength +20
62!:mime	application/javascript
63!:ext	bundle/jsbundle
64
65# Hermes by Facebook https://hermesengine.dev/
66# https://github.com/facebook/hermes/blob/master/include/hermes/\
67# BCGen/HBC/BytecodeFileFormat.h#L24
680	lequad		0x1F1903C103BC1FC6	Hermes JavaScript bytecode
69>8	lelong		x			\b, version %d
70
71# v8 JavaScript engine bytecode
72# From: Alexandre Iooss <erdnaxe@crans.org>
73# URL:	https://v8.dev/docs/ignition
74# Note: used in bytenode and NW.js protected source code
75# V8 bytecode extraction was added in NodeJS v5.7.0 (V8 4.6.85.31).
76# Version information is provided for some v8 versions found in NodeJS releases.
772	uleshort		=0xC0DE
78>0	ulelong^0xC0DE0000	>0
79# Reservation table starts at 40
80>>40	ulelong&0xFFFFFF00	=0x80000000
81# Stub keys present
82>>>24	ulelong			>0
83>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
84>>>>4	ulelong			=0xEE4BF478	version 5.1.281.111,
85>>>>4	ulelong			=0xC4A0100C	version 5.5.372.43,
86>>>>8	ulelong			x		source size: %u bytes,
87>>>>12	ulelong			x		cpu features: %#08X,
88>>>>16	ulelong			x		flag hash: %#08X,
89>>>>20	ulelong			x		%u reservations,
90>>>>28	ulelong			x		payload size: %u bytes,
91>>>>32	ulelong			x		checksum1: %#08X,
92>>>>36	ulelong			x		checksum2: %#08X
93# No stub keys
94>>>24	ulelong			=0
95>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
96>>>>4	ulelong			=0x54F0AD81	version 6.2.414.46,
97>>>>4	ulelong			=0X7D1BF182	version 6.2.414.54,
98>>>>4	ulelong			=0x35BA122E	version 6.2.414.77,
99>>>>4	ulelong			=0X9319F9C2	version 6.2.414.78,
100>>>>4	ulelong			=0xB1240060	version 6.6.346.32,
101>>>>4	ulelong			=0x2B757060	version 6.7.288.46,
102>>>>4	ulelong			=0x09D147AA	version 6.7.288.49,
103>>>>4	ulelong			=0xF4D4F48A	version 6.8.275.32,
104>>>>4	ulelong			=0xD3961326	version 7.0.276.38,
105>>>>8	ulelong			x		source size: %u bytes,
106>>>>12	ulelong			x		cpu features: %#08X,
107>>>>16	ulelong			x		flag hash: %#08X,
108>>>>20	ulelong			x		%u reservations,
109>>>>28	ulelong			x		payload size: %u bytes,
110>>>>32	ulelong			x		checksum1: %#08X,
111>>>>36	ulelong			x		checksum2: %#08X
112# Reservation table starts at 32
113>>32	ulelong&0xFFFFFF00	=0x80000000
114# Second checksum present
115>>>28	ulelong			>0
116>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
117>>>>4	ulelong			=0x21DDF627	version 7.4.288.21,
118>>>>4	ulelong			=0x1FC9FE84	version 7.4.288.27,
119>>>>4	ulelong			=0x60A99E8B	version 7.5.288.22,
120>>>>4	ulelong			=0x4F665E90	version 7.6.303.29,
121>>>>4	ulelong			=0xC7ACFCDE	version 7.7.299.11,
122>>>>4	ulelong			=0x7F641D8F	version 7.7.299.13,
123>>>>4	ulelong			=0xFD9A4F2E	version 7.8.279.17,
124>>>>4	ulelong			=0x3A845324	version 7.8.279.23,
125>>>>4	ulelong			=0xFF52FEAF	version 7.9.317.25,
126>>>>8	ulelong			x		source size: %u bytes,
127>>>>12	ulelong			x		flag hash: %#08X,
128>>>>16	ulelong			x		%u reservations,
129>>>>20	ulelong			x		payload size: %u bytes,
130>>>>24	ulelong			x		checksum1: %#08X,
131>>>>28	ulelong			x		checksum2: %#08X
132# No second checksum
133>>>28	ulelong			=0
134>>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
135>>>>4	ulelong			=0x8725E0F8	version 8.1.307.30,
136>>>>4	ulelong			=0x09ED1289	version 8.1.307.31,
137>>>>4	ulelong			=0xA5728C87	version 8.3.110.9,
138>>>>4	ulelong			=0xB45C5D30	version 8.4.371.23,
139>>>>4	ulelong			=0xED9C278B	version 8.4.371.19,
140>>>>4	ulelong			=0xD27BFF42	version 8.6.395.16,
141>>>>8	ulelong			x		source size: %u bytes,
142>>>>12	ulelong			x		flag hash: %#08X,
143>>>>16	ulelong			x		%u reservations,
144>>>>20	ulelong			x		payload size: %u bytes,
145>>>>24	ulelong			x		payload checksum: %#08X
146# No reservation table and code starts at 24
147>>32	ulelong		=0
148>>>0	ulelong^0xC0DE0000	x		v8 bytecode, external reference table size: %u bytes,
149>>>4	ulelong			=0x9A6F0B0F	version 9.0.257.17,
150>>>4	ulelong			=0x271D5D1E	version 9.0.257.24,
151>>>4	ulelong			=0x4EEA75DF	version 9.0.257.25,
152>>>4	ulelong			=0x80809479	version 9.1.269.36,
153>>>4	ulelong			=0x55C46F65	version 9.1.269.38,
154>>>4	ulelong			=0x8A9C758A	version 9.2.230.21,
155>>>4	ulelong			=0x9712F0E1	version 9.3.345.16,
156>>>4	ulelong			=0x29593715	version 9.4.146.19,
157>>>4	ulelong			=0xCD991825	version 9.4.146.24,
158>>>4	ulelong			=0xACDD64EE	version 9.4.146.26,
159>>>4	ulelong			=0xC96B4CD5	version 9.5.172.21,
160>>>4	ulelong			=0xBCCE4578	version 9.5.172.25,
161>>>4	ulelong			=0xA2EEA077	version 9.6.180.15,
162>>>4	ulelong			=0xFD350011	version 10.1.124.8,
163>>>4	ulelong			=0xBEF4028F	version 10.2.154.13,
164>>>4	ulelong			=0xAF632352	version 10.2.154.4,
165>>>8	ulelong			x		source size: %u bytes,
166>>>12	ulelong			x		flag hash: %#08X,
167>>>16	ulelong			x		payload size: %u bytes,
168>>>20	ulelong			x		payload checksum: %#08X
169