Changes between Version 38 and Version 39 of HashSourceCodes


Ignore:
Timestamp:
Feb 6, 2013, 6:19:21 AM (11 years ago)
Author:
os
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HashSourceCodes

    v38 v39  
    13751375}}}
    13761376Build with: valac --pkg gio-2.0 hash.vala
     1377
     1378== AutoHotKey ==
     1379{{{
     1380#NoEnv
     1381SetBatchLines, -1
     1382; http://www.opensubti.../breakdance.avi
     1383; OpenSubtitles Hash = 8E245D9679D31E12
     1384FilePath := "Breakdance.avi"
     1385MsgBox, 0, OpenSubtitlesHash, % Filepath . ":`r`n" . GetOpenSubtitlesHash(FilePath)
     1386ExitApp
     1387
     1388
     1389; ==================================================================================================
     1390GetOpenSubtitlesHash(FilePath) {
     1391   ; http://trac.opensubt...HashSourceCodes
     1392   Static X := { 0: "0",  1: "1",  2: "2",  3: "3",  4: "4",  5: "5",  6: "6",  7: "7"
     1393              ,  8: "8",  9: "9", 10: "A", 11: "B", 12: "C", 13: "D", 14: "E", 15: "F"}
     1394   ; Check the file size ---------------------------------------------------------------------------
     1395   ; 9000000000 > $moviebytesize >= 131072 bytes (changed > to  >= for the lower limit)
     1396   FileGetSize, FileSize, %FilePath%
     1397   If (FileSize < 131072) || (FileSize >= 9000000000)
     1398      Return ""
     1399   ; Read the first and last 64 KB -----------------------------------------------------------------
     1400   VarSetCapacity(FileParts, 131072)         ; allocate sufficient memory
     1401   File := FileOpen(FilePath, "r")           ; open the file
     1402   File.Seek(0, 0)                           ; set the file pointer (just for balance)
     1403   File.RawRead(FileParts, 65536)            ; read the first 64 KB
     1404   File.Seek(-65536, 2)                      ; set the file pointer for the last 64 KB
     1405   File.RawRead(&FileParts + 65536, 65536)   ; read the last 64 KB
     1406   File.Close()                              ; got all we need, so the file can be closed
     1407   ; Now calculate the hash using two UINTs for the low- and high-order parts of an UINT64 ---------
     1408   LoUINT := FileSize & 0xFFFFFFFF           ; store low-order UINT of file size
     1409   HiUINT := FileSize >> 32                  ; store high-order UINT of file size
     1410   Offset := -4                              ; to allow adding 4 on first iteration
     1411   Loop, 16384 {                             ; 131072 / 8
     1412      LoUINT += NumGet(FileParts, Offset += 4, "UInt") ; add first UINT value to low-order UINT
     1413      HiUINT += NumGet(FileParts, Offset += 4, "UInt") ; add second UINT value to high-order UINT
     1414   }
     1415   ; Adjust the probable overflow of the low-order UINT
     1416   HiUINT += LoUINT >> 32                    ; add the overflow to the high-order UINT
     1417   LoUINT &= 0xFFFFFFFF                      ; remove the overflow from the low-order UINT
     1418   ; Now get the hex string, i.e. the hash ---------------------------------------------------------
     1419   Hash := ""
     1420   VarSetCapacity(UINT64, 8, 0)
     1421   NumPut((HiUINT << 32) | LoUINT, UINT64, 0, "UInt64")
     1422   Loop, 8
     1423      Hash .= X[(Byte := NumGet(UINT64, 8 - A_Index, "UChar")) >> 4] . X[Byte & 0x0F]
     1424   Return Hash
     1425}
     1426; ==================================================================================================
     1427}}}