3 #include "Script_internal.h"
4 #include "endianness.h"
9 #define COMMENT(F, FMT, ...) fprintf(F, "; " FMT, ##__VA_ARGS__)
11 static int dump_sections(AF
* a
, FILE *f
, size_t start
, size_t count
) {
14 fprintf(f
, ".sections\n");
17 for(; i
< count
; i
++) {
18 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
19 int off
= AF_read_int(a
);
20 fprintf(f
, "\"%s\" = %d\n", buf
, off
);
27 static int dump_strings(AF
* a
, FILE *f
, size_t start
, size_t len
) {
30 fprintf(f
, ".%s\n\"", "strings");
33 size_t togo
= len
> sizeof(buf
) ? sizeof(buf
) : len
;
34 if(togo
!= (size_t) AF_read(a
, buf
, togo
))
37 for(i
= 0; i
< togo
; i
++) {
41 if(len
) fprintf(f
, "\"");
43 fprintf(f
, "%c", buf
[i
]);
49 static void free_fixup_data(struct fixup_data
*ret
) {
51 for(i
= 0; i
<= FIXUP_MAX
; i
++) {
52 free(ret
->codeindex_per
[i
]);
58 /* fixup_data needs to be zeroed */
59 static int get_fixups(AF
* a
, size_t start
, size_t count
, struct fixup_data
*ret
) {
61 if(!(ret
->types
= malloc(count
))) goto err
;
62 if(!(ret
->codeindex
= malloc(count
* sizeof(unsigned)))) goto err
;
66 if(count
!= (size_t) AF_read(a
, ret
->types
, count
)) goto err
;
67 for(i
= 0; i
< count
; i
++) {
68 assert(ret
->types
[i
]>=0 && ret
->types
[i
]<=FIXUP_MAX
);
69 ret
->count
[ret
->types
[i
]]++;
70 ret
->codeindex
[i
] = AF_read_uint(a
);
72 for(i
= 0; i
<= FIXUP_MAX
; i
++) {
73 ret
->codeindex_per
[i
] = malloc(ret
->count
[i
] * sizeof(unsigned));
74 if(!ret
->codeindex_per
[i
]) goto err
;
75 ret
->count
[i
] = 0; /* reset to 0 to use as index i.t. next loop */
78 for(i
= 0; i
< count
; i
++) {
79 ret
->codeindex_per
[ret
->types
[i
]][ret
->count
[ret
->types
[i
]]++] = ret
->codeindex
[i
];
88 static int dump_fixups(FILE *f
, size_t count
, struct fixup_data
*fxd
) {
89 static const char* typenames
[] = {
90 [FIXUP_GLOBALDATA
] = "FIXUP_GLOBALDATA",
91 [FIXUP_FUNCTION
] = "FIXUP_FUNCTION",
92 [FIXUP_STRING
] = "FIXUP_STRING",
93 [FIXUP_IMPORT
] = "FIXUP_IMPORT",
94 [FIXUP_DATADATA
] = "FIXUP_DATADATA",
95 [FIXUP_STACK
] = "FIXUP_STACK",
98 fprintf(f
, ".%ss\n", "fixup");
100 for(i
= 0; i
< count
; i
++) {
101 fprintf(f
, "%s: %.12u\n", typenames
[(int)fxd
->types
[i
]], fxd
->codeindex
[i
]);
107 static int dump_import_export(AF
* a
, FILE *f
, size_t start
, size_t count
, int import
) {
108 static const char* secnames
[2] = { "export", "import" };
109 const char* secname
= secnames
[import
];
111 char buf
[256]; /* arbitrarily chosen */
113 AF_set_pos(a
, start
);
114 fprintf(f
, ".%ss\n", secname
);
115 for(i
= 0; i
< count
; i
++) {
116 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
117 fprintf(f
, "%.12zu\"%s\"\n", i
, buf
);
119 unsigned int addr
= AF_read_uint(a
);
120 fprintf(f
, "%d:%.12u\n", addr
>> 24, addr
& 0x00FFFFFF);
126 static struct function_export
* get_exports(AF
* a
, size_t start
, size_t count
) {
128 struct function_export
* fl
= malloc(count
* sizeof(struct function_export
));
129 AF_set_pos(a
, start
);
130 char buf
[4096]; size_t i
;
131 for(i
= 0; i
< count
; i
++) {
132 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
133 fl
[i
].fn
= strdup(buf
);
134 unsigned int addr
= AF_read_uint(a
);
135 fl
[i
].type
= addr
>> 24;
136 fl
[i
].instr
= (addr
& 0x00FFFFFF);
141 static struct importlist
get_imports(AF
* a
, size_t start
, size_t count
) {
142 struct importlist ret
= {0};
143 if(!count
) return ret
;
144 ret
.names
= malloc(count
* sizeof(char*));
145 if(!ret
.names
) return ret
;
146 AF_set_pos(a
, start
);
147 char buf
[4096]; size_t i
;
148 for(i
= 0; i
< count
; i
++) {
149 if(!AF_read_string(a
, buf
, sizeof(buf
))) {
151 return (struct importlist
) {0};
153 ret
.names
[i
] = strdup(buf
);
163 static int sort_comp(const void* xp
, const void *yp
) {
164 const unsigned *x
= xp
, *y
= yp
;
165 if(*x
== *y
) return 0;
166 else if(*x
> *y
) return 1;
171 static struct labels
get_labels(unsigned *code
, size_t count
) {
172 struct labels ret
= {0, 0};
173 if(!count
) return ret
;
178 while(insno
< count
) {
179 if(ret
.count
+ 1 > capa
) {
180 capa
= capa
? capa
* 2 : 16;
181 if(!(p
= realloc(ret
.insno
, capa
* sizeof(unsigned*)))) {
182 if(ret
.insno
) free(ret
.insno
);
186 } else ret
.insno
= p
;
188 insn
= code
[insno
] & 0x00ffffff;
191 assert(insn
< SCMD_MAX
);
193 case SCMD_JZ
: case SCMD_JMP
: case SCMD_JNZ
:
199 for(; i
< opcodes
[insn
].argcount
; i
++) {
200 int val
= code
[insno
];
203 if((int) insno
+ val
< 0 || insno
+ val
>= count
|| code
[insno
+ val
] > SCMD_MAX
) {
204 dprintf(2, "error: label referenced from jump at %zu is out of bounds\n"
205 "or points to non-instruction start code.\n", insno
);
208 ret
.insno
[ret
.count
] = insno
+ val
;
213 qsort(ret
.insno
, ret
.count
, sizeof(unsigned), sort_comp
);
217 static struct strings
get_strings(AF
* a
, size_t start
, size_t size
) {
218 struct strings ret
= {0,0,0};
219 if(!size
) return ret
;
220 if(!(ret
.data
= malloc(size
))) return ret
;
221 AF_set_pos(a
, start
);
222 if(size
!= (size_t) AF_read(a
, ret
.data
, size
)) {
228 size_t i
, strcnt
= 0;
229 for(i
= 0; i
< size
; i
++) {
230 if(!ret
.data
[i
]) strcnt
++;
232 if(!(ret
.strings
= malloc(strcnt
* sizeof(char*)))) goto free1
;
237 for(i
= 0; i
< size
; i
++) {
239 ret
.strings
[strcnt
] = p
;
250 static char* get_varname(struct function_export
* exp
, size_t expcount
, unsigned globaloffset
) {
252 for(; i
< expcount
; i
++)
253 if(exp
[i
].type
== EXPORT_DATA
&& exp
[i
].instr
== globaloffset
)
258 unsigned *get_code(AF
*a
, size_t start
, size_t count
) {
259 unsigned *ret
= malloc(count
* sizeof(unsigned));
261 AF_set_pos(a
, start
);
263 for(i
=0; i
<count
; i
++)
264 ret
[i
] = AF_read_uint(a
);
268 static enum varsize
get_varsize_from_instr(unsigned* code
, size_t codecount
, size_t index
) {
269 assert(index
< codecount
);
270 switch(code
[index
]) {
271 case SCMD_MEMREADB
: case SCMD_MEMWRITEB
:
273 case SCMD_MEMREADW
: case SCMD_MEMWRITEW
:
275 case SCMD_MEMWRITEPTR
:
276 case SCMD_MEMREADPTR
:
277 case SCMD_MEMZEROPTR
:
278 case SCMD_MEMINITPTR
:
279 case SCMD_MEMREAD
: case SCMD_MEMWRITE
:
286 struct varinfo
find_fixup_for_globaldata(FILE *f
, size_t offset
, struct fixup_data
*fxd
, unsigned* code
, size_t codecount
) {
287 static enum varsize last_size
= vs4
;
290 struct varinfo ret
= {0,vs0
};
291 for(i
= 0; i
< fxd
->count
[FIXUP_GLOBALDATA
]; i
++) {
293 size_t x
= fxd
->codeindex_per
[FIXUP_GLOBALDATA
][i
];
294 assert(x
+ 1 < codecount
);
295 if(code
[x
] == offset
) {
297 enum varsize oldvarsize
= ret
.varsize
;
298 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+1);
299 if(!ret
.varsize
) switch(code
[x
+1]) {
301 // li mar, @Obj; mr ax, mar; callobj ax
302 if(x
+5 < codecount
&&
303 code
[x
+2] == AR_MAR
&&
304 code
[x
+4] == SCMD_CALLOBJ
&&
305 code
[x
+3] == code
[x
+5]) {
310 // li mar, @var; muli dx, 4; ptrget mar; ptrassert; dynamicbounds dx
311 if(x
+5 < codecount
&&
312 code
[x
+2] != AR_MAR
&&
313 code
[x
+4] == SCMD_MEMREADPTR
&&
316 // muli is used as an array index like:
317 // muli REG, 4; add MAR, REG; PUSH/POP MAR; ...
318 else if(x
+11 < codecount
&&
319 code
[x
+4] == SCMD_ADDREG
&&
320 code
[x
+5] == AR_MAR
&&
321 code
[x
+6] == code
[x
+2] &&
322 code
[x
+7] == SCMD_PUSHREG
&&
323 code
[x
+8] == AR_MAR
&&
324 code
[x
+9] == SCMD_POPREG
&&
325 code
[x
+10] == AR_MAR
) {
326 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+11);
329 code
[x
+11] == SCMD_ADDREG
&&
330 code
[x
+12] == AR_MAR
&&
331 code
[x
+13] != code
[x
+2]
333 /* this variation adds another reg to mar before calling ptrget */
334 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+14);
335 else if(!ret
.varsize
&&
337 code
[x
+11] == SCMD_PUSHREG
&&
339 /* this variation pushes ax on the stack before doing a ptrget ax, which overwrites ax */
340 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+13);
342 else if(x
+7 < codecount
&&
343 code
[x
+4] == SCMD_ADDREG
&&
344 code
[x
+5] == AR_MAR
&&
345 code
[x
+6] == code
[x
+2]) {
346 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+7);
349 code
[x
+7] == SCMD_PUSHREG
&&
351 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+9);
356 // addreg is typically used on an index register into an array
357 // followed by a byteread/store of the desired size
358 // the index register needs to be added to mar reg
359 assert(x
+2 < codecount
&& code
[x
+2] == AR_MAR
);
360 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+4);
361 // a typical method call
362 if(!ret
.varsize
&& x
+8 < codecount
&&
363 code
[x
+4] == SCMD_REGTOREG
&&
364 code
[x
+5] == AR_MAR
&&
365 code
[x
+7] == SCMD_CALLOBJ
&&
366 code
[x
+6] == code
[x
+8])
370 // ptrget and similar ops are typically preceded by push mar, pop mar
371 if(x
+4 < codecount
&&
372 code
[x
+2] == AR_MAR
&&
373 code
[x
+3] == SCMD_POPREG
&&
374 code
[x
+4] == AR_MAR
) {
375 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+5);
376 if(!ret
.varsize
&& x
+7 < codecount
&&
377 code
[x
+5] == SCMD_ADDREG
&&
379 ret
.varsize
= get_varsize_from_instr(code
, codecount
, x
+8);
385 /* don't bother guessing the varsize if we already determined it */
386 ret
.varsize
= oldvarsize
;
388 dprintf(2, "warning: '%s' globaldata fixup on insno %zu offset %zu\n",
389 opcodes
[code
[x
+1]].mnemonic
, x
+1, offset
);
390 COMMENT(f
, "warning: '%s' globaldata fixup on insno %zu offset %zu\n",
391 opcodes
[code
[x
+1]].mnemonic
, x
+1, offset
);
394 if(oldvarsize
!= 0 && oldvarsize
!= ret
.varsize
)
401 COMMENT(f
, "warning: couldn't determine varsize, default to 4\n");
404 COMMENT(f
, "unref'd, assuming array member with last known size\n");
405 ret
.varsize
= last_size
;
408 last_size
= ret
.varsize
;
413 int has_datadata_fixup(unsigned gdoffset
, struct fixup_data
*fxd
) {
415 for(i
= 0; i
< fxd
->count
[FIXUP_DATADATA
]; i
++)
416 if(fxd
->codeindex_per
[FIXUP_DATADATA
][i
] == gdoffset
)
421 static int dump_globaldata(AF
*a
, FILE *f
, size_t start
, size_t size
,
422 struct function_export
* exp
, size_t expcount
,
423 struct fixup_data
*fxd
,
424 unsigned *code
, size_t codesize
) {
426 const char*typenames
[vsmax
] = {[vs0
]="ERR", [vs1
]="char", [vs2
]="short", [vs4
]="int"};
427 fprintf(f
, ".%s\n", "data");
428 AF_set_pos(a
, start
);
430 for(; i
< size
; v
++) {
431 struct varinfo vi
= find_fixup_for_globaldata(f
, i
, fxd
, code
, codesize
);
439 x
= AF_read_short(a
);
442 x
= ByteArray_readByte(a
->b
);
445 COMMENT(f
, "unreferenced variable, assuming int\n");
451 char* vn
= get_varname(exp
, expcount
, i
);
452 if(has_datadata_fixup(i
, fxd
)) {
453 if(vn
) fprintf(f
, "export %s %s = .data + %d\n", typenames
[vi
.varsize
], vn
, x
);
454 else fprintf(f
, "%s var%.6zu = .data + %d\n", typenames
[vi
.varsize
], i
, x
);
456 if(vn
) fprintf(f
, "export %s %s = %d\n", typenames
[vi
.varsize
], vn
, x
);
457 else fprintf(f
, "%s var%.6zu = %d\n", typenames
[vi
.varsize
], i
, x
);
459 i
+= (const unsigned[vsmax
]) {[vs0
]=0, [vs1
]=1, [vs2
]=2, [vs4
]=4} [vi
.varsize
];
464 #include "StringEscape.h"
465 #define DEBUG_OFFSETS 1
466 #define DEBUG_BYTECODE 1
467 static int disassemble_code_and_data(AF
* a
, ASI
* s
, FILE *f
, int flags
, struct fixup_data
*fxd
) {
468 int debugmode
= getenv("AGSDEBUG") != 0;
469 size_t start
= s
->codestart
;
470 size_t len
= s
->codesize
* sizeof(unsigned);
472 unsigned *code
= get_code(a
, s
->codestart
, s
->codesize
);
474 struct function_export
* fl
= get_exports(a
, s
->exportstart
, s
->exportcount
);
476 dump_globaldata(a
, f
, s
->globaldatastart
, s
->globaldatasize
, fl
, s
->exportcount
, fxd
, code
, s
->codesize
);
478 if(!len
) return 1; /* its valid for a scriptfile to have no code at all */
481 struct importlist il
= get_imports(a
, s
->importstart
, s
->importcount
);
483 struct labels lbl
= get_labels(code
, s
->codesize
);
485 struct strings str
= get_strings(a
, s
->stringsstart
, s
->stringssize
);
487 AF_set_pos(a
, start
);
488 fprintf(f
, ".%s\n", "text");
490 size_t currInstr
= 0, currExp
= 0, currFixup
= 0, currLbl
= 0;
491 /* the data_data fixups appear to be glued separately onto the fixup logic,
492 * they are the only entries not sorted by instrucion number */
493 while(currFixup
< s
->fixupcount
&& fxd
->types
[currFixup
] == FIXUP_DATADATA
) currFixup
++;
494 while(currInstr
< s
->codesize
) {
495 if(flags
& DISAS_DEBUG_OFFSETS
) COMMENT(f
, "offset: %llu\n", (long long) AF_get_pos(a
));
496 unsigned regs
, args
, insn
= AF_read_uint(a
), op
= insn
& 0x00ffffff;
497 assert(op
< SCMD_MAX
);
498 while(currExp
< s
->exportcount
&& fl
[currExp
].type
!= EXPORT_FUNCTION
)
500 if(currExp
< s
->exportcount
&& fl
[currExp
].instr
== currInstr
) {
501 /* new function starts here */
502 fprintf(f
, "\n%s:\n", fl
[currExp
].fn
);
505 if(currLbl
< lbl
.count
) {
506 if(lbl
.insno
[currLbl
] == currInstr
) {
508 while(currLbl
< lbl
.count
&& lbl
.insno
[currLbl
] == currInstr
) {
509 currLbl
++; numrefs
++;
511 fprintf(f
, "label%.12zu: ", currInstr
);
512 COMMENT(f
, "referenced by %zu spots\n", numrefs
);
518 regs
= opcodes
[op
].regcount
;
519 args
= opcodes
[op
].argcount
;
521 if(insn
== SCMD_LINENUM
&& (flags
& DISAS_SKIP_LINENO
)) {
522 insn
= AF_read_uint(a
);
523 COMMENT(f
, "line %u\n", insn
);
528 if(flags
& DISAS_DEBUG_BYTECODE
) {
529 unsigned char insbuf
[16];
530 unsigned iblen
= 0, val
;
531 val
= end_htole32(insn
);
532 memcpy(insbuf
+iblen
, &val
, 4); iblen
+= 4;
534 off_t currpos
= AF_get_pos(a
);
536 for(size_t l
= 0; l
< args
; l
++) {
537 assert(iblen
+4 <= sizeof(insbuf
));
538 val
= AF_read_uint(a
);
539 val
= end_htole32(val
);
540 memcpy(insbuf
+iblen
, &val
, 4); iblen
+= 4;
543 char printbuf
[sizeof(insbuf
)*2 + 1], *pb
= printbuf
;
544 for(size_t l
= 0; l
< iblen
; l
++, pb
+=2)
545 sprintf(pb
, "%02x", (int) insbuf
[l
]);
546 COMMENT(f
, "%s\n", printbuf
);
548 AF_set_pos(a
, currpos
);
552 fprintf(f
, "%.12zu""\t%s ", currInstr
- 1, opcodes
[op
].mnemonic
);
554 fprintf(f
, /*"%.12zu"*/"\t%s ", /*currInstr - 1, */opcodes
[op
].mnemonic
);
556 if(insn
== SCMD_REGTOREG
) {
557 /* the "mov" instruction differs from all others in that the source comes first
558 we do not want that. */
560 src
= AF_read_uint(a
);
562 dst
= AF_read_uint(a
);
564 fprintf(f
, "%s, %s\n", regnames
[dst
], regnames
[src
]);
567 for (size_t l
= 0; l
< args
; l
++) {
568 char escapebuf
[4096];
569 if(l
) fprintf(f
, ", ");
570 insn
= AF_read_uint(a
);
572 if((!l
&& regs
) || (l
== 1 && regs
== 2))
573 fprintf(f
, "%s", regnames
[insn
]);
575 while(currFixup
< s
->fixupcount
&& fxd
->types
[currFixup
] == FIXUP_DATADATA
)
576 currFixup
++; /* DATADATA fixups are unrelated to the code */
577 if(currFixup
< s
->fixupcount
&& fxd
->codeindex
[currFixup
] == currInstr
- 1) {
578 switch(fxd
->types
[currFixup
]) {
581 fprintf(f
, "IMP:%s", il
.names
[insn
]);
583 fprintf(f
, "%s", il
.names
[insn
]);
585 case FIXUP_FUNCTION
: {
587 for(; x
< s
->exportcount
; x
++) {
588 if(fl
[x
].type
== EXPORT_FUNCTION
&& fl
[x
].instr
== insn
) {
589 fprintf(f
, "%s", fl
[x
].fn
);
595 case FIXUP_GLOBALDATA
: {
596 char *vn
= get_varname(fl
, s
->exportcount
, insn
);
597 if(vn
) fprintf(f
, "@%s", vn
);
598 else fprintf(f
, "@var%.6u", insn
);
600 case FIXUP_STACK
: /* it is unclear if and where those ever get generated */
601 fprintf(f
, ".stack + %d", insn
);
604 escape(str
.data
+ insn
, escapebuf
, sizeof(escapebuf
));
605 fprintf(f
, "\"%s\"", escapebuf
);
612 case SCMD_JMP
: case SCMD_JZ
: case SCMD_JNZ
:
613 fprintf(f
, "label%.12zu", currInstr
+ (int) insn
);
616 fprintf(f
, "%d", insn
);
627 int ASI_disassemble(AF
* a
, ASI
* s
, char *fn
, int flags
) {
630 if((f
= fopen(fn
, "w")) == 0)
632 AF_set_pos(a
, s
->start
);
633 struct fixup_data fxd
= {0};
634 if(!get_fixups(a
, s
->fixupstart
, s
->fixupcount
, &fxd
)) return 0;
636 //if(!dump_globaldata(a, fd, s->globaldatastart, s->globaldatasize)) goto err_close;
637 if(!disassemble_code_and_data(a
, s
, f
, flags
, &fxd
)) goto err_close
;
638 if(!dump_strings(a
, f
, s
->stringsstart
, s
->stringssize
)) goto err_close
;
639 if(!dump_fixups(f
, s
->fixupcount
, &fxd
)) goto err_close
;
640 if(!dump_import_export(a
, f
, s
->importstart
, s
->importcount
, 1)) goto err_close
;
641 if(!dump_import_export(a
, f
, s
->exportstart
, s
->exportcount
, 0)) goto err_close
;
642 if(!dump_sections(a
, f
, s
->sectionstart
, s
->sectioncount
)) goto err_close
;
644 free_fixup_data(&fxd
);
652 int ASI_read_script(AF
*a
, ASI
* s
) {
653 s
->start
= AF_get_pos(a
);
656 if(l
!= (size_t) AF_read(a
, sig
, l
)) return 0;
657 assert(memcmp("SCOM", sig
, 4) == 0);
658 s
->version
= AF_read_int(a
);
659 s
->globaldatasize
= AF_read_int(a
);
660 s
->codesize
= AF_read_int(a
);
661 s
->stringssize
= AF_read_int(a
);
662 if(s
->globaldatasize
) {
663 s
->globaldatastart
= AF_get_pos(a
);
664 l
= s
->globaldatasize
;
665 if(!AF_read_junk(a
, l
)) return 0;
666 } else s
->globaldatastart
= 0;
668 s
->codestart
= AF_get_pos(a
);
669 l
= s
->codesize
* sizeof(int);
670 if(!AF_read_junk(a
, l
)) return 0;
671 } else s
->codestart
= 0;
673 s
->stringsstart
= AF_get_pos(a
);
675 if(!AF_read_junk(a
, l
)) return 0;
676 } else s
->stringsstart
= 0;
677 s
->fixupcount
= AF_read_int(a
);
679 s
->fixupstart
= AF_get_pos(a
);
681 if(!AF_read_junk(a
, l
)) return 0; /* fixup types */
683 if(!AF_read_junk(a
, l
)) return 0; /* fixups */
684 } else s
->fixupstart
= 0;
685 s
->importcount
= AF_read_int(a
);
687 s
->importstart
= AF_get_pos(a
);
690 for(; i
< s
->importcount
; i
++)
691 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
692 } else s
->importstart
= 0;
693 s
->exportcount
= AF_read_int(a
);
695 s
->exportstart
= AF_get_pos(a
);
698 for(; i
< s
->exportcount
; i
++) {
699 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
700 AF_read_int(a
); /* export_addr */
702 } else s
->exportstart
= 0;
705 if (s
->version
>= 83) {
706 s
->sectioncount
= AF_read_int(a
);
707 if(s
->sectioncount
) {
708 s
->sectionstart
= AF_get_pos(a
);
711 for(; i
< s
->sectioncount
; i
++) {
712 if(!AF_read_string(a
, buf
, sizeof(buf
))) return 0;
713 AF_read_int(a
); /* section offset */
717 if(0xbeefcafe != AF_read_uint(a
)) return 0;
718 s
->len
= AF_get_pos(a
) - s
->start
;