示例#1
0
文件: winldr.c 项目: RareHare/reactos
PVOID
WinLdrLoadModule(PCSTR ModuleName,
                 ULONG *Size,
                 TYPE_OF_MEMORY MemoryType)
{
    ULONG FileId;
    PVOID PhysicalBase;
    FILEINFORMATION FileInfo;
    ULONG FileSize;
    ULONG Status;
    ULONG BytesRead;

    //CHAR ProgressString[256];

    /* Inform user we are loading files */
    //sprintf(ProgressString, "Loading %s...", FileName);
    //UiDrawProgressBarCenter(1, 100, ProgressString);

    TRACE("Loading module %s\n", ModuleName);
    *Size = 0;

    /* Open the image file */
    Status = ArcOpen((PCHAR)ModuleName, OpenReadOnly, &FileId);
    if (Status != ESUCCESS)
    {
        /* In case of errors, we just return, without complaining to the user */
        return NULL;
    }

    /* Get this file's size */
    Status = ArcGetFileInformation(FileId, &FileInfo);
    if (Status != ESUCCESS)
    {
        ArcClose(FileId);
        return NULL;
    }
    FileSize = FileInfo.EndingAddress.LowPart;
    *Size = FileSize;

    /* Allocate memory */
    PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
    if (PhysicalBase == NULL)
    {
        ArcClose(FileId);
        return NULL;
    }

    /* Load whole file */
    Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
    ArcClose(FileId);
    if (Status != ESUCCESS)
    {
        return NULL;
    }

    TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);

    return PhysicalBase;
}
示例#2
0
BOOLEAN
WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                     IN LPCSTR DirectoryPath,
                     IN LPCSTR HiveName)
{
	ULONG FileId;
	CHAR FullHiveName[256];
	LONG Status;
	FILEINFORMATION FileInfo;
	ULONG HiveFileSize;
	ULONG_PTR HiveDataPhysical;
	PVOID HiveDataVirtual;
	ULONG BytesRead;
	LPCWSTR FsService;

	/* Concatenate path and filename to get the full name */
	strcpy(FullHiveName, DirectoryPath);
	strcat(FullHiveName, HiveName);
	//Print(L"Loading %s...\n", FullHiveName);
	Status = ArcOpen(FullHiveName, OpenReadOnly, &FileId);

	if (Status != ESUCCESS)
	{
		UiMessageBox("Opening hive file failed!");
		return FALSE;
	}

	/* Get the file length */
	Status = ArcGetFileInformation(FileId, &FileInfo);

	if (Status != ESUCCESS)
	{
		ArcClose(FileId);
		UiMessageBox("Hive file has 0 size!");
		return FALSE;
	}
	HiveFileSize = FileInfo.EndingAddress.LowPart;

	/* Round up the size to page boundary and alloc memory */
	HiveDataPhysical = (ULONG_PTR)MmAllocateMemoryWithType(
		MM_SIZE_TO_PAGES(HiveFileSize + MM_PAGE_SIZE - 1) << MM_PAGE_SHIFT,
		LoaderRegistryData);

	if (HiveDataPhysical == 0)
	{
		ArcClose(FileId);
		UiMessageBox("Unable to alloc memory for a hive!");
		return FALSE;
	}

	/* Convert address to virtual */
    HiveDataVirtual = PaToVa((PVOID)HiveDataPhysical);

	/* Fill LoaderBlock's entries */
	LoaderBlock->RegistryLength = HiveFileSize;
	LoaderBlock->RegistryBase = HiveDataVirtual;

	/* Finally read from file to the memory */
	Status = ArcRead(FileId, (PVOID)HiveDataPhysical, HiveFileSize, &BytesRead);
	if (Status != ESUCCESS)
	{
		ArcClose(FileId);
		UiMessageBox("Unable to read from hive file!");
		return FALSE;
	}

	// Add boot filesystem driver to the list
	FsService = FsGetServiceName(FileId);
	if (FsService)
	{
		TRACE("  Adding filesystem service %S\n", FsService);
		Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
			L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
			NULL,
			(LPWSTR)FsService);
		if (!Status)
			TRACE(" Failed to add filesystem service\n");
	}
	else
	{
		TRACE("  No required filesystem service\n");
	}

	ArcClose(FileId);
	return TRUE;
}
示例#3
0
BOOLEAN
WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                  IN LPCSTR DirectoryPath,
                  IN LPCSTR AnsiFileName,
                  IN LPCSTR OemFileName,
                  IN LPCSTR LanguageFileName)
{
	CHAR FileName[255];
	ULONG AnsiFileId;
	ULONG OemFileId;
	ULONG LanguageFileId;
	ULONG AnsiFileSize, OemFileSize, LanguageFileSize;
	ULONG TotalSize;
	ULONG_PTR NlsDataBase;
	PVOID NlsVirtual;
	BOOLEAN AnsiEqualsOem = FALSE;
	FILEINFORMATION FileInfo;
	ULONG BytesRead, Status;

	/* There may be a case, when OEM and ANSI page coincide */
	if (!strcmp(AnsiFileName, OemFileName))
		AnsiEqualsOem = TRUE;

	/* Open file with ANSI and store its size */
	//Print(L"Loading %s...\n", Filename);
	strcpy(FileName, DirectoryPath);
	strcat(FileName, AnsiFileName);
	Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);

	if (Status != ESUCCESS)
		goto Failure;

	Status = ArcGetFileInformation(AnsiFileId, &FileInfo);
	if (Status != ESUCCESS)
		goto Failure;
	AnsiFileSize = FileInfo.EndingAddress.LowPart;
	TRACE("AnsiFileSize: %d\n", AnsiFileSize);
	ArcClose(AnsiFileId);

	/* Open OEM file and store its length */
	if (AnsiEqualsOem)
	{
		OemFileSize = 0;
	}
	else
	{
		//Print(L"Loading %s...\n", Filename);
		strcpy(FileName, DirectoryPath);
		strcat(FileName, OemFileName);
		Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);

		if (Status != ESUCCESS)
			goto Failure;

		Status = ArcGetFileInformation(OemFileId, &FileInfo);
		if (Status != ESUCCESS)
			goto Failure;
		OemFileSize = FileInfo.EndingAddress.LowPart;
		ArcClose(OemFileId);
	}
	TRACE("OemFileSize: %d\n", OemFileSize);

	/* And finally open the language codepage file and store its length */
	//Print(L"Loading %s...\n", Filename);
	strcpy(FileName, DirectoryPath);
	strcat(FileName, LanguageFileName);
	Status = ArcOpen(FileName, OpenReadOnly, &LanguageFileId);

	if (Status != ESUCCESS)
		goto Failure;

	Status = ArcGetFileInformation(LanguageFileId, &FileInfo);
	if (Status != ESUCCESS)
		goto Failure;
	LanguageFileSize = FileInfo.EndingAddress.LowPart;
	ArcClose(LanguageFileId);
	TRACE("LanguageFileSize: %d\n", LanguageFileSize);

	/* 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 */
	TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
		MM_SIZE_TO_PAGES(OemFileSize)  +
		MM_SIZE_TO_PAGES(LanguageFileSize);

	/* Store it for later marking the pages as NlsData type */
	TotalNLSSize = TotalSize;

	NlsDataBase = (ULONG_PTR)MmAllocateMemoryWithType(TotalSize*MM_PAGE_SIZE, LoaderNlsData);

	if (NlsDataBase == 0)
		goto Failure;

	NlsVirtual = PaToVa((PVOID)NlsDataBase);
	LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
	LoaderBlock->NlsData->OemCodePageData = (PVOID)((PUCHAR)NlsVirtual +
		(MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
	LoaderBlock->NlsData->UnicodeCodePageData = (PVOID)((PUCHAR)NlsVirtual +
		(MM_SIZE_TO_PAGES(AnsiFileSize) << 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 */
	if (AnsiEqualsOem)
		LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;


	/* Now actually read the data into memory, starting with Ansi file */
	strcpy(FileName, DirectoryPath);
	strcat(FileName, AnsiFileName);
	Status = ArcOpen(FileName, OpenReadOnly, &AnsiFileId);

	if (Status != ESUCCESS)
		goto Failure;

	Status = ArcRead(AnsiFileId, VaToPa(LoaderBlock->NlsData->AnsiCodePageData), AnsiFileSize, &BytesRead);

	if (Status != ESUCCESS)
		goto Failure;

	ArcClose(AnsiFileId);

	/* OEM now, if it doesn't equal Ansi of course */
	if (!AnsiEqualsOem)
	{
		strcpy(FileName, DirectoryPath);
		strcat(FileName, OemFileName);
		Status = ArcOpen(FileName, OpenReadOnly, &OemFileId);

		if (Status != ESUCCESS)
			goto Failure;

		Status = ArcRead(OemFileId, VaToPa(LoaderBlock->NlsData->OemCodePageData), OemFileSize, &BytesRead);

		if (Status != ESUCCESS)
			goto Failure;

		ArcClose(OemFileId);
	}

	/* finally the language file */
	strcpy(FileName, DirectoryPath);
	strcat(FileName, LanguageFileName);
	Status = ArcOpen(FileName, OpenReadOnly, &LanguageFileId);

	if (Status != ESUCCESS)
		goto Failure;

	Status = ArcRead(LanguageFileId, VaToPa(LoaderBlock->NlsData->UnicodeCodePageData), LanguageFileSize, &BytesRead);

	if (Status != ESUCCESS)
		goto Failure;

	ArcClose(LanguageFileId);

	//
	// THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
	// Should go to WinLdrLoadOemHalFont(), when it will be implemented
	//
	LoaderBlock->OemFontFile = VaToPa(LoaderBlock->NlsData->UnicodeCodePageData);

	/* Convert NlsTables address to VA */
	LoaderBlock->NlsData = PaToVa(LoaderBlock->NlsData);

	return TRUE;

Failure:
	//UiMessageBox("Error reading NLS file %s\n", Filename);
	UiMessageBox("Error reading NLS file!");
	return FALSE;
}
示例#4
0
文件: low.c 项目: BuloZB/WinNT4
ARC_STATUS
LowGetPartitionGeometry(
    IN  PCHAR   PartitionPath,
    OUT PULONG  TotalSectorCount,
    OUT PULONG  SectorSize,
    OUT PULONG  SectorsPerTrack,
    OUT PULONG  Heads
    )
/*++

Routine Description:

    This routine computes the drive geometry for the given partition or
    physical disk.

Arguments:

    PartitionPath   - Supplies a path to the partition or physical disk.
    NumberOfSectors - Returns the number of sectors.
    SectorSize      - Returns the sector size.
    SectorsPerTrack - Returns the number of sectors per track.
    Heads           - Returns the number of heads.

Return Value:

    ArcOpen, ArcGetFileInformation, ArcClose, E2BIG, ESUCCESS

--*/
{
    FILE_INFORMATION    file_info;
    ARC_STATUS          r;
    ULONG               fileid;
    LARGE_INTEGER       l;
    CM_DISK_GEOMETRY_DEVICE_DATA    *DiskGeometry;
    CONFIGURATION_COMPONENT         *DiskComponent;
    CM_PARTIAL_RESOURCE_LIST        *DiskConfiguration;
    CHAR                            DataBuffer[sizeof(CM_PARTIAL_RESOURCE_LIST) +
                                               sizeof(CM_DISK_GEOMETRY_DEVICE_DATA)];
    CM_PARTIAL_RESOURCE_DESCRIPTOR  *DiskData;

    // Always assume 512 bytes per sector.

    *SectorSize      = 512;

    // Assume the SCSI default values for number of heads and sectors per track

    *SectorsPerTrack = 32;
    *Heads           = 64;

    // See if there is device specific data describing the geometry of
    // the drive.  If there is none, then just use the default SCSI
    // values.

    DiskComponent = ArcGetComponent(PartitionPath);

    if (DiskComponent == NULL) {
        return EINVAL;
    }

    //
    // See if the ConfigurationDataLength is correct
    // It should contain one DeviceSpecific resource descriptor
    //

    if (DiskComponent->ConfigurationDataLength == sizeof(CM_PARTIAL_RESOURCE_LIST) +
                                                  sizeof(CM_DISK_GEOMETRY_DEVICE_DATA)  ) {

        DiskConfiguration = (CM_PARTIAL_RESOURCE_LIST *)DataBuffer;

        r = ArcGetConfigurationData(DiskConfiguration,DiskComponent);

        if (r == ESUCCESS) {

            //
            // See if the Configuration Data has ARC version 1.3 or greater
            //

            if  ( (DiskConfiguration->Version == 1 && DiskConfiguration->Revision >=3 ) ||
                  (DiskConfiguration->Version >  1)                                        ) {

                DiskData = &(DiskConfiguration->PartialDescriptors[DiskConfiguration->Count-1]);

                if (DiskData->Type == CmResourceTypeDeviceSpecific) {

                    if (DiskData->u.DeviceSpecificData.DataSize == sizeof(CM_DISK_GEOMETRY_DEVICE_DATA)) {
                        DiskGeometry     = (CM_DISK_GEOMETRY_DEVICE_DATA *)
                                           &(DiskConfiguration->PartialDescriptors[DiskConfiguration->Count]);
                        *SectorsPerTrack = DiskGeometry->SectorsPerTrack;
                        *Heads           = DiskGeometry->NumberOfHeads;
                        *SectorSize      = DiskGeometry->BytesPerSector;
                    }
                }
            }
        }
    }

//    PrintError("SectorSize = %08x",*SectorSize);
//    PrintError("SectorsPerTrack = %08x",*SectorsPerTrack);
//    PrintError("Heads = %08x",*Heads);

    r = ArcOpen(PartitionPath, ArcOpenReadOnly, &fileid);

    if (r != ESUCCESS) {
        return r;
    }

    r = ArcGetFileInformation(fileid, &file_info);

    if (r != ESUCCESS) {
        return r;
    }

    r = ArcClose(fileid);

    if (r != ESUCCESS) {
        return r;
    }

    l.QuadPart = file_info.EndingAddress.QuadPart -
                 file_info.StartingAddress.QuadPart;

    l.QuadPart = ((ULONGLONG)l.QuadPart) / ((ULONGLONG)(*SectorSize));

    if (l.HighPart) {
        return E2BIG;
    }

    *TotalSectorCount = l.LowPart;

    return ESUCCESS;
}
示例#5
0
BOOLEAN
InfOpenFile(
    PHINF InfHandle,
    PCSTR FileName,
    PULONG ErrorLine)
{
    FILEINFORMATION Information;
    ULONG FileId;
    PCHAR FileBuffer;
    ULONG FileSize, Count;
    PINFCACHE Cache;
    BOOLEAN Success;
    LONG ret;

    *InfHandle = NULL;
    *ErrorLine = (ULONG) - 1;

    //
    // Open the .inf file
    //
    FileId = FsOpenFile(FileName);
    if (!FileId)
    {
        return FALSE;
    }

    //
    // Query file size
    //
    ret = ArcGetFileInformation(FileId, &Information);
    if ((ret != ESUCCESS) || (Information.EndingAddress.HighPart != 0))
    {
        ArcClose(FileId);
        return FALSE;
    }
    FileSize = Information.EndingAddress.LowPart;

    //
    // Allocate buffer to cache the file
    //
    FileBuffer = MmHeapAlloc(FileSize + 1);
    if (!FileBuffer)
    {
        ArcClose(FileId);
        return FALSE;
    }

    //
    // Read file into memory
    //
    ret = ArcRead(FileId, FileBuffer, FileSize, &Count);
    if ((ret != ESUCCESS) || (Count != FileSize))
    {
        ArcClose(FileId);
        MmHeapFree(FileBuffer);
        return FALSE;
    }

    //
    // We don't need the file anymore. Close it
    //
    ArcClose(FileId);

    //
    // Append string terminator
    //
    FileBuffer[FileSize] = 0;

    //
    // Allocate infcache header
    //
    Cache = (PINFCACHE)MmHeapAlloc(sizeof(INFCACHE));
    if (!Cache)
    {
        MmHeapFree(FileBuffer);
        return FALSE;
    }

    //
    // Initialize inicache header
    //
    RtlZeroMemory(Cache, sizeof(INFCACHE));

    //
    // Parse the inf buffer
    //
    Success = InfpParseBuffer(Cache,
                              FileBuffer,
                              FileBuffer + FileSize,
                              ErrorLine);
    if (!Success)
    {
        MmHeapFree(Cache);
        Cache = NULL;
    }

    //
    // Free file buffer, as it has been parsed
    //
    MmHeapFree(FileBuffer);

    //
    // Return .inf parsed contents
    //
    *InfHandle = (HINF)Cache;

    return Success;
}
示例#6
0
ARC_STATUS
ReadAndVerifyUpdateFile(
    IN PCHAR PathName,
    OUT PULONG BufferAddress,
    OUT PULONG FirmwareStart,
    OUT PULONG BufferLength,
    OUT PULONG LowROMBlock,
    OUT PULONG HighROMBlock
    )
/*++

Routine Description:

    This attempts to load and verify the firmware update file.

Arguments:

    PathName		A pointer to string descriptor for the name of
		        the file to load.

    BufferAddress	A pointer to a variable that receives the
		        address of the image base.

    FirmwareStart	A pointer to a variable that receives the address
    			of the start of the firmware.  This is the first
    			byte after the null byte that terminates the
    			identifier string.

    BufferLength	A pointer to a variable that receives the length of
			the image.

    LowROMBlock		A pointer to a variable that receives the low ROM
    			block to be updated.

    HighROMBlock	A pointer to a variable that receives the low ROM
    			block to be updated.

Return Value:

    ESUCCESS is returned if the image file is loaded and verified.

    Otherwise, an unsuccessful status is returned that describes the
    reason for failure.  Additionally, some detailed error messages
    may be printed out by this function.

    With any return, the file will have already been closed.
--*/

{

    ULONG ActualBase;
    ULONG Count;
    ULONG FileId;
    ULONG Index;
    ULONG PageCount;
    ARC_STATUS Status;
    LARGE_INTEGER SeekPosition;
    FILE_INFORMATION FileInfo;
    ULONG FileSize;
    CHAR ChecksumAdjustment[4];
    ULONG AccumulatedSum;
    ULONG AmountOfBinaryData;
    

    //
    // Attempt to open the file.
    //

    Status = ArcOpen(PathName, ArcOpenReadOnly, &FileId);
    if (Status != ESUCCESS) {
        VenPrint(FWUP_READ_CANT_OPEN_MSG);
        return Status;
    }

    //
    // Get the file information to figure out how big the file is.
    //

    Status = ArcGetFileInformation(FileId, &FileInfo);

    if (Status != ESUCCESS) {
        VenPrint(FWUP_READ_CANT_GET_FILE_INFO_MSG);
        ArcClose(FileId);
	return Status;
    }

    FileSize = FileInfo.EndingAddress.LowPart - FileInfo.StartingAddress.LowPart;

    if ((FileSize < MINIMUM_UPDATE_FILE_SIZE) || (FileSize > MAXIMUM_UPDATE_FILE_SIZE)) {
    	VenPrint(FWUP_READ_BAD_SIZE_MSG);
    	ArcClose(FileId);
    	return EINVAL;
    }
    

    //
    // Compute number of pages in the file and read it in.
    //

    PageCount = (FileSize + PAGE_SIZE - 1) >> PAGE_SHIFT;

    Status = JnFsAllocateDescriptor(MemoryFree, PageCount, &ActualBase);

    if (Status != ESUCCESS) {
	VenPrint1(FWUP_READ_NOT_ENOUGH_MEMORY, PageCount);
        ArcClose(FileId);
        return Status;
    }

    //
    // Compute the byte address of the update file buffer
    //
    *BufferAddress = KSEG0_BASE | (ActualBase << PAGE_SHIFT);
    VenPrint(FWUP_READ_READING_MSG);
    Status = ArcRead(FileId, (PUCHAR)*BufferAddress, FileSize, &Count);
    ArcClose(FileId);

    if (Count != FileSize) {
        VenPrint2(FWUP_READ_BAD_READ_COUNT_MSG, FileSize, Count);
	if (Status != ESUCCESS) {
	    return Status;
	} else {
	    return EIO;
	}
    }    	
    if (Status != ESUCCESS) {
        return Status;
    }


    //
    // Verify the file's checksum.
    //

    VenPrint(FWUP_READ_VERIFYING_CHECKSUM_MSG);
    AccumulatedSum = 0;
    Index = 0;
    do {
        ChecksumAdjustment[0] = ChecksumAdjustment[1];
        ChecksumAdjustment[1] = ChecksumAdjustment[2];
        ChecksumAdjustment[2] = ChecksumAdjustment[3];
        ChecksumAdjustment[3] = *(((PUCHAR)*BufferAddress)+Index);
    	AccumulatedSum += *(((PUCHAR)*BufferAddress)+Index);
        Index++;
    } while (Index < FileSize);     // Filesize is 1-based, Index is 0-based

    // The last four bytes were really a 32-bit additive-zero checksum,
    // order of {low byte -- high byte }
    AccumulatedSum = AccumulatedSum -
		     ChecksumAdjustment[3] -
        	     ChecksumAdjustment[2] -
		     ChecksumAdjustment[1] -
		     ChecksumAdjustment[0];
    AccumulatedSum = AccumulatedSum +
    		     ((ChecksumAdjustment[3] << 24) |
    		      (ChecksumAdjustment[2] << 16) |
    		      (ChecksumAdjustment[1] << 8) |
    		      (ChecksumAdjustment[0]));
    		      
    if (AccumulatedSum != 0) {
    	VenPrint1 (FWUP_READ_BAD_CHECKSUM_MSG, AccumulatedSum);
        return ENOEXEC;
    }


    //
    // The checksum is good.  Find the start of the firmware data.
    //

    Index = 0;
    while ((Index < MAXIMUM_IDENTIFIER_LENGTH) &&
	   (*(((PUCHAR)*BufferAddress)+Index) != 0)) {
        Index++;
    }

    if (Index == MAXIMUM_IDENTIFIER_LENGTH) {
    	VenPrint(FWUP_READ_IDENTIFIER_TOO_LONG_MSG);
    	return ENOEXEC;
    }

    //
    // Skip over the starting block byte
    //

    *FirmwareStart = (ULONG)(((PUCHAR)*BufferAddress) + Index + 2);

    
    //
    // Now verify legality of the starting block number, and verify that
    // we have at least that much data in the binary section of the file.
    //

    *LowROMBlock = *(((PUCHAR)*BufferAddress) + Index + 1);

    if (*LowROMBlock > 0xf) {
    	VenPrint1(FWUP_READ_BAD_START_BLOCK_MSG, *LowROMBlock);
    	return ENOEXEC;
    }

    AmountOfBinaryData = FileSize -
                         (ULONG)((PUCHAR)*FirmwareStart -
				 (PUCHAR)*BufferAddress) -
                         4;
          
    *BufferLength = AmountOfBinaryData;

    if ((AmountOfBinaryData % SIXTY_FOUR_KB) != 0) {
    	VenPrint(FWUP_READ_BAD_BINARY_DATA_MSG);
    	return EBADF;
    }

    *HighROMBlock = *LowROMBlock + (AmountOfBinaryData / SIXTY_FOUR_KB) - 1;
    
    if ((*HighROMBlock < *LowROMBlock) || (*HighROMBlock > 0xf)) {
    	VenPrint2(FWUP_READ_TOO_MUCH_DATA_MSG, *LowROMBlock, *HighROMBlock);
    	return E2BIG;
    }


    return ESUCCESS;
}
示例#7
0
BOOLEAN IniFileInitialize(VOID)
{
    FILEINFORMATION FileInformation;
    ULONG FileId; // File handle for freeldr.ini
    PCHAR FreeLoaderIniFileData;
    ULONG FreeLoaderIniFileSize, Count;
    LONG ret;
    BOOLEAN Success;
    TRACE("IniFileInitialize()\n");

    //
    // Open freeldr.ini
    //
    ret = IniOpenIniFile(&FileId);
    if (ret != ESUCCESS)
    {
        UiMessageBoxCritical("Error opening freeldr.ini or file not found.\nYou need to re-install FreeLoader.");
        return FALSE;
    }

    //
    // Get the file size
    //
    ret = ArcGetFileInformation(FileId, &FileInformation);
    if (ret != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
    {
        UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
        return FALSE;
    }
    FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;

    //
    // Allocate memory to cache the whole freeldr.ini
    //
    FreeLoaderIniFileData = MmHeapAlloc(FreeLoaderIniFileSize);
    if (!FreeLoaderIniFileData)
    {
        UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
        ArcClose(FileId);
        return FALSE;
    }

    //
    // Read freeldr.ini off the disk
    //
    ret = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
    if (ret != ESUCCESS || Count != FreeLoaderIniFileSize)
    {
        UiMessageBoxCritical("Error while reading freeldr.ini.");
        ArcClose(FileId);
        MmHeapFree(FreeLoaderIniFileData);
        return FALSE;
    }

    //
    // Parse the .ini file data
    //
    Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);

    //
    // Do some cleanup, and return
    //
    ArcClose(FileId);
    MmHeapFree(FreeLoaderIniFileData);

    return Success;
}