CPAU Updated

  • Thread starter Thread starter Joe Richards [MVP]
  • Start date Start date
J

Joe Richards [MVP]

FYI. I have updated CPAU to now have the ability to CRC check files and have
those CRCs stored in the job file and when the job file is executed it will
verify those stored CRCs prior to executing the job. This way if you are
specifying a script or batch file, you can be sure no one has modified the file
prior to running with enhanced credentials.

joe
 
Joe Richards said:
FYI. I have updated CPAU to now have the ability to CRC check files and have
those CRCs stored in the job file and when the job file is executed it will
verify those stored CRCs prior to executing the job. This way if you are
specifying a script or batch file, you can be sure no one has modified the file
prior to running with enhanced credentials.

joe


Nice feature, thanks Joe. Just curious, how did you go about calculating
the CRC?
 
The old fashioned way. :o)

I looked at various pieces of code out on the internet that did the CRC
calculation and then put something together based on what I saw and smacked it
around a bit to fit it into my general format.

Kind of handy to have those functions now, previously when I was doing stuff
that needed CRC checking I would wrap it in perl and use the CRC functions from
the Zip module that is available through CPAN. Now I have what I want and can
quickly and easily write up some multithreaded stuff. Just have to add a mutex
on the table initialization if the table is stored in a shared memory (global)
area.



I will do something I like never do and post the relevant bits since I didn't
write them from scratch. Watch for wrap...




bool bCrcInitialized=false;
ULONG ulCrc32Table[256];

void InitCRC32(void);
ULONG Reflect(ULONG, char);
int GetCRC(char*, DWORD, ULONG crc=0);


void InitCRC32(void)
{
ULONG ulPolynomial = 0x04c11db7;
for(int i = 0; i <= 0xFF; i++)
{
ulCrc32Table=Reflect(i, 8) << 24;
for (int j = 0; j < 8; j++)
ulCrc32Table = (ulCrc32Table << 1) ^ (ulCrc32Table & (1 << 31) ?
ulPolynomial : 0);
ulCrc32Table = Reflect(ulCrc32Table, 32);
}
bCrcInitialized=true;
}


ULONG Reflect(ULONG ref, char ch)
{
ULONG value(0);
for(int i = 1; i < (ch + 1); i++)
{
if(ref & 1) value |= 1 << (ch - i);
ref >>= 1;
}
return value;
}


int GetCRC(char *buf, DWORD dwSize, ULONG crc)
{
crc = crc ^ 0xffffffffL;
while(dwSize--)
{
crc = (crc >> 8) ^ ulCrc32Table[(crc ^ (*buf++)) & 0xFF];
}
return crc^0xffffffffL;
}
 
Joe Richards said:
The old fashioned way. :o)

I looked at various pieces of code out on the internet that did the CRC
calculation and then put something together based on what I saw and smacked it
around a bit to fit it into my general format.

Kind of handy to have those functions now, previously when I was doing stuff
that needed CRC checking I would wrap it in perl and use the CRC functions from
the Zip module that is available through CPAN. Now I have what I want and can
quickly and easily write up some multithreaded stuff. Just have to add a mutex
on the table initialization if the table is stored in a shared memory (global)
area.



I will do something I like never do and post the relevant bits since I didn't
write them from scratch. Watch for wrap...

Very cool, thanks. This will save me some time on a project I have coming
up.
 
Back
Top