Ich bin jetzt soweit, dass es funktioniert. Nur von Char auf Byte habe ich noch nicht umgestellt, da das irgendwie nicht klappt.
Delphi-Quellcode:
// Calculate the hash of a files content and append it to the file
aFileStream := TFileStream.Create(sFile, fmOpenReadWrite or fmShareDenyNone);
try
aFileStream.Position := 0;
SetLength(s, aFileStream.Size);
aFileStream.Read(s[1], Length(s));
// hash berechnen
aFileStream.Position := aFileStream.Size;
aFileStream.Write(s[1], Length(s) * SizeOf(Char));
finally
aFileStream.Free;
end;
Delphi-Quellcode:
aFileStream := TFileStream.Create(sFile, fmOpenRead or fmShareDenyWrite);
try
// Get the hash of the original file content (without the hash we appended before)
aFileStream.Position := 0;
SetLength(s, aFileStream.Size - (32 * SizeOf(Char)));
aFileStream.Read(s[1], Length(s));
// hash berechnen
// Get hash from stream end
SetLength(sOut, 32 * SizeOf(Char));
aFileStream.Position := aFileStream.Size - Length(sOut);
aFileStream.Read(sOut[1], Length(sOut));
finally
aFileStream.Free;
end;