Ejemplo n.º 1
0
static BOOLEAN
WinLdrpLoadAndScanReferencedDll(PLIST_ENTRY ModuleListHead,
                                PCCH DirectoryPath,
                                PCH ImportName,
                                PLDR_DATA_TABLE_ENTRY *DataTableEntry)
{
    CHAR FullDllName[256];
    BOOLEAN Success;
    PVOID BasePA = NULL;

    /* Prepare the full path to the file to be loaded */
    strcpy(FullDllName, DirectoryPath);
    strcat(FullDllName, ImportName);

    TRACE("Loading referenced DLL: %s\n", FullDllName);
    //Print(L"Loading referenced DLL: %s\n", FullDllName);

    /* Load the image */
    Success = WinLdrLoadImage(FullDllName, LoaderBootDriver, &BasePA);
    if (!Success)
    {
        ERR("WinLdrLoadImage() failed\n");
        return Success;
    }

    /* Allocate DTE for newly loaded DLL */
    Success = WinLdrAllocateDataTableEntry(ModuleListHead,
                                           ImportName,
                                           FullDllName,
                                           BasePA,
                                           DataTableEntry);
    if (!Success)
    {
        ERR("WinLdrAllocateDataTableEntry() failed\n");
        return Success;
    }

    /* Scan its dependencies too */
    TRACE("WinLdrScanImportDescriptorTable() calling ourselves for %S\n",
        VaToPa((*DataTableEntry)->BaseDllName.Buffer));
    Success = WinLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, *DataTableEntry);
    if (!Success)
    {
        ERR("WinLdrScanImportDescriptorTable() failed\n");
        return Success;
    }

    return TRUE;
}
Ejemplo n.º 2
0
static
BOOLEAN
LoadModule(
    PLOADER_PARAMETER_BLOCK LoaderBlock,
    PCCH Path,
    PCCH File,
    TYPE_OF_MEMORY MemoryType,
    PLDR_DATA_TABLE_ENTRY *Dte,
    BOOLEAN IsKdTransportDll,
    ULONG Percentage)
{
    BOOLEAN Status;
    CHAR FullFileName[MAX_PATH];
    CHAR ProgressString[256];
    PVOID BaseAdress = NULL;

    UiDrawBackdrop();
    sprintf(ProgressString, "Loading %s...", File);
    UiDrawProgressBarCenter(Percentage, 100, ProgressString);

    strcpy(FullFileName, Path);
    strcat(FullFileName, "SYSTEM32\\");
    strcat(FullFileName, File);

    Status = WinLdrLoadImage(FullFileName, MemoryType, &BaseAdress);
    if (!Status)
    {
        TRACE("Loading %s failed\n", File);
        return FALSE;
    }
    TRACE("%s loaded successfully at %p\n", File, BaseAdress);

    strcpy(FullFileName, "WINDOWS\\SYSTEM32\\");
    strcat(FullFileName, File);
    /*
     * Cheat about the base DLL name if we are loading
     * the Kernel Debugger Transport DLL, to make the
     * PE loader happy.
     */
    Status = WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead,
                                          (IsKdTransportDll ? "KDCOM.DLL" : File),
                                          FullFileName,
                                          BaseAdress,
                                          Dte);

    return Status;
}
Ejemplo n.º 3
0
static BOOLEAN
WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
                       LPCSTR BootPath,
                       PUNICODE_STRING FilePath,
                       ULONG Flags,
                       PLDR_DATA_TABLE_ENTRY *DriverDTE)
{
    CHAR FullPath[1024];
    CHAR DriverPath[1024];
    CHAR DllName[1024];
    PCHAR DriverNamePos;
    BOOLEAN Status;
    PVOID DriverBase = NULL;

    // Separate the path to file name and directory path
    _snprintf(DriverPath, sizeof(DriverPath), "%wZ", FilePath);
    DriverNamePos = strrchr(DriverPath, '\\');
    if (DriverNamePos != NULL)
    {
        // Copy the name
        strcpy(DllName, DriverNamePos+1);

        // Cut out the name from the path
        *(DriverNamePos+1) = 0;
    }
    else
    {
        // There is no directory in the path
        strcpy(DllName, DriverPath);
        DriverPath[0] = 0;
    }

    TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath, DllName);

    // Check if driver is already loaded
    Status = WinLdrCheckForLoadedDll(LoadOrderListHead, DllName, DriverDTE);
    if (Status)
    {
        // We've got the pointer to its DTE, just return success
        return TRUE;
    }

    // It's not loaded, we have to load it
    _snprintf(FullPath, sizeof(FullPath), "%s%wZ", BootPath, FilePath);
    Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
    if (!Status)
        return FALSE;

    // Allocate a DTE for it
    Status = WinLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
    if (!Status)
    {
        ERR("WinLdrAllocateDataTableEntry() failed\n");
        return FALSE;
    }

    // Modify any flags, if needed
    (*DriverDTE)->Flags |= Flags;

    // Look for any dependencies it may have, and load them too
    sprintf(FullPath,"%s%s", BootPath, DriverPath);
    Status = WinLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
    if (!Status)
    {
        ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath);
        return FALSE;
    }

    return TRUE;
}