Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
23
Task/Machine-code/Pluto/machine-code-1.pluto
Normal file
23
Task/Machine-code/Pluto/machine-code-1.pluto
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* mclib.c */
|
||||
|
||||
// gcc -c -fpic mclib.c
|
||||
// gcc -shared -o mclib.so mclib.o
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
extern uchar run_machine_code(const char *code, uchar a, uchar b, int len) {
|
||||
void *buf;
|
||||
uchar c;
|
||||
/* copy code to executable buffer */
|
||||
buf = mmap (0, len, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
memcpy (buf, code, len);
|
||||
/* run code */
|
||||
c = ((uchar (*) (uchar, uchar))buf)(a, b);
|
||||
/* free buffer */
|
||||
munmap (buf, len);
|
||||
return c;
|
||||
}
|
||||
19
Task/Machine-code/Pluto/machine-code-2.pluto
Normal file
19
Task/Machine-code/Pluto/machine-code-2.pluto
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
local ffi = require "pluto:ffi"
|
||||
local lib = ffi.open("./mclib.so")
|
||||
lib:cdef[[
|
||||
unsigned char run_machine_code(const char *code, unsigned char a, unsigned char b, int len);
|
||||
]]
|
||||
|
||||
local a = 7
|
||||
local b = 12
|
||||
|
||||
-- x64 opcodes for this task
|
||||
local m = {
|
||||
0x55, 0x48, 0x89, 0xe5, 0x89, 0x7d,
|
||||
0xfc, 0x89, 0x75, 0xf8, 0x8b, 0x75,
|
||||
0xfc, 0x03, 0x75, 0xf8, 0x89, 0x75,
|
||||
0xf4, 0x8b, 0x45, 0xf4, 0x5d, 0xc3
|
||||
}
|
||||
|
||||
local code = m:mapped(|byte| -> string.char(byte)):concat("")
|
||||
print($"{a} + {b} = {lib.run_machine_code(code, a, b, #m)}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue