PDA

View Full Version : Understand the "Generate License Code" Mechanism


Nixkap
September 6th, 2008, 02:06
Hi Guys,

Here is the deal:

We are talking about a soft called No links to Apps

I've been able to crack the commercial version but I'd like to know how to generate the S/N for it as I we can see the Generate License Code Mechanism in .Net Reflector. ( Here is a screenshot of the registration box ("http://img6.pictiger.com/9d6/16678213.jpg") )



In C# :

public string GenerateLicenseCode(string name, string count, string product, string time)
{
string str = (name + count + product).GetHashCode().ToString();
str = time + str;
byte[] inArray = new byte[str.Length];
long num = 0L;
foreach (char ch in str)
{
byte num2 = 0x23;
inArray[(int) ((IntPtr) num)] = (byte) (ch ^ num2);
num += 1L;
}
return Convert.ToBase64String(inArray).Substring(0, 20);
}



In VB :

Public Function GenerateLicenseCode(ByVal name As String, ByVal count As String, ByVal product As String, ByVal time As String) As String
Dim str As String = (name & count & product).GetHashCode.ToString
str = (time & str)
Dim inArray As Byte() = New Byte(str.Length - 1) {}
Dim num As Long = 0
Dim ch As Char
For Each ch In str
Dim num2 As Byte = &H23
inArray(CInt(DirectCast(num, IntPtr))) = CByte((ch Xor num2))
num = (num + 1)
Next
Return Convert.ToBase64String(inArray).Substring(0, 20)
End Function

If someone could help me or at least give me some more info, that would be great.

Cheers guys and keep up the good work

FrankRizzo
September 6th, 2008, 15:40
I guess I don't understand. It LOOKS like you have the code RIGHT THERE.

What exactly are you asking?

Nixkap
September 6th, 2008, 16:03
Ok first of all. What is that GetHashCode ?

and what would be my serial for the user TEST for example ? So I can work on it and understand how it works ...

Can someone describe Line by line what it does ???

That's what I'm after. Many thanks in advance ...

Thx FrankRizzo for the response.

FrankRizzo
September 6th, 2008, 16:34
Quote:
[Originally Posted by Nixkap;76872]Ok first of all. What is that GetHashCode ?


If you hang around here for long, you'll see this A LOT>

"Google is your friend"

http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx

Code:
string str = (name + count + product).GetHashCode().ToString();


Makes a new string (str) from the string class. This string will contain the passed in variables of name, count, and product all pasted together. (think of it as" NameCountProduct". Then, they will run this through the GetHasCode method, which will produce a number for that collection of stuff. Then, they will run the result from that, through ToString, which converts it back into a string, and they store the result in the variable named str.

If you are confused about that, break it apart, and do it 1 group at a time.

Code:

string str;
int hash;

str = (name + count + product);
hash = str.GetHashCode();
str = hash; (Or something like this, I'm no .NET programmer).


And then this line:

Code:
str = time + str;


This line simply prepends the contents of the variable time, to the string generated above. Let's say for example that the above code generated a hash of "12345", when this line is executed, it will generate "Time12345". (using the word Time instead of the value passed to the function).

Code:
byte[] inArray = new byte[str.Length];


Simply makes a new array of bytes that is the length of the str variable now. And calls it inArray.

Code:
long num = 0L;


Simply defines a new variable named num that is a long, and is set to 0.

Code:
foreach (char ch in str)
{
byte num2 = 0x23;
inArray[(int) ((IntPtr) num)] = (byte) (ch ^ num2);
num += 1L;
}


This is simply a "For Next" loop that processes each byte of our string "str".
All it does is simply take each letter in the string, and XOR it with 0x23 (Hex 23), and store the results in inArray.

That leaves us with this:

Code:
return Convert.ToBase64String(inArray).Substring(0, 20);


This takes the 1st 20 bytes of inArray, and converts it to Base64. (Base64 is a technique for being able to express binary data as printable characters).

So, this technique is pretty simple, when taken in it's entirety, it concatenates most of the passed in strings into one, generates a hash of that, prepends that with the Time variable to make another string. Then, it XORs each character of that string with a value, and then Base64 converts the 1st 20 characters of that into a string that is returned to the caller.

As far as keygen functions go, this one is pretty simple.

If any aspects of my description didn't make sense, ask further questions, but if it's something like "What is Base64", then I must say: Google is your friend!

Nixkap
September 6th, 2008, 16:43
That's great

Thanks very much for that long and complete answer !

I will work on it and then hopefully be able to generate that £$% serial, cause I really want to be able to do it :-)

Frank

Cheers for your help