Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Purpose: Xenus NTOS emulator entrypoint.
- Author: Reece W.
- License: All Rights Reserved J. Reece Wilson
- */
- #include <xenus_lazy.h>
- #include <liblinux.hpp>
- #include <ITypes\ITaskStruct.hpp>
- #include <ITypes\IFile.hpp>
- #include <ITypes\IPath.hpp>
- bool file_to_root(char * path, char * dest)
- {
- size_t i;
- size_t length;
- length = strlen(path);
- memcpy(dest, path, length + 1);
- for (i = length; i > 0; i--)
- {
- if (path[i] == '/')
- {
- *(char **)(&(dest[i + 1])) = (char *)0x00;
- break;
- }
- }
- return i != 0;
- }
- int unlink_file(const char * req_path)
- {
- char file_dir[256];
- file_k path_handle;
- file_k target_handle;
- inode_k delegated_inode;
- if (!file_to_root((char *)req_path, file_dir))
- return 0; /* failed to strip path to dir */
- if (!(target_handle = filp_open(req_path, O_RDONLY, 0600)))
- return -1; /* file not found */
- if (!(path_handle = filp_open(file_dir, O_DIRECTORY, 0600)))
- return -2; /* dir not found. odd linking? device? who knows? */
- //printf("%s is located in %s\n", req_path, file_dir);
- IFile file = IFile(target_handle);
- IPath file_path = IPath(file.get_f_path());
- IFile path = IFile(path_handle);
- vfs_unlink(path.get_f_inode(),
- file_path.get_dentry(),
- &delegated_inode);
- filp_close(target_handle, 0);
- filp_close(path_handle, 0);
- return 1;
- }
- void test_write(const char * fn)
- {
- loff_t pos;
- file_k file;
- const char * string;
- pos = 0;
- string = "Hello from Xenus!";
- if (!(file = filp_open(fn, O_CREAT | O_RDWR, 0777)))
- {
- printf("Failed to open file %s \n", fn);
- return;
- }
- kernel_write(file,
- (const void *)string,
- strlen(string),
- &pos);
- filp_close(file, 0);
- }
- static mod_global_data_t ntos_module = { 0 };
- bool subsystem_ntos_init(mod_dependency_list_p deps)
- {
- return true;
- }
- int subsystem_ntos_start()
- {
- test_write("/Xenus/TestFile"); //create
- unlink_file("/Xenus/TestFile"); //then delete
- return 1;
- }
- void subsystem_ntos_shutdown()
- {
- }
- void entrypoint(xenus_entrypoint_ctx_p context)
- {
- /* Do note, the IAT is still NULL'd at this moment in time! */
- context->size = sizeof(xenus_entrypoint_ctx_t);
- context->description = "An emulation attempt of the Microsoft Windows� Kernel (ntos.exe).";
- context->copyright = "All rights reserved, Reece Wilson (2018)";
- context->init = subsystem_ntos_init;
- context->start = subsystem_ntos_start;
- context->shutdown = subsystem_ntos_shutdown;
- context->dependencies.count = 0;
- context->static_data = &ntos_module;
- }
Add Comment
Please, Sign In to add comment