- Mastering Assembly Programming
- Alexey Lyashko
- 394字
- 2021-08-20 10:23:33
The Windows Assembly template (32-bit)
A Windows executable consists of several sections (the structure of a PE executable/object file will be covered in more detail in Chapter 9, Operating System Interface); usually, one section for code, one for data, and one for import data (this contains information on external procedures, which are imported from dynamic link libraries). Dynamic-link libraries (DLL) also have an export section, which contains information on procedures/objects publicly available in the DLL itself. In our template, we simply define the sections and let the assembler do the rest of the work (write headers and so on).
Now, let's take a look at the template itself. See further explanation of PE specifics in the comments:
; File: srctemplate_win.asm
; First of all, we tell the compiler which type of executable we want it
; to be. In our case it is a 32-bit PE executable.
format PE GUI
; Tell the compiler where we want our program to start - define the entry
; point. We want it to be at the place labeled with '_start'.
entry _start
; The following line includes a set of macros, shipped with FASM, which
; are essential for the Windows program. We can, of course, implement all
; we need ourselves, and we will do that in chapter 9.
include 'win32a.inc'
; PE file consists of at least one section.
; In this template we only need 3:
; 1. '.text' - section that contains executable code
; 2. '.data' - section that contains data
; 3. '.idata' - section that contains import information
;
; '.text' section: contains code, is readable, is executable
section '.text' code readable executable
_start:
;
; Put your code here
;
; We have to terminate the process properly
; Put return code on stack
push 0
; Call ExitProcess Windows API procedure
call [exitProcess]
; '.data' section: contains data, is readable, may be writeable
section '.data' data readable writeable
;
; Put your data here
;
; '.idata' section: contains import information, is readable, is writeable
section '.idata' import data readable writeable
; 'library' macro from 'win32a.inc' creates proper entry for importing
; procedures from a dynamic link library. For now it is only 'kernel32.dll',
; library kernel, 'kernel32.dll'
; 'import' macro creates the actual entries for procedures we want to import
; from a dynamic link library
import kernel,
exitProcess, 'ExitProcess'
推薦閱讀
- Google Flutter Mobile Development Quick Start Guide
- 程序員面試白皮書
- PHP 7底層設計與源碼實現
- Learning Informatica PowerCenter 10.x(Second Edition)
- 軟件架構:Python語言實現
- Android系統級深入開發
- Statistical Application Development with R and Python(Second Edition)
- C++反匯編與逆向分析技術揭秘(第2版)
- Vue.js應用測試
- TypeScript圖形渲染實戰:2D架構設計與實現
- Python繪圖指南:分形與數據可視化(全彩)
- 信息學奧林匹克競賽初賽精講精練
- Java EE互聯網輕量級框架整合開發:SSM+Redis+Spring微服務(上下冊)
- Elasticsearch實戰(第2版)
- A/B 測試:創新始于試驗