ajout de Sheebr + support de shutdown + auto install kernel
This commit is contained in:
@@ -4,3 +4,6 @@ rootfs
|
|||||||
linux-firmware
|
linux-firmware
|
||||||
disk.img
|
disk.img
|
||||||
diskoffset
|
diskoffset
|
||||||
|
package-lock.json
|
||||||
|
build
|
||||||
|
node_modules
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.linting.enabled": false
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"target_name": "syscall",
|
||||||
|
'cflags': [ '-Wall' ],
|
||||||
|
"sources": [
|
||||||
|
"clibs/chibrax/syscall.cc"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
rm -rf rootfs
|
||||||
|
rm -rf build
|
||||||
|
rm -f disk.img
|
||||||
|
rm -f diskoffset
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
node node_modules/node-gyp/bin/node-gyp.js configure
|
||||||
|
node node_modules/node-gyp/bin/node-gyp.js build
|
||||||
|
|
||||||
|
cp build/Release/syscall.node rootfs\ overrides/chibrax/syscall.node
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#include <sys/syscall.h> /* Definition of SYS_* constants */
|
||||||
|
#include <sys/reboot.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <node.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef RB_HALT_SYSTEM
|
||||||
|
# define BMAGIC_HALT RB_HALT_SYSTEM
|
||||||
|
#else
|
||||||
|
# define BMAGIC_HALT RB_HALT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BMAGIC_REBOOT RB_AUTOBOOT
|
||||||
|
|
||||||
|
#define BMAGIC_POWEROFF RB_POWER_OFF
|
||||||
|
|
||||||
|
|
||||||
|
namespace syscallNode {
|
||||||
|
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
v8::Isolate* isolate = args.GetIsolate();
|
||||||
|
|
||||||
|
if (!args[0]->IsNumber()) {
|
||||||
|
isolate->ThrowException(v8::Exception::TypeError(
|
||||||
|
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long argsValue = args[0].As<v8::Number>()->Value();
|
||||||
|
syscall(argsValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodeHalt(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
reboot(BMAGIC_HALT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
reboot(BMAGIC_REBOOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodePoweroff(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
|
reboot(BMAGIC_POWEROFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize(v8::Local<v8::Object> exports) {
|
||||||
|
NODE_SET_METHOD(exports, "halt", nodeHalt);
|
||||||
|
NODE_SET_METHOD(exports, "reboot", nodeReboot);
|
||||||
|
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
|
||||||
|
NODE_SET_METHOD(exports, "poweroff", nodePoweroff);
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE_MODULE(syscall_api, Initialize)
|
||||||
|
}
|
||||||
@@ -10,6 +10,14 @@ then echo "Please run createLiveImage.sh first"
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "rebuilding C++ hooks"
|
||||||
|
./clibs.sh
|
||||||
|
echo "done"
|
||||||
|
|
||||||
|
echo "coping overrides..."
|
||||||
|
sudo cp rootfs\ overrides/* rootfs/ -r
|
||||||
|
echo "done"
|
||||||
|
|
||||||
|
|
||||||
CHIBRAX_MOUNT_POINT="/tmp/chibraxMountPoint"
|
CHIBRAX_MOUNT_POINT="/tmp/chibraxMountPoint"
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ mkdir $CHIBRAX_MOUNT_POINT -p
|
|||||||
mkfs.ext4 ${LOOP}
|
mkfs.ext4 ${LOOP}
|
||||||
mount ${LOOP} $CHIBRAX_MOUNT_POINT
|
mount ${LOOP} $CHIBRAX_MOUNT_POINT
|
||||||
|
|
||||||
|
echo "rebuilding C++ hooks"
|
||||||
|
./clibs.sh
|
||||||
|
echo "done"
|
||||||
|
|
||||||
echo "coping rootfs"
|
echo "coping rootfs"
|
||||||
cp rootfs/* $CHIBRAX_MOUNT_POINT -r
|
cp rootfs/* $CHIBRAX_MOUNT_POINT -r
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
pwd
|
if [ ! -d src ]
|
||||||
|
then
|
||||||
|
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ src
|
||||||
|
fi
|
||||||
cd src
|
cd src
|
||||||
make mrproper
|
make mrproper
|
||||||
cp ../.config .config
|
cp ../.config .config
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"node-gyp": "^8.4.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
sudo rm root.iso
|
|
||||||
sudo rm chibrax.tar.gz
|
|
||||||
|
|
||||||
echo "Cloning the firmware"
|
|
||||||
git clone https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
|
|
||||||
cd linux-firmware && git pull && cd -
|
|
||||||
sudo mkdir -p rootfs/usr/lib/firmware
|
|
||||||
sudo cp linux-firmware/* rootfs/usr/lib/firmware/ -r
|
|
||||||
|
|
||||||
sudo cp rootfs\ overrides/* rootfs/ -r
|
|
||||||
|
|
||||||
sudo rm rootfs/var/cache -rf
|
|
||||||
|
|
||||||
sudo tar -czvf chibrax.tar.gz rootfs
|
|
||||||
sudo mkisofs -o rootfs.iso chibrax.tar.gz
|
|
||||||
|
|
||||||
sudo rm rootfs/etc/grub.d/10_linux
|
|
||||||
sudo rm rootfs/etc/grub.d/10_linux_xen
|
|
||||||
sudo rm rootfs/etc/grub.d/30_os-prober
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//@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()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function rHook(path) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { hookTo, fHook }
|
||||||
@@ -1,29 +1,53 @@
|
|||||||
const audio = require('./audio.js')
|
//@ts-check
|
||||||
|
function panic() {
|
||||||
|
console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE")
|
||||||
|
while(1) {}
|
||||||
|
}
|
||||||
|
|
||||||
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
|
async function main() {
|
||||||
console.log(`
|
try {
|
||||||
|
const audio = require('./audio.js')
|
||||||
|
//@ts-expect-error
|
||||||
|
const { poweroff, halt } = require('./shutdown.js')
|
||||||
|
const input = require('./input.js')
|
||||||
|
const { fHook } = require("./hook.js")
|
||||||
|
|
||||||
|
console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
|
||||||
|
console.log(`
|
||||||
|
|
||||||
|
|
||||||
_______ _________ ______ _______ _______
|
_______ _________ ______ _______ _______
|
||||||
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /|
|
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /|
|
||||||
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / )
|
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / )
|
||||||
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) /
|
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) /
|
||||||
| | | ___ | | | | __ ( | __)| ___ | ) _ (
|
| | | ___ | | | | __ ( | __)| ___ | ) _ (
|
||||||
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\
|
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\
|
||||||
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ )
|
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ )
|
||||||
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\|
|
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\|
|
||||||
|
|
||||||
_______ _______
|
_______ _______
|
||||||
( ___ )( ____ \\
|
( ___ )( ____ \\
|
||||||
| ( ) || ( \\/
|
| ( ) || ( \\/
|
||||||
| | | || (_____
|
| | | || (_____
|
||||||
| | | |(_____ )
|
| | | |(_____ )
|
||||||
| | | | ) |
|
| | | | ) |
|
||||||
| (___) |/\\____) |
|
| (___) |/\\____) |
|
||||||
(_______)\\_______)
|
(_______)\\_______)
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
audio('/chibrax/sheeebr.wav')
|
audio('/chibrax/sheeebr.wav')
|
||||||
|
|
||||||
while(1) {}
|
//chainload into sheebr
|
||||||
|
await fHook("/usr/bin/sheebr.js")
|
||||||
|
poweroff()
|
||||||
|
|
||||||
|
/*while(1){}
|
||||||
|
console.log("End of init reached")
|
||||||
|
panic()*/
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
panic()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main()
|
||||||
|
|||||||
@@ -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,5 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^16.11.10"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
syscalls = require('./syscall.node')
|
||||||
|
module.exports = syscalls
|
||||||
@@ -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,16 @@
|
|||||||
|
{
|
||||||
|
"include": ["./**/*"],
|
||||||
|
"compilerOptions": {
|
||||||
|
// Tells TypeScript to read JS files, as
|
||||||
|
// normally they are ignored as source files
|
||||||
|
"allowJs": true,
|
||||||
|
// Generate d.ts files
|
||||||
|
"declaration": true,
|
||||||
|
"emitDeclarationOnly": false,
|
||||||
|
"noEmit": true,
|
||||||
|
"lib": [ "ES2016" ],
|
||||||
|
"target": "es2016",
|
||||||
|
"moduleResolution":"Node",
|
||||||
|
"noImplicitAny": true,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
if(process.argv.length >= 3){
|
||||||
|
console.log(process.argv[3])
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
let path = process.argv[3] ?? '.'
|
||||||
|
let optionsArray = process.argv.slice(4) ?? []
|
||||||
|
let options = []
|
||||||
|
for(let option of optionsArray){
|
||||||
|
if(option.startwith("--")) options.push(option.slice)
|
||||||
|
else if(options.startwith("-")) options.push += option.slice(1).split('').map(el => {return '-' + el})
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = fs.readdirSync(path);
|
||||||
|
const nonHiddenFiles = files.filter(file => file[0] != '.')
|
||||||
|
|
||||||
|
console.log(options.includes('-a') ? files.join(' ') : nonHiddenFiles.join(' '))
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
if(process.argv.length >= 3){
|
||||||
|
fs.mkdir(process.argv[3], { recursive: true }, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
console.log(process.cwd())
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
const { Lexer } = require('../lib/sheebr/lexer')
|
||||||
|
const { getline } = require('../lib/sheebr/utils')
|
||||||
|
const fs = require('fs')
|
||||||
|
const environment = require('../lib/sheebr/environment')
|
||||||
|
const readline = require('readline').createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
terminal: false
|
||||||
|
});
|
||||||
|
const readlineSync = require('../lib/sheebr/readLineSync')
|
||||||
|
let execSync = require('child_process').execSync
|
||||||
|
|
||||||
|
|
||||||
|
let current_dir = process.cwd()
|
||||||
|
|
||||||
|
start()
|
||||||
|
|
||||||
|
async function start(){
|
||||||
|
while(true){
|
||||||
|
input = await getline("sheebr> ");
|
||||||
|
if(input == "exit") break;
|
||||||
|
else evaluate(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluate(input){
|
||||||
|
let lexer = new Lexer(input)
|
||||||
|
args = lexer.scanTokens()
|
||||||
|
|
||||||
|
if(args[0] == "cd"){
|
||||||
|
if(args.length != 2){
|
||||||
|
console.log("Wrong number of arguments"); return;}
|
||||||
|
if(!fs.existsSync(args[1])){console.log("Folder does not exist"); return;}
|
||||||
|
current_dir = args[1][0] == "/" ? args[1] : current_dir + '/' + args[1];
|
||||||
|
console.log(current_dir)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// check for all folders in path
|
||||||
|
|
||||||
|
let found = false;
|
||||||
|
for(let path of environment.path){
|
||||||
|
let tobreak = false;
|
||||||
|
const files = fs.readdirSync(path);
|
||||||
|
if(files.includes(`${args[0]}.js`)){
|
||||||
|
found = true;
|
||||||
|
script = execSync(`node ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir});
|
||||||
|
process.stdout.write(script)
|
||||||
|
tobreak = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tobreak) break;
|
||||||
|
}
|
||||||
|
if(!found){
|
||||||
|
console.log("Program not found")
|
||||||
|
}
|
||||||
|
let program = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
if(process.argv.length >= 3){
|
||||||
|
fs.openSync(process.argv[3], 'w');
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
let environment = {
|
||||||
|
path: ["/sheebr", "/usr/bin"]
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = environment
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
const { isAlpha } = require('./utils')
|
||||||
|
|
||||||
|
|
||||||
|
class Lexer{
|
||||||
|
constructor(source){
|
||||||
|
this.tokens = [];
|
||||||
|
this.current = 0;
|
||||||
|
this.start = 0;
|
||||||
|
this.source = source
|
||||||
|
}
|
||||||
|
|
||||||
|
scanTokens(){
|
||||||
|
while(this.current < this.source.length){
|
||||||
|
this.start = this.current
|
||||||
|
this.scanToken()
|
||||||
|
|
||||||
|
}
|
||||||
|
return this.tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
scanToken(){
|
||||||
|
|
||||||
|
if(this.source[this.current] == "\""){
|
||||||
|
this.string()
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
let content = ""
|
||||||
|
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
|
||||||
|
content += this.source[this.current];
|
||||||
|
this.current++;
|
||||||
|
|
||||||
|
}
|
||||||
|
this.tokens.push(content)
|
||||||
|
}
|
||||||
|
this.current++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
string(){
|
||||||
|
this.current++;
|
||||||
|
let content = ""
|
||||||
|
while(this.source[this.current] != "\"" && this.current < this.source.length){
|
||||||
|
content += this.source[this.current];
|
||||||
|
this.current++;
|
||||||
|
}
|
||||||
|
this.tokens.push(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
addToken(tokenType, value=""){
|
||||||
|
this.tokens.push(Token(tokenType, value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Lexer
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
|||||||
|
async function getline(str) {
|
||||||
|
process.stdout.write(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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAlpha(str){
|
||||||
|
return /^[a-zA-Z]*$/.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isAlpha, getline
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user