mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 22:46:43 +00:00
[FREELDR] Minor fixes.
- Add some forgotten, or move some misplaced ArcClose() calls so as to avoid leakages in failure paths. (Thanks to Serge Gautherie for having caught some of them.) - Simplify some code; remove unneeded casts; use string-safe functions.
This commit is contained in:
parent
85d44fca59
commit
423d1e2e09
3 changed files with 74 additions and 75 deletions
|
@ -63,6 +63,7 @@ BOOLEAN IniFileInitialize(VOID)
|
||||||
if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
|
if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
|
||||||
{
|
{
|
||||||
UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
|
UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
|
||||||
|
ArcClose(FileId);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
|
FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
|
||||||
|
|
|
@ -31,6 +31,7 @@ LoadAndBootBootSector(
|
||||||
IN PCHAR Argv[],
|
IN PCHAR Argv[],
|
||||||
IN PCHAR Envp[])
|
IN PCHAR Envp[])
|
||||||
{
|
{
|
||||||
|
ARC_STATUS Status;
|
||||||
PCSTR FileName;
|
PCSTR FileName;
|
||||||
ULONG FileId;
|
ULONG FileId;
|
||||||
ULONG BytesRead;
|
ULONG BytesRead;
|
||||||
|
@ -54,14 +55,14 @@ LoadAndBootBootSector(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read boot sector */
|
/* Read boot sector */
|
||||||
if ((ArcRead(FileId, (PVOID)0x7c00, 512, &BytesRead) != ESUCCESS) || (BytesRead != 512))
|
Status = ArcRead(FileId, (PVOID)0x7c00, 512, &BytesRead);
|
||||||
|
ArcClose(FileId);
|
||||||
|
if ((Status != ESUCCESS) || (BytesRead != 512))
|
||||||
{
|
{
|
||||||
UiMessageBox("Unable to read boot sector.");
|
UiMessageBox("Unable to read boot sector.");
|
||||||
return EIO;
|
return EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcClose(FileId);
|
|
||||||
|
|
||||||
/* Check for validity */
|
/* Check for validity */
|
||||||
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +94,7 @@ LoadAndBootPartitionOrDrive(
|
||||||
IN UCHAR DriveNumber,
|
IN UCHAR DriveNumber,
|
||||||
IN ULONG PartitionNumber OPTIONAL)
|
IN ULONG PartitionNumber OPTIONAL)
|
||||||
{
|
{
|
||||||
|
ARC_STATUS Status;
|
||||||
ULONG FileId;
|
ULONG FileId;
|
||||||
ULONG BytesRead;
|
ULONG BytesRead;
|
||||||
CHAR ArcPath[MAX_PATH];
|
CHAR ArcPath[MAX_PATH];
|
||||||
|
@ -100,7 +102,10 @@ LoadAndBootPartitionOrDrive(
|
||||||
/* Construct the corresponding ARC path */
|
/* Construct the corresponding ARC path */
|
||||||
ConstructArcPath(ArcPath, "", DriveNumber, PartitionNumber);
|
ConstructArcPath(ArcPath, "", DriveNumber, PartitionNumber);
|
||||||
*strrchr(ArcPath, '\\') = ANSI_NULL; // Trim the trailing path separator.
|
*strrchr(ArcPath, '\\') = ANSI_NULL; // Trim the trailing path separator.
|
||||||
if (ArcOpen(ArcPath, OpenReadOnly, &FileId) != ESUCCESS)
|
|
||||||
|
/* Open the volume */
|
||||||
|
Status = ArcOpen(ArcPath, OpenReadOnly, &FileId);
|
||||||
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
UiMessageBox("Unable to open %s", ArcPath);
|
UiMessageBox("Unable to open %s", ArcPath);
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
@ -110,7 +115,9 @@ LoadAndBootPartitionOrDrive(
|
||||||
* Now try to read the partition boot sector or the MBR (when PartitionNumber == 0).
|
* Now try to read the partition boot sector or the MBR (when PartitionNumber == 0).
|
||||||
* If this fails then abort.
|
* If this fails then abort.
|
||||||
*/
|
*/
|
||||||
if ((ArcRead(FileId, (PVOID)0x7c00, 512, &BytesRead) != ESUCCESS) || (BytesRead != 512))
|
Status = ArcRead(FileId, (PVOID)0x7c00, 512, &BytesRead);
|
||||||
|
ArcClose(FileId);
|
||||||
|
if ((Status != ESUCCESS) || (BytesRead != 512))
|
||||||
{
|
{
|
||||||
if (PartitionNumber != 0)
|
if (PartitionNumber != 0)
|
||||||
UiMessageBox("Unable to read partition's boot sector.");
|
UiMessageBox("Unable to read partition's boot sector.");
|
||||||
|
@ -119,8 +126,6 @@ LoadAndBootPartitionOrDrive(
|
||||||
return EIO;
|
return EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcClose(FileId);
|
|
||||||
|
|
||||||
/* Check for validity */
|
/* Check for validity */
|
||||||
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,14 +41,14 @@ WinLdrLoadSystemHive(
|
||||||
ARC_STATUS Status;
|
ARC_STATUS Status;
|
||||||
FILEINFORMATION FileInfo;
|
FILEINFORMATION FileInfo;
|
||||||
ULONG HiveFileSize;
|
ULONG HiveFileSize;
|
||||||
ULONG_PTR HiveDataPhysical;
|
PVOID HiveDataPhysical;
|
||||||
PVOID HiveDataVirtual;
|
PVOID HiveDataVirtual;
|
||||||
ULONG BytesRead;
|
ULONG BytesRead;
|
||||||
PCWSTR FsService;
|
PCWSTR FsService;
|
||||||
|
|
||||||
/* Concatenate path and filename to get the full name */
|
/* Concatenate path and filename to get the full name */
|
||||||
strcpy(FullHiveName, DirectoryPath);
|
RtlStringCbCopyA(FullHiveName, sizeof(FullHiveName), DirectoryPath);
|
||||||
strcat(FullHiveName, HiveName);
|
RtlStringCbCatA(FullHiveName, sizeof(FullHiveName), HiveName);
|
||||||
|
|
||||||
Status = ArcOpen(FullHiveName, OpenReadOnly, &FileId);
|
Status = ArcOpen(FullHiveName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
|
@ -69,11 +69,11 @@ WinLdrLoadSystemHive(
|
||||||
HiveFileSize = FileInfo.EndingAddress.LowPart;
|
HiveFileSize = FileInfo.EndingAddress.LowPart;
|
||||||
|
|
||||||
/* Round up the size to page boundary and alloc memory */
|
/* Round up the size to page boundary and alloc memory */
|
||||||
HiveDataPhysical = (ULONG_PTR)MmAllocateMemoryWithType(
|
HiveDataPhysical = MmAllocateMemoryWithType(
|
||||||
MM_SIZE_TO_PAGES(HiveFileSize + MM_PAGE_SIZE - 1) << MM_PAGE_SHIFT,
|
MM_SIZE_TO_PAGES(HiveFileSize + MM_PAGE_SIZE - 1) << MM_PAGE_SHIFT,
|
||||||
LoaderRegistryData);
|
LoaderRegistryData);
|
||||||
|
|
||||||
if (HiveDataPhysical == 0)
|
if (HiveDataPhysical == NULL)
|
||||||
{
|
{
|
||||||
ArcClose(FileId);
|
ArcClose(FileId);
|
||||||
UiMessageBox("Unable to alloc memory for a hive!");
|
UiMessageBox("Unable to alloc memory for a hive!");
|
||||||
|
@ -81,14 +81,14 @@ WinLdrLoadSystemHive(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert address to virtual */
|
/* Convert address to virtual */
|
||||||
HiveDataVirtual = PaToVa((PVOID)HiveDataPhysical);
|
HiveDataVirtual = PaToVa(HiveDataPhysical);
|
||||||
|
|
||||||
/* Fill LoaderBlock's entries */
|
/* Fill LoaderBlock's entries */
|
||||||
LoaderBlock->RegistryLength = HiveFileSize;
|
LoaderBlock->RegistryLength = HiveFileSize;
|
||||||
LoaderBlock->RegistryBase = HiveDataVirtual;
|
LoaderBlock->RegistryBase = HiveDataVirtual;
|
||||||
|
|
||||||
/* Finally read from file to the memory */
|
/* Finally read from file to the memory */
|
||||||
Status = ArcRead(FileId, (PVOID)HiveDataPhysical, HiveFileSize, &BytesRead);
|
Status = ArcRead(FileId, HiveDataPhysical, HiveFileSize, &BytesRead);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
ArcClose(FileId);
|
ArcClose(FileId);
|
||||||
|
@ -131,7 +131,7 @@ WinLdrInitSystemHive(
|
||||||
|
|
||||||
if (Setup)
|
if (Setup)
|
||||||
{
|
{
|
||||||
strcpy(SearchPath, SystemRoot);
|
RtlStringCbCopyA(SearchPath, sizeof(SearchPath), SystemRoot);
|
||||||
HiveName = "SETUPREG.HIV";
|
HiveName = "SETUPREG.HIV";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -140,8 +140,8 @@ WinLdrInitSystemHive(
|
||||||
// fails, then give system.alt a try, and finally try a system.sav
|
// fails, then give system.alt a try, and finally try a system.sav
|
||||||
|
|
||||||
// FIXME: For now we only try system
|
// FIXME: For now we only try system
|
||||||
strcpy(SearchPath, SystemRoot);
|
RtlStringCbCopyA(SearchPath, sizeof(SearchPath), SystemRoot);
|
||||||
strcat(SearchPath, "system32\\config\\");
|
RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\config\\");
|
||||||
HiveName = "SYSTEM";
|
HiveName = "SYSTEM";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +191,8 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
|
||||||
TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName);
|
TRACE("NLS data %s %s %s\n", AnsiName, OemName, LangName);
|
||||||
|
|
||||||
/* Load NLS data */
|
/* Load NLS data */
|
||||||
strcpy(SearchPath, SystemRoot);
|
RtlStringCbCopyA(SearchPath, sizeof(SearchPath), SystemRoot);
|
||||||
strcat(SearchPath, "system32\\");
|
RtlStringCbCatA(SearchPath, sizeof(SearchPath), "system32\\");
|
||||||
Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
|
Success = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
|
||||||
TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
|
TRACE("NLS data loading %s\n", Success ? "successful" : "failed");
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
&hKey);
|
&hKey);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Couldn't open CodePage registry key");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Couldn't open CodePage registry key");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, L"ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, L"ACP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Couldn't get ACP NLS setting");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Couldn't get ACP NLS setting");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "ACP NLS Setting exists, but isn't readable");
|
||||||
//return FALSE;
|
//return FALSE;
|
||||||
wcscpy(NameBuffer, L"c_1252.nls"); // HACK: ReactOS bug CORE-6105
|
wcscpy(NameBuffer, L"c_1252.nls"); // HACK: ReactOS bug CORE-6105
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, L"OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, L"OEMCP", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Couldn't get OEMCP NLS setting");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Couldn't get OEMCP NLS setting");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "OEMCP NLS setting exists, but isn't readable");
|
||||||
//return FALSE;
|
//return FALSE;
|
||||||
wcscpy(NameBuffer, L"c_437.nls"); // HACK: ReactOS bug CORE-6105
|
wcscpy(NameBuffer, L"c_437.nls"); // HACK: ReactOS bug CORE-6105
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
&hKey);
|
&hKey);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Couldn't open Language registry key");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Couldn't open Language registry key");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, L"Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, L"Default", NULL, (PUCHAR)szIdBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Couldn't get Language Default setting");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Couldn't get Language Default setting");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ WinLdrGetNLSNames(PSTR AnsiName,
|
||||||
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
rc = RegQueryValue(hKey, szIdBuffer, NULL, (PUCHAR)NameBuffer, &BufferSize);
|
||||||
if (rc != ERROR_SUCCESS)
|
if (rc != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
//strcpy(szErrorOut, "Language Default setting exists, but isn't readable");
|
//RtlStringCbCopyA(szErrorOut, sizeof(szErrorOut), "Language Default setting exists, but isn't readable");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
sprintf(LangName, "%S", NameBuffer);
|
sprintf(LangName, "%S", NameBuffer);
|
||||||
|
@ -305,12 +305,10 @@ WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
|
||||||
IN PCSTR LanguageFileName)
|
IN PCSTR LanguageFileName)
|
||||||
{
|
{
|
||||||
CHAR FileName[255];
|
CHAR FileName[255];
|
||||||
ULONG AnsiFileId;
|
ULONG FileId;
|
||||||
ULONG OemFileId;
|
|
||||||
ULONG LanguageFileId;
|
|
||||||
ULONG AnsiFileSize, OemFileSize, LanguageFileSize;
|
ULONG AnsiFileSize, OemFileSize, LanguageFileSize;
|
||||||
ULONG TotalSize;
|
ULONG TotalSize;
|
||||||
ULONG_PTR NlsDataBase;
|
PVOID NlsDataBase;
|
||||||
PVOID NlsVirtual;
|
PVOID NlsVirtual;
|
||||||
BOOLEAN AnsiEqualsOem = FALSE;
|
BOOLEAN AnsiEqualsOem = FALSE;
|
||||||
FILEINFORMATION FileInfo;
|
FILEINFORMATION FileInfo;
|
||||||
|
@ -322,21 +320,21 @@ WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
|
||||||
AnsiEqualsOem = TRUE;
|
AnsiEqualsOem = TRUE;
|
||||||
|
|
||||||
/* Open file with ANSI and store its size */
|
/* Open file with ANSI and store its size */
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, AnsiFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), AnsiFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcGetFileInformation(AnsiFileId, &FileInfo);
|
Status = ArcGetFileInformation(FileId, &FileInfo);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
goto Failure;
|
goto Failure;
|
||||||
AnsiFileSize = FileInfo.EndingAddress.LowPart;
|
AnsiFileSize = FileInfo.EndingAddress.LowPart;
|
||||||
TRACE("AnsiFileSize: %d\n", AnsiFileSize);
|
TRACE("AnsiFileSize: %d\n", AnsiFileSize);
|
||||||
ArcClose(AnsiFileId);
|
|
||||||
|
|
||||||
/* Open OEM file and store its length */
|
/* Open OEM file and store its length */
|
||||||
if (AnsiEqualsOem)
|
if (AnsiEqualsOem)
|
||||||
|
@ -346,128 +344,123 @@ WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Print(L"Loading %s...\n", Filename);
|
//Print(L"Loading %s...\n", Filename);
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, OemFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), OemFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcGetFileInformation(OemFileId, &FileInfo);
|
Status = ArcGetFileInformation(FileId, &FileInfo);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
goto Failure;
|
goto Failure;
|
||||||
OemFileSize = FileInfo.EndingAddress.LowPart;
|
OemFileSize = FileInfo.EndingAddress.LowPart;
|
||||||
ArcClose(OemFileId);
|
|
||||||
}
|
}
|
||||||
TRACE("OemFileSize: %d\n", OemFileSize);
|
TRACE("OemFileSize: %d\n", OemFileSize);
|
||||||
|
|
||||||
/* And finally open the language codepage file and store its length */
|
/* And finally open the language codepage file and store its length */
|
||||||
//Print(L"Loading %s...\n", Filename);
|
//Print(L"Loading %s...\n", Filename);
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, LanguageFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), LanguageFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &LanguageFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcGetFileInformation(LanguageFileId, &FileInfo);
|
Status = ArcGetFileInformation(FileId, &FileInfo);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
goto Failure;
|
goto Failure;
|
||||||
LanguageFileSize = FileInfo.EndingAddress.LowPart;
|
LanguageFileSize = FileInfo.EndingAddress.LowPart;
|
||||||
ArcClose(LanguageFileId);
|
|
||||||
TRACE("LanguageFileSize: %d\n", LanguageFileSize);
|
TRACE("LanguageFileSize: %d\n", LanguageFileSize);
|
||||||
|
|
||||||
/* Sum up all three length, having in mind that every one of them
|
/* Sum up all three length, having in mind that every one of them
|
||||||
must start at a page boundary => thus round up each file to a page */
|
must start at a page boundary => thus round up each file to a page */
|
||||||
TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
|
TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
|
||||||
MM_SIZE_TO_PAGES(OemFileSize) +
|
MM_SIZE_TO_PAGES(OemFileSize) +
|
||||||
MM_SIZE_TO_PAGES(LanguageFileSize);
|
MM_SIZE_TO_PAGES(LanguageFileSize);
|
||||||
|
|
||||||
/* Store it for later marking the pages as NlsData type */
|
/* Store it for later marking the pages as NlsData type */
|
||||||
TotalNLSSize = TotalSize;
|
TotalNLSSize = TotalSize;
|
||||||
|
|
||||||
NlsDataBase = (ULONG_PTR)MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);
|
NlsDataBase = MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);
|
||||||
|
if (NlsDataBase == NULL)
|
||||||
if (NlsDataBase == 0)
|
|
||||||
goto Failure;
|
goto Failure;
|
||||||
|
|
||||||
NlsVirtual = PaToVa((PVOID)NlsDataBase);
|
NlsVirtual = PaToVa(NlsDataBase);
|
||||||
LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
|
LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
|
||||||
LoaderBlock->NlsData->OemCodePageData = (PVOID)((PUCHAR)NlsVirtual +
|
LoaderBlock->NlsData->OemCodePageData = (PVOID)((ULONG_PTR)NlsVirtual +
|
||||||
(MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
|
(MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
|
||||||
LoaderBlock->NlsData->UnicodeCodePageData = (PVOID)((PUCHAR)NlsVirtual +
|
LoaderBlock->NlsData->UnicodeCodePageData = (PVOID)((ULONG_PTR)NlsVirtual +
|
||||||
(MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
|
(MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
|
||||||
(MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
|
(MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
|
||||||
|
|
||||||
/* Ansi and OEM data are the same - just set pointers to the same area */
|
/* Ansi and OEM data are the same - just set pointers to the same area */
|
||||||
if (AnsiEqualsOem)
|
if (AnsiEqualsOem)
|
||||||
LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
|
LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
|
||||||
|
|
||||||
|
|
||||||
/* Now actually read the data into memory, starting with Ansi file */
|
/* Now actually read the data into memory, starting with Ansi file */
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, AnsiFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), AnsiFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcRead(AnsiFileId, VaToPa(LoaderBlock->NlsData->AnsiCodePageData), AnsiFileSize, &BytesRead);
|
Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->AnsiCodePageData), AnsiFileSize, &BytesRead);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcClose(AnsiFileId);
|
|
||||||
|
|
||||||
/* OEM now, if it doesn't equal Ansi of course */
|
/* OEM now, if it doesn't equal Ansi of course */
|
||||||
if (!AnsiEqualsOem)
|
if (!AnsiEqualsOem)
|
||||||
{
|
{
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, OemFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), OemFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcRead(OemFileId, VaToPa(LoaderBlock->NlsData->OemCodePageData), OemFileSize, &BytesRead);
|
Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->OemCodePageData), OemFileSize, &BytesRead);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcClose(OemFileId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally the language file */
|
/* Finally the language file */
|
||||||
strcpy(FileName, DirectoryPath);
|
RtlStringCbCopyA(FileName, sizeof(FileName), DirectoryPath);
|
||||||
strcat(FileName, LanguageFileName);
|
RtlStringCbCatA(FileName, sizeof(FileName), LanguageFileName);
|
||||||
Status = ArcOpen(FileName, OpenReadOnly, &LanguageFileId);
|
Status = ArcOpen(FileName, OpenReadOnly, &FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
WARN("Error while opening '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ArcRead(LanguageFileId, VaToPa(LoaderBlock->NlsData->UnicodeCodePageData), LanguageFileSize, &BytesRead);
|
Status = ArcRead(FileId, VaToPa(LoaderBlock->NlsData->UnicodeCodePageData), LanguageFileSize, &BytesRead);
|
||||||
|
ArcClose(FileId);
|
||||||
if (Status != ESUCCESS)
|
if (Status != ESUCCESS)
|
||||||
{
|
{
|
||||||
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
WARN("Error while reading '%s', Status: %u\n", FileName, Status);
|
||||||
goto Failure;
|
goto Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcClose(LanguageFileId);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
|
// THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
|
||||||
// Should go to WinLdrLoadOemHalFont(), when it will be implemented
|
// Should go to WinLdrLoadOemHalFont(), when it will be implemented
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue