Hacking a .Net Assembly

Ok so as many of my followers will know (if not go read some of my previous posts) i love using local only internet to my advantage because of the fact that its soo cheap. Alas one of the biggest problems that i have had is that there are very few twitter applications that allow you to set your own server, this now puts me at a slight disadvantage , because although there are open source apps they just dont work the way you want.

The Remedy: A Spot of reverse engineering

So this is my quick remedy , hack the app to do what i want.Granted this is not always the best plan but i was not in the mood to re-write and entire app (although i am sure it would have been just as fun) and the current open source one was to slow. The application i decided to reverse engineer is called jata ,please keep in mind that the only reason i used this app was because it was written in .Net and its open source. Also the author has promised to release the source code , i just could not be bothered to wait , when it is released i will update the code where it needs to be updated.

Getting the tools

The main tool we will be using is Reflector , its a free download so  go ahead and grab it now. We also need the file Disassembler add in that will generate the files and project for us. The last and final tool you will need is visual studio or visual c# express.

Getting Started

The basis of this hack is to allow us to use local only twitter , to do that we need to change all instances of www.twitter.com to our address turn.lostninja.co.za.

Steps to follow

  1. Extract reflector to a temp folder for this session.
  2. Extract the File Disassembler add in.
  3. Load the add in by first starting reflector then navigating to View -> AddIns. Click the add button  , locate the dll that was extracted (File Disassembler ) and select it.
  4. If all went well you should see the add in loaded as seen below.

    Addin now loaded

    Addin now loaded

  5. Ensure that Jata is installed then click File -> Open and locate the following dll’s ,TwitterooCore.dll and Yedda.Twitter.dll.
  6. Now as you may have noticed , the application uses the Twitterroo framework for twitter access , if you are feeling lazy you can load the twitteroo project and make the changes there. For the purpose of this post we will be reverse engineering it.
  7. Once the dll’s have been loaded you will see them added to the end of the list as seen below.

    Both the Dll's have been loaded

    Both the Dll's have been loaded

  8. Now right click on each of the assemblies and choose export , this will prompt you for a location to save to. Accept the default or choose your own folders.
  9. Once the exports are complete navigate to each of the folders and load up the C# projects.
  10. Now as stated in the start you will have to do a find and replace on the word www.twitter.com and replace with what ever server you will be using.
  11. Once you are done with the find and replace you now need to build each of the projects separately.
  12. After the builds are complete ( should not take more than a few seconds ) navigate to the build directories and copy the dll’s that were built. Note you can ignore the PDB’s as they are only required for debugging.
  13. Navigate to jata folder and paste the dll’s that we copied in the previous step , windows will now ask you if you want to overwrite the file’s , say yes to all.
  14. That is all (it was for me at least) , if you now start up jata you can now login as normal and access twitter locally using a cooler application :)

I would just like to state now before any hate mail comes in but nothing here is illegal , the steps outlined here have helped me to recover source code after crashes where the latest source code was not available except on the production server. This also helps alot when you have to take over applications that were written by other people but no source code was left behind.

One of the things to keep in mind is the modify assemblies and replacing them will work in some cases like this but not always. It will especially not work if the application has been strongly named and signed. There is ways to bypass thiss but i doubt i will be discussing it here. Unfortunately there is no real way to prevent reverse engineering as a determined engineer will always get through. But it does help to obfuscate code before releasing to the public .Another added mesure is to have critical code reside on a secure server (provided by you) , and clients simply making calls to this server , this approach will not work in larger applications that need scaling but in the beginning it should be enough to keep curious people out.

As always let me know what you think questions and critisim welcome.

~stalkerh

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

3 Comments to “Hacking a .Net Assembly”

  1. StevenMcD 28 January 2009 at 10:08 am #

    very very nice man.

  2. jameel 28 January 2009 at 10:10 am #

    Thanks , much appreciated

  3. Shoban 13 April 2009 at 5:05 am #

    Thanks for the post. Source code is released now ;-)
    -Developer of jata


Leave a Reply