تقييم الموضوع :
  • 1 أصوات - بمعدل 5
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] كيفية التعديل على قيمه معينه داخل ملف هيكس
#20
(21-05-14, 12:55 AM)vbnet كتب : -
بالنسبة لـ CRC32

منقول

هذا كلاس CrcStream
كود :
Imports System.IO

''' <summary>
''' Encapsulates a <see cref="System.IO.Stream" /> to calculate the CRC32 checksum on-the-fly as data passes through.
''' </summary>
Public Class CrcStream
    Inherits Stream
    ''' <summary>
    ''' Encapsulate a <see cref="System.IO.Stream" />.
    ''' </summary>
    ''' <param name="stream">The stream to calculate the checksum for.</param>
    Public Sub New(ByVal stream As Stream)
        Me.m_stream = stream
    End Sub

    Private m_stream As Stream

    ''' <summary>
    ''' Gets the underlying stream.
    ''' </summary>
    Public ReadOnly Property Stream() As Stream
        Get
            Return m_stream
        End Get
    End Property

    Public Overrides ReadOnly Property CanRead() As Boolean
        Get
            Return m_stream.CanRead
        End Get
    End Property

    Public Overrides ReadOnly Property CanSeek() As Boolean
        Get
            Return m_stream.CanSeek
        End Get
    End Property

    Public Overrides ReadOnly Property CanWrite() As Boolean
        Get
            Return m_stream.CanWrite
        End Get
    End Property

    Public Overrides Sub Flush()
        m_stream.Flush()
    End Sub

    Public Overrides ReadOnly Property Length() As Long
        Get
            Return m_stream.Length
        End Get
    End Property

    Public Overrides Property Position() As Long
        Get
            Return m_stream.Position
        End Get
        Set(ByVal value As Long)
            m_stream.Position = value
        End Set
    End Property

    Public Overrides Function Seek(ByVal offset As Long, ByVal origin As SeekOrigin) As Long
        Return m_stream.Seek(offset, origin)
    End Function

    Public Overrides Sub SetLength(ByVal value As Long)
        m_stream.SetLength(value)
    End Sub

    Public Overrides Function Read(ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer) As Integer
        count = m_stream.Read(buffer, offset, count)
        m_readCrc = CalculateCrc(m_readCrc, buffer, offset, count)
        Return count
    End Function

    Public Overrides Sub Write(ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer)
        m_stream.Write(buffer, offset, count)

        m_writeCrc = CalculateCrc(m_writeCrc, buffer, offset, count)
    End Sub

    Private Function CalculateCrc(ByVal crc As UInteger, ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer) As UInteger
        Dim i As Integer = offset, [end] As Integer = offset + count
        While i < [end]
            crc = (crc >> 8) Xor table((crc Xor buffer(i)) And &HFF)
            i += 1
        End While

        Return crc
    End Function

    Private Shared table As UInteger() = GenerateTable()

    Private Shared Function GenerateTable() As UInteger()
        Dim table As UInteger() = New UInteger(255) {}

        Dim crc As UInteger
        Const poly As UInteger = &HEDB88320UI
        For i As UInteger = 0 To table.Length - 1
            crc = i
            For j As Integer = 8 To 1 Step -1
                If (crc And 1) = 1 Then
                    crc = (crc >> 1) Xor poly
                Else
                    crc >>= 1
                End If
            Next
            table(i) = crc
        Next

        Return table


    End Function

    Private m_readCrc As UInteger = &HFFFFFFFFUI

    ''' <summary>
    ''' Gets the CRC checksum of the data that was read by the stream thus far.
    ''' </summary>
    Public ReadOnly Property ReadCrc() As UInteger
        Get
            Return m_readCrc Xor &HFFFFFFFFUI
        End Get
    End Property

    Private m_writeCrc As UInteger = &HFFFFFFFFUI

    ''' <summary>
    ''' Gets the CRC checksum of the data that was written to the stream thus far.
    ''' </summary>
    Public ReadOnly Property WriteCrc() As UInteger
        Get
            Return m_writeCrc Xor &HFFFFFFFFUI
        End Get
    End Property

    ''' <summary>
    ''' Resets the read and write checksums.
    ''' </summary>
    Public Sub ResetChecksum()
        m_readCrc = &HFFFFFFFFUI
        m_writeCrc = &HFFFFFFFFUI
    End Sub

End Class

طريقة استخدامه
كود :
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Open a file stream, encapsulate it in CrcStream
        Dim file As New IO.FileStream("C:\test.exe", IO.FileMode.Open)
        Dim stream As New CrcStream(file)

        'Use the file somehow -- in this case, read it as a string
        Dim reader As New IO.StreamReader(stream)
        Dim text As String = reader.ReadToEnd()

        'Print the checksum
        MessageBox.Show("CRC: " & stream.ReadCrc.ToString("X8"))

    End Sub

End Class

المصدر (CrcStream stream checksum calculator)

تمام يا اخي ولكن عندما اضغط على الزر يظهر ال CRC تمام ولكن لمذا لا يقوم بتغييره في هيدر الملف اي انه لا يكتب في الأسطر اللذي وضحتها
يظهر الرسالة فقط


ولكن لا يغير الظاهر في الرسالة في الرقام الموجوده في هذه الصفحة في المكان المحدد
يعني يفضل لو الظاهر في الرسالة يكتب بالأرقام في هذه المنطقة واسف اني تعبتك معايا
ولك مني كل الحب والتقدير اخي

انتظر منك الرد في القريب العاجل
وشكرالك ولمجهودتك وجعله الله في ميزان حسناتك
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
RE: كيفية التعديل على قيمه معينه داخل ملف هيكس - بواسطة محمديات - 21-05-14, 07:21 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيفية منع ظهور الأخطاء من إعدادات البيسيك mmaalmesry 2 851 29-08-25, 10:30 AM
آخر رد: mmaalmesry
  [سؤال] طريقة توسيط النص داخل اداة comboBox سمير1404 7 3,860 24-08-25, 01:01 PM
آخر رد: أبو خالد الشكري
  كيفية جلب أسماء الأعمدة بجدول من جداول sql heem1986 2 747 17-08-25, 09:15 PM
آخر رد: heem1986
  كيفية حفظ إعدادات البرنامج بحيث لا تتغير أحمد إبراهيم سعد 4 3,004 06-08-25, 06:34 PM
آخر رد: Taha Okla
  مساعدة في كيفية ترحيل البيانات من داتا قريدفيو إلى داتا قريدفيو في فيجوال بيسك ahmedfa71 13 2,246 09-07-25, 11:24 PM
آخر رد: أبو خالد الشكري
  كيفية احتساب الفرق بين تاريخين بناء على عدد معين مصمم هاوي 2 554 15-01-25, 02:02 PM
آخر رد: مصمم هاوي
  كيفية التعامل مع inputbox في فيجوال ستوديو أسامة حسين 4 3,506 14-01-25, 02:04 AM
آخر رد: أبو خالد الشكري
  استدعاء من جدولين داخل اداه FlowLayoutPanel برجاء الافادة للضرورة جداً modymody300894 7 638 15-11-24, 11:02 AM
آخر رد: modymody300894
  كيفية معرفة الجهاز رئيسي ام فرعي المتألق9 1 398 13-11-24, 06:41 PM
آخر رد: justforit
  كتابه عدد معين من الارقام داخل تيكست بوكس modymody300894 3 559 07-11-24, 09:15 PM
آخر رد: modymody300894

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم