📄 server.c
字号:
{
*SizeValue++ = '\0';
break;
}
else
{
SizeValue++;
}
}
/* Make sure it's valid */
if (!*SizeValue) return(STATUS_INVALID_PARAMETER);
/* Convert it to an integer */
Status = RtlCharToInteger(SizeValue,
0,
&Size);
if (!NT_SUCCESS(Status)) return Status;
/* Multiply by 1024 entries and round to page size */
CsrSrvSharedSectionSize = ROUND_UP(Size * 1024, CsrNtSysInfo.PageSize);
/* Create the Secion */
SectionSize.LowPart = CsrSrvSharedSectionSize;
SectionSize.HighPart = 0;
Status = NtCreateSection(&CsrSrvSharedSection,
SECTION_ALL_ACCESS,
NULL,
&SectionSize,
PAGE_EXECUTE_READWRITE,
SEC_BASED | SEC_RESERVE,
NULL);
if (!NT_SUCCESS(Status)) return Status;
/* Map the section */
Status = NtMapViewOfSection(CsrSrvSharedSection,
NtCurrentProcess(),
&CsrSrvSharedSectionBase,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
MEM_TOP_DOWN,
PAGE_EXECUTE_READWRITE);
if(!NT_SUCCESS(Status))
{
/* Fail */
NtClose(CsrSrvSharedSection);
return(Status);
}
/* FIXME: Write the value to registry */
/* The Heap is the same place as the Base */
CsrSrvSharedSectionHeap = CsrSrvSharedSectionBase;
/* Create the heap */
if (!(RtlCreateHeap(HEAP_ZERO_MEMORY,
CsrSrvSharedSectionHeap,
CsrSrvSharedSectionSize,
PAGE_SIZE,
0,
0)))
{
/* Failure, unmap section and return */
NtUnmapViewOfSection(NtCurrentProcess(),
CsrSrvSharedSectionBase);
NtClose(CsrSrvSharedSection);
return STATUS_NO_MEMORY;
}
/* Now allocate space from the heap for the Shared Data */
CsrSrvSharedStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
0,
CSR_SERVER_DLL_MAX *
sizeof(PVOID));
/* Write the values to the PEB */
Peb->ReadOnlySharedMemoryBase = CsrSrvSharedSectionBase;
Peb->ReadOnlySharedMemoryHeap = CsrSrvSharedSectionHeap;
Peb->ReadOnlyStaticServerData = CsrSrvSharedStaticServerData;
/* Return */
return STATUS_SUCCESS;
}
/*++
* @name CsrSrvAttachSharedSection
*
* The CsrSrvAttachSharedSection maps the CSR Shared Section into a new
* CSR Process' address space, and returns the pointers to the section
* through the Connection Info structure.
*
* @param CsrProcess
* Pointer to the CSR Process that is attempting a connection.
*
* @param ConnectInfo
* Pointer to the CSR Connection Info structure for the incoming
* connection.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* othwerwise.
*
* @remarks None.
*
*--*/
NTSTATUS
NTAPI
CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
OUT PCSR_CONNECTION_INFO ConnectInfo)
{
NTSTATUS Status;
ULONG ViewSize = 0;
/* Check if we have a process */
if (CsrProcess)
{
/* Map the sectio into this process */
Status = NtMapViewOfSection(CsrSrvSharedSection,
CsrProcess->ProcessHandle,
&CsrSrvSharedSectionBase,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
SEC_NO_CHANGE,
PAGE_EXECUTE_READ);
if (!NT_SUCCESS(Status)) return Status;
}
/* Write the values in the Connection Info structure */
ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
ConnectInfo->SharedSectionData = CsrSrvSharedStaticServerData;
/* Return success */
return STATUS_SUCCESS;
}
/*++
* @name CsrSrvIdentifyAlertableThread
* @implemented NT4
*
* The CsrSrvIdentifyAlertableThread CSR API marks a CSR Thread as alertable.
*
* @param ApiMessage
* Pointer to the CSR API Message for this request.
*
* @param Reply
* Pointer to an optional reply to this request.
*
* @return STATUS_SUCCESS.
*
* @remarks None.
*
*--*/
NTSTATUS
NTAPI
CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{
PCSR_THREAD CsrThread = NtCurrentTeb()->CsrClientThread;
/* Set the alertable flag */
CsrThread->Flags |= CsrThreadAltertable;
/* Return success */
return STATUS_SUCCESS;
}
/*++
* @name CsrSrvSetPriorityClass
* @implemented NT4
*
* The CsrSrvSetPriorityClass CSR API is deprecated.
*
* @param ApiMessage
* Pointer to the CSR API Message for this request.
*
* @param Reply
* Pointer to an optional reply to this request.
*
* @return STATUS_SUCCESS.
*
* @remarks None.
*
*--*/
NTSTATUS
NTAPI
CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{
/* Deprecated */
return STATUS_SUCCESS;
}
/*++
* @name CsrSrvUnusedFunction
* @implemented NT4
*
* The CsrSrvUnusedFunction CSR API is a stub for deprecated APIs.
*
* The CsrSrvSetPriorityClass CSR API is deprecated.
*
* @param ApiMessage
* Pointer to the CSR API Message for this request.
*
* @param Reply
* Pointer to an optional reply to this request.
*
* @return STATUS_INVALID_PARAMETER.
*
* @remarks CsrSrvSetPriorityClass does not use this stub because it must
* return success.
*
*--*/
NTSTATUS
NTAPI
CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{
/* Deprecated */
return STATUS_INVALID_PARAMETER;
}
/* PUBLIC FUNCTIONS***********************************************************/
/*++
* @name CsrSetCallingSpooler
* @implemented NT4
*
* the CsrSetCallingSpooler routine is deprecated.
*
* @param Reserved
* Deprecated
*
* @return None.
*
* @remarks This routine was used in archaic versions of NT for Printer Drivers.
*
*--*/
VOID
NTAPI
CsrSetCallingSpooler(ULONG Reserved)
{
/* Deprecated */
return;
}
/*++
* @name CsrUnhandledExceptionFilter
* @implemented NT5
*
* The CsrUnhandledExceptionFilter routine handles all exceptions
* within SEH-protected blocks.
*
* @param ExceptionPointers
* System-defined Argument.
*
* @return EXCEPTION_EXECUTE_HANDLER.
*
* @remarks None.
*
*--*/
_SEH_FILTER(CsrUnhandledExceptionFilter)
{
struct _EXCEPTION_POINTERS *ExceptionInfo = _SEH_GetExceptionPointers();
SYSTEM_KERNEL_DEBUGGER_INFORMATION DebuggerInfo;
EXCEPTION_DISPOSITION Result = EXCEPTION_EXECUTE_HANDLER;
BOOLEAN OldValue;
NTSTATUS Status;
UNICODE_STRING ErrorSource;
ULONG_PTR ErrorParameters[4];
ULONG Response;
/* Check if a debugger is installed */
Status = NtQuerySystemInformation(SystemKernelDebuggerInformation,
&DebuggerInfo,
sizeof(DebuggerInfo),
NULL);
/* Check if this is Session 0, and the Debugger is Enabled */
if ((NtCurrentPeb()->SessionId) && (NT_SUCCESS(Status)) &&
(DebuggerInfo.KernelDebuggerEnabled))
{
/* Call the Unhandled Exception Filter */
if ((Result = RtlUnhandledExceptionFilter(ExceptionInfo)) !=
EXCEPTION_CONTINUE_EXECUTION)
{
/* We're going to raise an error. Get Shutdown Privilege first */
Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
TRUE,
TRUE,
&OldValue);
/* Use the Process token if that failed */
if (Status == STATUS_NO_TOKEN)
{
Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
TRUE,
FALSE,
&OldValue);
}
/* Initialize our Name String */
RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
/* Set the parameters */
ErrorParameters[0] = PtrToUlong(&ErrorSource);
ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
ErrorParameters[2] = PtrToUlong(ExceptionInfo->ExceptionRecord->ExceptionAddress);
ErrorParameters[3] = PtrToUlong(ExceptionInfo->ContextRecord);
/* Bugcheck */
Status = NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED,
4,
1,
ErrorParameters,
OptionShutdownSystem,
&Response);
}
/* Just terminate us */
NtTerminateProcess(NtCurrentProcess(),
ExceptionInfo->ExceptionRecord->ExceptionCode);
}
return Result;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -