Hier ist eine Klasse dich ich von C# nach Vb.Net übersetzt und modifiziert habe. Sie berechnet die Adler32-Checksumme eines Buffers oder Streams.
Hier ein kleines beispiel wie man die Manifest-Checksumme einer GCF Datei berechnet:
Copyright: © 1999, 2000, 2001 Free Software Foundation, Inc. © 2001 Mike Krueger
Translation and modification: Me (rAzoR8)
Source: koders.com/csharp/fid630960EA3…CC79915FB359B62788D3.aspx
VB.NET-Quellcode
- Public Class Adler32
- Private Const Base As Integer = 65521
- Private _Checksum As Long
- Public ReadOnly Property Checksum() As Long
- Get
- Return _Checksum
- End Get
- End Property
- Public Sub New()
- _Checksum = 0
- End Sub
- Public Sub Clear()
- _Checksum = 0
- End Sub
- Public Sub Update(ByVal value As Integer)
- Dim s1 As UInt32 = _Checksum And &HFFFF
- Dim s2 As UInt32 = _Checksum >> 16
- s1 = (s1 + (CUInt(value) And &HFF)) Mod Base
- s2 = (s1 + s2) Mod Base
- _Checksum = (s2 << 16) + s1
- End Sub
- Public Sub Update(ByVal buffer As Byte(), ByVal offset As UInt32, ByVal count As Integer)
- If buffer Is Nothing Then
- Throw New ArgumentNullException("Buffer")
- End If
- If count < 0 Then
- Throw New ArgumentOutOfRangeException("Count", "cannot be negative")
- End If
- If offset + count > buffer.Length Then
- Throw New ArgumentOutOfRangeException("Offset AndOr Count")
- End If
- Dim s1 As UInt32 = _Checksum And &HFFFF
- Dim s2 As UInt32 = _Checksum >> 16
- While count > 0
- Dim n As Integer = 3800
- If n > count Then
- n = count
- End If
- count -= n
- n -= 1
- While n >= 0
- s1 = s1 + CUInt(buffer(offset) And &HFF)
- s2 = s2 + s1
- offset += 1
- n -= 1
- End While
- s1 = s1 Mod Base
- s2 = s2 Mod Base
- End While
- _Checksum = (s2 << 16) Or s1
- End Sub
- Public Sub Update(ByVal Stream As FileStream, ByVal count As Integer)
- If Stream Is Nothing Then
- Throw New ArgumentNullException("Buffer")
- End If
- If count < 0 Then
- Throw New ArgumentOutOfRangeException("Count", "cannot be negative")
- End If
- If Stream.Position + count > Stream.Length Then
- Throw New ArgumentOutOfRangeException("Offset AndOr Count")
- End If
- Dim s1 As UInt32 = _Checksum And &HFFFF
- Dim s2 As UInt32 = _Checksum >> 16
- While count > 0
- Dim n As Integer = 3800
- If n > count Then
- n = count
- End If
- count -= n
- n -= 1
- While n >= 0
- s1 = s1 + CUInt(Stream.ReadByte() And &HFF)
- s2 = s2 + s1
- n -= 1
- End While
- s1 = s1 Mod Base
- s2 = s2 Mod Base
- End While
- _Checksum = (s2 << 16) Or s1
- End Sub
- End Class
Hier ein kleines beispiel wie man die Manifest-Checksumme einer GCF Datei berechnet:
Copyright: © 1999, 2000, 2001 Free Software Foundation, Inc. © 2001 Mike Krueger
Translation and modification: Me (rAzoR8)
Source: koders.com/csharp/fid630960EA3…CC79915FB359B62788D3.aspx
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „razor8“ ()