Sign in to follow this  
Followers 0
fi3ldy

CRC32 File Generation

7 posts in this topic

Ok, I'm getting a little ahead of my here.. I've done a little searching and found nothing on generating file crc32 strings <_<

I was wondering if anybody knew of a way to generate the file crc32. Ideally I am going to use this for scanning running processes and picking up specific programs.

Thanks in advanced!

Share this post


Link to post
Share on other sites



@

Ths is what i found in my au3 box.

Don't ask questions because I am not the author, and don't understand what it is supposed to do.

#include-once

; CRC32 Encryption Function in AutoIt
; by the DtTvB

; Converted from Visual Basic code
; from http://www.di-mgt.com.au/src/basCRC32.txt

global $crcArray[256];
$crcArray[0] = 0x0;
$crcArray[1] = 0x77073096;
$crcArray[2] = 0xEE0E612C;
$crcArray[3] = 0x990951BA;
$crcArray[4] = 0x76DC419;
$crcArray[5] = 0x706AF48F;
$crcArray[6] = 0xE963A535;
$crcArray[7] = 0x9E6495A3;
$crcArray[8] = 0xEDB8832;
$crcArray[9] = 0x79DCB8A4;
$crcArray[10] = 0xE0D5E91E;
$crcArray[11] = 0x97D2D988;
$crcArray[12] = 0x9B64C2B;
$crcArray[13] = 0x7EB17CBD;
$crcArray[14] = 0xE7B82D07;
$crcArray[15] = 0x90BF1D91;
$crcArray[16] = 0x1DB71064;
$crcArray[17] = 0x6AB020F2;
$crcArray[18] = 0xF3B97148;
$crcArray[19] = 0x84BE41DE;
$crcArray[20] = 0x1ADAD47D;
$crcArray[21] = 0x6DDDE4EB;
$crcArray[22] = 0xF4D4B551;
$crcArray[23] = 0x83D385C7;
$crcArray[24] = 0x136C9856;
$crcArray[25] = 0x646BA8C0;
$crcArray[26] = 0xFD62F97A;
$crcArray[27] = 0x8A65C9EC;
$crcArray[28] = 0x14015C4F;
$crcArray[29] = 0x63066CD9;
$crcArray[30] = 0xFA0F3D63;
$crcArray[31] = 0x8D080DF5;
$crcArray[32] = 0x3B6E20C8;
$crcArray[33] = 0x4C69105E;
$crcArray[34] = 0xD56041E4;
$crcArray[35] = 0xA2677172;
$crcArray[36] = 0x3C03E4D1;
$crcArray[37] = 0x4B04D447;
$crcArray[38] = 0xD20D85FD;
$crcArray[39] = 0xA50AB56B;
$crcArray[40] = 0x35B5A8FA;
$crcArray[41] = 0x42B2986C;
$crcArray[42] = 0xDBBBC9D6;
$crcArray[43] = 0xACBCF940;
$crcArray[44] = 0x32D86CE3;
$crcArray[45] = 0x45DF5C75;
$crcArray[46] = 0xDCD60DCF;
$crcArray[47] = 0xABD13D59;
$crcArray[48] = 0x26D930AC;
$crcArray[49] = 0x51DE003A;
$crcArray[50] = 0xC8D75180;
$crcArray[51] = 0xBFD06116;
$crcArray[52] = 0x21B4F4B5;
$crcArray[53] = 0x56B3C423;
$crcArray[54] = 0xCFBA9599;
$crcArray[55] = 0xB8BDA50F;
$crcArray[56] = 0x2802B89E;
$crcArray[57] = 0x5F058808;
$crcArray[58] = 0xC60CD9B2;
$crcArray[59] = 0xB10BE924;
$crcArray[60] = 0x2F6F7C87;
$crcArray[61] = 0x58684C11;
$crcArray[62] = 0xC1611DAB;
$crcArray[63] = 0xB6662D3D;
$crcArray[64] = 0x76DC4190;
$crcArray[65] = 0x1DB7106;
$crcArray[66] = 0x98D220BC;
$crcArray[67] = 0xEFD5102A;
$crcArray[68] = 0x71B18589;
$crcArray[69] = 0x6B6B51F;
$crcArray[70] = 0x9FBFE4A5;
$crcArray[71] = 0xE8B8D433;
$crcArray[72] = 0x7807C9A2;
$crcArray[73] = 0xF00F934;
$crcArray[74] = 0x9609A88E;
$crcArray[75] = 0xE10E9818;
$crcArray[76] = 0x7F6A0DBB;
$crcArray[77] = 0x86D3D2D;
$crcArray[78] = 0x91646C97;
$crcArray[79] = 0xE6635C01;
$crcArray[80] = 0x6B6B51F4;
$crcArray[81] = 0x1C6C6162;
$crcArray[82] = 0x856530D8;
$crcArray[83] = 0xF262004E;
$crcArray[84] = 0x6C0695ED;
$crcArray[85] = 0x1B01A57B;
$crcArray[86] = 0x8208F4C1;
$crcArray[87] = 0xF50FC457;
$crcArray[88] = 0x65B0D9C6;
$crcArray[89] = 0x12B7E950;
$crcArray[90] = 0x8BBEB8EA;
$crcArray[91] = 0xFCB9887C;
$crcArray[92] = 0x62DD1DDF;
$crcArray[93] = 0x15DA2D49;
$crcArray[94] = 0x8CD37CF3;
$crcArray[95] = 0xFBD44C65;
$crcArray[96] = 0x4DB26158;
$crcArray[97] = 0x3AB551CE;
$crcArray[98] = 0xA3BC0074;
$crcArray[99] = 0xD4BB30E2;
$crcArray[100] = 0x4ADFA541;
$crcArray[101] = 0x3DD895D7;
$crcArray[102] = 0xA4D1C46D;
$crcArray[103] = 0xD3D6F4FB;
$crcArray[104] = 0x4369E96A;
$crcArray[105] = 0x346ED9FC;
$crcArray[106] = 0xAD678846;
$crcArray[107] = 0xDA60B8D0;
$crcArray[108] = 0x44042D73;
$crcArray[109] = 0x33031DE5;
$crcArray[110] = 0xAA0A4C5F;
$crcArray[111] = 0xDD0D7CC9;
$crcArray[112] = 0x5005713C;
$crcArray[113] = 0x270241AA;
$crcArray[114] = 0xBE0B1010;
$crcArray[115] = 0xC90C2086;
$crcArray[116] = 0x5768B525;
$crcArray[117] = 0x206F85B3;
$crcArray[118] = 0xB966D409;
$crcArray[119] = 0xCE61E49F;
$crcArray[120] = 0x5EDEF90E;
$crcArray[121] = 0x29D9C998;
$crcArray[122] = 0xB0D09822;
$crcArray[123] = 0xC7D7A8B4;
$crcArray[124] = 0x59B33D17;
$crcArray[125] = 0x2EB40D81;
$crcArray[126] = 0xB7BD5C3B;
$crcArray[127] = 0xC0BA6CAD;
$crcArray[128] = 0xEDB88320;
$crcArray[129] = 0x9ABFB3B6;
$crcArray[130] = 0x3B6E20C;
$crcArray[131] = 0x74B1D29A;
$crcArray[132] = 0xEAD54739;
$crcArray[133] = 0x9DD277AF;
$crcArray[134] = 0x4DB2615;
$crcArray[135] = 0x73DC1683;
$crcArray[136] = 0xE3630B12;
$crcArray[137] = 0x94643B84;
$crcArray[138] = 0xD6D6A3E;
$crcArray[139] = 0x7A6A5AA8;
$crcArray[140] = 0xE40ECF0B;
$crcArray[141] = 0x9309FF9D;
$crcArray[142] = 0xA00AE27;
$crcArray[143] = 0x7D079EB1;
$crcArray[144] = 0xF00F9344;
$crcArray[145] = 0x8708A3D2;
$crcArray[146] = 0x1E01F268;
$crcArray[147] = 0x6906C2FE;
$crcArray[148] = 0xF762575D;
$crcArray[149] = 0x806567CB;
$crcArray[150] = 0x196C3671;
$crcArray[151] = 0x6E6B06E7;
$crcArray[152] = 0xFED41B76;
$crcArray[153] = 0x89D32BE0;
$crcArray[154] = 0x10DA7A5A;
$crcArray[155] = 0x67DD4ACC;
$crcArray[156] = 0xF9B9DF6F;
$crcArray[157] = 0x8EBEEFF9;
$crcArray[158] = 0x17B7BE43;
$crcArray[159] = 0x60B08ED5;
$crcArray[160] = 0xD6D6A3E8;
$crcArray[161] = 0xA1D1937E;
$crcArray[162] = 0x38D8C2C4;
$crcArray[163] = 0x4FDFF252;
$crcArray[164] = 0xD1BB67F1;
$crcArray[165] = 0xA6BC5767;
$crcArray[166] = 0x3FB506DD;
$crcArray[167] = 0x48B2364B;
$crcArray[168] = 0xD80D2BDA;
$crcArray[169] = 0xAF0A1B4C;
$crcArray[170] = 0x36034AF6;
$crcArray[171] = 0x41047A60;
$crcArray[172] = 0xDF60EFC3;
$crcArray[173] = 0xA867DF55;
$crcArray[174] = 0x316E8EEF;
$crcArray[175] = 0x4669BE79;
$crcArray[176] = 0xCB61B38C;
$crcArray[177] = 0xBC66831A;
$crcArray[178] = 0x256FD2A0;
$crcArray[179] = 0x5268E236;
$crcArray[180] = 0xCC0C7795;
$crcArray[181] = 0xBB0B4703;
$crcArray[182] = 0x220216B9;
$crcArray[183] = 0x5505262F;
$crcArray[184] = 0xC5BA3BBE;
$crcArray[185] = 0xB2BD0B28;
$crcArray[186] = 0x2BB45A92;
$crcArray[187] = 0x5CB36A04;
$crcArray[188] = 0xC2D7FFA7;
$crcArray[189] = 0xB5D0CF31;
$crcArray[190] = 0x2CD99E8B;
$crcArray[191] = 0x5BDEAE1D;
$crcArray[192] = 0x9B64C2B0;
$crcArray[193] = 0xEC63F226;
$crcArray[194] = 0x756AA39C;
$crcArray[195] = 0x26D930A;
$crcArray[196] = 0x9C0906A9;
$crcArray[197] = 0xEB0E363F;
$crcArray[198] = 0x72076785;
$crcArray[199] = 0x5005713;
$crcArray[200] = 0x95BF4A82;
$crcArray[201] = 0xE2B87A14;
$crcArray[202] = 0x7BB12BAE;
$crcArray[203] = 0xCB61B38;
$crcArray[204] = 0x92D28E9B;
$crcArray[205] = 0xE5D5BE0D;
$crcArray[206] = 0x7CDCEFB7;
$crcArray[207] = 0xBDBDF21;
$crcArray[208] = 0x86D3D2D4;
$crcArray[209] = 0xF1D4E242;
$crcArray[210] = 0x68DDB3F8;
$crcArray[211] = 0x1FDA836E;
$crcArray[212] = 0x81BE16CD;
$crcArray[213] = 0xF6B9265B;
$crcArray[214] = 0x6FB077E1;
$crcArray[215] = 0x18B74777;
$crcArray[216] = 0x88085AE6;
$crcArray[217] = 0xFF0F6A70;
$crcArray[218] = 0x66063BCA;
$crcArray[219] = 0x11010B5C;
$crcArray[220] = 0x8F659EFF;
$crcArray[221] = 0xF862AE69;
$crcArray[222] = 0x616BFFD3;
$crcArray[223] = 0x166CCF45;
$crcArray[224] = 0xA00AE278;
$crcArray[225] = 0xD70DD2EE;
$crcArray[226] = 0x4E048354;
$crcArray[227] = 0x3903B3C2;
$crcArray[228] = 0xA7672661;
$crcArray[229] = 0xD06016F7;
$crcArray[230] = 0x4969474D;
$crcArray[231] = 0x3E6E77DB;
$crcArray[232] = 0xAED16A4A;
$crcArray[233] = 0xD9D65ADC;
$crcArray[234] = 0x40DF0B66;
$crcArray[235] = 0x37D83BF0;
$crcArray[236] = 0xA9BCAE53;
$crcArray[237] = 0xDEBB9EC5;
$crcArray[238] = 0x47B2CF7F;
$crcArray[239] = 0x30B5FFE9;
$crcArray[240] = 0xBDBDF21C;
$crcArray[241] = 0xCABAC28A;
$crcArray[242] = 0x53B39330;
$crcArray[243] = 0x24B4A3A6;
$crcArray[244] = 0xBAD03605;
$crcArray[245] = 0xCDD70693;
$crcArray[246] = 0x54DE5729;
$crcArray[247] = 0x23D967BF;
$crcArray[248] = 0xB3667A2E;
$crcArray[249] = 0xC4614AB8;
$crcArray[250] = 0x5D681B02;
$crcArray[251] = 0x2A6F2B94;
$crcArray[252] = 0xB40BBE37;
$crcArray[253] = 0xC30C8EA1;
$crcArray[254] = 0x5A05DF1B;
$crcArray[255] = 0x2D02EF8D;

func sr8($x);
    local $n;
    $n = floor(bitAnd($x, 0x7fffffff) / 256);
    if (not(bitAnd($x, 0x80000000) = 0)) then;
        $n = bitOr($n, 0x800000);
    endIf;
    return $n;
endFunc;

func _convCRC32($data);
    local $crc, $i, $t, $c, $a, $l;
    $crc = 0xffffffff;
    $l = stringLen($data);
    for $i = 1 to $l;
        $c = asc(stringMid($data, $i, 1));
        $t = bitXor(bitAnd($crc, 0xff), $c);
        $a = sr8($crc);
        $crc = bitXor($a, $crcArray[$t]);
    next;
    return bitXor($crc, 0xffffffff);
endFunc;

regards

ptrex

Share this post


Link to post
Share on other sites

Thanks for the replies. Ok, taking a look at that link, I'm kind of urging onto using file md5 hashes, as I'm not going to be able to work with crc32, seems to much work <_<

Share this post


Link to post
Share on other sites

As far as generating the a file for crc32, I have no clue, but I can help you generate a hex string for crc32:

Func Crc32($pData)
    Local $crc32tab[256] = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D]
    Local $pCrc32 = 0xFFFFFFFF, $i = 0
    
    For $i = 1 To BinaryLen($pData)
        $pCrc32 = BitXOR(BitShift($pCrc32,8),$crc32tab[BitXOR(BinaryMid($pData,$i,1),BitAND($pCrc32,0x000000FF))])
    Next
    $pCrc32 = BitNOT($pCrc32)
    
    Return Hex($pCrc32)
EndFunc

I didn't understand ptrex's functions, but the above was translated from the rehash project source code found on sourceforge.net. I tested it to the best of my abilities, and it seems to work as intended. I coded it with Binary info because whether you pass in a string or binary, binary functions will work on it, but String functions don't like to work with Binary datatypes correctly (I think, been awhile).

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@all

I changed it for readability and added an example cfr. the CRC16 example.

Dim $avTest[5] = ["Test line 1.", "abcdefghijklmnopqrstuvwxyz01234567890", 0xFEDCBA98, "", StringToBinary("Binary test.")]
$sMsg = ""
For $n = 0 To UBound($avTest) - 1
    $sMsg &= $avTest[$n] & " CRC32 = " & Crc32($avTest[$n]) & @CRLF
Next
MsgBox(64, "StringCrc16 Test", $sMsg)


Func Crc32($pData)
    Local $crc32tab[256] = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, _
    0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, _ 
    0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, _ 
    0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, _ 
    0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, _ 
    0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, _ 
    0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, _ 
    0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, _ 
    0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, _
    0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, _
    0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, _
    0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, _
    0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, _
    0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, _
    0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, _
    0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, _
    0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, _
    0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, _
    0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, _
    0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, _
    0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, _
    0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, _
    0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, _
    0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, _
    0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, _
    0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, _
    0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, _
    0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, _
    0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, _
    0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, _
    0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, _
    0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, _
    0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, _
    0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, _
    0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, _
    0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, _
    0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D]
    
    Local $pCrc32 = 0xFFFFFFFF, $i = 0
    
    For $i = 1 To BinaryLen($pData)
        $pCrc32 = BitXOR(BitShift($pCrc32,8),$crc32tab[BitXOR(BinaryMid($pData,$i,1),BitAND($pCrc32,0x000000FF))])
    Next
    $pCrc32 = BitNOT($pCrc32)
    
    Return Hex($pCrc32)
EndFunc

Regards,

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites

I've had this for quite some time.

It generates the crc table on startup instead of having to hardcode it.

;converted from http://www.vbforums.com/showthread.php?t=412922
#include <GUIConstants.au3>
Global $pInititialized
Global $pTable[256]

$Form1 = GUICreate("CRC32", 403, 239, 209, 164)
$FilePath = GUICtrlCreateInput("C:\Program Files\AutoIt3\Au3Info.exe", 6, 32, 347, 21)
;$FilePath = GUICtrlCreateInput("c:\Python25\shelve\workon\kjv.txt", 6, 32, 347, 21)
$Browse = GUICtrlCreateButton("...", 360, 32, 28, 22, 0)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$GetCRC = GUICtrlCreateButton("Generate CRC32", 98, 61, 193, 33, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Group1 = GUICtrlCreateGroup("Results:", 9, 98, 384, 127)
$FileSize = GUICtrlCreateLabel("", 70, 122, 315, 17, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$FileCRC = GUICtrlCreateLabel("", 70, 145, 315, 17, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$TotTime = GUICtrlCreateLabel("", 70, 168, 315, 17, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Label5 = GUICtrlCreateLabel("File Size:", 20, 122, 46, 17)
$Label6 = GUICtrlCreateLabel("CRC32:", 20, 145, 41, 17)
$Label7 = GUICtrlCreateLabel("Time:", 20, 168, 30, 17)
$Progress1 = GuiCtrlCreateProgress(20,195,365,17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label4 = GUICtrlCreateLabel("File Name:", 6, 8, 54, 17)
GUISetState(@SW_SHOW)

crcInit()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browse
            GUICtrlSetData($FilePath, FileOpenDialog("Select File", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All Files (*.*)", 1))
        Case $GetCRC
            If FileExists(GUICtrlRead($FilePath)) Then
                if (StringInStr(FileGetAttrib(GUICtrlRead($FilePath)), "D")) Then
                    MsgBox(266288, "CRC", "Please Select a file instead of a folder.")
                Else
                    $timer = TimerInit()
                    GUICtrlSetData($FileSize, FileGetSize(GUICtrlRead($FilePath)))
                    GUICtrlSetData($FileCRC, "")
                    GUICtrlSetData($TotTime, "")
                    
                    GUICtrlSetData($FileCRC, crc32File(GUICtrlRead($FilePath)))
                    GUICtrlSetData($TotTime, _TicksToTime(TimerDiff($timer)))
                EndIf
            EndIf
    EndSwitch
    If GUICtrlRead($FilePath) <> "" Then
        If BitAND(GUICtrlGetState($GetCRC), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($GetCRC, $GUI_ENABLE)
    Else
        If BitAND(GUICtrlGetState($GetCRC), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($GetCRC, $GUI_DISABLE)
    EndIf
WEnd


Func crcInit($Poly = 0xEDB88320)
    Local $crc
    Local $i
    Local $j
    For $i = 0 To 255
        $crc = $i
        For $j = 0 To 7
            If BitAND($crc, 0x1) Then
                $crc = BitXOR(BitAND(BitAND($crc, 0xFFFFFFFE) / 0x2, 0x7FFFFFFF), $Poly)
            Else
                $crc = BitAND(($crc / 0x2), 0x7FFFFFFF)
            EndIf
        Next
        $pTable[$i] = $crc
    Next
    $pInititialized = 1
EndFunc   ;==>crcInit

Func crc32File($Path)
    Local $Buffer
    Local $BufferSize
    Local $crc
    Local $FileNr
    Local $Length
    Local $i
    If Not $pInititialized Then crcInit()
    $FileLen = FileGetSize($Path)
    $Length = $FileLen
    $BufferSize = 1024 * 32 ;'32 KB
    If $Length < $BufferSize Then $BufferSize = $Length
    $ReadStruct = DllStructCreate("byte[" & $BufferSize & "]")
    $FileNr = FileOpen($Path, 0)
    Local $Progress = $Length
    $crc = 0xFFFFFFFF
    Local $TotalProgress = 0
    GuiCtrlSetData($Progress1,0)
    While $Length
        If $Length < $BufferSize Then
            $BufferSize = $Length
        EndIf
        DllStructSetData($ReadStruct, 1, FileRead($FileNr, $BufferSize))
        For $i = 1 To $BufferSize
            $Buffer = (DllStructGetData($ReadStruct, 1, $i))
            $crc = BitXOR(BitAND((BitAND($crc, 0xFFFFFF00) / 0x100), 0xFFFFFF) , ($pTable[BitAND(BitXOR($Buffer, $crc), 0xFF) ]))
        Next
        $Length = $Length - $BufferSize
        $TotalProgress = $TotalProgress + $BufferSize
        GuiCtrlSetData($Progress1,Int(100* (($TotalProgress + $i) / $Progress)))
    WEnd
    $ReadStruct = 0
    FileClose($FileNr)
    Return Hex(BitNOT($crc), 8)
EndFunc   ;==>crc32File

;===============================================================================
;
; Description:      Converts the specified tick amount to hours, minutes, and
;                   seconds.
; Parameter(s):     $iTicks - Tick amount
;
; Requirement(s):   None
; Return Value(s):  On Success Array of times
;                   On Failure - 0 and sets @ERROR = 1
; Author(s):        Marc <mrd at gmx de>
;                    This version modified by eltorro gehossafats at netmdc dot com
; Note(s):          None
;
;===============================================================================
Func _TicksToTime($iTicks)
    If Number($iTicks) > 0 Then
        $iTicks = Round($iTicks / 1000)
        Local $iHours = Int($iTicks / 3600)
        $iTicks = Mod($iTicks, 3600)
        Local $iMins = Int($iTicks / 60)
        Local $iSecs = Round(Mod($iTicks, 60))
        ; If $iHours = 0 then $iHours = 24
        Return StringFormat("%02i:%02i:%02i", $iHours, $iMins, $iSecs)
    Else
        SetError(1)
        Return ""
    EndIf
EndFunc   ;==>_TicksToTime

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0