| 1100 | |
| 1101 | == MASM == |
| 1102 | {{{ |
| 1103 | Calc_Hash proc uses esi ebx edx pFile:dword, pBuf:dword |
| 1104 | |
| 1105 | LOCAL hFile:dword, fSize:dword, NBR:dword, pMem:dword |
| 1106 | |
| 1107 | invoke CreateFile,pFile,GENERIC_ALL,0,0,OPEN_EXISTING,0,0 |
| 1108 | mov hFile,eax |
| 1109 | cmp eax,INVALID_HANDLE_VALUE |
| 1110 | jz @Error |
| 1111 | |
| 1112 | invoke SetFilePointer,hFile,0,NULL,FILE_END |
| 1113 | mov fSize,eax |
| 1114 | push eax |
| 1115 | |
| 1116 | invoke GlobalAlloc,GPTR,131072 |
| 1117 | mov pMem,eax |
| 1118 | |
| 1119 | invoke SetFilePointer,hFile,0,NULL,FILE_BEGIN |
| 1120 | invoke ReadFile,hFile,pMem,65536,addr NBR,NULL |
| 1121 | |
| 1122 | sub fSize,65536 |
| 1123 | add pMem,65536 |
| 1124 | |
| 1125 | invoke SetFilePointer,hFile,fSize,NULL,FILE_BEGIN |
| 1126 | invoke ReadFile,hFile,pMem,65536,addr NBR,NULL |
| 1127 | |
| 1128 | sub pMem,65536 |
| 1129 | mov esi,pMem |
| 1130 | mov ecx,131072 |
| 1131 | pop eax |
| 1132 | mov edx,eax |
| 1133 | push eax |
| 1134 | |
| 1135 | @@: |
| 1136 | add edx,[esi] |
| 1137 | adc ebx,[esi+4] |
| 1138 | add esi,8 |
| 1139 | sub ecx,8 |
| 1140 | jnz @B |
| 1141 | |
| 1142 | push edx |
| 1143 | push ebx |
| 1144 | invoke wsprintf,pBuf,addr HashFormat |
| 1145 | pop eax |
| 1146 | pop eax |
| 1147 | |
| 1148 | invoke CloseHandle,hFile |
| 1149 | invoke GlobalFree,pMem |
| 1150 | pop ecx |
| 1151 | |
| 1152 | @Error: ; If error eax returns (INVALID_HANDLE_VALUE) |
| 1153 | |
| 1154 | ; Hash value is copied to pBuf |
| 1155 | ; eax returns Movie Filesize |
| 1156 | |
| 1157 | ret |
| 1158 | |
| 1159 | Calc_Hash endp |
| 1160 | }}} |