fix ps/2 mouse init, make Stall more precise, rename CurrentProcess to KeGetCurrentProcess, correct type about maneuvers, add file writing to win32
This commit is contained in:
1 parent
8c7564d5e1
commit
a37f5b1581
14 files changed
+288
-75
No files matched your search
+64
-5
@@ -21,7 +21,9 @@ typedef int BOOL;
|
||||
|
||||
// File I/O constants
|
||||
#define GENERIC_READ 0x80000000L
|
||||
#define GENERIC_WRITE 0x40000000L
|
||||
#define OPEN_EXISTING 3
|
||||
#define CREATE_ALWAYS 2
|
||||
#define FILE_SHARE_READ 0x00000001
|
||||
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
|
||||
|
||||
@@ -75,9 +77,9 @@ typedef struct _WIN32_FIND_DATAA {
|
||||
} WIN32_FIND_DATAA;
|
||||
|
||||
BOOL CreateProcessA(const char* lpApp, char* lpCmdLine,
|
||||
void* lpPA, void* lpTA, BOOL bInherit,
|
||||
DWORD dwFlags, void* lpEnv, const char* lpDir,
|
||||
STARTUPINFOA* lpSI, PROCESS_INFORMATION* lpPI);
|
||||
void* lpPA, void* lpTA, BOOL bInherit,
|
||||
DWORD dwFlags, void* lpEnv, const char* lpDir,
|
||||
STARTUPINFOA* lpSI, PROCESS_INFORMATION* lpPI);
|
||||
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMs);
|
||||
BOOL GetExitCodeProcess(HANDLE hProcess, DWORD* lpExitCode);
|
||||
BOOL CloseHandle(HANDLE hObject);
|
||||
@@ -89,10 +91,12 @@ BOOL FindClose(HANDLE hFindFile);
|
||||
BOOL SetCurrentDirectoryA(const char* lpPathName);
|
||||
BOOL DeleteFileA(const char* lpFileName);
|
||||
HANDLE CreateFileA(const char* lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
|
||||
void* lpSecurityAttributes, DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
|
||||
void* lpSecurityAttributes, DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
|
||||
BOOL ReadFile(HANDLE hFile, void* lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
DWORD* lpNumberOfBytesRead, void* lpOverlapped);
|
||||
BOOL WriteFile(HANDLE hFile, const void* lpBuffer, DWORD nNumberOfBytesToWrite,
|
||||
DWORD* lpNumberOfBytesWritten, void* lpOverlapped);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global handles
|
||||
@@ -172,6 +176,51 @@ static char* trim(char* s) {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Built-in commands
|
||||
// ---------------------------------------------------------------------------
|
||||
static void cmd_help() {
|
||||
print("Available commands:\n"
|
||||
" help - Show this list\n"
|
||||
" dir - List files in current directory\n"
|
||||
" cd <path> - Change directory\n"
|
||||
" type <file> - Display file contents\n"
|
||||
" del <file> - Delete a file\n"
|
||||
" write <file> <tx> - Create a file with text\n"
|
||||
" exit - Close the shell\n");
|
||||
}
|
||||
|
||||
static void cmd_write(const char* args) {
|
||||
char filename[MAX_PATH];
|
||||
int i = 0;
|
||||
|
||||
// Parse filename (up to first space)
|
||||
while (args[i] != ' ' && args[i] != '\0' && i < MAX_PATH - 1) {
|
||||
filename[i] = args[i];
|
||||
i++;
|
||||
}
|
||||
filename[i] = '\0';
|
||||
|
||||
if (args[i] == '\0' || args[i+1] == '\0') {
|
||||
print("write: usage: write <filename> <text>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* text = args + i + 1; // Content starts after the space
|
||||
|
||||
HANDLE hFile = CreateFileA(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
print("write: could not create file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD written;
|
||||
if (!WriteFile(hFile, text, (DWORD)strlen(text), &written, 0)) {
|
||||
print("write: error writing to file\n");
|
||||
} else {
|
||||
print("File written successfully.\n");
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
static void cmd_dir() {
|
||||
WIN32_FIND_DATAA fd;
|
||||
HANDLE hFind = FindFirstFileA("*", &fd);
|
||||
@@ -226,6 +275,11 @@ static int runCommand(const char* cmd) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "help") == 0) {
|
||||
cmd_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "dir") == 0) {
|
||||
cmd_dir();
|
||||
return 0;
|
||||
@@ -256,6 +310,11 @@ static int runCommand(const char* cmd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strncmp(cmd, "write ", 6) == 0) {
|
||||
cmd_write(cmd + 6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --- External Process Execution ---
|
||||
STARTUPINFOA si;
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
Reference in new issue
Block a user