mirror of
https://github.com/reactos/reactos.git
synced 2025-08-01 19:13:30 +00:00
*** empty log message ***
svn path=/trunk/; revision=143
This commit is contained in:
parent
d55d012d33
commit
02e3d7b08e
45 changed files with 6603 additions and 7008 deletions
10
reactos/apps/tests/hello/hello.c
Normal file
10
reactos/apps/tests/hello/hello.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include <ddk/ntddk.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
NtDisplayString("Shell Starting...\n");
|
||||||
|
ExitThread(0);
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
all: test.bin
|
all: hello.bin
|
||||||
|
|
||||||
test.bin: test.o
|
OBJECTS = ../common/crt0.o hello.o
|
||||||
$(LD) -Ttext 0x10000 test.o ../../lib/ntdll/ntdll.a -o test.exe
|
|
||||||
$(OBJCOPY) -O binary test.exe test.bin
|
hello.bin: $(OBJECTS)
|
||||||
|
$(LD) -Ttext 0x10000 $(OBJECTS) ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a -o hello.exe
|
||||||
|
$(OBJCOPY) -O binary hello.exe hello.bin
|
||||||
|
|
||||||
include ../../rules.mak
|
include ../../rules.mak
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
BITS 32
|
|
||||||
|
|
||||||
EXTERN _NtDisplayString
|
|
||||||
|
|
||||||
_main:
|
|
||||||
push dword _string
|
|
||||||
call _NtDisplayString
|
|
||||||
l1:
|
|
||||||
jmp l1
|
|
||||||
|
|
||||||
_string db 'Hello world from user mode!',0xa,0
|
|
|
@ -50,6 +50,19 @@ void ExecuteCd(char* cmdline)
|
||||||
|
|
||||||
void ExecuteDir(char* cmdline)
|
void ExecuteDir(char* cmdline)
|
||||||
{
|
{
|
||||||
|
HANDLE shandle;
|
||||||
|
WIN32_FIND_DATA FindData;
|
||||||
|
|
||||||
|
shandle = FindFirstFile("*.*",&FindData);
|
||||||
|
|
||||||
|
if (shandle==INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
do
|
||||||
|
{
|
||||||
|
debug_printf("Scanning %s\n",FindData.cFileName);
|
||||||
|
} while(FindNextFile(shandle,&FindData));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteType(char* cmdline)
|
void ExecuteType(char* cmdline)
|
||||||
|
@ -76,6 +89,28 @@ void ExecuteType(char* cmdline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ExecuteProcess(char* name, char* cmdline)
|
||||||
|
{
|
||||||
|
PROCESS_INFORMATION ProcessInformation;
|
||||||
|
STARTUPINFO StartupInfo;
|
||||||
|
char arguments;
|
||||||
|
|
||||||
|
memset(&StartupInfo,0,sizeof(StartupInfo));
|
||||||
|
StartupInfo.cb = sizeof(STARTUPINFO);
|
||||||
|
StartupInfo.lpTitle = name;
|
||||||
|
|
||||||
|
return(CreateProcessA(name,
|
||||||
|
cmdline,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
TRUE,
|
||||||
|
CREATE_NEW_CONSOLE,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&StartupInfo,
|
||||||
|
&ProcessInformation));
|
||||||
|
}
|
||||||
|
|
||||||
void ExecuteCommand(char* line)
|
void ExecuteCommand(char* line)
|
||||||
{
|
{
|
||||||
char* cmd;
|
char* cmd;
|
||||||
|
@ -122,6 +157,11 @@ void ExecuteCommand(char* line)
|
||||||
ExecuteType(tail);
|
ExecuteType(tail);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ExecuteProcess(cmd,tail))
|
||||||
|
{
|
||||||
|
debug_printf("Done ExecuteProcess\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
debug_printf("Unknown command\n");
|
debug_printf("Unknown command\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +196,8 @@ void main()
|
||||||
{
|
{
|
||||||
static char line[255];
|
static char line[255];
|
||||||
|
|
||||||
|
KERNEL32_Init();
|
||||||
|
|
||||||
NtDisplayString("Shell Starting...\n");
|
NtDisplayString("Shell Starting...\n");
|
||||||
|
|
||||||
KeyboardHandle = CreateFile("Keyboard",
|
KeyboardHandle = CreateFile("Keyboard",
|
||||||
|
|
|
@ -486,12 +486,7 @@ NtContinue(
|
||||||
IN CINT IrqLevel
|
IN CINT IrqLevel
|
||||||
);
|
);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS STDCALL ZwContinue(IN PCONTEXT Context, IN CINT IrqLevel);
|
||||||
STDCALL
|
|
||||||
ZwContinue(
|
|
||||||
IN PCONTEXT Context,
|
|
||||||
IN CINT IrqLevel
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS system libraries
|
||||||
|
* FILE: lib/crtdll/stdlib/malloc.c
|
||||||
|
* PURPOSE: stdc memory allocation functions
|
||||||
|
* PROGRAMMER: ??
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
void* malloc(size_t size)
|
void* malloc(size_t size)
|
||||||
{
|
{
|
||||||
return(HeapAlloc(GetProcessHeap(),
|
return(HeapAlloc(GetProcessHeap(), 0, size));
|
||||||
0,
|
|
||||||
size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(void* ptr)
|
void free(void* ptr)
|
||||||
{
|
{
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(), 0, ptr);
|
||||||
0,
|
|
||||||
ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* calloc(size_t nmemb, size_t size)
|
void* calloc(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
return(HeapAlloc(GetProcessHeap(),
|
return(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nmemb*size));
|
||||||
HEAP_ZERO_MEMORY,
|
|
||||||
nmemb*size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* realloc(void* ptr, size_t size)
|
void* realloc(void* ptr, size_t size)
|
||||||
{
|
{
|
||||||
return(HeapReAlloc(GetProcessHeap(),
|
return(HeapReAlloc(GetProcessHeap(), 0, ptr, size));
|
||||||
0,
|
|
||||||
ptr,
|
|
||||||
size));
|
|
||||||
}
|
}
|
||||||
|
|
68
reactos/lib/kernel32/file/cnotify.c
Normal file
68
reactos/lib/kernel32/file/cnotify.c
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS system libraries
|
||||||
|
* FILE: lib/kernel32/file/find.c
|
||||||
|
* PURPOSE: Find functions
|
||||||
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||||
|
* UPDATE HISTORY:
|
||||||
|
* Created 01/11/98
|
||||||
|
*/
|
||||||
|
#include <windows.h>
|
||||||
|
#include <wstring.h>
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
FindCloseChangeNotification(
|
||||||
|
HANDLE hChangeHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstChangeNotificationA(
|
||||||
|
LPCSTR lpPathName,
|
||||||
|
WINBOOL bWatchSubtree,
|
||||||
|
DWORD dwNotifyFilter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
|
WCHAR PathNameW[MAX_PATH];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((*lpPathName)!=0 && i < MAX_PATH)
|
||||||
|
{
|
||||||
|
PathNameW[i] = *lpPathName;
|
||||||
|
lpPathName++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
PathNameW[i] = 0;
|
||||||
|
return FindFirstChangeNotificationW(PathNameW, bWatchSubtree, dwNotifyFilter );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstChangeNotificationW(
|
||||||
|
LPCWSTR lpPathName,
|
||||||
|
WINBOOL bWatchSubtree,
|
||||||
|
DWORD dwNotifyFilter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
STDCALL
|
||||||
|
FindNextChangeNotification(
|
||||||
|
HANDLE hChangeHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
450
reactos/lib/kernel32/file/find-bak.c
Normal file
450
reactos/lib/kernel32/file/find-bak.c
Normal file
|
@ -0,0 +1,450 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS system libraries
|
||||||
|
* FILE: lib/kernel32/file/find.c
|
||||||
|
* PURPOSE: Find functions
|
||||||
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||||
|
* UPDATE HISTORY:
|
||||||
|
* Created 01/11/98
|
||||||
|
*/
|
||||||
|
#include <windows.h>
|
||||||
|
#include <wstring.h>
|
||||||
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
|
typedef enum _FINDEX_INFO_LEVELS
|
||||||
|
{
|
||||||
|
FindExSearchNameMatch,
|
||||||
|
FindExSearchLimitToDirectories,
|
||||||
|
FindExSearchLimitToDevices,
|
||||||
|
|
||||||
|
} FINDEX_INFO_LEVELS ;
|
||||||
|
|
||||||
|
typedef enum _FINDEX_SEARCH_OPS
|
||||||
|
{
|
||||||
|
FindExInfoStandard
|
||||||
|
|
||||||
|
} FINDEX_SEARCH_OPS;
|
||||||
|
|
||||||
|
int wcharicmp ( WCHAR char1, WCHAR char2 );
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter);
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileW(
|
||||||
|
LPCWSTR lpFileName,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
);
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
STDCALL
|
||||||
|
FindNextFileW(
|
||||||
|
HANDLE hFind,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
);
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileExA(
|
||||||
|
LPCSTR lpFileName,
|
||||||
|
FINDEX_INFO_LEVELS fInfoLevelId,
|
||||||
|
LPVOID lpFindFileData,
|
||||||
|
FINDEX_SEARCH_OPS fSearchOp,
|
||||||
|
LPVOID lpSearchFilter,
|
||||||
|
DWORD dwAdditionalFlags
|
||||||
|
);
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileExW(
|
||||||
|
LPCWSTR lpFileName,
|
||||||
|
FINDEX_INFO_LEVELS fInfoLevelId,
|
||||||
|
LPVOID lpFindFileData,
|
||||||
|
FINDEX_SEARCH_OPS fSearchOp,
|
||||||
|
LPVOID lpSearchFilter,
|
||||||
|
DWORD dwAdditionalFlags
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef struct _FIND_FILE_INFO
|
||||||
|
{
|
||||||
|
ULONG Offset;
|
||||||
|
PVOID SearchFilter;
|
||||||
|
WCHAR FileName[MAX_PATH];
|
||||||
|
WCHAR PathName[MAX_PATH];
|
||||||
|
FILE_DIRECTORY_INFORMATION *FileDirectory;
|
||||||
|
} FIND_FILE_INFO;
|
||||||
|
|
||||||
|
typedef struct _WIN32_FIND_DATAW {
|
||||||
|
DWORD dwFileAttributes;
|
||||||
|
FILETIME ftCreationTime;
|
||||||
|
FILETIME ftLastAccessTime;
|
||||||
|
FILETIME ftLastWriteTime;
|
||||||
|
DWORD nFileSizeHigh;
|
||||||
|
DWORD nFileSizeLow;
|
||||||
|
DWORD dwReserved0;
|
||||||
|
DWORD dwReserved1;
|
||||||
|
WCHAR cFileName[ MAX_PATH ];
|
||||||
|
WCHAR cAlternateFileName[ 14 ];
|
||||||
|
} WIN32_FIND_DATAW, *LPWIN32_FIND_DATAW, *PWIN32_FIND_DATAW;
|
||||||
|
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
STDCALL
|
||||||
|
FindClose(
|
||||||
|
HANDLE hFind
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( hFind == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(),0,((FIND_FILE_INFO *)hFind)->FileDirectory);
|
||||||
|
HeapFree(GetProcessHeap(),0,hFind);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileA(
|
||||||
|
LPCSTR lpFileName,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA FindFileDataW;
|
||||||
|
WCHAR FileNameW[MAX_PATH];
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((*lpFileName)!=0 && i < MAX_PATH)
|
||||||
|
{
|
||||||
|
FileNameW[i] = *lpFileName;
|
||||||
|
lpFileName++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
FileNameW[i] = 0;
|
||||||
|
FindFirstFileW(FileNameW,&FindFileDataW);
|
||||||
|
|
||||||
|
// converteer FindFileDataW
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileW(
|
||||||
|
LPCWSTR lpFileName,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return FindFirstFileExW(lpFileName,FindExInfoStandard,lpFindFileData,FindExSearchNameMatch,NULL,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
STDCALL
|
||||||
|
FindNextFileA(
|
||||||
|
HANDLE hFind,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA FindFileDataW;
|
||||||
|
FindNextFileW(hFind,&FindFileDataW);
|
||||||
|
// converteer FindFileDataW
|
||||||
|
}
|
||||||
|
|
||||||
|
WINBOOL
|
||||||
|
STDCALL
|
||||||
|
FindNextFileW(
|
||||||
|
HANDLE hFind,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
WCHAR *pNameRead;
|
||||||
|
WCHAR FileName[MAX_PATH];
|
||||||
|
|
||||||
|
FIND_FILE_INFO *FindPtr = hFind;
|
||||||
|
FILE_DIRECTORY_INFORMATION *FileDirectory;
|
||||||
|
|
||||||
|
if ( FindPtr == NULL )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Try to find a file */
|
||||||
|
FileDirectory = FindPtr->Offset + FindPtr->FileDirectory;
|
||||||
|
while ( FileDirectory->NextEntryOffset != 0 ) {
|
||||||
|
|
||||||
|
pNameRead = FileDirectory->FileName;
|
||||||
|
FindPtr->Offset += FileDirectory->NextEntryOffset;
|
||||||
|
for(i=0;i<FileDirectory->FileNameLength;i++)
|
||||||
|
dprintf("%c\n",(char)pNameRead[i]);
|
||||||
|
if (mfs_regexp(pNameRead, FindPtr->FileName))
|
||||||
|
{
|
||||||
|
/* We found one! */
|
||||||
|
if (FindPtr->PathName[0] != L'\0')
|
||||||
|
{
|
||||||
|
lstrcpyW(lpFindFileData->cFileName, FindPtr->PathName);
|
||||||
|
lstrcatW(lpFindFileData->cFileName, L"/");
|
||||||
|
lstrcatW(lpFindFileData->cFileName, pNameRead);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
|
||||||
|
lstrcpyW(lpFindFileData->cFileName, pNameRead);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lstrcpyW(lpFindFileData->cAlternateFileName, L"");
|
||||||
|
lpFindFileData->dwReserved0 = 0;
|
||||||
|
lpFindFileData->dwReserved1 = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
FileDirectory = FindPtr->Offset + FindPtr->FileDirectory;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileExA(
|
||||||
|
LPCSTR lpFileName,
|
||||||
|
FINDEX_INFO_LEVELS fInfoLevelId,
|
||||||
|
LPVOID lpFindFileData,
|
||||||
|
FINDEX_SEARCH_OPS fSearchOp,
|
||||||
|
LPVOID lpSearchFilter,
|
||||||
|
DWORD dwAdditionalFlags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
WCHAR FileNameW[MAX_PATH];
|
||||||
|
WIN32_FIND_DATAW FindFileDataW;
|
||||||
|
FindFirstFileExW(FileNameW,fInfoLevelId,&FindFileDataW,fSearchOp,lpSearchFilter,dwAdditionalFlags);
|
||||||
|
// conerteer FindFileDataW
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE
|
||||||
|
STDCALL
|
||||||
|
FindFirstFileExW(
|
||||||
|
LPCWSTR lpFileName,
|
||||||
|
FINDEX_INFO_LEVELS fInfoLevelId,
|
||||||
|
LPVOID lpFindFileData,
|
||||||
|
FINDEX_SEARCH_OPS fSearchOp,
|
||||||
|
LPVOID lpSearchFilter,
|
||||||
|
DWORD dwAdditionalFlags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
NTSTATUS errCode;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
HANDLE FileHandle = NULL;
|
||||||
|
FIND_FILE_INFO *hFind;
|
||||||
|
WCHAR *FilePart;
|
||||||
|
UNICODE_STRING FileNameString, PathNameString;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
|
||||||
|
|
||||||
|
ACCESS_MASK DesiredAccess=FILE_READ_DATA;
|
||||||
|
|
||||||
|
ULONG FileAttributes=FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
ULONG ShareAccess=FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||||
|
ULONG CreateDisposition=FILE_OPEN;
|
||||||
|
ULONG CreateOptions=FILE_DIRECTORY_FILE;
|
||||||
|
|
||||||
|
|
||||||
|
hFind = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,sizeof(FIND_FILE_INFO));
|
||||||
|
|
||||||
|
hFind->FileDirectory = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,8192);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Try to find a path and a filename in the passed filename */
|
||||||
|
|
||||||
|
lstrcpyW(hFind->PathName, lpFileName);
|
||||||
|
FilePart = wcsrchr(hFind->PathName, '\\');
|
||||||
|
|
||||||
|
if (FilePart == NULL){
|
||||||
|
GetCurrentDirectory(MAX_PATH, hFind->PathName);
|
||||||
|
lstrcpyW(hFind->FileName, lpFileName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FilePart[0] = L'\0';
|
||||||
|
lstrcpyW(hFind->FileName, &FilePart[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
hFind->Offset = 0;
|
||||||
|
|
||||||
|
|
||||||
|
PathNameString.Length = lstrlenW(hFind->PathName)*sizeof(WCHAR);
|
||||||
|
PathNameString.Buffer = hFind->PathName;
|
||||||
|
PathNameString.MaximumLength = FileNameString.Length;
|
||||||
|
|
||||||
|
|
||||||
|
FileNameString.Length = lstrlenW(hFind->FileName)*sizeof(WCHAR);
|
||||||
|
FileNameString.Buffer = hFind->FileName;
|
||||||
|
FileNameString.MaximumLength = FileNameString.Length;
|
||||||
|
|
||||||
|
|
||||||
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
|
ObjectAttributes.ObjectName = &PathNameString;
|
||||||
|
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
|
||||||
|
ObjectAttributes.SecurityDescriptor = NULL;
|
||||||
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
errCode = NtCreateFile(
|
||||||
|
&FileHandle,
|
||||||
|
DesiredAccess,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
NULL, // AllocationSize
|
||||||
|
FileAttributes,
|
||||||
|
ShareAccess,
|
||||||
|
CreateDisposition,
|
||||||
|
CreateOptions,
|
||||||
|
NULL, // EaBuffer
|
||||||
|
0); //
|
||||||
|
|
||||||
|
if ( !NT_SUCCESS(errCode) ) {
|
||||||
|
printf("%x\n",errCode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCode = NtQueryDirectoryFile(
|
||||||
|
FileHandle,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&IoStatusBlock,
|
||||||
|
hFind->FileDirectory,
|
||||||
|
8192,
|
||||||
|
FileDirectoryInformation,
|
||||||
|
FALSE,
|
||||||
|
&FileNameString,
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
|
if ( !NT_SUCCESS(errCode) ) {
|
||||||
|
printf("%x\n",errCode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ( FindNextFileW(hFind,lpFindFileData) )
|
||||||
|
return hFind;
|
||||||
|
else {
|
||||||
|
FindClose(hFind);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
WINBOOL
|
||||||
|
mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter)
|
||||||
|
{
|
||||||
|
/* The following code is provided by Tarang and I trust him...
|
||||||
|
*/
|
||||||
|
LPWSTR lpTempFileName = (LPWSTR)lpFileName;
|
||||||
|
LPWSTR lpTempFilter = (LPWSTR)lpFilter;
|
||||||
|
WCHAR TempToken [ 2 ];
|
||||||
|
WCHAR TempFilter [ 2 ];
|
||||||
|
WINBOOL Matched = FALSE;
|
||||||
|
|
||||||
|
if ( ( ! (LPWSTR)lpFileName ) || ( ! *(LPWSTR)lpFileName ) ||
|
||||||
|
( ! (LPWSTR)lpFilter ) || ( ! *(LPWSTR)lpFilter ) )
|
||||||
|
return 0L;
|
||||||
|
|
||||||
|
if ( ! lstrcmpW ( ( LPSTR )lpFilter, "*.*" ) )
|
||||||
|
{
|
||||||
|
wsprintf ( TempFilter, "*" );
|
||||||
|
lpTempFilter = TempFilter;
|
||||||
|
lpFilter = TempFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( ( lpTempFilter ) && ( *lpTempFilter ) && ( ! Matched ) )
|
||||||
|
{
|
||||||
|
memset ( TempToken, 0, sizeof ( TempToken ) );
|
||||||
|
switch ( *lpTempFilter )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
if ( wcharicmp ( *lpTempFileName, *lpTempFilter ) )
|
||||||
|
{
|
||||||
|
lpTempFileName = (LPWSTR)lpFileName;
|
||||||
|
lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" );
|
||||||
|
if ( lpTempFilter )
|
||||||
|
lpTempFilter+=sizeof(WCHAR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lpTempFilter+=sizeof(WCHAR);
|
||||||
|
lpTempFileName+=sizeof(WCHAR);
|
||||||
|
switch ( *lpTempFilter )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L'\0':
|
||||||
|
case L' ':
|
||||||
|
case L',':
|
||||||
|
case L';':
|
||||||
|
if ( ! *lpTempFileName )
|
||||||
|
Matched = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L'?':
|
||||||
|
lpTempFilter+=sizeof(WCHAR);
|
||||||
|
lpTempFileName+=sizeof(WCHAR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L'*':
|
||||||
|
lpTempFilter += sizeof(WCHAR);
|
||||||
|
if ( ! ( TempToken [ 0 ] = *( lpTempFilter ) ) )
|
||||||
|
Matched = TRUE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lpTempFilter+=sizeof(WCHAR);
|
||||||
|
while ( ( lpTempFileName = wcspbrk ( lpTempFileName, TempToken ) ) &&
|
||||||
|
( ! Matched ) ) {
|
||||||
|
lpTempFileName+= sizeof(WCHAR);
|
||||||
|
Matched = mfs_regexp ( lpTempFileName, lpTempFilter );
|
||||||
|
}
|
||||||
|
if ( ( ! lpTempFileName ) && ( ! Matched ) )
|
||||||
|
{
|
||||||
|
lpTempFileName = (LPWSTR)lpFileName;
|
||||||
|
lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" );
|
||||||
|
if ( lpTempFilter )
|
||||||
|
lpTempFilter+=sizeof(WCHAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L'\0':
|
||||||
|
case L' ':
|
||||||
|
case L',':
|
||||||
|
case L';':
|
||||||
|
Matched = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (DWORD)Matched;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int wcharicmp ( WCHAR char1, WCHAR char2 )
|
||||||
|
{
|
||||||
|
WCHAR Char1 = ( L'a' <= char1 ) && ( char1 <= L'z' ) ?
|
||||||
|
char1 - L'a' + L'A' : char1;
|
||||||
|
WCHAR Char2 = ( L'a' <= char2 ) && ( char2 <= L'z' ) ?
|
||||||
|
char2 - L'a' + L'A' : char2;
|
||||||
|
return ( Char2 - Char1 );
|
||||||
|
}
|
|
@ -7,515 +7,123 @@
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
* Created 01/11/98
|
* Created 01/11/98
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <wstring.h>
|
#include <wstring.h>
|
||||||
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
typedef enum _FINDEX_INFO_LEVELS
|
/* TYPES ********************************************************************/
|
||||||
|
|
||||||
|
typedef struct _KERNEL32_FIND_FILE_DATA
|
||||||
{
|
{
|
||||||
FindExSearchNameMatch,
|
HANDLE DirectoryHandle;
|
||||||
FindExSearchLimitToDirectories,
|
FILE_DIRECTORY_INFORMATION FileInfo;
|
||||||
FindExSearchLimitToDevices,
|
} KERNEL32_FIND_FILE_DATA, *PKERNEL32_FIND_FILE_DATA;
|
||||||
|
|
||||||
} FINDEX_INFO_LEVELS ;
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
typedef enum _FINDEX_SEARCH_OPS
|
HANDLE FindFirstFileA(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
|
||||||
{
|
{
|
||||||
FindExInfoStandard
|
WCHAR lpFileNameW[MAX_PATH];
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
} FINDEX_SEARCH_OPS;
|
i = 0;
|
||||||
|
while (lpFileName[i]!=0)
|
||||||
|
{
|
||||||
|
lpFileNameW[i] = lpFileName[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
int wcharicmp ( WCHAR char1, WCHAR char2 );
|
return(FindFirstFileW(lpFileNameW,lpFindFileData));
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter);
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileW(
|
|
||||||
LPWSTR lpFileName,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
);
|
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
STDCALL
|
|
||||||
FindNextFileW(
|
|
||||||
HANDLE hFind,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
);
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileExA(
|
|
||||||
LPCSTR lpFileName,
|
|
||||||
FINDEX_INFO_LEVELS fInfoLevelId,
|
|
||||||
LPVOID lpFindFileData,
|
|
||||||
FINDEX_SEARCH_OPS fSearchOp,
|
|
||||||
LPVOID lpSearchFilter,
|
|
||||||
DWORD dwAdditionalFlags
|
|
||||||
);
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileExW(
|
|
||||||
LPCWSTR lpFileName,
|
|
||||||
FINDEX_INFO_LEVELS fInfoLevelId,
|
|
||||||
LPVOID lpFindFileData,
|
|
||||||
FINDEX_SEARCH_OPS fSearchOp,
|
|
||||||
LPVOID lpSearchFilter,
|
|
||||||
DWORD dwAdditionalFlags
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef struct _FIND_FILE_INFO
|
|
||||||
{
|
|
||||||
ULONG Offset;
|
|
||||||
PVOID SearchFilter;
|
|
||||||
WCHAR FileName[MAX_PATH];
|
|
||||||
WCHAR PathName[MAX_PATH];
|
|
||||||
FILE_DIRECTORY_INFORMATION *FileDirectory;
|
|
||||||
} FIND_FILE_INFO;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
typedef struct _WIN32_FIND_DATAW {
|
|
||||||
DWORD dwFileAttributes;
|
|
||||||
FILETIME ftCreationTime;
|
|
||||||
FILETIME ftLastAccessTime;
|
|
||||||
FILETIME ftLastWriteTime;
|
|
||||||
DWORD nFileSizeHigh;
|
|
||||||
DWORD nFileSizeLow;
|
|
||||||
DWORD dwReserved0;
|
|
||||||
DWORD dwReserved1;
|
|
||||||
WCHAR cFileName[ MAX_PATH ];
|
|
||||||
WCHAR cAlternateFileName[ 14 ];
|
|
||||||
} WIN32_FIND_DATAW, *LPWIN32_FIND_DATAW, *PWIN32_FIND_DATAW;
|
|
||||||
*/
|
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
STDCALL
|
|
||||||
FindClose(
|
|
||||||
HANDLE hFind
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
if ( hFind == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(),0,((FIND_FILE_INFO *)hFind)->FileDirectory);
|
|
||||||
HeapFree(GetProcessHeap(),0,hFind);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WINBOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData)
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileA(
|
|
||||||
LPCSTR lpFileName,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA FindFileDataW;
|
return(FindNextFileW(hFindFile, lpFindFileData));
|
||||||
WCHAR FileNameW[MAX_PATH];
|
|
||||||
ULONG i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((*lpFileName)!=0 && i < MAX_PATH)
|
|
||||||
{
|
|
||||||
FileNameW[i] = *lpFileName;
|
|
||||||
lpFileName++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
FileNameW[i] = 0;
|
|
||||||
FindFirstFileW(FileNameW,&FindFileDataW);
|
|
||||||
|
|
||||||
// converteer FindFileDataW
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE
|
BOOL FindClose(HANDLE hFindFile)
|
||||||
STDCALL
|
|
||||||
FindFirstFileW(
|
|
||||||
LPWSTR lpFileName,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return FindFirstFileExW(lpFileName,FindExInfoStandard,lpFindFileData,FindExSearchNameMatch,NULL,0);
|
PKERNEL32_FIND_FILE_DATA IData;
|
||||||
|
|
||||||
|
IData = (PKERNEL32_FIND_FILE_DATA)hFindFile;
|
||||||
|
NtClose(IData->DirectoryHandle);
|
||||||
|
HeapFree(GetProcessHeap(), 0, IData);
|
||||||
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
WINBOOL
|
HANDLE STDCALL FindFirstFileW(LPCWSTR lpFileName,
|
||||||
STDCALL
|
LPWIN32_FIND_DATA lpFindFileData)
|
||||||
FindNextFileA(
|
|
||||||
HANDLE hFind,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA FindFileDataW;
|
WCHAR CurrentDirectory[MAX_PATH];
|
||||||
FindNextFileW(hFind,&FindFileDataW);
|
WCHAR Pattern[MAX_PATH];
|
||||||
// converteer FindFileDataW
|
WCHAR Directory[MAX_PATH];
|
||||||
|
PWSTR End;
|
||||||
|
PKERNEL32_FIND_FILE_DATA IData;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
UNICODE_STRING DirectoryNameStr;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
UNICODE_STRING PatternStr;
|
||||||
|
|
||||||
|
dprintf("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n",
|
||||||
|
lpFileName, lpFindFileData);
|
||||||
|
|
||||||
|
GetCurrentDirectoryW(MAX_PATH, CurrentDirectory);
|
||||||
|
Directory[0] = '\\';
|
||||||
|
Directory[1] = '?';
|
||||||
|
Directory[2] = '?';
|
||||||
|
Directory[3] = '\\';
|
||||||
|
Directory[4] = 0;
|
||||||
|
wcscat(Directory, CurrentDirectory);
|
||||||
|
wcscat(Directory, lpFileName);
|
||||||
|
End = wcschr(Directory, '\\');
|
||||||
|
*End = 0;
|
||||||
|
|
||||||
|
wcscpy(Pattern, End+1);
|
||||||
|
|
||||||
|
dprintf("Directory %w End %w\n",Directory,End);
|
||||||
|
|
||||||
|
IData = HeapAlloc(GetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(KERNEL32_FIND_FILE_DATA));
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&DirectoryNameStr, Directory);
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&DirectoryNameStr,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (ZwOpenFile(&IData->DirectoryHandle,
|
||||||
|
FILE_TRAVERSE,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
0,
|
||||||
|
OPEN_EXISTING)!=STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&PatternStr, Pattern);
|
||||||
|
|
||||||
|
NtQueryDirectoryFile(IData->DirectoryHandle,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&IoStatusBlock,
|
||||||
|
(PVOID)&IData->FileInfo,
|
||||||
|
sizeof(IData->FileInfo),
|
||||||
|
FileDirectoryInformation,
|
||||||
|
TRUE,
|
||||||
|
&PatternStr,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
return(IData);
|
||||||
}
|
}
|
||||||
|
|
||||||
WINBOOL
|
WINBOOL STDCALL FindNextFileW(HANDLE hFindFile,
|
||||||
STDCALL
|
LPWIN32_FIND_DATA lpFindFileData)
|
||||||
FindNextFileW(
|
|
||||||
HANDLE hFind,
|
|
||||||
LPWIN32_FIND_DATA lpFindFileData
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
WCHAR *pNameRead;
|
|
||||||
WCHAR FileName[MAX_PATH];
|
|
||||||
|
|
||||||
FIND_FILE_INFO *FindPtr = hFind;
|
|
||||||
FILE_DIRECTORY_INFORMATION *FileDirectory;
|
|
||||||
|
|
||||||
if ( FindPtr == NULL )
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* Try to find a file */
|
|
||||||
FileDirectory = FindPtr->Offset + FindPtr->FileDirectory;
|
|
||||||
while ( FileDirectory->NextEntryOffset != 0 ) {
|
|
||||||
|
|
||||||
pNameRead = FileDirectory->FileName;
|
|
||||||
FindPtr->Offset += FileDirectory->NextEntryOffset;
|
|
||||||
for(i=0;i<FileDirectory->FileNameLength;i++)
|
|
||||||
printf("%c\n",(char)pNameRead[i]);
|
|
||||||
if (mfs_regexp(pNameRead, FindPtr->FileName))
|
|
||||||
{
|
|
||||||
/* We found one! */
|
|
||||||
if (FindPtr->PathName[0] != L'\0')
|
|
||||||
{
|
|
||||||
lstrcpyW(lpFindFileData->cFileName, FindPtr->PathName);
|
|
||||||
lstrcatW(lpFindFileData->cFileName, L"/");
|
|
||||||
lstrcatW(lpFindFileData->cFileName, pNameRead);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
|
|
||||||
lstrcpyW(lpFindFileData->cFileName, pNameRead);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lstrcpyW(lpFindFileData->cAlternateFileName, L"");
|
|
||||||
lpFindFileData->dwReserved0 = 0;
|
|
||||||
lpFindFileData->dwReserved1 = 0;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
FileDirectory = FindPtr->Offset + FindPtr->FileDirectory;
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileExA(
|
|
||||||
LPCSTR lpFileName,
|
|
||||||
FINDEX_INFO_LEVELS fInfoLevelId,
|
|
||||||
LPVOID lpFindFileData,
|
|
||||||
FINDEX_SEARCH_OPS fSearchOp,
|
|
||||||
LPVOID lpSearchFilter,
|
|
||||||
DWORD dwAdditionalFlags
|
|
||||||
)
|
|
||||||
{
|
|
||||||
WCHAR FileNameW[MAX_PATH];
|
|
||||||
WIN32_FIND_DATAW FindFileDataW;
|
|
||||||
FindFirstFileExW(FileNameW,fInfoLevelId,&FindFileDataW,fSearchOp,lpSearchFilter,dwAdditionalFlags);
|
|
||||||
// conerteer FindFileDataW
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstFileExW(
|
|
||||||
LPCWSTR lpFileName,
|
|
||||||
FINDEX_INFO_LEVELS fInfoLevelId,
|
|
||||||
LPVOID lpFindFileData,
|
|
||||||
FINDEX_SEARCH_OPS fSearchOp,
|
|
||||||
LPVOID lpSearchFilter,
|
|
||||||
DWORD dwAdditionalFlags
|
|
||||||
)
|
|
||||||
{
|
|
||||||
NTSTATUS errCode;
|
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
|
||||||
HANDLE FileHandle = NULL;
|
|
||||||
FIND_FILE_INFO *hFind;
|
|
||||||
WCHAR *FilePart;
|
|
||||||
UNICODE_STRING FileNameString, PathNameString;
|
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
|
|
||||||
|
|
||||||
ACCESS_MASK DesiredAccess=FILE_READ_DATA;
|
|
||||||
|
|
||||||
ULONG FileAttributes=FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
ULONG ShareAccess=FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
|
||||||
ULONG CreateDisposition=FILE_OPEN;
|
|
||||||
ULONG CreateOptions=FILE_DIRECTORY_FILE;
|
|
||||||
|
|
||||||
|
|
||||||
hFind = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,sizeof(FIND_FILE_INFO));
|
|
||||||
|
|
||||||
hFind->FileDirectory = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,8192);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Try to find a path and a filename in the passed filename */
|
|
||||||
|
|
||||||
lstrcpyW(hFind->PathName, lpFileName);
|
|
||||||
FilePart = wcsrchr(hFind->PathName, '\\');
|
|
||||||
|
|
||||||
if (FilePart == NULL){
|
|
||||||
GetCurrentDirectory(MAX_PATH, hFind->PathName);
|
|
||||||
lstrcpyW(hFind->FileName, lpFileName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
FilePart[0] = L'\0';
|
|
||||||
lstrcpyW(hFind->FileName, &FilePart[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
hFind->Offset = 0;
|
|
||||||
|
|
||||||
|
|
||||||
PathNameString.Length = lstrlenW(hFind->PathName)*sizeof(WCHAR);
|
|
||||||
PathNameString.Buffer = hFind->PathName;
|
|
||||||
PathNameString.MaximumLength = FileNameString.Length;
|
|
||||||
|
|
||||||
|
|
||||||
FileNameString.Length = lstrlenW(hFind->FileName)*sizeof(WCHAR);
|
|
||||||
FileNameString.Buffer = hFind->FileName;
|
|
||||||
FileNameString.MaximumLength = FileNameString.Length;
|
|
||||||
|
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
|
||||||
ObjectAttributes.ObjectName = &PathNameString;
|
|
||||||
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT;
|
|
||||||
ObjectAttributes.SecurityDescriptor = NULL;
|
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
errCode = NtCreateFile(
|
|
||||||
&FileHandle,
|
|
||||||
DesiredAccess,
|
|
||||||
&ObjectAttributes,
|
|
||||||
&IoStatusBlock,
|
|
||||||
NULL, // AllocationSize
|
|
||||||
FileAttributes,
|
|
||||||
ShareAccess,
|
|
||||||
CreateDisposition,
|
|
||||||
CreateOptions,
|
|
||||||
NULL, // EaBuffer
|
|
||||||
0); //
|
|
||||||
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
printf("%x\n",errCode);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
errCode = NtQueryDirectoryFile(
|
|
||||||
FileHandle,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&IoStatusBlock,
|
|
||||||
hFind->FileDirectory,
|
|
||||||
8192,
|
|
||||||
FileDirectoryInformation,
|
|
||||||
FALSE,
|
|
||||||
&FileNameString,
|
|
||||||
FALSE
|
|
||||||
);
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
printf("%x\n",errCode);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( FindNextFileW(hFind,lpFindFileData) )
|
|
||||||
return hFind;
|
|
||||||
else {
|
|
||||||
FindClose(hFind);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
FindCloseChangeNotification(
|
|
||||||
HANDLE hChangeHandle
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstChangeNotificationA(
|
|
||||||
LPCSTR lpPathName,
|
|
||||||
WINBOOL bWatchSubtree,
|
|
||||||
DWORD dwNotifyFilter
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ULONG i;
|
|
||||||
|
|
||||||
WCHAR PathNameW[MAX_PATH];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((*lpPathName)!=0 && i < MAX_PATH)
|
|
||||||
{
|
|
||||||
PathNameW[i] = *lpPathName;
|
|
||||||
lpPathName++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
PathNameW[i] = 0;
|
|
||||||
return FindFirstChangeNotificationW(PathNameW, bWatchSubtree, dwNotifyFilter );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
FindFirstChangeNotificationW(
|
|
||||||
LPCWSTR lpPathName,
|
|
||||||
WINBOOL bWatchSubtree,
|
|
||||||
DWORD dwNotifyFilter
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
STDCALL
|
|
||||||
FindNextChangeNotification(
|
|
||||||
HANDLE hChangeHandle
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
WINBOOL
|
|
||||||
mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter)
|
|
||||||
{
|
|
||||||
/* The following code is provided by Tarang and I trust him...
|
|
||||||
*/
|
|
||||||
LPWSTR lpTempFileName = (LPWSTR)lpFileName;
|
|
||||||
LPWSTR lpTempFilter = (LPWSTR)lpFilter;
|
|
||||||
WCHAR TempToken [ 2 ];
|
|
||||||
WCHAR TempFilter [ 2 ];
|
|
||||||
WINBOOL Matched = FALSE;
|
|
||||||
|
|
||||||
if ( ( ! (LPWSTR)lpFileName ) || ( ! *(LPWSTR)lpFileName ) ||
|
|
||||||
( ! (LPWSTR)lpFilter ) || ( ! *(LPWSTR)lpFilter ) )
|
|
||||||
return 0L;
|
|
||||||
|
|
||||||
if ( ! lstrcmpW ( ( LPSTR )lpFilter, "*.*" ) )
|
|
||||||
{
|
|
||||||
wsprintf ( TempFilter, "*" );
|
|
||||||
lpTempFilter = TempFilter;
|
|
||||||
lpFilter = TempFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( ( lpTempFilter ) && ( *lpTempFilter ) && ( ! Matched ) )
|
|
||||||
{
|
|
||||||
memset ( TempToken, 0, sizeof ( TempToken ) );
|
|
||||||
switch ( *lpTempFilter )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
if ( wcharicmp ( *lpTempFileName, *lpTempFilter ) )
|
|
||||||
{
|
|
||||||
lpTempFileName = (LPWSTR)lpFileName;
|
|
||||||
lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" );
|
|
||||||
if ( lpTempFilter )
|
|
||||||
lpTempFilter+=sizeof(WCHAR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lpTempFilter+=sizeof(WCHAR);
|
|
||||||
lpTempFileName+=sizeof(WCHAR);
|
|
||||||
switch ( *lpTempFilter )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case L'\0':
|
|
||||||
case L' ':
|
|
||||||
case L',':
|
|
||||||
case L';':
|
|
||||||
if ( ! *lpTempFileName )
|
|
||||||
Matched = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case L'?':
|
|
||||||
lpTempFilter+=sizeof(WCHAR);
|
|
||||||
lpTempFileName+=sizeof(WCHAR);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case L'*':
|
|
||||||
lpTempFilter += sizeof(WCHAR);
|
|
||||||
if ( ! ( TempToken [ 0 ] = *( lpTempFilter ) ) )
|
|
||||||
Matched = TRUE;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lpTempFilter+=sizeof(WCHAR);
|
|
||||||
while ( ( lpTempFileName = wcspbrk ( lpTempFileName, TempToken ) ) &&
|
|
||||||
( ! Matched ) ) {
|
|
||||||
lpTempFileName+= sizeof(WCHAR);
|
|
||||||
Matched = mfs_regexp ( lpTempFileName, lpTempFilter );
|
|
||||||
}
|
|
||||||
if ( ( ! lpTempFileName ) && ( ! Matched ) )
|
|
||||||
{
|
|
||||||
lpTempFileName = (LPWSTR)lpFileName;
|
|
||||||
lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" );
|
|
||||||
if ( lpTempFilter )
|
|
||||||
lpTempFilter+=sizeof(WCHAR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case L'\0':
|
|
||||||
case L' ':
|
|
||||||
case L',':
|
|
||||||
case L';':
|
|
||||||
Matched = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (DWORD)Matched;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int wcharicmp ( WCHAR char1, WCHAR char2 )
|
|
||||||
{
|
|
||||||
WCHAR Char1 = ( L'a' <= char1 ) && ( char1 <= L'z' ) ?
|
|
||||||
char1 - L'a' + L'A' : char1;
|
|
||||||
WCHAR Char2 = ( L'a' <= char2 ) && ( char2 <= L'z' ) ?
|
|
||||||
char2 - L'a' + L'A' : char2;
|
|
||||||
return ( Char2 - Char1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
124
reactos/lib/kernel32/file/find1.c
Normal file
124
reactos/lib/kernel32/file/find1.c
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS system libraries
|
||||||
|
* FILE: lib/kernel32/file/find.c
|
||||||
|
* PURPOSE: Find functions
|
||||||
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||||
|
* UPDATE HISTORY:
|
||||||
|
* Created 01/11/98
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <wstring.h>
|
||||||
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
|
/* TYPES ********************************************************************/
|
||||||
|
|
||||||
|
typedef struct _KERNEL32_FIND_FILE_DATA;
|
||||||
|
{
|
||||||
|
HANDLE DirectoryHandle;
|
||||||
|
FILE_DIRECTORY_INFORMATION FileInfo;
|
||||||
|
} KERNEL32_FIND_FILE_DATA, *PKERNEL32_FIND_FILE_DATA;
|
||||||
|
|
||||||
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
|
HANDLE FindFirstFileA(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
|
||||||
|
{
|
||||||
|
WCHAR lpFileNameW[MAX_PATH];
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (lpFileName[i]!=0)
|
||||||
|
{
|
||||||
|
lpFileName[i] = lpFileName[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(FindFirstFileW(lpFileName,lpFindFileData));
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData)
|
||||||
|
{
|
||||||
|
return(FindNextFileW(hFindFile, lpFindFileData));
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL FindClose(HANDLE hFindFile)
|
||||||
|
{
|
||||||
|
PKERNEL32_FIND_FILE_DATA IData;
|
||||||
|
|
||||||
|
IData = (PKERNEL32_FIND_FILE_DATA)hFindFile;
|
||||||
|
NtClose(IData->DirectoryHandle);
|
||||||
|
HeapFree(IData);
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE STDCALL FindFirstFileW(LPCWSTR lpFileName,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData)
|
||||||
|
{
|
||||||
|
WCHAR CurrentDirectory[MAX_PATH];
|
||||||
|
WCHAR Pattern[MAX_PATH];
|
||||||
|
WCHAR Directory[MAX_PATH];
|
||||||
|
PWSTR End;
|
||||||
|
PKERNEL32_FIND_FILE_DATA IData;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
UNICODE_STRING DirectoryNameStr;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
|
||||||
|
dprintf("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n",
|
||||||
|
lpFileName, lpFindFileData);
|
||||||
|
|
||||||
|
GetCurrentDirectoryW(MAX_PATH, CurrentDirectory);
|
||||||
|
Directory[0] = '\\';
|
||||||
|
Directory[1] = '?';
|
||||||
|
Directory[2] = '?';
|
||||||
|
Directory[3] = '\\';
|
||||||
|
Directory[4] = 0;
|
||||||
|
wstrcat(Directory, CurrentDirectory);
|
||||||
|
wstrcat(Directory, lpFileName);
|
||||||
|
End = wstrchr(Directory, '\\');
|
||||||
|
*End = 0;
|
||||||
|
|
||||||
|
wstrcpy(Pattern, End+1);
|
||||||
|
|
||||||
|
dprintf("Directory %w End %w\n",Directory,End);
|
||||||
|
|
||||||
|
IData = HeapAlloc(GetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(KERNEL32_FIND_FILE_DATA));
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&DirectoryNameStr, Directory);
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&DirectoryNameStr,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (ZwOpenFile(&IData->DirectoryHandle,
|
||||||
|
FILE_TRAVERSE,
|
||||||
|
&ObjectAttributes,
|
||||||
|
0,
|
||||||
|
OPEN_EXISTING)!=STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
NtQueryDirectoryFile(IData->DirectoryHandle,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&IoStatusBlock,
|
||||||
|
&IData->FileInfo,
|
||||||
|
sizeof(IData->FileInfo),
|
||||||
|
FileDirectoryInformation,
|
||||||
|
TRUE,
|
||||||
|
Pattern,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
return(IData);
|
||||||
|
}
|
||||||
|
|
||||||
|
WINBOOL STDCALL FindNextFileW(HANDLE hFindFile,
|
||||||
|
LPWIN32_FIND_DATA lpFindFileData)
|
||||||
|
{
|
||||||
|
}
|
8
reactos/lib/kernel32/internal/init.c
Normal file
8
reactos/lib/kernel32/internal/init.c
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#include <windows.h>
|
||||||
|
#include <ddk/ntddk.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
VOID KERNEL32_Init(VOID)
|
||||||
|
{
|
||||||
|
__HeapInit(0, 4*1024*1024, 4*1024*1024);
|
||||||
|
}
|
|
@ -1,379 +0,0 @@
|
||||||
/*
|
|
||||||
* linux/lib/vsprintf.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
|
||||||
/*
|
|
||||||
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Appropiated for the reactos kernel, March 1998 -- David Welch
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include <internal/debug.h>
|
|
||||||
#include <internal/ctype.h>
|
|
||||||
#include <internal/string.h>
|
|
||||||
|
|
||||||
unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
|
|
||||||
{
|
|
||||||
unsigned long result = 0,value;
|
|
||||||
|
|
||||||
if (!base) {
|
|
||||||
base = 10;
|
|
||||||
if (*cp == '0') {
|
|
||||||
base = 8;
|
|
||||||
cp++;
|
|
||||||
if ((*cp == 'x') && isxdigit(cp[1])) {
|
|
||||||
cp++;
|
|
||||||
base = 16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
|
|
||||||
? toupper(*cp) : *cp)-'A'+10) < base) {
|
|
||||||
result = result*base + value;
|
|
||||||
cp++;
|
|
||||||
}
|
|
||||||
if (endp)
|
|
||||||
*endp = (char *)cp;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we use this so that we can do without the ctype library */
|
|
||||||
#define is_digit(c) ((c) >= '0' && (c) <= '9')
|
|
||||||
|
|
||||||
static int skip_atoi(const char **s)
|
|
||||||
{
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
while (is_digit(**s))
|
|
||||||
i = i*10 + *((*s)++) - '0';
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ZEROPAD 1 /* pad with zero */
|
|
||||||
#define SIGN 2 /* unsigned/signed long */
|
|
||||||
#define PLUS 4 /* show plus */
|
|
||||||
#define SPACE 8 /* space if plus */
|
|
||||||
#define LEFT 16 /* left justified */
|
|
||||||
#define SPECIAL 32 /* 0x */
|
|
||||||
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
|
|
||||||
|
|
||||||
#define do_div(n,base) ({ \
|
|
||||||
int __res; \
|
|
||||||
__res = ((unsigned long) n) % (unsigned) base; \
|
|
||||||
n = ((unsigned long) n) / (unsigned) base; \
|
|
||||||
__res; })
|
|
||||||
|
|
||||||
static char * number(char * str, long num, int base, int size, int precision
|
|
||||||
,int type)
|
|
||||||
{
|
|
||||||
char c,sign,tmp[66];
|
|
||||||
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (type & LARGE)
|
|
||||||
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
||||||
if (type & LEFT)
|
|
||||||
type &= ~ZEROPAD;
|
|
||||||
if (base < 2 || base > 36)
|
|
||||||
return 0;
|
|
||||||
c = (type & ZEROPAD) ? '0' : ' ';
|
|
||||||
sign = 0;
|
|
||||||
if (type & SIGN) {
|
|
||||||
if (num < 0) {
|
|
||||||
sign = '-';
|
|
||||||
num = -num;
|
|
||||||
size--;
|
|
||||||
} else if (type & PLUS) {
|
|
||||||
sign = '+';
|
|
||||||
size--;
|
|
||||||
} else if (type & SPACE) {
|
|
||||||
sign = ' ';
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (type & SPECIAL) {
|
|
||||||
if (base == 16)
|
|
||||||
size -= 2;
|
|
||||||
else if (base == 8)
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
if (num == 0)
|
|
||||||
tmp[i++]='0';
|
|
||||||
else while (num != 0)
|
|
||||||
tmp[i++] = digits[do_div(num,base)];
|
|
||||||
if (i > precision)
|
|
||||||
precision = i;
|
|
||||||
size -= precision;
|
|
||||||
if (!(type&(ZEROPAD+LEFT)))
|
|
||||||
while(size-->0)
|
|
||||||
*str++ = ' ';
|
|
||||||
if (sign)
|
|
||||||
*str++ = sign;
|
|
||||||
if (type & SPECIAL)
|
|
||||||
if (base==8)
|
|
||||||
*str++ = '0';
|
|
||||||
else if (base==16) {
|
|
||||||
*str++ = '0';
|
|
||||||
*str++ = digits[33];
|
|
||||||
}
|
|
||||||
if (!(type & LEFT))
|
|
||||||
while (size-- > 0)
|
|
||||||
*str++ = c;
|
|
||||||
while (i < precision--)
|
|
||||||
*str++ = '0';
|
|
||||||
while (i-- > 0)
|
|
||||||
*str++ = tmp[i];
|
|
||||||
while (size-- > 0)
|
|
||||||
*str++ = ' ';
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
int vsprintf(char *buf, const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
unsigned long num;
|
|
||||||
int i, base;
|
|
||||||
char * str;
|
|
||||||
const char *s;
|
|
||||||
const short int* sw;
|
|
||||||
|
|
||||||
int flags; /* flags to number() */
|
|
||||||
|
|
||||||
int field_width; /* width of output field */
|
|
||||||
int precision; /* min. # of digits for integers; max
|
|
||||||
number of chars for from string */
|
|
||||||
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
|
||||||
|
|
||||||
for (str=buf ; *fmt ; ++fmt) {
|
|
||||||
if (*fmt != '%') {
|
|
||||||
*str++ = *fmt;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* process flags */
|
|
||||||
flags = 0;
|
|
||||||
repeat:
|
|
||||||
++fmt; /* this also skips first '%' */
|
|
||||||
switch (*fmt) {
|
|
||||||
case '-': flags |= LEFT; goto repeat;
|
|
||||||
case '+': flags |= PLUS; goto repeat;
|
|
||||||
case ' ': flags |= SPACE; goto repeat;
|
|
||||||
case '#': flags |= SPECIAL; goto repeat;
|
|
||||||
case '0': flags |= ZEROPAD; goto repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get field width */
|
|
||||||
field_width = -1;
|
|
||||||
if (is_digit(*fmt))
|
|
||||||
field_width = skip_atoi(&fmt);
|
|
||||||
else if (*fmt == '*') {
|
|
||||||
++fmt;
|
|
||||||
/* it's the next argument */
|
|
||||||
field_width = va_arg(args, int);
|
|
||||||
if (field_width < 0) {
|
|
||||||
field_width = -field_width;
|
|
||||||
flags |= LEFT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the precision */
|
|
||||||
precision = -1;
|
|
||||||
if (*fmt == '.') {
|
|
||||||
++fmt;
|
|
||||||
if (is_digit(*fmt))
|
|
||||||
precision = skip_atoi(&fmt);
|
|
||||||
else if (*fmt == '*') {
|
|
||||||
++fmt;
|
|
||||||
/* it's the next argument */
|
|
||||||
precision = va_arg(args, int);
|
|
||||||
}
|
|
||||||
if (precision < 0)
|
|
||||||
precision = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the conversion qualifier */
|
|
||||||
qualifier = -1;
|
|
||||||
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
|
|
||||||
qualifier = *fmt;
|
|
||||||
++fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* default base */
|
|
||||||
base = 10;
|
|
||||||
|
|
||||||
switch (*fmt) {
|
|
||||||
case 'c':
|
|
||||||
if (!(flags & LEFT))
|
|
||||||
while (--field_width > 0)
|
|
||||||
*str++ = ' ';
|
|
||||||
*str++ = (unsigned char) va_arg(args, int);
|
|
||||||
while (--field_width > 0)
|
|
||||||
*str++ = ' ';
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
sw = va_arg(args,short int *);
|
|
||||||
// DPRINT("L %x\n",sw);
|
|
||||||
if (sw==NULL)
|
|
||||||
{
|
|
||||||
// CHECKPOINT;
|
|
||||||
s = "<NULL>";
|
|
||||||
while ((*s)!=0)
|
|
||||||
{
|
|
||||||
*str++ = *s++;
|
|
||||||
}
|
|
||||||
// CHECKPOINT;
|
|
||||||
// DbgPrint("str %x\n",str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while ((*sw)!=0)
|
|
||||||
{
|
|
||||||
*str++ = (char)(*sw++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// CHECKPOINT;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
s = va_arg(args, char *);
|
|
||||||
if (!s)
|
|
||||||
s = "<NULL>";
|
|
||||||
|
|
||||||
len = strnlen(s, precision);
|
|
||||||
|
|
||||||
if (!(flags & LEFT))
|
|
||||||
while (len < field_width--)
|
|
||||||
*str++ = ' ';
|
|
||||||
for (i = 0; i < len; ++i)
|
|
||||||
*str++ = *s++;
|
|
||||||
while (len < field_width--)
|
|
||||||
*str++ = ' ';
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case 'p':
|
|
||||||
if (field_width == -1) {
|
|
||||||
field_width = 2*sizeof(void *);
|
|
||||||
flags |= ZEROPAD;
|
|
||||||
}
|
|
||||||
str = number(str,
|
|
||||||
(unsigned long) va_arg(args, void *), 16,
|
|
||||||
field_width, precision, flags);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
|
||||||
case 'n':
|
|
||||||
if (qualifier == 'l') {
|
|
||||||
long * ip = va_arg(args, long *);
|
|
||||||
*ip = (str - buf);
|
|
||||||
} else {
|
|
||||||
int * ip = va_arg(args, int *);
|
|
||||||
*ip = (str - buf);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* integer number formats - set up the flags and "break" */
|
|
||||||
case 'o':
|
|
||||||
base = 8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'b':
|
|
||||||
base = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'X':
|
|
||||||
flags |= LARGE;
|
|
||||||
case 'x':
|
|
||||||
base = 16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'd':
|
|
||||||
case 'i':
|
|
||||||
flags |= SIGN;
|
|
||||||
case 'u':
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (*fmt != '%')
|
|
||||||
*str++ = '%';
|
|
||||||
if (*fmt)
|
|
||||||
*str++ = *fmt;
|
|
||||||
else
|
|
||||||
--fmt;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (qualifier == 'l')
|
|
||||||
num = va_arg(args, unsigned long);
|
|
||||||
else if (qualifier == 'h')
|
|
||||||
if (flags & SIGN)
|
|
||||||
num = va_arg(args, short);
|
|
||||||
else
|
|
||||||
num = va_arg(args, unsigned short);
|
|
||||||
else if (flags & SIGN)
|
|
||||||
num = va_arg(args, int);
|
|
||||||
else
|
|
||||||
num = va_arg(args, unsigned int);
|
|
||||||
str = number(str, num, base, field_width, precision, flags);
|
|
||||||
}
|
|
||||||
*str = '\0';
|
|
||||||
return str-buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sprintf(char * buf, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
i=vsprintf(buf,fmt,args);
|
|
||||||
va_end(args);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wsprintfA(char * buf, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
i=vsprintf(buf,fmt,args);
|
|
||||||
va_end(args);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wsprintfW(unsigned short * buf, const unsigned short *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
//i=vsprintf(buf,fmt,args);
|
|
||||||
va_end(args);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned short towupper(unsigned short w)
|
|
||||||
{
|
|
||||||
if ( w < L'A' )
|
|
||||||
return w + 'A';
|
|
||||||
else
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
char iswlower(unsigned short w)
|
|
||||||
{
|
|
||||||
if ( w < L'A' )
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,17 +6,17 @@ MISC_OBJECTS = misc/error.o misc/atom.o misc/handle.o misc/env.o misc/dllmain.o
|
||||||
|
|
||||||
FILE_OBJECTS = file/file.o file/curdir.o file/lfile.o file/dir.o \
|
FILE_OBJECTS = file/file.o file/curdir.o file/lfile.o file/dir.o \
|
||||||
file/iocompl.o file/volume.o file/deviceio.o file/dosdev.o \
|
file/iocompl.o file/volume.o file/deviceio.o file/dosdev.o \
|
||||||
file/create.o
|
file/create.o file/find.o file/cnotify.o
|
||||||
|
|
||||||
MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o
|
MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o
|
||||||
|
|
||||||
THREAD_OBJECTS = thread/thread.o
|
THREAD_OBJECTS = thread/thread.o
|
||||||
|
|
||||||
PROCESS_OBJECTS = process/proc.o
|
PROCESS_OBJECTS = process/proc.o process/cmdline.o
|
||||||
|
|
||||||
STRING_OBJECTS = string/lstring.o
|
STRING_OBJECTS = string/lstring.o
|
||||||
|
|
||||||
INTERNAL_OBJECTS = internal/dprintf.o
|
INTERNAL_OBJECTS = internal/dprintf.o internal/init.o
|
||||||
|
|
||||||
EXCEPT_OBJECTS = except/except.o
|
EXCEPT_OBJECTS = except/except.o
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ OBJECTS = $(MISC_OBJECTS) $(FILE_OBJECTS) $(THREAD_OBJECTS) \
|
||||||
|
|
||||||
|
|
||||||
kernel32.a: $(OBJECTS)
|
kernel32.a: $(OBJECTS)
|
||||||
$(AR) vrcs kernel32.a $(OBJECTS)
|
$(AR) rcs kernel32.a $(OBJECTS)
|
||||||
|
|
||||||
dummy:
|
dummy:
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ static HEAP_BUCKET __HeapDefaultBuckets[]=
|
||||||
{ NULL, 256, 15, 4088 },
|
{ NULL, 256, 15, 4088 },
|
||||||
};
|
};
|
||||||
|
|
||||||
PHEAP __ProcessHeap;
|
PHEAP __ProcessHeap = NULL;
|
||||||
|
|
||||||
static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end);
|
static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end);
|
||||||
static BOOL __HeapDecommit(PHEAP pheap, LPVOID start, LPVOID end);
|
static BOOL __HeapDecommit(PHEAP pheap, LPVOID start, LPVOID end);
|
||||||
|
@ -61,8 +61,6 @@ static BOOL __HeapFreeFragment(PHEAP pheap, ULONG flags, LPVOID ptr);
|
||||||
static PHEAP __HeapPrepare(LPVOID base, ULONG minsize, ULONG maxsize,
|
static PHEAP __HeapPrepare(LPVOID base, ULONG minsize, ULONG maxsize,
|
||||||
ULONG flags);
|
ULONG flags);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* __HeapCommit *
|
* __HeapCommit *
|
||||||
* *
|
* *
|
||||||
|
@ -625,7 +623,7 @@ PHEAP __HeapPrepare(LPVOID base, ULONG minsize, ULONG maxsize, ULONG flags)
|
||||||
|
|
||||||
VOID WINAPI __HeapInit(LPVOID base, ULONG minsize, ULONG maxsize)
|
VOID WINAPI __HeapInit(LPVOID base, ULONG minsize, ULONG maxsize)
|
||||||
{
|
{
|
||||||
VirtualAlloc(base,maxsize,MEM_RESERVE,PAGE_READWRITE);
|
base = VirtualAlloc(base,maxsize,MEM_RESERVE,PAGE_READWRITE);
|
||||||
VirtualAlloc(base,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);
|
VirtualAlloc(base,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);
|
||||||
|
|
||||||
__HeapPrepare(base, minsize, maxsize, 0);
|
__HeapPrepare(base, minsize, maxsize, 0);
|
||||||
|
|
47
reactos/lib/kernel32/process/cmdline.c
Normal file
47
reactos/lib/kernel32/process/cmdline.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
|
* PROJECT: ReactOS system libraries
|
||||||
|
* FILE: lib/kernel32/proc/proc.c
|
||||||
|
* PURPOSE: Process functions
|
||||||
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||||
|
* UPDATE HISTORY:
|
||||||
|
* Created 01/11/98
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES ****************************************************************/
|
||||||
|
|
||||||
|
#define UNICODE
|
||||||
|
#include <windows.h>
|
||||||
|
#include <kernel32/proc.h>
|
||||||
|
#include <kernel32/thread.h>
|
||||||
|
#include <wstring.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ddk/rtl.h>
|
||||||
|
#include <ddk/li.h>
|
||||||
|
|
||||||
|
/* GLOBALS ******************************************************************/
|
||||||
|
|
||||||
|
unsigned char CommandLineA[MAX_PATH];
|
||||||
|
|
||||||
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
|
LPSTR STDCALL GetCommandLineA(VOID)
|
||||||
|
{
|
||||||
|
WCHAR *CommandLineW;
|
||||||
|
ULONG i = 0;
|
||||||
|
|
||||||
|
CommandLineW = GetCommandLineW();
|
||||||
|
while ((CommandLineW[i])!=0 && i < MAX_PATH)
|
||||||
|
{
|
||||||
|
CommandLineA[i] = (unsigned char)CommandLineW[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
CommandLineA[i] = 0;
|
||||||
|
return CommandLineA;
|
||||||
|
}
|
||||||
|
|
||||||
|
LPWSTR STDCALL GetCommandLineW(VOID)
|
||||||
|
{
|
||||||
|
return GetCurrentPeb()->StartupInfo->CommandLine;
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
* Created 01/11/98
|
* Created 01/11/98
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* INCLUDES ****************************************************************/
|
||||||
|
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <kernel32/proc.h>
|
#include <kernel32/proc.h>
|
||||||
|
@ -16,6 +19,8 @@
|
||||||
#include <ddk/rtl.h>
|
#include <ddk/rtl.h>
|
||||||
#include <ddk/li.h>
|
#include <ddk/li.h>
|
||||||
|
|
||||||
|
/* GLOBALS *****************************************************************/
|
||||||
|
|
||||||
extern NT_PEB *CurrentPeb;
|
extern NT_PEB *CurrentPeb;
|
||||||
extern NT_PEB Peb;
|
extern NT_PEB Peb;
|
||||||
|
|
||||||
|
@ -23,10 +28,9 @@ WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
|
||||||
|
|
||||||
VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle);
|
VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle);
|
||||||
|
|
||||||
WINBOOL
|
/* FUNCTIONS ****************************************************************/
|
||||||
STDCALL
|
|
||||||
GetProcessId(HANDLE hProcess, LPDWORD lpProcessId );
|
|
||||||
|
|
||||||
|
WINBOOL STDCALL GetProcessId(HANDLE hProcess, LPDWORD lpProcessId);
|
||||||
|
|
||||||
NT_PEB *GetCurrentPeb(VOID)
|
NT_PEB *GetCurrentPeb(VOID)
|
||||||
{
|
{
|
||||||
|
@ -46,304 +50,334 @@ HANDLE STDCALL GetCurrentThread(VOID)
|
||||||
return (HANDLE)NtCurrentThread();
|
return (HANDLE)NtCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD
|
DWORD STDCALL GetCurrentProcessId(VOID)
|
||||||
STDCALL
|
|
||||||
GetCurrentProcessId(VOID)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return (DWORD)(GetTeb()->Cid).UniqueProcess;
|
return (DWORD)(GetTeb()->Cid).UniqueProcess;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char CommandLineA[MAX_PATH];
|
WINBOOL STDCALL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode )
|
||||||
|
|
||||||
LPSTR
|
|
||||||
STDCALL
|
|
||||||
GetCommandLineA(
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
WCHAR *CommandLineW;
|
NTSTATUS errCode;
|
||||||
ULONG i = 0;
|
PROCESS_BASIC_INFORMATION ProcessBasic;
|
||||||
|
ULONG BytesWritten;
|
||||||
|
|
||||||
CommandLineW = GetCommandLineW();
|
errCode = NtQueryInformationProcess(hProcess,
|
||||||
while ((CommandLineW[i])!=0 && i < MAX_PATH)
|
ProcessBasicInformation,
|
||||||
{
|
&ProcessBasic,
|
||||||
CommandLineA[i] = (unsigned char)CommandLineW[i];
|
sizeof(PROCESS_BASIC_INFORMATION),
|
||||||
i++;
|
&BytesWritten);
|
||||||
}
|
if (!NT_SUCCESS(errCode))
|
||||||
CommandLineA[i] = 0;
|
{
|
||||||
return CommandLineA;
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
}
|
return FALSE;
|
||||||
LPWSTR
|
}
|
||||||
STDCALL
|
memcpy( lpExitCode ,&ProcessBasic.ExitStatus,sizeof(DWORD));
|
||||||
GetCommandLineW(
|
return TRUE;
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GetCurrentPeb()->StartupInfo->CommandLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WINBOOL STDCALL GetProcessId(HANDLE hProcess, LPDWORD lpProcessId )
|
||||||
WINBOOL
|
|
||||||
STDCALL
|
|
||||||
GetExitCodeProcess(
|
|
||||||
HANDLE hProcess,
|
|
||||||
LPDWORD lpExitCode
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
NTSTATUS errCode;
|
NTSTATUS errCode;
|
||||||
PROCESS_BASIC_INFORMATION ProcessBasic;
|
PROCESS_BASIC_INFORMATION ProcessBasic;
|
||||||
ULONG BytesWritten;
|
ULONG BytesWritten;
|
||||||
|
|
||||||
errCode = NtQueryInformationProcess(hProcess,ProcessBasicInformation,&ProcessBasic,sizeof(PROCESS_BASIC_INFORMATION),&BytesWritten);
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
memcpy( lpExitCode ,&ProcessBasic.ExitStatus,sizeof(DWORD));
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
|
errCode = NtQueryInformationProcess(hProcess,
|
||||||
|
ProcessBasicInformation,
|
||||||
|
&ProcessBasic,
|
||||||
|
sizeof(PROCESS_BASIC_INFORMATION),
|
||||||
|
&BytesWritten);
|
||||||
|
if (!NT_SUCCESS(errCode))
|
||||||
|
{
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
memcpy( lpProcessId ,&ProcessBasic.UniqueProcessId,sizeof(DWORD));
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
WINBOOL
|
PWSTR InternalAnsiToUnicode(PWSTR Out, LPCSTR In, ULONG MaxLength)
|
||||||
STDCALL
|
|
||||||
GetProcessId(
|
|
||||||
HANDLE hProcess,
|
|
||||||
LPDWORD lpProcessId
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
NTSTATUS errCode;
|
ULONG i;
|
||||||
PROCESS_BASIC_INFORMATION ProcessBasic;
|
|
||||||
ULONG BytesWritten;
|
|
||||||
|
|
||||||
errCode = NtQueryInformationProcess(hProcess,ProcessBasicInformation,&ProcessBasic,sizeof(PROCESS_BASIC_INFORMATION),&BytesWritten);
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
memcpy( lpProcessId ,&ProcessBasic.UniqueProcessId,sizeof(DWORD));
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WINBOOL
|
|
||||||
STDCALL
|
|
||||||
CreateProcessA(
|
|
||||||
LPCSTR lpApplicationName,
|
|
||||||
LPSTR lpCommandLine,
|
|
||||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|
||||||
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
||||||
WINBOOL bInheritHandles,
|
|
||||||
DWORD dwCreationFlags,
|
|
||||||
LPVOID lpEnvironment,
|
|
||||||
LPCSTR lpCurrentDirectory,
|
|
||||||
LPSTARTUPINFO lpStartupInfo,
|
|
||||||
LPPROCESS_INFORMATION lpProcessInformation
|
|
||||||
)
|
|
||||||
{
|
|
||||||
WCHAR ApplicationNameW[MAX_PATH];
|
|
||||||
WCHAR CommandLineW[MAX_PATH];
|
|
||||||
WCHAR CurrentDirectoryW[MAX_PATH];
|
|
||||||
|
|
||||||
|
|
||||||
ULONG i;
|
|
||||||
|
|
||||||
|
if (In == NULL)
|
||||||
|
{
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((*lpApplicationName)!=0 && i < MAX_PATH)
|
while ((*In)!=0 && i < MaxLength)
|
||||||
{
|
{
|
||||||
ApplicationNameW[i] = *lpApplicationName;
|
Out[i] = *In;
|
||||||
lpApplicationName++;
|
In++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
ApplicationNameW[i] = 0;
|
Out[i] = 0;
|
||||||
|
return(Out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
|
||||||
|
LPSTR lpCommandLine,
|
||||||
|
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||||
|
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||||
|
WINBOOL bInheritHandles,
|
||||||
|
DWORD dwCreationFlags,
|
||||||
|
LPVOID lpEnvironment,
|
||||||
|
LPCSTR lpCurrentDirectory,
|
||||||
|
LPSTARTUPINFO lpStartupInfo,
|
||||||
|
LPPROCESS_INFORMATION lpProcessInformation)
|
||||||
|
/*
|
||||||
|
* FUNCTION: The CreateProcess function creates a new process and its
|
||||||
|
* primary thread. The new process executes the specified executable file
|
||||||
|
* ARGUMENTS:
|
||||||
|
*
|
||||||
|
* lpApplicationName = Pointer to name of executable module
|
||||||
|
* lpCommandLine = Pointer to command line string
|
||||||
|
* lpProcessAttributes = Process security attributes
|
||||||
|
* lpThreadAttributes = Thread security attributes
|
||||||
|
* bInheritHandles = Handle inheritance flag
|
||||||
|
* dwCreationFlags = Creation flags
|
||||||
|
* lpEnvironment = Pointer to new environment block
|
||||||
|
* lpCurrentDirectory = Pointer to current directory name
|
||||||
|
* lpStartupInfo = Pointer to startup info
|
||||||
|
* lpProcessInformation = Pointer to process information
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
WCHAR ApplicationNameW[MAX_PATH];
|
||||||
|
WCHAR CommandLineW[MAX_PATH];
|
||||||
|
WCHAR CurrentDirectoryW[MAX_PATH];
|
||||||
|
PWSTR PApplicationNameW;
|
||||||
|
PWSTR PCommandLineW;
|
||||||
|
PWSTR PCurrentDirectoryW;
|
||||||
|
ULONG i;
|
||||||
|
|
||||||
i = 0;
|
OutputDebugStringA("CreateProcessA\n");
|
||||||
while ((*lpCommandLine)!=0 && i < MAX_PATH)
|
|
||||||
{
|
|
||||||
CommandLineW[i] = *lpCommandLine;
|
|
||||||
lpCommandLine++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
CommandLineW[i] = 0;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((*lpCurrentDirectory)!=0 && i < MAX_PATH)
|
|
||||||
{
|
|
||||||
CurrentDirectoryW[i] = *lpCurrentDirectory;
|
|
||||||
lpCurrentDirectory++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
CurrentDirectoryW[i] = 0;
|
|
||||||
|
|
||||||
return CreateProcessW(ApplicationNameW,CommandLineW, lpProcessAttributes,lpThreadAttributes,
|
|
||||||
bInheritHandles,dwCreationFlags,lpEnvironment,CurrentDirectoryW,lpStartupInfo,
|
|
||||||
lpProcessInformation);
|
|
||||||
|
|
||||||
|
|
||||||
|
PApplicationNameW = InternalAnsiToUnicode(ApplicationNameW,
|
||||||
|
lpApplicationName,
|
||||||
|
MAX_PATH);
|
||||||
|
PCommandLineW = InternalAnsiToUnicode(CommandLineW,
|
||||||
|
lpCommandLine,
|
||||||
|
MAX_PATH);
|
||||||
|
PCurrentDirectoryW = InternalAnsiToUnicode(CurrentDirectoryW,
|
||||||
|
lpCurrentDirectory,
|
||||||
|
MAX_PATH);
|
||||||
|
return CreateProcessW(PApplicationNameW,
|
||||||
|
PCommandLineW,
|
||||||
|
lpProcessAttributes,
|
||||||
|
lpThreadAttributes,
|
||||||
|
bInheritHandles,
|
||||||
|
dwCreationFlags,
|
||||||
|
lpEnvironment,
|
||||||
|
PCurrentDirectoryW,
|
||||||
|
lpStartupInfo,
|
||||||
|
lpProcessInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WINBOOL
|
WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
|
||||||
STDCALL
|
LPWSTR lpCommandLine,
|
||||||
CreateProcessW(
|
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||||
LPCWSTR lpApplicationName,
|
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||||
LPWSTR lpCommandLine,
|
WINBOOL bInheritHandles,
|
||||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
DWORD dwCreationFlags,
|
||||||
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
LPVOID lpEnvironment,
|
||||||
WINBOOL bInheritHandles,
|
LPCWSTR lpCurrentDirectory,
|
||||||
DWORD dwCreationFlags,
|
LPSTARTUPINFO lpStartupInfo,
|
||||||
LPVOID lpEnvironment,
|
LPPROCESS_INFORMATION lpProcessInformation)
|
||||||
LPCWSTR lpCurrentDirectory,
|
|
||||||
LPSTARTUPINFO lpStartupInfo,
|
|
||||||
LPPROCESS_INFORMATION lpProcessInformation
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
HANDLE hFile, hSection, hProcess, hThread;
|
HANDLE hFile, hSection, hProcess, hThread;
|
||||||
KPRIORITY PriorityClass;
|
KPRIORITY PriorityClass;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
BOOLEAN CreateSuspended;
|
BOOLEAN CreateSuspended;
|
||||||
|
NTSTATUS errCode;
|
||||||
|
UNICODE_STRING ApplicationNameString;
|
||||||
|
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
|
||||||
|
LPVOID lpParameter = NULL;
|
||||||
|
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
|
||||||
|
WCHAR TempApplicationName[255];
|
||||||
|
WCHAR TempFileName[255];
|
||||||
|
WCHAR TempDirectoryName[255];
|
||||||
|
ULONG i;
|
||||||
|
ULONG BaseAddress;
|
||||||
|
ULONG Size;
|
||||||
|
LARGE_INTEGER SectionOffset;
|
||||||
|
|
||||||
NTSTATUS errCode;
|
dprintf("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n",
|
||||||
|
lpApplicationName,lpCommandLine);
|
||||||
|
|
||||||
UNICODE_STRING ApplicationNameString;
|
hFile = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the application name
|
||||||
|
*/
|
||||||
|
TempApplicationName[0] = '\\';
|
||||||
|
TempApplicationName[1] = '?';
|
||||||
|
TempApplicationName[2] = '?';
|
||||||
|
TempApplicationName[3] = '\\';
|
||||||
|
TempApplicationName[4] = 0;
|
||||||
|
|
||||||
|
dprintf("TempApplicationName '%w'\n",TempApplicationName);
|
||||||
|
|
||||||
|
if (lpApplicationName != NULL)
|
||||||
|
{
|
||||||
|
wcscpy(TempFileName, lpApplicationName);
|
||||||
|
|
||||||
|
dprintf("TempFileName '%w'\n",TempFileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wcscpy(TempFileName, lpCommandLine);
|
||||||
|
|
||||||
|
dprintf("TempFileName '%w'\n",TempFileName);
|
||||||
|
|
||||||
|
for (i=0; TempFileName[i]!=' ' && TempFileName[i] != 0; i++);
|
||||||
|
TempFileName[i]=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (TempFileName[1] != ':')
|
||||||
|
{
|
||||||
|
GetCurrentDirectoryW(MAX_PATH,TempDirectoryName);
|
||||||
|
wcscat(TempApplicationName,TempDirectoryName);
|
||||||
|
}
|
||||||
|
wcscat(TempApplicationName,TempFileName);
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&ApplicationNameString, TempApplicationName);
|
||||||
|
|
||||||
|
dprintf("ApplicationName %w\n",ApplicationNameString.Buffer);
|
||||||
|
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&ApplicationNameString,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL,
|
||||||
|
SecurityDescriptor);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to open the executable
|
||||||
|
*/
|
||||||
|
|
||||||
|
errCode = NtOpenFile(&hFile,
|
||||||
|
SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FILE_SHARE_DELETE|FILE_SHARE_READ,
|
||||||
|
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
|
||||||
|
|
||||||
|
if ( !NT_SUCCESS(errCode) )
|
||||||
|
{
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCode = NtCreateSection(&hSection,
|
||||||
|
SECTION_ALL_ACCESS,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
PAGE_EXECUTE,
|
||||||
|
SEC_IMAGE,
|
||||||
|
hFile);
|
||||||
|
NtClose(hFile);
|
||||||
|
|
||||||
|
if ( !NT_SUCCESS(errCode) )
|
||||||
|
{
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCode = NtCreateProcess(&hProcess,
|
||||||
|
PROCESS_ALL_ACCESS,
|
||||||
|
NULL,
|
||||||
|
NtCurrentProcess(),
|
||||||
|
bInheritHandles,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
BaseAddress = (PVOID)0x10000;
|
||||||
|
LARGE_INTEGER_QUAD_PART(SectionOffset) = 0;
|
||||||
|
Size = 0x10000;
|
||||||
|
NtMapViewOfSection(hSection,
|
||||||
|
hProcess,
|
||||||
|
&BaseAddress,
|
||||||
|
0,
|
||||||
|
Size,
|
||||||
|
&SectionOffset,
|
||||||
|
&Size,
|
||||||
|
0,
|
||||||
|
MEM_COMMIT,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
|
||||||
|
|
||||||
|
NtClose(hSection);
|
||||||
|
|
||||||
|
if ( !NT_SUCCESS(errCode) )
|
||||||
|
{
|
||||||
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
PriorityClass = NORMAL_PRIORITY_CLASS;
|
||||||
|
NtSetInformationProcess(hProcess,
|
||||||
|
ProcessBasePriority,
|
||||||
|
&PriorityClass,
|
||||||
|
sizeof(KPRIORITY));
|
||||||
|
#endif
|
||||||
|
dprintf("Creating thread for process\n");
|
||||||
|
lpStartAddress = BaseAddress;
|
||||||
|
hThread = CreateRemoteThread(hProcess,
|
||||||
|
lpThreadAttributes,
|
||||||
|
4096, // 1 page ??
|
||||||
|
lpStartAddress,
|
||||||
|
lpParameter,
|
||||||
|
dwCreationFlags,
|
||||||
|
&lpProcessInformation->dwThreadId);
|
||||||
|
|
||||||
|
if ( hThread == NULL )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
lpProcessInformation->hProcess = hProcess;
|
||||||
|
lpProcessInformation->hThread = hThread;
|
||||||
|
|
||||||
|
GetProcessId(hProcess,&lpProcessInformation->dwProcessId);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
|
HANDLE STDCALL OpenProcess(DWORD dwDesiredAccess,
|
||||||
LPVOID lpParameter = NULL;
|
WINBOOL bInheritHandle,
|
||||||
|
DWORD dwProcessId)
|
||||||
hFile = NULL;
|
|
||||||
|
|
||||||
ApplicationNameString.Length = lstrlenW(lpApplicationName)*sizeof(WCHAR);
|
|
||||||
|
|
||||||
ApplicationNameString.Buffer = (WCHAR *)lpApplicationName;
|
|
||||||
ApplicationNameString.MaximumLength = ApplicationNameString.Length;
|
|
||||||
|
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( lpProcessAttributes != NULL ) {
|
|
||||||
if ( lpProcessAttributes->bInheritHandle )
|
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
|
||||||
else
|
|
||||||
ObjectAttributes.Attributes = 0;
|
|
||||||
ObjectAttributes.SecurityDescriptor = lpProcessAttributes->lpSecurityDescriptor;
|
|
||||||
}
|
|
||||||
ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
|
|
||||||
|
|
||||||
errCode = NtOpenFile(&hFile,(SYNCHRONIZE|FILE_EXECUTE), &ObjectAttributes,
|
|
||||||
&IoStatusBlock,(FILE_SHARE_DELETE|FILE_SHARE_READ),(FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE));
|
|
||||||
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
errCode = NtCreateSection(&hSection,SECTION_ALL_ACCESS,NULL,NULL,PAGE_EXECUTE,SEC_IMAGE,hFile);
|
|
||||||
NtClose(hFile);
|
|
||||||
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( lpProcessAttributes != NULL ) {
|
|
||||||
if ( lpProcessAttributes->bInheritHandle )
|
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
|
||||||
else
|
|
||||||
ObjectAttributes.Attributes = 0;
|
|
||||||
ObjectAttributes.SecurityDescriptor = lpProcessAttributes->lpSecurityDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
errCode = NtCreateProcess(&hProcess,PROCESS_ALL_ACCESS, &ObjectAttributes,NtCurrentProcess(),bInheritHandles,hSection,NULL,NULL);
|
|
||||||
NtClose(hSection);
|
|
||||||
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PriorityClass = NORMAL_PRIORITY_CLASS;
|
|
||||||
NtSetInformationProcess(hProcess,ProcessBasePriority,&PriorityClass,sizeof(KPRIORITY));
|
|
||||||
|
|
||||||
if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED)
|
|
||||||
CreateSuspended = TRUE;
|
|
||||||
else
|
|
||||||
CreateSuspended = FALSE;
|
|
||||||
|
|
||||||
hThread = CreateRemoteThread(
|
|
||||||
hProcess,
|
|
||||||
lpThreadAttributes,
|
|
||||||
4096, // 1 page ??
|
|
||||||
lpStartAddress,
|
|
||||||
lpParameter,
|
|
||||||
CREATE_SUSPENDED,
|
|
||||||
&lpProcessInformation->dwThreadId
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if ( hThread == NULL )
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lpProcessInformation->hProcess = hProcess;
|
|
||||||
lpProcessInformation->hThread = hThread;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GetProcessId(hProcess,&lpProcessInformation->dwProcessId);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HANDLE
|
|
||||||
STDCALL
|
|
||||||
OpenProcess(
|
|
||||||
DWORD dwDesiredAccess,
|
|
||||||
WINBOOL bInheritHandle,
|
|
||||||
DWORD dwProcessId
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
NTSTATUS errCode;
|
||||||
|
HANDLE ProcessHandle;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
CLIENT_ID ClientId ;
|
||||||
|
|
||||||
|
ClientId.UniqueProcess = (HANDLE)dwProcessId;
|
||||||
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
|
ObjectAttributes.RootDirectory = (HANDLE)NULL;
|
||||||
|
ObjectAttributes.SecurityDescriptor = NULL;
|
||||||
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
NTSTATUS errCode;
|
if ( bInheritHandle == TRUE )
|
||||||
HANDLE ProcessHandle;
|
ObjectAttributes.Attributes = OBJ_INHERIT;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
else
|
||||||
CLIENT_ID ClientId ;
|
ObjectAttributes.Attributes = 0;
|
||||||
|
|
||||||
ClientId.UniqueProcess = (HANDLE)dwProcessId;
|
errCode = NtOpenProcess(&ProcessHandle,
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
dwDesiredAccess,
|
||||||
ObjectAttributes.RootDirectory = (HANDLE)NULL;
|
&ObjectAttributes,
|
||||||
ObjectAttributes.SecurityDescriptor = NULL;
|
&ClientId);
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
if (!NT_SUCCESS(errCode))
|
||||||
|
{
|
||||||
if ( bInheritHandle == TRUE )
|
SetLastError(RtlNtStatusToDosError(errCode));
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
return NULL;
|
||||||
else
|
}
|
||||||
ObjectAttributes.Attributes = 0;
|
return ProcessHandle;
|
||||||
|
|
||||||
errCode = NtOpenProcess ( &ProcessHandle, dwDesiredAccess, &ObjectAttributes, &ClientId);
|
|
||||||
if ( !NT_SUCCESS(errCode) ) {
|
|
||||||
SetLastError(RtlNtStatusToDosError(errCode));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return ProcessHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <kernel32/thread.h>
|
#include <kernel32/thread.h>
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <internal/i386/segment.h>
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
STDCALL
|
STDCALL
|
||||||
|
@ -45,47 +45,64 @@ CreateRemoteThread(
|
||||||
LPDWORD lpThreadId
|
LPDWORD lpThreadId
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
NTSTATUS errCode;
|
NTSTATUS errCode;
|
||||||
HANDLE ThreadHandle;
|
HANDLE ThreadHandle;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
CLIENT_ID ClientId;
|
CLIENT_ID ClientId;
|
||||||
CONTEXT ThreadContext;
|
CONTEXT ThreadContext;
|
||||||
INITIAL_TEB InitialTeb;
|
INITIAL_TEB InitialTeb;
|
||||||
BOOLEAN CreateSuspended = FALSE;
|
BOOLEAN CreateSuspended = FALSE;
|
||||||
|
ULONG BaseAddress;
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
ObjectAttributes.ObjectName = NULL;
|
ObjectAttributes.ObjectName = NULL;
|
||||||
ObjectAttributes.Attributes = 0;
|
ObjectAttributes.Attributes = 0;
|
||||||
if ( lpThreadAttributes != NULL ) {
|
if ( lpThreadAttributes != NULL ) {
|
||||||
if ( lpThreadAttributes->bInheritHandle )
|
if ( lpThreadAttributes->bInheritHandle )
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
ObjectAttributes.Attributes = OBJ_INHERIT;
|
||||||
ObjectAttributes.SecurityDescriptor = lpThreadAttributes->lpSecurityDescriptor;
|
ObjectAttributes.SecurityDescriptor = lpThreadAttributes->lpSecurityDescriptor;
|
||||||
}
|
}
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED )
|
if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED )
|
||||||
CreateSuspended = TRUE;
|
CreateSuspended = TRUE;
|
||||||
else
|
else
|
||||||
CreateSuspended = FALSE;
|
CreateSuspended = FALSE;
|
||||||
// fix context
|
|
||||||
GetThreadContext(NtCurrentThread(),&ThreadContext);
|
|
||||||
// fix teb [ stack context ] --> check the image file
|
|
||||||
|
|
||||||
errCode = NtCreateThread(
|
BaseAddress = 0;
|
||||||
&ThreadHandle,
|
ZwAllocateVirtualMemory(hProcess,
|
||||||
THREAD_ALL_ACCESS,
|
&BaseAddress,
|
||||||
&ObjectAttributes,
|
0,
|
||||||
hProcess,
|
&dwStackSize,
|
||||||
&ClientId,
|
MEM_COMMIT,
|
||||||
&ThreadContext,
|
PAGE_READWRITE);
|
||||||
&InitialTeb,
|
|
||||||
CreateSuspended
|
|
||||||
);
|
|
||||||
if ( lpThreadId != NULL )
|
|
||||||
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
|
||||||
|
|
||||||
return ThreadHandle;
|
|
||||||
|
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||||
|
ThreadContext.Eip = lpStartAddress;
|
||||||
|
ThreadContext.SegGs = USER_DS;
|
||||||
|
ThreadContext.SegFs = USER_DS;
|
||||||
|
ThreadContext.SegEs = USER_DS;
|
||||||
|
ThreadContext.SegDs = USER_DS;
|
||||||
|
ThreadContext.SegCs = USER_CS;
|
||||||
|
ThreadContext.SegSs = USER_DS;
|
||||||
|
ThreadContext.Esp = BaseAddress + dwStackSize;
|
||||||
|
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||||
|
|
||||||
|
|
||||||
|
errCode = NtCreateThread(&ThreadHandle,
|
||||||
|
THREAD_ALL_ACCESS,
|
||||||
|
&ObjectAttributes,
|
||||||
|
hProcess,
|
||||||
|
&ClientId,
|
||||||
|
&ThreadContext,
|
||||||
|
&InitialTeb,
|
||||||
|
CreateSuspended);
|
||||||
|
if ( lpThreadId != NULL )
|
||||||
|
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
||||||
|
|
||||||
|
return ThreadHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
NT_TEB *GetTeb(VOID)
|
NT_TEB *GetTeb(VOID)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
all: ntdll.a
|
all: ntdll.a
|
||||||
|
|
||||||
OBJECTS = napi.o stubs/stubs.o string/wstring.o stdio/vsprintf.o
|
OBJECTS = napi.o stubs/stubs.o string/wstring.o stdio/vsprintf.o \
|
||||||
|
rtl/unicode.o rtl/namespc.o
|
||||||
|
|
||||||
ntdll.a: $(OBJECTS)
|
ntdll.a: $(OBJECTS)
|
||||||
$(AR) vcsr ntdll.a $(OBJECTS)
|
$(AR) vcsr ntdll.a $(OBJECTS)
|
||||||
|
|
|
@ -71,6 +71,7 @@ wchar_t* wcscpy(wchar_t* str1, const wchar_t* str2)
|
||||||
s++;
|
s++;
|
||||||
str2++;
|
str2++;
|
||||||
}
|
}
|
||||||
|
*s = 0;
|
||||||
return(str1);
|
return(str1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#define STUB(x) void x(void) { NtDisplayString("NTDLL: Stub for "#x); }
|
#define STUB(x) void x(void) { NtDisplayString("NTDLL: Stub for "#x"\n"); }
|
||||||
|
|
||||||
// ?Allocate@CBufferAllocator@@UAEPAXK@Z
|
// ?Allocate@CBufferAllocator@@UAEPAXK@Z
|
||||||
STUB(PropertyLengthAsVariant)
|
STUB(PropertyLengthAsVariant)
|
||||||
|
@ -78,12 +78,8 @@ STUB(RtlAllocateAndInitializeSid)
|
||||||
STUB(RtlAllocateHandle)
|
STUB(RtlAllocateHandle)
|
||||||
STUB(RtlAllocateHeap)
|
STUB(RtlAllocateHeap)
|
||||||
STUB(RtlAnsiCharToUnicodeChar)
|
STUB(RtlAnsiCharToUnicodeChar)
|
||||||
STUB(RtlAnsiStringToUnicodeSize)
|
|
||||||
STUB(RtlAnsiStringToUnicodeString)
|
|
||||||
STUB(RtlAppendAsciizToString)
|
STUB(RtlAppendAsciizToString)
|
||||||
STUB(RtlAppendStringToString)
|
STUB(RtlAppendStringToString)
|
||||||
STUB(RtlAppendUnicodeStringToString)
|
|
||||||
STUB(RtlAppendUnicodeToString)
|
|
||||||
STUB(RtlApplyRXact)
|
STUB(RtlApplyRXact)
|
||||||
STUB(RtlApplyRXactNoFlush)
|
STUB(RtlApplyRXactNoFlush)
|
||||||
STUB(RtlAreAllAccessesGranted)
|
STUB(RtlAreAllAccessesGranted)
|
||||||
|
@ -92,7 +88,6 @@ STUB(RtlAreBitsClear)
|
||||||
STUB(RtlAreBitsSet)
|
STUB(RtlAreBitsSet)
|
||||||
STUB(RtlAssert)
|
STUB(RtlAssert)
|
||||||
STUB(RtlCaptureStackBackTrace)
|
STUB(RtlCaptureStackBackTrace)
|
||||||
STUB(RtlCharToInteger)
|
|
||||||
STUB(RtlCheckRegistryKey)
|
STUB(RtlCheckRegistryKey)
|
||||||
STUB(RtlClearAllBits)
|
STUB(RtlClearAllBits)
|
||||||
STUB(RtlClearBits)
|
STUB(RtlClearBits)
|
||||||
|
@ -100,8 +95,6 @@ STUB(RtlClosePropertySet)
|
||||||
STUB(RtlCompactHeap)
|
STUB(RtlCompactHeap)
|
||||||
STUB(RtlCompareMemory)
|
STUB(RtlCompareMemory)
|
||||||
STUB(RtlCompareMemoryUlong)
|
STUB(RtlCompareMemoryUlong)
|
||||||
STUB(RtlCompareString)
|
|
||||||
STUB(RtlCompareUnicodeString)
|
|
||||||
STUB(RtlCompressBuffer)
|
STUB(RtlCompressBuffer)
|
||||||
STUB(RtlConsoleMultiByteToUnicodeN)
|
STUB(RtlConsoleMultiByteToUnicodeN)
|
||||||
STUB(RtlConvertExclusiveToShared)
|
STUB(RtlConvertExclusiveToShared)
|
||||||
|
@ -115,8 +108,6 @@ STUB(RtlCopyLuidAndAttributesArray)
|
||||||
STUB(RtlCopySecurityDescriptor)
|
STUB(RtlCopySecurityDescriptor)
|
||||||
STUB(RtlCopySid)
|
STUB(RtlCopySid)
|
||||||
STUB(RtlCopySidAndAttributesArray)
|
STUB(RtlCopySidAndAttributesArray)
|
||||||
STUB(RtlCopyString)
|
|
||||||
STUB(RtlCopyUnicodeString)
|
|
||||||
STUB(RtlCreateAcl)
|
STUB(RtlCreateAcl)
|
||||||
STUB(RtlCreateAndSetSD)
|
STUB(RtlCreateAndSetSD)
|
||||||
STUB(RtlCreateAtomTable)
|
STUB(RtlCreateAtomTable)
|
||||||
|
@ -173,8 +164,6 @@ STUB(RtlEqualDomainName)
|
||||||
STUB(RtlEqualLuid)
|
STUB(RtlEqualLuid)
|
||||||
STUB(RtlEqualPrefixSid)
|
STUB(RtlEqualPrefixSid)
|
||||||
STUB(RtlEqualSid)
|
STUB(RtlEqualSid)
|
||||||
STUB(RtlEqualString)
|
|
||||||
STUB(RtlEqualUnicodeString)
|
|
||||||
STUB(RtlEraseUnicodeString)
|
STUB(RtlEraseUnicodeString)
|
||||||
STUB(RtlExpandEnvironmentStrings_U)
|
STUB(RtlExpandEnvironmentStrings_U)
|
||||||
STUB(RtlExtendHeap)
|
STUB(RtlExtendHeap)
|
||||||
|
@ -194,12 +183,10 @@ STUB(RtlFirstFreeAce)
|
||||||
STUB(RtlFlushPropertySet)
|
STUB(RtlFlushPropertySet)
|
||||||
STUB(RtlFormatCurrentUserKeyPath)
|
STUB(RtlFormatCurrentUserKeyPath)
|
||||||
STUB(RtlFormatMessage)
|
STUB(RtlFormatMessage)
|
||||||
STUB(RtlFreeAnsiString)
|
|
||||||
STUB(RtlFreeHandle)
|
STUB(RtlFreeHandle)
|
||||||
STUB(RtlFreeHeap)
|
STUB(RtlFreeHeap)
|
||||||
STUB(RtlFreeOemString)
|
STUB(RtlFreeOemString)
|
||||||
STUB(RtlFreeSid)
|
STUB(RtlFreeSid)
|
||||||
STUB(RtlFreeUnicodeString)
|
|
||||||
STUB(RtlFreeUserThreadStack)
|
STUB(RtlFreeUserThreadStack)
|
||||||
STUB(RtlGenerate8dot3Name)
|
STUB(RtlGenerate8dot3Name)
|
||||||
STUB(RtlGetAce)
|
STUB(RtlGetAce)
|
||||||
|
@ -225,11 +212,8 @@ STUB(RtlImageNtHeader)
|
||||||
STUB(RtlImageRvaToSection)
|
STUB(RtlImageRvaToSection)
|
||||||
STUB(RtlImageRvaToVa)
|
STUB(RtlImageRvaToVa)
|
||||||
STUB(RtlImpersonateSelf)
|
STUB(RtlImpersonateSelf)
|
||||||
STUB(RtlInitAnsiString)
|
|
||||||
STUB(RtlInitCodePageTable)
|
STUB(RtlInitCodePageTable)
|
||||||
STUB(RtlInitNlsTables)
|
STUB(RtlInitNlsTables)
|
||||||
STUB(RtlInitString)
|
|
||||||
STUB(RtlInitUnicodeString)
|
|
||||||
STUB(RtlInitializeAtomPackage)
|
STUB(RtlInitializeAtomPackage)
|
||||||
STUB(RtlInitializeBitMap)
|
STUB(RtlInitializeBitMap)
|
||||||
STUB(RtlInitializeContext)
|
STUB(RtlInitializeContext)
|
||||||
|
@ -242,7 +226,6 @@ STUB(RtlInitializeResource)
|
||||||
STUB(RtlInitializeSid)
|
STUB(RtlInitializeSid)
|
||||||
STUB(RtlInsertElementGenericTable)
|
STUB(RtlInsertElementGenericTable)
|
||||||
STUB(RtlIntegerToChar)
|
STUB(RtlIntegerToChar)
|
||||||
STUB(RtlIntegerToUnicodeString)
|
|
||||||
STUB(RtlIsDosDeviceName_U)
|
STUB(RtlIsDosDeviceName_U)
|
||||||
STUB(RtlIsGenericTableEmpty)
|
STUB(RtlIsGenericTableEmpty)
|
||||||
STUB(RtlIsNameLegalDOS8Dot3)
|
STUB(RtlIsNameLegalDOS8Dot3)
|
||||||
|
@ -353,9 +336,7 @@ STUB(RtlTimeToSecondsSince1980)
|
||||||
STUB(RtlTimeToTimeFields)
|
STUB(RtlTimeToTimeFields)
|
||||||
STUB(RtlTryEnterCriticalSection)
|
STUB(RtlTryEnterCriticalSection)
|
||||||
STUB(RtlUnicodeStringToAnsiSize)
|
STUB(RtlUnicodeStringToAnsiSize)
|
||||||
STUB(RtlUnicodeStringToAnsiString)
|
|
||||||
STUB(RtlUnicodeStringToCountedOemString)
|
STUB(RtlUnicodeStringToCountedOemString)
|
||||||
STUB(RtlUnicodeStringToInteger)
|
|
||||||
STUB(RtlUnicodeStringToOemSize)
|
STUB(RtlUnicodeStringToOemSize)
|
||||||
STUB(RtlUnicodeStringToOemString)
|
STUB(RtlUnicodeStringToOemString)
|
||||||
STUB(RtlUnicodeToCustomCPN)
|
STUB(RtlUnicodeToCustomCPN)
|
||||||
|
@ -366,7 +347,6 @@ STUB(RtlUniform)
|
||||||
STUB(RtlUnlockHeap)
|
STUB(RtlUnlockHeap)
|
||||||
STUB(RtlUnwind)
|
STUB(RtlUnwind)
|
||||||
STUB(RtlUpcaseUnicodeChar)
|
STUB(RtlUpcaseUnicodeChar)
|
||||||
STUB(RtlUpcaseUnicodeString)
|
|
||||||
STUB(RtlUpcaseUnicodeStringToAnsiString)
|
STUB(RtlUpcaseUnicodeStringToAnsiString)
|
||||||
STUB(RtlUpcaseUnicodeStringToCountedOemString)
|
STUB(RtlUpcaseUnicodeStringToCountedOemString)
|
||||||
STUB(RtlUpcaseUnicodeStringToOemString)
|
STUB(RtlUpcaseUnicodeStringToOemString)
|
||||||
|
@ -374,7 +354,6 @@ STUB(RtlUpcaseUnicodeToCustomCPN)
|
||||||
STUB(RtlUpcaseUnicodeToMultiByteN)
|
STUB(RtlUpcaseUnicodeToMultiByteN)
|
||||||
STUB(RtlUpcaseUnicodeToOemN)
|
STUB(RtlUpcaseUnicodeToOemN)
|
||||||
STUB(RtlUpperChar)
|
STUB(RtlUpperChar)
|
||||||
STUB(RtlUpperString)
|
|
||||||
STUB(RtlUsageHeap)
|
STUB(RtlUsageHeap)
|
||||||
STUB(RtlValidAcl)
|
STUB(RtlValidAcl)
|
||||||
STUB(RtlValidSecurityDescriptor)
|
STUB(RtlValidSecurityDescriptor)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -31,7 +31,7 @@ LOADERS = dos
|
||||||
# Select the device drivers and filesystems you want
|
# Select the device drivers and filesystems you want
|
||||||
#
|
#
|
||||||
KERNEL_SERVICES = parallel keyboard null mouse serial sound ide test sdisk \
|
KERNEL_SERVICES = parallel keyboard null mouse serial sound ide test sdisk \
|
||||||
minix vfat # ext2fs
|
minix vfat ext2
|
||||||
|
|
||||||
APPS = hello shell
|
APPS = hello shell
|
||||||
|
|
||||||
|
@ -104,8 +104,8 @@ serial: dummy
|
||||||
sound: dummy
|
sound: dummy
|
||||||
make -C services/dd/sound
|
make -C services/dd/sound
|
||||||
|
|
||||||
ext2fs: dummy
|
ext2: dummy
|
||||||
make -C services/fs/ext2fs
|
make -C services/fs/ext2
|
||||||
|
|
||||||
#
|
#
|
||||||
# Kernel loaders
|
# Kernel loaders
|
||||||
|
|
|
@ -17,12 +17,14 @@ _irq_handler_%1:
|
||||||
;
|
;
|
||||||
pusha
|
pusha
|
||||||
push ds
|
push ds
|
||||||
|
push es
|
||||||
|
|
||||||
;
|
;
|
||||||
; Load DS
|
; Load DS
|
||||||
;
|
;
|
||||||
mov ax,KERNEL_DS
|
mov ax,KERNEL_DS
|
||||||
mov ds,ax
|
mov ds,ax
|
||||||
|
mov es,ax
|
||||||
|
|
||||||
;
|
;
|
||||||
; Mask the corresponding vector at the PIC
|
; Mask the corresponding vector at the PIC
|
||||||
|
@ -43,6 +45,7 @@ _irq_handler_%1:
|
||||||
; Restore stack, registers and return to interrupted routine
|
; Restore stack, registers and return to interrupted routine
|
||||||
;
|
;
|
||||||
pop eax
|
pop eax
|
||||||
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
popa
|
popa
|
||||||
iret
|
iret
|
||||||
|
|
|
@ -223,11 +223,7 @@ BOOL is_page_present(unsigned int vaddr)
|
||||||
* buffer from an irq.
|
* buffer from an irq.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
unsigned int* page_dir = physical_to_linear(current_task->cr3);
|
|
||||||
#else
|
|
||||||
unsigned int* page_dir = get_page_directory();
|
unsigned int* page_dir = get_page_directory();
|
||||||
#endif
|
|
||||||
unsigned int* page_tlb = NULL;
|
unsigned int* page_tlb = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -150,7 +150,7 @@ NTSTATUS KeValidateUserContext(PCONTEXT Context)
|
||||||
(Context->EFlags & FLAG_VM) ||
|
(Context->EFlags & FLAG_VM) ||
|
||||||
(!(Context->EFlags & FLAG_IF)))
|
(!(Context->EFlags & FLAG_IF)))
|
||||||
{
|
{
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_UNSUCCESSFUL);
|
||||||
}
|
}
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ NTSTATUS InitalizeLoadedDriver(PDRIVER_INITIALIZE entry)
|
||||||
/*
|
/*
|
||||||
* Allocate memory for a driver object
|
* Allocate memory for a driver object
|
||||||
* NOTE: The object only becomes system visible once the associated
|
* NOTE: The object only becomes system visible once the associated
|
||||||
* device objects are intialized
|
* device objects are initialized
|
||||||
*/
|
*/
|
||||||
DriverObject=ExAllocatePool(NonPagedPool,sizeof(DRIVER_OBJECT));
|
DriverObject=ExAllocatePool(NonPagedPool,sizeof(DRIVER_OBJECT));
|
||||||
if (DriverObject==NULL)
|
if (DriverObject==NULL)
|
||||||
|
|
|
@ -306,3 +306,4 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||||
IoSecondStageCompletion(Irp,PriorityBoost);
|
IoSecondStageCompletion(Irp,PriorityBoost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
>>>>>>> 1.7
|
||||||
|
|
|
@ -28,6 +28,9 @@ NTSTATUS IoPageRead(PFILE_OBJECT FileObject,
|
||||||
PIO_STACK_LOCATION StackPtr;
|
PIO_STACK_LOCATION StackPtr;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
DPRINT("IoPageRead(FileObject %x, Address %x)\n",
|
||||||
|
FileObject,Address);
|
||||||
|
|
||||||
KeInitializeEvent(&Event,NotificationEvent,FALSE);
|
KeInitializeEvent(&Event,NotificationEvent,FALSE);
|
||||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
FileObject->DeviceObject,
|
FileObject->DeviceObject,
|
||||||
|
|
|
@ -117,7 +117,7 @@ asmlinkage void _main(boot_param* _bp)
|
||||||
unsigned int start1;
|
unsigned int start1;
|
||||||
boot_param bp;
|
boot_param bp;
|
||||||
|
|
||||||
// memset((void *)&edata,0,((int)&end)-((int)&edata));
|
memset((void *)&edata,0,((int)&end)-((int)&edata));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy the parameters to a local buffer because lowmem will go away
|
* Copy the parameters to a local buffer because lowmem will go away
|
||||||
|
@ -139,15 +139,7 @@ asmlinkage void _main(boot_param* _bp)
|
||||||
DbgPrint("Reduce the amount of uninitialized data\n");
|
DbgPrint("Reduce the amount of uninitialized data\n");
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
DPRINT("MmGetPhysicalAddress(start) = %x\n",MmGetPhysicalAddress((void *)start));
|
|
||||||
DPRINT("bp.module_length[0] %x PAGE_ROUND_UP(bp.module_length[0]) %x\n",
|
|
||||||
bp.module_length[0],PAGE_ROUND_UP(bp.module_length[0]));
|
|
||||||
start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
|
start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
|
||||||
DPRINT("bp.module_length[1] %x PAGE_ROUND_UP(bp.module_length[1]) %x\n",
|
|
||||||
bp.module_length[1],PAGE_ROUND_UP(bp.module_length[1]));
|
|
||||||
|
|
||||||
DPRINT("start %x *start %x\n",start,*((unsigned int *)start));
|
|
||||||
DPRINT("start1 %x *start1 %x\n",start1,*((unsigned int *)start1));
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -155,15 +147,10 @@ asmlinkage void _main(boot_param* _bp)
|
||||||
*/
|
*/
|
||||||
HalInit(&bp);
|
HalInit(&bp);
|
||||||
MmInitalize(&bp);
|
MmInitalize(&bp);
|
||||||
CHECKPOINT;
|
|
||||||
KeInit();
|
KeInit();
|
||||||
CHECKPOINT;
|
|
||||||
ObInit();
|
ObInit();
|
||||||
CHECKPOINT;
|
|
||||||
PsInit();
|
PsInit();
|
||||||
CHECKPOINT;
|
|
||||||
IoInit();
|
IoInit();
|
||||||
CHECKPOINT;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initalize services loaded at boot time
|
* Initalize services loaded at boot time
|
||||||
|
@ -172,11 +159,9 @@ asmlinkage void _main(boot_param* _bp)
|
||||||
|
|
||||||
start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
|
start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
|
||||||
start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
|
start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
|
||||||
// DbgPrint("start1 %x *start1 %x\n",start1,*((unsigned int *)start1));
|
|
||||||
for (i=1;i<bp.nr_files;i++)
|
for (i=1;i<bp.nr_files;i++)
|
||||||
{
|
{
|
||||||
process_boot_module(start);
|
process_boot_module(start);
|
||||||
// DbgPrint("start1 %x *start1 %x\n",start1,*((unsigned int *)start1));
|
|
||||||
start=start+PAGE_ROUND_UP(bp.module_length[i]);
|
start=start+PAGE_ROUND_UP(bp.module_length[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ static unsigned long long system_time = 0;
|
||||||
/*
|
/*
|
||||||
* Number of timer interrupts since initialisation
|
* Number of timer interrupts since initialisation
|
||||||
*/
|
*/
|
||||||
static volatile unsigned long long ticks=0;
|
volatile ULONGLONG KiTimerTicks;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The increment in the system clock every timer tick (in system time units)
|
* The increment in the system clock every timer tick (in system time units)
|
||||||
|
@ -76,10 +76,10 @@ VOID KeCalibrateTimerLoop(VOID)
|
||||||
for (i=0;i<20;i++)
|
for (i=0;i<20;i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
start_tick = ticks;
|
start_tick = KiTimerTicks;
|
||||||
microseconds = 0;
|
microseconds = 0;
|
||||||
while (start_tick == ticks);
|
while (start_tick == KiTimerTicks);
|
||||||
while (ticks == (start_tick+TICKS_TO_CALIBRATE))
|
while (KiTimerTicks == (start_tick+TICKS_TO_CALIBRATE))
|
||||||
{
|
{
|
||||||
KeStallExecutionProcessor(1);
|
KeStallExecutionProcessor(1);
|
||||||
microseconds++;
|
microseconds++;
|
||||||
|
@ -418,7 +418,7 @@ VOID KeQueryTickCount(PLARGE_INTEGER TickCount)
|
||||||
* TickCount (OUT) = Points to storage for the number of ticks
|
* TickCount (OUT) = Points to storage for the number of ticks
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
LARGE_INTEGER_QUAD_PART(*TickCount) = ticks;
|
LARGE_INTEGER_QUAD_PART(*TickCount) = KiTimerTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HandleExpiredTimer(PKTIMER current)
|
static void HandleExpiredTimer(PKTIMER current)
|
||||||
|
@ -484,11 +484,13 @@ BOOLEAN KiTimerInterrupt(VOID)
|
||||||
char* vidmem=(char *)physical_to_linear(0xb8000 + 160 - 36);
|
char* vidmem=(char *)physical_to_linear(0xb8000 + 160 - 36);
|
||||||
int i;
|
int i;
|
||||||
int x,y;
|
int x,y;
|
||||||
|
extern ULONG PiNrThreads;
|
||||||
|
extern ULONG EiNrUsedBlocks;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Increment the number of timers ticks
|
* Increment the number of timers ticks
|
||||||
*/
|
*/
|
||||||
ticks++;
|
KiTimerTicks++;
|
||||||
system_time = system_time + CLOCK_INCREMENT;
|
system_time = system_time + CLOCK_INCREMENT;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -508,7 +510,8 @@ BOOLEAN KiTimerInterrupt(VOID)
|
||||||
(EiFreeNonPagedPool + EiUsedNonPagedPool);
|
(EiFreeNonPagedPool + EiUsedNonPagedPool);
|
||||||
}
|
}
|
||||||
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks);
|
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks);
|
||||||
sprintf(str,"%.4u %.4u %.7u",x,y,ticks);
|
memset(str, 0, sizeof(str));
|
||||||
|
sprintf(str,"%.8u %.8u",EiNrUsedBlocks,KiTimerTicks);
|
||||||
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,EiUsedNonPagedPool);
|
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,EiUsedNonPagedPool);
|
||||||
for (i=0;i<17;i++)
|
for (i=0;i<17;i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
|
|
||||||
#if CHECKED
|
#if 0
|
||||||
#define VALIDATE_POOL validate_kernel_pool()
|
#define VALIDATE_POOL validate_kernel_pool()
|
||||||
#else
|
#else
|
||||||
#define VALIDATE_POOL
|
#define VALIDATE_POOL
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
typedef struct _block_hdr
|
typedef struct _block_hdr
|
||||||
{
|
{
|
||||||
ULONG magic;
|
ULONG magic;
|
||||||
unsigned int size;
|
ULONG size;
|
||||||
struct _block_hdr* previous;
|
struct _block_hdr* previous;
|
||||||
struct _block_hdr* next;
|
struct _block_hdr* next;
|
||||||
ULONG tag;
|
ULONG tag;
|
||||||
|
@ -62,8 +62,8 @@ static unsigned int kernel_pool_base = 0;
|
||||||
*/
|
*/
|
||||||
static block_hdr* free_list_head = NULL;
|
static block_hdr* free_list_head = NULL;
|
||||||
static block_hdr* used_list_head = NULL;
|
static block_hdr* used_list_head = NULL;
|
||||||
static unsigned int nr_free_blocks = 0;
|
static ULONG nr_free_blocks;
|
||||||
unsigned int nr_used_blocks = 0;
|
ULONG EiNrUsedBlocks = 0;
|
||||||
|
|
||||||
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGESIZE)
|
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGESIZE)
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static void validate_used_list(void)
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
blocks_seen++;
|
blocks_seen++;
|
||||||
if (blocks_seen > nr_used_blocks)
|
if (blocks_seen > EiNrUsedBlocks)
|
||||||
{
|
{
|
||||||
printk("Too many blocks on list\n");
|
printk("Too many blocks on list\n");
|
||||||
for(;;);
|
for(;;);
|
||||||
|
@ -278,7 +278,7 @@ static void add_to_used_list(block_hdr* blk)
|
||||||
used_list_head->previous=blk;
|
used_list_head->previous=blk;
|
||||||
}
|
}
|
||||||
used_list_head=blk;
|
used_list_head=blk;
|
||||||
nr_used_blocks++;
|
EiNrUsedBlocks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ static void remove_from_used_list(block_hdr* current)
|
||||||
current->previous->next=NULL;
|
current->previous->next=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nr_used_blocks--;
|
EiNrUsedBlocks--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -528,13 +528,11 @@ asmlinkage VOID ExFreePool(PVOID block)
|
||||||
* block = block to free
|
* block = block to free
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
block_hdr *blk = address_to_block(block);
|
block_hdr* blk=address_to_block(block);
|
||||||
|
OLD_DPRINT("(%s:%d) freeing block %x\n",__FILE__,__LINE__,blk);
|
||||||
|
|
||||||
OLD_DPRINT("ExFreePool(block %x), size %d, caller %x\n",
|
// DbgPrint("ExFreePool(block %x), size %d, caller %x\n",block,blk->size,
|
||||||
block,
|
// ((PULONG)&block)[-1]);
|
||||||
blk->size,
|
|
||||||
((PULONG)&block)[-1]);
|
|
||||||
OLD_DPRINT("freeing block %x\n",blk);
|
|
||||||
|
|
||||||
VALIDATE_POOL;
|
VALIDATE_POOL;
|
||||||
|
|
||||||
|
@ -562,9 +560,9 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type, ULONG size, ULONG Tag)
|
||||||
block_hdr* current=NULL;
|
block_hdr* current=NULL;
|
||||||
void* block;
|
void* block;
|
||||||
|
|
||||||
OLD_DPRINT("Blocks on free list %d\n",nr_free_blocks);
|
// DbgPrint("Blocks on free list %d\n",nr_free_blocks);
|
||||||
OLD_DPRINT("Blocks on used list %d\n",nr_used_blocks);
|
// DbgPrint("Blocks on used list %d\n",eiNrUsedblocks);
|
||||||
OLD_DPRINT("ExAllocateNonPagedPool(type %d, size %d)\n",type,size);
|
// OLD_DPRINT("ExAllocateNonPagedPool(type %d, size %d)\n",type,size);
|
||||||
VALIDATE_POOL;
|
VALIDATE_POOL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -593,6 +591,7 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type, ULONG size, ULONG Tag)
|
||||||
{
|
{
|
||||||
OLD_DPRINT("found block %x of size %d\n",current,size);
|
OLD_DPRINT("found block %x of size %d\n",current,size);
|
||||||
block=take_block(current,size);
|
block=take_block(current,size);
|
||||||
|
VALIDATE_POOL;
|
||||||
memset(block,0,size);
|
memset(block,0,size);
|
||||||
return(block);
|
return(block);
|
||||||
}
|
}
|
||||||
|
@ -603,7 +602,7 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type, ULONG size, ULONG Tag)
|
||||||
* Otherwise create a new block
|
* Otherwise create a new block
|
||||||
*/
|
*/
|
||||||
block=block_to_address(grow_kernel_pool(size));
|
block=block_to_address(grow_kernel_pool(size));
|
||||||
|
VALIDATE_POOL;
|
||||||
memset(block,0,size);
|
memset(block,0,size);
|
||||||
|
return(block);
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,16 +45,11 @@ PVOID ExAllocatePool(POOL_TYPE PoolType, ULONG NumberOfBytes)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PVOID Block;
|
PVOID Block;
|
||||||
|
// DbgPrint("ExAllocatePool(NumberOfBytes %d) caller %x\n",
|
||||||
OLD_DPRINT("ExAllocatePool(NumberOfBytes %d) caller %x\n",
|
// NumberOfBytes,((PULONG)&PoolType)[-1]);
|
||||||
NumberOfBytes,
|
|
||||||
((PULONG)&PoolType)[-1]);
|
|
||||||
|
|
||||||
Block = ExAllocatePoolWithTag(PoolType,NumberOfBytes,TAG_NONE);
|
Block = ExAllocatePoolWithTag(PoolType,NumberOfBytes,TAG_NONE);
|
||||||
|
// DbgPrint("ExAllocatePool() = %x\n",Block);
|
||||||
OLD_DPRINT("ExAllocatePool() = %x\n",Block);
|
return(Block);
|
||||||
|
|
||||||
return Block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PVOID ExAllocatePoolWithTag(ULONG type, ULONG size, ULONG Tag)
|
PVOID ExAllocatePoolWithTag(ULONG type, ULONG size, ULONG Tag)
|
||||||
|
@ -121,4 +116,3 @@ PVOID ExAllocatePoolWithQuota(POOL_TYPE PoolType, ULONG NumberOfBytes)
|
||||||
{
|
{
|
||||||
return(ExAllocatePoolWithQuotaTag(PoolType,NumberOfBytes,TAG_NONE));
|
return(ExAllocatePoolWithQuotaTag(PoolType,NumberOfBytes,TAG_NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ NTSTATUS STDCALL ZwCreateSection(OUT PHANDLE SectionHandle,
|
||||||
PSECTION_OBJECT Section;
|
PSECTION_OBJECT Section;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("ZwCreateSection()\n");
|
DbgPrint("ZwCreateSection()\n");
|
||||||
|
|
||||||
Section = ObGenericCreateObject(SectionHandle,
|
Section = ObGenericCreateObject(SectionHandle,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
|
@ -128,11 +128,13 @@ NTSTATUS STDCALL ZwCreateSection(OUT PHANDLE SectionHandle,
|
||||||
NULL);
|
NULL);
|
||||||
if (Status != STATUS_SUCCESS)
|
if (Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
|
DPRINT("ZwCreateSection() = %x\n",Status);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Section->AllocateAttributes = AllocationAttributes;
|
Section->AllocateAttributes = AllocationAttributes;
|
||||||
|
|
||||||
|
DPRINT("ZwCreateSection() = STATUS_SUCCESS\n");
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -547,6 +547,7 @@ NTSTATUS ObLookupObject(HANDLE rootdir, PWSTR string, PVOID* Object,
|
||||||
}
|
}
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
*Object = current_dir;
|
*Object = current_dir;
|
||||||
|
DPRINT("(%s:%d) current_dir %x\n",__FILE__,__LINE__,current_dir);
|
||||||
|
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <internal/ob.h>
|
#include <internal/ob.h>
|
||||||
#include <wstring.h>
|
#include <wstring.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
@ -96,10 +97,11 @@ PVOID ObGenericCreateObject(PHANDLE Handle,
|
||||||
POBJECT_TYPE Type)
|
POBJECT_TYPE Type)
|
||||||
{
|
{
|
||||||
POBJECT_HEADER hdr = NULL;
|
POBJECT_HEADER hdr = NULL;
|
||||||
UNICODE_STRING ObjectName;
|
|
||||||
PWSTR path;
|
PWSTR path;
|
||||||
PWSTR name;
|
PWSTR name;
|
||||||
PWSTR Ignored;
|
PWSTR Ignored;
|
||||||
|
PULONG addr;
|
||||||
|
PWSTR Buffer;
|
||||||
|
|
||||||
DPRINT("ObGenericCreateObject(Handle %x, DesiredAccess %x,"
|
DPRINT("ObGenericCreateObject(Handle %x, DesiredAccess %x,"
|
||||||
"ObjectAttributes %x, Type %x)\n",Handle,DesiredAccess,
|
"ObjectAttributes %x, Type %x)\n",Handle,DesiredAccess,
|
||||||
|
@ -109,15 +111,18 @@ PVOID ObGenericCreateObject(PHANDLE Handle,
|
||||||
* Allocate the object body and header
|
* Allocate the object body and header
|
||||||
*/
|
*/
|
||||||
hdr=(POBJECT_HEADER)ExAllocatePool(NonPagedPool,OBJECT_ALLOC_SIZE(Type));
|
hdr=(POBJECT_HEADER)ExAllocatePool(NonPagedPool,OBJECT_ALLOC_SIZE(Type));
|
||||||
|
DPRINT("OBJECT_ALLOC_SIZE(Type) %d\n",OBJECT_ALLOC_SIZE(Type));
|
||||||
if (hdr==NULL)
|
if (hdr==NULL)
|
||||||
{
|
{
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
DPRINT("hdr %x\n",hdr);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If unnamed then initalize
|
* If unnamed then initalize
|
||||||
*/
|
*/
|
||||||
if (ObjectAttributes==NULL)
|
if (ObjectAttributes==NULL || ObjectAttributes->ObjectName==NULL)
|
||||||
{
|
{
|
||||||
ObInitializeObjectHeader(Type,NULL,hdr);
|
ObInitializeObjectHeader(Type,NULL,hdr);
|
||||||
if (Handle != NULL)
|
if (Handle != NULL)
|
||||||
|
@ -130,44 +135,53 @@ PVOID ObGenericCreateObject(PHANDLE Handle,
|
||||||
return(HEADER_TO_BODY(hdr));
|
return(HEADER_TO_BODY(hdr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy the object name into a buffer
|
* Copy the object name into a buffer
|
||||||
*/
|
*/
|
||||||
DPRINT("ObjectAttributes->ObjectName %x\n",ObjectAttributes->ObjectName);
|
// DbgPrint("ObjectAttributes->ObjectName %x\n",ObjectAttributes->ObjectName);
|
||||||
DPRINT("ObjectAttributes->ObjectName->Length %d\n",
|
// DbgPrint("ObjectAttributes->ObjectName->Length %d\n",
|
||||||
ObjectAttributes->ObjectName->Length);
|
// ObjectAttributes->ObjectName->Length);
|
||||||
ObjectName.MaximumLength = ObjectAttributes->ObjectName->Length;
|
// DbgPrint("ObjectAttributes->ObjectName->MaximumLength %d\n",
|
||||||
ObjectName.Buffer = ExAllocatePool(NonPagedPool,
|
// ObjectAttributes->ObjectName->MaximumLength);
|
||||||
((ObjectAttributes->ObjectName->Length+1)*2));
|
Buffer = ExAllocatePool(NonPagedPool,
|
||||||
if (ObjectName.Buffer==NULL)
|
((ObjectAttributes->ObjectName->Length+1)*2));
|
||||||
|
if (Buffer==NULL)
|
||||||
{
|
{
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
RtlCopyUnicodeString(&ObjectName,ObjectAttributes->ObjectName);
|
memcpy(Buffer, ObjectAttributes->ObjectName->Buffer,
|
||||||
|
(ObjectAttributes->ObjectName->Length+1)*2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Seperate the name into a path and name
|
* Seperate the name into a path and name
|
||||||
*/
|
*/
|
||||||
name = wcsrchr(ObjectName.Buffer,'\\');
|
name = wcsrchr(Buffer,'\\');
|
||||||
if (name==NULL)
|
if (name==NULL)
|
||||||
{
|
{
|
||||||
name=ObjectName.Buffer;
|
name=Buffer;
|
||||||
path=NULL;
|
path=NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
path=ObjectName.Buffer;
|
path=Buffer;
|
||||||
*name=0;
|
*name=0;
|
||||||
name=name+1;
|
name=name+1;
|
||||||
}
|
}
|
||||||
|
DPRINT("name %w path %w\n",name,path);
|
||||||
|
|
||||||
ObLookupObject(ObjectAttributes->RootDirectory,path,
|
ObLookupObject(ObjectAttributes->RootDirectory,
|
||||||
&hdr->Parent,&Ignored, 0L);
|
path,
|
||||||
|
&hdr->Parent,
|
||||||
|
&Ignored,
|
||||||
|
0L);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the object header
|
* Initialize the object header
|
||||||
*/
|
*/
|
||||||
ObInitializeObjectHeader(Type,name,hdr);
|
ObInitializeObjectHeader(Type,name,hdr);
|
||||||
|
|
||||||
|
|
||||||
ObCreateEntry(hdr->Parent,hdr);
|
ObCreateEntry(hdr->Parent,hdr);
|
||||||
|
|
||||||
DPRINT("Handle %x\n",Handle);
|
DPRINT("Handle %x\n",Handle);
|
||||||
|
@ -192,6 +206,7 @@ VOID ObInitializeObjectHeader(POBJECT_TYPE Type, PWSTR name,
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PWSTR temp_name;
|
PWSTR temp_name;
|
||||||
|
extern unsigned long long ticks;
|
||||||
|
|
||||||
DPRINT("ObInitializeObjectHeader(id %x name %w obj %x)\n",Type,
|
DPRINT("ObInitializeObjectHeader(id %x name %w obj %x)\n",Type,
|
||||||
name,ObjectHeader);
|
name,ObjectHeader);
|
||||||
|
@ -207,10 +222,7 @@ VOID ObInitializeObjectHeader(POBJECT_TYPE Type, PWSTR name,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ObjectHeader->Name.MaximumLength = wstrlen(name);
|
RtlInitUnicodeString(&(ObjectHeader->Name),name);
|
||||||
ObjectHeader->Name.Buffer = ExAllocatePool(NonPagedPool,
|
|
||||||
(ObjectHeader->Name.MaximumLength+1)*2);
|
|
||||||
RtlInitUnicodeString(&ObjectHeader->Name,name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,468 +0,0 @@
|
||||||
.file "object.c"
|
|
||||||
.version "01.01"
|
|
||||||
gcc2_compiled.:
|
|
||||||
.text
|
|
||||||
.align 16
|
|
||||||
.globl NtSetInformationObject
|
|
||||||
.type NtSetInformationObject,@function
|
|
||||||
NtSetInformationObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl %ebx
|
|
||||||
movl 8(%ebp),%ebx
|
|
||||||
movl 12(%ebp),%ecx
|
|
||||||
movl 16(%ebp),%edx
|
|
||||||
movl 20(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl %edx
|
|
||||||
pushl %ecx
|
|
||||||
pushl %ebx
|
|
||||||
call ZwSetInformationObject
|
|
||||||
movl -4(%ebp),%ebx
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $16
|
|
||||||
.Lfe1:
|
|
||||||
.size NtSetInformationObject,.Lfe1-NtSetInformationObject
|
|
||||||
.section .rodata
|
|
||||||
.LC0:
|
|
||||||
.string "object.c"
|
|
||||||
.LC1:
|
|
||||||
.string "ZwSetInformationObject"
|
|
||||||
.LC2:
|
|
||||||
.string "%s at %s:%d is unimplemented, have a nice day\n"
|
|
||||||
.text
|
|
||||||
.align 16
|
|
||||||
.globl ZwSetInformationObject
|
|
||||||
.type ZwSetInformationObject,@function
|
|
||||||
ZwSetInformationObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl $38
|
|
||||||
pushl $.LC0
|
|
||||||
pushl $.LC1
|
|
||||||
pushl $.LC2
|
|
||||||
call DbgPrint
|
|
||||||
.align 4
|
|
||||||
.L17:
|
|
||||||
jmp .L17
|
|
||||||
.align 16
|
|
||||||
.Lfe2:
|
|
||||||
.size ZwSetInformationObject,.Lfe2-ZwSetInformationObject
|
|
||||||
.align 16
|
|
||||||
.globl NtQueryObject
|
|
||||||
.type NtQueryObject,@function
|
|
||||||
NtQueryObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
movl 8(%ebp),%esi
|
|
||||||
movl 12(%ebp),%ebx
|
|
||||||
movl 16(%ebp),%ecx
|
|
||||||
movl 20(%ebp),%edx
|
|
||||||
movl 24(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl %edx
|
|
||||||
pushl %ecx
|
|
||||||
pushl %ebx
|
|
||||||
pushl %esi
|
|
||||||
call ZwQueryObject
|
|
||||||
leal -8(%ebp),%esp
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $20
|
|
||||||
.Lfe3:
|
|
||||||
.size NtQueryObject,.Lfe3-NtQueryObject
|
|
||||||
.section .rodata
|
|
||||||
.LC3:
|
|
||||||
.string "ZwQueryObject"
|
|
||||||
.text
|
|
||||||
.align 16
|
|
||||||
.globl ZwQueryObject
|
|
||||||
.type ZwQueryObject,@function
|
|
||||||
ZwQueryObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl $60
|
|
||||||
pushl $.LC0
|
|
||||||
pushl $.LC3
|
|
||||||
pushl $.LC2
|
|
||||||
call DbgPrint
|
|
||||||
.align 4
|
|
||||||
.L26:
|
|
||||||
jmp .L26
|
|
||||||
.align 16
|
|
||||||
.Lfe4:
|
|
||||||
.size ZwQueryObject,.Lfe4-ZwQueryObject
|
|
||||||
.align 16
|
|
||||||
.globl NtMakeTemporaryObject
|
|
||||||
.type NtMakeTemporaryObject,@function
|
|
||||||
NtMakeTemporaryObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call ZwMakeTemporaryObject
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.Lfe5:
|
|
||||||
.size NtMakeTemporaryObject,.Lfe5-NtMakeTemporaryObject
|
|
||||||
.align 16
|
|
||||||
.globl ZwMakeTemporaryObject
|
|
||||||
.type ZwMakeTemporaryObject,@function
|
|
||||||
ZwMakeTemporaryObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
subl $4,%esp
|
|
||||||
movl 8(%ebp),%edx
|
|
||||||
pushl $0
|
|
||||||
leal -4(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl $0
|
|
||||||
pushl $0
|
|
||||||
pushl $0
|
|
||||||
pushl %edx
|
|
||||||
call ObReferenceObjectByHandle
|
|
||||||
addl $24,%esp
|
|
||||||
testl %eax,%eax
|
|
||||||
jne .L30
|
|
||||||
movl -4(%ebp),%eax
|
|
||||||
movb $0,-12(%eax)
|
|
||||||
movl -4(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call ObDereferenceObject
|
|
||||||
xorl %eax,%eax
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.align 16
|
|
||||||
.L30:
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.Lfe6:
|
|
||||||
.size ZwMakeTemporaryObject,.Lfe6-ZwMakeTemporaryObject
|
|
||||||
.align 16
|
|
||||||
.globl ObGenericCreateObject
|
|
||||||
.type ObGenericCreateObject,@function
|
|
||||||
ObGenericCreateObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
subl $12,%esp
|
|
||||||
pushl %edi
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
movl 16(%ebp),%edi
|
|
||||||
movl 20(%ebp),%ecx
|
|
||||||
movl 28(%ecx),%eax
|
|
||||||
addl $36,%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl $0
|
|
||||||
call ExAllocatePool
|
|
||||||
movl %eax,%esi
|
|
||||||
addl $8,%esp
|
|
||||||
testl %esi,%esi
|
|
||||||
je .L46
|
|
||||||
testl %edi,%edi
|
|
||||||
jne .L35
|
|
||||||
pushl %esi
|
|
||||||
pushl $0
|
|
||||||
movl 20(%ebp),%ecx
|
|
||||||
pushl %ecx
|
|
||||||
call ObInitializeObjectHeader
|
|
||||||
addl $12,%esp
|
|
||||||
jmp .L47
|
|
||||||
.align 16
|
|
||||||
.L35:
|
|
||||||
movl 8(%edi),%ecx
|
|
||||||
movw (%ecx),%dx
|
|
||||||
sall $16,%edx
|
|
||||||
movzwl -8(%ebp),%eax
|
|
||||||
orl %edx,%eax
|
|
||||||
movl %eax,-8(%ebp)
|
|
||||||
movzwl (%ecx),%eax
|
|
||||||
leal 2(,%eax,2),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl $0
|
|
||||||
call ExAllocatePool
|
|
||||||
movl %eax,-4(%ebp)
|
|
||||||
addl $8,%esp
|
|
||||||
testl %eax,%eax
|
|
||||||
jne .L39
|
|
||||||
.L46:
|
|
||||||
xorl %eax,%eax
|
|
||||||
jmp .L45
|
|
||||||
.align 16
|
|
||||||
.L39:
|
|
||||||
movl 8(%edi),%eax
|
|
||||||
pushl %eax
|
|
||||||
leal -8(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call RtlCopyUnicodeString
|
|
||||||
pushl $92
|
|
||||||
movl -4(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call wcsrchr
|
|
||||||
movl %eax,%ebx
|
|
||||||
addl $16,%esp
|
|
||||||
testl %ebx,%ebx
|
|
||||||
jne .L40
|
|
||||||
movl -4(%ebp),%ebx
|
|
||||||
xorl %edx,%edx
|
|
||||||
jmp .L41
|
|
||||||
.align 16
|
|
||||||
.L40:
|
|
||||||
movl -4(%ebp),%edx
|
|
||||||
movw $0,(%ebx)
|
|
||||||
addl $2,%ebx
|
|
||||||
.L41:
|
|
||||||
leal -12(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
leal 28(%esi),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl %edx
|
|
||||||
movl 4(%edi),%eax
|
|
||||||
pushl %eax
|
|
||||||
call ObLookupObject
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
movl 20(%ebp),%ecx
|
|
||||||
pushl %ecx
|
|
||||||
call ObInitializeObjectHeader
|
|
||||||
pushl %esi
|
|
||||||
movl 28(%esi),%eax
|
|
||||||
pushl %eax
|
|
||||||
call ObCreateEntry
|
|
||||||
addl $36,%esp
|
|
||||||
.L47:
|
|
||||||
cmpl $0,8(%ebp)
|
|
||||||
je .L42
|
|
||||||
pushl $0
|
|
||||||
movl 12(%ebp),%ecx
|
|
||||||
pushl %ecx
|
|
||||||
leal 36(%esi),%eax
|
|
||||||
pushl %eax
|
|
||||||
call KeGetCurrentProcess
|
|
||||||
pushl %eax
|
|
||||||
call ObInsertHandle
|
|
||||||
movl 8(%ebp),%ecx
|
|
||||||
movl %eax,(%ecx)
|
|
||||||
.L42:
|
|
||||||
leal 36(%esi),%eax
|
|
||||||
.L45:
|
|
||||||
leal -24(%ebp),%esp
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe7:
|
|
||||||
.size ObGenericCreateObject,.Lfe7-ObGenericCreateObject
|
|
||||||
.align 16
|
|
||||||
.globl ObInitializeObjectHeader
|
|
||||||
.type ObInitializeObjectHeader,@function
|
|
||||||
ObInitializeObjectHeader:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
movl 12(%ebp),%esi
|
|
||||||
movl 16(%ebp),%ebx
|
|
||||||
movl $0,20(%ebx)
|
|
||||||
movl $0,16(%ebx)
|
|
||||||
movl %eax,32(%ebx)
|
|
||||||
movb $0,24(%ebx)
|
|
||||||
testl %esi,%esi
|
|
||||||
jne .L49
|
|
||||||
movw $0,(%ebx)
|
|
||||||
movl $0,4(%ebx)
|
|
||||||
jmp .L50
|
|
||||||
.align 16
|
|
||||||
.L49:
|
|
||||||
pushl %esi
|
|
||||||
call wstrlen
|
|
||||||
movw %ax,2(%ebx)
|
|
||||||
andl $65535,%eax
|
|
||||||
leal 2(,%eax,2),%eax
|
|
||||||
pushl %eax
|
|
||||||
pushl $0
|
|
||||||
call ExAllocatePool
|
|
||||||
movl %eax,4(%ebx)
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
call RtlInitUnicodeString
|
|
||||||
.L50:
|
|
||||||
leal -8(%ebp),%esp
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe8:
|
|
||||||
.size ObInitializeObjectHeader,.Lfe8-ObInitializeObjectHeader
|
|
||||||
.align 16
|
|
||||||
.globl ObReferenceObjectByPointer
|
|
||||||
.type ObReferenceObjectByPointer,@function
|
|
||||||
ObReferenceObjectByPointer:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
incl -20(%eax)
|
|
||||||
xorl %eax,%eax
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe9:
|
|
||||||
.size ObReferenceObjectByPointer,.Lfe9-ObReferenceObjectByPointer
|
|
||||||
.align 16
|
|
||||||
.globl ObPerformRetentionChecks
|
|
||||||
.type ObPerformRetentionChecks,@function
|
|
||||||
ObPerformRetentionChecks:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl %ebx
|
|
||||||
movl 8(%ebp),%ebx
|
|
||||||
cmpl $0,16(%ebx)
|
|
||||||
jne .L54
|
|
||||||
cmpl $0,20(%ebx)
|
|
||||||
jne .L54
|
|
||||||
cmpb $0,24(%ebx)
|
|
||||||
jne .L54
|
|
||||||
pushl %ebx
|
|
||||||
call ObRemoveEntry
|
|
||||||
pushl %ebx
|
|
||||||
call ExFreePool
|
|
||||||
.L54:
|
|
||||||
xorl %eax,%eax
|
|
||||||
movl -4(%ebp),%ebx
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe10:
|
|
||||||
.size ObPerformRetentionChecks,.Lfe10-ObPerformRetentionChecks
|
|
||||||
.align 16
|
|
||||||
.globl ObDereferenceObject
|
|
||||||
.type ObDereferenceObject,@function
|
|
||||||
ObDereferenceObject:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
leal -36(%eax),%edx
|
|
||||||
decl -20(%eax)
|
|
||||||
pushl %edx
|
|
||||||
call ObPerformRetentionChecks
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe11:
|
|
||||||
.size ObDereferenceObject,.Lfe11-ObDereferenceObject
|
|
||||||
.align 16
|
|
||||||
.globl NtClose
|
|
||||||
.type NtClose,@function
|
|
||||||
NtClose:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call ZwClose
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.Lfe12:
|
|
||||||
.size NtClose,.Lfe12-NtClose
|
|
||||||
.align 16
|
|
||||||
.globl ZwClose
|
|
||||||
.type ZwClose,@function
|
|
||||||
ZwClose:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
pushl %eax
|
|
||||||
call KeGetCurrentProcess
|
|
||||||
pushl %eax
|
|
||||||
call ObTranslateHandle
|
|
||||||
movl %eax,%edx
|
|
||||||
addl $8,%esp
|
|
||||||
testl %edx,%edx
|
|
||||||
je .L59
|
|
||||||
movl (%edx),%eax
|
|
||||||
movl $0,(%edx)
|
|
||||||
leal -36(%eax),%edx
|
|
||||||
decl -16(%eax)
|
|
||||||
pushl %edx
|
|
||||||
call ObPerformRetentionChecks
|
|
||||||
xorl %eax,%eax
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.align 16
|
|
||||||
.L59:
|
|
||||||
movl $-1073741816,%eax
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret $4
|
|
||||||
.Lfe13:
|
|
||||||
.size ZwClose,.Lfe13-ZwClose
|
|
||||||
.align 16
|
|
||||||
.globl ObReferenceObjectByHandle
|
|
||||||
.type ObReferenceObjectByHandle,@function
|
|
||||||
ObReferenceObjectByHandle:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
pushl %edi
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
movl 8(%ebp),%eax
|
|
||||||
movl 16(%ebp),%ebx
|
|
||||||
movl 24(%ebp),%esi
|
|
||||||
pushl %eax
|
|
||||||
call KeGetCurrentProcess
|
|
||||||
pushl %eax
|
|
||||||
call ObTranslateHandle
|
|
||||||
testl %eax,%eax
|
|
||||||
je .L64
|
|
||||||
movl (%eax),%edx
|
|
||||||
testl %edx,%edx
|
|
||||||
jne .L63
|
|
||||||
.L64:
|
|
||||||
movl $-1073741816,%eax
|
|
||||||
jmp .L68
|
|
||||||
.align 16
|
|
||||||
.L63:
|
|
||||||
leal -36(%edx),%ecx
|
|
||||||
testl %ebx,%ebx
|
|
||||||
je .L66
|
|
||||||
cmpl %ebx,-4(%edx)
|
|
||||||
je .L66
|
|
||||||
movl $-2147483605,%eax
|
|
||||||
jmp .L68
|
|
||||||
.align 16
|
|
||||||
.L66:
|
|
||||||
movl 12(%ebp),%edi
|
|
||||||
testl %edi,4(%eax)
|
|
||||||
jne .L67
|
|
||||||
incl 16(%ecx)
|
|
||||||
movl (%eax),%eax
|
|
||||||
movl %eax,(%esi)
|
|
||||||
xorl %eax,%eax
|
|
||||||
jmp .L68
|
|
||||||
.align 16
|
|
||||||
.L67:
|
|
||||||
movl $-2147483557,%eax
|
|
||||||
.L68:
|
|
||||||
leal -12(%ebp),%esp
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
movl %ebp,%esp
|
|
||||||
popl %ebp
|
|
||||||
ret
|
|
||||||
.Lfe14:
|
|
||||||
.size ObReferenceObjectByHandle,.Lfe14-ObReferenceObjectByHandle
|
|
||||||
.ident "GCC: (GNU) 2.7.2.3"
|
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: ntoskrnl/ke/bug.c
|
* FILE: ntoskrnl/ps/idle.c
|
||||||
* PURPOSE: Graceful system shutdown if a bug is detected
|
* PURPOSE: Using idle time
|
||||||
* PROGRAMMER: David Welch (welch@mcmail.com)
|
* PROGRAMMER: David Welch (welch@cwcom.net)
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
* Created 22/05/98
|
* Created 22/05/98
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,9 +13,13 @@
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <internal/ps.h>
|
#include <internal/ps.h>
|
||||||
|
|
||||||
#define NDEBUG
|
//#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
|
/* GLBOALS *******************************************************************/
|
||||||
|
|
||||||
|
extern ULONG PiNrThreads;
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle,
|
NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle,
|
||||||
|
@ -51,6 +55,14 @@ NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID PsReleaseThread(PETHREAD Thread)
|
||||||
|
{
|
||||||
|
DPRINT("PsReleaseThread(Thread %x)\n",Thread);
|
||||||
|
|
||||||
|
RemoveEntryList(&Thread->Tcb.Entry);
|
||||||
|
ExFreePool(Thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus)
|
NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus)
|
||||||
/*
|
/*
|
||||||
|
@ -63,6 +75,8 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus)
|
||||||
KIRQL oldlvl;
|
KIRQL oldlvl;
|
||||||
PETHREAD CurrentThread;
|
PETHREAD CurrentThread;
|
||||||
|
|
||||||
|
PiNrThreads--;
|
||||||
|
|
||||||
CurrentThread = PsGetCurrentThread();
|
CurrentThread = PsGetCurrentThread();
|
||||||
|
|
||||||
CurrentThread->ExitStatus = ExitStatus;
|
CurrentThread->ExitStatus = ExitStatus;
|
||||||
|
@ -70,7 +84,6 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus)
|
||||||
DPRINT("terminating %x\n",CurrentThread);
|
DPRINT("terminating %x\n",CurrentThread);
|
||||||
KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);
|
KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);
|
||||||
CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED;
|
CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED;
|
||||||
RemoveEntryList(&CurrentThread->Tcb.Entry);
|
|
||||||
ZwYieldExecution();
|
ZwYieldExecution();
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <internal/mm.h>
|
#include <internal/mm.h>
|
||||||
#include <internal/string.h>
|
#include <internal/string.h>
|
||||||
|
|
||||||
#define NDEBUG
|
//#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
/* GLOBALS ******************************************************************/
|
/* GLOBALS ******************************************************************/
|
||||||
|
@ -157,20 +157,25 @@ NTSTATUS STDCALL ZwCreateProcess(
|
||||||
LARGE_INTEGER Offset;
|
LARGE_INTEGER Offset;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
DPRINT("ZwCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
|
||||||
|
|
||||||
Status = ObReferenceObjectByHandle(ParentProcessHandle,
|
Status = ObReferenceObjectByHandle(ParentProcessHandle,
|
||||||
PROCESS_CREATE_PROCESS,
|
PROCESS_CREATE_PROCESS,
|
||||||
PsProcessType,
|
PsProcessType,
|
||||||
UserMode,
|
UserMode,
|
||||||
&ParentProcessHandle,
|
&ParentProcessHandle,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (Status != STATUS_SUCCESS)
|
if (Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
DPRINT("ZwCreateProcess() = %x\n",Status);
|
DPRINT("ZwCreateProcess() = %x\n",Status);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Process = ObGenericCreateObject(ProcessHandle,DesiredAccess,
|
Process = ObGenericCreateObject(ProcessHandle,
|
||||||
ObjectAttributes,PsProcessType);
|
DesiredAccess,
|
||||||
|
ObjectAttributes,
|
||||||
|
PsProcessType);
|
||||||
KProcess = &(Process->Pcb);
|
KProcess = &(Process->Pcb);
|
||||||
|
|
||||||
InitializeListHead(&(KProcess->MemoryAreaList));
|
InitializeListHead(&(KProcess->MemoryAreaList));
|
||||||
|
@ -187,6 +192,14 @@ NTSTATUS STDCALL ZwCreateProcess(
|
||||||
PageDirectory[i]=CurrentPageDirectory[i];
|
PageDirectory[i]=CurrentPageDirectory[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: I don't what I'm supposed to know with a section handle
|
||||||
|
*/
|
||||||
|
if (SectionHandle != NULL)
|
||||||
|
{
|
||||||
|
DbgPrint("ZwCreateProcess() non-NULL SectionHandle\n");
|
||||||
|
return(STATUS_UNSUCCESSFUL);
|
||||||
|
}
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ static KSPIN_LOCK ThreadListLock = {0,};
|
||||||
*/
|
*/
|
||||||
static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},};
|
static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},};
|
||||||
static BOOLEAN DoneInitYet = FALSE;
|
static BOOLEAN DoneInitYet = FALSE;
|
||||||
|
ULONG PiNrThreads = 0;
|
||||||
|
|
||||||
static PETHREAD CurrentThread = NULL;
|
static PETHREAD CurrentThread = NULL;
|
||||||
|
|
||||||
|
@ -66,7 +67,8 @@ static VOID PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread)
|
||||||
{
|
{
|
||||||
KIRQL oldlvl;
|
KIRQL oldlvl;
|
||||||
|
|
||||||
DPRINT("PsInsertIntoThreadList(Priority %d, Thread %x)\n",Priority,Thread);
|
DPRINT("PsInsertIntoThreadList(Priority %x, Thread %x)\n",Priority,
|
||||||
|
Thread);
|
||||||
|
|
||||||
KeAcquireSpinLock(&ThreadListLock,&oldlvl);
|
KeAcquireSpinLock(&ThreadListLock,&oldlvl);
|
||||||
InsertTailList(&PriorityListHead[THREAD_PRIORITY_MAX+Priority],
|
InsertTailList(&PriorityListHead[THREAD_PRIORITY_MAX+Priority],
|
||||||
|
@ -91,12 +93,19 @@ static PETHREAD PsScanThreadList(KPRIORITY Priority)
|
||||||
PETHREAD oldest = NULL;
|
PETHREAD oldest = NULL;
|
||||||
ULONG oldest_time = 0;
|
ULONG oldest_time = 0;
|
||||||
|
|
||||||
DPRINT("PsScanThreadList(Priority %d)\n",Priority);
|
// DPRINT("PsScanThreadList(Priority %d)\n",Priority);
|
||||||
|
|
||||||
current_entry = PriorityListHead[THREAD_PRIORITY_MAX+Priority].Flink;
|
current_entry = PriorityListHead[THREAD_PRIORITY_MAX+Priority].Flink;
|
||||||
while (current_entry != &PriorityListHead[THREAD_PRIORITY_MAX+Priority])
|
while (current_entry != &PriorityListHead[THREAD_PRIORITY_MAX+Priority])
|
||||||
{
|
{
|
||||||
current = CONTAINING_RECORD(current_entry,ETHREAD,Tcb.Entry);
|
current = CONTAINING_RECORD(current_entry,ETHREAD,Tcb.Entry);
|
||||||
|
#if 0
|
||||||
|
if (current->Tcb.ThreadState == THREAD_STATE_TERMINATED &&
|
||||||
|
current != CurrentThread)
|
||||||
|
{
|
||||||
|
PsReleaseThread(CurrentThread);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (current->Tcb.ThreadState == THREAD_STATE_RUNNABLE)
|
if (current->Tcb.ThreadState == THREAD_STATE_RUNNABLE)
|
||||||
{
|
{
|
||||||
if (oldest == NULL || oldest_time > current->Tcb.LastTick)
|
if (oldest == NULL || oldest_time > current->Tcb.LastTick)
|
||||||
|
@ -107,7 +116,7 @@ static PETHREAD PsScanThreadList(KPRIORITY Priority)
|
||||||
}
|
}
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
}
|
}
|
||||||
DPRINT("PsScanThreadList() = %x\n",oldest);
|
// DPRINT("PsScanThreadList() = %x\n",oldest);
|
||||||
return(oldest);
|
return(oldest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,16 +148,16 @@ VOID PsDispatchThread(VOID)
|
||||||
Candidate = PsScanThreadList(CurrentPriority);
|
Candidate = PsScanThreadList(CurrentPriority);
|
||||||
if (Candidate == CurrentThread)
|
if (Candidate == CurrentThread)
|
||||||
{
|
{
|
||||||
DPRINT("Scheduling current thread\n");
|
// DbgPrint("Scheduling current thread\n");
|
||||||
KeQueryTickCount(&TickCount);
|
KeQueryTickCount(&TickCount);
|
||||||
CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount);
|
CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount);
|
||||||
CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING;
|
CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING;
|
||||||
KeReleaseSpinLock(&ThreadListLock,irql);
|
KeReleaseSpinLock(&ThreadListLock,irql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Candidate != NULL)
|
if (Candidate != NULL)
|
||||||
{
|
{
|
||||||
DPRINT("Scheduling %x\n",Candidate);
|
// DbgPrint("Scheduling %x\n",Candidate);
|
||||||
|
|
||||||
Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING;
|
Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING;
|
||||||
|
|
||||||
|
@ -175,6 +184,8 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
|
||||||
PETHREAD Thread;
|
PETHREAD Thread;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
PiNrThreads++;
|
||||||
|
|
||||||
Thread = ObGenericCreateObject(ThreadHandle,
|
Thread = ObGenericCreateObject(ThreadHandle,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
ThreadAttributes,
|
ThreadAttributes,
|
||||||
|
@ -202,15 +213,23 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Thread->ThreadsProcess=SystemProcess;
|
Thread->ThreadsProcess=SystemProcess;
|
||||||
|
ObReferenceObjectByPointer(Thread->ThreadsProcess,
|
||||||
|
PROCESS_CREATE_THREAD,
|
||||||
|
PsProcessType,
|
||||||
|
UserMode);
|
||||||
}
|
}
|
||||||
|
ObReferenceObjectByPointer(Thread->ThreadsProcess,
|
||||||
|
PROCESS_CREATE_THREAD,
|
||||||
|
PsProcessType,
|
||||||
|
UserMode);
|
||||||
InitializeListHead(Thread->Tcb.ApcList);
|
InitializeListHead(Thread->Tcb.ApcList);
|
||||||
InitializeListHead(&(Thread->IrpList));
|
InitializeListHead(&(Thread->IrpList));
|
||||||
Thread->Cid.UniqueThread=NextThreadUniqueId++;
|
Thread->Cid.UniqueThread=InterlockedIncrement(&NextThreadUniqueId);
|
||||||
// thread->Cid.ThreadId=InterlockedIncrement(&NextThreadUniqueId);
|
|
||||||
PsInsertIntoThreadList(Thread->Tcb.CurrentPriority,Thread);
|
PsInsertIntoThreadList(Thread->Tcb.CurrentPriority,Thread);
|
||||||
|
|
||||||
*ThreadPtr = Thread;
|
*ThreadPtr = Thread;
|
||||||
|
|
||||||
|
ObDereferenceObject(Thread->ThreadsProcess);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +344,9 @@ NTSTATUS ZwCreateThread(PHANDLE ThreadHandle,
|
||||||
PETHREAD Thread;
|
PETHREAD Thread;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
DbgPrint("ZwCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
|
||||||
|
ThreadHandle,ThreadContext);
|
||||||
|
|
||||||
Status = PsInitializeThread(ProcessHandle,&Thread,ThreadHandle,
|
Status = PsInitializeThread(ProcessHandle,&Thread,ThreadHandle,
|
||||||
DesiredAccess,ObjectAttributes);
|
DesiredAccess,ObjectAttributes);
|
||||||
if (Status != STATUS_SUCCESS)
|
if (Status != STATUS_SUCCESS)
|
||||||
|
@ -509,6 +531,7 @@ NTSTATUS STDCALL ZwResumeThread(IN HANDLE ThreadHandle,
|
||||||
Thread->Tcb.ThreadState = THREAD_STATE_RUNNABLE;
|
Thread->Tcb.ThreadState = THREAD_STATE_RUNNABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObDereferenceObject(Thread);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,6 +593,7 @@ NTSTATUS STDCALL ZwSuspendThread(IN HANDLE ThreadHandle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObDereferenceObject(Thread);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,22 @@ bits 32
|
||||||
section .text
|
section .text
|
||||||
|
|
||||||
DECLARE_GLOBAL_SYMBOL InterlockedIncrement
|
DECLARE_GLOBAL_SYMBOL InterlockedIncrement
|
||||||
|
push ebp
|
||||||
|
mov ebp,esp
|
||||||
|
|
||||||
|
push eax
|
||||||
|
push ebx
|
||||||
|
|
||||||
mov eax,1
|
mov eax,1
|
||||||
mov ebx,[esp+4]
|
mov ebx,[ebp+8]
|
||||||
xadd [ebx],eax
|
xadd [ebx],eax
|
||||||
|
|
||||||
|
pop ebx
|
||||||
|
pop eax
|
||||||
|
|
||||||
|
mov esp,ebp
|
||||||
|
pop ebp
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -221,27 +221,27 @@ VOID RtlCopyString(IN OUT PSTRING DestinationString, IN PSTRING SourceString)
|
||||||
VOID RtlCopyUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
VOID RtlCopyUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
||||||
IN PUNICODE_STRING SourceString)
|
IN PUNICODE_STRING SourceString)
|
||||||
{
|
{
|
||||||
unsigned long copylen, i;
|
unsigned long copylen, i;
|
||||||
|
|
||||||
if(SourceString==NULL) {
|
if(SourceString==NULL)
|
||||||
DestinationString->Length=0;
|
{
|
||||||
} else {
|
DestinationString->Length=0;
|
||||||
if(SourceString->Length<DestinationString->MaximumLength) {
|
}
|
||||||
copylen=SourceString->Length;
|
else
|
||||||
} else {
|
{
|
||||||
copylen=DestinationString->MaximumLength;
|
copylen = min(DestinationString->MaximumLength,
|
||||||
};
|
SourceString->Length);
|
||||||
for(i=0; i<copylen; i++)
|
for(i=0; i<copylen; i++)
|
||||||
{
|
{
|
||||||
*DestinationString->Buffer=*SourceString->Buffer;
|
*DestinationString->Buffer=*SourceString->Buffer;
|
||||||
DestinationString->Buffer++;
|
DestinationString->Buffer++;
|
||||||
SourceString->Buffer++;
|
SourceString->Buffer++;
|
||||||
};
|
}
|
||||||
*DestinationString->Buffer=0;
|
*DestinationString->Buffer=0;
|
||||||
DestinationString->Buffer-=copylen;
|
DestinationString->Buffer-=copylen;
|
||||||
SourceString->Buffer-=copylen;
|
SourceString->Buffer-=copylen;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
BOOLEAN RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive)
|
BOOLEAN RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive)
|
||||||
{
|
{
|
||||||
|
@ -350,20 +350,24 @@ VOID RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
|
||||||
IN PCWSTR SourceString)
|
IN PCWSTR SourceString)
|
||||||
{
|
{
|
||||||
unsigned long i, DestSize;
|
unsigned long i, DestSize;
|
||||||
UNICODE_STRING Dest=*DestinationString;
|
|
||||||
|
|
||||||
if(SourceString==NULL) {
|
DPRINT("RtlInitUnicodeString(DestinationString %x, "
|
||||||
|
"SourceString %x)\n",DestinationString,SourceString);
|
||||||
|
|
||||||
|
if (SourceString==NULL)
|
||||||
|
{
|
||||||
DestinationString->Length=0;
|
DestinationString->Length=0;
|
||||||
DestinationString->MaximumLength=0;
|
DestinationString->MaximumLength=0;
|
||||||
DestinationString->Buffer=NULL;
|
DestinationString->Buffer=NULL;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DestSize=wstrlen((PWSTR)SourceString);
|
DestSize=wstrlen((PWSTR)SourceString);
|
||||||
DestinationString->Length=DestSize;
|
DestinationString->Length=DestSize;
|
||||||
DestinationString->MaximumLength=DestSize+1;
|
DestinationString->MaximumLength=DestSize+1;
|
||||||
|
|
||||||
DestinationString->Buffer=(PWSTR)SourceString;
|
DestinationString->Buffer=(PWSTR)SourceString;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
NTSTATUS RtlIntegerToUnicodeString(IN ULONG Value, IN ULONG Base, /* optional */
|
NTSTATUS RtlIntegerToUnicodeString(IN ULONG Value, IN ULONG Base, /* optional */
|
||||||
IN OUT PUNICODE_STRING String)
|
IN OUT PUNICODE_STRING String)
|
||||||
|
|
|
@ -129,7 +129,7 @@ VOID ExExecuteShell(VOID)
|
||||||
|
|
||||||
BaseAddress = (PVOID)0x10000;
|
BaseAddress = (PVOID)0x10000;
|
||||||
LARGE_INTEGER_QUAD_PART(SectionOffset) = 0;
|
LARGE_INTEGER_QUAD_PART(SectionOffset) = 0;
|
||||||
Size = 0x10000;
|
Size = 0x20000;
|
||||||
ZwMapViewOfSection(SectionHandle,
|
ZwMapViewOfSection(SectionHandle,
|
||||||
ShellHandle,
|
ShellHandle,
|
||||||
&BaseAddress,
|
&BaseAddress,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue