NO

Author Topic: Remove Unused Imports from Import Table  (Read 4905 times)

drCsharp

  • Guest
Remove Unused Imports from Import Table
« on: March 25, 2019, 09:26:05 PM »
Hi Everybody

I'm working with Visual Studio 2012 & 2017 with C++ 11 and Pelles C 9.0 with C++ 11...

When I build a empty program and DLL but they contain lots of unused imports in pe file!

VC++ has 26 imports of KERNEL32 and Pelles has 55 imports of KERNEL32 My project is totally empty!

I need to remove them from linker and compiled file.

I have an DLL is compiled with Pelles C and it only has 4 import that it really use :

Code: [Select]
KERNEL32.dll
          VirtualProtect  ord:0 rva2iat: 000012A0
          GetModuleHandleA  ord:0 rva2iat: 000012A8
          Sleep  ord:0 rva2iat: 000012B0
          CreateThread  ord:0 rva2iat: 000012B8

I want to do the same , I don't need any of those 55 imports and functions , How Can I do it ?

< Referenced File developed in Pelles C Attached >

Regards,
Mike
 
« Last Edit: March 25, 2019, 09:28:40 PM by drCsharp »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Remove Unused Imports from Import Table
« Reply #1 on: March 25, 2019, 09:56:30 PM »
Examine this:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifdef _WIN64
#pragma comment(linker, "/ENTRY:DllMainCRTStartup")
#else
#pragma comment(linker, "/ENTRY:_DllMainCRTStartup@12")
#endif
BOOL WINAPI DllMainCRTStartup(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH) g_hmod = hDLL;
return TRUE;
}
May the source be with you

drCsharp

  • Guest
Re: Remove Unused Imports from Import Table
« Reply #2 on: March 25, 2019, 10:46:31 PM »
Examine this...

TimoVJL Wow ! thanks a lot buddy! I was searching for this for 2 days you saved me!
I'm getting really interested in Pelles C !

Where can I find and learn stuffs like this question ? linker and imports, section editing and ...
Thank you Again !