-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPE_SectionHeaderByName.asm
85 lines (68 loc) · 1.8 KB
/
PE_SectionHeaderByName.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;==============================================================================
;
; PE Library
;
; Copyright (c) 2019 by fearless
;
; http://github.com/mrfearless
;
;==============================================================================
.686
.MMX
.XMM
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
includelib user32.lib
includelib kernel32.lib
include PE.inc
.CODE
PE_ALIGN
;------------------------------------------------------------------------------
; PE_SectionHeaderByName - Get section specified by lpszSectionName
; Returns: pointer to section IMAGE_SECTION_HEADER or NULL
;------------------------------------------------------------------------------
PE_SectionHeaderByName PROC USES EBX hPE:DWORD, lpszSectionName:DWORD
LOCAL pHeaderSections:DWORD
LOCAL pCurrentSection:DWORD
LOCAL lpszName:DWORD
LOCAL nTotalSections:DWORD
LOCAL nSection:DWORD
.IF hPE == NULL
xor eax, eax
ret
.ENDIF
.IF lpszSectionName == NULL
xor eax, eax
ret
.ENDIF
Invoke PE_HeaderSections, hPE
.IF eax == 0
ret
.ENDIF
mov pHeaderSections, eax
mov pCurrentSection, eax
Invoke PE_SectionHeaderCount, hPE
mov nTotalSections, eax
mov ebx, pCurrentSection
mov nSection, 0
mov eax, 0
.WHILE eax < nTotalSections
lea eax, [ebx].IMAGE_SECTION_HEADER.Name1
mov lpszName, eax
Invoke lstrcmp, lpszName, lpszSectionName
.IF eax == 0 ; match
mov eax, pCurrentSection
ret
.ENDIF
add pCurrentSection, SIZEOF IMAGE_SECTION_HEADER
mov ebx, pCurrentSection
inc nSection
mov eax, nSection
.ENDW
xor eax, eax
ret
PE_SectionHeaderByName ENDP
PE_LIBEND