CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Question PE import table: DLL(name), Functions (name & address)

    Hello everyone.

    I want to make EXE-file to process its own Import Table printing to console DLL names and Functions (including names and addresses).

    Mapping file is not an option (CreateFileMapping and MapViewOfFile) as file started is already locating in memory. Also alignment should be according to RVA, not to raw offset.

    As I understand ImageBase can be received by GetModuleHandleA(0) function. But I don't know how to proceed further.

    Starting with:

    HANDLE f = CreateFileA("PEview.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    HMODULE fMap = GetModuleHandleA(0);
    IMAGE_DOS_HEADER* mz_head = (IMAGE_DOS_HEADER*)fMap;
    if(mz_head->e_magic != IMAGE_DOS_SIGNATURE) {cout << "Unable to locate MS_DOS_HEADER"; _getch(); exit(0);};
    IMAGE_NT_HEADERS* nt_head = (IMAGE_NT_HEADERS*)(fMap + mz_head->e_lfanew);
    if(nt_head->Signature != IMAGE_NT_SIGNATURE) {cout << "Unable to locate FILE_NT_HEADER"; _getch(); exit(0);};
    and getting an error: Unable to locate FILE_NT_HEADER

    Please help.

  2. #2
    Join Date
    Apr 2010
    Posts
    172

    Re: PE import table: DLL(name), Functions (name & address)

    To get dll functions names and base address to be processed through you exe why not use

    Code:
    HMODULE h;
    int funcaddress = 0;
    h = GetModule("blah.dll");
    
    funcaddress = GetProcAddress(h,"function");
    
    // format funcaddress to hex....... then print it out to screen

  3. #3
    Join Date
    Apr 2008
    Posts
    6

    Re: PE import table: DLL(name), Functions (name & address)

    You can walk the modules list in your process to list the modules. You can then ReadProcessMemory or memcpy and use the ImageNtHeader and other functions to get the information you want.

    For more info about module walking: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured