il fallait que sa puisse passer sur un cv
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
syscall.node
|
||||
ioctl.node
|
||||
mount.node
|
||||
file.node
|
||||
node_modules
|
||||
package-lock.json
|
||||
@@ -0,0 +1,9 @@
|
||||
const fs = require('fs')
|
||||
const audiopath = '/dev/audio'
|
||||
|
||||
module.exports = (path) => {
|
||||
if(fs.existsSync(path) && fs.existsSync(audiopath)) {
|
||||
const data = fs.readFileSync(path)
|
||||
fs.writeFileSync(audiopath, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
//@ts-check
|
||||
/** @type {{ [key: number]: string | undefined }} */
|
||||
module.exports = {
|
||||
1: "EPERM", //Operation not permitted
|
||||
2: "ENOENT", //No such file or directory
|
||||
3: "ESRCH", //No such process
|
||||
4: "EINTR", //Interrupted system call
|
||||
5: "EIO", //I/O error
|
||||
6: "ENXIO", //No such device or address
|
||||
7: "E2BIG", //Argument list too long
|
||||
8: "ENOEXEC", //Exec format error
|
||||
9: "EBADF", //Bad file number
|
||||
10: "ECHILD", //No child processes
|
||||
11: "EAGAIN", //Try again
|
||||
12: "ENOMEM", //Out of memory
|
||||
13: "EACCES", //Permission denied
|
||||
14: "EFAULT", //Bad address
|
||||
15: "ENOTBLK", //Block device required
|
||||
16: "EBUSY", //Device or resource busy
|
||||
17: "EEXIST", //File exists
|
||||
18: "EXDEV", //Cross-device link
|
||||
19: "ENODEV", //No such device
|
||||
20: "ENOTDIR", //Not a directory
|
||||
21: "EISDIR", //Is a directory
|
||||
22: "EINVAL", //Invalid argument
|
||||
23: "ENFILE", //File table overflow
|
||||
24: "EMFILE", //Too many open files
|
||||
25: "ENOTTY", //Not a typewriter
|
||||
26: "ETXTBSY", //Text file busy
|
||||
27: "EFBIG", //File too large
|
||||
28: "ENOSPC", //No space left on device
|
||||
29: "ESPIPE", //Illegal seek
|
||||
30: "EROFS", //Read-only file system
|
||||
31: "EMLINK", //Too many links
|
||||
32: "EPIPE", //Broken pipe
|
||||
33: "EDOM", //Math argument out of domain of func
|
||||
34: "ERANGE", //Math result not representable
|
||||
35: "EDEADLK", //Resource deadlock would occur
|
||||
36: "ENAMETOOLONG", //File name too long
|
||||
37: "ENOLCK", //No record locks available
|
||||
38: "ENOSYS", //Function not implemented
|
||||
39: "ENOTEMPTY", //Directory not empty
|
||||
40: "ELOOP", //Too many symbolic links encountered
|
||||
42: "ENOMSG", //No message of desired type
|
||||
43: "EIDRM", //Identifier removed
|
||||
44: "ECHRNG", //Channel number out of range
|
||||
45: "EL2NSYNC", //Level 2 not synchronized
|
||||
46: "EL3HLT", //Level 3 halted
|
||||
47: "EL3RST", //Level 3 reset
|
||||
48: "ELNRNG", //Link number out of range
|
||||
49: "EUNATCH", //Protocol driver not attached
|
||||
50: "ENOCSI", //No CSI structure available
|
||||
51: "EL2HLT", //Level 2 halted
|
||||
52: "EBADE", //Invalid exchange
|
||||
53: "EBADR", //Invalid request descriptor
|
||||
54: "EXFULL", //Exchange full
|
||||
55: "ENOANO", //No anode
|
||||
56: "EBADRQC", //Invalid request code
|
||||
57: "EBADSLT", //Invalid slot
|
||||
59: "EBFONT", //Bad font file format
|
||||
60: "ENOSTR", //Device not a stream
|
||||
61: "ENODATA", //No data available
|
||||
62: "ETIME", //Timer expired
|
||||
63: "ENOSR", //Out of streams resources
|
||||
64: "ENONET", //Machine is not on the network
|
||||
65: "ENOPKG", //Package not installed
|
||||
66: "EREMOTE", //Object is remote
|
||||
67: "ENOLINK", //Link has been severed
|
||||
68: "EADV", //Advertise error
|
||||
69: "ESRMNT", //Srmount error
|
||||
70: "ECOMM", //Communication error on send
|
||||
71: "EPROTO", //Protocol error
|
||||
72: "EMULTIHOP", //Multihop attempted
|
||||
73: "EDOTDOT", //RFS specific error
|
||||
74: "EBADMSG", //Not a data message
|
||||
75: "EOVERFLOW", //Value too large for defined data type
|
||||
76: "ENOTUNIQ", //Name not unique on network
|
||||
77: "EBADFD", //File descriptor in bad state
|
||||
78: "EREMCHG", //Remote address changed
|
||||
79: "ELIBACC", //Can not access a needed shared library
|
||||
80: "ELIBBAD", //Accessing a corrupted shared library
|
||||
81: "ELIBSCN", //lib section in a.out corrupted
|
||||
82: "ELIBMAX", //Attempting to link in too many shared libraries
|
||||
83: "ELIBEXEC", //Cannot exec a shared library directly
|
||||
84: "EILSEQ", //Illegal byte sequence
|
||||
85: "ERESTART", //Interrupted system call should be restarted
|
||||
86: "ESTRPIPE", //Streams pipe error
|
||||
87: "EUSERS", //Too many users
|
||||
88: "ENOTSOCK", //Socket operation on non-socket
|
||||
89: "EDESTADDRREQ", //Destination address required
|
||||
90: "EMSGSIZE", //Message too long
|
||||
91: "EPROTOTYPE", //Protocol wrong type for socket
|
||||
92: "ENOPROTOOPT", //Protocol not available
|
||||
93: "EPROTONOSUPPORT", //Protocol not supported
|
||||
94: "ESOCKTNOSUPPORT", //Socket type not supported
|
||||
95: "EOPNOTSUPP", //Operation not supported on transport endpoint
|
||||
96: "EPFNOSUPPORT", //Protocol family not supported
|
||||
97: "EAFNOSUPPORT", //Address family not supported by protocol
|
||||
98: "EADDRINUSE", //Address already in use
|
||||
99: "EADDRNOTAVAIL", //Cannot assign requested address
|
||||
100: "ENETDOWN", //Network is down
|
||||
101: "ENETUNREACH", //Network is unreachable
|
||||
102: "ENETRESET", //Network dropped connection because of reset
|
||||
103: "ECONNABORTED", //Software caused connection abort
|
||||
104: "ECONNRESET", //Connection reset by peer
|
||||
105: "ENOBUFS", //No buffer space available
|
||||
106: "EISCONN", //Transport endpoint is already connected
|
||||
107: "ENOTCONN", //Transport endpoint is not connected
|
||||
108: "ESHUTDOWN", //Cannot send after transport endpoint shutdown
|
||||
109: "ETOOMANYREFS", //Too many references: cannot splice
|
||||
110: "ETIMEDOUT", //Connection timed out
|
||||
111: "ECONNREFUSED", //Connection refused
|
||||
112: "EHOSTDOWN", //Host is down
|
||||
113: "EHOSTUNREACH", //No route to host
|
||||
114: "EALREADY", //Operation already in progress
|
||||
115: "EINPROGRESS", //Operation now in progress
|
||||
116: "ESTALE", //Stale NFS file handle
|
||||
117: "EUCLEAN", //Structure needs cleaning
|
||||
118: "ENOTNAM", //Not a XENIX named type file
|
||||
119: "ENAVAIL", //No XENIX semaphores available
|
||||
120: "EISNAM", //Is a named type file
|
||||
121: "EREMOTEIO", //Remote I/O error
|
||||
122: "EDQUOT", //Quota exceeded
|
||||
123: "ENOMEDIUM", //No medium found
|
||||
124: "EMEDIUMTYPE", //Wrong medium type
|
||||
125: "ECANCELED", //Operation Canceled
|
||||
126: "ENOKEY", //Required key not available
|
||||
127: "EKEYEXPIRED", //Key has expired
|
||||
128: "EKEYREVOKED", //Key has been revoked
|
||||
129: "EKEYREJECTED", //Key was rejected by service
|
||||
130: "EOWNERDEAD", //Owner died
|
||||
131: "ENOTRECOVERABLE",
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
const jimp = require('jimp')
|
||||
|
||||
const screen = getScreenDimensions()
|
||||
const buffer = Buffer.alloc(screen.width * screen.height * screen.byteDepth)
|
||||
//TODO: implement automatic cache cleanup
|
||||
/**
|
||||
* @type {{ [key: string]: import('@jimp/core').Bitmap }}
|
||||
*/
|
||||
const imageCache = {}
|
||||
|
||||
function getScreenDimensions() {
|
||||
const vsize = fs.readFileSync('/sys/class/graphics/fb0/virtual_size', { encoding: 'utf-8' }).split(',')
|
||||
const byteDepth = parseInt(fs.readFileSync('/sys/class/graphics/fb0/bits_per_pixel').toString()) / 8
|
||||
|
||||
return {
|
||||
width: parseInt(vsize[0]),
|
||||
height: parseInt(vsize[1]),
|
||||
byteDepth
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { Buffer } data
|
||||
*/
|
||||
function flip(data = buffer) {
|
||||
try {
|
||||
fs.writeFileSync('/dev/fb0', data, { encoding: 'binary' })
|
||||
} catch(e) {
|
||||
console.log("could not write to /dev/fb0")
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
buffer.fill(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filepath
|
||||
*/
|
||||
function removeFromCache(filepath) {
|
||||
delete imageCache[filepath]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filepath
|
||||
* @returns { Promise<import('@jimp/core').Bitmap> } BGRA buffer
|
||||
*/
|
||||
async function readImgFile(filepath) {
|
||||
const img = await jimp.read(filepath)
|
||||
const bitmap = img.bitmap
|
||||
bitmap.data = rgbaTObgra(bitmap.data)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { number } x
|
||||
* @param { number } y
|
||||
* @param { import('@jimp/core').Bitmap | Pencil } bitmap
|
||||
*/
|
||||
function drawBitmap(x, y, bitmap, handleTransparency = true) {
|
||||
for(let dy = 0; dy < bitmap.height; dy++) {
|
||||
let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1)
|
||||
let bitmapLineStart = bitmap.width * screen.byteDepth * dy
|
||||
let dx = x
|
||||
|
||||
const offscreenRight = dx + bitmap.width - screen.width
|
||||
if(offscreenRight > 0) {
|
||||
bitmapLineEnd -= offscreenRight*4
|
||||
}
|
||||
|
||||
const offscreenLeft = -dx
|
||||
if(offscreenLeft > 0) {
|
||||
bitmapLineStart += offscreenLeft*4
|
||||
dx = 0
|
||||
}
|
||||
|
||||
const offscreenTop = -y
|
||||
if(offscreenTop >= dy) {
|
||||
dy = offscreenTop
|
||||
continue
|
||||
}
|
||||
|
||||
const offscreenBottom = bitmap.height + y - screen.height
|
||||
if(offscreenBottom > 0 && bitmap.height - offscreenBottom <= dy) {
|
||||
break
|
||||
}
|
||||
|
||||
if(bitmapLineEnd < bitmapLineStart) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
const line = bitmap.data.subarray(bitmapLineStart, bitmapLineEnd)
|
||||
|
||||
const bufferPlacement = dx * screen.byteDepth + screen.width * (dy + y) * screen.byteDepth
|
||||
|
||||
if(handleTransparency) {
|
||||
const currentLine = buffer.subarray(bufferPlacement, bufferPlacement + line.length)
|
||||
for(let i=0; i < line.length; i += 4) {
|
||||
const transparency = line.readUInt8(i+3) / 255
|
||||
if(transparency < 1) {
|
||||
/** @type { Uint8Array } */
|
||||
const newLine = new Uint8Array(3)
|
||||
for(let j=0; j < 3; j++) {
|
||||
newLine[j] = (currentLine.readUInt8(j+i)*1-transparency + line.readUInt8(j+i)*transparency)
|
||||
}
|
||||
line.set(newLine, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer.set(Array.from(line), bufferPlacement)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { number } x
|
||||
* @param { number } y
|
||||
* @param { string } filepath
|
||||
* @description this function work fine but will use caching. to clear the cache you can use removeFromCache(filepath) or you can keep the cache on the
|
||||
* client side and use readImgFile and drawBitmap methods instead
|
||||
*/
|
||||
async function drawImgFile(x, y, filepath) {
|
||||
//not caching would imply reading the image each time we want to write it to the screen even for small movement
|
||||
let bitmap;
|
||||
if(!imageCache[filepath]) {
|
||||
bitmap = await readImgFile(filepath)
|
||||
imageCache[filepath] = bitmap
|
||||
} else {
|
||||
bitmap = imageCache[filepath]
|
||||
}
|
||||
drawBitmap(x, y, bitmap)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { Buffer } buff
|
||||
*/
|
||||
function rgbaTObgra(buff) {
|
||||
for(let i=0; i < buff.length; i += 4) {
|
||||
const r = buff.readUInt8(i)
|
||||
const b = buff.readUInt8(i+2)
|
||||
|
||||
buff.set([b], i)
|
||||
buff.set([r], i+2)
|
||||
}
|
||||
return buff
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } color
|
||||
* @returns { number[] }
|
||||
*/
|
||||
function parseHexColor(color) {
|
||||
if(!color.startsWith('#') || color.length !== 7) {
|
||||
throw new Error('invalid hex color code')
|
||||
}
|
||||
const r = parseInt(color.substring(1,2), 16)
|
||||
const v = parseInt(color.substring(3,4), 16)
|
||||
const b = parseInt(color.substring(5,6), 16)
|
||||
return [b, v, r, 0]
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param { number } x
|
||||
* @param { number } y
|
||||
* @param { string | number[] } colorCode
|
||||
*/
|
||||
function setPixel(x, y, colorCode) {
|
||||
if (screen.byteDepth !== 4) {
|
||||
throw new Error('Depth not supported yet')
|
||||
}
|
||||
|
||||
if(typeof colorCode === 'string') {
|
||||
colorCode = parseHexColor(colorCode)
|
||||
}
|
||||
buffer.set(colorCode, (x + y * screen.width) * screen.byteDepth)
|
||||
}
|
||||
|
||||
module.exports = { flip, clear, getScreenDimensions, drawImgFile, readImgFile, drawBitmap, parseHexColor, setPixel, removeFromCache }
|
||||
@@ -0,0 +1,23 @@
|
||||
//@ts-check
|
||||
const { exec, fork } = require('child_process');
|
||||
/**
|
||||
* @param {string} path
|
||||
* @deprecated
|
||||
*/
|
||||
function hookTo(path) {
|
||||
exec(`node ${path}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
*/
|
||||
async function fHook(path) {
|
||||
const child = fork(path)
|
||||
return new Promise((res, rej) => {
|
||||
child.on('exit', () => {
|
||||
res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { hookTo, fHook }
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
//@ts-check
|
||||
function panic() {
|
||||
console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE")
|
||||
while(1) {}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const initd = require('./initd.js')
|
||||
const reboot = require('./reboot.js')
|
||||
const { fHook } = require("./hook.js")
|
||||
|
||||
console.clear()
|
||||
|
||||
await initd()
|
||||
|
||||
//chainload into sheebr
|
||||
await fHook("/usr/bin/sheebr.js")
|
||||
reboot.disableCtrlAltSupr()
|
||||
reboot.powerOff()
|
||||
|
||||
console.log("End of init reached")
|
||||
reboot.enableCtrlAltSupr()
|
||||
panic()
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
panic()
|
||||
}
|
||||
}
|
||||
main()
|
||||
@@ -0,0 +1,83 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
/**
|
||||
* @typedef {{ name: string, before: string[], after: string[], init(): undefined | Promise<undefined> }} InitScript
|
||||
*/
|
||||
async function init() {
|
||||
|
||||
const initdFiles = fs.readdirSync('/etc/init.d/')
|
||||
const initdScripts = initdFiles.filter( (v) => v.endsWith('.js'))
|
||||
|
||||
/**
|
||||
* @type { Array<String> }
|
||||
*/
|
||||
const finishedScripts = []
|
||||
|
||||
/**
|
||||
* @type { Array<InitScript> }
|
||||
*/
|
||||
const scripts = []
|
||||
|
||||
for(const script of initdScripts) {
|
||||
const scriptCandidate = require(path.join('/etc/init.d/', script))
|
||||
if(scriptCandidate?.before && scriptCandidate?.after && scriptCandidate?.init)
|
||||
scripts.push({ ...scriptCandidate, name: script})
|
||||
else
|
||||
console.error(`Invalid(missing exports) script error :${script}`)
|
||||
}
|
||||
|
||||
const befores = processBefores(scripts)
|
||||
|
||||
let i = 0
|
||||
while(scripts.length) {
|
||||
const s = scripts[i % scripts.length]
|
||||
i += 1
|
||||
if(isSubSet(s.after, finishedScripts) && ( !befores[s.name] || isSubSet(befores[s.name], finishedScripts) )) {
|
||||
//on supprime ce service
|
||||
scripts.splice(scripts.indexOf(s), 1)
|
||||
const result = s.init()
|
||||
if(typeof result?.then === 'function') {
|
||||
await result
|
||||
finishedScripts.push(s.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Array<T>} arraya
|
||||
* @param {Array<T>} arrayb
|
||||
*/
|
||||
function isSubSet(arraya, arrayb) {
|
||||
for(const a of arraya) {
|
||||
if(!arrayb.includes(a)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<InitScript>} scripts
|
||||
* @returns {{ [key: string]: string[] }}
|
||||
*/
|
||||
function processBefores(scripts) {
|
||||
/**
|
||||
* @type {{ [key: string]: string[] }}
|
||||
*/
|
||||
const result = {}
|
||||
for(const script of scripts) {
|
||||
for(const before of script.before){
|
||||
if(! result[before]) result[before] = [script.name]
|
||||
else result[before].push(script.name)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
module.exports = init
|
||||
@@ -0,0 +1,27 @@
|
||||
//@ts-check
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns
|
||||
*/
|
||||
async function input(str) {
|
||||
console.log(str)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
let line = "";
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
});
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = input
|
||||
@@ -0,0 +1,6 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const { ioctl } = require('./ioctl.node')
|
||||
|
||||
|
||||
module.exports = { ioctl }
|
||||
@@ -0,0 +1,35 @@
|
||||
//@ts-check
|
||||
|
||||
//@ts-expect-error
|
||||
const ip = require('./ip.node')
|
||||
|
||||
const flags = {
|
||||
IFF_UP: 0x1, /* Interface is up. */
|
||||
IFF_BROADCAST: 0x2, /* Broadcast address valid. */
|
||||
IFF_DEBUG: 0x4, /* Turn on debugging. */
|
||||
IFF_LOOPBACK: 0x8, /* Is a loopback net. */
|
||||
IFF_POINTOPOINT: 0x10, /* Interface is point-to-point link. */
|
||||
IFF_NOTRAILERS: 0x20, /* Avoid use of trailers. */
|
||||
IFF_RUNNING: 0x40, /* Resources allocated. */
|
||||
IFF_NOARP: 0x80, /* No address resolution protocol. */
|
||||
IFF_PROMISC: 0x100, /* Receive all packets. */
|
||||
/* Not supported */
|
||||
IFF_ALLMULTI: 0x200, /* Receive all multicast packets. */
|
||||
IFF_MASTER: 0x400, /* Master of a load balancer. */
|
||||
IFF_SLAVE: 0x800, /* Slave of a load balancer. */
|
||||
IFF_MULTICAST: 0x1000, /* Supports multicast. */
|
||||
IFF_PORTSEL: 0x2000, /* Can set media type. */
|
||||
IFF_AUTOMEDIA: 0x4000, /* Auto media select active. */
|
||||
IFF_DYNAMIC: 0x8000 /* Dialup device with changing addresses. */
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } interface
|
||||
* @param { number } flags
|
||||
* @return { number }
|
||||
*/
|
||||
function setFlags(interface, flags) {
|
||||
return ip.setFlags(interface, flags)
|
||||
}
|
||||
|
||||
module.exports = { setFlags, flags }
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,65 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const { syscall } = require('./syscall.node')
|
||||
const errno = require('./errno')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
|
||||
|
||||
// TBD
|
||||
const SYSCALL_INIT_MODULE = 105
|
||||
const SYSCALL_FINIT_MODULE = 273
|
||||
|
||||
const doProcExists = () => fs.existsSync('/proc')
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} path
|
||||
* @param {string} params
|
||||
* @param {number} flags
|
||||
* @deprecated un tested dangerous
|
||||
*/
|
||||
function finit_module(path, params = "", flags = 0) {
|
||||
const fileDescriptor = fs.openSync(path, 'r')
|
||||
const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
|
||||
if(result > 0) {
|
||||
throw new Error(errno[result])
|
||||
} else {
|
||||
if(result == -1) {
|
||||
throw new Error('non number or string argument recived')
|
||||
}else if(result == -2) {
|
||||
throw new Error('unsuported argument length (1-5)')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uname() {
|
||||
if(!doProcExists) {
|
||||
throw "Proc don't exists exception"
|
||||
}
|
||||
const linuxVersionString = fs.readFileSync('/proc/version').toString()
|
||||
return linuxVersionString.split(' ')[2]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} modulename
|
||||
*/
|
||||
function modprobe(modulename) {
|
||||
const name = uname()
|
||||
if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) {
|
||||
finit_module(path.join('/lib/modules', name, 'kernel', modulename))
|
||||
} else {
|
||||
throw new Error("file not found " + path.join('/lib/modules', name, 'kernel', modulename))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function lsmod() {
|
||||
if(!doProcExists) {
|
||||
throw "Proc don't exists exception"
|
||||
}
|
||||
return fs.readFileSync('/proc/modules').toString('utf-8').split('\n')
|
||||
}
|
||||
|
||||
module.exports = { modprobe, uname, finit_module, doProcExists, lsmod, syscall }
|
||||
@@ -0,0 +1,68 @@
|
||||
//@ts-check
|
||||
const fs =require('fs')
|
||||
/**
|
||||
* @type {{ mount: (device_path: string, mount_point: string, fs: string, flags: number, fsparams: string ) => number }}
|
||||
*///@ts-expect-error
|
||||
const nodemount = require("./mount.node")
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const cmount = nodemount.mount
|
||||
|
||||
|
||||
/* These are the fs-independent mount-flags: up to 16 flags are
|
||||
supported */
|
||||
const flags = {
|
||||
MS_RDONLY: 1, /* Mount read-only. */
|
||||
MS_NOSUID: 2, /* Ignore suid and sgid bits. */
|
||||
MS_NODEV: 4, /* Disallow access to device special files. */
|
||||
MS_NOEXEC: 8, /* Disallow program execution. */
|
||||
MS_SYNCHRONOUS: 16, /* Writes are synced at once. */
|
||||
MS_REMOUNT: 32, /* Alter flags of a mounted FS. */
|
||||
MS_MANDLOCK: 64, /* Allow mandatory locks on an FS. */
|
||||
MS_DIRSYNC: 128, /* Directory modifications are synchronous. */
|
||||
MS_NOATIME: 1024, /* Do not update access times. */
|
||||
MS_NODIRATIME: 2048, /* Do not update directory access times. */
|
||||
MS_BIND: 4096, /* Bind directory at different place. */
|
||||
MS_MOVE: 8192,
|
||||
MS_REC: 16384,
|
||||
MS_SILENT: 32768,
|
||||
MS_POSIXACL: 1 << 16, /* VFS does not apply the umask. */
|
||||
MS_UNBINDABLE: 1 << 17, /* Change to unbindable. */
|
||||
MS_PRIVATE: 1 << 18, /* Change to private. */
|
||||
MS_SLAVE: 1 << 19, /* Change to slave. */
|
||||
MS_SHARED: 1 << 20, /* Change to shared. */
|
||||
MS_RELATIME: 1 << 21, /* Update atime relative to mtime/ctime. */
|
||||
MS_KERNMOUNT: 1 << 22, /* This is a kern_mount call. */
|
||||
MS_I_VERSION: 1 << 23, /* Update inode I_version field. */
|
||||
MS_STRICTATIME: 1 << 24, /* Always perform atime updates. */
|
||||
MS_LAZYTIME: 1 << 25, /* Update the on-disk [acm]times lazily. */
|
||||
MS_ACTIVE: 1 << 30,
|
||||
MS_NOUSER: 1 << 31
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} devicePath
|
||||
* @param {string} mountPoint
|
||||
* @param {string} fstype
|
||||
* @param {number} flags
|
||||
* @param {string} fsparams
|
||||
* @returns {number}
|
||||
*/
|
||||
function mount(devicePath, mountPoint, fstype, flags, fsparams) {
|
||||
const supportedFilesystems = require('./suportedFilesystems')
|
||||
|
||||
const filesystem = supportedFilesystems.find( v => v.name === fstype)
|
||||
if(! filesystem) {
|
||||
throw "Invalid filesystem"
|
||||
}
|
||||
|
||||
if(! fs.existsSync(devicePath) && filesystem.hasdev)
|
||||
throw "Device don't exist"
|
||||
return cmount(devicePath, mountPoint, fstype, flags, fsparams)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = { mount, cmount, flags }
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.21"
|
||||
},
|
||||
"dependencies": {
|
||||
"jimp": "^0.16.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//@ts-check
|
||||
/* Perform a hard reset now. */
|
||||
const RB_AUTOBOOT = 0x01234567
|
||||
|
||||
/* Halt the system. */
|
||||
const RB_HALT_SYSTEM = 0xcdef0123
|
||||
|
||||
/* Enable reboot using Ctrl-Alt-Delete keystroke. */
|
||||
const RB_ENABLE_CAD = 0x89abcdef
|
||||
|
||||
/* Disable reboot using Ctrl-Alt-Delete keystroke. */
|
||||
const RB_DISABLE_CAD = 0
|
||||
|
||||
/* Stop system and switch power off if possible. */
|
||||
const RB_POWER_OFF = 0x4321fedc
|
||||
|
||||
/* Suspend system using software suspend. */
|
||||
const RB_SW_SUSPEND = 0xd000fce2
|
||||
|
||||
/* Reboot system into new kernel. */ //no idea how to use that but hey
|
||||
const RB_KEXEC = 0x45584543
|
||||
|
||||
/**
|
||||
@type {{
|
||||
reboot: (rebootid: number) => void //https://unix.superglobalmegacorp.com/Net2/newsrc/sys/syscall.h.html
|
||||
syscall: (syscallid: number) => void
|
||||
}}
|
||||
*///@ts-expect-error
|
||||
const syscalls = require('./syscall.node')
|
||||
|
||||
function disableCtrlAltSupr() {
|
||||
syscalls.reboot(RB_DISABLE_CAD)
|
||||
}
|
||||
|
||||
function enableCtrlAltSupr() {
|
||||
syscalls.reboot(RB_ENABLE_CAD)
|
||||
}
|
||||
|
||||
function halt() {
|
||||
syscalls.reboot(RB_HALT_SYSTEM)
|
||||
}
|
||||
|
||||
function reboot() {
|
||||
syscalls.reboot(RB_AUTOBOOT)
|
||||
}
|
||||
|
||||
function powerOff() {
|
||||
syscalls.reboot(RB_POWER_OFF)
|
||||
}
|
||||
|
||||
function suspend() {
|
||||
syscalls.reboot(RB_SW_SUSPEND)
|
||||
}
|
||||
|
||||
|
||||
module.exports = { disableCtrlAltSupr, enableCtrlAltSupr, halt, reboot, powerOff, suspend }
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
async function mSleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
async function sleep(s) {
|
||||
return mSleep(s * 1000)
|
||||
}
|
||||
|
||||
module.exports = { mSleep, sleep }
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const csocket = require('./socket.node')
|
||||
|
||||
/**
|
||||
* @param { number } domain
|
||||
* @param { number } type
|
||||
* @param { number } protocol
|
||||
* @return { number }
|
||||
*/
|
||||
function socket(domain, type, protocol) {
|
||||
return csocket.socket(domain, type, protocol)
|
||||
}
|
||||
|
||||
const socketTypes = {
|
||||
SOCK_DGRAM : 1, /* Connectionless, unreliable datagrams of fixed maximum length. */
|
||||
SOCK_STREAM : 2, /* Sequenced, reliable, connection-based byte streams. */
|
||||
SOCK_RAW : 3, /* Raw protocol interface. */
|
||||
SOCK_RDM : 4, /* Reliably-delivered messages. */
|
||||
SOCK_SEQPACKET : 5, /* Sequenced, reliable, connection-based, datagrams of fixed maximum length. */
|
||||
SOCK_DCCP : 6, /* Datagram Congestion Control Protocol. */
|
||||
SOCK_PACKET : 10, /* Linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level. */
|
||||
|
||||
SOCK_CLOEXEC : 0o2000000, /* Atomically set close-on-exec flag for the new descriptor(s). */
|
||||
SOCK_NONBLOCK : 0o0000200 /* Atomically mark descriptor(s) as non-blocking. */
|
||||
}
|
||||
|
||||
module.exports = { socketTypes, socket }
|
||||
@@ -0,0 +1,9 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
|
||||
const systems = fs.readFileSync('/proc/filesystems', { encoding: 'utf-8' }).split('\n')
|
||||
|
||||
const filesystems = systems.map(s => ({ hasdev: !s.includes('nodev'), name: s.includes('nodev') ? s.split('nodev')[1].trim() : s.trim() }))
|
||||
|
||||
module.exports = filesystems
|
||||
Object.freeze(module.exports)
|
||||
Reference in New Issue
Block a user