*ActCtx = NULL;
/* Check whether the image has manifest resource associated with it */
- Info.Type = (ULONG)RT_MANIFEST;
- Info.Name = (ULONG)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
+ Info.Type = (ULONG_PTR)RT_MANIFEST;
+ Info.Name = (ULONG_PTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
Info.Language = 0;
if (!(Status = LdrFindResource_U(DllHandle, &Info, 3, &Entry)))
{
UNICODE_STRING KeyName;
UNICODE_STRING ValueName;
HANDLE KeyHandle;
+ SIZE_T StringLength;
NTSTATUS Status;
+ StringLength = wcslen(lpBuffer);
+ if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
+ {
+ return FALSE;
+ }
+
RtlInitUnicodeString(&KeyName, RegistryKey);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
0,
REG_SZ,
(PVOID)lpBuffer,
- (wcslen (lpBuffer) + 1) * sizeof(WCHAR));
+ (StringLength + 1) * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
NTSTATUS Status;
/* Set the Client ID */
- ClientId.UniqueProcess = (HANDLE)dwProcessId;
- ClientId.UniqueThread = (HANDLE)dwThreadId;
+ ClientId.UniqueProcess = UlongToHandle(dwProcessId);
+ ClientId.UniqueThread = UlongToHandle(dwThreadId);
/* Continue debugging */
Status = DbgUiContinue(&ClientId, dwContinueStatus);
BaseWindowsSystemDirectory = BaseStaticServerData->WindowsSystemDirectory;
/* Construct the default path (using the static buffer) */
- _snwprintf(BaseDefaultPathBuffer,
- sizeof(BaseDefaultPathBuffer) / sizeof(WCHAR),
- L".;%wZ;%wZ\\system;%wZ;",
- &BaseWindowsSystemDirectory,
- &BaseWindowsDirectory,
- &BaseWindowsDirectory);
+ Status = RtlStringCbPrintfW(BaseDefaultPathBuffer,
+ sizeof(BaseDefaultPathBuffer),
+ L".;%wZ;%wZ\\system;%wZ;",
+ &BaseWindowsSystemDirectory,
+ &BaseWindowsDirectory,
+ &BaseWindowsDirectory);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NLS Init failed\n");
+ return FALSE;
+ }
BaseDefaultPath.Buffer = BaseDefaultPathBuffer;
- BaseDefaultPath.Length = wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
+ BaseDefaultPath.Length = (USHORT)wcslen(BaseDefaultPathBuffer) * sizeof(WCHAR);
BaseDefaultPath.MaximumLength = sizeof(BaseDefaultPathBuffer);
/* Use remaining part of the default path buffer for the append path */
char* psz, size_t nChars, char** module_name)
{
MEMORY_BASIC_INFORMATION mbi;
- if (VirtualQuery(addr, &mbi, sizeof(mbi)) != sizeof(mbi) ||
- !GetModuleFileNameA((HMODULE)mbi.AllocationBase, psz, nChars))
+
+ if ((nChars > MAXDWORD) ||
+ (VirtualQuery(addr, &mbi, sizeof(mbi)) != sizeof(mbi)) ||
+ !GetModuleFileNameA((HMODULE)mbi.AllocationBase, psz, (DWORD)nChars))
{
psz[0] = '\0';
*module_name = psz;
{
PVOID Data;
ULONG Size, OldProtect;
+ SIZE_T Size2;
MEMORY_BASIC_INFORMATION mbi;
NTSTATUS Status;
LONG Ret = EXCEPTION_CONTINUE_SEARCH;
{
/* The user tried to write into the resources. Make the page
writable... */
- Size = 1;
+ Size2 = 1;
Status = NtProtectVirtualMemory(NtCurrentProcess(),
&Ptr,
- &Size,
+ &Size2,
PAGE_READWRITE,
&OldProtect);
if (NT_SUCCESS(Status))
* line. The biggest 32-bit unsigned int (0xFFFFFFFF == 4.294.967.295)
* takes 10 decimal digits. We then count the terminating NULL.
*/
- Length = wcslen(AeDebugPath) + 2*10 + 1;
+ Length = (ULONG)wcslen(AeDebugPath) + 2*10 + 1;
/* Check whether the debugger path may be a relative path */
if ((*AeDebugPath != L'"') &&
(RtlDetermineDosPathNameType_U(AeDebugPath) == RtlPathTypeRelative))
{
/* Relative path, prepend SystemRoot\System32 */
- PrependLength = wcslen(SharedUserData->NtSystemRoot) + 10 /* == wcslen(L"\\System32\\") */;
+ PrependLength = (ULONG)wcslen(SharedUserData->NtSystemRoot) + 10 /* == wcslen(L"\\System32\\") */;
if (PrependLength + Length <= ARRAYSIZE(AeDebugCmdLine))
{
hr = StringCchPrintfW(AeDebugCmdLine,
*Current;
/* Align the addresses */
- Current = (volatile CHAR *)ROUND_DOWN(Current, PageSize);
- Last = (PCHAR)ROUND_DOWN(Last, PageSize);
+ Current = (volatile CHAR *)ALIGN_DOWN_POINTER_BY(Current, PageSize);
+ Last = (PCHAR)ALIGN_DOWN_POINTER_BY(Last, PageSize);
/* Probe the entire range */
while (Current != Last)
*Current = *Current;
/* Align the addresses */
- Current = (volatile CHAR *)ROUND_DOWN(Current, PageSize);
- Last = (PCHAR)ROUND_DOWN(Last, PageSize);
+ Current = (volatile CHAR *)ALIGN_DOWN_POINTER_BY(Current, PageSize);
+ Last = (PCHAR)ALIGN_DOWN_POINTER_BY(Last, PageSize);
/* Probe the entire range */
while (Current != Last)
/* Create the pipe name */
swprintf(Buffer,
- L"\\Device\\NamedPipe\\Win32Pipes.%08x.%08x",
+ L"\\Device\\NamedPipe\\Win32Pipes.%p.%08x",
NtCurrentTeb()->ClientId.UniqueProcess,
PipeId);
RtlInitUnicodeString(&PipeName, Buffer);
PVOID hMapped;
ULONG Ordinal = 0;
- if (HIWORD(lpProcName) != 0)
+ if ((ULONG_PTR)lpProcName > MAXUSHORT)
{
/* Look up by name */
RtlInitAnsiString(&ProcedureName, (LPSTR)lpProcName);
else
{
/* Look up by ordinal */
- Ordinal = (ULONG)lpProcName;
+ Ordinal = PtrToUlong(lpProcName);
}
/* Map provided handle */
IN LPVOID Environment)
{
PWCHAR PathBuffer, Buffer, AppNameEnd, PathCurrent;
- ULONG PathLengthInBytes;
+ SIZE_T PathLengthInBytes;
NTSTATUS Status;
UNICODE_STRING EnvPath;
PBASE_SEARCH_PATH_TYPE Order;
/* Yep, so in this case get the length of the file part too */
Status = RtlUnicodeToMultiByteSize(&FilePartSize,
Buffer,
- (LocalFilePart - Buffer) *
+ (ULONG)(LocalFilePart - Buffer) *
sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
/* Yep, so in this case get the length of the file part too */
Status = RtlUnicodeToMultiByteSize(&FilePartSize,
Buffer,
- (LocalFilePart - Buffer) *
+ (ULONG)(LocalFilePart - Buffer) *
sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
OUT LPWSTR *lpFilePart OPTIONAL)
{
UNICODE_STRING FileNameString, ExtensionString, PathString, CallerBuffer;
- ULONG Flags, LengthNeeded, FilePartSize;
+ ULONG Flags;
+ SIZE_T LengthNeeded, FilePartSize;
NTSTATUS Status;
DWORD Result = 0;
IN DWORD cchBuffer)
{
PWCHAR Path, Original, First, Last, Buffer, Src, Dst;
- ULONG Length;
+ SIZE_T Length, ReturnLength;
WCHAR LastChar;
HANDLE FindHandle;
- DWORD ReturnLength;
ULONG ErrorMode;
BOOLEAN Found = FALSE;
WIN32_FIND_DATAW FindFileData;
IN DWORD cchBuffer)
{
PWCHAR Path, Original, First, Last, Buffer, Src, Dst;
- ULONG Length;
+ SIZE_T Length, ReturnLength;
WCHAR LastChar;
HANDLE FindHandle;
- DWORD ReturnLength;
ULONG ErrorMode;
BOOLEAN Found = FALSE;
WIN32_FIND_DATAW FindFileData;
if (Handles->ViewBase.QuadPart)
{
Status = NtUnmapViewOfSection(NtCurrentProcess(),
- (PVOID)Handles->ViewBase.LowPart);
+ (PVOID)(ULONG_PTR)Handles->ViewBase.QuadPart);
ASSERT(NT_SUCCESS(Status));
}
}
SECTION_IMAGE_INFORMATION ImageInformation;
IO_STATUS_BLOCK IoStatusBlock;
CLIENT_ID ClientId;
- ULONG NoWindow, RegionSize, StackSize, ErrorCode, Flags;
+ ULONG NoWindow, StackSize, ErrorCode, Flags;
+ SIZE_T RegionSize;
USHORT ImageMachine;
ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
ULONG_PTR ErrorParameters[2];
SIZE_T n;
WCHAR SaveChar;
ULONG Length, FileAttribs, CmdQuoteLength;
- ULONG CmdLineLength, ResultSize;
+ ULONG ResultSize;
+ SIZE_T EnvironmentLength, CmdLineLength;
PWCHAR QuotedCmdLine, AnsiCmdCommand, ExtBuffer, CurrentDirectory;
PWCHAR NullBuffer, ScanString, NameBuffer, SearchPath, DebuggerCmdLine;
ANSI_STRING AnsiEnv;
AnsiEnv.Buffer = pcScan = (PCHAR)lpEnvironment;
while ((*pcScan) || (*(pcScan + 1))) ++pcScan;
+ /* Make sure the environment is not too large */
+ EnvironmentLength = (pcScan + sizeof(ANSI_NULL) - (PCHAR)lpEnvironment);
+ if (EnvironmentLength > MAXUSHORT)
+ {
+ /* Fail */
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
/* Create our ANSI String */
- AnsiEnv.Length = pcScan - (PCHAR)lpEnvironment + sizeof(ANSI_NULL);
+ AnsiEnv.Length = (USHORT)EnvironmentLength;
AnsiEnv.MaximumLength = AnsiEnv.Length + sizeof(ANSI_NULL);
/* Allocate memory for the Unicode Environment */
if (VdmReserve)
{
/* Reserve the requested allocation */
+ RegionSize = VdmReserve;
Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress,
0,
- &VdmReserve,
+ &RegionSize,
MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(Status))
Result = FALSE;
goto Quickie;
}
+
+ VdmReserve = (ULONG)RegionSize;
}
/* Check if we've already queried information on the section */
/* Write the remote PEB address and clear it locally, we no longer use it */
CreateProcessMsg->PebAddressNative = RemotePeb;
+#ifdef _WIN64
+ DPRINT1("TODO: WOW64 is not supported yet\n");
+ CreateProcessMsg->PebAddressWow64 = 0;
+#else
CreateProcessMsg->PebAddressWow64 = (ULONG)RemotePeb;
+#endif
RemotePeb = NULL;
/* Now check what kind of architecture this image was made for */
BOOL Success = FALSE;
NTSTATUS Status;
- ULONG RegionSize, EnvironmentSize = 0;
+ ULONG EnvironmentSize = 0;
+ SIZE_T RegionSize;
PWCHAR Environment, NewEnvironment = NULL;
ENV_NAME_TYPE NameType;
ULONG NameLength, NumChars, Remaining;
BaseDestroyVDMEnvironment(IN PANSI_STRING AnsiEnv,
IN PUNICODE_STRING UnicodeEnv)
{
- ULONG Dummy = 0;
+ SIZE_T Dummy = 0;
/* Clear the ANSI buffer since Rtl creates this for us */
if (AnsiEnv->Buffer) RtlFreeAnsiString(AnsiEnv);
NTSTATUS Status;
/* Make sure the address is within the granularity of the system (64K) */
- if ((lpAddress) &&
- (lpAddress < (PVOID)BaseStaticServerData->SysInfo.AllocationGranularity))
+ if ((lpAddress != NULL) &&
+ (lpAddress < UlongToPtr(BaseStaticServerData->SysInfo.AllocationGranularity)))
{
/* Fail the call */
SetLastError(ERROR_INVALID_PARAMETER);
#include <ndk/setypes.h>
#include <ndk/umfuncs.h>
+#include <ntstrsafe.h>
+
/* CSRSS Headers */
#include <csr/csr.h>
#include <win/base.h>