I'm lazy and I hate doing the same tasks over and over again. Making UI for my crackme solutions is one of such tasks. It always goes like this: open Visual Studio, create new Windows Forms project in C#, drop 2 labels, 2 edit boxes and one button on the form. Set label texts to "Name" and "Serial", set button title to "Generate..", set the project icon, etc., etc..
There must be a better way!
..and it's certainly not the way Blue Indian did his keygen template:
To build this template on your own, open the solution in Visual studio, comment out the calls for uFMOD and implement your own logic, after successful build of keygen, close the Visual studio, open the Form_Main.cs file in any text editor and uncomment those two calls to uFMod, save it. Now double click on the build.bat file to built it finally.
-To change the ICON and XM tune, edit the mini.res (resource file) with any resource editor like Restorator or any of your choice.
Open this, delete those, compile that, and what? I'm already confused, sorry.
Introducing Visual Studio project templates
I'm sure you know that when you click "New project" in Visual Studio, you're presented with number of choices, like "Windows Forms Application", "Console Application", "Class Library" and so on. All these are project templates that are installed by default.
They provide all the files that are required for a particular project type, include standard assembly references, and set default project properties and compiler options. Hmm, that's exactly what I needed! smile
This article at MSDN nicely explains that project template is simply a ZIP file that contains all the necessary files and a special .vstemplate file. This .vstemplate file is an XML file containing metadata Visual Studio needs to display the template in the "New Project" dialog.
Let's try to put it all together.
Making simple keygen template
Here is my keygen for Mr. eXoDia's simple crackme:
Obviously, template should not contain code for specific crackme. Let's change that to something trivial and mark as FIXME:
Now I need to remove all references to crackme name. I will replace them with template parameter $safeprojectname$ in all files. After this change, project won't compile anymore, so you need to be extra careful when changing stuff!
Hardcoding year in the (c) string is not a good idea because I want to use this template in year 2016 as well:
Now I just need to update AssemblyInfo.cs to make sure each project has correct name, (c) and GUIDs:
Did it work? Let's see... File->Export Template, follow the wizard and...
It works. Kinda. The created template still has quite a few references to Mr eXodia's crackme, I'll need to modify project and solution files manually. Unzip the template, fix the files in text editor and ZIP them back. And now it works!
Few more cosmetic fixes (like using $projectname$ where possible), using $if$ and $targetframeworkversion$ to target all .NET framework versions, better namespace names and we have a template that's actually useful.
Download here: https://www.mediafire.com/?sx1i5ba1uijjkii
It's not particularly pretty but that's pretty much what I've been using for 2+ years now - and hopefully it can inspire you to do something similar with your own code. wink