mirror of
https://github.com/wnayes/macutils.git
synced 2024-12-30 06:30:02 +00:00
64-bit: Fix CRC on 64-bit systems by using 32-bit types.
This commit is contained in:
parent
f980b8a9a9
commit
0b9ba9ae5d
@ -1,10 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include "../fileio/machdr.h"
|
||||
#include "../fileio/rdfile.h"
|
||||
#include "../crc/crc.h"
|
||||
|
||||
extern int dorep;
|
||||
extern unsigned long binhex_crcinit;
|
||||
extern unsigned long binhex_updcrc();
|
||||
|
||||
#define RUNCHAR 0x90
|
||||
|
||||
@ -43,35 +42,35 @@ void dofile()
|
||||
|
||||
void doheader()
|
||||
{
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
int i, n;
|
||||
|
||||
crc = binhex_crcinit;
|
||||
n = file_info[I_NAMEOFF];
|
||||
crc = binhex_updcrc(crc, file_info + I_NAMEOFF, n + 1);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_NAMEOFF), n + 1);
|
||||
for(i = 0; i <= n; i++) {
|
||||
outbyte(file_info[I_NAMEOFF + i]);
|
||||
}
|
||||
n = 0;
|
||||
crc = binhex_updcrc(crc, (char *)&n, 1);
|
||||
crc = binhex_updcrc(crc, (unsigned char *)&n, 1);
|
||||
outbyte(0);
|
||||
crc = binhex_updcrc(crc, file_info + I_TYPEOFF, 4);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_TYPEOFF), 4);
|
||||
for(i = 0; i < 4; i++) {
|
||||
outbyte(file_info[I_TYPEOFF + i]);
|
||||
}
|
||||
crc = binhex_updcrc(crc, file_info + I_AUTHOFF, 4);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_AUTHOFF), 4);
|
||||
for(i = 0; i < 4; i++) {
|
||||
outbyte(file_info[I_AUTHOFF + i]);
|
||||
}
|
||||
crc = binhex_updcrc(crc, file_info + I_FLAGOFF, 2);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_FLAGOFF), 2);
|
||||
for(i = 0; i < 2; i++) {
|
||||
outbyte(file_info[I_FLAGOFF + i]);
|
||||
}
|
||||
crc = binhex_updcrc(crc, file_info + I_DLENOFF, 4);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_DLENOFF), 4);
|
||||
for(i = 0; i < 4; i++) {
|
||||
outbyte(file_info[I_DLENOFF + i]);
|
||||
}
|
||||
crc = binhex_updcrc(crc, file_info + I_RLENOFF, 4);
|
||||
crc = binhex_updcrc(crc, (unsigned char*)(file_info + I_RLENOFF), 4);
|
||||
for(i = 0; i < 4; i++) {
|
||||
outbyte(file_info[I_RLENOFF + i]);
|
||||
}
|
||||
@ -83,10 +82,10 @@ void dofork(fork, size)
|
||||
char *fork;
|
||||
int size;
|
||||
{
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
int i;
|
||||
|
||||
crc = binhex_updcrc(binhex_crcinit, fork, size);
|
||||
crc = binhex_updcrc(binhex_crcinit, (unsigned char*)fork, size);
|
||||
for(i = 0; i < size; i++) {
|
||||
outbyte(fork[i]);
|
||||
}
|
||||
|
14
crc/crc.h
Normal file
14
crc/crc.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef CRC_CRC_H
|
||||
#define CRC_CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint32_t arc_crcinit;
|
||||
extern uint32_t binhex_crcinit;
|
||||
extern uint32_t zip_crcinit;
|
||||
|
||||
extern uint32_t arc_updcrc(uint32_t icrc, unsigned char *icp, int32_t icnt);
|
||||
extern uint32_t binhex_updcrc(uint32_t icrc, unsigned char *icp, int32_t icnt);
|
||||
extern uint32_t zip_updcrc(uint32_t icrc, unsigned char *icp, int32_t icnt);
|
||||
|
||||
#endif
|
@ -64,12 +64,13 @@ int poly, init, swapped, bits;
|
||||
(void)fprintf(stderr, "Cannot open %s for writing\n", buf);
|
||||
exit(1);
|
||||
}
|
||||
(void)fprintf(fd, "unsigned long %s_crcinit = %d;\n", name, init);
|
||||
(void)fprintf(fd, "#include \"crc.h\"\n");
|
||||
(void)fprintf(fd, "uint32_t %s_crcinit = %d;\n", name, init);
|
||||
(void)fprintf(fd, "\n");
|
||||
if(bits == 16) {
|
||||
(void)fprintf(fd, "static unsigned short crctab[256] = {\n");
|
||||
(void)fprintf(fd, "static uint16_t crctab[256] = {\n");
|
||||
} else {
|
||||
(void)fprintf(fd, "static unsigned long crctab[256] = {\n");
|
||||
(void)fprintf(fd, "static uint32_t crctab[256] = {\n");
|
||||
}
|
||||
(void)fprintf(fd, " ");
|
||||
if(bits == 16) {
|
||||
@ -109,7 +110,7 @@ int poly, init, swapped, bits;
|
||||
}
|
||||
(void)fprintf(fd, "};\n");
|
||||
(void)fprintf(fd, "\n");
|
||||
(void)fprintf(fd, "unsigned long %s_updcrc(unsigned long icrc, unsigned char *icp, int icnt)\n", name);
|
||||
(void)fprintf(fd, "uint32_t %s_updcrc(uint32_t icrc, unsigned char *icp, int32_t icnt)\n", name);
|
||||
(void)fprintf(fd, "{\n");
|
||||
if(bits == 16) {
|
||||
(void)fprintf(fd, "#define M1 0xff\n");
|
||||
@ -118,9 +119,9 @@ int poly, init, swapped, bits;
|
||||
(void)fprintf(fd, "#define M1 0xffffff\n");
|
||||
(void)fprintf(fd, "#define M2 0xffffff00\n");
|
||||
}
|
||||
(void)fprintf(fd, " register unsigned long crc = icrc;\n");
|
||||
(void)fprintf(fd, " register uint32_t crc = icrc;\n");
|
||||
(void)fprintf(fd, " register unsigned char *cp = icp;\n");
|
||||
(void)fprintf(fd, " register int cnt = icnt;\n");
|
||||
(void)fprintf(fd, " register int32_t cnt = icnt;\n");
|
||||
(void)fprintf(fd, "\n");
|
||||
(void)fprintf(fd, " while(cnt--) {\n");
|
||||
if(bits == 16) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
extern void exit();
|
||||
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
|
||||
#ifdef HQX
|
||||
void comp_q_crc(c)
|
||||
|
12
hexbin/crc.h
12
hexbin/crc.h
@ -1,10 +1,10 @@
|
||||
#define INITCRC binhex_crcinit
|
||||
|
||||
extern unsigned long crc;
|
||||
extern unsigned long binhex_crcinit;
|
||||
extern unsigned long binhex_updcrc();
|
||||
#include "../crc/crc.h"
|
||||
|
||||
extern void comp_q_crc();
|
||||
extern void comp_q_crc_n();
|
||||
extern void verify_crc();
|
||||
extern uint32_t crc;
|
||||
|
||||
extern void comp_q_crc (register unsigned int c);
|
||||
extern void comp_q_crc_n (register unsigned char *s, register unsigned char *e);
|
||||
extern void verify_crc (unsigned long calc_crc, unsigned long file_crc);
|
||||
|
||||
|
@ -92,11 +92,11 @@ void cpt()
|
||||
#endif /* SCAN */
|
||||
exit(1);
|
||||
}
|
||||
cpt_crc = (*updcrc)(cpt_crc, cptptr, cpthdr.commentsize);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)cptptr, cpthdr.commentsize);
|
||||
|
||||
for(i = 0; i < cpthdr.entries; i++) {
|
||||
*cptptr = getc(infp);
|
||||
cpt_crc = (*updcrc)(cpt_crc, cptptr, 1);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)cptptr, 1);
|
||||
if(*cptptr & 0x80) {
|
||||
cptptr[F_FOLDER] = 1;
|
||||
*cptptr &= 0x3f;
|
||||
@ -110,7 +110,7 @@ void cpt()
|
||||
#endif /* SCAN */
|
||||
exit(1);
|
||||
}
|
||||
cpt_crc = (*updcrc)(cpt_crc, cptptr + 1, *cptptr);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)(cptptr + 1), *cptptr);
|
||||
if(cptptr[F_FOLDER]) {
|
||||
if(fread(cptptr + F_FOLDERSIZE, 1, 2, infp) != 2) {
|
||||
(void)fprintf(stderr, "Can't read file header #%d\n", i+1);
|
||||
@ -119,7 +119,7 @@ void cpt()
|
||||
#endif /* SCAN */
|
||||
exit(1);
|
||||
}
|
||||
cpt_crc = (*updcrc)(cpt_crc, cptptr + F_FOLDERSIZE, 2);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)(cptptr + F_FOLDERSIZE), 2);
|
||||
} else {
|
||||
if(fread(cptptr + F_VOLUME, 1, FILEHDRSIZE - F_VOLUME, infp) !=
|
||||
FILEHDRSIZE - F_VOLUME) {
|
||||
@ -129,7 +129,7 @@ void cpt()
|
||||
#endif /* SCAN */
|
||||
exit(1);
|
||||
}
|
||||
cpt_crc = (*updcrc)(cpt_crc, cptptr + F_VOLUME,
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)(cptptr + F_VOLUME),
|
||||
FILEHDRSIZE - F_VOLUME);
|
||||
}
|
||||
cptptr += FILEHDRSIZE;
|
||||
@ -203,7 +203,7 @@ struct cptHdr *s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
cpt_crc = (*updcrc)(cpt_crc, temp + CPTHDRSIZE + C_ENTRIES, 3);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)(temp + CPTHDRSIZE + C_ENTRIES), 3);
|
||||
s->hdrcrc = get4(temp + CPTHDRSIZE + C_HDRCRC);
|
||||
s->entries = get2(temp + CPTHDRSIZE + C_ENTRIES);
|
||||
s->commentsize = temp[CPTHDRSIZE + C_COMMENT];
|
||||
@ -415,7 +415,7 @@ unsigned short type;
|
||||
} else {
|
||||
cpt_rle_lzh();
|
||||
}
|
||||
cpt_crc = (*updcrc)(cpt_crc, out_buffer, obytes);
|
||||
cpt_crc = (*updcrc)(cpt_crc, (unsigned char*)out_buffer, obytes);
|
||||
}
|
||||
|
||||
void cpt_wrfile1(in_char, ibytes, obytes, type, blocksize)
|
||||
|
@ -1,4 +1,6 @@
|
||||
unsigned long crcinit;
|
||||
#include "crc.h"
|
||||
|
||||
unsigned long (*updcrc)();
|
||||
uint32_t crcinit;
|
||||
|
||||
uint32_t (*updcrc)(uint32_t icrc, unsigned char *icp, int32_t icnt);
|
||||
|
||||
|
@ -1,13 +1,6 @@
|
||||
#define INIT_CRC crcinit
|
||||
|
||||
extern unsigned long arc_crcinit;
|
||||
extern unsigned long binhex_crcinit;
|
||||
extern unsigned long zip_crcinit;
|
||||
|
||||
extern unsigned long arc_updcrc(unsigned long icrc, unsigned char *icp, int icnt);
|
||||
extern unsigned long binhex_updcrc(unsigned long icrc, unsigned char *icp, int icnt);
|
||||
extern unsigned long zip_updcrc(unsigned long icrc, unsigned char *icp, int icnt);
|
||||
|
||||
extern unsigned long crcinit;
|
||||
extern unsigned long (*updcrc)();
|
||||
#include "../crc/crc.h"
|
||||
|
||||
extern uint32_t crcinit;
|
||||
extern uint32_t (*updcrc)(uint32_t icrc, unsigned char *icp, int32_t icnt);
|
||||
|
@ -151,7 +151,7 @@ void dd_arch(bin_hdr)
|
||||
unsigned char *bin_hdr;
|
||||
{
|
||||
unsigned long data_size;
|
||||
unsigned long crc, filecrc;
|
||||
uint32_t crc, filecrc;
|
||||
struct fileHdr f;
|
||||
struct fileCHdr cf;
|
||||
char locname[64];
|
||||
@ -322,7 +322,7 @@ struct fileCHdr *cf;
|
||||
int skip;
|
||||
{
|
||||
register int i;
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
int n, to_uncompress;
|
||||
unsigned char *hdr;
|
||||
char ftype[5], fauth[5];
|
||||
@ -428,7 +428,7 @@ int skip;
|
||||
static void dd_cfilehdr(f)
|
||||
struct fileCHdr *f;
|
||||
{
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
unsigned char *hdr;
|
||||
|
||||
hdr = dd_data_ptr;
|
||||
|
@ -368,7 +368,7 @@ int method;
|
||||
int rsrcLength, dataLength;
|
||||
int doit;
|
||||
char *mname;
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
|
||||
if(filehdr->upsize > lzh_filesize) {
|
||||
if(lzh_filesize == 0) {
|
||||
@ -557,7 +557,7 @@ int method;
|
||||
}
|
||||
}
|
||||
if(doit) {
|
||||
crc = (*updcrc)(INIT_CRC, lzh_file, filehdr->upsize);
|
||||
crc = (*updcrc)(INIT_CRC, (unsigned char*)lzh_file, filehdr->upsize);
|
||||
if(filehdr->crc != crc) {
|
||||
(void)fprintf(stderr,
|
||||
"CRC error on file: need 0x%04x, got 0x%04x\n",
|
||||
|
@ -122,10 +122,10 @@ void pit()
|
||||
start_info(info, filehdr.rlen, filehdr.dlen);
|
||||
start_data();
|
||||
pit_wrfile(filehdr.dlen, decode);
|
||||
data_crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dlen);
|
||||
data_crc = (*updcrc)(INIT_CRC, (unsigned char*)out_buffer, filehdr.dlen);
|
||||
start_rsrc();
|
||||
pit_wrfile(filehdr.rlen, decode);
|
||||
data_crc = (*updcrc)(data_crc, out_buffer, filehdr.rlen);
|
||||
data_crc = (*updcrc)(data_crc, (unsigned char*)out_buffer, filehdr.rlen);
|
||||
if(decode == nocomp) {
|
||||
crc = getb(infp);
|
||||
crc = (crc << 8) | getb(infp);
|
||||
@ -164,7 +164,7 @@ struct pit_header *f;
|
||||
int compr;
|
||||
{
|
||||
register int i;
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
int n;
|
||||
char hdr[HDRBYTES];
|
||||
char ftype[5], fauth[5];
|
||||
@ -182,7 +182,7 @@ int compr;
|
||||
}
|
||||
}
|
||||
crc = INIT_CRC;
|
||||
crc = (*updcrc)(crc, hdr, HDRBYTES - 2);
|
||||
crc = (*updcrc)(crc, (unsigned char*)hdr, HDRBYTES - 2);
|
||||
|
||||
f->hdrCRC = get2(hdr + H_HDRCRC);
|
||||
if(f->hdrCRC != crc) {
|
||||
|
@ -157,7 +157,7 @@ static int readsithdr(sitHdr *s)
|
||||
static int sit_filehdr(struct fileHdr *f, int skip)
|
||||
{
|
||||
register int i;
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
int n;
|
||||
char hdr[FILEHDRSIZE];
|
||||
char ftype[5], fauth[5];
|
||||
@ -170,7 +170,7 @@ static int sit_filehdr(struct fileHdr *f, int skip)
|
||||
return -1;
|
||||
}
|
||||
crc = INIT_CRC;
|
||||
crc = (*updcrc)(crc, hdr, FILEHDRSIZE - 2);
|
||||
crc = (*updcrc)(crc, (unsigned char*)hdr, FILEHDRSIZE - 2);
|
||||
|
||||
f->hdrCRC = get2(hdr + F_HDRCRC);
|
||||
if(f->hdrCRC != crc) {
|
||||
@ -390,7 +390,7 @@ char *name;
|
||||
static void sit_unstuff(filehdr)
|
||||
struct fileHdr filehdr;
|
||||
{
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
|
||||
if(write_it) {
|
||||
start_info(info, filehdr.rsrcLength, filehdr.dataLength);
|
||||
@ -403,7 +403,7 @@ struct fileHdr filehdr;
|
||||
}
|
||||
sit_wrfile(filehdr.compRLength, filehdr.rsrcLength, filehdr.compRMethod);
|
||||
if(write_it) {
|
||||
crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.rsrcLength);
|
||||
crc = (*updcrc)(INIT_CRC, (unsigned char*)out_buffer, filehdr.rsrcLength);
|
||||
if(filehdr.rsrcCRC != crc) {
|
||||
(void)fprintf(stderr,
|
||||
"CRC error on resource fork: need 0x%04x, got 0x%04x\n",
|
||||
@ -422,7 +422,7 @@ struct fileHdr filehdr;
|
||||
}
|
||||
sit_wrfile(filehdr.compDLength, filehdr.dataLength, filehdr.compDMethod);
|
||||
if(write_it) {
|
||||
crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dataLength);
|
||||
crc = (*updcrc)(INIT_CRC, (unsigned char*)out_buffer, filehdr.dataLength);
|
||||
if(filehdr.dataCRC != crc) {
|
||||
(void)fprintf(stderr,
|
||||
"CRC error on data fork: need 0x%04x, got 0x%04x\n",
|
||||
|
@ -274,7 +274,7 @@ struct fileHdr fhdr;
|
||||
static void zma_mooz(filehdr)
|
||||
struct fileHdr filehdr;
|
||||
{
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
|
||||
if(write_it) {
|
||||
start_info(info, filehdr.rsrcLength, filehdr.dataLength);
|
||||
@ -287,7 +287,7 @@ struct fileHdr filehdr;
|
||||
}
|
||||
zma_wrfile(filehdr.compDLength, filehdr.dataLength, filehdr.what);
|
||||
if(write_it) {
|
||||
crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.dataLength);
|
||||
crc = (*updcrc)(INIT_CRC, (unsigned char*)out_buffer, filehdr.dataLength);
|
||||
if(filehdr.dataCRC != crc) {
|
||||
(void)fprintf(stderr,
|
||||
"CRC error on data fork: need 0x%04x, got 0x%04x\n",
|
||||
@ -306,7 +306,7 @@ struct fileHdr filehdr;
|
||||
}
|
||||
zma_wrfile(filehdr.compRLength, filehdr.rsrcLength, filehdr.what);
|
||||
if(write_it) {
|
||||
crc = (*updcrc)(INIT_CRC, out_buffer, filehdr.rsrcLength);
|
||||
crc = (*updcrc)(INIT_CRC, (unsigned char*)out_buffer, filehdr.rsrcLength);
|
||||
if(filehdr.rsrcCRC != crc) {
|
||||
(void)fprintf(stderr,
|
||||
"CRC error on resource fork: need 0x%04x, got 0x%04x\n",
|
||||
|
Loading…
Reference in New Issue
Block a user