Beispiel #1
0
BOOL WINAPI ScyllaRebuildFileW(const WCHAR * fileToRebuild, BOOL removeDosStub, BOOL updatePeHeaderChecksum, BOOL createBackup)
{

	if (createBackup)
	{
		if (!ProcessAccessHelp::createBackupFile(fileToRebuild))
		{
			return FALSE;
		}
	}

	PeParser peFile(fileToRebuild, true);
	if (peFile.readPeSectionsFromFile())
	{
		peFile.setDefaultFileAlignment();
		if (removeDosStub)
		{
			peFile.removeDosStub();
		}
		peFile.alignAllSectionHeaders();
		peFile.fixPeHeader();

		if (peFile.savePeFileToDisk(fileToRebuild))
		{
			if (updatePeHeaderChecksum)
			{
				PeParser::updatePeHeaderChecksum(fileToRebuild, (DWORD)ProcessAccessHelp::getFileSize(fileToRebuild));
			}
			return TRUE;
		}
	}

	return FALSE;
}
// Adds a modules to the MODULE_FILE_INFO list.  If the module imports other
// modules, this routine recurses to add them, and check their imports.
errModuleDependencyList
MODULE_DEPENDENCY_LIST::AddModule( PSTR pszFileName )
{
    PE_EXE peFile( pszFileName );       // Get easy access to the executable
    
    if ( FALSE == peFile.IsValid() )    // A valid PE file???
        return (errModuleDependencyList)peFile.GetErrorType();

    PMODULE_FILE_INFO pNew = new MODULE_FILE_INFO( pszFileName );
    if ( !pNew )
        return errMDL_GENERAL_FAILURE;

    pNew->m_pNext = m_pList;
    m_pList = pNew;

    m_cModules++;
    
    //
    // Now see if this module imports any other modules.  If so, we need
    // to recurse and add them as well.
    //
    if (0 == peFile.GetDataDirectoryEntrySize( IMAGE_DIRECTORY_ENTRY_IMPORT ))
        return errMDL_NO_ERROR;

    // Make a pointer to the imports table
    PIMAGE_IMPORT_DESCRIPTOR pImportDir;
    pImportDir = (PIMAGE_IMPORT_DESCRIPTOR)
        peFile.GetDataDirectoryEntryPointer(IMAGE_DIRECTORY_ENTRY_IMPORT);
    if ( !pImportDir )
        return errMDL_NO_ERROR;

    // While there are still non-null IMAGE_IMPORT_DESCRIPTORs...
    while ( pImportDir->Name )
    {
        // Get a pointer to the imported module's base name
        PSTR pszBaseName;
        pszBaseName = (PSTR)peFile.GetReadablePointerFromRVA(pImportDir->Name);
        if ( !pszBaseName )
            break;

        // Check to see if it's already in our list.  Don't add again if so.
        if ( 0 == LookupModule( pszBaseName, FALSE ) )
        {
            // Search path supposedly has the same searching algorithm as
            // the the Win32 loader...
            char szPath[MAX_PATH];
            PSTR pszDontCare;
            if ( SearchPath(0, pszBaseName, 0, MAX_PATH, szPath, &pszDontCare))
                AddModule( szPath );
            else
                pNew->AddNotFoundModule( pszBaseName );
        }
        
        pImportDir++;   // Advance to next imported module
    }

    return errMDL_NO_ERROR;
}
Beispiel #3
0
void DumpMemoryGui::setAllSectionNames( DWORD_PTR moduleBase, WCHAR * moduleName )
{
	WCHAR sectionNameW[IMAGE_SIZEOF_SHORT_NAME + 1] = {0};

	PeParser peFile(moduleName);

	if (peFile.isValidPeFile())
	{
		std::vector<PeFileSection> & listSectionHeader = peFile.getSectionHeaderList();

		for (WORD i = 0; i < peFile.getNumberOfSections(); i++)
		{
			peFile.getSectionNameUnicode(i, sectionNameW, _countof(sectionNameW));

			setSectionName(moduleBase + listSectionHeader[i].sectionHeader.VirtualAddress, listSectionHeader[i].sectionHeader.Misc.VirtualSize, sectionNameW);
		}
	}
	else
	{
		MessageBox(moduleName,L"Not a valid PE -> This should never happen",MB_ICONERROR);
	}

}
Beispiel #4
0
bool PluginLoader::isValidDllFile( const WCHAR * fullpath )
{
	PeParser peFile(fullpath, false);

	return (peFile.isTargetFileSamePeFormat() && peFile.hasExportDirectory());
}
Beispiel #5
0
DWORD ProcessAccessHelp::getEntryPointFromFile(const WCHAR * filePath)
{
    PeParser peFile(filePath, false);

    return peFile.getEntryPoint();
}