減小vc編譯檔案體積

來源:互聯網
上載者:User

今天突然想到見過別人用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寫的會小很多

這些選項也沒有研究的很透 肯定還存在問題 這裡先留個文章  以後改進了弄明白了再來修改

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.