تقييم الموضوع :
  • 1 أصوات - بمعدل 5
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] كيفية التعديل على قيمه معينه داخل ملف هيكس
#11
تفضل أخي، استبدال صف بدل صف آخر وكود Check Sum قبل وبعد التعديل Smile

كود :
Imports System.Security.Cryptography

Dim MyFileStream As IO.FileStream = Nothing

Try
    'تعريف مسار الملف
    MyFileStream = New IO.FileStream("D:\test.exe", IO.FileMode.Open, IO.FileAccess.ReadWrite)

    'كود التحقق قبل التعديل على الملف
    Using CheckSum As MD5 = MD5.Create()
        Dim Result As String = BitConverter.ToString(CheckSum.ComputeHash(MyFileStream)).Replace("-", "")
        MessageBox.Show("MD5 before edit: " & vbCr & Result, "MD5", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Using

    'تعريف مصفوفتين من البايت عدد عناصرهما 16
    Dim Buffer1(15) As Byte
    Dim Buffer2(15) As Byte

    'الانتقال إلى الصف الثالث وعنوانه 00
    MyFileStream.Seek(&H0, IO.SeekOrigin.Begin)

    'قرائة الصف الأول وهو مكون من 16 بايت
    MyFileStream.Read(Buffer1, 0, Buffer1.Length)

    'الانتقال إلى الصف الثالث وعنوانه 30
    MyFileStream.Seek(&H30, IO.SeekOrigin.Begin)

    'قرائة الصف الثالث وهو مكون من 16 بايت
    MyFileStream.Read(Buffer2, 0, Buffer2.Length)

    'الانتقال إلى الصف الأول وعنوانه 00
    MyFileStream.Seek(&H0, IO.SeekOrigin.Begin)
    'استبدال الصف الأول بالثالث
    MyFileStream.Write(Buffer2, 0, Buffer2.Length)

    'الانتقال إلى الصف الثالث وعنوانه 30
    MyFileStream.Seek(&H30, IO.SeekOrigin.Begin)
    'استبدال الصف الثالث بالأول
    MyFileStream.Write(Buffer1, 0, Buffer2.Length)

    'الانتقال لبداية الملف
    MyFileStream.Seek(&H0, IO.SeekOrigin.Begin)

    'كود التحقق بعد التعديل على الملف
    Using CheckSum As MD5 = MD5.Create()
        Dim Result As String = BitConverter.ToString(CheckSum.ComputeHash(MyFileStream)).Replace("-", "")
        MessageBox.Show("MD5 after edit: " & vbCr & Result, "MD5", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Using

Finally
    If MyFileStream IsNot Nothing Then MyFileStream.Close()
End Try
الرد }}}
تم الشكر بواسطة: محمديات
#12
شكرا شكرا على المساعده وكن اخي الكريم ال Check sum هنا يظهر كرساله فقط ولا يغير في ال Check sum الخاص بالملف نفسه اريده يغير في check sum الملف نفسه يعني بعد ما يطلع الناتج بعد يبدأ بالتغيير في الملف نفسه وانتظر الرد
وجعل الله هذا العمل في ميزان حسناتك
الرد }}}
تم الشكر بواسطة:
#13
(19-05-14, 02:56 PM)محمديات كتب : شكرا شكرا على المساعده وكن اخي الكريم ال Check sum هنا يظهر كرساله فقط ولا يغير في ال Check sum الخاص بالملف نفسه اريده يغير في check sum الملف نفسه يعني بعد ما يطلع الناتج بعد يبدأ بالتغيير في الملف نفسه وانتظر الرد
وجعل الله هذا العمل في ميزان حسناتك

يا أخ محمديات ممكن توضيح أكثر بخصوص Check Sum !
مع العلم أن Check Sum لن تتغير للملف إلا إذا تم التعديل عليه وأنا أوضحت هذا الشيء في الكود بحيث يظهر لك Check Sum للملف قبل التعديل وبعد التعديل
الرد }}}
تم الشكر بواسطة: محمديات
#14

ال CHECK SUM المفروض بيغير القيم ده بس يعني لو عدلنا على الملف مثلا في الهيكس 34 وجعلناه ff مثلا
فأن ال ال CHECK SUM
هوه اللي هيتغير في المكان المشار اليه اللي اشارت عليها في الصورة السابقة لكن كود الذي كتبته اخي كان فقط يخرج رسالة بأن ال check sum اتغير ولكن لا يقوم بالتغير في هيدر الملف ليتناسق ويتناسب بين المحتوى والهيدر وياريت لو
توضح ايضا لي كيف أقوم بالبحث عن 6 قيم بجوار بعضهم داخل ملف الهيكس وعند وجود هذه القيم يقوم بتغيير مثلا القيمه الخامسه وانا موضحها في الصورة التالية ان عندما يجد هذه القيم بجوار بعضها يقوم بتغيير القيمه اللي عليها الدائرة الحمراء بالرقم الذي اسفل الدائرة الموجود في الصورة



الرد }}}
تم الشكر بواسطة:
#15
بالنسبة لـ Check Sum
هو الملف مخزن في بدايته Check Sum وما نوع هذا Check Sum ؟
الرد }}}
تم الشكر بواسطة: محمديات
#16
هاشوف نوع ال Check sum
ولكن ياريت لو حضرتك تجهز لي هذا الكود الخاص بالطلب هذا

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



الرد }}}
تم الشكر بواسطة:
#17
نوع ال check sum
Crt 32
الرد }}}
تم الشكر بواسطة:
#18
-
بالنسبة لـ 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)
الرد }}}
تم الشكر بواسطة: محمديات
#19
تفضل أخي، هذا بالنسبة للبحث عن 3 قم واستبدال القيمة الثالثة

كود :
Dim MyFileStream As IO.FileStream = Nothing

Try
    'تعريف مسار الملف
    MyFileStream = New IO.FileStream("D:\test.exe", IO.FileMode.Open, IO.FileAccess.ReadWrite)

    'مصفوفة من البايت بحجم الملف
    Dim Buffer(MyFileStream.Length - 1) As Byte

    'المصفوفة المراد البحث عنها داخل الملف
    Dim Find As Byte() = {&HFF, &HFF, &H10}

    'قرائة الملف حتي النهاية
    MyFileStream.Read(Buffer, 0, Buffer.Length)

    Dim Index As Integer = 0
    Do
        Index = SearchByteArray(Buffer, Find, Index)

        If Index <> -1 Then
            'اسنبدال القيمة الثالثة بقيمة جديدة
            Buffer(Index + 2) = &HFF
        End If
    Loop Until Index = -1

    'الانتقال لبداية الملف
    MyFileStream.Seek(&H0, IO.SeekOrigin.Begin)

    'كتابة المصفوفة للملف بعد التعديل
    MyFileStream.Write(Buffer, 0, Buffer.Length)

    'للتأكد من أنه تم كتابة كل البيانات للملف
    MyFileStream.Flush()

Finally
    If MyFileStream IsNot Nothing Then MyFileStream.Close()
End Try

والكود المستخدم للبحث داخل مصفوفة عن مصفوفة آخرى من برمجتي (مع العلم أنه كل الأكواد من برمجتي) Wink

كود :
Function SearchByteArray(ByVal Array As Byte(), ByVal Find As Byte(), ByVal Start As Integer) As Integer
    If Find.Length > Array.Length Then Return -1

    Dim Index As Integer = 0

    If Start > 0 Then
        Index = Start + Find.Length
    End If

    If Index > Array.Length Then Return -1

    For I As Integer = Index To (Array.Length - Find.Length) - 2
        If Array(I) = Find(0) Then
            Dim Counter As Integer = 1

            For J As Integer = 1 To Find.Length - 1
                If Array(I + J) = Find(J) Then
                    Counter += 1
                Else
                    Exit For
                End If
            Next

            If Counter = Find.Length Then Return I
        End If
    Next

    Return -1
End Function
الرد }}}
تم الشكر بواسطة: محمديات
#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 تمام ولكن لمذا لا يقوم بتغييره في هيدر الملف اي انه لا يكتب في الأسطر اللذي وضحتها
يظهر الرسالة فقط


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

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


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيفية منع ظهور الأخطاء من إعدادات البيسيك mmaalmesry 2 850 29-08-25, 10:30 AM
آخر رد: mmaalmesry
  [سؤال] طريقة توسيط النص داخل اداة comboBox سمير1404 7 3,859 24-08-25, 01:01 PM
آخر رد: أبو خالد الشكري
  كيفية جلب أسماء الأعمدة بجدول من جداول sql heem1986 2 746 17-08-25, 09:15 PM
آخر رد: heem1986
  كيفية حفظ إعدادات البرنامج بحيث لا تتغير أحمد إبراهيم سعد 4 3,004 06-08-25, 06:34 PM
آخر رد: Taha Okla
  مساعدة في كيفية ترحيل البيانات من داتا قريدفيو إلى داتا قريدفيو في فيجوال بيسك ahmedfa71 13 2,225 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 397 13-11-24, 06:41 PM
آخر رد: justforit
  كتابه عدد معين من الارقام داخل تيكست بوكس modymody300894 3 557 07-11-24, 09:15 PM
آخر رد: modymody300894

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


يقوم بقرائة الموضوع: