support Administrator
Joined: January 26 2005 Location: United States Posts: 1666
|
Posted: January 09 2007 at 2:35pm | IP Logged
|
|
|
Hi hermes,
Thanks for pointing that out. Yes it is a bug in the example source code procedure ReadLicenseImage(). We will fix it for the next release.
The bug won't cause any effects though seeing that the last byte of license data is an internal pad byte. We got lucky.
Here is a version of the procedure that will get the last byte in the license data properly:
Code:
BOOL PhoneSetingsDlg::ReadLicenseImage(char *pLicenseFileName, BYTE **ppRuntimeMicrocode, int *pRuntimeMicrocodeLength)
{
BOOL ret = FALSE;
FILE *fp;
char ch;
char Line[256];
char *str;
CString tmp;
BOOL done = FALSE;
CCommaSeparatedList Helper;
BYTE value;
int NumBytes;
int Pass;
BYTE *pRuntimeMicrocode;
BYTE *pCurByte;
int RuntimeMicrocodeLength;
fp = fopen(pLicenseFileName,"rt");
if(fp)
{
// go through the data once to determine byte size. pass 2 actually
// saves the data.
for(Pass=0;Pass<2;Pass++)
{
if(Pass == 1)
{
// allocate space for converted pass 2 data.
pRuntimeMicrocode = new BYTE[NumBytes];
if(!pRuntimeMicrocode)
{
// memory error.
break;
}
else
{
pCurByte = pRuntimeMicrocode;
RuntimeMicrocodeLength = NumBytes;
}
}
NumBytes = 0;
// get to the open bracket.
ch = 0;
while((!feof(fp) && ch != '{'))
{
ch = fgetc(fp);
}
// start processing lines.
while(!done && !feof(fp))
{
if(!fgets(Line,sizeof(Line)-1,fp))
{
done = TRUE;
}
else
{
str = Line;
for(;!done;)
{
str = strstr(str,"0x");
if(!str)
{
break;
}
else
{
// see if we are at the end of the data.
if(*(str + 4) == '\n')
{
// convert the last data byte.
Helper.copytil(&tmp,str,"\n");
// terminate further processing.
done = TRUE;
}
else
{
// convert the byte as normal.
Helper.copytil(&tmp,str,",");
}
HexToByte(CSPTR(tmp),&value);
NumBytes ++;
str += 2;
if(Pass == 1)
{
*pCurByte = value;
pCurByte ++;
}
}
}
}
}
if(Pass == 0)
{
if(NumBytes <= 8192)
{
// bad microcode file.
break;
}
else
{
done = FALSE;
rewind(fp);
}
}
else
{
*ppRuntimeMicrocode = pRuntimeMicrocode;
*pRuntimeMicrocodeLength = RuntimeMicrocodeLength;
done = TRUE;
// success.
ret = TRUE;
}
}
fclose(fp);
}
return(ret);
}
|
|
|
Repost as neeed,
Support
|