forked from synalysis/Grammars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf32.grammar
164 lines (154 loc) · 8.84 KB
/
elf32.grammar
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.15">
<grammar name="ELF grammar" start="id:72" author="Matt" fileextension="elf">
<description>Grammar for ELF files</description>
<scripts>
<script name="SamplePython" type="Grammar" id="101">
<source language="Python">def init():
print "init"
def processGrammar(grammar):
print "grammar"
currentGrammar = grammar
elfFile = currentGrammar:getStructureByName("ELF_file”)
shHdr = elfFile:getStructureByName("Elf32_Shdr”)
print elfFile
print shHdr
def terminate():
print "terminate"
</source>
</script>
<script name="SampleLua" type="Grammar" id="101">
<source language="Lua">function init()
print "hello init"
end
function processGrammar(grammar)
print "hello grammar"
print (grammar)
elfFile = grammar:getStructureByName("ELF_file")
print (elfFile)
shHdrElement = elfFile:getElementByName("Elf32_Shdr")
print (shHdrElement)
shHdr = shHdrElement:getStructure()
print (shHdr:getName())
end
function terminate()
print "end of processing"
end
</source>
</script>
</scripts>
<structure name="ELF_file" id="72" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structure name="ELF32_Ehdr" id="73">
<structure name="e_ident" id="74">
<number name="EI_MAG0" mustmatch="yes" id="75" strokecolor="FF2600" type="integer" length="1" endian="little" display="hex" valueexpression="0x7f"/>
<string name="ELF_MAG123" mustmatch="yes" id="76" type="fixed-length" length="3">
<fixedvalues>
<fixedvalue name="ELF_MAGIC123" value="ELF"/>
</fixedvalues>
</string>
<number name="EI_CLASS" mustmatch="yes" id="77" type="integer" length="1" minval="0" maxval="2">
<fixedvalues>
<fixedvalue name="ELFCLASS32" value="1"/>
<fixedvalue name="ELFCLASSNONE" value="0"/>
<fixedvalue name="ELFCLASS64" value="2"/>
</fixedvalues>
</number>
<number name="EI_DATA" mustmatch="yes" id="78" type="integer" length="1" minval="0" maxval="2">
<fixedvalues>
<fixedvalue name="ELFDATANONE" value="0"/>
<fixedvalue name="ELFDATA2LSB" value="1"/>
<fixedvalue name="ELFDATA2MSB" value="2"/>
</fixedvalues>
</number>
<number name="EI_VERSION" id="79" type="integer" length="1" minval="0" maxval="1">
<fixedvalues>
<fixedvalue name="EV_NONE" value="0"/>
<fixedvalue name="EV_CURRENT" value="1"/>
</fixedvalues>
</number>
<binary name="EI_PAD" id="80" length="9">
<fixedvalues>
<fixedvalue name="EI_PAD" value="00"/>
</fixedvalues>
</binary>
</structure>
<number name="e_type" mustmatch="yes" id="82" type="integer" length="2" endian="little" display="hex">
<fixedvalues>
<fixedvalue name="ET_NONE" value="0x0"/>
<fixedvalue name="ET_REL" value="0x1"/>
<fixedvalue name="ET_EXEC" value="0x2"/>
<fixedvalue name="ET_DYN" value="0x3"/>
<fixedvalue name="ET_CORE" value="0x4"/>
<fixedvalue name="ET_LOPROC" value="0xFF00"/>
<fixedvalue name="ET_HIPROC" value="0xFFFF"/>
</fixedvalues>
</number>
<number name="e_machine" mustmatch="yes" id="83" type="integer" length="2" endian="little">
<fixedvalues>
<fixedvalue name="EM_NONE" value="0"/>
<fixedvalue name="EM_M32" value="1"/>
<fixedvalue name="EM_SPARC" value="2"/>
<fixedvalue name="EM_386" value="3"/>
<fixedvalue name="EM_68K" value="4"/>
<fixedvalue name="EM_88K" value="5"/>
<fixedvalue name="EM_860" value="7"/>
<fixedvalue name="EM_MIPS" value="8"/>
</fixedvalues>
</number>
<number name="e_version" mustmatch="yes" id="84" type="integer" length="4" endian="little">
<fixedvalues>
<fixedvalue name="EV_NONE" value="0"/>
<fixedvalue name="EV_CURRENT" value="1"/>
</fixedvalues>
</number>
<number name="e_entry" id="85" type="integer" length="4" endian="little" display="hex"/>
<number name="e_phoff" id="86" type="integer" length="4" endian="little" display="hex">
<description>Program Header Offset - offset into this file</description>
</number>
<number name="e_shoff" id="87" type="integer" length="4" endian="little" display="hex">
<description>Section Header Offset - offset into this file</description>
</number>
<number name="e_flags" id="88" type="integer" length="4" endian="little"/>
<number name="e_hsize" id="89" type="integer" length="2" endian="little">
<description>E Header Size</description>
</number>
<number name="e_phentsize" id="90" type="integer" length="2" endian="little">
<description>This member holds the size in bytes of one entry in the file’s program header table; all entries are the same size.</description>
</number>
<number name="e_phnum" id="91" type="integer" length="2" endian="little">
<description>This member holds the number of entries in the program header table. Thus the pro- duct of e_phentsize and e_phnum gives the table’s size in bytes. If a file has no pro- gram header table, e_phnum holds the value zero.</description>
</number>
<number name="e_shentsize" id="92" type="integer" length="2" endian="little">
<description>This member holds a section header’s size in bytes. A section header is one entry in the section header table; all entries are the same size.</description>
</number>
<number name="e_shnum" id="93" type="integer" length="2" endian="little">
<description>This member holds the number of entries in the section header table. Thus the product of e_shentsize and e_shnum gives the section header table’s size in bytes. If a file has no section header table, e_shnum holds the value zero.</description>
</number>
<number name="e_shstrndx" id="94" type="integer" length="2" endian="little">
<description>This member holds the section header table index of the entry associated with the sec- tion name string table. If the file has no section name string table, this member holds the value SHN_UNDEF. See ‘‘Sections’’ and ‘‘String Table’’ below for more information.</description>
</number>
</structure>
<scriptelement name="find_shdr" id="96">
<script name="unnamed" type="Generic">
<source language="Lua">logSrc = currentMapper:getCurrentLogSrc()
currentResults = currentMapper:getCurrentResults()
currentOffset = currentMapper:getCurrentOffset()
shoffsStr = currentResults:getResultByName("e_shoff")
shoffVal = shoffsStr:getValue():getUnsigned()
shnumStr = currentResults:getResultByName("e_shnum")
shnumVal = shnumStr:getValue():getUnsigned()
currentGrammar = currentMapper:getCurrentGrammar()
shHdr = currentGrammar:getStructureByName("sh_name")
currentResults:addStructureStartAtPosition(
shHdr, shoffVal, 0, shHdr:getName())
</source>
</script>
</scriptelement>
<structure name="Elf32_Shdr" id="97" endian="little">
<number name="sh_name" id="98" type="integer" length="4" display="hex">
<description>This member specifies the name of the section. Its value is an index into the section header string table section [see ‘‘String Table’’ below], giving the location of a null- terminated string.</description>
</number>
</structure>
</structure>
</grammar>
</ufwb>