-
Notifications
You must be signed in to change notification settings - Fork 14
/
bar.grammar
68 lines (59 loc) · 3.7 KB
/
bar.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
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.2">
<grammar name="Age of Mythology BAR" start="id:3627" author="Kelvin Chung" fileextension="bar">
<description>Grammar for BAR files used in Age of Mythology</description>
<structure name="Age of Mythology BAR file" id="3627" encoding="ISO_8859-1:1987" endian="little" signed="no">
<structref name="BAR Header" id="3629" structure="id:3628"/>
</structure>
<structure name="BAR Header" id="3628" encoding="ISO_8859-1:1987" endian="little" signed="no">
<binary name="Unknown" id="3631" length="12"/>
<number name="Number of files" id="3632" fillcolor="FCFC3E" type="integer" length="4"/>
<number name="Directory Entry length" id="3633" fillcolor="FE9227" type="integer" length="4"/>
<number name="Directory" id="3634" fillcolor="FF30FA" type="integer" length="4" display="hex"/>
<scriptelement name="Render Directory" id="3635">
<script language="Lua">offsetField = "Directory"
sizeField = "Number of files"
entryType = "Directory Offset Entry"
results = currentMapper:getCurrentResults()
currentGrammar = currentMapper:getCurrentGrammar()
logSrc = currentMapper:getCurrentLogSrc()
sizeResult = results:getResultByName(sizeField)
offsetResult = results:getResultByName(offsetField)
size = sizeResult:getValue():getUnsignedNumber()
firstOffset = offsetResult:getValue():getUnsignedNumber()
directoryStart = firstOffset + (4 * size)
structure = currentGrammar:getStructureByName(entryType)
entryStructure = currentGrammar:getStructureByName("Directory Entry")
-- TODO: add a virtual structure wrapper?
logSrc:logMessage(_VERSION, 111, synalysis.SEVERITY_INFO, "Begin Rendering Entries")
offset = firstOffset
for i = 1,size do
currentMapper:mapStructureAtPosition(structure, offset, 4)
offset = offset + 4
-- get offset of actual entry
local lastResult = results:getLastResult()
local localOffset = lastResult:getValue():getUnsignedNumber()
logSrc:logMessage(_VERSION, 111, synalysis.SEVERITY_INFO, string.format("localOffset: 0x%X", localOffset))
local directoryEntryStart = directoryStart + localOffset
logSrc:logMessage(_VERSION, 111, synalysis.SEVERITY_INFO, string.format("Entry located at 0x%X", directoryEntryStart))
-- structure is of indeterminate size, so we shoehorn an arbitrary large size
currentMapper:mapStructureAtPosition(entryStructure, directoryEntryStart, currentMapper:getCurrentOffset() + currentMapper:getCurrentRemainingSize() - directoryEntryStart)
end
logSrc:logMessage(_VERSION, 111, synalysis.SEVERITY_INFO, "Finish Rendering Entries")
return 0</script>
</scriptelement>
</structure>
<structure name="File" id="3637" encoding="ISO_8859-1:1987" endian="little" signed="no">
<binary name="File Data" id="3638" length="0"/>
</structure>
<structure name="Directory Entry" id="3640" encoding="ISO_8859-1:1987" endian="little" signed="no">
<offset name="File" id="3641" fillcolor="FF30FA" length="4" references="id:3637" referenced-size="id:3642" follownullreference="yes"/>
<number name="File Length" id="3642" fillcolor="FE9227" type="integer" length="4"/>
<binary name="Unknown" id="3643" length="12"/>
<string name="Filename" id="3644" fillcolor="02FDFD" type="zero-terminated"/>
</structure>
<structure name="Directory Offset Entry" id="3646" encoding="ISO_8859-1:1987" endian="little" signed="no">
<number name="Directory Entry Offset" id="3647" fillcolor="FF30FA" type="integer" length="4" display="hex"/>
</structure>
</grammar>
</ufwb>