C + + methods to get the current process IAT _c language

Source: Internet
Author: User

This article describes the C + + acquisition of the current process Iat method, share for everyone to reference.

The implementation methods are as follows:

Copy Code code as follows:
#include <windows.h>
#include <stdio.h>

int main (int argc, char* argv[])
{
Hmodule hmodule =:: Getmodulehandlea (NULL);
image_dos_header* Pdosheader = (image_dos_header*) hmodule;
image_optional_header* Popntheader = (image_optional_header*) ((byte*) hmodule + pdosheader->e_lfanew + 24); Add 24 here.
image_import_descriptor* Pimportdesc = (image_import_descriptor*) ((byte*) hmodule + popntheader->datadirectory[ Image_directory_entry_import]. virtualaddress);

while (Pimportdesc->firstthunk)
{
char* pszdllname = (char*) ((byte*) hmodule + pimportdesc->name);
printf ("Module name:%s\n", pszdllname);

DWORD n = 0;
A image_thunk_data is an import function
image_thunk_data* Pthunk = (image_thunk_data*) ((byte*) hmodule + pimportdesc->originalfirstthunk);
while (PTHUNK->U1. Function)
{
Get function name
char* pszfuncname = (char*) (byte*) hmodule+pthunk->u1. ADDRESSOFDATA+2); The function name is preceded by two.
printf ("Function name:%-25s,", pszfuncname);
Get function Address
Pdword lpaddr = (dword*) ((byte*) hmodule + pimportdesc->firstthunk) + N; From the address of the first function, after each + 4 bytes
printf ("addrss:%x\n", lpaddr);
n++; Add one DWORD at a time
pthunk++;
}
printf ("\ n");
pimportdesc++;
}
return 0;
}

I hope this article will help you with the C + + program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.