Skip to content

Commit 7665179

Browse files
committed
Tentative fix for issue #53 - allow variable length app names
1 parent e6e9a42 commit 7665179

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

export.cpp

+31-5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ enum calc_type {
9494
};
9595

9696
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 );
9798
int siggen (const unsigned char* hashbuf, unsigned char* sigbuf, int* outf);
9899
void intelhex (FILE * outfile , const unsigned char* buffer, int size, unsigned int address = 0x4000);
99100
void alphanumeric (char* namestring, bool allow_lower);
@@ -212,7 +213,7 @@ void makehex (const unsigned char *output_contents, DWORD size, FILE *outfile) {
212213

213214
void makeapp (const unsigned char *output_contents, DWORD size, FILE *outfile, const char* prgmname) {
214215
unsigned char *buffer;
215-
int i,pnt,siglength,tempnum,f,pages;
216+
int i,pnt,siglength,tempnum,f,pages,field_sz;
216217
unsigned int total_size;
217218

218219
/* Copy file to memory */
@@ -264,14 +265,16 @@ void makeapp (const unsigned char *output_contents, DWORD size, FILE *outfile, c
264265
pages = size>>14; /* this is safe because we know there's enough room for the sig */
265266
if (size & 0x3FFF) pages++;
266267
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)) {
270270
free(buffer);
271271
SetLastSPASMError(SPASM_ERR_SIGNER_MISSING_NAME);
272272
return;
273273
}
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];
275278

276279
#ifndef NO_APPSIGN
277280
/* Calculate MD5 */
@@ -360,6 +363,29 @@ int findfield( unsigned char byte, const unsigned char* buffer ) {
360363
return 0;
361364
}
362365

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+
363389
#ifndef NO_APPSIGN
364390
int siggen(const unsigned char* hashbuf, unsigned char* sigbuf, int* outf) {
365391
mpz_t mhash, p, q, r, s, temp, result;

0 commit comments

Comments
 (0)