add something...

This commit is contained in:
2025-04-03 21:27:34 +05:00
parent 6cfff3ee65
commit 896579518c
7 changed files with 3015 additions and 0 deletions

43
Makefile Normal file
View File

@@ -0,0 +1,43 @@
LUA_V = 54
CC=kos32-gcc
LD=kos32-ld
STRIP=kos32-strip
OBJCOPY=kos32-objcopy
STD=-std=gnu99
CFLAGS=$(SYSCFLAGS) -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(STD) $(MYCFLAGS)
LDFLAGS=$(SYSLDFLAGS) $(MYLDFLAGS) lua$(LUA_V).dll.a
LIBS=$(SYSLIBS) $(MYLIBS)
ifeq ($(OS),Windows_NT)
TOOLCHAIN_PATH=C:/MinGW/msys/1.0/home/autobuild/tools/win32
else
TOOLCHAIN_PATH=/home/autobuild/tools/win32
endif
KOLIBRIOS_REPO=../../kolibrios
SDK_DIR=$(KOLIBRIOS_REPO)/contrib/sdk
NewLib_DIR=$(SDK_DIR)/sources/newlib
SYSCFLAGS=-fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I$(NewLib_DIR)/libc/include -I$(TOOLCHAIN_PATH)/include
SYSLDFLAGS=--image-base 0 -Tapp-dynamic.lds
SYSLIBS=-nostdlib -L $(SDK_DIR)/lib -L$(TOOLCHAIN_PATH)/lib -L$(TOOLCHAIN_PATH)/mingw32/lib -lgcc -lc.dll -ldll
MYCFLAGS=
MYLDFLAGS=
MYLIBS=
MYOBJS=
ALL_O = src/syscalls.o src/ARP_entry.o src/sytemColors.o
syscalls.dll: $(ALL_O)
$(CC) -shared -T dll.lds --entry _DllStartup -o $@ lsyscalls.o $(SYSLIBS)
clean:
rm -f $(ALL_O) syscalls.dll
src/syscalls.o: src/syscalls.c
src/ARP_entry.o: src/ARP_entry.c src/ARP_entry.h
src/sytemColors.o: src/sytemColors.c src/sytemColors.h

142
src/ARP_entry.c Normal file
View File

@@ -0,0 +1,142 @@
#include "ARP_entry.h"
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/ksys.h>
static int syscalls_gcARPEntry(lua_State *L)
{
free(lua_touserdata(L, 1));
return 0;
}
static bool syscalls_cmpAPREntry(const struct ARP_entry *entry1, const struct ARP_entry *entry2)
{
return memcmp(entry1, entry2, sizeof(struct ARP_entry));
}
int syscalls_indexARPEntry(lua_State *L)
{
struct ARP_entry *entry = (struct ARP_entry *)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
const char *index = luaL_checkstring(L, 2);
if (strcmp(index, "IP") == 0)
{
lua_pushinteger(L, entry->IP);
}
else if (strcmp(index, "MAC") == 0)
{
char str[7];
memset(str, entry->MAC, 6);
str[6] = '\n';
lua_pushstring(L, str);
}
else if (strcmp(index, "Status") == 0)
{
lua_pushinteger(L, entry->Status);
}
else if (strcmp(index, "TTL") == 0)
{
lua_pushinteger(L, entry->TTL);
}
else
{
_ksys_debug_puts("err\n");
}
return 1;
}
int syscalls_newindexARPEntry(lua_State *L)
{
struct ARP_entry *entry = (struct ARP_entry *)luaL_checkudata(L, 1, syscalls_ARPEntry_metatable_name);
const char *index = luaL_checkstring(L, 2);
if (strcmp(index, "IP"))
{
entry->IP = luaL_checkinteger(L, 3);
}
else if (strcmp(index, "MAC"))
{
memset(entry->MAC, luaL_checkstring(L, 3), 6);
}
else if (strcmp(index, "Status"))
{
entry->Status = luaL_checkinteger(L, 3);
}
else if (strcmp(index, "TTL"))
{
entry->TTL = luaL_checkinteger(L, 3);
}
else
{
_ksys_debug_puts("err\n");
}
return 0;
}
static int syscalls_eqAPREntry(lua_State *L)
{
lua_pushboolean(
L,
syscalls_cmpAPREntry(
(struct ARP_entry *)lua_touserdata(L, 1),
(struct ARP_entry *)lua_touserdata(L, 2)
)
);
return 1;
}
int syscalls_newARPEntry(lua_State *L)
{
struct ARP_entry *entry = malloc(sizeof(struct ARP_entry));
entry->IP = luaL_checkinteger(L, 1);
memcpy(entry->MAC, luaL_checkstring(L, 2), 6);
entry->Status = luaL_checkinteger(L, 3);
entry->TTL = luaL_checkinteger(L, 4);
syscalls_pushARPEntry(
L,
entry);
return 1;
}
static const luaL_Reg syscalls_ARPEntry_m[] = {
{"__index", syscalls_indexARPEntry},
{"__newindex", syscalls_newindexARPEntry},
{"__eq", syscalls_eqAPREntry},
{"__gc", syscalls_gcARPEntry},
{NULL, NULL}};
void syscalls_pushARPEntry(lua_State* L, struct ARP_entry* entry)
{
*(struct ARP_entry**)lua_newuserdata(L, sizeof(struct ARP_entry)) = entry;
luaL_newlibtable(L, syscalls_ARPEntry_m);
luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
lua_setmetatable(L, -2);
}
static const luaL_Reg syscalls_ARPEntry_lib[] = {
{"new", syscalls_newARPEntry},
{NULL, NULL}};
void syscalls_register_ARPEntry(lua_State *L)
{
luaL_newlib(L, syscalls_ARPEntry_lib);
lua_setfield(L, -2, syscalls_ARPEntry_name);
luaL_newlibtable(L, syscalls_ARPEntry_m);
luaL_setfuncs(L, syscalls_ARPEntry_m, 0);
}

36
src/ARP_entry.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef _SYSCALLS_ARP_ENTRY_
#define _SYSCALLS_ARP_ENTRY
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdint.h>
struct ARP_entry
{
uint32_t IP;
char MAC[6];
uint16_t Status;
uint16_t TTL;
};
#define syscalls_ARPEntry_name "ARPEntry"
#define syscalls_ARPEntry_metatable_name syscalls_ARPEntry_name ".mt"
/*
* Create ARPEntry
*/
void syscalls_pushARPEntry(lua_State *L, struct ARP_entry *entry);
/*
* shell of syscalls_createARPEntry for lua
*/
int syscalls_newARPEntry(lua_State *L);
int syscalls_indexARPEntry(lua_State *L);
int syscalls_newindexARPEntry(lua_State *L);
void syscalls_register_ARPEntry(lua_State *L);
#endif

277
src/scancodes.h Normal file
View File

@@ -0,0 +1,277 @@
#ifndef _SYSCALLS_ENUM_SCANCODES_
#define _SYSCALLS_ENUM_SCANCODES_
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <sys/ksys.h>
static inline void syscalls_register_scancodes(lua_State *L)
{
lua_newtable(L);
lua_pushinteger(L, KSYS_SCANCODE_0);
lua_setfield(L, -2, "0");
lua_pushinteger(L, KSYS_SCANCODE_1);
lua_setfield(L, -2, "1");
lua_pushinteger(L, KSYS_SCANCODE_2);
lua_setfield(L, -2, "2");
lua_pushinteger(L, KSYS_SCANCODE_3);
lua_setfield(L, -2, "3");
lua_pushinteger(L, KSYS_SCANCODE_4);
lua_setfield(L, -2, "4");
lua_pushinteger(L, KSYS_SCANCODE_5);
lua_setfield(L, -2, "6");
lua_pushinteger(L, KSYS_SCANCODE_7);
lua_setfield(L, -2, "7");
lua_pushinteger(L, KSYS_SCANCODE_8);
lua_setfield(L, -2, "8");
lua_pushinteger(L, KSYS_SCANCODE_9);
lua_setfield(L, -2, "9");
lua_pushinteger(L, KSYS_SCANCODE_A);
lua_setfield(L, -2, "A");
lua_pushinteger(L, KSYS_SCANCODE_B);
lua_setfield(L, -2, "B");
lua_pushinteger(L, KSYS_SCANCODE_C);
lua_setfield(L, -2, "C");
lua_pushinteger(L, KSYS_SCANCODE_D);
lua_setfield(L, -2, "D");
lua_pushinteger(L, KSYS_SCANCODE_E);
lua_setfield(L, -2, "E");
lua_pushinteger(L, KSYS_SCANCODE_F);
lua_setfield(L, -2, "F");
lua_pushinteger(L, KSYS_SCANCODE_G);
lua_setfield(L, -2, "G");
lua_pushinteger(L, KSYS_SCANCODE_H);
lua_setfield(L, -2, "H");
lua_pushinteger(L, KSYS_SCANCODE_J);
lua_setfield(L, -2, "J");
lua_pushinteger(L, KSYS_SCANCODE_K);
lua_setfield(L, -2, "K");
lua_pushinteger(L, KSYS_SCANCODE_L);
lua_setfield(L, -2, "L");
lua_pushinteger(L, KSYS_SCANCODE_M);
lua_setfield(L, -2, "M");
lua_pushinteger(L, KSYS_SCANCODE_N);
lua_setfield(L, -2, "N");
lua_pushinteger(L, KSYS_SCANCODE_O);
lua_setfield(L, -2, "O");
lua_pushinteger(L, KSYS_SCANCODE_P);
lua_setfield(L, -2, "P");
lua_pushinteger(L, KSYS_SCANCODE_Q);
lua_setfield(L, -2, "Q");
lua_pushinteger(L, KSYS_SCANCODE_R);
lua_setfield(L, -2, "R");
lua_pushinteger(L, KSYS_SCANCODE_S);
lua_setfield(L, -2, "S");
lua_pushinteger(L, KSYS_SCANCODE_T);
lua_setfield(L, -2, "T");
lua_pushinteger(L, KSYS_SCANCODE_U);
lua_setfield(L, -2, "U");
lua_pushinteger(L, KSYS_SCANCODE_V);
lua_setfield(L, -2, "V");
lua_pushinteger(L, KSYS_SCANCODE_W);
lua_setfield(L, -2, "W");
lua_pushinteger(L, KSYS_SCANCODE_X);
lua_setfield(L, -2, "X");
lua_pushinteger(L, KSYS_SCANCODE_Y);
lua_setfield(L, -2, "Y");
lua_pushinteger(L, KSYS_SCANCODE_Z);
lua_setfield(L, -2, "Z");
lua_pushinteger(L, KSYS_SCANCODE_F1);
lua_setfield(L, -2, "F1");
lua_pushinteger(L, KSYS_SCANCODE_F2);
lua_setfield(L, -2, "F2");
lua_pushinteger(L, KSYS_SCANCODE_F3);
lua_setfield(L, -2, "F3");
lua_pushinteger(L, KSYS_SCANCODE_F4);
lua_setfield(L, -2, "F4");
lua_pushinteger(L, KSYS_SCANCODE_F5);
lua_setfield(L, -2, "F5");
lua_pushinteger(L, KSYS_SCANCODE_F6);
lua_setfield(L, -2, "F6");
lua_pushinteger(L, KSYS_SCANCODE_F7);
lua_setfield(L, -2, "F7");
lua_pushinteger(L, KSYS_SCANCODE_F8);
lua_setfield(L, -2, "F8");
lua_pushinteger(L, KSYS_SCANCODE_F9);
lua_setfield(L, -2, "F9");
lua_pushinteger(L, KSYS_SCANCODE_F10);
lua_setfield(L, -2, "F10");
lua_pushinteger(L, KSYS_SCANCODE_F11);
lua_setfield(L, -2, "F11");
lua_pushinteger(L, KSYS_SCANCODE_F12);
lua_setfield(L, -2, "F12");
lua_pushinteger(L, KSYS_SCANCODE_LSHIFT);
lua_setfield(L, -2, "LeftShift");
lua_pushinteger(L, KSYS_SCANCODE_RSHIFT);
lua_setfield(L, -2, "RightShift");
lua_pushinteger(L, KSYS_SCANCODE_BACKSLASH);
lua_setfield(L, -2, "Backslash");
lua_pushinteger(L, KSYS_SCANCODE_COMMA);
lua_setfield(L, -2, "Comma");
lua_pushinteger(L, KSYS_SCANCODE_SLASH);
lua_setfield(L, -2, "Slash");
lua_pushinteger(L, KSYS_SCANCODE_LALT);
lua_setfield(L, -2, "LeftAlt");
lua_pushinteger(L, KSYS_SCANCODE_EXT_RALT);
lua_setfield(L, -2, "RightAlt");
lua_pushinteger(L, KSYS_SCANCODE_LCTRL);
lua_setfield(L, -2, "LeftCtrl");
lua_pushinteger(L, KSYS_SCANCODE_EXT_RCTRL);
lua_setfield(L, -2, "RightCtrl");
lua_pushinteger(L, KSYS_SCANCODE_CAPSLOCK);
lua_setfield(L, -2, "CapsLock");
lua_pushinteger(L, KSYS_SCANCODE_NUMLOCK);
lua_setfield(L, -2, "NumLock");
lua_pushinteger(L, KSYS_SCANCODE_POINT);
lua_setfield(L, -2, "Point");
lua_pushinteger(L, KSYS_SCANCODE_ENTER);
lua_setfield(L, -2, "Enter");
lua_pushinteger(L, KSYS_SCANCODE_ESC);
lua_setfield(L, -2, "Esc");
lua_pushinteger(L, KSYS_SCANCODE_TAB);
lua_setfield(L, -2, "Tab");
lua_pushinteger(L, KSYS_SCANCODE_EXT_HOME);
lua_setfield(L, -2, "Home");
lua_pushinteger(L, KSYS_SCANCODE_EXT_PGUP);
lua_setfield(L, -2, "PageUp");
lua_pushinteger(L, KSYS_SCANCODE_EXT_PGDOWN);
lua_setfield(L, -2, "PageDown");
lua_pushinteger(L, KSYS_SCANCODE_EXT_END);
lua_setfield(L, -2, "End");
lua_pushinteger(L, KSYS_SCANCODE_EXT_UP);
lua_setfield(L, -2, "Up");
lua_pushinteger(L, KSYS_SCANCODE_EXT_DOWN);
lua_setfield(L, -2, "Down");
lua_pushinteger(L, KSYS_SCANCODE_EXT_LEFT);
lua_setfield(L, -2, "Left");
lua_pushinteger(L, KSYS_SCANCODE_EXT_RIGHT);
lua_setfield(L, -2, "Right");
lua_pushinteger(L, KSYS_SCANCODE_EXT_DELETE);
lua_setfield(L, -2, "Delete");
lua_pushinteger(L, KSYS_SCANCODE_EXT_INSERT);
lua_setfield(L, -2, "Insert");
lua_pushinteger(L, KSYS_SCANCODE_MINUS);
lua_setfield(L, -2, "Minus");
lua_pushinteger(L, KSYS_SCANCODE_EXT_NUMPAD_ENTER);
lua_setfield(L, -2, "NumpadEnter");
lua_pushinteger(L, KSYS_SCANCODE_EXT_NUMPAD_DIV);
lua_setfield(L, -2, "NumpadDiv");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_MULT);
lua_setfield(L, -2, "NumpadMult");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_MINUS);
lua_setfield(L, -2, "NumpadMinus");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_PLUS);
lua_setfield(L, -2, "NumpadPlus");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_0);
lua_setfield(L, -2, "Numpad_0");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_1);
lua_setfield(L, -2, "Numpad_1");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_2);
lua_setfield(L, -2, "Numpad_2");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_3);
lua_setfield(L, -2, "Numpad_3");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_4);
lua_setfield(L, -2, "Numpad_4");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_5);
lua_setfield(L, -2, "Numpad_5");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_6);
lua_setfield(L, -2, "Numpad_6");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_7);
lua_setfield(L, -2, "Numpad_7");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_8);
lua_setfield(L, -2, "Numpad_8");
lua_pushinteger(L, KSYS_SCANCODE_NUMPAD_9);
lua_setfield(L, -2, "Numpad_9");
lua_setfield(L, -2, "scancode");
}
#endif // _SYSCALLS_ENUM_SCANCODES_

2314
src/syscalls.c Normal file

File diff suppressed because it is too large Load Diff

184
src/systemColors.c Normal file
View File

@@ -0,0 +1,184 @@
#include "systemColors.h"
#include <string.h>
#include <stdlib.h>
int syscalls_newSystemColors(lua_State* L)
{
ksys_colors_table_t* colorsTable = malloc(sizeof(ksys_colors_table_t));
colorsTable->frame_area = luaL_optinteger(L, 1, 0);
colorsTable->grab_bar = luaL_optinteger(L, 2, 0);
colorsTable->grab_bar_button = luaL_optinteger(L, 3, 0);
colorsTable->grab_button_text = luaL_optinteger(L, 4, 0);
colorsTable->grab_text = luaL_optinteger(L, 5, 0);
colorsTable->work_area = luaL_optinteger(L, 6, 0);
colorsTable->work_button = luaL_optinteger(L, 7, 0);
colorsTable->work_button_text = luaL_optinteger(L, 8, 0);
colorsTable->work_graph = luaL_optinteger(L, 9, 0);
colorsTable->work_text = luaL_optinteger(L, 10, 0);
syscalls_pushSystemColors(L, colorsTable);
return 1;
}
static int syscalls_indexSystemColors(lua_State* L)
{
const ksys_colors_table_t* t = (const ksys_colors_table_t*)luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
const char* index = luaL_checkstring(L, 2);
if (strcmp("frameArea", index) == 0)
{
lua_pushinteger(L, t->frame_area);
}
else if (strcmp("grabBar", index) == 0)
{
lua_pushinteger(L, t->grab_bar);
}
else if (strcmp("grabBarButton", index) == 0)
{
lua_pushinteger(L, t->grab_bar_button);
}
else if (strcmp("grab_button_text", index) == 0)
{
lua_pushinteger(L, t->grab_button_text);
}
else if (strcmp("grabText", index) == 0)
{
lua_pushinteger(L, t->grab_text);
}
else if (strcmp("workArea", index) == 0)
{
lua_pushinteger(L, t->work_area);
}
else if (strcmp("workButton", index) == 0)
{
lua_pushinteger(L, t->work_button);
}
else if (strcmp("workButtonText", index) == 0)
{
lua_pushinteger(L, t->work_button_text);
}
else if (strcmp("workGraph", index) == 0)
{
lua_pushinteger(L, t->work_graph);
}
else if (strcmp("workText", index) == 0)
{
lua_pushinteger(L, t->work_text);
}
else
{
luaL_error(L, "wrong index: %s", index);
}
return 1;
}
static int syscalls_newindexSystemColors(lua_State* L)
{
ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
const char* index = luaL_checkstring(L, 2);
LUA_INTEGER val = luaL_checkinteger(L, 3);
if (strcmp("frameArea", index) == 0)
{
t->frame_area = val;
}
else if (strcmp("grabBar", index) == 0)
{
t->grab_bar = val;
}
else if (strcmp("grabBarButton", index) == 0)
{
t->grab_bar_button = val;
}
else if (strcmp("grab_button_text", index) == 0)
{
t->grab_button_text = val;
}
else if (strcmp("grabText", index) == 0)
{
t->grab_text = val;
}
else if (strcmp("workArea", index) == 0)
{
t->work_area = val;
}
else if (strcmp("workButton", index) == 0)
{
t->work_button = val;
}
else if (strcmp("workButtonText", index) == 0)
{
t->work_button_text = val;
}
else if (strcmp("workGraph", index) == 0)
{
t->work_graph = val;
}
else if (strcmp("workText", index) == 0)
{
t->work_text = val;
}
else
{
luaL_error(L, "wrong index: %s", index);
}
return 0;
}
static int sycalls_eqSystemColors(lua_State* L)
{
lua_pushboolean(
L,
memcmp(
luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name),
luaL_checkudata(L, 2, syscalls_SystemColors_metatable_name),
sizeof(ksys_colors_table_t)
)
);
return 1;
}
static int sycalls_gcSystemColors(lua_State* L)
{
ksys_colors_table_t* t = luaL_checkudata(L, 1, syscalls_SystemColors_metatable_name);
free(t);
return 1;
}
static const luaL_Reg syscalls_SystemColors_m[] = {
{"__index", syscalls_indexSystemColors},
{"__newindex", syscalls_newindexSystemColors},
{"__eq", sycalls_eqSystemColors},
{NULL, NULL} };
void syscalls_pushSystemColors(lua_State* L, ksys_colors_table_t* colorsTable)
{
*(ksys_colors_table_t**)lua_newuserdata(L, sizeof(ksys_colors_table_t)) = colorsTable;
luaL_newlibtable(L, syscalls_SystemColors_m);
luaL_setfuncs(L, syscalls_SystemColors_m, 0);
lua_setmetatable(L, -2);
}
static const luaL_Reg syscalls_SystemColors_lib[] = {
{"new", syscalls_newSystemColors},
{NULL, NULL} };
void syscalls_register_SystemColors(lua_State* L)
{
luaL_newlib(L, syscalls_SystemColors_lib);
lua_setfield(L, -2, syscalls_SystemColors_name);
luaL_newlibtable(L, syscalls_SystemColors_m);
luaL_setfuncs(L, syscalls_SystemColors_m, 0);
}

19
src/systemColors.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef _SYSCALLS_SYSTEMCOLORS_H_
#define _SYSCALLS_SYSTEMCOLORS_H_
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <sys/ksys.h>
#define syscalls_SystemColors_name "SystemColors"
#define syscalls_SystemColors_metatable_name syscalls_SystemColors_name ".mt"
int syscalls_newSystemColors(lua_State *L);
void syscalls_pushSystemColors(lua_State *L, ksys_colors_table_t *t);
void syscalls_register_SystemColors(lua_State *L);
#endif // _SYSCALLS_SYSTEMCOLORS_H_