int GetHmodTableIndex( PUNICODE_STRING pstrLibName) { int i; ATOM atom; UNICODE_STRING strLibName; /* * Probe string */ try { strLibName = ProbeAndReadUnicodeString(pstrLibName); ProbeForReadUnicodeStringBuffer(strLibName); atom = UserAddAtom(strLibName.Buffer, FALSE); } except (W32ExceptionHandler(FALSE, RIP_WARNING)) { return -1; } /* * If we can't add the atom we're hosed * so return an error. */ if (atom == 0) { return -1; } /* * Search for atom index */ for (i = 0; i < catomSysTableEntries && aatomSysLoaded[i] != atom; i++) ; if (i == catomSysTableEntries) { /* * Find empty entry for atom */ for (i = 0; i < catomSysTableEntries && aatomSysLoaded[i]; i++) ; /* * Check if no empty entry found */ if (i == catomSysTableEntries) { if (i == CLIBS) { UserDeleteAtom(atom); RIPERR0(ERROR_NOT_ENOUGH_MEMORY, RIP_WARNING, "Memory allocation failed in GetHmodTableIndex"); return -1; } /* * Increase table size */ catomSysTableEntries++; } /* * Set entry */ aatomSysLoaded[i] = atom; acatomSysUse[i] = 0; acatomSysDepends[i] = 0; } else { UserDeleteAtom(atom); } return i; }
NTSTATUS NtDisplayString( IN PUNICODE_STRING String ) /*++ Routine Description: This service calls the HAL to display a string on the console. The caller must have SeTcbPrivilege to display a message. Arguments: String - A pointer to the string that is to be displayed. Return Value: !NT_SUCCESS - The operation failed or the caller did not have appropriate priviledges. --*/ { KPROCESSOR_MODE PreviousMode; UNICODE_STRING CapturedString; PUCHAR StringBuffer = NULL; PUCHAR AnsiStringBuffer = NULL; STRING AnsiString; // // Check to determine if the caller has the privilege to make this // call. // PreviousMode = KeGetPreviousMode(); if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) { return STATUS_PRIVILEGE_NOT_HELD; } try { // // If the previous mode was user, then check the input parameters. // if (PreviousMode != KernelMode) { // // Probe and capture the input unicode string descriptor. // CapturedString = ProbeAndReadUnicodeString(String); // // If the captured string descriptor has a length of zero, then // return success. // if ((CapturedString.Buffer == 0) || (CapturedString.MaximumLength == 0)) { return STATUS_SUCCESS; } // // Probe and capture the input string. // // N.B. Note the length is in bytes. // ProbeForRead( CapturedString.Buffer, CapturedString.MaximumLength, sizeof(UCHAR) ); // // Allocate a non-paged string buffer because the buffer passed to // HalDisplay string must be non-paged. // StringBuffer = ExAllocatePoolWithTag(NonPagedPool, CapturedString.MaximumLength, 'grtS'); if ( !StringBuffer ) { return STATUS_NO_MEMORY; } RtlMoveMemory(StringBuffer, CapturedString.Buffer, CapturedString.MaximumLength); CapturedString.Buffer = (PWSTR)StringBuffer; // // Allocate a string buffer for the ansi string. // AnsiStringBuffer = ExAllocatePoolWithTag(NonPagedPool, CapturedString.MaximumLength, 'grtS'); if (AnsiStringBuffer == NULL) { ExFreePool(StringBuffer); return STATUS_NO_MEMORY; } AnsiString.MaximumLength = CapturedString.MaximumLength; AnsiString.Length = 0; AnsiString.Buffer = AnsiStringBuffer; // // Transform the string to ANSI until the HAL handles unicode. // RtlUnicodeStringToOemString( &AnsiString, &CapturedString, FALSE ); } else { // // Allocate a string buffer for the ansi string. // AnsiStringBuffer = ExAllocatePoolWithTag(NonPagedPool, String->MaximumLength, 'grtS'); if (AnsiStringBuffer == NULL) { return STATUS_NO_MEMORY; } AnsiString.MaximumLength = String->MaximumLength; AnsiString.Length = 0; AnsiString.Buffer = AnsiStringBuffer; // // We were in kernel mode; just transform the original string. // RtlUnicodeStringToOemString( &AnsiString, String, FALSE ); } HalDisplayString( AnsiString.Buffer ); // // Free up the memory we used to store the strings. // if (PreviousMode != KernelMode) { ExFreePool(StringBuffer); } ExFreePool(AnsiStringBuffer); } except(EXCEPTION_EXECUTE_HANDLER) { if (StringBuffer != NULL) { ExFreePool(StringBuffer); } return GetExceptionCode(); } return STATUS_SUCCESS; }
NTSTATUS NtLoadDriver( IN PUNICODE_STRING DriverServiceName ) /*++ Routine Description: This service dynamically loads a device or file system driver into the currently running system. It requires that the caller have the appropriate privilege to execute this service. Arguments: DriverServiceName - Specifies the name of the node in the registry associated with the driver to be loaded. Return Value: The status returned is the final completion status of the load operation. --*/ { KPROCESSOR_MODE requestorMode; UNICODE_STRING driverServiceName; PWCHAR nameBuffer = (PWCHAR) NULL; LOAD_PACKET loadPacket; PAGED_CODE(); // // Get the previous mode; i.e., the mode of the caller. // requestorMode = KeGetPreviousMode(); if (requestorMode != KernelMode) { // // The caller's access mode is not kernel so check to ensure that // the caller has the privilege to load a driver and probe and // capture the name of the driver service entry. // if (!SeSinglePrivilegeCheck( SeLoadDriverPrivilege, requestorMode )) { return STATUS_PRIVILEGE_NOT_HELD; } // // The caller has the appropriate privilege to load and unload // drivers, so capture the driver service name string so that it // can be used to locate the driver from the registry node. // try { driverServiceName = ProbeAndReadUnicodeString( DriverServiceName ); if (!driverServiceName.Length) { return STATUS_INVALID_PARAMETER; } ProbeForRead( driverServiceName.Buffer, driverServiceName.Length, sizeof( WCHAR ) ); nameBuffer = ExAllocatePoolWithQuota( PagedPool, driverServiceName.Length ); RtlCopyMemory( nameBuffer, driverServiceName.Buffer, driverServiceName.Length ); driverServiceName.Buffer = nameBuffer; } except(EXCEPTION_EXECUTE_HANDLER) { // // An exception was incurred while attempting to capture the // input name string or while attempting to allocate the name // string buffer. Simply clean everything up and return an // appropriate error status code. // if (nameBuffer) { ExFreePool( nameBuffer ); } return GetExceptionCode(); } } else {