BOOLEAN RtlCreateUnicodeStringFromAsciiz( OUT PUNICODE_STRING DestinationString, IN PCSZ SourceString ) { ANSI_STRING AnsiString; NTSTATUS Status; RtlInitAnsiString( &AnsiString, SourceString ); Status = RtlAnsiStringToUnicodeString( DestinationString, &AnsiString, TRUE ); if (NT_SUCCESS( Status )) { return( TRUE ); } else { return( FALSE ); } }
/* * @unimplemented */ VOID WINAPI FatalAppExitA(UINT uAction, LPCSTR lpMessageText) { UNICODE_STRING MessageTextU; ANSI_STRING MessageText; RtlInitAnsiString(&MessageText, (LPSTR)lpMessageText); RtlAnsiStringToUnicodeString(&MessageTextU, &MessageText, TRUE); FatalAppExitW(uAction, MessageTextU.Buffer); RtlFreeUnicodeString(&MessageTextU); }
/* Function 15 */ NTSTATUS ElfrRegisterEventSourceA( EVENTLOG_HANDLE_A UNCServerName, PRPC_STRING ModuleName, PRPC_STRING RegModuleName, ULONG MajorVersion, ULONG MinorVersion, PIELF_HANDLE LogHandle) { NTSTATUS Status; UNICODE_STRING ModuleNameW; Status = RtlAnsiStringToUnicodeString(&ModuleNameW, (PANSI_STRING)ModuleName, TRUE); if (!NT_SUCCESS(Status)) { DPRINT1("RtlAnsiStringToUnicodeString failed (Status 0x%08lx)\n", Status); return Status; } /* RegModuleName must be an empty string */ if (RegModuleName->Length > 0) { RtlFreeUnicodeString(&ModuleNameW); return STATUS_INVALID_PARAMETER; } if ((MajorVersion != 1) || (MinorVersion != 1)) { RtlFreeUnicodeString(&ModuleNameW); return STATUS_INVALID_PARAMETER; } /* FIXME: Must verify that caller has write access */ Status = ElfCreateEventLogHandle((PLOGHANDLE*)LogHandle, &ModuleNameW, TRUE); RtlFreeUnicodeString(&ModuleNameW); return Status; }
NTSTATUS FxDriver::OpenParametersKey( VOID ) { HRESULT hr; NTSTATUS status; PFX_DRIVER_GLOBALS FxDriverGlobals = GetDriverGlobals(); PDRIVER_OBJECT_UM pDrvObj = GetDriverObject(); IWudfDeviceStack* pDevStack = (IWudfDeviceStack*)pDrvObj->WudfDevStack; UMINT::WDF_PROPERTY_STORE_ROOT rootSpecifier; UMINT::WDF_PROPERTY_STORE_RETRIEVE_FLAGS flags; CANSI_STRING serviceNameA; DECLARE_UNICODE_STRING_SIZE(serviceNameW, WDF_DRIVER_GLOBALS_NAME_LEN); HKEY hKey; RtlInitAnsiString(&serviceNameA, FxDriverGlobals->Public.DriverName); status = RtlAnsiStringToUnicodeString(&serviceNameW, &serviceNameA, FALSE); if (NT_SUCCESS(status)) { rootSpecifier.LengthCb = sizeof(UMINT::WDF_PROPERTY_STORE_ROOT); rootSpecifier.RootClass = UMINT::WdfPropertyStoreRootDriverParametersKey; rootSpecifier.Qualifier.ParametersKey.ServiceName = serviceNameW.Buffer; flags = UMINT::WdfPropertyStoreCreateIfMissing; hr = pDevStack->CreateRegistryEntry(&rootSpecifier, flags, GENERIC_ALL & ~(GENERIC_WRITE | KEY_CREATE_SUB_KEY | WRITE_DAC), NULL, &hKey, NULL); status = FxDevice::NtStatusFromHr(pDevStack, hr); if (NT_SUCCESS(status)) { m_DriverParametersKey = hKey; } } return status; }
/* * @implemented */ HANDLE WINAPI CreateSemaphoreExA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCSTR lpName OPTIONAL, IN DWORD dwFlags, IN DWORD dwDesiredAccess) { NTSTATUS Status; ANSI_STRING AnsiName; PUNICODE_STRING UnicodeCache; LPCWSTR UnicodeName = NULL; /* Check for a name */ if (lpName) { /* Use TEB Cache */ UnicodeCache = &NtCurrentTeb()->StaticUnicodeString; /* Convert to unicode */ RtlInitAnsiString(&AnsiName, lpName); Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE); if (!NT_SUCCESS(Status)) { /* Conversion failed */ SetLastErrorByStatus(Status); return NULL; } /* Otherwise, save the buffer */ UnicodeName = (LPCWSTR)UnicodeCache->Buffer; } /* Call the Unicode API */ return CreateSemaphoreExW(lpSemaphoreAttributes, lInitialCount, lMaximumCount, UnicodeName, dwFlags, dwDesiredAccess); }
VOID HalReportResourceUsage( VOID ) /*++ Routine Description: Arguments: Return Value: --*/ { ANSI_STRING AHalName; UNICODE_STRING UHalName; // // Report IO space usage // for HAL/system resources // RtlInitAnsiString (&AHalName, HalName); RtlAnsiStringToUnicodeString (&UHalName, &AHalName, TRUE); HalpReportResourceUsage ( &UHalName, PCIBus ); //RtlFreeUnicodeString (&UHalName); // // Now create the registry keys // used to log errors if they // do not already exist // HalpCreateLogKeys(); }
/* * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ** * * * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ** */ NTSTATUS cfsd_UserModeCommunication( IN PVOID ConnectionCookie, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferSize, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferSize, OUT PULONG ReturnOutputBufferLength ) { STRING FNameString; KdPrint( (PRINT_TAG "File Name from USER MODE to hide (%s) [%d]\n", InputBuffer, InputBufferSize ) ); /* !!!!!!!!!!!!!!! ALL TEMP CODE SO YOU CAN TEST THE DRIVER FROM USER MODE WITHOUT HAVING TO RECOMPILE TO CHANGE A FILE NAME !!!!!!!!!!!!!! */ try { RtlInitAnsiString( &FNameString, InputBuffer ); RtlAnsiStringToUnicodeString( &uFName, &FNameString, TRUE ); RtlUpcaseUnicodeString( &uFName, &uFName, FALSE ); gHiddenData->HFile = uFName; // By not calling this we are going to leak memory everytime user mode makes a file name change. This is just a kludge // to let user mode experiement with file names // RtlFreeUnicodeString(&uFName); } except( EXCEPTION_EXECUTE_HANDLER ) { return GetExceptionCode(); } return STATUS_SUCCESS; }
/* * @implemented */ SOCKET EXPORT WSASocketA(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOA lpProtocolInfo, IN GROUP g, IN DWORD dwFlags) /* * FUNCTION: Creates a new socket */ { WSAPROTOCOL_INFOW ProtocolInfoW; LPWSAPROTOCOL_INFOW p; UNICODE_STRING StringU; ANSI_STRING StringA; WS_DbgPrint(MAX_TRACE, ("af (%d) type (%d) protocol (%d).\n", af, type, protocol)); if (lpProtocolInfo) { memcpy(&ProtocolInfoW, lpProtocolInfo, sizeof(WSAPROTOCOL_INFOA) - sizeof(CHAR) * (WSAPROTOCOL_LEN + 1)); RtlInitAnsiString(&StringA, (LPSTR)lpProtocolInfo->szProtocol); RtlInitUnicodeString(&StringU, (LPWSTR)&ProtocolInfoW.szProtocol); RtlAnsiStringToUnicodeString(&StringU, &StringA, FALSE); p = &ProtocolInfoW; } else { p = NULL; } return WSASocketW(af, type, protocol, p, g, dwFlags); }
/****************************************************************************** * Driver unload handler * ******************************************************************************/ static VOID DDKAPI my_unload(PDRIVER_OBJECT DriverObject) { ANSI_STRING SymbolicLinkNameA; UNICODE_STRING SymbolicLinkNameW; DbgPrint("DriverUnload called\r\n"); PsSetCreateProcessNotifyRoutine(create_process_watcher, TRUE); PsRemoveLoadImageNotifyRoutine(load_image_watcher); RtlInitString(&SymbolicLinkNameA, MY_DOSDEVICE_NAME); RtlAnsiStringToUnicodeString(&SymbolicLinkNameW, &SymbolicLinkNameA, TRUE); IoDeleteSymbolicLink(&SymbolicLinkNameW); IoDeleteDevice(DriverObject->DeviceObject); for (int i = 0; i < ENT_CNT; ++i) if(g_proc_table[i].pid) DbgPrint("Registered process stays: %d\r\n", g_proc_table[i].pid); }
BOOL NTAPI RtlLargeStringToUnicodeString( PUNICODE_STRING DestinationString, PLARGE_STRING SourceString) { ANSI_STRING AnsiString; RtlInitUnicodeString(DestinationString, NULL); if (DestinationString && SourceString && SourceString->bAnsi) { RtlInitAnsiString(&AnsiString, (LPSTR)SourceString->Buffer); return NT_SUCCESS(RtlAnsiStringToUnicodeString(DestinationString, &AnsiString, TRUE)); } else if (DestinationString && SourceString) { return RtlCreateUnicodeString(DestinationString, SourceString->Buffer); } else return FALSE; }
NTSTATUS OnWrite(PDEVICE_OBJECT pDeviceObj, PIRP pIrp) { DbgPrint("%s", "Write Called\n"); PIO_STACK_LOCATION stack_location = IoGetCurrentIrpStackLocation(pIrp); PVOID system_buffer = pIrp->AssociatedIrp.SystemBuffer; ULONG write_size = stack_location->Parameters.Write.Length; PVOID &context = stack_location->FileObject->FsContext; ANSI_STRING ansi_string = {write_size, write_size, (PCHAR)system_buffer}; context = (PUNICODE_STRING)ExAllocatePoolWithTag(PagedPool, sizeof(UNICODE_STRING), TAG_CONVERSION); RtlAnsiStringToUnicodeString((PUNICODE_STRING)context, &ansi_string, TRUE); pIrp->IoStatus.Information = write_size; pIrp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(pIrp, IO_NO_INCREMENT); return STATUS_SUCCESS; }
/********************************************************************** * AbortSystemShutdownA * * @unimplemented */ BOOL WINAPI AbortSystemShutdownA(LPCSTR lpMachineName) { ANSI_STRING MachineNameA; UNICODE_STRING MachineNameW; NTSTATUS Status; BOOL rv; RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName); Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); if (STATUS_SUCCESS != Status) { SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } rv = AbortSystemShutdownW(MachineNameW.Buffer); RtlFreeUnicodeString(&MachineNameW); SetLastError(ERROR_SUCCESS); return rv; }
/* Function 13 */ NTSTATUS ElfrBackupELFA( IELF_HANDLE LogHandle, PRPC_STRING BackupFileName) { NTSTATUS Status; UNICODE_STRING BackupFileNameW; Status = RtlAnsiStringToUnicodeString(&BackupFileNameW, (PANSI_STRING)BackupFileName, TRUE); if (!NT_SUCCESS(Status)) return Status; Status = ElfrBackupELFW(LogHandle, (PRPC_UNICODE_STRING)&BackupFileNameW); RtlFreeUnicodeString(&BackupFileNameW); return Status; }
NTSTATUS RegistryDeleteSubKey( IN PHANDLE Key, IN PCHAR Name ) { ANSI_STRING Ansi; UNICODE_STRING Unicode; HANDLE SubKey; NTSTATUS status; RtlInitAnsiString(&Ansi, Name); status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); if (!NT_SUCCESS(status)) goto fail1; status = RegistryOpenKey(Key, &Unicode, KEY_ALL_ACCESS, &SubKey); if (!NT_SUCCESS(status)) goto fail2; status = ZwDeleteKey(SubKey); if (!NT_SUCCESS(status)) goto fail3; ZwClose(SubKey); RtlFreeUnicodeString(&Unicode); return STATUS_SUCCESS; fail3: ZwClose(SubKey); fail2: RtlFreeUnicodeString(&Unicode); fail1: return status; }
/* Function 16 */ NTSTATUS ElfrOpenBELA( EVENTLOG_HANDLE_A UNCServerName, PRPC_STRING BackupFileName, ULONG MajorVersion, ULONG MinorVersion, PIELF_HANDLE LogHandle) { NTSTATUS Status; UNICODE_STRING BackupFileNameW; DPRINT("ElfrOpenBELA(%Z)\n", BackupFileName); Status = RtlAnsiStringToUnicodeString(&BackupFileNameW, (PANSI_STRING)BackupFileName, TRUE); if (!NT_SUCCESS(Status)) { DPRINT1("RtlAnsiStringToUnicodeString failed (Status 0x%08lx)\n", Status); return Status; } if ((MajorVersion != 1) || (MinorVersion != 1)) { RtlFreeUnicodeString(&BackupFileNameW); return STATUS_INVALID_PARAMETER; } /* FIXME: UNCServerName must specify the server */ /* FIXME: Must verify that caller has read access */ Status = ElfCreateBackupLogHandle((PLOGHANDLE*)LogHandle, &BackupFileNameW); RtlFreeUnicodeString(&BackupFileNameW); return Status; }
NTSTATUS co_os_open_file(char *pathname, PHANDLE FileHandle) { NTSTATUS status; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; UNICODE_STRING unipath; ANSI_STRING ansi; ansi.Buffer = pathname; ansi.Length = strlen(pathname); ansi.MaximumLength = ansi.Length + 1; RtlAnsiStringToUnicodeString(&unipath, &ansi, TRUE); InitializeObjectAttributes(&ObjectAttributes, &unipath, OBJ_CASE_INSENSITIVE, NULL, NULL); status = ZwCreateFile(FileHandle, FILE_READ_DATA | FILE_WRITE_DATA | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, NULL, 0, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if (status != STATUS_SUCCESS) co_debug("ZwOpenFile() returned error: %x\n", status); RtlFreeUnicodeString(&unipath); return status; }
/********************************************************************** * RegisterServiceCtrlHandlerA * * @implemented */ SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerA(LPCSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc) { ANSI_STRING ServiceNameA; UNICODE_STRING ServiceNameU; SERVICE_STATUS_HANDLE SHandle; RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName); if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE))) { SetLastError(ERROR_OUTOFMEMORY); return (SERVICE_STATUS_HANDLE)0; } SHandle = RegisterServiceCtrlHandlerW(ServiceNameU.Buffer, lpHandlerProc); RtlFreeUnicodeString(&ServiceNameU); return SHandle; }
DWORD WINAPI MyGetFullPathNameA(IN LPSTR lpFileName, IN DWORD nBufferLength, OUT LPTSTR lpBuffer, OUT LPSTR* lpFilePart) { WCHAR szFileName[MAX_PATH], szFullName[MAX_PATH]; ANSI_STRING aString; UNICODE_STRING uString; static Bool bFirst; if (!bFirst) { bFirst = True; MessageBoxA(0, 0, 0, 0); } RtlInitAnsiString(&aString, lpFileName); uString.Buffer = szFileName; uString.Length = 0; uString.MaximumLength = countof(szFileName); RtlAnsiStringToUnicodeString(&uString, &aString, False); memset(lpBuffer, 0, nBufferLength); nBufferLength = GetFullPathNameW(szFileName, countof(szFullName), szFullName, (LPWSTR *)lpFilePart); if (lpFilePart) { *lpFilePart = *lpFilePart ? lpBuffer + (*lpFilePart - (LPSTR)szFullName) / 2 : lpBuffer; } aString.Buffer = (LPSTR)szFileName; aString.MaximumLength = sizeof(szFileName); RtlInitUnicodeString(&uString, szFullName); RtlUnicodeStringToAnsiString(&aString, &uString, False); memcpy(lpBuffer, szFileName, nBufferLength); if (lpFilePart && Status == UNPACKING) { lpFileName = *lpFilePart; memmove(lpFileName + 2, lpFileName, nBufferLength - (lpFileName - lpBuffer)); *(LPWORD)lpFileName = '\\/'; nBufferLength += 2; } return nBufferLength; }
static PKEY_VALUE_PARTIAL_INFORMATION RegistryAnsiToSz( PANSI_STRING Ansi ) { ULONG Length; PKEY_VALUE_PARTIAL_INFORMATION Partial; UNICODE_STRING Unicode; NTSTATUS status; Length = Ansi->Length + 1; Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + Length * sizeof (WCHAR)); status = STATUS_NO_MEMORY; if (Partial == NULL) goto fail1; Partial->TitleIndex = 0; Partial->Type = REG_SZ; Partial->DataLength = Length * sizeof (WCHAR); Unicode.MaximumLength = (UCHAR)Partial->DataLength; Unicode.Buffer = (PWCHAR)Partial->Data; Unicode.Length = 0; status = RtlAnsiStringToUnicodeString(&Unicode, Ansi, FALSE); if (!NT_SUCCESS(status)) goto fail2; return Partial; fail2: __RegistryFree(Partial); fail1: return NULL; }
/* * @implemented */ HANDLE WINAPI OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName) { NTSTATUS Status; ANSI_STRING AnsiName; PUNICODE_STRING UnicodeCache; /* Check for a name */ if (lpName) { /* Use TEB Cache */ UnicodeCache = &NtCurrentTeb()->StaticUnicodeString; /* Convert to unicode */ RtlInitAnsiString(&AnsiName, lpName); Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE); if (!NT_SUCCESS(Status)) { /* Conversion failed */ SetLastErrorByStatus(Status); return NULL; } } else { /* We need a name */ SetLastError(ERROR_INVALID_PARAMETER); return NULL; } /* Call the Unicode API */ return OpenSemaphoreW(dwDesiredAccess, bInheritHandle, (LPCWSTR)UnicodeCache->Buffer); }
/* Function 15 */ NTSTATUS ElfrRegisterEventSourceA( EVENTLOG_HANDLE_A UNCServerName, PRPC_STRING ModuleName, PRPC_STRING RegModuleName, DWORD MajorVersion, DWORD MinorVersion, IELF_HANDLE *LogHandle) { UNICODE_STRING ModuleNameW = { 0, 0, NULL }; if (ModuleName && !RtlAnsiStringToUnicodeString(&ModuleNameW, (PANSI_STRING)ModuleName, TRUE)) { return STATUS_NO_MEMORY; } /* RegModuleName must be an empty string */ if (RegModuleName->Length > 0) { RtlFreeUnicodeString(&ModuleNameW); return STATUS_INVALID_PARAMETER; } if ((MajorVersion != 1) || (MinorVersion != 1)) { RtlFreeUnicodeString(&ModuleNameW); return STATUS_INVALID_PARAMETER; } /* FIXME: Must verify that caller has write access */ *LogHandle = ElfCreateEventLogHandle(ModuleNameW.Buffer, TRUE); RtlFreeUnicodeString(&ModuleNameW); return STATUS_SUCCESS; }
// my loadlibrary, uses only ntdll functions LPVOID engine_NtLoadLibraryA(LPSTR lpModuleName) { STRING asModuleName; UNICODE_STRING usModuleName; HANDLE hModule; asModuleName.Buffer=(PCHAR)lpModuleName; asModuleName.Length=strlen(lpModuleName); asModuleName.MaximumLength=asModuleName.Length; if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&usModuleName,&asModuleName,TRUE))) return NULL; if (!NT_SUCCESS(LdrLoadDll(NULL,0,&usModuleName,&hModule))) { RtlFreeUnicodeString(&usModuleName); return NULL; } RtlFreeUnicodeString(&usModuleName); return hModule; }
VOID SrvDisallowSlmAccessA ( IN PANSI_STRING StatusFile, IN HANDLE RootDirectory ) { NTSTATUS status; UNICODE_STRING unicodeStatusFile; status = RtlAnsiStringToUnicodeString( &unicodeStatusFile, StatusFile, TRUE ); ASSERT( NT_SUCCESS(status) ); SrvDisallowSlmAccess( &unicodeStatusFile, RootDirectory ); RtlFreeUnicodeString( &unicodeStatusFile ); return; } // SrvDisallowSlmAccessA
BOOL giveMePac(PCSTR Username, PSID DomainSid, DWORD UserId, KerberosTime *AuthTime, DWORD SignatureType, EncryptionKey * SignatureKey, _octet1 *pac) { BOOL status = FALSE; KERB_VALIDATION_INFO validationInfo = {0}; STRING user; kull_m_kerberos_asn1_helper_util_UTCKerberosTimeToFileTime(AuthTime, &validationInfo.LogonTime); KIWI_NEVERTIME(&validationInfo.LogoffTime); KIWI_NEVERTIME(&validationInfo.KickOffTime); KIWI_NEVERTIME(&validationInfo.PasswordLastSet); KIWI_NEVERTIME(&validationInfo.PasswordCanChange); KIWI_NEVERTIME(&validationInfo.PasswordMustChange); pac->length = 0; pac->value = NULL; RtlInitString(&user, Username); if(NT_SUCCESS(RtlAnsiStringToUnicodeString(&validationInfo.EffectiveName, &user, TRUE))) { validationInfo.LogonDomainId = (PISID) DomainSid; validationInfo.UserId = UserId; validationInfo.UserAccountControl = USER_DONT_EXPIRE_PASSWORD | USER_NORMAL_ACCOUNT; validationInfo.PrimaryGroupId = defaultGroups[0].RelativeId; validationInfo.GroupCount = ARRAYSIZE(defaultGroups); validationInfo.GroupIds = defaultGroups; if(kuhl_m_pac_validationInfo_to_PAC(&validationInfo, SignatureType, (PPACTYPE *) &pac->value, (DWORD *) &pac->length)) { kprintf(" * PAC generated\n"); if(status = NT_SUCCESS(kuhl_m_pac_signature((PPACTYPE) pac->value, pac->length, SignatureType, SignatureKey ? SignatureKey->keyvalue.value : NULL, SignatureKey ? SignatureKey->keyvalue.length : 0))) kprintf(" * PAC \"\"\"signed\"\"\"\n"); else LocalFree(pac->value); } RtlFreeUnicodeString(&validationInfo.EffectiveName); } return status; }
HANDLE WINAPI OpenWaitableTimerA( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpTimerName ) { PUNICODE_STRING Unicode; ANSI_STRING AnsiString; NTSTATUS Status; if ( ARGUMENT_PRESENT(lpTimerName) ) { Unicode = &NtCurrentTeb()->StaticUnicodeString; RtlInitAnsiString(&AnsiString,lpTimerName); Status = RtlAnsiStringToUnicodeString(Unicode,&AnsiString,FALSE); if ( !NT_SUCCESS(Status) ) { if ( Status == STATUS_BUFFER_OVERFLOW ) { SetLastError(ERROR_FILENAME_EXCED_RANGE); } else { BaseSetLastNTError(Status); } return NULL; } } else { BaseSetLastNTError(STATUS_INVALID_PARAMETER); return NULL; } return OpenWaitableTimerW( dwDesiredAccess, bInheritHandle, (LPCWSTR)Unicode->Buffer ); }
/*NOTE: API IS A HACK */ VOID WINAPI BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString, OUT LPWSTR* UnicodeString) { ANSI_STRING AnsiTemp; UNICODE_STRING UnicodeTemp; DPRINT("BasepAnsiStringToHeapUnicodeString\n"); /* First create the ANSI_STRING */ RtlInitAnsiString(&AnsiTemp, AnsiString); if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&UnicodeTemp, &AnsiTemp, TRUE))) { *UnicodeString = UnicodeTemp.Buffer; } else { *UnicodeString = NULL; } }
/* cmdGetConfigSys - Creates a temp file to replace c:\config.sys * * Entry - Client (DS:DX) pointer to receive file name * * EXIT - This routine will Terminate the vdm if it fails * And will not return * * The buffer to receive the file name must be at least 64 bytes */ VOID cmdGetConfigSys (VOID) { UNICODE_STRING Unicode; OEM_STRING OemString; ANSI_STRING AnsiString; ExpandConfigFiles(TRUE); RtlInitAnsiString(&AnsiString, pchTmpConfigFile); if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&Unicode, &AnsiString, TRUE)) ) goto ErrExit; OemString.Buffer = (char *)GetVDMAddr(getDS(),getDX()); OemString.MaximumLength = 64; if ( !NT_SUCCESS(RtlUnicodeStringToOemString(&OemString,&Unicode,FALSE)) ) goto ErrExit; RtlFreeUnicodeString(&Unicode); return; ErrExit: RcErrorDialogBox(ED_INITMEMERR, pchTmpConfigFile, NULL); TerminateVDM(); }
/****************************************************************************** * ClearEventLogA [ADVAPI32.@] */ BOOL WINAPI ClearEventLogA(IN HANDLE hEventLog, IN LPCSTR lpBackupFileName) { ANSI_STRING BackupFileNameA; UNICODE_STRING BackupFileNameW; NTSTATUS Status; BOOL Result; TRACE("%p, %s\n", hEventLog, lpBackupFileName); if (lpBackupFileName == NULL) { RtlInitUnicodeString(&BackupFileNameW, NULL); } else { RtlInitAnsiString(&BackupFileNameA, lpBackupFileName); Status = RtlAnsiStringToUnicodeString(&BackupFileNameW, &BackupFileNameA, TRUE); if (!NT_SUCCESS(Status)) { SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } } Result = ClearEventLogW(hEventLog, BackupFileNameW.Buffer); RtlFreeUnicodeString(&BackupFileNameW); return Result; }
//失败返回0 ULONG GetTargetProtocolBlockWin7(char *ProName, DWORD dwLen) { UNICODE_STRING uniNPF; ULONG uHeader=0; NTSTATUS status = STATUS_SUCCESS; PNDIS_PROTOCOL_BLOCKWin7 pProtoBLock=NULL; BOOLEAN bFound = FALSE; PNDIS_PROTOCOL_BLOCKWin7 pNpfProtocolBlock=NULL; char szBuffer[1024]; ANSI_STRING aniStr1; RtlZeroMemory(szBuffer, sizeof(szBuffer)); if (dwLen>sizeof(szBuffer)) { return STATUS_UNSUCCESSFUL; } RtlMoveMemory(szBuffer, ProName, dwLen); RtlInitAnsiString(&aniStr1, szBuffer); RtlAnsiStringToUnicodeString(&uniNPF, &aniStr1, TRUE); do { uHeader = GetProtocolHeader(); if (uHeader==0) { status = STATUS_UNSUCCESSFUL; break; } pProtoBLock = (PNDIS_PROTOCOL_BLOCKWin7)uHeader; while(pProtoBLock) { if (RtlEqualUnicodeString(&pProtoBLock->Name, &uniNPF,TRUE)) { bFound = TRUE; break; } pProtoBLock = (PNDIS_PROTOCOL_BLOCKWin7)pProtoBLock->NextProtocol; } if (!bFound) { kprintf("Can not find protocol name: %s\n", ProName); break; } pNpfProtocolBlock = pProtoBLock; //NdisDeregisterProtocol(&status, (NDIS_HANDLE)uHeader); // deregister it } while (0); RtlFreeUnicodeString(&uniNPF); return (ULONG)pNpfProtocolBlock; }
NTSTATUS ApfCreateDataSection(PAPFCONTROL *ApfDataSectionPointer) { NTSTATUS Status; STRING ApfDataSectionName; UNICODE_STRING ApfDataSectionUnicodeName; OBJECT_ATTRIBUTES ObjectAttributes; LARGE_INTEGER AllocationSize; ULONG ViewSize; PAPFCONTROL DataSectionPointer; // // Initialize object attributes // RtlInitString(&ApfDataSectionName, DATA_SEC_NAME); Status = RtlAnsiStringToUnicodeString( &ApfDataSectionUnicodeName, &ApfDataSectionName, TRUE); if (NT_SUCCESS(Status)) { InitializeObjectAttributes( &ObjectAttributes, &ApfDataSectionUnicodeName, OBJ_OPENIF | OBJ_CASE_INSENSITIVE, NULL, &SecDescriptor); } #ifdef ERRORDBG else { KdPrint (("WAP: RtlAnsiStringToUnicodeString() failed in " "ApfCreateDataSection, %lx\n", Status)); } #endif AllocationSize.HighPart = 0; // Need a slot to account for calibration data // AllocationSize.LowPart = (API_COUNT + 1) * sizeof(APFDATA); // Create a read-write section // Status = NtCreateSection(&ApfDataSectionHandle, SECTION_MAP_READ | SECTION_MAP_WRITE, &ObjectAttributes, &AllocationSize, PAGE_READWRITE, SEC_COMMIT, NULL); if (NT_SUCCESS(Status)) { ViewSize = AllocationSize.LowPart; DataSectionPointer = NULL; // Map the section // Status = NtMapViewOfSection(ApfDataSectionHandle, MyProcess, (PVOID *)&DataSectionPointer, 0, AllocationSize.LowPart, NULL, &ViewSize, ViewUnmap, 0L, PAGE_READWRITE); #ifdef ERRORDBG if (!NT_SUCCESS(Status)) { KdPrint (("WAP: NtMapViewOfSection() failed in ApfCreateDataSection," " %lx\n", Status)); } #endif *ApfDataSectionPointer = DataSectionPointer; } #ifdef ERRORDBG else { KdPrint (("WAP: NtCreateSection() failed in ApfCreateDataSection " "%lx\n", Status)); } #endif return(Status); } /* ApfCreateDataSection () */