-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello.asm
59 lines (48 loc) · 1.11 KB
/
hello.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
BITS 32
ORG 0
WriteFile equ 0x7c810d87 ; Varies depending on environments
ImageBase equ 0x00400000
filealign equ 4
sectalign equ 4 ; must be 4 because of e_lfanew
%define round(n, r) (((n+(r-1))/r)*r)
dw "MZ"
dw 0
pe_hdr dd "PE" ; Signature
dw 0x014C ; CPU: i386
dw 1 ; Number of Sections
hello db "Hello,world"
hello_e db 0
dw 4 ; offset between sections and opthdr
dw 0x0103 ; Characteristics: RELOCS_STRIPPED|EXECUTABLE|32BI
opthdr:
dw 0x010B ; Magic
code1:
mov edx, hello + ImageBase
push eax
push ebx
jmp short code2
db 0 ; not used
dd codesize
dd code1 ;
dd codesize
dd code1 ; EntryPoint
dd ImageBase ; ImageBase Address
sectbl: dd 4 ; PE hdr / Section Alignment
dd 4 ; File Alignment
code2:
push byte hello_e - hello
push edx
push byte 7 ; stdout handle
jmp short code3
db 0 ; not used
dw 4 ; Subsys Major Ver
code3:
call WriteFile - ImageBase
ret
dd round(hdrsize, sectalign)+round(codesize,sectalign) ; SizeOfImage
dd round(hdrsize, filealign) ; SizeOfHeaders
dd 0
db 3 ; Subsystem:console
codesize equ $ - code1
hdrsize equ $ - $$
filesize equ $ - $$