diff options
author | Ash Wolf <ninji@wuffs.org> | 2022-10-19 21:16:13 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2022-10-19 21:16:13 +0100 |
commit | d1f153d34b023d81768f6087f67dbfff714bafc9 (patch) | |
tree | a694d470a60655d0cda15a70791fbdb90a2398cf /command_line/CmdLine/Src/MacEmul/Resources.c | |
parent | 775b6861666af36d317fb577cf489e2c6377f878 (diff) | |
download | MWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.tar.gz MWCC-d1f153d34b023d81768f6087f67dbfff714bafc9.zip |
let's commit all this before my VM blows up and nukes my work
Diffstat (limited to '')
-rw-r--r-- | command_line/CmdLine/Src/MacEmul/Resources.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/command_line/CmdLine/Src/MacEmul/Resources.c b/command_line/CmdLine/Src/MacEmul/Resources.c index 796ed43..ef2aab0 100644 --- a/command_line/CmdLine/Src/MacEmul/Resources.c +++ b/command_line/CmdLine/Src/MacEmul/Resources.c @@ -1,4 +1,4 @@ -#include "mwcc_decomp.h" +#include "cmdline.h" // Fork Attributes enum { @@ -284,6 +284,7 @@ memcpy(buf, ((unsigned char *) file_data) + __offs, (count)); \ } while(0) static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt32 file_size) { + // this function has various awkwardly swapped registers MemRsrcMap *rm; Ty70 thdr; Ty70 *dhdr; @@ -316,27 +317,29 @@ static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt cnt = sizeof(Ty70); RF_READ(&thdr, 0, cnt, mapFail); + dhdr = &thdr; ref_offs = cnt; cnt = ((thdr.map_offs < thdr.data_offs) ? thdr.map_offs : thdr.data_offs) - sizeof(Ty70); if (cnt > sizeof(MemRsrcSysData)) cnt = sizeof(MemRsrcSysData); RF_READ(&tsys, ref_offs, cnt, mapFail); + dsys = &tsys; - msize = thdr.map_len; + msize = dhdr->map_len; buffer = malloc(msize); if (!buffer) goto memFail; - ref_offs = thdr.map_offs; + ref_offs = dhdr->map_offs; RF_READ(buffer, ref_offs, msize, mapFail); if ( - (thdr.map_offs > file_size) - || ((thdr.map_offs + thdr.map_len) > file_size) - || (thdr.data_offs > file_size) - || ((thdr.data_offs + thdr.data_len) > file_size) - || ((thdr.map_offs < thdr.data_offs) ? ((thdr.map_offs + thdr.map_len) != thdr.data_offs) : ((thdr.data_offs + thdr.data_len) != thdr.map_offs)) + (dhdr->map_offs > file_size) + || ((dhdr->map_offs + dhdr->map_len) > file_size) + || (dhdr->data_offs > file_size) + || ((dhdr->data_offs + dhdr->data_len) > file_size) + || ((dhdr->map_offs < dhdr->data_offs) ? ((dhdr->map_offs + dhdr->map_len) > dhdr->data_offs) : ((dhdr->data_offs + dhdr->data_len) > dhdr->map_offs)) ) goto mapFail; @@ -344,13 +347,13 @@ static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt if (!rm) goto memFail; - rm->sys_data = tsys; + rm->sys_data = *dsys; dmap = (Ty73 *) buffer; - if ((dmap->typelist_offs + thdr.map_offs) > file_size) + if ((dmap->typelist_offs + dhdr->map_offs) > file_size) goto freeAndMapFail; dtyp = (Ty75 *) (((unsigned char *) buffer) + dmap->typelist_offs + 2); - if ((dmap->namelist_offs + thdr.map_offs) > file_size) + if ((dmap->namelist_offs + dhdr->map_offs) > file_size) goto freeAndMapFail; dnam = (Ty80 *) (((unsigned char *) buffer) + dmap->namelist_offs); if (dmap->types_idx != 0xFFFF) { @@ -359,21 +362,21 @@ static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt if (!mtyp) goto freeAndReturn; - if ((thdr.map_offs + dmap->typelist_offs + dtyp[cnt].ref_list_offs) > file_size) + if ((dmap->typelist_offs + dtyp[cnt].ref_list_offs + dhdr->map_offs) > file_size) goto freeAndMapFail; drle = (Ty77 *) (((unsigned char *) dtyp) + dtyp[cnt].ref_list_offs - 2); if (dtyp[cnt].rsrc_idx != 0xFFFF) { for (rcnt = 0; rcnt <= dtyp[cnt].rsrc_idx; rcnt++) { ref_offs = (drle[rcnt].data_offs[0] << 16) | (drle[rcnt].data_offs[1] << 8) | drle[rcnt].data_offs[2]; - offs = thdr.data_offs + ref_offs; + offs = ref_offs + dhdr->data_offs; if (offs > file_size) goto freeAndMapFail; esize = 4; RF_READ(&tent, offs, esize, freeAndMapFail); offs += esize; - if ((thdr.data_offs + ref_offs + tent.len) > file_size) + if ((tent.len + ref_offs + dhdr->data_offs) > file_size) goto freeAndMapFail; hand = NewHandle(tent.len); @@ -385,7 +388,7 @@ static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt HUnlock(hand); if (drle[rcnt].name_offs != 0xFFFF) { - nameptr = (StringPtr) (dnam + drle[rcnt].name_offs); + nameptr = (StringPtr) dnam + drle[rcnt].name_offs; name = malloc(nameptr[0] + 1); memcpy(name, nameptr, nameptr[0] + 1); } else { @@ -1250,14 +1253,14 @@ void HCreateResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName) { } } -OSErr FSpOpenResFile(const FSSpec *fss, SInt8 permission) { +OSErr FSpOpenResFile(const FSSpec *spec, SInt8 permission) { SInt16 ref; SInt32 size; if (permission != fsRdPerm) - FSpCreate(fss, 'CWIE', 'TEXT', -1); + FSpCreate(spec, 'CWIE', 'TEXT', -1); - resError = FSpOpenRF(fss, (permission == fsWrPerm) ? fsRdWrPerm : permission, &ref); + resError = FSpOpenRF(spec, (permission == fsWrPerm) ? fsRdWrPerm : permission, &ref); if (!resError) { GetEOF(ref, &size); if (size == 0 && permission != fsRdPerm) |