Hack .NET Framework : Use private classes to fulfill your need

Lutz Roeder's Reflector is the most useful .NET utility ever built. It has helped me many times in the past to browse through compiled code and use it correctly. Since it decompiles the code and shows the code inside, it is actually better than help files or any other form of documentation on any assembly. If you use the Reflector then you can find that .NET framework itself has many private utility classes built into it which are used by the public classes but as a developer we cannot use it. Reflector will let you find a lot of those classes which can be instantiated and used via Reflection.

Lets take the example of System.Security.Util is a private namespace in mscorlib which has a class called Hex. This class can encode and decode hexadecimal string. Since it is a reusable class we should use it when required rather than writing a new class. See the Hex class below in Reflector

Reflector_hiddenclass

Now this looks like a pretty useful class. But its private, how do we use it? In order to do so we can get hold of the private type via reflection like this:

    Type type = Type.GetType("System.Security.Util.Hex, mscorlib");

Then we need to get a hold of the method ( in this case the class is static so are its method ).

    MethodInfo
encodeHexString = type.GetMethod("EncodeHexString", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

We now have the method and all we need to do is to invoke it. Since the method is static it will not need any object as reference when invoked.

    List<object> parms = new List<object>();
    parms.Add( Encoding.ASCII.GetBytes("This is to be converted to hex"));

    string encoded = (string)encodeHexString.Invoke(null, parms.ToArray());

Here we have invoked the method of a private class in an assembly and got output from it. Ain't that nice!

In order to make things simpler you can write a wrapper class around and use it to instantiate and call the private classes or private  methods of any class.

This sample contains such a class and here is how easy it is to use it. In the next code block we are converting a string to hexadecimal format and then getting it back to original format using the private Hex class.

HiddenType wrapper = new HiddenType("System.Security.Util.Hex,mscorlib");

string originalString = "This is a string";

Console.WriteLine("Original string is \t: {0}", originalString);

byte[] bytes = Encoding.ASCII.GetBytes (originalString);

string encodedString = (string) wrapper.InvokeStaticFunction("EncodeHexString", bytes);

Console.WriteLine("Encoded string is \t: {0}", encodedString);

byte[] decodedBytes = (byte[]) wrapper.InvokeStaticFunction("DecodeHexString", encodedString);

string decodedString = Encoding.ASCII.GetString(decodedBytes);

Console.WriteLine("Decoded string is \t: {0}", decodedString);

The code sample can be downloaded below. Keep on reflecting ...

Download PrivateClassDemo.zip

Technorati Tags: , ,

kick it on DotNetKicks.com


Run multiple websites in Windows XP with IISAdmin.NET

The IIS in Windows XP does not let you add more than one site to the IIS. With IISAdmin.NET you can add multiple websites to your IIS in windows XP. However only one site can stay active at any time.

Iisadmin_2
This article at CodeProject uses Directory services to create a web site.
If you take a look at the image on the right you can see a screenshot of how to create a site using this tool. But the site must be started from this IISAdmin application.

This is very convenient for a ASP.NET developer who needs to work on multiple websites at his own development environment and uses XP.

Iis

Once the site is created you will see multiple sites in your IIS like in the Image on the left and  it can be seen that only one site is running.


Related
Computer based companies provide internet marketing program. These companies provide many promotional programs and services including seo services. Other than these services they used to affiliate the organizations by providing web hosting service. As most of the people who are new to web design strategy feel uncomfortable in knowing different services. Then such people are provided by shared hosting services due to which they get much of experience of different web services. Some famous companies launch affiliate program which provide a platform for small firms for promotion. Few technologies like ip phones decrease the communication gap within these services and provide a cheap communication path for them.


Hack Your Router With DD-WRT

Ddwrt   Today I found this site where anyone can upgrade their router via firmware patch. Most normal routers can be patched and turned into this feature rich, user friendly powerful router. There is this project called DD-WRT where one can get a patch for the routers.

Unfortunately there was no patch for my router model to upgrade to. So for now I have to stick with the old router ( ASUS WL520g ). But anyway this was a really cool hack.


The Ultimate Blog about Dhaka

I was born in  Dhaka city, the capital of Bangladesh. Although I am living in Kuala Lumpur right now, I cannot seem to forget Dhaka. Anyone who has grown up in Dhaka will find this blog at blogspot to provide a very nostalgic feeling.

http://dhakadailyphoto.blogspot.com/ is a site where a retired Civil Engineer Mr. Ershad Ahmed has put in thousands of images from Dhaka. This is a wonderful blog where one can find pictures of his childhood School ( I did ),  the playground, the roads etc. The site has an very large repository of images. It also contains the history of Dhaka and many pictures historical elements in Dhaka from past and present. If you want to travel to Dhaka visit this blog and go through it, you will know Dhaka. This blog is a treasure cove for the Dhaka dweller.


Bangla Forums and Blogs

Image:Flag of Bangladesh.svg  Although there are a huge number of people who's native tongue is Bangla (Bengali) in computing world it has been a late comer. This probably had to do something with the region not being financially viable for internationalization of popular softwares and Bangla always have had quite a quarrel with keyboard layouts, font and scripts. Anyway with Unicode being more popular it has become quite a standard and more and more Bangla sites have come into being. I am going to mention a few top ones that I like.

Somewhereinblog.net is a mix between a forum and a blog and it is quite popular. Typing in Bangla is quite easy at this blogsite although Opera browser is not supported yet.

Sachalayatan.com is a online writers community where I was able to find some good articles and writings. But it has a closed door policy and from the site policy and the practice of the moderators it seems that the site is only for a people with a certain mental blend or Philosophy. Its seems in order to be open-minded the site owners have made it a place for people with similar mental structure rather than being open to all kinds of input.

চলো বাংলার গান গাই.

Releated Link: Bangladesh, Bangla

Information Improvisation

If you were fully loaded with information in computer technology then test 50-694 would be easier for you. Another famous test preparation of CCNA-IT is included online on different site holding 640-802 certificates. Different other online websites provides preparation guidelines for certification of 3M0-701. Other than these certificates, SNIA S10-200 practical questions and answers are also provided by different sites. Juniper examination preparation and certification of JN0-201 is also provided online. Other than this certification, real IBM 000-859 holds 120 questions and their answers that really helps in your examination.


The facebook revolution

One could try to imagine what is behind all the facebook screaming around the world. Whats so great about it? Well ... the thing about this application is that ... its about people, its about you and me.

There are so many social networking sites ... facebook seems the like the perfect one. I found my all classmates from grad school in a matter of hour and days. I was connected in a matter of days, got to know what my friends are doing, who has how many kids, doing what, who traveled Europe this summer, got to see their traveling pics. It felt so ... good. But thats not all. They have "Privacy" implement the right way.

Facebook has a public API which exposes their user database and there are so many wonderful applications written around this API that facebook is like the best widget source. Personally I think Facebook has much better widgets than all these ajax based start pages around like Pageflakes, Netvibes, iGoogle. For example you can have a movie application in Facebook and see what your friends and family, co-workers are thinking about the movie you just rated.

Recently New you times had this article written on the Facebook Revolution. The article is titled OMG my mom joined facebook!!. A must read.

Thoughts Aside

Latest direct marketing techniques through email marketing involve electronic media. Few of the electronic marketing companies are offering cheapest domain name in order to promote their electronic services. Their main service is web hosting in which they provide different companies links. These business web hosting is now becoming more popular for marketing product and services. These websites or companies provide tools for web design that helps in designing personal websites. These companies provide backup for recovering their lost data.


FrameworkX.ObjectSpace ( A smart and easy Object Relational Mapper)

FrameworkX is a ORM Libary that was written in .NET.  Written in .NET 1.1 first then it was rewritten in .NET 2.0.

Unlike other ORMs which design the database first then use clases and configurations file to generate classes and Data Access Layer, FrameworkX takes a different approach. Here Entity classes are defined and the their data types defined in the class using attributes and even foreign key are mapped with Attribute. Then any kind of query, even table creation can be done using the class library only.

Its real easy to use. Download FrameworkX.zip (329.8K)


'My visit to Swaziland

 Africa!!

I had a wonderful journey to Swaziland a few weeks ago. I loved the people of Swaziland, they were very friendly and warm. The American movies seem to give you very bad idea about black people. That may be true about American blacks but not true about African black people. They are very friendly and warm. Since Swaziland is a land of only 1 million people that also added to people being nice. Africa is a beautiful continent. Maybe Africa does not have the wonderful landscape like Asia or America, but has something different to offer. If you travel miles after miles in Africa may be you’d be able feel that the continent has a heart of itself. If you feel the beat of that heart then you would understand the wonderful bliss.

Perfect Weather

Anyway I had some misconceptions about how Africa is like, it must be terribly hot in there with Lions and Elephants with very little touch of civilization. No that certainly is not the case. Its quite cold in Swaziland and I heard 4 years ago there was snow. I loved the weather, its perfect. Most of the time you would feel chill in the air, which I really like. But it can start raining anytime, or get hot with bright sunlight. One may even experience cold, fog, rain and hot in the same day. One particular thing about Africans intrigued me, that they cannot stand cold. Although they are living here all their life they seem to be wearing sweaters and leather jackets to stay off the cold but I was walking around with a simple shirt, my friend wore a T-shirt only.

I have had a wonderful time in Africa. Maybe I will visit Africa again.


In the name of Islam !!!

Written in reaction to the serial terrorist bomb blast in Bangladesh. Only 2 persons were injured.

I really fail to understand how can a Muslim can kill innocent civilians in the name if Islam! Islam is a religion of peace and how can someone who has read The Quran and knows the life of the Rasul (Peace be upon him) can do such horrific things.

If someone want to carry out Jihad they would have to have the correct ground for that and that must be conducted in a correct way. Killing innocent people randomly is such a horrific act and Islam does not support this by any way. I cant think of the punishment in afterlife for the people who carries out these aimless violence.

It is true that Muslims are tortured, humiliated in various parts of the world by westerners. But that does not give anyone rights to carry out aimless attacks. Nothing does.

The strangest thing that I find is how some people read The Quran and even after that they fail to understand the value of life, a soul. There are places in the world where being a Muslim is a crime and one may die for that, but to take a life without reason is a serious sin. When a person kills a fellow human being for unjustified reasons ( self protection, punishment for murder etc are valid reasons) it is a sin of huge proportions.

It may be hard for a westerner to grab the idea why Islam is a religion of peace with all these media hype of terrorism. But I find it hard to believe that a Muslim who has read The Quran can kill innocent people unjustifiably. Because at first he must know what Islam is all about. There are places in The Quran where people are to carry out Jihad in the ways it should be carried out and not to be carried out by unjustified means. These are highly horrific means that people are executing.

May Allah help everyone to see the right path.

All praise is due to Allah, The Lord of the Worlds.

Independent Thought

Practical exams of HP0-683 hold all the questions related to information technology. This is the practice link for the Hewlett Packard exams. Similarly, the different site provides the juniper exam certification holing practical number JN0-541. The site allows different practical answers to various questions as HP0-727 hold answers of question regarding Hewlett Packard Company. Different companies include link to HP0-438 examinations, which is also a computer-based exam. The certification allows the students to enhance their information further in certification of 642-452. Other certifications that the site announces recently are numbered as 70-235.