This page hosts a formal specification of .agg file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
digraph {
rankdir=LR;
node [shape=plaintext];
subgraph cluster__heroes_of_might_and_magic_agg {
label="HeroesOfMightAndMagicAgg";
graph[style=dotted];
heroes_of_might_and_magic_agg__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="num_files_pos">0</TD><TD PORT="num_files_size">2</TD><TD>u2le</TD><TD PORT="num_files_type">num_files</TD></TR>
<TR><TD PORT="entries_pos">2</TD><TD PORT="entries_size">14</TD><TD>Entry</TD><TD PORT="entries_type">entries</TD></TR>
<TR><TD COLSPAN="4" PORT="entries__repeat">repeat num_files times</TD></TR>
</TABLE>>];
heroes_of_might_and_magic_agg__inst__filenames [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="filenames_pos">(entries.last.offset + entries.last.size)</TD><TD PORT="filenames_size">15</TD><TD>Filename</TD><TD PORT="filenames_type">filenames</TD></TR>
<TR><TD COLSPAN="4" PORT="filenames__repeat">repeat num_files times</TD></TR>
</TABLE>>];
subgraph cluster__entry {
label="HeroesOfMightAndMagicAgg::Entry";
graph[style=dotted];
entry__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="hash_pos">0</TD><TD PORT="hash_size">2</TD><TD>u2le</TD><TD PORT="hash_type">hash</TD></TR>
<TR><TD PORT="offset_pos">2</TD><TD PORT="offset_size">4</TD><TD>u4le</TD><TD PORT="offset_type">offset</TD></TR>
<TR><TD PORT="size_pos">6</TD><TD PORT="size_size">4</TD><TD>u4le</TD><TD PORT="size_type">size</TD></TR>
<TR><TD PORT="size2_pos">10</TD><TD PORT="size2_size">4</TD><TD>u4le</TD><TD PORT="size2_type">size2</TD></TR>
</TABLE>>];
entry__inst__body [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="body_pos">offset</TD><TD PORT="body_size">size</TD><TD></TD><TD PORT="body_type">body</TD></TR>
</TABLE>>];
}
subgraph cluster__filename {
label="HeroesOfMightAndMagicAgg::Filename";
graph[style=dotted];
filename__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="str_pos">0</TD><TD PORT="str_size">...</TD><TD>str(ASCII)</TD><TD PORT="str_type">str</TD></TR>
</TABLE>>];
}
}
heroes_of_might_and_magic_agg__seq:entries_type -> entry__seq [style=bold];
heroes_of_might_and_magic_agg__seq:num_files_type -> heroes_of_might_and_magic_agg__seq:entries__repeat [color="#404040"];
entry__seq:offset_type -> heroes_of_might_and_magic_agg__inst__filenames:filenames_pos [color="#404040"];
entry__seq:size_type -> heroes_of_might_and_magic_agg__inst__filenames:filenames_pos [color="#404040"];
heroes_of_might_and_magic_agg__inst__filenames:filenames_type -> filename__seq [style=bold];
heroes_of_might_and_magic_agg__seq:num_files_type -> heroes_of_might_and_magic_agg__inst__filenames:filenames__repeat [color="#404040"];
entry__seq:offset_type -> entry__inst__body:body_pos [color="#404040"];
entry__seq:size_type -> entry__inst__body:body_size [color="#404040"];
}