-1

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 70 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 :

    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 70 imports and functions , How Can I do it ?

Dr.CSharp
  • 23
  • 1
  • 6
  • *Why* do you want to remove them? – Roger Lipscombe Mar 25 '19 at 15:56
  • 2
    Even if you have an empty `main` function, there's still some code to handle the stuff that's needed before `main` is called, and that cleans up after `main` returns. This is supplied by the compiler, and you shouldn't really build without it unless on smaller embedded systems (where you have your own startup code that then calls `main`). – Some programmer dude Mar 25 '19 at 15:57
  • As for your problem, what *is* your problem? Why do you need to "remove them"? Remember that a DLL is only loaded *once* and during run-time. – Some programmer dude Mar 25 '19 at 15:58
  • How are you constructing the project, are you making a windows binary, or are you making a command line exe ? It could make a big difference. – Owl Mar 25 '19 at 15:59
  • @RogerLipscombe I saw somebody did it and I'm interested how he did it. You know loving pe stuffs :D – Dr.CSharp Mar 25 '19 at 16:18
  • @Someprogrammerdude Thanks , No I didn't use even Main , it VC++ I disabled CRT to be able to do that but in PC++ i just compiled a complete empty cpp file [ file size = 0 ] - And I need them becuz I saw somebody did it , I want to know how .... – Dr.CSharp Mar 25 '19 at 16:20
  • @Owl Nah , it's a dll , with no include and no code ... For example I just need VirtualProtect in my dll and nothing more , No need to loadlibrary but it's in my imports... – Dr.CSharp Mar 25 '19 at 16:22
  • "I'd like to learn more about what these bits do" is a different question than "how do I get rid of these bits?"... – Roger Lipscombe Mar 25 '19 at 16:25
  • @RogerLipscombe What you suggest ? Hackforums or CheatUnknown ? I think here people have more low-level knowledge ! – Dr.CSharp Mar 25 '19 at 16:36
  • 1
    I don't believe there's 4 response to **"WHY YOU WANT TO DO THAT"** instead of actually answering to question .... – Dr.CSharp Mar 25 '19 at 17:51
  • Because **you don't want to do that**. The compiler put them there for a reason. – Roger Lipscombe Mar 25 '19 at 21:00
  • 1
    @RogerLipscombe I just did and it works fine ... useless community ! – Dr.CSharp Mar 25 '19 at 23:16
  • It's a valid question "why is the bathroom sink compiled into my hello world". I see nothing wrong with that as a question. – Owl Mar 26 '19 at 16:14

1 Answers1

0

Thanks to TimoVJL | Here's the solution :

#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;
} 
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
Dr.CSharp
  • 23
  • 1
  • 6