vigievuln 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/data/fingerprints/index.js +80 -0
  4. package/data/fingerprints/interpreters/javascript/bun.json +23 -0
  5. package/data/fingerprints/interpreters/javascript/deno.json +10 -0
  6. package/data/fingerprints/interpreters/javascript/electron.json +20 -0
  7. package/data/fingerprints/interpreters/javascript/gjs.json +8 -0
  8. package/data/fingerprints/interpreters/javascript/javascriptcore.json +14 -0
  9. package/data/fingerprints/interpreters/javascript/jscgtk.json +10 -0
  10. package/data/fingerprints/interpreters/javascript/node.json +26 -0
  11. package/data/fingerprints/interpreters/javascript/nwjs.json +8 -0
  12. package/data/fingerprints/interpreters/javascript/webkitgtk.json +10 -0
  13. package/data/fingerprints/interpreters/javascript/wpewebkit.json +10 -0
  14. package/data/fingerprints/interpreters/languages/dotnet.json +8 -0
  15. package/data/fingerprints/interpreters/languages/erlang.json +9 -0
  16. package/data/fingerprints/interpreters/languages/gawk.json +10 -0
  17. package/data/fingerprints/interpreters/languages/guile.json +9 -0
  18. package/data/fingerprints/interpreters/languages/java.json +8 -0
  19. package/data/fingerprints/interpreters/languages/julia.json +9 -0
  20. package/data/fingerprints/interpreters/languages/lua.json +11 -0
  21. package/data/fingerprints/interpreters/languages/luajit.json +10 -0
  22. package/data/fingerprints/interpreters/languages/perl.json +11 -0
  23. package/data/fingerprints/interpreters/languages/php.json +22 -0
  24. package/data/fingerprints/interpreters/languages/powershell.json +17 -0
  25. package/data/fingerprints/interpreters/languages/pypy.json +8 -0
  26. package/data/fingerprints/interpreters/languages/python.json +24 -0
  27. package/data/fingerprints/interpreters/languages/r.json +9 -0
  28. package/data/fingerprints/interpreters/languages/racket.json +9 -0
  29. package/data/fingerprints/interpreters/languages/raku.json +8 -0
  30. package/data/fingerprints/interpreters/languages/ruby.json +21 -0
  31. package/data/fingerprints/interpreters/languages/tcl.json +9 -0
  32. package/data/fingerprints/interpreters/shells/bash.json +10 -0
  33. package/data/fingerprints/interpreters/shells/dash.json +8 -0
  34. package/data/fingerprints/interpreters/shells/fish.json +9 -0
  35. package/data/fingerprints/interpreters/shells/ksh.json +8 -0
  36. package/data/fingerprints/interpreters/shells/zsh.json +9 -0
  37. package/data/fingerprints/services/databases/clickhouse.json +8 -0
  38. package/data/fingerprints/services/databases/elasticsearch.json +8 -0
  39. package/data/fingerprints/services/databases/etcd.json +9 -0
  40. package/data/fingerprints/services/databases/mariadb.json +9 -0
  41. package/data/fingerprints/services/databases/memcached.json +9 -0
  42. package/data/fingerprints/services/databases/mongo.json +8 -0
  43. package/data/fingerprints/services/databases/mysql.json +9 -0
  44. package/data/fingerprints/services/databases/opensearch.json +8 -0
  45. package/data/fingerprints/services/databases/postgres.json +18 -0
  46. package/data/fingerprints/services/databases/redis.json +9 -0
  47. package/data/fingerprints/services/databases/valkey.json +8 -0
  48. package/data/fingerprints/services/dns-directory/bind.json +8 -0
  49. package/data/fingerprints/services/dns-directory/dnsmasq.json +8 -0
  50. package/data/fingerprints/services/dns-directory/slapd.json +8 -0
  51. package/data/fingerprints/services/dns-directory/unbound.json +8 -0
  52. package/data/fingerprints/services/mail/cyrus.json +8 -0
  53. package/data/fingerprints/services/mail/dovecot.json +8 -0
  54. package/data/fingerprints/services/mail/exim.json +9 -0
  55. package/data/fingerprints/services/mail/opendkim.json +8 -0
  56. package/data/fingerprints/services/mail/opensmtpd.json +8 -0
  57. package/data/fingerprints/services/mail/postfix.json +8 -0
  58. package/data/fingerprints/services/mail/rspamd.json +8 -0
  59. package/data/fingerprints/services/mail/sendmail.json +8 -0
  60. package/data/fingerprints/services/messaging/kafka.json +8 -0
  61. package/data/fingerprints/services/messaging/mosquitto.json +8 -0
  62. package/data/fingerprints/services/messaging/nats.json +9 -0
  63. package/data/fingerprints/services/messaging/rabbitmq.json +8 -0
  64. package/data/fingerprints/services/remote-access/dropbear.json +8 -0
  65. package/data/fingerprints/services/remote-access/openssh.json +10 -0
  66. package/data/fingerprints/services/remote-access/proftpd.json +8 -0
  67. package/data/fingerprints/services/remote-access/samba.json +8 -0
  68. package/data/fingerprints/services/remote-access/vsftpd.json +8 -0
  69. package/data/fingerprints/services/web-proxies/apache.json +18 -0
  70. package/data/fingerprints/services/web-proxies/caddy.json +9 -0
  71. package/data/fingerprints/services/web-proxies/envoy.json +8 -0
  72. package/data/fingerprints/services/web-proxies/haproxy.json +10 -0
  73. package/data/fingerprints/services/web-proxies/lighttpd.json +8 -0
  74. package/data/fingerprints/services/web-proxies/nginx.json +14 -0
  75. package/data/fingerprints/services/web-proxies/squid.json +8 -0
  76. package/data/fingerprints/services/web-proxies/tomcat.json +8 -0
  77. package/data/fingerprints/services/web-proxies/traefik.json +9 -0
  78. package/data/fingerprints/services/web-proxies/varnish.json +8 -0
  79. package/lib/artifacts/component-scope.js +1 -1
  80. package/lib/artifacts/elf-product.js +215 -0
  81. package/lib/artifacts/image-products.js +180 -0
  82. package/lib/artifacts/install-version.js +44 -0
  83. package/lib/artifacts/pe-product.js +28 -0
  84. package/lib/artifacts/product-advisories.js +207 -0
  85. package/lib/artifacts/product-catalog.js +62 -0
  86. package/lib/artifacts/report-inventory.js +2 -0
  87. package/lib/artifacts/report.js +27 -4
  88. package/lib/artifacts/scan.js +25 -6
  89. package/lib/cli-image.js +1 -1
  90. package/lib/codecs/binary/elf-metadata.js +6 -0
  91. package/lib/codecs/binary/metadata.js +1 -1
  92. package/lib/codecs/binary/pe-metadata.js +47 -11
  93. package/lib/codecs/binary/scan.js +1 -1
  94. package/lib/json-export.js +1 -1
  95. package/lib/providers/nvd.js +16 -2
  96. package/lib/resource-cache/engine.js +3 -2
  97. package/lib/resource-cache/validate.js +1 -0
  98. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "postgres",
4
+ "label": "PostgreSQL",
5
+ "category": "service",
6
+ "executable": "^postgres$",
7
+ "osPackage": "^postgresql(?:-?\\d+)?(?:-server)?$",
8
+ "cpe": "postgresql:postgresql",
9
+ "peVersionInfo": {
10
+ "names": [
11
+ "PostgreSQL"
12
+ ],
13
+ "originals": [
14
+ "postgres.exe"
15
+ ]
16
+ },
17
+ "elfBanner": "\\x00postgres \\(PostgreSQL\\) (\\d+\\.\\d+(?:\\.\\d+)?)\\x00"
18
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "redis",
4
+ "label": "Redis",
5
+ "category": "service",
6
+ "executable": "^redis-server$",
7
+ "osPackage": "^redis(?:-server)?$",
8
+ "cpe": "redis:redis"
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "valkey",
4
+ "label": "Valkey",
5
+ "category": "service",
6
+ "executable": "^valkey-server$",
7
+ "osPackage": "^valkey(?:-server)?$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "bind",
4
+ "label": "BIND",
5
+ "category": "service",
6
+ "executable": "^named$",
7
+ "osPackage": "^(?:bind|bind9|bind-server)$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "dnsmasq",
4
+ "label": "Dnsmasq",
5
+ "category": "service",
6
+ "executable": "^dnsmasq$",
7
+ "osPackage": "^dnsmasq(?:-base)?$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "slapd",
4
+ "label": "OpenLDAP",
5
+ "category": "service",
6
+ "executable": "^slapd$",
7
+ "osPackage": "^(?:slapd|openldap-servers)$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "unbound",
4
+ "label": "Unbound",
5
+ "category": "service",
6
+ "executable": "^unbound$",
7
+ "osPackage": "^unbound$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "cyrus",
4
+ "label": "Cyrus IMAP",
5
+ "category": "service",
6
+ "executable": "^imapd$",
7
+ "osPackage": "^cyrus-imapd$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "dovecot",
4
+ "label": "Dovecot",
5
+ "category": "service",
6
+ "executable": "^dovecot$",
7
+ "osPackage": "^dovecot(?:-core)?$"
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "exim",
4
+ "label": "Exim",
5
+ "category": "service",
6
+ "executable": "^exim4?$",
7
+ "osPackage": "^exim(?:4(?:-daemon-(?:light|heavy))?)?$",
8
+ "cpe": "exim:exim"
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "opendkim",
4
+ "label": "OpenDKIM",
5
+ "category": "service",
6
+ "executable": "^opendkim$",
7
+ "osPackage": "^opendkim$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "opensmtpd",
4
+ "label": "OpenSMTPD",
5
+ "category": "service",
6
+ "executable": "^smtpd$",
7
+ "osPackage": "^opensmtpd$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "postfix",
4
+ "label": "Postfix",
5
+ "category": "service",
6
+ "executable": "^master$",
7
+ "osPackage": "^postfix$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "rspamd",
4
+ "label": "Rspamd",
5
+ "category": "service",
6
+ "executable": "^rspamd$",
7
+ "osPackage": "^rspamd$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "sendmail",
4
+ "label": "Sendmail",
5
+ "category": "service",
6
+ "executable": "^sendmail$",
7
+ "osPackage": "^sendmail(?:-bin)?$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "kafka",
4
+ "label": "Apache Kafka",
5
+ "category": "service",
6
+ "executable": "^kafka-server-start$",
7
+ "osPackage": "^kafka$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "mosquitto",
4
+ "label": "Mosquitto",
5
+ "category": "service",
6
+ "executable": "^mosquitto$",
7
+ "osPackage": "^mosquitto$"
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "nats",
4
+ "label": "NATS Server",
5
+ "category": "service",
6
+ "executable": "^nats-server$",
7
+ "osPackage": "^nats-server$",
8
+ "goMainModule": "github.com/nats-io/nats-server"
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "rabbitmq",
4
+ "label": "RabbitMQ",
5
+ "category": "service",
6
+ "executable": "^rabbitmq-server$",
7
+ "osPackage": "^rabbitmq-server$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "dropbear",
4
+ "label": "Dropbear SSH",
5
+ "category": "service",
6
+ "executable": "^dropbear$",
7
+ "osPackage": "^dropbear(?:-bin)?$"
8
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "openssh",
4
+ "label": "OpenSSH server",
5
+ "category": "service",
6
+ "executable": "^sshd$",
7
+ "osPackage": "^openssh-server$",
8
+ "elfBanner": "\\x00OpenSSH_(\\d+\\.\\d+(?:p\\d+)?)\\x00",
9
+ "cpe": "openbsd:openssh"
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "proftpd",
4
+ "label": "ProFTPD",
5
+ "category": "service",
6
+ "executable": "^proftpd$",
7
+ "osPackage": "^proftpd(?:-core)?$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "samba",
4
+ "label": "Samba",
5
+ "category": "service",
6
+ "executable": "^smbd$",
7
+ "osPackage": "^(?:samba|samba-server)$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "vsftpd",
4
+ "label": "vsftpd",
5
+ "category": "service",
6
+ "executable": "^vsftpd$",
7
+ "osPackage": "^vsftpd$"
8
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "apache",
4
+ "label": "Apache HTTP Server",
5
+ "category": "service",
6
+ "executable": "^(?:apache2|httpd)$",
7
+ "osPackage": "^(?:apache2(?:-bin)?|httpd(?:-core)?)$",
8
+ "cpe": "apache:http_server",
9
+ "elfBanner": "\\0Apache\\/(\\d+\\.\\d+\\.\\d+)(?=\\0)",
10
+ "peVersionInfo": {
11
+ "names": [
12
+ "Apache HTTP Server"
13
+ ],
14
+ "originals": [
15
+ "httpd.exe"
16
+ ]
17
+ }
18
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "caddy",
4
+ "label": "Caddy",
5
+ "category": "service",
6
+ "executable": "^caddy$",
7
+ "osPackage": "^caddy$",
8
+ "goMainModule": "github.com/caddyserver/caddy"
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "envoy",
4
+ "label": "Envoy",
5
+ "category": "service",
6
+ "executable": "^envoy$",
7
+ "osPackage": "^envoy$"
8
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "haproxy",
4
+ "label": "HAProxy",
5
+ "category": "service",
6
+ "executable": "^haproxy$",
7
+ "osPackage": "^haproxy$",
8
+ "cpe": "haproxy:haproxy",
9
+ "elfBanner": "\\0HAProxy version (\\d+\\.\\d+\\.\\d+)(?: |\\0)"
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "lighttpd",
4
+ "label": "lighttpd",
5
+ "category": "service",
6
+ "executable": "^lighttpd$",
7
+ "osPackage": "^lighttpd$"
8
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "nginx",
4
+ "label": "NGINX",
5
+ "category": "service",
6
+ "executable": "^nginx$",
7
+ "osPackage": "^nginx(?:-(?:core|full|light|extras))?$",
8
+ "cpe": "f5:nginx",
9
+ "elfBanner": "\\0nginx\\/(\\d+\\.\\d+\\.\\d+)(?=\\0)",
10
+ "cpeAliases": [
11
+ "nginx:nginx",
12
+ "igor_sysoev:nginx"
13
+ ]
14
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "squid",
4
+ "label": "Squid",
5
+ "category": "service",
6
+ "executable": "^squid$",
7
+ "osPackage": "^squid$"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "tomcat",
4
+ "label": "Apache Tomcat",
5
+ "category": "service",
6
+ "executable": "^jsvc-tomcat$",
7
+ "osPackage": "^tomcat\\d*$"
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "traefik",
4
+ "label": "Traefik",
5
+ "category": "service",
6
+ "executable": "^traefik$",
7
+ "osPackage": "^traefik$",
8
+ "goMainModule": "github.com/traefik/traefik"
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "varnish",
4
+ "label": "Varnish Cache",
5
+ "category": "service",
6
+ "executable": "^varnishd$",
7
+ "osPackage": "^varnish$"
8
+ }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const IMAGE_COMPONENT_SCOPE='image-components/1';
3
+ const IMAGE_COMPONENT_SCOPE='image-components/2';
4
4
  const parts=value=>String(value||'').replace(/\\/g,'/').split('/').filter(Boolean);
5
5
  const stores=new Set(['node_modules','vendor','site-packages','dist-packages','specifications','__pypackages__','.cache','.npm','.yarn','.m2','.gradle','.nuget']);
6
6
  // Installed metadata is authoritative inside package stores; source manifests
@@ -0,0 +1,215 @@
1
+ 'use strict';
2
+
3
+ const { catalog, binaryProduct } = require('./product-catalog');
4
+ const codecs = new Map(
5
+ [...catalog.values()].filter((product) => product.elfCodec).map((product) => [product.elfCodec, product])
6
+ );
7
+ const libraries = [...catalog.values()].filter((product) => product.library);
8
+ function libraryProduct(name) {
9
+ return libraries.find((product) => product.library.test(name));
10
+ }
11
+
12
+ function sectionsOf({ read, header, bits, word, u16, u32, max }) {
13
+ const wide = bits === 64,
14
+ stride = u16(header, wide ? 58 : 46),
15
+ count = u16(header, wide ? 60 : 48);
16
+ if (!count || count > 4096 || stride < (wide ? 64 : 40) || stride * count > max) return [];
17
+ const table = read(word(header, wide ? 40 : 32), stride * count);
18
+ return Array.from({ length: count }, (_, i) => {
19
+ const p = i * stride;
20
+ return {
21
+ name: u32(table, p),
22
+ type: u32(table, p + 4),
23
+ offset: word(table, p + (wide ? 24 : 16)),
24
+ size: word(table, p + (wide ? 32 : 20)),
25
+ link: u32(table, p + (wide ? 40 : 24)),
26
+ entry: word(table, p + (wide ? 56 : 36))
27
+ };
28
+ });
29
+ }
30
+
31
+ function bunGraph(elf, sections) {
32
+ const trailer = Buffer.from('\n---- Bun! ----\n');
33
+ if (elf.size >= 24) {
34
+ const end = elf.read(elf.size - 24, 24);
35
+ if (end.subarray(0, 16).equals(trailer) && end.readBigUInt64LE(16) === BigInt(elf.size)) return true;
36
+ }
37
+ const names = sections[elf.u16(elf.header, elf.bits === 64 ? 62 : 50)];
38
+ if (!names || names.size > 65536) return false;
39
+ const strings = elf.read(names.offset, names.size);
40
+ for (const section of sections) {
41
+ if (
42
+ section.type !== 1 ||
43
+ strings.toString('latin1', section.name, section.name + 5) !== '.bun\0' ||
44
+ section.size < 32
45
+ )
46
+ continue;
47
+ const len = elf.read(section.offset, 8).readBigUInt64LE();
48
+ if (
49
+ len >= 24n &&
50
+ len <= BigInt(section.size - 8) &&
51
+ elf.read(section.offset + 8 + Number(len) - 16, 16).equals(trailer)
52
+ )
53
+ return true;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ function symbolBytes(elf, sections, wanted) {
59
+ const wide = elf.bits === 64,
60
+ result = new Map();
61
+ for (const section of sections) {
62
+ if (section.type !== 11) continue;
63
+ const strings = sections[section.link];
64
+ if (
65
+ strings?.type !== 3 ||
66
+ section.entry !== (wide ? 24 : 16) ||
67
+ section.size % section.entry ||
68
+ Math.max(section.size, strings.size) > elf.max
69
+ )
70
+ continue;
71
+ const names = elf.read(strings.offset, strings.size);
72
+ if (!wanted.every((name) => names.includes(name + '\0'))) continue;
73
+ const symbols = elf.read(section.offset, section.size);
74
+ for (let j = 0; j < symbols.length; j += section.entry) {
75
+ const start = elf.u32(symbols, j);
76
+ const end = names.subarray(start, start + 49).indexOf(0) + start;
77
+ if (end < start || end - start > 48) continue;
78
+ const name = names.toString('latin1', start, end);
79
+ if (!wanted.includes(name) || !elf.u16(symbols, j + (wide ? 6 : 14))) continue;
80
+ const type = symbols[j + (wide ? 4 : 12)];
81
+ if (!(type >> 4) || (type & 15) !== (name === 'Py_Version' ? 1 : 2)) continue;
82
+ const length = elf.word(symbols, j + (wide ? 16 : 8));
83
+ if (length < 1 || length > 32) continue;
84
+ result.set(name, elf.read(elf.mapped(elf.word(symbols, j + (wide ? 8 : 4)), length), length));
85
+ }
86
+ }
87
+ return result;
88
+ }
89
+
90
+ function constantReturn(bytes, machine) {
91
+ if (!bytes) return;
92
+ // Entire leaf function must be a literal return. No machine code is run.
93
+ if (machine === 62 || machine === 3) {
94
+ if (bytes.subarray(0, 4).equals(Buffer.from([0xf3, 0x0f, 0x1e, machine === 62 ? 0xfa : 0xfb])))
95
+ bytes = bytes.subarray(4);
96
+ if (bytes.equals(Buffer.from([0x31, 0xc0, 0xc3]))) return 0;
97
+ if (bytes.length === 6 && bytes[0] === 0xb8 && bytes[5] === 0xc3) return bytes.readUInt32LE(1);
98
+ }
99
+ if (machine === 183 && bytes.length === 8 && bytes.readUInt32LE(4) === 0xd65f03c0) {
100
+ const mov = bytes.readUInt32LE(0);
101
+ if ((mov & 0xffe0001f) >>> 0 === 0x52800000) return (mov >>> 5) & 0xffff;
102
+ }
103
+ }
104
+
105
+ function exportedVersion(product, elf, sections) {
106
+ if (product.elfCodec === 'py-version') {
107
+ const bytes = symbolBytes(elf, sections, ['Py_Version']).get('Py_Version');
108
+ if (!bytes || ![4, 8].includes(bytes.length)) return;
109
+ const hex = bytes.length === 4 ? elf.u32(bytes, 0) : elf.word(bytes, 0);
110
+ if (hex <= 0xffffffff && hex >>> 24 === 3 && (hex & 255) === 0xf0)
111
+ return {
112
+ id: product.id,
113
+ version: [hex >>> 24, (hex >>> 16) & 255, (hex >>> 8) & 255].join('.'),
114
+ source: 'Py_Version'
115
+ };
116
+ }
117
+ if (['webkit-version', 'jsc-version'].includes(product.elfCodec)) {
118
+ const prefix = product.elfCodec === 'jsc-version' ? 'jsc' : 'webkit';
119
+ const names = ['major', 'minor', 'micro'].map((part) => prefix + '_get_' + part + '_version');
120
+ const symbols = symbolBytes(elf, sections, names);
121
+ const parts = names.map((name) => constantReturn(symbols.get(name), elf.machine));
122
+ if (parts.every((n) => Number.isInteger(n) && n <= 65535) && parts[0] > 0)
123
+ return { id: product.id, version: parts.join('.'), source: prefix + ' version API' };
124
+ }
125
+ }
126
+
127
+ // For renamed/embedded Node, bind the inspector version to the release archive
128
+ // compiled into Node. Compatibility strings in another JS engine do not suffice.
129
+ function embeddedEngines(elf, product) {
130
+ const tags = new Set(),
131
+ releases = new Set();
132
+ const jsc = codecs.get('jsc-build');
133
+ const markers = new Set(jsc.elfBuildMarkers);
134
+ const checkNode = !['node-release', 'bun-standalone'].includes(product?.elfCodec);
135
+ const checkJsc = !['jsc-version', 'webkit-version'].includes(product?.elfCodec);
136
+ let registered = false;
137
+ if (!checkNode && !checkJsc) return [];
138
+ for (const chunk of readonlyChunks(elf)) {
139
+ if (checkJsc) for (const marker of markers) if (chunk.includes(marker)) markers.delete(marker);
140
+ if (!checkNode) {
141
+ if (!markers.size) break;
142
+ continue;
143
+ }
144
+ if (chunk.includes('node_module_register\0')) registered = true;
145
+ if (tags.size <= 1 && chunk.includes('node.js/v'))
146
+ for (const m of chunk.matchAll(/\0node\.js\/v(\d+\.\d+\.\d+)(?=\0)/g)) {
147
+ tags.add(m[1]);
148
+ if (tags.size > 1) break;
149
+ }
150
+ if (releases.size <= 1 && chunk.includes('nodejs.org/download/release/'))
151
+ for (const m of chunk.matchAll(
152
+ /https:\/\/nodejs\.org\/download\/release\/v(\d+\.\d+\.\d+)\/node-v\1\.tar\.gz\0/g
153
+ )) {
154
+ releases.add(m[1]);
155
+ if (releases.size > 1) break;
156
+ }
157
+ }
158
+ const products = [],
159
+ [version] = tags;
160
+ if (registered && tags.size === 1 && releases.size === 1 && releases.has(version))
161
+ products.push({ id: codecs.get('node-release').id, version, source: 'node-release-and-inspector' });
162
+ if (checkJsc && !markers.size) products.push({ id: jsc.id, version: null, source: 'jsc-build-markers' });
163
+ return products;
164
+ }
165
+
166
+ function* readonlyChunks(elf) {
167
+ let remaining = elf.size;
168
+ for (const segment of elf.segments.filter((s) => s.type === 1 && !(s.flags & 2))) {
169
+ if (segment.filesz > remaining) throw Error('overlapping ELF load segments');
170
+ remaining -= segment.filesz;
171
+ let tail = '';
172
+ const step = Math.min(256 * 1024, elf.max);
173
+ for (let pos = 0; pos < segment.filesz; pos += step) {
174
+ const data =
175
+ tail + elf.read(segment.offset + pos, Math.min(step, segment.filesz - pos)).toString('latin1');
176
+ yield data;
177
+ tail = data.slice(-160);
178
+ }
179
+ }
180
+ }
181
+
182
+ function embeddedProducts(name, elf) {
183
+ const sections = sectionsOf(elf);
184
+ const bundled = bunGraph(elf, sections);
185
+ const product = bundled
186
+ ? codecs.get('bun-standalone')
187
+ : binaryProduct(name) ||
188
+ libraryProduct(name) ||
189
+ binaryProduct(elf.soname) ||
190
+ libraryProduct(elf.soname || '');
191
+ const products = elf.size >= 1024 * 1024 ? embeddedEngines(elf, product) : [];
192
+ if (!product) return products;
193
+ const exported = exportedVersion(product, elf, sections);
194
+ if (exported) products.push(exported);
195
+ if (!product.banner) return products;
196
+ // Read only mapped, read-only data. Small overlapping chunks also handle
197
+ // signatures spanning a read boundary without loading an entire executable.
198
+ const versions = new Set();
199
+ for (const data of readonlyChunks(elf)) {
200
+ for (const match of data.matchAll(product.banner)) {
201
+ const version = match.slice(1).join('.');
202
+ if (version.length <= 40) versions.add(version);
203
+ if (versions.size > 1) return products;
204
+ }
205
+ }
206
+ if (versions.size)
207
+ products.push({
208
+ id: product.id,
209
+ version: [...versions][0],
210
+ source: bundled ? 'bun-module-graph' : 'embedded-version-banner'
211
+ });
212
+ else if (bundled) products.push({ id: 'bun', version: null, source: 'bun-module-graph' });
213
+ return products;
214
+ }
215
+ module.exports = { embeddedProducts, libraryProduct };