المشاركات : 24
المواضيع 0
الإنتساب : May 2014
السمعة :
1
الشكر: 4
تم شكره 58 مرات في 14 مشاركات
تفضل أخي، استبدال صف بدل صف آخر وكود Check Sum قبل وبعد التعديل
كود :
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
المشاركات : 21
المواضيع 1
الإنتساب : May 2014
السمعة :
0
الشكر: 25
تم شكره 0 مرات في 0 مشاركات
شكرا شكرا على المساعده وكن اخي الكريم ال Check sum هنا يظهر كرساله فقط ولا يغير في ال Check sum الخاص بالملف نفسه اريده يغير في check sum الملف نفسه يعني بعد ما يطلع الناتج بعد يبدأ بالتغيير في الملف نفسه وانتظر الرد
وجعل الله هذا العمل في ميزان حسناتك
المشاركات : 24
المواضيع 0
الإنتساب : May 2014
السمعة :
1
الشكر: 4
تم شكره 58 مرات في 14 مشاركات
(19-05-14, 02:56 PM)محمديات كتب : شكرا شكرا على المساعده وكن اخي الكريم ال Check sum هنا يظهر كرساله فقط ولا يغير في ال Check sum الخاص بالملف نفسه اريده يغير في check sum الملف نفسه يعني بعد ما يطلع الناتج بعد يبدأ بالتغيير في الملف نفسه وانتظر الرد
وجعل الله هذا العمل في ميزان حسناتك
يا أخ محمديات ممكن توضيح أكثر بخصوص Check Sum !
مع العلم أن Check Sum لن تتغير للملف إلا إذا تم التعديل عليه وأنا أوضحت هذا الشيء في الكود بحيث يظهر لك Check Sum للملف قبل التعديل وبعد التعديل
المشاركات : 21
المواضيع 1
الإنتساب : May 2014
السمعة :
0
الشكر: 25
تم شكره 0 مرات في 0 مشاركات
ال CHECK SUM المفروض بيغير القيم ده بس يعني لو عدلنا على الملف مثلا في الهيكس 34 وجعلناه ff مثلا
فأن ال ال CHECK SUM
هوه اللي هيتغير في المكان المشار اليه اللي اشارت عليها في الصورة السابقة لكن كود الذي كتبته اخي كان فقط يخرج رسالة بأن ال check sum اتغير ولكن لا يقوم بالتغير في هيدر الملف ليتناسق ويتناسب بين المحتوى والهيدر وياريت لو
توضح ايضا لي كيف أقوم بالبحث عن 6 قيم بجوار بعضهم داخل ملف الهيكس وعند وجود هذه القيم يقوم بتغيير مثلا القيمه الخامسه وانا موضحها في الصورة التالية ان عندما يجد هذه القيم بجوار بعضها يقوم بتغيير القيمه اللي عليها الدائرة الحمراء بالرقم الذي اسفل الدائرة الموجود في الصورة
المشاركات : 24
المواضيع 0
الإنتساب : May 2014
السمعة :
1
الشكر: 4
تم شكره 58 مرات في 14 مشاركات
بالنسبة لـ Check Sum
هو الملف مخزن في بدايته Check Sum وما نوع هذا Check Sum ؟
المشاركات : 21
المواضيع 1
الإنتساب : May 2014
السمعة :
0
الشكر: 25
تم شكره 0 مرات في 0 مشاركات
هاشوف نوع ال Check sum
ولكن ياريت لو حضرتك تجهز لي هذا الكود الخاص بالطلب هذا
توضح ايضا لي كيف أقوم بالبحث عن 6 قيم بجوار بعضهم داخل ملف الهيكس وعند وجود هذه القيم يقوم بتغيير مثلا القيمه الخامسه وانا موضحها في الصورة التالية ان عندما يجد هذه القيم بجوار بعضها يقوم بتغيير القيمه اللي عليها الدائرة الحمراء بالرقم الذي اسفل الدائرة الموجود في الصورة
المشاركات : 21
المواضيع 1
الإنتساب : May 2014
السمعة :
0
الشكر: 25
تم شكره 0 مرات في 0 مشاركات
المشاركات : 403
المواضيع 2
الإنتساب : Feb 2014
السمعة :
65
الشكر: 32
تم شكره 837 مرات في 280 مشاركات
-
بالنسبة لـ 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)
المشاركات : 24
المواضيع 0
الإنتساب : May 2014
السمعة :
1
الشكر: 4
تم شكره 58 مرات في 14 مشاركات
تفضل أخي، هذا بالنسبة للبحث عن 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
والكود المستخدم للبحث داخل مصفوفة عن مصفوفة آخرى من برمجتي (مع العلم أنه كل الأكواد من برمجتي)
كود :
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
المشاركات : 21
المواضيع 1
الإنتساب : May 2014
السمعة :
0
الشكر: 25
تم شكره 0 مرات في 0 مشاركات
(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 تمام ولكن لمذا لا يقوم بتغييره في هيدر الملف اي انه لا يكتب في الأسطر اللذي وضحتها
يظهر الرسالة فقط
ولكن لا يغير الظاهر في الرسالة في الرقام الموجوده في هذه الصفحة في المكان المحدد
يعني يفضل لو الظاهر في الرسالة يكتب بالأرقام في هذه المنطقة واسف اني تعبتك معايا
ولك مني كل الحب والتقدير اخي
انتظر منك الرد في القريب العاجل
وشكرالك ولمجهودتك وجعله الله في ميزان حسناتك
|