{"id":17,"date":"2006-04-25T20:24:31","date_gmt":"2006-04-25T18:24:31","guid":{"rendered":"http:\/\/arjarapu.com\/wordpress\/?p=17"},"modified":"2010-02-27T20:54:53","modified_gmt":"2010-02-28T02:24:53","slug":"cracking-net-dlls-for-amateurs-1-of-2","status":"publish","type":"post","link":"http:\/\/www.arjarapu.com\/wordpress\/2006\/04\/cracking-net-dlls-for-amateurs-1-of-2\/","title":{"rendered":"Cracking .NET DLL&#8217;s for Amateurs &#8211; 1 of 2"},"content":{"rendered":"<p>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&#8217;s and successful cracked them, I want to share that knowledge by writing &#8211; 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&#8217;s cracking is?<\/p>\n<p>In this tutorial, let&#8217;s build a simple application first and then try to crack it.<br \/>\n<!--more--><br \/>\nApplication:<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>Also, let&#8217;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.<\/p>\n<p>Application: To achieve this &#8211; first we build the core logic for all such computations using operations +, -, *, \/ and ^ as show below.<\/p>\n<pre class=\"brush:vb\">\r\nSelect Case Me.cbOperator.SelectedItem\r\n   Case &quot;ADD&quot;\r\n      dValue = dFirstNumber + dSecondNumber\r\n   Case &quot;MULTIPLY&quot;\r\n      dValue = dFirstNumber * dSecondNumber\r\n   Case &quot;DIVIDE&quot;\r\n      dValue = dFirstNumber \/ dSecondNumber\r\n   Case &quot;SUBTRACT&quot;\r\n      dValue = dFirstNumber - dSecondNumber\r\n   Case &quot;POWER&quot;\r\n      dValue = dFirstNumber ^ dSecondNumber\r\nEnd Select\r\n<\/pre>\n<p>cbOperator is a combo box containing list of accessible operators populated based on the software &#8211; 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<\/p>\n<table border='1'>\n<tr>\n<th>Licence<\/th>\n<th>+<\/th>\n<th>&#8211;<\/th>\n<th>*<\/th>\n<th>\/<\/th>\n<th>^<\/th>\n<\/tr>\n<tr>\n<td>Trial NOT Expired<\/td>\n<td>x<\/td>\n<td>x<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Trial Expired<\/td>\n<td>x<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Full Licence<\/td>\n<td>x<\/td>\n<td>x<\/td>\n<td>x<\/td>\n<td>x<\/td>\n<td>x<\/td>\n<\/tr>\n<\/table>\n<p>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 &#038; write information from the Windows Registry Entry.<\/p>\n<pre class=\"brush:vb\">\r\n''' -----------------------------------------------------------------------------\r\n''' &lt;summary&gt;\r\n''' Reads data of subKey\\value located in Local machine of Windows registry\r\n''' &lt;\/summary&gt;\r\n'''\r\n&lt;param name=&quot;subKey&quot;&gt;Name or path of subKey relative to Local Machine to open&lt;\/param&gt;\r\n    '''\r\n&lt;param name=&quot;value&quot;&gt;Name of value to read data from&lt;\/param&gt;\r\n    '''\r\n&lt;param name=&quot;defaultValue&quot;&gt;If value is not found defaultValue is returned&lt;\/param&gt;\r\n    ''' &lt;returns&gt;Returns String containing either value data or defaultValue&lt;\/returns&gt;\r\n''' &lt;remarks&gt;\r\n''' &lt;\/remarks&gt;\r\n''' &lt;history&gt;\r\n''' \t[Shyam Arjarapu]\t4\/25\/2006\tCreated\r\n''' &lt;\/history&gt;\r\n''' -----------------------------------------------------------------------------\r\nPrivate Function ReadKey(ByVal subKey As String, ByVal value As String, ByVal defaultValue As String) As String\r\n   Dim oRegKey, oRegSubKey As Microsoft.Win32.RegistryKey\r\n   Dim oValue As Object\r\n\r\n   oRegKey = Microsoft.Win32.Registry.LocalMachine\r\n   oRegSubKey = oRegKey.OpenSubKey(subKey)\r\n\r\n   If oRegSubKey Is Nothing Then\r\n      oRegSubKey = oRegKey.CreateSubKey(subKey)\r\n   End If\r\n\r\n   oValue = oRegSubKey.GetValue(value, defaultValue)\r\n\r\n   Return oValue\r\nEnd Function\r\n\r\n''' -----------------------------------------------------------------------------\r\n''' &lt;summary&gt;\r\n''' Writes data to subKey\\value located in Local machine of Windows registry\r\n''' &lt;\/summary&gt;\r\n'''\r\n&lt;param name=&quot;subKey&quot;&gt;Name or path of subKey relative to Local Machine to open&lt;\/param&gt;\r\n    '''\r\n&lt;param name=&quot;value&quot;&gt;Name of value to store data in&lt;\/param&gt;\r\n    '''\r\n&lt;param name=&quot;valueData&quot;&gt;Data to store&lt;\/param&gt;\r\n    ''' &lt;remarks&gt;\r\n''' &lt;\/remarks&gt;\r\n''' &lt;history&gt;\r\n''' \t[Shyam Arjarapu]\t4\/25\/2006\tCreated\r\n''' &lt;\/history&gt;\r\n''' -----------------------------------------------------------------------------\r\nPrivate Sub WriteKey(ByVal subKey As String, ByVal value As String, ByVal valueData As Object)\r\n   Dim oRegKey, oRegSubKey As Microsoft.Win32.RegistryKey\r\n   Dim oValue As Object\r\n\r\n   oRegKey = Microsoft.Win32.Registry.LocalMachine\r\n   oRegSubKey = oRegKey.OpenSubKey(subKey)\r\n\r\n   If oRegSubKey Is Nothing Then\r\n      oRegSubKey = oRegKey.CreateSubKey(subKey)\r\n   End If\r\n\r\n   oRegSubKey.SetValue(value, valueData)\r\nEnd Sub\r\n<\/pre>\n<p>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\u00e2\u20ac\u2122t 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.<\/p>\n<pre class=\"brush:vb\">\r\n   sKey = &quot;SOFTWARE\\MYSOFTWARES&quot;\r\n   sValue = &quot;STARTTIME&quot;\r\n\r\n   'read the installation date\r\n   oValueData = ReadKey(sKey, sValue, &quot;-1&quot;)\r\n   If oValueData = &quot;-1&quot; Then\r\n      oValueData = Now.UtcNow.Ticks()\r\n      WriteKey(sKey, sValue, oValueData)\r\n   End If\r\n   dStartTime = New Date(oValueData)\r\n\r\n   'Verify if Trial version is active or not.\r\n   If DateDiff(DateInterval.Day, dStartTime, Now.UtcNow) &gt; 14 Then\r\n      blnTrialExpired = True\r\n   Else\r\n      blnTrialExpired = False\r\n   End If\r\n<\/pre>\n<p>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. <\/p>\n<pre class=\"brush:vb\">\r\nIf licenceKey.Length = 10 Then\r\n   If licenceKey.ToUpper.StartsWith(&quot;ABC&quot;) Then\r\n      If licenceKey.ToUpper.EndsWith(&quot;123&quot;) Then\r\n         blnValidKey = True\r\n      Else\r\n         blnValidKey = False\r\n      End If\r\n   Else\r\n      blnValidKey = False\r\n   End If\r\nElse\r\n   blnValidKey = False\r\nEnd If\r\n<\/pre>\n<p>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&#8217;s structure looks like this <\/p>\n<pre class=\"brush:xml\">\r\n&lt; ?xml version=&quot;1.0&quot;?&gt;\r\n&lt;licence&gt;\r\n\t&lt;validfrom&gt;01\/01\/2005&lt;\/validfrom&gt;\r\n&lt;validto&gt;01\/01\/2007&lt;\/validto&gt;\r\n&lt;features&gt;\r\n   &lt;operator&gt;MULTIPLY&lt;\/operator&gt;\r\n   &lt;operator&gt;DIVIDE&lt;\/operator&gt;\r\n   &lt;operator&gt;POWER&lt;\/operator&gt;\r\n&lt;\/features&gt;\r\n&lt;\/licence&gt;\r\n<\/pre>\n<p>So when user got the valid licence with him\/her, we load the licence.key file to set the accessibility rights of the application.<\/p>\n<pre class=\"brush:vb\">\r\n   oXmlDoc.Load(sLicenceFilePath)\r\n   dtTo = oXmlDoc.GetElementsByTagName(&quot;validto&quot;).Item(0).InnerText\r\n   If dtTo &lt; Now Then\r\n      Exit Sub\r\n   End If\r\n\r\n   blnLicenceExpired = False\r\n   oXmlNodeList = oXmlDoc.GetElementsByTagName(&quot;operator&quot;)\r\n\r\n   For Each oXmlNode In oXmlNodeList\r\n      Select Case oXmlNode.InnerText.ToUpper\r\n         Case &quot;MULTIPLY&quot;\r\n            blnHasMultiply = True\r\n         Case &quot;DIVIDE&quot;\r\n            blnHasDivide = True\r\n         Case &quot;POWER&quot;\r\n            blnHasPower = True\r\n      End Select\r\n   Next\r\n<\/pre>\n<p>Please check the complete source code at this Link: http:\/\/www.arjarapu.com\/wordpress\/wp-content\/uploads\/2011\/12\/BasicsOfCracking.zip<\/p>\n<p>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. <\/p>\n<p>Second session &#8211; coming soon.<\/p>\n<p>References:<\/p>\n<p>For detailed help on reading and writing to registry, please refer<br \/>\n<a href=\"http:\/\/www.dotnetspider.com\/namespace\/ShowClass.aspx?ClassId=94\">Dot Net Spider<br \/>\n<\/a><a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfMicrosoftWin32RegistryKeyClassTopic.asp\">MSDN<\/a><br \/>\n<a href=\"http:\/\/www.thecodeproject.com\/csharp\/modifyregistry.asp\">Code Project<\/a><\/p>\n<p>&#8211; Shyam K. Arjarapu<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s and successful cracked them, I want to &hellip; <a href=\"http:\/\/www.arjarapu.com\/wordpress\/2006\/04\/cracking-net-dlls-for-amateurs-1-of-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[11,24,29],"_links":{"self":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/17"}],"collection":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":4,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":62,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/17\/revisions\/62"}],"wp:attachment":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}