减小vc编译文件体积
今天突然想到见过别人用vc写的木马 下载者之类大小都只有 几K (没用过pe压缩程序)
我写个hello world用 release + minimize size 编译都有30++k
于是google寻求解答 搜索了一些相关信息 有效的做个总结如下
#include
//自定义加载的库
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"msvcrt.lib")
//自定义函数入口
#pragma comment(linker, "/ENTRY:EntryPoint")
//自定义对齐方式
#pragma comment (linker, "/ALIGN:512")
#pragma comment(linker, "/FILEALIGN:512")
// 优化选项
#pragma comment(linker, "/opt:nowin98")
#pragma comment(linker, "/opt:ref")
#pragma comment (linker, "/OPT:ICF")
// 合并区段
#pragma comment(linker, "/MERGE:.rdata=.data")
#pragma comment(linker, "/MERGE:.text=.data")
#pragma comment(linker, "/MERGE:.reloc=.data")
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow ) ;
void EntryPoint()
{
ExitProcess(WinMain(GetModuleHandle(NULL), NULL,
GetCommandLine(), SW_SHOWNORMAL));
}
/////////////////////////////////////////////////////////////////////////////////////////////////
写了下段代码编译后1K
用peid查看不是vc6.0 而是First Publisher Graphics format *
也不了解pe 只能先这样了 最近时间要学习下相关的知识
2
3#pragma comment(lib,"kernel32.lib")
4#pragma comment(lib,"shell32.lib")
5#pragma comment(lib,"msvcrt.lib")
6
7#pragma comment(linker, "/ENTRY:EntryPoint")
8
9#pragma comment (linker, "/ALIGN:512")
10#pragma comment(linker, "/FILEALIGN:512")
11
12#pragma comment(linker, "/opt:nowin98")
13#pragma comment(linker, "/opt:ref")
14#pragma comment (linker, "/OPT:ICF")
15
16#pragma comment(linker, "/MERGE:.rdata=.data")
17#pragma comment(linker, "/MERGE:.text=.data")
18#pragma comment(linker, "/MERGE:.reloc=.data")
19
20
21
22int WINAPI WinMain( HINSTANCE hInstance,
23 HINSTANCE hPrevInstance,
24 LPSTR lpCmdLine,
25 int iCmdShow ) ;
26
27void EntryPoint()
28{
29 ExitProcess(WinMain(GetModuleHandle(NULL), NULL,
30 GetCommandLine(), SW_SHOWNORMAL));
31}
32int WINAPI WinMain( HINSTANCE hInstance,
33 HINSTANCE hPrevInstance,
34 LPSTR lpCmdLine,
35 int iShowCmd )
36{
37 MessageBox(NULL, TEXT("hello!"), TEXT("hi"), 0) ;
38 return 0 ;
39}
遇到的一些问题 就是编译可以通过但有2个警告还需要解决下
对pe的结构还不是很了解 用uedit32看了下 还有很多00 不知道是不是还有压缩的空间
实现同样功能用masm32写的会小很多