@@ -94,6 +94,7 @@ enum calc_type {
94
94
};
95
95
96
96
int findfield ( unsigned char byte, const unsigned char * buffer );
97
+ int findfield_flex ( unsigned char prefix_byte, const unsigned char * buffer, int *buf_field_loc, int *buf_field_size );
97
98
int siggen (const unsigned char * hashbuf, unsigned char * sigbuf, int * outf);
98
99
void intelhex (FILE * outfile , const unsigned char * buffer, int size, unsigned int address = 0x4000 );
99
100
void alphanumeric (char * namestring, bool allow_lower);
@@ -212,7 +213,7 @@ void makehex (const unsigned char *output_contents, DWORD size, FILE *outfile) {
212
213
213
214
void makeapp (const unsigned char *output_contents, DWORD size, FILE *outfile, const char * prgmname) {
214
215
unsigned char *buffer;
215
- int i,pnt,siglength,tempnum,f,pages;
216
+ int i,pnt,siglength,tempnum,f,pages,field_sz ;
216
217
unsigned int total_size;
217
218
218
219
/* Copy file to memory */
@@ -264,14 +265,16 @@ void makeapp (const unsigned char *output_contents, DWORD size, FILE *outfile, c
264
265
pages = size>>14 ; /* this is safe because we know there's enough room for the sig */
265
266
if (size & 0x3FFF ) pages++;
266
267
buffer[pnt] = pages;
267
- /* Name Field: MUST BE 8 CHARACTERS, no checking if valid */
268
- pnt = findfield (0x48 , buffer);
269
- if (!pnt) {
268
+ /* Name Field: Can be a variable number of characters, no checking if valid */
269
+ if (findfield_flex (0x40 , buffer, &pnt, &field_sz)) {
270
270
free (buffer);
271
271
SetLastSPASMError (SPASM_ERR_SIGNER_MISSING_NAME);
272
272
return ;
273
273
}
274
- for (i=0 ; i < 8 ;i++) name[i]=buffer[i+pnt];
274
+ /* Set name length */
275
+ *(name - 1 ) = (field_sz <= 8 ) ? field_sz : 8 ;
276
+ /* Only copy the part of the name defined in the size returned */
277
+ for (i=0 ; i < ((field_sz <= 8 ) ? field_sz : 8 ); i++) name[i]=buffer[i+pnt];
275
278
276
279
#ifndef NO_APPSIGN
277
280
/* Calculate MD5 */
@@ -360,6 +363,29 @@ int findfield( unsigned char byte, const unsigned char* buffer ) {
360
363
return 0 ;
361
364
}
362
365
366
+ /* This implements findfield but with byte splitting, e.g.
367
+ * prefix for first 4 bits and size for last 4 bits.
368
+ * Uses return by arg to return both location and app field size.
369
+ * Actual return value indicates success or failure. Location and size
370
+ * will be set to 0 if failure.
371
+ */
372
+ int findfield_flex ( unsigned char prefix_byte, const unsigned char * buffer, int *buf_field_loc, int *buf_field_size ) {
373
+ int pnt=6 ;
374
+ while (buffer[pnt++] == 0x80 ) {
375
+ if ((buffer[pnt] & 0xF0 ) == (prefix_byte & 0xF0 )) {
376
+ *buf_field_size = (buffer[pnt] & 0x0F );
377
+ pnt++;
378
+ *buf_field_loc = pnt;
379
+ return 0 ;
380
+ } else
381
+ pnt += (buffer[pnt] & 0x0F );
382
+ pnt++;
383
+ }
384
+ *buf_field_loc = 0 ;
385
+ *buf_field_size = 0 ;
386
+ return 1 ;
387
+ }
388
+
363
389
#ifndef NO_APPSIGN
364
390
int siggen (const unsigned char * hashbuf, unsigned char * sigbuf, int * outf) {
365
391
mpz_t mhash, p, q, r, s, temp, result;
0 commit comments