/*++ Copyright (c) Microsoft Corporation. All rights reserved. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. Module Name: osserver.c Abstract: Original Author: Dave Probert Environment: User mode Win32 console application Revision History: --*/ #include #include #include #include #include #include "..\inc\OZ-UTokyo2004.h" int go; int here; // // Declare implemented sys calls // ULONG_PTR mysyscall_printmsg(HANDLE clientprocess, POZSYSCALL syscall); POZSYSCALLHANDLER syscallhandlers[MYSYS_LIMIT] = { mysyscall_printmsg // myos_printmsg }; PCHAR mysyscallname[MYSYS_LIMIT] = { "printmsg" }; CHAR BUFFER[512]; // // Define each system call handler, e.g. // ULONG_PTR mysyscall_printmsg(HANDLE clientprocess, POZSYSCALL syscall) { BOOL r = 0; if (syscall->ozarg[1] < sizeof(BUFFER)) { r = OzReadChildMemory(clientprocess, (PVOID)syscall->ozarg[0], (ULONG_PTR)syscall->ozarg[1], BUFFER); if (r) { printf(BUFFER); } } return r; } char clientpath[8*MAX_PATH]; // make it plenty big VOID _cdecl main( ULONG argc, PCHAR argv[] ) { PROCESS_INFORMATION processinfo; STARTUPINFO startupinfo; HANDLE childprocess; HANDLE childthread; DWORD childprocessid; DWORD childthreadid; HANDLE syscallport; PVOID startaddr; BOOL r; char *parentpath, *e, *appname; int parentpathlength; RtlZeroMemory(&startupinfo, sizeof(startupinfo)); if (argc < 1) { ExitProcess(1); } appname = "OZApp.exe"; //SetVerboseFlag(TRUE); SetServerFlag(TRUE); parentpath = argv[0]; parentpathlength = 0; // // Get client pathname // e = strrchr(parentpath, '\\'); if (e) { parentpathlength = e - parentpath + 1; strncpy(clientpath, parentpath, parentpathlength); } else { parentpathlength = 0; } strcpy(clientpath + parentpathlength, appname); printf("Running %s\n", clientpath); // // Create a child process // r = CreateProcess( clientpath, // LPCTSTR lpApplicationName, NULL, // LPTSTR lpCommandLine, NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes, NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes, FALSE, // BOOL bInheritHandles, CREATE_SUSPENDED, // DWORD dwCreationFlags, NULL, // LPVOID lpEnvironment, NULL, // LPCTSTR lpCurrentDirectory, &startupinfo, // LPSTARTUPINFO lpStartupInfo, &processinfo // LPPROCESS_INFORMATION lpProcessInformation ); if (!r) { printf("CreateProcess\n"); ExitProcess(2); } childprocess = processinfo.hProcess; childthread = processinfo.hThread; childprocessid = processinfo.dwProcessId; childthreadid = processinfo.dwThreadId; // // associate our handle with the child processid // OzRegisterPIDHandle(childprocessid, childprocess); // // start the child process' thread running // OzResumeThread(childthread); // // the system call loop // OzDispatchSyscalls (syscallhandlers, MYSYS_LIMIT); // // exit // OzTerminateThread(childthread, 0); OzTerminateProcess(childthread, 0); CloseHandle(childthread); CloseHandle(childprocess); printf("bye\n"); ExitProcess(0); }