When I was newbie in .NET, it was a shocked for me to learn that .NET assemblies can be decompile. But today I know that this is a normal situation for a language which is compiling to an intermediate language. As we know that, after compiling a .NET project the output will be in MSIL (Microsoft Intermediate Language). And during the application lifecycle this codes will be compiled to Native Codes by the JIT (Just-In-Time Compiler) when they first used and cached in that computer for the future usages. Anyway this is another subject for us how JIT works, but here the problem is our assemblies are in MSIL format which has about 229 opcodes and all these opcodes has a standard working procedure. So if we know these opcodes and how they are working, we can produce the .NET codes by reverse engineering. This is simply what decompilers do. But why there are no stable decompilers for the native exes?
Most of the people know that switch works like if-else blocks. The only difference between the switch and if-else is its being for the many conditional states, and also writing switch is more simple than if-else block. This knowledge is really a big mistake because switch has a different algorithm and working-procedure comparing to if-else block. To demonstrate this, I wrote a simple example which indicates the performance differences between switch and if-else in many different situations.
In one of my public projects, I used Xenocode PostBuild to obfuscate my codes. PostBuild is a very popular and common Obfuscation Tool for the .NET assemblies. When I worked for the Xenocode, I saw that the developers of PostBuild are really very good at doing their jobs. Most of them had worked for the Microsoft before. So I can say that if you need an obfuscation tool, you can use Xenocode PostBuild obfuscation tool without thinking a second.
Today I wrote a simple application, which shows what the difference is between initializing a static field in the explicit static constructor and doing the same during the declaration time (inline). I know that even when we initialize our static fields inline, the compiler will add an implicit static constructor to that class and initialize static values in that method. But this example showed me that there is really a long time difference between initializing static fields inline and in explicit static constructor. Here are a screenshot from the example – in this example BeforeFieldInit means that the static fields are initialized inline and NotBeforeFieldInit means that static fields are initialized in the explicit static constructor:
For a very long time ago, in one of my projects, I needed to capture the screenshot which must have to support both full screen capturing and specific regional capturing.
Also I need to paste that captured image back to the screen programmatically. At that moment I solved my problem by using some WinApi methods in the user32.dll and gdi32.dll. Here I want to share that code with you.
If you want to find MS SQL Servers which are available in a network, there are two different ways you can use for searching the network for available Sql Servers.
1 – There is a class in the .NET Framework which name is SqlDataSourceEnumerator in the System.Data.Sql namespace. We can use that class, and get the sql servers easly:
DataTable sqls = SqlDataSourceEnumerator.Instance.GetDataSources();
In this method we can only get the Sql Server machines on a network. There is also another method to get list of SQL Servers on a network. Also this second method can also be used to search for some other type of servers too. Here is the second method;
Everybody knows that Reflection is a really very important topic in .NET. So I won’t repeat the importance of it, it is an unquestionable subject; besides, I have to admit that it saved my life too many times.
But like every good thing Reflection has also some disadvantages, too. One of the important disadvantages of the Reflection is performance.
Tonight i uploaded an example about Server-Client applications to the server. The name of the example is B-MSN which is an instant messaging program like MSN, AOL or Yahoo IM.
Some of the specifications of the B-MSN are;
Supports personal image
NetServer and NetClient components which you can also use them as standalone
Flashes window when a new message received
Supports RTF text sending
Informs you while the person whom you chat with is writing a message to you
Supports Saving Message Histories
Since blogs have started to spread as mushrooms in the world of web, I have been thinking about creating my own blog which I can use as a sharing point of some useful and functional codes, ideas, theories about .NET and C#. My aim is not only sharing codes, but also making some discussions inside the depths of the .NET with the people of the .NET, but something always happened to prevent me from creating my own blog space through all these times. Although I persuaded myself that I couldn’t open my blog because of “business”, “time limitation”, etc., I know the real reason has been laziness.