PDA

View Full Version : I need some help to make a keygen


g_ramzi
November 4th, 2008, 12:26
how to make a keygen for this?


the "strkey" must be like this :: 11111111-1111111-111111111-111111111


public static void SetLicence (string strKey)

{

string str = "";
string str2 = "";
string str3 = "";
string str4 = "";
if ((strKey != "" && (strKey.Length == 35))
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < strKey.Length; i++)
{
if ((strKey[I] > 'F') && (strKey[I] < '['))
{
builder.Append('0');
}
else
{
builder.Append(strKey[I]);
}
}
strKey = builder.ToString();
str = strKey.Substring(0, 8);
strKey = strKey.Replace(str + "-", "";
str2 = strKey.Substring(0, 8);
strKey = strKey.Replace(str2 + "-", "";
str3 = strKey.Substring(0, 8);
strKey = strKey.Replace(str3 + "-", "";
str4 = strKey;
long num2 = 0L;
num2 += Convert.ToInt32(str.Substring(0, 3), 16);
num2 += Convert.ToInt32(str2.Substring(0, 3), 16);
num2 += Convert.ToInt32(str3.Substring(0, 3), 16);
if (num2 == Convert.ToInt32(str4, 16))
{
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string str5 = Convert.ToInt32(str.Substring(0, 6), 16).ToString();
if ((versionInfo.FileMajorPart.ToString("0" + versionInfo.FileMinorPart.ToString("00") == str5.Substring(0, 3))
{
string code = GetCode();
long num3 = 0L;
for (int j = 0; j < code.Substring(6).Length; j++)
{
num3 += (long) code.Substring(6)[j];
}
if (Convert.ToInt32(str2, 16) == ((num3 * 999) % 0x7fffffffL))
{
MessageBox.Show("Good Work!!!!";
}
}
}
}
if (menmLicenseType == LicenseType.Demo)
{
MessageBox.Show("Try again!!!!";
}


}





//// And Thanks a lot!!!!

personmans
November 7th, 2008, 14:52
Seeing as you have the source code...or part of the source code?

I would suggest compiling it and adding debug messages
(ie MessageBox.Show(code); ) after it gets assigned to see what the value is, basically you just need to understand the code very well.


PS source code = keygen. You should be able to edit any source code to make its own keygen.

g_ramzi
November 8th, 2008, 02:55
///This is what i've done until now

///I'm planning to use this code to protect my program after making a keygen ///for it




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Keygen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show(Convert.GetTypeCode(textBox1.Text).ToString());
textBox2.Text = Convert.ToInt32(textBox1.Text, 16).ToString();
}

private void button2_Click(object sender, EventArgs e)
{
// MessageBox.Show(DecimalToBase(Convert.ToInt32(textBox2.Text), 16,8));
string code = GetCode();
long num3 = 0L;
for (int j = 0; j < code.Substring(6).Length; j++)
{
num3 += (long)code.Substring(6)[j];
}
MessageBox.Show(DecimalToBase((int)((num3 * 2457) % 2147483647),16,8));

}


private static string DecimalToBase(int iDec, int numbase, int intLength)
{
char[] chArray = new char[] { 'A', 'B', 'C', 'D', 'E', 'F' };
string str = "";
int[] numArray = new int[20];
int num = 20;
while (iDec > 0)
{
int num2 = iDec % numbase;
numArray[--num] = num2;
iDec /= numbase;
}
for (int i = 0; i < numArray.Length; i++)
{
if (((int)numArray.GetValue(i)) >= 10)
{
str = str + chArray[((int)numArray.GetValue(i)) % 10];
}
else
{
str = str + numArray.GetValue(i);
}
}
str = str.TrimStart(new char[] { '0' });
string str2 = "";
for (int j = 1; j <= (intLength - str.Length); j++)
{
str2 = str2 + "0";
}
return (str2 + str);

}

public static string GetCode()
{
FileVersionInfo fileVersionInfo1 = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
int i1 = (((fileVersionInfo1.FileMajorPart * 100000) + (fileVersionInfo1.FileMinorPart * 1000)) + fileVersionInfo1.FileBuildPart);
i1 *= 2;
string string1 = string.Format("{0:X6}", i1);
string string2 = GetVolumeSerial(Assembly.GetExecutingAssembly().Location.Substring(0, 1));
return (string1 + string2);

}

[DllImportAttribute("kernel32.dll", EntryPoint = "GetVolumeInformation", CharSet = CharSet.None, ExactSpelling = false, SetLastError = false, PreserveSig = true, CallingConvention = CallingConvention.Winapi, BestFitMapping = false, ThrowOnUnmappableChar = false)]
[PreserveSigAttribute()]
private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, uint VolumeNameSize, ref uint VolumeSerialNumber, ref uint MaximumComponentLength, ref uint FileSystemFlags, StringBuilder FileSystemNameBuffer, uint FileSystemNameSize);
private static string GetVolumeSerial(string strDriveLetter)
{
string s = "";
uint uInt32_1 = uint.MinValue;
uint uInt32_2 = uint.MinValue;
StringBuilder stringBuilder1 = new StringBuilder(256);
uint uInt32_3 = uint.MinValue;
StringBuilder stringBuilder2 = new StringBuilder(256);
strDriveLetter = (strDriveLetter + ":\\";
long int64_1 = GetVolumeInformation(strDriveLetter, stringBuilder1, ((uint)stringBuilder1.Capacity), ref uInt32_1, ref uInt32_2, ref uInt32_3, stringBuilder2, ((uint)stringBuilder2.Capacity));
s = Convert.ToString(uInt32_1).Replace("-", "";
return s;
}
}
}

personmans
November 9th, 2008, 04:23
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Keygen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show(Convert.GetTypeCode(textBox1.Text).ToString());
textBox2.Text = Convert.ToInt32(textBox1.Text, 16).ToString();
}

private void button2_Click(object sender, EventArgs e)
{
// MessageBox.Show(DecimalToBase(Convert.ToInt32(textBox2.Text), 16,8));
string code = GetCode();
long num3 = 0L;

for (int j = 0; j < code.Substring(6).Length; j++)
{
num3 += (long)code.Substring(6)[j];
}

MessageBox.Show(DecimalToBase((int)((num3 * 2457) % 2147483647),16,8));
}


private static string DecimalToBase(int iDec, int numbase, int intLength)
{
char[] chArray = new char[] { 'A', 'B', 'C', 'D', 'E', 'F' };
string str = "";
int[] numArray = new int[20];
int num = 20;

while (iDec > 0)
{
int num2 = iDec % numbase;
numArray[--num] = num2;
iDec /= numbase;
}

for (int i = 0; i < numArray.Length; i++)
{
if (((int)numArray.GetValue(i)) >= 10)
{
str = str + chArray[((int)numArray.GetValue(i)) % 10];
}
else
{
str = str + numArray.GetValue(i);
}
}

str = str.TrimStart(new char[] { '0' });
string str2 = "";

for (int j = 1; j <= (intLength - str.Length); j++)
{
str2 = str2 + "0";
}
return (str2 + str);

}

public static string GetCode()
{
FileVersionInfo fileVersionInfo1 = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
int i1 = (((fileVersionInfo1.FileMajorPart * 100000) + (fileVersionInfo1.FileMinorPart * 1000)) + fileVersionInfo1.FileBuildPart);//get version info and format it
i1 *= 2; //double our version number...
string string1 = string.Format("{0:X6}", i1); //take version info (doubled) and get the HEX string of it
string string2 = GetVolumeSerial(Assembly.GetExecutingAssembly().Location.Substring(0, 1)); //volume serial using drive letter in some weird fashion
return (string1 + string2); //concatenates version with serial
}

[DllImportAttribute("kernel32.dll", EntryPoint = "GetVolumeInformation", CharSet = CharSet.None, ExactSpelling = false, SetLastError = false, PreserveSig = true, CallingConvention = CallingConvention.Winapi, BestFitMapping = false, ThrowOnUnmappableChar = false)]
[PreserveSigAttribute()]

private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, uint VolumeNameSize, ref uint VolumeSerialNumber, ref uint MaximumComponentLength, ref uint FileSystemFlags, StringBuilder FileSystemNameBuffer, uint FileSystemNameSize);

private static string GetVolumeSerial(string strDriveLetter)
{
string s = "";
uint uInt32_1 = uint.MinValue;
uint uInt32_2 = uint.MinValue;
StringBuilder stringBuilder1 = new StringBuilder(256);
uint uInt32_3 = uint.MinValue;
StringBuilder stringBuilder2 = new StringBuilder(256);
strDriveLetter = (strDriveLetter + ":\\"; //concatenate drive letter such as "C" with ":\"
long int64_1 = GetVolumeInformation(strDriveLetter, stringBuilder1, ((uint)stringBuilder1.Capacity), ref uInt32_1, ref uInt32_2, ref uInt32_3, stringBuilder2, ((uint)stringBuilder2.Capacity));
s = Convert.ToString(uInt32_1).Replace("-", ""; //remove our dashes from return (lpVolumeSerialNumber)
return s; //send back lpVolumeSerialNumber without dashes
}
}
}







public static void SetLicence (string strKey) {
string str = "";
string str2 = "";
string str3 = "";
string str4 = "";
if ((strKey != "" && (strKey.Length == 35)) //length must be 35, or quit
{
StringBuilder builder = new StringBuilder();

for (int i = 0; i < strKey.Length; i++) //loop through the 35
{
if ((strKey[I] > 'F') && (strKey[I] < '[')) // check if its between 70 and 91 (ascii codes for values), if so make it zero
{ // this is F-Z basically
builder.Append('0');
}
else //if it's below 70 or above 90 keep it.
{ // That makes it 0-9 and A-F as well as a-z if there is no toUpper command.
builder.Append(strKey[I]);
}
}

strKey = builder.ToString(); //Missing the code for the function, but make our array into 3 strings again?

str = strKey.Substring(0, 8); // get the first 9 characters
strKey = strKey.Replace(str + "-", ""; //remove a dash
str2 = strKey.Substring(0, 8);// get the next 9 characters
strKey = strKey.Replace(str2 + "-", "";//remove a dash
str3 = strKey.Substring(0, 8);// get the last 9 characters
strKey = strKey.Replace(str3 + "-", "";//remove a dash
str4 = strKey; //str4 holds our whole serial now

long num2 = 0L;

num2 += Convert.ToInt32(str.Substring(0, 3), 16); //make 32 bit int (of the first 4 letters of str), add it to zero
num2 += Convert.ToInt32(str2.Substring(0, 3), 16); //make 32 bit int(of the first 4 letters of str2), add it to the last one
num2 += Convert.ToInt32(str3.Substring(0, 3), 16); //make 32 bit int(of the first 4 letters of str3), add it to the last one

if (num2 == Convert.ToInt32(str4, 16)) //make the whole serial into a 32 bit int
{
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); //Returns name of application
string str5 = Convert.ToInt32(str.Substring(0, 6), 16).ToString(); //convert first 7 chars of str to an int, then to a string

if ((versionInfo.FileMajorPart.ToString("0" + versionInfo.FileMinorPart.ToString("00") == str5.Substring(0, 3)) //Returns version info
{
string code = GetCode(); //returns (version*2 in hex) + with volume serial (without dashes)
long num3 = 0L; //new variable...

for (int j = 0; j < code.Substring(6).Length; j++) //loop through the code from above.
{
num3 += (long) code.Substring(6)[j]; //sum up all the values of the code
}
if (Convert.ToInt32(str2, 16) == ((num3 * 999) % 0x7fffffffL)) //recall what str2was as a 32bit int, check if it == num3*999 modulus 2147483647
{
MessageBox.Show("Good Work!!!!";
}
}
}
}
if (menmLicenseType == LicenseType.Demo)
{
MessageBox.Show("Try again!!!!";

personmans
November 9th, 2008, 14:29
(One thing I'm missing is what the Substring(6) does, I THINK it grabs everything after the 6th value, which means it ignores the whole version number thing, and adds up the digits of the volume serial.)
Updated commented code, I'm still not sure what you are doing with this. Are you writing a protection or trying to figure out what it does?

If you are trying to figure it out, write down your computers serial number without dashes and add up the digits of the volume serial.Now multiply by 999 and modulus 2147483647.
This is the number you want to equal.

Now take the 2nd set of characters from the serial number that you have
(say its 11111111-11111111-11111111-11111111)

and run it through the loop at the start of the program:
In this case, you still get 11111111
Then "Convert.ToInt32" it.
And it has to == that number (in bold) above

g_ramzi
November 11th, 2008, 13:33
In fact, i've ripped the code using reflector and i want to make a keygen in order to be able to use it for protecting my program.
Due to its complexity, i want to reverse it than i will use it after making some changes surely.

personmans
November 13th, 2008, 18:44
Quote:
[Originally Posted by g_ramzi;77683]In fact, i've ripped the code using reflector and i want to make a keygen in order to be able to use it for protecting my program.
Due to its complexity, i want to reverse it than i will use it after making some changes surely.


If you are still stuck on making a keygen, please read up on .NET code or get a compiler and see what the results of each variable would be at each step of the program. By looking at the outputs, you will be able to determine what has changed and then make a keygen to copy that functionality.

It seems to me like, in order to make this scheme work, you would have to get the volume serial and version number from the user. -> I would make an option in the program to output these using a reversible encryption and ask the user to email it to you. That way you reverse the encryption, plug the values in your keygen, and provide them with a key.

All in all I don't think this code would make the strongest keys.

g_ramzi
November 14th, 2008, 02:08
Always thank you for the help. I'm still trying to understand the functioning of the code but it is really a little bit complex. I do not lose the hope .