mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
that's one shitty way of injecting a code...
This commit is contained in:
@@ -20,7 +20,17 @@ class SIG {
|
||||
}
|
||||
}
|
||||
const SIGTERM = new SIG("TERM",15);
|
||||
const SIGSEGV = new SIG("SEGV",11)
|
||||
const SIGSEGV = new SIG("SEGV",11);
|
||||
|
||||
function generateRandomHashStr(len) {
|
||||
let cs = 'qwfpgarstdzxcvbjluyhneiokmQWFPGARSTDZXCVBJLUYHNEIOKM';
|
||||
let s = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
s += cs[(Math.random()*cs.length)|0];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// define TVDOS
|
||||
var _TVDOS = {};
|
||||
_TVDOS.VERSION = "1.0";
|
||||
@@ -147,13 +157,26 @@ Object.freeze(filesystem);
|
||||
filesystem.open("A", "tvdos/gl.js", "R");
|
||||
var GL = eval(filesystem.readAll("A"));
|
||||
|
||||
let checkTerm = `if (sys.peek(-49)&1) throw new InterruptedException();`;
|
||||
let injectIntChk = (s, n) => {
|
||||
// primitive way of injecting a code; will replace a JS string that matches the regex...
|
||||
let k = s
|
||||
.replace(/while *\([^\n]+\) *{/, "$& "+n+"();")
|
||||
.replace(/for *\([^\n]+\) *{/, "$& "+n+"();");
|
||||
serial.println(k);
|
||||
return k;
|
||||
}
|
||||
|
||||
// @param cmdsrc JS source code
|
||||
// @param args arguments for the program, must be Array, and args[0] is always the name of the program, e.g.
|
||||
// for command line 'echo foo bar', args[0] must be 'echo'
|
||||
// @return status returned by the program
|
||||
var execApp = (cmdsrc, args) => {
|
||||
var intchkFunName = `tvdosSIGTERM_${generateRandomHashStr(16)}`;
|
||||
var execAppPrg = eval(
|
||||
`var _appStub=function(exec_args){${cmdsrc}\n};_appStub`); // making 'exec_args' a app-level global
|
||||
`var ${intchkFunName} = function(){ ${checkTerm} };` +
|
||||
`var _appStub=function(exec_args){${injectIntChk(cmdsrc, intchkFunName)}\n};` +
|
||||
`_appStub`); // making 'exec_args' a app-level global
|
||||
|
||||
var status = 0;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AppLoader {
|
||||
// val vm = VM(64.kB(), TheRealWorld(), arrayOf(GenericBios))
|
||||
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, BasicRom.INSTANCE});
|
||||
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{OEMBios.INSTANCE, BasicRom.INSTANCE});
|
||||
VM vm = new VM(32 << 10, new TheRealWorld(), new VMProgramRom[]{TandemBios.INSTANCE, BasicRom.INSTANCE});
|
||||
VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TandemBios.INSTANCE, BasicRom.INSTANCE});
|
||||
//VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TBASRelBios.INSTANCE});
|
||||
|
||||
EmulInstance reference = new EmulInstance(appConfig, vm, "net.torvald.tsvm.peripheral.ReferenceGraphicsAdapter", "assets/disk0");
|
||||
|
||||
@@ -47,6 +47,9 @@ class VM(
|
||||
|
||||
val startTime: Long
|
||||
|
||||
var resetDown = false
|
||||
var stopDown = false
|
||||
|
||||
var romMapping = 255
|
||||
internal set
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
||||
38L -> keyboardInputRequested.toInt().toByte()
|
||||
39L -> rawInputFunctionLatched.toInt().toByte()
|
||||
in 40..47 -> keyEventBuffers[adi - 40]
|
||||
48L -> ((vm.resetDown.toInt() shl 7) or (vm.stopDown.toInt())).toByte()
|
||||
|
||||
in 64..67 -> vm.memsize.shr((adi - 64) * 8).toByte()
|
||||
68L -> (uptimeCounterLatched.toInt() or RTClatched.toInt().shl(1)).toByte()
|
||||
|
||||
@@ -73,6 +73,10 @@ MMIO
|
||||
40..47 RO: Key Press buffer
|
||||
stores keys that are held down. Can accomodate 8-key rollover (in keyboard geeks' terms)
|
||||
0x0 is written for the empty area; numbers are always sorted
|
||||
48..51 RO: System flags
|
||||
48: 0b r000 000t
|
||||
t: STOP button (should raise SIGTERM)
|
||||
r: RESET button (should reset the system)
|
||||
|
||||
64..67 RO: User area memory size in bytes
|
||||
68 WO: Counter latch
|
||||
|
||||
Reference in New Issue
Block a user