static int test_pru2(uint8 *data, char *t, int s) { int k; PW_REQUEST_DATA(s, 12 + 31 * 8); if (readmem32b(data) != 0x534e5421) return -1; #if 0 /* check sample address */ j = (data[i + 4] << 24) + (data[i + 5] << 16) + (data[i + 6] << 8) + data[i + 7]; PW_REQUEST_DATA (s, j); #endif /* test volumes */ for (k = 0; k < 31; k++) { if (data[11 + k * 8] > 0x40) return -1; } /* test finetunes */ for (k = 0; k < 31; k++) { if (data[10 + k * 8] > 0x0F) return -1; } pw_read_title(NULL, t, 0); return 0; }
static int test_ksm (uint8 *data, char *t, int s) { int j, k, l; int start = 0; PW_REQUEST_DATA(s, 1536); if (data[start] != 'M' || data[start + 1] != '.') return -1; /* test "a" */ if (data[start + 15] != 'a') return -1; /* test volumes */ for (k = 0; k < 15; k++) { if (data[start + 54 + k * 32] > 0x40) return -1; } /* test tracks data */ /* first, get the highest track number .. */ j = 0; for (k = 0; k < 1024; k++) { if (data[start + k + 512] == 0xFF) break; if (data[start + k + 512] > j) j = data[start + k + 512]; } if (k == 1024) return -1; if (j == 0) return -1; PW_REQUEST_DATA(s, start + 1536 + j * 192 + 63 * 3); /* so, now, j is the highest track number (first is 00h !!) */ /* real test on tracks data starts now */ for (k = 0; k <= j; k++) { for (l = 0; l < 64; l++) { if (data[start + 1536 + k * 192 + l * 3] > 0x24) return -1; } } /* j is still the highest track number */ pw_read_title(data + 2, t, 13); return 0; }
static int test_hrt(const uint8 *data, char *t, int s) { int i; PW_REQUEST_DATA(s, 1084); if (readmem32b(data + 1080) != MAGIC4('H','R','T','!')) return -1; for (i = 0; i < 31; i++) { const uint8 *d = data + 20 + i * 30; /* test finetune */ if (d[24] > 0x0f) return -1; /* test volume */ if (d[25] > 0x40) return -1; } pw_read_title(data, t, 20); return 0; }
static int test_fcm(uint8 *data, char *t, int s) { int start = 0; int j; PW_REQUEST_DATA(s, 37 + 8 * 31); /* "FC-M" : ID of FC-M packer */ if (data[0] != 'F' || data[1] != 'C' || data[2] != '-' || data[3] != 'M') return -1; /* test 1 */ if (data[start + 4] != 0x01) return -1; /* test 2 */ if (data[start + 5] != 0x00) return -1; /* test 3 */ for (j = 0; j < 31; j++) { if (data[start + 37 + 8 * j] > 0x40) return -1; } pw_read_title(data + 10, t, 20); return 0; }
static int test_ntp(uint8 *data, int s) { int j, k; int start = 0; PW_REQUEST_DATA(s, 64); if (readmem32b(data + start) != MAGIC4('M','O','D','U')) return -1; j = readmem16b(data + start + 20) + 4; /* "BODY" tag */ k = readmem16b(data + start + 28) + j + 4; /* "SAMP" tag */ PW_REQUEST_DATA(s, j + 4); if (readmem32b(data + start + j) != MAGIC4('B','O','D','Y')) return -1; PW_REQUEST_DATA(s, k + 4); if (readmem32b(data + start + k) != MAGIC4('S','A','M','P')) return -1; return 0; }
static int test_pha(const uint8 *data, char *t, int s) { int i; int ptr, ssize; PW_REQUEST_DATA(s, 451 + 128 * 4); if (data[10] != 0x03 || data[11] != 0xc0) return -1; /* test #2 (volumes,sample addresses and whole sample size) */ ssize = 0; for (i = 0; i < 31; i++) { const uint8 *d = data + i * 14; /* sample size */ ssize += readmem16b(d) << 1; if (d[3] > 0x40) return -1; /* loop start */ if ((readmem16b(d + 4) << 1) > ssize) return -1; /* address of sample data */ if (readmem32b(d + 8) < 0x3c0) return -1; } if (ssize <= 2 || ssize > 31 * 65535) return -1; /* test #3 (addresses of pattern in file ... ptk_tableible ?) */ /* l is the whole sample size */ /* ssize is used here as a variable ... set to 0 afterward */ for (i = 0; i < 128; i++) { ptr = readmem32b(data + 448 + i * 4); if (ptr + 2 - 960 < ssize) return -1; } pw_read_title(NULL, t, 0); return 0; }
static int test_skyt(const uint8 *data, char *t, int s) { int i; PW_REQUEST_DATA(s, 8 * 31 + 12); /* test 2 */ for (i = 0; i < 31; i++) { if (data[8 * i + 4] > 0x40) return -1; } if (readmem32b(data + 256) != MAGIC4('S','K','Y','T')) return -1; pw_read_title(NULL, t, 0); return 0; }
static int test_pru1(uint8 *data, char *t, int s) { PW_REQUEST_DATA(s, 1084); if (readmem32b(data + 1080) != 0x534e542e) /* "SNT." */ return -1; /* test 2 */ if (data[951] != 0x7f) return -1; /* test 3 */ if (data[950] > 0x7f) return -1; pw_read_title(data, t, 20); return 0; }
static int test_eu (uint8 *data, char *t, int s) { int j, k, l, m, n, o; int start = 0; PW_REQUEST_DATA (s, 1084); /* test 2 */ j = data[start + 950]; if (j == 0 || j > 127) return -1; /* test #3 finetunes & volumes */ for (k = 0; k < 31; k++) { o = (data[start + 42 + k * 30] << 8) + data[start + 43 + k * 30]; m = (data[start + 46 + k * 30] << 8) + data[start + 47 + k * 30]; n = (data[start + 48 + k * 30] << 8) + data[start + 49 + k * 30]; o *= 2; m *= 2; n *= 2; if (o > 0xffff || m > 0xffff || n > 0xffff) return -1; if ((m + n) > (o + 2)) return -1; if (data[start + 44 + k * 30] > 0x0f || data[start + 45 + k * 30] > 0x40) return -1; } /* test 4 */ l = (data[start + 1080] << 24) + (data[start + 1081] << 16) + (data[start + 1082] << 8) + data[start + 1083]; #if 0 if ((l + start) > in_size) return -1; #endif if (l < 1084) return -1; m = 0; /* pattern list */ for (k = 0; k < j; k++) { n = data[start + 952 + k]; if (n > m) m = n; if (n > 127) return -1; } k += 2; /* to be sure .. */ while (k != 128) { if (data[start + 952 + k] != 0) return -1; k += 1; } m += 1; /* m is the highest pattern number */ /* test #5 */ /* j is still the size if the pattern table */ /* l is still the address of the sample data */ /* m is the highest pattern number */ n = 0; j = 999999L; PW_REQUEST_DATA (s, start + (m * 4) * 2 + 1085); for (k = 0; k < (m * 4); k++) { o = (data[start + k * 2 + 1084] << 8) + data[start + k * 2 + 1085]; if (o > l || o < 1084) return -1; if (o > n) n = o; if (o < j) j = o; } /* o is the highest track address */ /* j is the lowest track address */ /* test track datas */ /* last track wont be tested ... */ for (k = j; k < o; k++) { if ((data[start + k] & 0xC0) == 0xC0) continue; if ((data[start + k] & 0xC0) == 0x80) { k += 2; continue; } if ((data[start + k] & 0xC0) == 0x40) { if ((data[start + k] & 0x3F) == 0x00 && data[start + k + 1] == 0x00) return -1; k += 1; continue; } if ((data[start + k] & 0xC0) == 0x00) { if (data[start + k] > 0x13) return -1; k += 3; continue; } } pw_read_title(data, t, 20); return 0; }
static int test_tdd(uint8 *data, char *t, int s) { int i; int ssize, psize, pdata_ofs; PW_REQUEST_DATA(s, 564); /* test #2 (volumes,sample addresses and whole sample size) */ ssize = 0; for (i = 0; i < 31; i++) { uint8 *d = data + i * 14; int addr = readmem32b(d + 130); /* sample address */ int size = readmem16b(d + 134); /* sample size */ int sadr = readmem32b(d + 138); /* loop start address */ int lsiz = readmem16b(d + 142); /* loop size (replen) */ /* volume > 40h ? */ if (d[137] > 0x40) return -1; /* loop start addy < sampl addy ? */ if (sadr < addr) return -1; /* addy < 564 ? */ if (addr < 564 || sadr < 564) return -1; /* loop start > size ? */ if (sadr - addr > size) return -1; /* loop start+replen > size ? */ if (sadr - addr + lsiz > size + 2) return -1; ssize += size; } if (ssize <= 2 || ssize > 31 * 65535) return -1; #if 0 /* test #3 (addresses of pattern in file ... ptk_tableible ?) */ /* ssize is the whole sample size :) */ if ((ssize + 564) > in_size) { Test = BAD; return; } #endif /* test size of pattern list */ if (data[0] == 0 || data[0] > 0x7f) return -1; /* test pattern list */ psize = 0; for (i = 0; i < 128; i++) { int pat = data[i + 2]; if (pat > 0x7f) return -1; if (pat > psize) psize = pat; } psize++; psize <<= 10; /* test end of pattern list */ for (i = data[0] + 2; i < 128; i++) { if (data[i + 2] != 0) return -1; } #if 0 /* test if not out of file range */ if ((ssize + 564 + k) > in_size) return -1; #endif /* ssize is the whole sample data size */ /* test pattern data now ... */ pdata_ofs = 564 + ssize; PW_REQUEST_DATA(s, 564 + ssize + psize); for (i = 0; i < psize; i += 4) { uint8 *d = data + pdata_ofs + i; /* sample number > 31 ? */ if (d[0] > 0x1f) return -1; /* note > 0x48 (36*2) */ if (d[1] > 0x48 || (d[1] & 0x01) == 0x01) return -1; /* fx=C and fxtArg > 64 ? */ if ((d[2] & 0x0f) == 0x0c && d[3] > 0x40) return -1; /* fx=D and fxtArg > 64 ? */ if ((d[2] & 0x0f) == 0x0d && d[3] > 0x40) return -1; /* fx=B and fxtArg > 127 ? */ if ((d[2] & 0x0f) == 0x0b) return -1; } pw_read_title(NULL, t, 0); return -1; }
static int test_fuchs (uint8 *data, int s) { int start = 0; int j, k, m, n, o; #if 0 /* test #1 */ if (i < 192) { Test = BAD; return; } start = i - 192; #endif if (readmem32b(data + 192) != 0x534f4e47) /* SONG */ return -1; /* all sample size */ j = ((data[start + 10] << 24) + (data[start + 11] << 16) + (data[start + 12] << 8) + data[start + 13]); if (j <= 2 || j >= (65535 * 16)) return -1; /* samples descriptions */ m = 0; for (k = 0; k < 16; k++) { /* size */ o = (data[start + k * 2 + 14] << 8) + data[start + k * 2 + 15]; /* loop start */ n = (data[start + k * 2 + 78] << 8) + data[start + k * 2 + 79]; /* volumes */ if (data[start + 46 + k * 2] > 0x40) return -1; /* size < loop start ? */ if (o < n) return -1; m += o; } /* m is the size of all samples (in descriptions) */ /* j is the sample data sizes (header) */ /* size<2 or size > header sample size ? */ if (m <= 2 || m > j) return -1; /* get highest pattern number in pattern list */ k = 0; for (j = 0; j < 40; j++) { n = data[start + j * 2 + 113]; if (n > 40) return -1; if (n > k) k = n; } /* m is the size of all samples (in descriptions) */ /* k is the highest pattern data -1 */ #if 0 /* input file not long enough ? */ k += 1; k *= 1024; PW_REQUEST_DATA (s, k + 200); #endif /* m is the size of all samples (in descriptions) */ /* k is the pattern data size */ return 0; }
static int test_tdd (uint8 *data, int s) { int j, k, l, m, n; int start = 0, ssize; PW_REQUEST_DATA (s, 564); /* test #2 (volumes,sample addresses and whole sample size) */ ssize = 0; for (j = 0; j < 31; j++) { uint8 *d = data + start + j * 14; k = readmem32b(d + 130); /* sample address */ l = readmem16b(d + 134); /* sample size */ m = readmem32b(d + 138); /* loop start address */ n = readmem16b(d + 142); /* loop size (replen) */ /* volume > 40h ? */ if (data[start + j * 14 + 137] > 0x40) return -1; /* loop start addy < sampl addy ? */ if (m < k) return -1; /* addy < 564 ? */ if (k < 564 || m < 564) return -1; /* loop start > size ? */ if (m - k > l) return -1; /* loop start+replen > size ? */ if (m - k + n > l + 2) return -1; ssize += l; } if (ssize <= 2 || ssize > (31 * 65535)) return -1; #if 0 /* test #3 (addresses of pattern in file ... ptk_tableible ?) */ /* ssize is the whole sample size :) */ if ((ssize + 564) > in_size) { /*printf ( "#3 (start:%ld)\n" , start );*/ Test = BAD; return; } #endif /* test size of pattern list */ if (data[start] > 0x7f || data[start] == 0x00) return -1; /* test pattern list */ k = 0; for (j = 0; j < 128; j++) { if (data[start + j + 2] > 0x7f) return -1; if (data[start + j + 2] > k) k = data[start + j + 2]; } k += 1; k *= 1024; /* test end of pattern list */ for (j = data[start] + 2; j < 128; j++) { if (data[start + j + 2] != 0) return -1; } #if 0 /* test if not out of file range */ if ((start + ssize + 564 + k) > in_size) return -1; #endif /* ssize is the whole sample data size */ /* k is the whole pattern data size */ /* test pattern data now ... */ l = start + 564 + ssize; /* l points on pattern data */ for (j = 0; j < k; j += 4) { /* sample number > 31 ? */ if (data[l + j] > 0x1f) return -1; /* note > 0x48 (36*2) */ if (data[l + j + 1] > 0x48 || (data[l + j + 1] & 0x01) == 0x01) return -1; /* fx=C and fxtArg > 64 ? */ if ((data[l + j + 2] & 0x0f) == 0x0c && data[l + j + 3] > 0x40) return -1; /* fx=D and fxtArg > 64 ? */ if ((data[l + j + 2] & 0x0f) == 0x0d && data[l + j + 3] > 0x40) return -1; /* fx=B and fxtArg > 127 ? */ if ((data[l + j + 2] & 0x0f) == 0x0b) return -1; } return -1; }