mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 00:54:40 +00:00
Added ZwQueryFileInformation
svn path=/trunk/; revision=113
This commit is contained in:
parent
bc06faa8cd
commit
683ed8c5a1
10 changed files with 311 additions and 512 deletions
|
@ -1,158 +0,0 @@
|
|||
#include <stdarg.h>
|
||||
#include <windows.h>
|
||||
|
||||
HANDLE stdin;
|
||||
HANDLE stdout;
|
||||
|
||||
|
||||
void Console_puts(char* str)
|
||||
{
|
||||
ULONG nchar;
|
||||
|
||||
WriteConsole(stdout,
|
||||
str,
|
||||
strlen(str),
|
||||
&nchar,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void Console_printf(char* fmt, ...)
|
||||
{
|
||||
char buffer[255];
|
||||
va_list vargs;
|
||||
|
||||
va_start(vargs,fmt);
|
||||
vsprintf(buffer,fmt,vargs);
|
||||
Console_puts(buffer);
|
||||
va_end(vargs);
|
||||
}
|
||||
|
||||
void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength)
|
||||
{
|
||||
char ch;
|
||||
DWORD nbytes;
|
||||
|
||||
Console_puts(Prompt);
|
||||
|
||||
ReadConsole(stdin,
|
||||
Output,
|
||||
OutputLength,
|
||||
&nbytes,
|
||||
NULL);
|
||||
Output[nbytes-2]=0;
|
||||
}
|
||||
|
||||
void func_cd(char* s)
|
||||
{
|
||||
Console_printf("Changing directory to %s\n",s);
|
||||
if (!SetCurrentDirectory(s))
|
||||
{
|
||||
Console_puts("Failed to change to directory\n");
|
||||
}
|
||||
}
|
||||
|
||||
void func_dir(char* s)
|
||||
{
|
||||
HANDLE shandle;
|
||||
WIN32_FIND_DATA FindData;
|
||||
|
||||
shandle = FindFirstFile("*.*",&FindData);
|
||||
|
||||
if (shandle==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
do
|
||||
{
|
||||
Console_printf("Scanning %s\n",FindData.cFileName);
|
||||
} while(FindNextFile(shandle,&FindData));
|
||||
}
|
||||
|
||||
int is_builtin(char* name, char* args)
|
||||
{
|
||||
if (strcmp(name,"dir")==0)
|
||||
{
|
||||
func_dir(args);
|
||||
return(1);
|
||||
}
|
||||
if (strcmp(name,"cd")==0)
|
||||
{
|
||||
func_cd(args);
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int process_command(char* str)
|
||||
{
|
||||
char* name;
|
||||
char* args;
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si;
|
||||
char process_arg[255];
|
||||
|
||||
if (strcmp(str,"exit")==0)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
name = strtok(str," \t");
|
||||
args = strtok(NULL,"");
|
||||
|
||||
if (is_builtin(name,args))
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
memset(&si,0,sizeof(STARTUPINFO));
|
||||
si.cb=sizeof(STARTUPINFO);
|
||||
si.lpTitle=strdup(name);
|
||||
|
||||
strcpy(process_arg,name);
|
||||
strcat(process_arg," ");
|
||||
if(args!=NULL)
|
||||
{
|
||||
strcat(process_arg,args);
|
||||
}
|
||||
Console_printf("name '%s' process_arg '%s'\n",name,process_arg);
|
||||
if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE,
|
||||
CREATE_NEW_CONSOLE,
|
||||
NULL,NULL,&si,&pi))
|
||||
{
|
||||
Console_printf("Failed to execute process\n");
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void build_prompt(char* prompt)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = GetCurrentDirectory(255,prompt);
|
||||
strcat(prompt,">");
|
||||
}
|
||||
|
||||
void command_loop()
|
||||
{
|
||||
char line[255];
|
||||
char prompt[255];
|
||||
int do_exit = 0;
|
||||
|
||||
while (!do_exit)
|
||||
{
|
||||
build_prompt(prompt);
|
||||
Console_getline(prompt,line,255);
|
||||
Console_printf("Processing command '%s'\n",line);
|
||||
do_exit = process_command(line);
|
||||
}
|
||||
}
|
||||
|
||||
int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
|
||||
{
|
||||
AllocConsole();
|
||||
stdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
command_loop();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
all: cmd.bin
|
||||
|
||||
OBJECTS = ../common/crt0.o cmd.o
|
||||
|
||||
LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \
|
||||
../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a
|
||||
|
||||
cmd.bin: $(OBJECTS)
|
||||
$(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe
|
||||
$(OBJCOPY) -O binary cmd.exe cmd.bin
|
||||
|
||||
include ../../rules.mak
|
|
@ -263,52 +263,6 @@ enum
|
|||
#define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
|
||||
#define FILE_VALID_SET_FLAGS 0x00001036
|
||||
|
||||
/*
|
||||
* file information
|
||||
*/
|
||||
#define FileDirectoryInformation 1
|
||||
#define FileFullDirectoryInformation 2
|
||||
#define FileBothDirectoryInformation 3
|
||||
#define FileBasicInformation 4
|
||||
#define FileStandardInformation 5
|
||||
#define FileInternalInformation 6
|
||||
#define FileEaInformation 7
|
||||
#define FileAccessInformation 8
|
||||
#define FileNameInformation 9
|
||||
#define FileRenameInformation 10
|
||||
#define FileLinkInformation 11
|
||||
#define FileNamesInformation 12
|
||||
#define FileDispositionInformation 13
|
||||
#define FilePositionInformation 14
|
||||
#define FileFullEaInformation 15
|
||||
#define FileModeInformation 16
|
||||
#define FileAlignmentInformation 17
|
||||
#define FileAllInformation 18
|
||||
#define FileAllocationInformation 19
|
||||
#define FileEndOfFileInformation 20
|
||||
#define FileAlternateNameInformation 21
|
||||
#define FileStreamInformation 22
|
||||
#define FilePipeInformation 23
|
||||
#define FilePipeLocalInformation 24
|
||||
#define FilePipeRemoteInformation 25
|
||||
#define FileMailslotQueryInformation 26
|
||||
#define FileMailslotSetInformation 27
|
||||
#define FileCompressionInformation 28
|
||||
#define FileCopyOnWriteInformation 29
|
||||
#define FileCompletionInformation 30
|
||||
#define FileMoveClusterInformation 31
|
||||
#define FileOleClassIdInformation 32
|
||||
#define FileOleStateBitsInformation 33
|
||||
#define FileNetworkOpenInformation 34
|
||||
#define FileObjectIdInformation 35
|
||||
#define FileOleAllInformation 36
|
||||
#define FileOleDirectoryInformation 37
|
||||
#define FileContentIndexInformation 38
|
||||
#define FileInheritContentIndexInformation 39
|
||||
#define FileOleInformation 40
|
||||
#define FileMaximumInformation 41
|
||||
|
||||
|
||||
|
||||
typedef ULONG FS_INFORMATION_CLASS;
|
||||
|
||||
|
|
|
@ -55,8 +55,54 @@ typedef ULONG POOL_TYPE;
|
|||
typedef ULONG TIMER_TYPE;
|
||||
typedef ULONG MM_SYSTEM_SIZE;
|
||||
typedef ULONG LOCK_OPERATION;
|
||||
|
||||
/* File information for IRP_MJ_QUERY_INFORMATION (and SET) */
|
||||
typedef enum _FILE_INFORMATION_CLASS
|
||||
{
|
||||
FileDirectoryInformation = 1,
|
||||
FileFullDirectoryInformation,
|
||||
FileBothDirectoryInformation,
|
||||
FileBasicInformation,
|
||||
FileStandardInformation,
|
||||
FileInternalInformation,
|
||||
FileEaInformation,
|
||||
FileAccessInformation,
|
||||
FileNameInformation,
|
||||
FileRenameInformation,
|
||||
FileLinkInformation,
|
||||
FileNamesInformation,
|
||||
FileDispositionInformation,
|
||||
FilePositionInformation,
|
||||
FileFullEaInformation,
|
||||
FileModeInformation,
|
||||
FileAlignmentInformation,
|
||||
FileAllInformation,
|
||||
FileAllocationInformation,
|
||||
FileEndOfFileInformation,
|
||||
FileAlternateNameInformation,
|
||||
FileStreamInformation,
|
||||
FilePipeInformation,
|
||||
FilePipeLocalInformation,
|
||||
FilePipeRemoteInformation,
|
||||
FileMailslotQueryInformation,
|
||||
FileMailslotSetInformation,
|
||||
FileCompressionInformation,
|
||||
FileCopyOnWriteInformation,
|
||||
FileCompletionInformation,
|
||||
FileMoveClusterInformation,
|
||||
FileOleClassIdInformation,
|
||||
FileOleStateBitsInformation,
|
||||
FileNetworkOpenInformation,
|
||||
FileObjectIdInformation,
|
||||
FileOleAllInformation,
|
||||
FileOleDirectoryInformation,
|
||||
FileContentIndexInformation,
|
||||
FileInheritContentIndexInformation,
|
||||
FileOleInformation,
|
||||
FileMaximumInformation,
|
||||
} FILE_INFORMATION_CLASS;
|
||||
|
||||
typedef ULONG KEY_INFORMATION_CLASS;
|
||||
typedef ULONG FILE_INFORMATION_CLASS;
|
||||
typedef ULONG KEY_VALUE_INFORMATION_CLASS;
|
||||
typedef LARGE_INTEGER PHYSICAL_ADDRESS;
|
||||
typedef PHYSICAL_ADDRESS* PPHYSICAL_ADDRESS;
|
||||
|
|
|
@ -25,9 +25,6 @@
|
|||
#define FILE_OVERWRITE_IF 0x0005
|
||||
#define FILE_MAXIMUM_DISPOSITION 0x0005
|
||||
|
||||
|
||||
|
||||
|
||||
//process query / set information class
|
||||
|
||||
#define ProcessBasicInformation 0
|
||||
|
@ -72,15 +69,12 @@
|
|||
#define ThreadPriorityBoost 14
|
||||
#define MaxThreadInfoClass 15
|
||||
|
||||
|
||||
|
||||
// key query information class
|
||||
|
||||
#define KeyBasicInformation 0
|
||||
#define KeyNodeInformation 1
|
||||
#define KeyFullInformation 2
|
||||
|
||||
|
||||
// key set information class
|
||||
|
||||
#define KeyWriteTimeInformation 0
|
||||
|
@ -107,16 +101,12 @@
|
|||
|
||||
#define EventBasicInformation 0
|
||||
|
||||
|
||||
// system information
|
||||
|
||||
#define SystemPerformanceInformation 5
|
||||
#define SystemCacheInformation 21
|
||||
#define SystemTimeAdjustmentInformation 28
|
||||
|
||||
|
||||
|
||||
|
||||
// shutdown action
|
||||
|
||||
typedef enum SHUTDOWN_ACTION_TAG {
|
||||
|
@ -125,26 +115,21 @@ typedef enum SHUTDOWN_ACTION_TAG {
|
|||
ShutdownPowerOff
|
||||
} SHUTDOWN_ACTION;
|
||||
|
||||
|
||||
|
||||
// wait type
|
||||
|
||||
#define WaitAll 0
|
||||
#define WaitAny 1
|
||||
|
||||
|
||||
// key restore flags
|
||||
|
||||
#define REG_WHOLE_HIVE_VOLATILE 1
|
||||
#define REG_REFRESH_HIVE 2
|
||||
|
||||
|
||||
// object type access rights
|
||||
|
||||
#define OBJECT_TYPE_CREATE 0x0001
|
||||
#define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
|
||||
|
||||
|
||||
// directory access rights
|
||||
|
||||
#define DIRECTORY_QUERY 0x0001
|
||||
|
@ -315,10 +300,6 @@ typedef struct _SYSTEM_CACHE_INFORMATION {
|
|||
ULONG Unused[4];
|
||||
} SYSTEM_CACHE_INFORMATION;
|
||||
|
||||
|
||||
|
||||
// file information
|
||||
|
||||
typedef struct _FILE_BASIC_INFORMATION
|
||||
{
|
||||
TIME CreationTime;
|
||||
|
|
|
@ -16,7 +16,97 @@
|
|||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
NTSTATUS ZwQueryInformationFile(HANDLE FileHandle,
|
||||
NTSTATUS
|
||||
NtQueryInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
{
|
||||
return ZwQueryInformationFile(FileHandle,
|
||||
IoStatusBlock,
|
||||
FileInformation,
|
||||
Length,
|
||||
FileInformationClass);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
ZwQueryInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PFILE_OBJECT FileObject;
|
||||
PIRP Irp;
|
||||
PIO_STACK_LOCATION StackPtr;
|
||||
KEVENT Event;
|
||||
|
||||
DPRINT("ZwQueryInformation(Handle %x StatBlk %x FileInfo %x Length %d Class %d)\n",
|
||||
FileHandle,
|
||||
IoStatusBlock,
|
||||
FileInformation,
|
||||
Length,
|
||||
FileInformationClass);
|
||||
|
||||
/* Get the file object from the file handle */
|
||||
Status = ObReferenceObjectByHandle(FileHandle,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
NULL,
|
||||
UserMode,
|
||||
(PVOID *) &FileObject,
|
||||
NULL);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
DPRINT("FileObject %x\n", FileObject);
|
||||
|
||||
/* initialize an event object to wait on for the request */
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
/* build the IRP to be sent to the driver for the request */
|
||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_QUERY_INFORMATION,
|
||||
FileObject->DeviceObject,
|
||||
FileInformation,
|
||||
Length,
|
||||
0,
|
||||
&Event,
|
||||
IoStatusBlock);
|
||||
StackPtr = IoGetNextIrpStackLocation(Irp);
|
||||
StackPtr->FileObject = FileObject;
|
||||
StackPtr->Parameters.QueryFile.Length = Length;
|
||||
StackPtr->Parameters.QueryFile.FileInformationClass = FileInformationClass;
|
||||
|
||||
/* Pass the IRP to the FSD (and wait for it if required) */
|
||||
DPRINT("FileObject->DeviceObject %x\n", FileObject->DeviceObject);
|
||||
Status = IoCallDriver(FileObject->DeviceObject, Irp);
|
||||
if (Status == STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO))
|
||||
{
|
||||
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
||||
Status = Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NtSetInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
{
|
||||
return ZwSetInformationFile(FileHandle,
|
||||
IoStatusBlock,
|
||||
FileInformation,
|
||||
Length,
|
||||
FileInformationClass);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
ZwSetInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
|
@ -25,78 +115,39 @@ NTSTATUS ZwQueryInformationFile(HANDLE FileHandle,
|
|||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS NtQueryInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
PGENERIC_MAPPING
|
||||
IoGetFileObjectGenericMapping(VOID)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS ZwSetInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
NTSTATUS STDCALL
|
||||
NtQueryAttributesFile(IN HANDLE FileHandle,
|
||||
IN PVOID Buffer)
|
||||
{
|
||||
return ZwQueryAttributesFile(FileHandle, Buffer);
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL
|
||||
ZwQueryAttributesFile(IN HANDLE FileHandle, IN PVOID Buffer)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS NtSetInformationFile(HANDLE FileHandle,
|
||||
PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID FileInformation,
|
||||
ULONG Length,
|
||||
FILE_INFORMATION_CLASS FileInformationClass)
|
||||
NTSTATUS STDCALL
|
||||
NtQueryFullAttributesFile(IN HANDLE FileHandle, IN PVOID Attributes)
|
||||
{
|
||||
return ZwQueryFullAttributesFile(FileHandle, Attributes);
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL
|
||||
ZwQueryFullAttributesFile(IN HANDLE FileHandle, IN PVOID Attributes)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
PGENERIC_MAPPING IoGetFileObjectGenericMapping()
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
NtQueryAttributesFile(
|
||||
IN HANDLE FileHandle,
|
||||
IN PVOID Buffer
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
ZwQueryAttributesFile(
|
||||
IN HANDLE FileHandle,
|
||||
IN PVOID Buffer
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
NtQueryFullAttributesFile(
|
||||
IN HANDLE FileHandle,
|
||||
IN PVOID Attributes
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
ZwQueryFullAttributesFile(
|
||||
IN HANDLE FileHandle,
|
||||
IN PVOID Attributes
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
NtQueryEaFile(
|
||||
IN HANDLE FileHandle,
|
||||
NTSTATUS STDCALL
|
||||
NtQueryEaFile(IN HANDLE FileHandle,
|
||||
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG Length,
|
||||
|
@ -104,29 +155,52 @@ NtQueryEaFile(
|
|||
IN PVOID EaList OPTIONAL,
|
||||
IN ULONG EaListLength,
|
||||
IN PULONG EaIndex OPTIONAL,
|
||||
IN BOOLEAN RestartScan
|
||||
)
|
||||
IN BOOLEAN RestartScan)
|
||||
{
|
||||
return NtQueryEaFile(FileHandle,
|
||||
IoStatusBlock,
|
||||
Buffer,
|
||||
Length,
|
||||
ReturnSingleEntry,
|
||||
EaList,
|
||||
EaListLength,
|
||||
EaIndex,
|
||||
RestartScan);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
NtSetEaFile(
|
||||
IN HANDLE FileHandle,
|
||||
IN PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID EaBuffer,
|
||||
ULONG EaBufferSize
|
||||
)
|
||||
NTSTATUS STDCALL
|
||||
ZwQueryEaFile(IN HANDLE FileHandle,
|
||||
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG Length,
|
||||
IN BOOLEAN ReturnSingleEntry,
|
||||
IN PVOID EaList OPTIONAL,
|
||||
IN ULONG EaListLength,
|
||||
IN PULONG EaIndex OPTIONAL,
|
||||
IN BOOLEAN RestartScan)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
STDCALL
|
||||
ZwSetEaFile(
|
||||
IN HANDLE FileHandle,
|
||||
NTSTATUS STDCALL
|
||||
NtSetEaFile(IN HANDLE FileHandle,
|
||||
IN PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID EaBuffer,
|
||||
ULONG EaBufferSize
|
||||
)
|
||||
ULONG EaBufferSize)
|
||||
{
|
||||
return ZwSetEaFile(FileHandle,
|
||||
IoStatusBlock,
|
||||
EaBuffer,
|
||||
EaBufferSize);
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL
|
||||
ZwSetEaFile(IN HANDLE FileHandle,
|
||||
IN PIO_STATUS_BLOCK IoStatusBlock,
|
||||
PVOID EaBuffer,
|
||||
ULONG EaBufferSize)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -86,39 +86,122 @@ NTSTATUS LdrLoadDriver(PUNICODE_STRING FileName)
|
|||
return LdrProcessImage(SectionHandle, BaseAddress);
|
||||
}
|
||||
|
||||
NTSTATUS LdrLoadImage(PUNICODE_STRING FileName)
|
||||
/*
|
||||
* FUNCTION: Loads a PE executable into the current process
|
||||
* FUNCTION: Loads a PE executable into the specified process
|
||||
* ARGUMENTS:
|
||||
* FileName = File to load
|
||||
* Filename = File to load
|
||||
* ProcessHandle = handle
|
||||
* RETURNS: Status
|
||||
*/
|
||||
|
||||
NTSTATUS
|
||||
LdrLoadImage(PUNICODE_STRING Filename, HANDLE ProcessHandle)
|
||||
{
|
||||
char BlockBuffer[512];
|
||||
NTSTATUS Status;
|
||||
HANDLE FileHandle;
|
||||
OBJECT_ATTRIBUTES FileObjectAttributes;
|
||||
PIMAGE_DOS_HEADER PEDosHeader;
|
||||
PIMAGE_NT_HEADERS PEHeader;
|
||||
|
||||
HANDLE SectionHandle;
|
||||
ANSI_STRING AnsiFileName;
|
||||
UNICODE_STRING UnicodeFileName;
|
||||
OBJECT_ATTRIBUTES FileAttributes;
|
||||
PVOID BaseAddress;
|
||||
|
||||
// Open the image file or die
|
||||
RtlInitAnsiString(&AnsiFileName, FileName);
|
||||
RtlAnsiStringToUnicodeString(&UnicodeFileName, &AnsiFileName, TRUE);
|
||||
InitializeObjectAttributes(&FileAttributes,
|
||||
&UnicodeFileName,
|
||||
/* Open the image file */
|
||||
InitializeObjectAttributes(&FileObjectAttributes,
|
||||
&Filename,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
FileHandle = ZwFileOpen(&FileHandle, 0, &FileAttributes, NULL, 0, 0);
|
||||
Status = ZwFileOpen(&FileHandle, 0, &FileObjectAttributes, NULL, 0, 0);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
RtlFreeUnicodeString(&UnicodeFileName);
|
||||
|
||||
// FIXME: should DLLs be named sections?
|
||||
// FIXME: get current process and associate with section
|
||||
/* Read first block of image to determine type */
|
||||
Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 512, 0, 0);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
ZwClose(FileHandle);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* If MZ header exists */
|
||||
PEDosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
|
||||
if (PEDosHeader->e_magic == 0x54AD)
|
||||
{
|
||||
/* FIXME: if PE header exists */
|
||||
/* FIXME: load PE image */
|
||||
/* FIXME: else */
|
||||
/* FIXME: load MZ image */
|
||||
}
|
||||
else /* Assume bin format and load */
|
||||
/* FIXME: could check for a.out, ELF, COFF, etc. images here... */
|
||||
{
|
||||
Status = ZwCreateSection(&SectionHandle,
|
||||
SECTION_ALL_ACCESS,
|
||||
NULL,
|
||||
NULL,
|
||||
PAGE_READWRITE,
|
||||
MEM_COMMIT,
|
||||
FileHandle);
|
||||
ZwClose(FileHandle);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
BaseAddress = (PVOID)0x10000;
|
||||
SectionOffset.HighPart = 0;
|
||||
SectionOffset.LowPart = 0;
|
||||
|
||||
/* FIXME: get the size of the file */
|
||||
Size = 0x8000;
|
||||
|
||||
ZwMapViewOfSection(SectionHandle,
|
||||
ProcessHandle,
|
||||
&BaseAddress,
|
||||
0,
|
||||
0x8000,
|
||||
&SectionOffset,
|
||||
&Size,
|
||||
0,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
|
||||
memset(&Context,0,sizeof(CONTEXT));
|
||||
|
||||
Context.SegSs = USER_DS;
|
||||
Context.Esp = 0x2000;
|
||||
Context.EFlags = 0x202;
|
||||
Context.SegCs = USER_CS;
|
||||
Context.Eip = 0x10000;
|
||||
Context.SegDs = USER_DS;
|
||||
Context.SegEs = USER_DS;
|
||||
Context.SegFs = USER_DS;
|
||||
Context.SegGs = USER_DS;
|
||||
|
||||
BaseAddress = 0x1000;
|
||||
StackSize = 0x1000;
|
||||
ZwAllocateVirtualMemory(ProcessHandle,
|
||||
&BaseAddress,
|
||||
0,
|
||||
&StackSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
ZwCreateThread(&ThreadHandle,
|
||||
THREAD_ALL_ACCESS,
|
||||
NULL,
|
||||
ShellHandle,
|
||||
NULL,
|
||||
&Context,
|
||||
NULL,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
/* FIXME: should DLLs be named sections? */
|
||||
/* FIXME: get current process and associate with section */
|
||||
|
||||
// Map the image into a section or die
|
||||
Status = ZwCreateSection(&SectionHandle,
|
||||
|
|
|
@ -70,8 +70,9 @@ endif
|
|||
|
||||
CC = $(PREFIX)gcc
|
||||
NATIVE_CC = gcc
|
||||
CFLAGS = -O2 -I../../../include -I../../include -I../include -fno-builtin \
|
||||
$(LEAN_AND_MEAN_DEFINE) $(DEFINES) -Wall -Wstrict-prototypes $(DEBUGGING_CFLAGS)
|
||||
CFLAGS = -O2 -I../../../include -I../../include \
|
||||
-I../include -fno-builtin $(LEAN_AND_MEAN_DEFINE) \
|
||||
$(DEFINES) -Wall -Wstrict-prototypes $(DEBUGGING_CFLAGS)
|
||||
CXXFLAGS = $(CFLAGS)
|
||||
NASM_CMD = nasmw
|
||||
NFLAGS = -i../../include/ -i../include/ -pinternal/asm.inc -f$(NASM_FORMAT) -d$(NASM_FORMAT)
|
||||
|
|
|
@ -1,158 +0,0 @@
|
|||
#include <stdarg.h>
|
||||
#include <windows.h>
|
||||
|
||||
HANDLE stdin;
|
||||
HANDLE stdout;
|
||||
|
||||
|
||||
void Console_puts(char* str)
|
||||
{
|
||||
ULONG nchar;
|
||||
|
||||
WriteConsole(stdout,
|
||||
str,
|
||||
strlen(str),
|
||||
&nchar,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void Console_printf(char* fmt, ...)
|
||||
{
|
||||
char buffer[255];
|
||||
va_list vargs;
|
||||
|
||||
va_start(vargs,fmt);
|
||||
vsprintf(buffer,fmt,vargs);
|
||||
Console_puts(buffer);
|
||||
va_end(vargs);
|
||||
}
|
||||
|
||||
void Console_getline(PCH Prompt, PCH Output, DWORD OutputLength)
|
||||
{
|
||||
char ch;
|
||||
DWORD nbytes;
|
||||
|
||||
Console_puts(Prompt);
|
||||
|
||||
ReadConsole(stdin,
|
||||
Output,
|
||||
OutputLength,
|
||||
&nbytes,
|
||||
NULL);
|
||||
Output[nbytes-2]=0;
|
||||
}
|
||||
|
||||
void func_cd(char* s)
|
||||
{
|
||||
Console_printf("Changing directory to %s\n",s);
|
||||
if (!SetCurrentDirectory(s))
|
||||
{
|
||||
Console_puts("Failed to change to directory\n");
|
||||
}
|
||||
}
|
||||
|
||||
void func_dir(char* s)
|
||||
{
|
||||
HANDLE shandle;
|
||||
WIN32_FIND_DATA FindData;
|
||||
|
||||
shandle = FindFirstFile("*.*",&FindData);
|
||||
|
||||
if (shandle==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
do
|
||||
{
|
||||
Console_printf("Scanning %s\n",FindData.cFileName);
|
||||
} while(FindNextFile(shandle,&FindData));
|
||||
}
|
||||
|
||||
int is_builtin(char* name, char* args)
|
||||
{
|
||||
if (strcmp(name,"dir")==0)
|
||||
{
|
||||
func_dir(args);
|
||||
return(1);
|
||||
}
|
||||
if (strcmp(name,"cd")==0)
|
||||
{
|
||||
func_cd(args);
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int process_command(char* str)
|
||||
{
|
||||
char* name;
|
||||
char* args;
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFO si;
|
||||
char process_arg[255];
|
||||
|
||||
if (strcmp(str,"exit")==0)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
name = strtok(str," \t");
|
||||
args = strtok(NULL,"");
|
||||
|
||||
if (is_builtin(name,args))
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
memset(&si,0,sizeof(STARTUPINFO));
|
||||
si.cb=sizeof(STARTUPINFO);
|
||||
si.lpTitle=strdup(name);
|
||||
|
||||
strcpy(process_arg,name);
|
||||
strcat(process_arg," ");
|
||||
if(args!=NULL)
|
||||
{
|
||||
strcat(process_arg,args);
|
||||
}
|
||||
Console_printf("name '%s' process_arg '%s'\n",name,process_arg);
|
||||
if (!CreateProcess(NULL,process_arg,NULL,NULL,FALSE,
|
||||
CREATE_NEW_CONSOLE,
|
||||
NULL,NULL,&si,&pi))
|
||||
{
|
||||
Console_printf("Failed to execute process\n");
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void build_prompt(char* prompt)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = GetCurrentDirectory(255,prompt);
|
||||
strcat(prompt,">");
|
||||
}
|
||||
|
||||
void command_loop()
|
||||
{
|
||||
char line[255];
|
||||
char prompt[255];
|
||||
int do_exit = 0;
|
||||
|
||||
while (!do_exit)
|
||||
{
|
||||
build_prompt(prompt);
|
||||
Console_getline(prompt,line,255);
|
||||
Console_printf("Processing command '%s'\n",line);
|
||||
do_exit = process_command(line);
|
||||
}
|
||||
}
|
||||
|
||||
int STDCALL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
|
||||
{
|
||||
AllocConsole();
|
||||
stdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
command_loop();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
all: cmd.bin
|
||||
|
||||
OBJECTS = ../common/crt0.o cmd.o
|
||||
|
||||
LIBS = ../../lib/mingw32/mingw32.a ../../lib/crtdll/crtdll.a \
|
||||
../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a
|
||||
|
||||
cmd.bin: $(OBJECTS)
|
||||
$(LD) -Ttext 0x10000 $(OBJECTS) $(LIBS) -o cmd.exe
|
||||
$(OBJCOPY) -O binary cmd.exe cmd.bin
|
||||
|
||||
include ../../rules.mak
|
Loading…
Reference in a new issue