Get CrC values of all process

Untamed

Well-known member
Joined
Jul 25, 2009
Messages
53
Programming Experience
5-10
Hello all, I had this problem and after quite a bit of hard work, I made a CRC check of processes. It combines a small amount of my own code with 2 or 3 other pieces of code I found via google.

Make a new class called CRC32.vb:
VB.NET:
Option Explicit On
Option Strict On

<System.Diagnostics.DebuggerStepThrough()> _
Friend Class CRC32

    ' This is v2 of the VB CRC32 algorithm provided by Paul
    ' (wpsjr1@succeed.net) - much quicker than the nasty
    ' original version I posted.  Excellent work!

    'Last edited by Jeff Ballard on 2008-10-16
    'Added GetCrc32String which returns the properly formatted string

    Private crc32Table() As Integer
    Private Const BUFFER_SIZE As Integer = 1024I

    Friend Function GetCrc32(ByRef stream As System.IO.FileStream) As Integer
        Dim crc32Result As Integer = &HFFFFFFFF

        Dim buffer(BUFFER_SIZE) As Byte
        Dim readSize As Integer = BUFFER_SIZE
        Dim count As Integer = stream.Read(buffer, 0I, readSize)
        Dim i As Integer
        Dim iLookup As Integer

        Do While (count > 0I)
            For i = 0I To count - 1I
                iLookup = (crc32Result And &HFF) Xor buffer(i)
                crc32Result = ((crc32Result And &HFFFFFF00) \ &H100) And &HFFFFFF   ' nasty shr 8 with vb :/
                crc32Result = crc32Result Xor crc32Table(iLookup)
            Next i
            count = stream.Read(buffer, 0I, readSize)
        Loop
        Return Not (crc32Result)
    End Function

    Friend Function GetCrc32String(ByRef stream As System.IO.FileStream) As String
        Return String.Format("{0:X8}", GetCrc32(stream))
    End Function

    Friend Sub New()
        ' This is the official polynomial used by CRC32 in PKZip.
        ' Often the polynomial is shown reversed (04C11DB7).
        Dim dwPolynomial As Integer = &HEDB88320
        Dim i, j As Integer

        ReDim crc32Table(256I)
        Dim dwCrc As Integer

        For i = 0I To 255I
            dwCrc = i
            For j = 8I To 1I Step -1I
                If (dwCrc And 1I) > 0I Then
                    dwCrc = ((dwCrc And &HFFFFFFFE) \ 2I) And &H7FFFFFFF
                    dwCrc = dwCrc Xor dwPolynomial
                Else
                    dwCrc = ((dwCrc And &HFFFFFFFE) \ 2I) And &H7FFFFFFF
                End If
            Next j
            crc32Table(i) = dwCrc
        Next i
    End Sub
End Class

Make your own sub and put this in it:
VB.NET:
        Dim ProcessList As System.Diagnostics.Process()
        ProcessList = System.Diagnostics.Process.GetProcesses()
        Try
            For Each process As Process In ProcessList
                For Each m As ProcessModule In process.Modules
                    Dim test As String = m.FileName
                    Dim fs = New FileStream(test, FileMode.Open, FileAccess.Read)
                    Dim Crc_Class As New CRC32
                    Dim Formated_Crc_String As String
                    Formated_Crc_String = Crc_Class.GetCrc32String(fs)
                Next
            Next
        Catch ex As Exception
        End Try

This gets the CRC values of all processes one by one, very quickly. Formated_Crc_String is the CRC value of that process.
Here is how I use the crc to block an unwanted program:
Put this code in the same sub as above, right under Formated_Crc_String = Crc_Class.GetCrc32String(fs)
VB.NET:
                    Dim CRCheck As String = "5E4BBC78"
                    If Formated_Crc_String = CRCheck Then
                        killProcess("program")
                        System.Diagnostics.Process.GetCurrentProcess.Kill()
Replace CRheck string with the crc value of the unwanted program. Then set the whole sub into a loop upon form loading, or whenever...
 
LOL, I love this line:
VB.NET:
'Last edited by Jeff Ballard on 2008-10-16
'Added GetCrc32String which returns the properly formatted string

I barely remember doing that a year ago and posting it on vbforums.com

So you modified it to get the CRC32 of a running process? How does one calculate the Concurrency Redundancy Check on a process when the Redundancy's changing every 2 miliseconds (before the CRC can be calculated it has to start over again because it's different)?
 
@JuggaloBrother I'm going to be honest, I don't know what you are completely asking. What do you mean by redundancy's? I have only been doing VB.Net for 4 months or so :p Thanks for making that script though, it made my life a lot easier xD
I have tested it and it does indeed block the hex that you put in, which is exactly what I wanted for my anticheat.

@formlesstree4 I posted this because I would have loved if someone else posted this for me... lol. But they didn't and I figured out most things on my own, and made it work on my own. Something like this in full is hard to find on the internet, so I decided to release it, as I am sure it will eventually help at least one person.
 
@JuggaloBrother I'm going to be honest, I don't know what you are completely asking. What do you mean by redundancy's? I have only been doing VB.Net for 4 months or so :p
I have tested it and it does indeed block the hex that you put in, which is exactly what I wanted for my anticheat.

Wikipedia said:
A cyclic redundancy check (CRC) is a non-secure hash function designed to detect accidental changes to raw computer data, and is commonly used in digital networks and storage devices such as hard disk drives. A CRC-enabled device calculates a short, fixed-length binary sequence, known as the CRC code or just CRC, for each block of data and sends or stores them both together. When a block is read or received the device repeats the calculation; if the new CRC does not match the one calculated earlier, then the block contains a data error and the device may take corrective action such as rereading or requesting the block be sent again.[1]

CRCs are so called because the check (data verification) code is a redundancy (it adds zero information) and the algorithm is based on cyclic codes. The term CRC may refer to the check code or to the function that calculates it, which accepts data streams of any length as input but always outputs a fixed-length code. CRCs are popular because they are simple to implement in binary hardware, are easy to analyse mathematically, and are particularly good at detecting common errors caused by noise in transmission channels.
[ame=http://en.wikipedia.org/wiki/CRC32]Cyclic redundancy check - Wikipedia, the free encyclopedia[/ame]

As the process runs it's bits are always shifting so when you calculate the CRC as soon as it's done, it's already going to be able to produce a new CRC code because it's running and has changed. CRC is meant for calculating the CRC hash on a file (any file, even dll's, exe's, etc) that's on a disk, flash drive, hard drive, etc not a running process. So I'm curious to how you went about it in the CRC calculation code? I already see where you pass it a memory stream.
 
I am blocking a compiled and uneditable hack for my program.
What I do is I get the filepath of that process, and I get the CRC value of that file. So I don't get it directly from the process, I get it from the file path, which I get from the process. Then, it calculates CRC value of that file and compares it to whichever CRC value string I want it to.
Does that answer your question? I am just using the process to get the file path :)
 
I am blocking a compiled and uneditable hack for my program.
What I do is I get the filepath of that process, and I get the CRC value of that file. So I don't get it directly from the process, I get it from the file path, which I get from the process. Then, it calculates CRC value of that file and compares it to whichever CRC value string I want it to.
Does that answer your question? I am just using the process to get the file path :)
That makes sense, I didn't see that part in your code at first, it's a sign it's been a very long day indeed.
 
VB.NET:
                              For Each process As Process In ProcessList
                For Each m As ProcessModule In process.Modules
                    Dim test As String = m.FileName
                    Dim fs = New FileStream(test, FileMode.Open, FileAccess.Read)
                    Dim Crc_Class As New CRC32
                    Dim Formated_Crc_String As String
                    Formated_Crc_String = Crc_Class.GetCrc32String(fs)
                Next
            Next
test string is getting the file path from the process.
fs string gets the filestream of that file path
It is then turned into a CRC value :)
 
Back
Top