forked from Hyperion/HyperionOS
did mutiple changes
This commit is contained in:
@@ -6,9 +6,10 @@ syscall.TTY_print("HyperionOS Bash Shell")
|
|||||||
local str=""
|
local str=""
|
||||||
local stopInput=false
|
local stopInput=false
|
||||||
local inputIO=syscall.IO_getBoundQueue()
|
local inputIO=syscall.IO_getBoundQueue()
|
||||||
local pid=syscall.HPV_getPid()
|
local pid=syscall.getpid()
|
||||||
local proc=0
|
local proc=0
|
||||||
local fs=require("sys.fs")
|
local fs=require("sys.fs")
|
||||||
|
local timeout=1
|
||||||
printInline("> ")
|
printInline("> ")
|
||||||
while true do
|
while true do
|
||||||
local event = {syscall.IO_pullEvent()}
|
local event = {syscall.IO_pullEvent()}
|
||||||
@@ -45,7 +46,7 @@ while true do
|
|||||||
printInline("> ")
|
printInline("> ")
|
||||||
end
|
end
|
||||||
syscall.IO_bind("bash:"..tostring(pid))
|
syscall.IO_bind("bash:"..tostring(pid))
|
||||||
proc = syscall.HPV_spawn(program, path)
|
proc = syscall.spawn(program, path)
|
||||||
syscall.IO_bind(inputIO)
|
syscall.IO_bind(inputIO)
|
||||||
end
|
end
|
||||||
str=""
|
str=""
|
||||||
@@ -58,7 +59,7 @@ while true do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if stopInput then
|
if stopInput then
|
||||||
local exited, code = syscall.HPV_collect(proc)
|
local exited, code = syscall.collect(proc)
|
||||||
if exited then
|
if exited then
|
||||||
print("\nTask exited with code:\n"..tostring(code))
|
print("\nTask exited with code:\n"..tostring(code))
|
||||||
printInline("> ")
|
printInline("> ")
|
||||||
@@ -66,16 +67,22 @@ while true do
|
|||||||
else
|
else
|
||||||
if event[1] then
|
if event[1] then
|
||||||
if event[1]=="keyTyped" and event[3]=="^c" then
|
if event[1]=="keyTyped" and event[3]=="^c" then
|
||||||
syscall.HPV_kill(proc)
|
syscall.kill(proc)
|
||||||
print("Terminated")
|
print("Terminated")
|
||||||
printInline("> ")
|
printInline("> ")
|
||||||
stopInput=false
|
stopInput=false
|
||||||
elseif event[1]=="keyTyped" and event[3]=="^d" then
|
elseif event[1]=="keyTyped" and event[3]=="^d" then
|
||||||
syscall.HPV_kill(proc)
|
syscall.kill(proc)
|
||||||
syscall.HPV_exit(0)
|
syscall.exit(0)
|
||||||
else
|
else
|
||||||
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
|
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
|
||||||
end
|
end
|
||||||
|
timeout=10
|
||||||
|
else
|
||||||
|
timeout=timeout-1
|
||||||
|
end
|
||||||
|
if timeout<0 then
|
||||||
|
sleep(.05)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
local userhost = (syscall.OS_getUser() or "Unknown").."@"..(syscall.OS_getHostname() or "Unknown")
|
local userhost = (syscall.getUser() or "Unknown").."@"..(syscall.getHostname() or "Unknown")
|
||||||
print(".. *. .. | "..userhost)
|
print(".. *. .. | "..userhost)
|
||||||
print(" *= +@* +* | "../rep("-",#userhost))
|
print(" *= +@* +* | "..string.rep("-",#userhost))
|
||||||
print(" .@#. -@@@= :#@. | OS: "..(syscall.OS_version() or "Unknown"))
|
print(" .@#. -@@@= :#@. | OS: "..(syscall.version() or "Unknown"))
|
||||||
print(" =@@+ *@@@# +@@= | Host: "..(syscall.OS_getHost() or "Unknown"))
|
print(" =@@+ *@@@# +@@= | Host: "..(syscall.getHost() or "Unknown"))
|
||||||
print(" %@@%: *@@@# -%@@% | Uptime: "..(syscall.OS_getUptime() or "Unknown"))
|
print(" %@@%: *@@@# -%@@% | Uptime: "..(syscall.getUptime() or "Unknown"))
|
||||||
print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring((#syscall.HPV_list() or "Unknown")))
|
print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring((#syscall.getTasks() or "Unknown")))
|
||||||
print(" :*@@@%- *@@@# -@@@@*: | Packages: ".."Unknown")
|
print(" :*@@@%- *@@@# -@@@@*: | Packages: ".."Unknown")
|
||||||
print(" =%@@#. *@@@# .#@@%= | Shell: "..(syscall.HPV_getEnviron("SHELL") or "Unknown"))
|
print(" =%@@#. *@@@# .#@@%= | Shell: "..(syscall.getEnviron("SHELL") or "Unknown"))
|
||||||
print(" :=. :*@@= *@@@# =@@+: .=: | ")
|
print(" :=. :*@@= *@@@# =@@+: .=: | ")
|
||||||
print(" %@#=..*# +@@@# #*..=#@# | ")
|
print(" %@#=..*# +@@@# #*..=#@# | ")
|
||||||
print(" .@@@@+=# .%@%: #=+@@@@. | ")
|
print(" .@@@@+=# .%@%: #=+@@@@. | ")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local fs = require("sys.fs")
|
local fs = require("sys.fs")
|
||||||
local bashStr = fs.readAllText("/bin/bash")
|
local bashStr = fs.readAllText("/bin/bash")
|
||||||
local bashFun = load(bashStr)
|
local bashFun = load(bashStr)
|
||||||
syscall.HPV_spawn(bashFun, "bash")
|
syscall.spawn(bashFun, "bash")
|
||||||
@@ -114,15 +114,15 @@ function fs.remove(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function fs.list(path)
|
function fs.list(path)
|
||||||
return syscall.list(path)
|
return syscall.listdir(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.type(path)
|
function fs.type(path)
|
||||||
return syscall.type(path)
|
return syscall.type(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.attributes(path)
|
function fs.stat(path)
|
||||||
return syscall.attributes(path)
|
return syscall.stat(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.exists(path)
|
function fs.exists(path)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ for i,v in ipairs(files) do
|
|||||||
if not startupFunc then
|
if not startupFunc then
|
||||||
kernel.log("Error loading startup script '" .. filepath .. "': " .. err, "ERROR")
|
kernel.log("Error loading startup script '" .. filepath .. "': " .. err, "ERROR")
|
||||||
else
|
else
|
||||||
syscall.HPV_spawn(function()
|
syscall.spawn(function()
|
||||||
syscall.IO_bind("eventQueue:"..tostring(i))
|
syscall.IO_bind("eventQueue:"..tostring(i))
|
||||||
local spot = #eventQueues+1
|
local spot = #eventQueues+1
|
||||||
eventQueues[spot]="eventQueue:"..tostring(i)
|
eventQueues[spot]="eventQueue:"..tostring(i)
|
||||||
@@ -38,20 +38,27 @@ for i,v in ipairs(files) do
|
|||||||
kernel.log("Successfully executed startup script: " .. filepath, "INFO")
|
kernel.log("Successfully executed startup script: " .. filepath, "INFO")
|
||||||
end
|
end
|
||||||
local event={true}
|
local event={true}
|
||||||
while event[1] do
|
while #event~=0 do
|
||||||
syscall.IO_pullEvent()
|
event={syscall.IO_pullEvent()}
|
||||||
end
|
end
|
||||||
end, "startup:" .. v)
|
end, "startup:" .. v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local timeout=1
|
||||||
while true do
|
while true do
|
||||||
local event = {syscall.IO_pullEvent()}
|
local event = {syscall.IO_pullEvent()}
|
||||||
if event[1] then
|
if event[1] then
|
||||||
for i,v in ipairs(eventQueues) do
|
for i,v in ipairs(eventQueues) do
|
||||||
syscall.IO_pushEvent(v, table.unpack(event))
|
syscall.IO_pushEvent(v, table.unpack(event))
|
||||||
end
|
end
|
||||||
|
timeout=10
|
||||||
|
else
|
||||||
|
timeout=timeout-1
|
||||||
|
end
|
||||||
|
if timeout<0 then
|
||||||
|
sleep(.05)
|
||||||
end
|
end
|
||||||
kernel.saveLog()
|
kernel.saveLog()
|
||||||
end
|
end
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
--:Minify:--
|
||||||
local kernel = ...
|
local kernel = ...
|
||||||
local vfs = {}
|
local vfs = {}
|
||||||
kernel.vfs=vfs
|
kernel.vfs=vfs
|
||||||
@@ -115,17 +116,13 @@ end
|
|||||||
local function getMeta(path)
|
local function getMeta(path)
|
||||||
local disk, newPath = resolvePath(path)
|
local disk, newPath = resolvePath(path)
|
||||||
|
|
||||||
kernel.log(newPath)
|
|
||||||
while newPath ~= "/" and newPath~="" do
|
while newPath ~= "/" and newPath~="" do
|
||||||
local target = newPath:match("([^/]+)/?$")
|
local target = newPath:match("([^/]+)/?$")
|
||||||
kernel.log(target)
|
|
||||||
if target == ".meta" then error("Cannot open metafile") end
|
if target == ".meta" then error("Cannot open metafile") end
|
||||||
if disk:fileExists(newPath .. ".meta") then
|
if disk:fileExists(newPath .. ".meta") then
|
||||||
return newPath .. ".meta", target
|
return newPath .. ".meta", target
|
||||||
end
|
end
|
||||||
newPath = newPath:gsub("/[^/]+/?$", "")
|
newPath = newPath:gsub("/[^/]+/?$", "")
|
||||||
kernel.log(newPath)
|
|
||||||
kernel.saveLog()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -430,7 +427,22 @@ function vfs.exists(path)
|
|||||||
local disk, diskPath = resolvePath(path)
|
local disk, diskPath = resolvePath(path)
|
||||||
local meta = getFileMeta(path)
|
local meta = getFileMeta(path)
|
||||||
checkperms(meta, "r")
|
checkperms(meta, "r")
|
||||||
disk:fileExists(diskPath)
|
return disk:fileExists(diskPath)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vfs.type(path)
|
||||||
|
local disk, diskPath = resolvePath(path)
|
||||||
|
local meta = getFileMeta(path)
|
||||||
|
checkperms(meta, "r")
|
||||||
|
return disk:type(diskPath)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vfs.getcwd()
|
||||||
|
return kernel.currentTask.cwd
|
||||||
|
end
|
||||||
|
|
||||||
|
function vfs.chdir(path)
|
||||||
|
kernel.currentTask.cwd=path
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Export syscalls
|
-- Export syscalls
|
||||||
@@ -453,9 +465,9 @@ sys["chmod"] = vfs.chmod
|
|||||||
sys["fchmod"] = vfs.fchmod
|
sys["fchmod"] = vfs.fchmod
|
||||||
sys["chown"] = vfs.chown
|
sys["chown"] = vfs.chown
|
||||||
sys["fchown"] = vfs.fchown
|
sys["fchown"] = vfs.fchown
|
||||||
sys["exists"]=vfs.exists
|
sys["exists"] = vfs.exists
|
||||||
|
sys["type"] = vfs.type
|
||||||
sys["mount"] = vfs.mount
|
sys["mount"] = vfs.mount
|
||||||
sys["umount"] = vfs.umount
|
sys["umount"] = vfs.umount
|
||||||
|
|
||||||
kernel.log("VFS module loaded")
|
kernel.log("VFS module loaded")
|
||||||
return vfs
|
|
||||||
@@ -1,238 +1,237 @@
|
|||||||
--:Minify:--
|
--:Minify:--
|
||||||
--local kernel = ...
|
local kernel = ...
|
||||||
--local pam = {}
|
local pam = {}
|
||||||
--kernel.pam = pam
|
kernel.pam = pam
|
||||||
--local loggedIn = {}
|
local loggedIn = {}
|
||||||
--
|
|
||||||
--local function getFile(path)
|
local function getFile(path)
|
||||||
-- local file = kernel.vfs.open(path, "r")
|
local file = kernel.vfs.open(path, "r")
|
||||||
-- if not file then error("Failed to open file: "..path) end
|
if not file then error("Failed to open file: "..path) end
|
||||||
-- local content = kernel.vfs.read(file, 1024000)
|
local content = kernel.vfs.read(file, 1024000)
|
||||||
-- kernel.vfs.close(file)
|
kernel.vfs.close(file)
|
||||||
-- return content
|
return content
|
||||||
--end
|
end
|
||||||
--
|
|
||||||
--local blake2s
|
local blake2s
|
||||||
--
|
|
||||||
--do
|
do
|
||||||
-- local MOD32 = 2^32
|
local MOD32 = 2^32
|
||||||
-- local function norm(x)
|
local function norm(x)
|
||||||
-- return x % MOD32
|
return x % MOD32
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function tobits(x)
|
local function tobits(x)
|
||||||
-- x = norm(x)
|
x = norm(x)
|
||||||
-- local t = {}
|
local t = {}
|
||||||
-- for i = 0, 31 do
|
for i = 0, 31 do
|
||||||
-- local b = x % 2
|
local b = x % 2
|
||||||
-- t[i] = b
|
t[i] = b
|
||||||
-- x = (x - b) / 2
|
x = (x - b) / 2
|
||||||
-- end
|
end
|
||||||
-- return t
|
return t
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function frombits(t)
|
local function frombits(t)
|
||||||
-- local x = 0
|
local x = 0
|
||||||
-- local p = 1
|
local p = 1
|
||||||
-- for i = 0, 31 do
|
for i = 0, 31 do
|
||||||
-- if t[i] == 1 then
|
if t[i] == 1 then
|
||||||
-- x = x + p
|
x = x + p
|
||||||
-- end
|
end
|
||||||
-- p = p * 2
|
p = p * 2
|
||||||
-- end
|
end
|
||||||
-- return norm(x)
|
return norm(x)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function bor(...)
|
local function bor(...)
|
||||||
-- local args = {...}
|
local args = {...}
|
||||||
-- if #args == 0 then return 0 end
|
if #args == 0 then return 0 end
|
||||||
-- local bits = tobits(args[1])
|
local bits = tobits(args[1])
|
||||||
-- for i = 2, #args do
|
for i = 2, #args do
|
||||||
-- local b = tobits(args[i])
|
local b = tobits(args[i])
|
||||||
-- for j = 0, 31 do
|
for j = 0, 31 do
|
||||||
-- bits[j] = (bits[j] == 1 or b[j] == 1) and 1 or 0
|
bits[j] = (bits[j] == 1 or b[j] == 1) and 1 or 0
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
-- return frombits(bits)
|
return frombits(bits)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function bxor(...)
|
local function bxor(...)
|
||||||
-- local args = {...}
|
local args = {...}
|
||||||
-- if #args == 0 then return 0 end
|
if #args == 0 then return 0 end
|
||||||
-- local bits = tobits(args[1])
|
local bits = tobits(args[1])
|
||||||
-- for i = 2, #args do
|
for i = 2, #args do
|
||||||
-- local b = tobits(args[i])
|
local b = tobits(args[i])
|
||||||
-- for j = 0, 31 do
|
for j = 0, 31 do
|
||||||
-- bits[j] = (bits[j] ~= b[j]) and 1 or 0
|
bits[j] = (bits[j] ~= b[j]) and 1 or 0
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
-- return frombits(bits)
|
return frombits(bits)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function lshift(x, n)
|
local function lshift(x, n)
|
||||||
-- return norm(norm(x) * 2^n)
|
return norm(norm(x) * 2^n)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function rshift(x, n)
|
local function rshift(x, n)
|
||||||
-- return math.floor(norm(x) / 2^n)
|
return math.floor(norm(x) / 2^n)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function rotr(x, n)
|
local function rotr(x, n)
|
||||||
-- return bor(rshift(x, n), lshift(x, 32 - n))
|
return bor(rshift(x, n), lshift(x, 32 - n))
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local IV = {
|
local IV = {
|
||||||
-- 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
|
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
|
||||||
-- 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
|
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
|
||||||
-- }
|
}
|
||||||
--
|
|
||||||
-- local SIGMA = {
|
local SIGMA = {
|
||||||
-- {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
|
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
|
||||||
-- {14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3},
|
{14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3},
|
||||||
-- {11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4},
|
{11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4},
|
||||||
-- {7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8},
|
{7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8},
|
||||||
-- {9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13},
|
{9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13},
|
||||||
-- {2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9},
|
{2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9},
|
||||||
-- {12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11},
|
{12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11},
|
||||||
-- {13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10},
|
{13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10},
|
||||||
-- {6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5},
|
{6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5},
|
||||||
-- {10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0}
|
{10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0}
|
||||||
-- }
|
}
|
||||||
--
|
|
||||||
-- local function G(v, a, b, c, d, x, y)
|
local function G(v, a, b, c, d, x, y)
|
||||||
-- v[a] = (v[a] + v[b] + x) % MOD32
|
v[a] = (v[a] + v[b] + x) % MOD32
|
||||||
-- v[d] = rotr(bxor(v[d], v[a]), 16)
|
v[d] = rotr(bxor(v[d], v[a]), 16)
|
||||||
-- v[c] = (v[c] + v[d]) % MOD32
|
v[c] = (v[c] + v[d]) % MOD32
|
||||||
-- v[b] = rotr(bxor(v[b], v[c]), 12)
|
v[b] = rotr(bxor(v[b], v[c]), 12)
|
||||||
-- v[a] = (v[a] + v[b] + y) % MOD32
|
v[a] = (v[a] + v[b] + y) % MOD32
|
||||||
-- v[d] = rotr(bxor(v[d], v[a]), 8)
|
v[d] = rotr(bxor(v[d], v[a]), 8)
|
||||||
-- v[c] = (v[c] + v[d]) % MOD32
|
v[c] = (v[c] + v[d]) % MOD32
|
||||||
-- v[b] = rotr(bxor(v[b], v[c]), 7)
|
v[b] = rotr(bxor(v[b], v[c]), 7)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local function compress(h, block, t, last)
|
local function compress(h, block, t, last)
|
||||||
-- local v = {}
|
local v = {}
|
||||||
-- for i = 1, 8 do v[i] = h[i] end
|
for i = 1, 8 do v[i] = h[i] end
|
||||||
-- for i = 1, 8 do v[i + 8] = IV[i] end
|
for i = 1, 8 do v[i + 8] = IV[i] end
|
||||||
--
|
|
||||||
-- v[13] = bxor(v[13], t)
|
v[13] = bxor(v[13], t)
|
||||||
-- if last then
|
if last then
|
||||||
-- v[15] = bxor(v[15], 0xFFFFFFFF)
|
v[15] = bxor(v[15], 0xFFFFFFFF)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local m = {}
|
local m = {}
|
||||||
-- for i = 0, 15 do
|
for i = 0, 15 do
|
||||||
-- local p = i * 4 + 1
|
local p = i * 4 + 1
|
||||||
-- m[i] =
|
m[i] =
|
||||||
-- (block:byte(p) or 0) +
|
(block:byte(p) or 0) +
|
||||||
-- ((block:byte(p + 1) or 0) * 0x100) +
|
((block:byte(p + 1) or 0) * 0x100) +
|
||||||
-- ((block:byte(p + 2) or 0) * 0x10000) +
|
((block:byte(p + 2) or 0) * 0x10000) +
|
||||||
-- ((block:byte(p + 3) or 0) * 0x1000000)
|
((block:byte(p + 3) or 0) * 0x1000000)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- for r = 1, 10 do
|
for r = 1, 10 do
|
||||||
-- local s = SIGMA[r]
|
local s = SIGMA[r]
|
||||||
-- G(v,1,5,9,13, m[s[1]], m[s[2]])
|
G(v,1,5,9,13, m[s[1]], m[s[2]])
|
||||||
-- G(v,2,6,10,14, m[s[3]], m[s[4]])
|
G(v,2,6,10,14, m[s[3]], m[s[4]])
|
||||||
-- G(v,3,7,11,15, m[s[5]], m[s[6]])
|
G(v,3,7,11,15, m[s[5]], m[s[6]])
|
||||||
-- G(v,4,8,12,16, m[s[7]], m[s[8]])
|
G(v,4,8,12,16, m[s[7]], m[s[8]])
|
||||||
-- G(v,1,6,11,16, m[s[9]], m[s[10]])
|
G(v,1,6,11,16, m[s[9]], m[s[10]])
|
||||||
-- G(v,2,7,12,13, m[s[11]], m[s[12]])
|
G(v,2,7,12,13, m[s[11]], m[s[12]])
|
||||||
-- G(v,3,8,9,14, m[s[13]], m[s[14]])
|
G(v,3,8,9,14, m[s[13]], m[s[14]])
|
||||||
-- G(v,4,5,10,15, m[s[15]], m[s[16]])
|
G(v,4,5,10,15, m[s[15]], m[s[16]])
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- for i = 1, 8 do
|
for i = 1, 8 do
|
||||||
-- h[i] = bxor(h[i], v[i], v[i + 8])
|
h[i] = bxor(h[i], v[i], v[i + 8])
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- function blake2s(msg, key)
|
function blake2s(msg, key)
|
||||||
-- key = key or ""
|
key = key or ""
|
||||||
--
|
|
||||||
-- local h = {}
|
local h = {}
|
||||||
-- for i = 1, 8 do h[i] = IV[i] end
|
for i = 1, 8 do h[i] = IV[i] end
|
||||||
--
|
|
||||||
-- local outlen = 32 -- bytes
|
local outlen = 32 -- bytes
|
||||||
-- h[1] = bxor(
|
h[1] = bxor(
|
||||||
-- h[1],
|
h[1],
|
||||||
-- 0x01010000 + lshift(#key, 8) + outlen
|
0x01010000 + lshift(#key, 8) + outlen
|
||||||
-- )
|
)
|
||||||
--
|
|
||||||
-- local t = 0
|
local t = 0
|
||||||
--
|
|
||||||
-- if #key > 0 then
|
if #key > 0 then
|
||||||
-- local block = key .. string.rep("\0", 64 - #key)
|
local block = key .. string.rep("\0", 64 - #key)
|
||||||
-- t = #key
|
t = #key
|
||||||
-- compress(h, block, t, false)
|
compress(h, block, t, false)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- for i = 1, #msg, 64 do
|
for i = 1, #msg, 64 do
|
||||||
-- local block = msg:sub(i, i + 63)
|
local block = msg:sub(i, i + 63)
|
||||||
-- if #block < 64 then
|
if #block < 64 then
|
||||||
-- block = block .. string.rep("\0", 64 - #block)
|
block = block .. string.rep("\0", 64 - #block)
|
||||||
-- end
|
end
|
||||||
-- t = t + math.min(64, #msg - i + 1)
|
t = t + math.min(64, #msg - i + 1)
|
||||||
-- compress(h, block, t, i + 64 > #msg)
|
compress(h, block, t, i + 64 > #msg)
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- local out = ""
|
local out = ""
|
||||||
-- for i = 1, 8 do
|
for i = 1, 8 do
|
||||||
-- out = out .. string.format("%08x", h[i])
|
out = out .. string.format("%08x", h[i])
|
||||||
-- end
|
end
|
||||||
-- return out
|
return out
|
||||||
-- end
|
end
|
||||||
--end
|
end
|
||||||
--
|
|
||||||
--if not blake2s then error("Failed to load blake2s") end
|
if not blake2s then error("Failed to load blake2s") end
|
||||||
--
|
|
||||||
--if not kernel.vfs.exists("/etc/pam.d/secret") then
|
if not kernel.vfs.exists("/etc/pam.d/secret") then
|
||||||
-- local key = ""
|
local key = ""
|
||||||
-- for i=1, 256 do
|
for i=1, 256 do
|
||||||
-- key=key..string.char(math.random(1,255))
|
key=key..string.char(math.random(1,255))
|
||||||
-- end
|
end
|
||||||
-- local handle = kernel.vfs.open("/etc/pam.d/secret", "w")
|
local handle = kernel.vfs.open("/etc/pam.d/secret", "w")
|
||||||
-- kernel.vfs.write(handle, key)
|
kernel.vfs.write(handle, key)
|
||||||
-- kernel.vfs.close(handle)
|
kernel.vfs.close(handle)
|
||||||
--end
|
end
|
||||||
--
|
|
||||||
--local pepper = getFile("/etc/pam.d/secret")
|
local pepper = getFile("/etc/pam.d/secret")
|
||||||
--
|
|
||||||
--function pam.authenticate(username, password)
|
function pam.authenticate(username, password)
|
||||||
-- local fpasswd = getFile("/etc/passwd")
|
local fpasswd = getFile("/etc/passwd")
|
||||||
-- local fshadow = getFile("/etc/shadow")
|
local fshadow = getFile("/etc/shadow")
|
||||||
--
|
|
||||||
-- local passwdLines = string.split(fpasswd, "\n")
|
local passwdLines = string.split(fpasswd, "\n")
|
||||||
-- local shadowLines = string.split(fshadow, "\n")
|
local shadowLines = string.split(fshadow, "\n")
|
||||||
--
|
|
||||||
-- local passwd = {}
|
local passwd = {}
|
||||||
-- local shadow = {}
|
local shadow = {}
|
||||||
-- for _, line in ipairs(passwdLines) do
|
for _, line in ipairs(passwdLines) do
|
||||||
-- local fields = string.split(line, ":")
|
local fields = string.split(line, ":")
|
||||||
-- passwd[fields[1]] = fields
|
passwd[fields[1]] = fields
|
||||||
-- end
|
end
|
||||||
-- for _, line in ipairs(shadowLines) do
|
for _, line in ipairs(shadowLines) do
|
||||||
-- local fields = string.split(line, ":")
|
local fields = string.split(line, ":")
|
||||||
-- shadow[fields[1]] = fields
|
shadow[fields[1]] = fields
|
||||||
-- end
|
end
|
||||||
--
|
|
||||||
-- for user, fields in pairs(passwd) do
|
for user, fields in pairs(passwd) do
|
||||||
-- if user == username then
|
if user == username then
|
||||||
-- local shadowPasswd = string.split(shadow[user][2], "$")
|
local shadowPasswd = string.split(shadow[user][2], "$")
|
||||||
-- local salt = shadowPasswd[2]
|
local salt = shadowPasswd[2]
|
||||||
-- local hashedPassword = blake2s(password .. salt, pepper)
|
local hashedPassword = blake2s(password .. salt, pepper)
|
||||||
-- if hashedPassword == shadowPasswd[3] then
|
if hashedPassword == shadowPasswd[3] then
|
||||||
-- loggedIn[username] = kernel.newUUID()
|
loggedIn[username] = kernel.newUUID()
|
||||||
-- return loggedIn[username]
|
return loggedIn[username]
|
||||||
-- else
|
else
|
||||||
-- return false
|
return false
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
--end
|
end
|
||||||
--
|
|
||||||
--function pam.authToken(username, token)
|
function pam.authToken(username, token)
|
||||||
-- return loggedIn[username] == token
|
return loggedIn[username] == token
|
||||||
--end
|
end
|
||||||
--
|
|
||||||
--
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function sys.sleep(ms)
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
function sys.getTaskInfo(pid)
|
function sys.getTask(pid)
|
||||||
if tasks[tostring(pid)] then
|
if tasks[tostring(pid)] then
|
||||||
local task = tasks[tostring(pid)]
|
local task = tasks[tostring(pid)]
|
||||||
local children = {}
|
local children = {}
|
||||||
@@ -169,14 +169,18 @@ function sys.continue(pid)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sys.getPid()
|
function sys.getpid()
|
||||||
return kernel.currentTask.pid
|
return kernel.currentTask.pid
|
||||||
end
|
end
|
||||||
|
|
||||||
function sys.list()
|
function sys.getppid()
|
||||||
|
return kernel.currentTask.parent.pid
|
||||||
|
end
|
||||||
|
|
||||||
|
function sys.getTasks()
|
||||||
local ret={}
|
local ret={}
|
||||||
for i,_ in pairs(tasks) do
|
for i,v in pairs(tasks) do
|
||||||
ret[i]=sys.getTaskInfo(i)
|
ret[i]=v.pid
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
@@ -203,18 +207,20 @@ function sys.exit(code)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.syscalls["spawn"]=sys.spawn
|
local sysc=kernel.syscalls
|
||||||
kernel.syscalls["sleep"]=sys.sleep
|
sysc["spawn"]=sys.spawn
|
||||||
kernel.syscalls["getTaskInfo"]=sys.getTaskInfo
|
sysc["sleep"]=sys.sleep
|
||||||
kernel.syscalls["collect"]=sys.collect
|
sysc["getTask"]=sys.getTask
|
||||||
kernel.syscalls["kill"]=sys.kill
|
sysc["collect"]=sys.collect
|
||||||
kernel.syscalls["stop"]=sys.stop
|
sysc["kill"]=sys.kill
|
||||||
kernel.syscalls["continue"]=sys.continue
|
sysc["stop"]=sys.stop
|
||||||
kernel.syscalls["getPid"]=sys.getPid
|
sysc["continue"]=sys.continue
|
||||||
kernel.syscalls["list"]=sys.list
|
sysc["getpid"]=sys.getpid
|
||||||
kernel.syscalls["setEnviron"]=sys.setEnviron
|
sysc["getppid"]=sys.getppid
|
||||||
kernel.syscalls["getEnviron"]=sys.getEnviron
|
sysc["getTasks"]=sys.getTasks
|
||||||
kernel.syscalls["exit"]=sys.exit
|
sysc["setEnviron"]=sys.setEnviron
|
||||||
|
sysc["getEnviron"]=sys.getEnviron
|
||||||
|
sysc["exit"]=sys.exit
|
||||||
kernel._G.sleep=function(...)coroutine.yield("syscall","sleep",...)end
|
kernel._G.sleep=function(...)coroutine.yield("syscall","sleep",...)end
|
||||||
|
|
||||||
local function reapDeadTasks()
|
local function reapDeadTasks()
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
local kernel = ...
|
local kernel = ...
|
||||||
kernel.log("Loading init system...")
|
kernel.log("Loading init system...")
|
||||||
kernel.log("InitPath: "..kernel.config.initPath)
|
kernel.log("InitPath: "..kernel.config.initPath)
|
||||||
local handle = kernel.vfs.open(kernel.config.initPath, "r")
|
|
||||||
kernel.log("O")
|
|
||||||
local data = kernel.vfs.read(handle, 1024 * 1024 * 4)
|
|
||||||
kernel.log("R")
|
|
||||||
kernel.vfs.close(handle)
|
|
||||||
kernel.log("C")
|
|
||||||
|
|
||||||
local initFunc, err = load(data, "@sysinit")
|
local handle = kernel.vfs.open(kernel.config.initPath, "r")
|
||||||
|
local data = kernel.vfs.read(handle, 1024 * 1024 * 4)
|
||||||
|
kernel.vfs.close(handle)
|
||||||
|
|
||||||
|
local initFunc, err = load(data, "@sysinit", "t", kernel._U)
|
||||||
if not initFunc then
|
if not initFunc then
|
||||||
error("Failed to load init system: "..err)
|
error("Failed to load init system: "..err)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user