Crackers and Hackers have fantasized me ever since I started gaining computer knowledge. The skills demonstrated by these guys have always driven me crazy. Having, unexpectedly, played around with couple of .NET DLL’s and successful cracked them, I want to share that knowledge by writing – basics of hacking / cracking the .NET DLLs. Being a beginner myself, the following tutorial should be considered by individuals who absolutely have no clue what’s cracking is?
In this tutorial, let’s build a simple application first and then try to crack it.
Application:
Super Calculator: Since, our main intension is to learn the concepts behind the cracking .NET dll; I worked on a simple one rather than a Super Calculator. As I want end users of this calculator to buy a full version, I will make all features available only for first 14 days of trial period.
Trial v/s Full Version features: Addition (+) being the basic operations, it is available in both trial and post-trial periods, whereas, the subtraction functionality will be disabled after trial period expiration. To achieve this, somehow you need to keep track the number of days passed since the date of installation. Usually most of them do this by saving time of installation into windows registry during product setup.
Also, let’s assume that we want to sell our wonderful product with add-on features of multiplication, division and power operations per license. To simplify, the end user have to end up paying additional amount for each add-on feature that he / she is interested in. Most of the applications achieve this by placing a license key file in specific folder that application is looking at. This license key will contain the details similar to our add-on features list.
Application: To achieve this – first we build the core logic for all such computations using operations +, -, *, / and ^ as show below.
Select Case Me.cbOperator.SelectedItem Case "ADD" dValue = dFirstNumber + dSecondNumber Case "MULTIPLY" dValue = dFirstNumber * dSecondNumber Case "DIVIDE" dValue = dFirstNumber / dSecondNumber Case "SUBTRACT" dValue = dFirstNumber - dSecondNumber Case "POWER" dValue = dFirstNumber ^ dSecondNumber End Select
cbOperator is a combo box containing list of accessible operators populated based on the software – Trial Version / Expiration, and add-on features purchased through License. Consider, the below table illustrating what operation items are available in the cbOperator based on license status
Licence | + | – | * | / | ^ |
---|---|---|---|---|---|
Trial NOT Expired | x | x | Â | Â | Â |
Trial Expired | x | Â | Â | Â | Â |
Full Licence | x | x | x | x | x |
Identifying trial / full version: We want to let the user use the product free for 14 days, so we want to save when did we ran the product for first time? As mentioned earlier, we would like to save this information in Registry entry. The following methods are used to read & write information from the Windows Registry Entry.
''' ----------------------------------------------------------------------------- ''' <summary> ''' Reads data of subKey\value located in Local machine of Windows registry ''' </summary> ''' <param name="subKey">Name or path of subKey relative to Local Machine to open</param> ''' <param name="value">Name of value to read data from</param> ''' <param name="defaultValue">If value is not found defaultValue is returned</param> ''' <returns>Returns String containing either value data or defaultValue</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [Shyam Arjarapu] 4/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- Private Function ReadKey(ByVal subKey As String, ByVal value As String, ByVal defaultValue As String) As String Dim oRegKey, oRegSubKey As Microsoft.Win32.RegistryKey Dim oValue As Object oRegKey = Microsoft.Win32.Registry.LocalMachine oRegSubKey = oRegKey.OpenSubKey(subKey) If oRegSubKey Is Nothing Then oRegSubKey = oRegKey.CreateSubKey(subKey) End If oValue = oRegSubKey.GetValue(value, defaultValue) Return oValue End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Writes data to subKey\value located in Local machine of Windows registry ''' </summary> ''' <param name="subKey">Name or path of subKey relative to Local Machine to open</param> ''' <param name="value">Name of value to store data in</param> ''' <param name="valueData">Data to store</param> ''' <remarks> ''' </remarks> ''' <history> ''' [Shyam Arjarapu] 4/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- Private Sub WriteKey(ByVal subKey As String, ByVal value As String, ByVal valueData As Object) Dim oRegKey, oRegSubKey As Microsoft.Win32.RegistryKey Dim oValue As Object oRegKey = Microsoft.Win32.Registry.LocalMachine oRegSubKey = oRegKey.OpenSubKey(subKey) If oRegSubKey Is Nothing Then oRegSubKey = oRegKey.CreateSubKey(subKey) End If oRegSubKey.SetValue(value, valueData) End Sub
On every form load event, we want to add which operations items are available for cbOperations combo box based on the License status. When we load the application for the very first time, obviously, the registry value we are looking for doesn’t exist. In such case, we create a new key with value of current date in ticks. If a key already exists then we read the data value and verify if today is 14 days beyond the first use of the application. If so the application is expired trial version.
sKey = "SOFTWARE\MYSOFTWARES" sValue = "STARTTIME" 'read the installation date oValueData = ReadKey(sKey, sValue, "-1") If oValueData = "-1" Then oValueData = Now.UtcNow.Ticks() WriteKey(sKey, sValue, oValueData) End If dStartTime = New Date(oValueData) 'Verify if Trial version is active or not. If DateDiff(DateInterval.Day, dStartTime, Now.UtcNow) > 14 Then blnTrialExpired = True Else blnTrialExpired = False End If
Also we look for License in registry. If it is Valid License (should be 10 characters, starts with ABC and ends with 123), then you we load the license file containing the add-on features.
If licenceKey.Length = 10 Then If licenceKey.ToUpper.StartsWith("ABC") Then If licenceKey.ToUpper.EndsWith("123") Then blnValidKey = True Else blnValidKey = False End If Else blnValidKey = False End If Else blnValidKey = False End If
License Key file is a simple XML file listing the dates during which this license file is valid and what add-on features that user has purchased with this license? It’s structure looks like this
< ?xml version="1.0"?> <licence> <validfrom>01/01/2005</validfrom> <validto>01/01/2007</validto> <features> <operator>MULTIPLY</operator> <operator>DIVIDE</operator> <operator>POWER</operator> </features> </licence>
So when user got the valid licence with him/her, we load the licence.key file to set the accessibility rights of the application.
oXmlDoc.Load(sLicenceFilePath) dtTo = oXmlDoc.GetElementsByTagName("validto").Item(0).InnerText If dtTo < Now Then Exit Sub End If blnLicenceExpired = False oXmlNodeList = oXmlDoc.GetElementsByTagName("operator") For Each oXmlNode In oXmlNodeList Select Case oXmlNode.InnerText.ToUpper Case "MULTIPLY" blnHasMultiply = True Case "DIVIDE" blnHasDivide = True Case "POWER" blnHasPower = True End Select Next
Please check the complete source code at this Link: http://www.arjarapu.com/wordpress/wp-content/uploads/2011/12/BasicsOfCracking.zip
to understand in detail. The Super Calculator ready, we ship it to the end users and hopefully, they would be interested to purchase the full version of this product. In this session we learnt, how to build an application supporting Trial Version / Full Version with Add on features. Now that you do have some idea about my application, continue to read my second session to learn how to hack them.
Second session – coming soon.
References:
For detailed help on reading and writing to registry, please refer
Dot Net Spider
MSDN
Code Project
– Shyam K. Arjarapu