My PE Loader cannot load EXE file which bulit with VS2005.

I need to write a Simple Loader which can run simple EXE(PE Format) file. My loader can parse PE header: IMPORT,EXPORT,RELOC......
I bulit AP.exe with VS2005, and AP.exe imported msvcr80d.dll.
So when my loader parse AP.exe's import table and call LoadLibrary to load msvcr80d.dll, but it return NULL.
I have searched some information on internet, and known the "manifest" file's effect.
I have read
Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies
and related information.
And I try some method to let my loader load msvcr80d.dll successful.
For example:
Before call LoadLibrary, I do open AP.exe.manifest file,
I do open %WINDIR%\WinSxS\Manifests\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c.manifest
I do change current directory to %WINDIR%\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c
But all these attempt failed too.
So my question is :
How does LoadLibrary know whether my loader has parse the "manifest" file
How let my loader can load msvcr80d.dll library successfully like WINDOWS Loader.
What can i do now
By the way, my loader can load exe file successfully which bulit with VC6.0 .
Thank you.


Answer this question

My PE Loader cannot load EXE file which bulit with VS2005.

  • Cyrus Chan

    Help me,please.

    yxxng


  • Sarath.

    Did you try embedding the manifest into the file

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Vijay R

    Dear Ayman,
    No, there's no external manifest(.manifest file) in <output dir>, because the manifest file has been embedded in AP.exe. Actually there is a AP.exe.embed.manifest in <output dir>.
    I'm sure that I have embedded the manifest file in AP.exe.
    You know, my work is write a simple loader which can run simple exe file, so i need to handle manifest myself. So the key of my question is how to parse the manifest file like windows loader load exe My loader can locate the manifest in AP.exe .rsrc section, but how to use it
    Thanks a lot and best regards,
    yxxng

  • J.Suazo

    Dear Ayman,

    Pls help me , for this question has pushed me into great trouble in my work.

    Thanks,
    yxxng


  • Luke Chalkley

    yxxng,

    Inside msvcr80.dll we include a call to the fusion loader to find out the fusion context the DLL is loaded from (so that the DLL can fail to load if it isn't loaded via fusion.)  This was added to make sure that the DLL wasn't being loaded using some other incorrect mechanism that wouldn't be servicable (like copying it the same directory as the .exe running it.)

    See the function _check_manifest in crtlib.c in the CRT sources for details on how we do this check.

    My guess is _check_manifest is failing which in turn is causing the crt to return a failure code from the DLL_PROCESS_ATTACH which then leads to the load failure you are seeing.  There are a variety of clever tricks your loader could probably use to fool msvcrt80.dll into loading.  An obvious one would be to hook GetProcAddress and while running the CRT's entry point with DLL_PROCESS_ATTACH return null for a query of kernel32's module handle + the entry point named "FindActCtxSectionStringW".

     Of course if your loader is merely delegating DLL loading to LoadLibrary today and you have some good reason to still need your own PE loader, you might want to look into the activation context APIs and using those to get the CRT loaded - see http://msdn.microsoft.com/library/default.asp url=/library/en-us/sbscs/setup/actctx_str.asp


  • Matt MacDonald

    It seems that you have the manifest externally (through a .manifest file) Is that correct If that is the case, did you try embedding it using the MT.exe tool

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Tomys

    Yes.I am sure that the manifest file was in Ap.exe .rsrc section already.

    But how to parse the manifest I mean that i dont know how to use the manifest.

    How to make the LoadLibrary realize that my loader has already parsed the manifest

    And how to let my loader calls LoadLibrary("msvcr80.dll") successfully

    Thanks a lot.

    yxxng


  • daydreamsy2k

    Hi,

    Calling LoadLibrary() on CRT DLLs is not a supported scenario. Actually it was never supported. Also you cannot load assembly from WinSxS folder using LoadLibrary(). It sounds like you are talking about mirroring what OS Loader does in a way of loading SxS assemblies. It is not a simple task and there is a whole policy around order and checks that OS loader does before loading DLLs for Sxs assemblies. VC forum is not the right place to ask this question. You need to talk to Windows OS folks. You may try asking Platform SDK newsgroups or contact developer support team on support.microsoft.com.

    Thanks,

    Nikola



  • stiflersmom100

    Dear Ayman,

    Please give me some comments about how to solve the problem, cause I cant finish my work until this problem is done, and it has trapped me for a long time.Thank you very much.

    I wonder if i can talk to you on MSN, or you can leave comments here ,both will be Ok.

    MY MSN:yxxnginsky@msn.com

    Best regards

    Yxxng


  • Ton vd Pol

    I will point the lib folks to your thread since they might be able to help better than myself.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • My PE Loader cannot load EXE file which bulit with VS2005.