Skip to content

Commit 503ab8d

Browse files
authored
Update nodejs-binary.md
1 parent 1542b55 commit 503ab8d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

content/blog/2021/05/11/nodejs-binary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: How to execute JS like a binary
33
date: 2021-05-11
44
description: How to execute JavaScript files like a binary file with usage of Linux custom binary formats
55
---
6-
There are dozens of binary file formats that supported by operating systems thatwe use. Binary format is standard that helps operating system to determine howto execute file: read content, load part of them into a memory, extract additional data etc.
6+
There are dozens of binary file formats that supported by operating systems that we use. Binary format is standard that helps operating system to determine howto execute file: read content, load part of them into a memory, extract additional data etc.
77

88
How operating system determines how it should execute one or the other binary file? There are several ways to do that: one of that is to look at file extension. For example if you use Windows operating system, you can easily rename any text file to add `.exe`-extension and after that it will be looks like executable file, but, for sure, it cannot be executed because it doesn't follow structure of standard executable file for Windows.
99

@@ -17,7 +17,7 @@ If you are using UNIX-like operating system, you can easily check content of any
1717
0000004
1818
```
1919

20-
In linux executable file is executed by kernel and format of executable is determinated using either magic numbers or file extension. Built-in module _binfmt_ is responsible for this process. In linux 5.9 you can find <a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/fs?h=linux-5.9.y" target="_blank">seven</a> file formats that kernel supports out of box. And, surprisingly, one of the format is shebang scripts — scripts, that start with `#!` symbol combination. Thus, if you run, using your favorite shell program, script, which has permission to be executed, kernel will decide what to do with your script.
20+
In linux executable file is executed by kernel and format of executable is determinated using either magic numbers or file extension. Built-in module _binfmt_ is responsible for this process. In linux 5.9 you can find <a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/fs?h=linux-5.9.y" target="_blank">seven</a> file formats that kernel supports out of box (take a look onto files with prefix `binfmt` there in the list). And, surprisingly, one of the format is shebang scripts — scripts, that start with `#!` symbol combination. Thus, if you run, using your favorite shell program, script, which has permission to be executed, kernel will decide what to do with your script.
2121

2222
But the most interesting part of this mechanism that you can easily extend itusing <a href="https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html" target="_blank">custom binary formats</a>. By default, your distribution has mounted folder `binfmt_misc` in `/proc/sys/fs`:
2323

0 commit comments

Comments
 (0)