今天突然想到見過別人用vc寫的木馬 下載者之類大小都只有 幾K (沒用過pe壓縮程式)
我寫個hello world用 release + minimize size 編譯都有30++k
於是google尋求解答 搜尋了一些相關資訊 有效做個總結如下
#include <windows.h>
//自訂載入的庫
#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 只能先這樣了 最近時間要學習下相關的知識
1#include <windows.h>
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寫的會小很多
這些選項也沒有研究的很透 肯定還存在問題 這裡先留個文章 以後改進了弄明白了再來修改