PDA

View Full Version : Tools for browsing and decompiling .NET/MONO assemblies


Buzzler
12th Mar 2011, 2:42 PM
If you want to write scripts for TS3 or alter the core, you'll need a tool to browse and decompile the TS3 core assemblies.

.NET Reflector (http://www.reflector.net/)

Reflector has been the top dog in browsing/decompiling .NET assemblies for years; in fact it's been the only tool for it. As of March 2011 the tool has gone pay with the release of version 7. It now costs $35 and needs to be activated. Information on the activation process is sparse; I only know that the tool gets chained to your computer and that you need to deactivate it to use a registration key on another computer. I don't know if the tool can be activated on multiple computers at the same time.

If you're willing to pay for it and don't mind the activation process, it's definitely a very good and mature tool.

You'll have no problem to find download mirrors for version 6.5 of Reflector, the last free version. Reflector is time-bombed, though, and V6.5 installations will cease to work and delete themselves in May 2011.

ILSpy (http://wiki.sharpdevelop.net/ilspy.ashx)

ILSpy is a very young tool, 5 weeks at the time I write this to be precise. Yet the progress it made is nothing but impressive. The analyzer doesn't work for me yet, but the decompiling quality is already very good. See second post for an example.

This tool currently has a downside: You can't limit it to .NET 2.0, so you'll find code that won't compile when you limit Visual Studio to .NET 2.0.

Still, I consider ILSpy a reasonable alternative to Reflector already, and if the development continues at a similar pace, it may even become better than Reflector.

Tools that might become alternatives in the future

Monoflector (https://github.com/jcdickinson/Monoflector)
Last time I checked, Monoflector didn't even have the functionality to open assemblies, so I have no idea what its decompiler is worth.

Announcement for a FOC tool by JetBrains (http://blogs.jetbrains.com/dotnet/2011/02/resharper-6-bundles-decompiler-free-standalone-tool-to-follow/)
This tool isn't even available yet, and it remains to be seen what it's worth if it really gets released this year. JetBrains knows their stuff, though, so it might amount to something.

Got something to add?

If you know any other tool(s), please give a link and post your experience with it. Same goes if you have something to say about the listed tools.

Buzzler
12th Mar 2011, 2:43 PM
Decompilation examples:

Original
private BookSkill FindSkillBook()
{
if (!this.ConfigureAvailableSkills())
{
return null;
}
List<SkillNames> list = HelperMethods.FindSkillsOfInterest(base.Actor).FindAll(delegate(SkillNames names) { return this.mSkillNames.Contains(names); });
SkillNames skillName;
if (list.Count > 0)
{
skillName = RandomUtil.GetRandomObjectFromList<SkillNames>(list);
}
else if (this.mSkillNames.Count > 0)
{
skillName = RandomUtil.GetRandomObjectFromList<SkillNames>(this.mSkillNames);
}
else
{
return null;
}
foreach (BookSkill book in this.mSkillBooks)
{
BookSkillData data = book.Data as BookSkillData;
if ((data != null) && (data.SkillGuid == skillName))
{
return book;
}
}
return null;
}

Reflector
private BookSkill FindSkillBook()
{
SkillNames skillName;
if (this.ConfigureAvailableSkills())
{
List<SkillNames> list = HelperMethods.FindSkillsOfInterest(base.Actor).FindAll(delegate (SkillNames names) {
return this.mSkillNames.Contains(names);
});
if (list.Count > 0x0)
{
skillName = RandomUtil.GetRandomObjectFromList<SkillNames>(list);
goto Label_0057;
}
if (this.mSkillNames.Count > 0x0)
{
skillName = RandomUtil.GetRandomObjectFromList<SkillNames>(this.mSkillNames);
goto Label_0057;
}
}
return null;
Label_0057:
foreach (BookSkill book in this.mSkillBooks)
{
BookSkillData data = book.Data as BookSkillData;
if ((data != null) && (data.SkillGuid == skillName))
{
return book;
}
}
return null;
}

ILSpy
private BookSkill FindSkillBook()
{
if (!this.ConfigureAvailableSkills())
{
return null;
}
List<SkillNames> list = HelperMethods.FindSkillsOfInterest(this.Actor).FindAll((SkillNames names) => this.mSkillNames.Contains(names));
SkillNames randomObjectFromList;
if (list.Count > 0)
{
randomObjectFromList = RandomUtil.GetRandomObjectFromList<SkillNames>(list);
}
else
{
if (this.mSkillNames.Count <= 0)
{
return null;
}
randomObjectFromList = RandomUtil.GetRandomObjectFromList<SkillNames>(this.mSkillNames);
}
BookSkill bookSkill;
foreach (BookSkill current in this.mSkillBooks)
{
BookSkillData bookSkillData = current.Data as BookSkillData;
if (bookSkillData != null && bookSkillData.SkillGuid == randomObjectFromList)
{
bookSkill = current;
return bookSkill;
}
}
return null;
return bookSkill;
}

Evaluation

Reflector
As you can see, Reflector's decompilation utilizes goto calls. It tends to do that now and then, which makes the affected code hard to read. Usually the decompilation is very good, though, and you can see that it had no problem decompiling the anonymous method call in FindAll.

ILSpy
ILSpy managed to decompile without needing goto calls, but it gacked a little on the foreach loop. That code would cause a compiler warning, but it would still compile. ILSpy properly decompiled the anonymous method call in FindAll as well, but it used a lambda expression to do so. That wouldn't compile in a project for TS3, because lamda expressions aren't supported in .NET 2.0, so you'd need to change that if you copy&paste-ed code. On a side note: The EAxian devs don't use delegate calls that much. By the time I write this, I'd see ILSpy's decompilation almost but not entirely on par with Reflector.

DarkWalker
6th Jun 2011, 3:36 PM
A quick heads up, Reflector's 6 series received a final update, Reflector 6.8. It's functionally identical to Reflector 6.6, but doesn't have the time bomb anymore. And, while free for previous free Reflector users, it does require registration.

lenglel
6th Jun 2011, 10:12 PM
does it come with an uninstaller? My butt is still chapped from manually uninstalling reflector
when the time bomb went off. I think I'll stick with ilspy, it does what I want it to do, and *only*
what I want it to do.

cmomoney
6th Jun 2011, 10:27 PM
I used ILSpy for a little while , but went back to Reflector, because i missed the way it searched(and other little things).

Jbob
24th Jan 2012, 7:07 PM
Has anybody used dotPeek .NET decompiler from JetBrains yet I just discovered my version of reflector is not working.

brazilnut
7th Aug 2012, 4:17 AM
Bumping this thread as I have just spent the last 48hrs playing around with every decompiler I could get my hands on to try and decompile Sims3GameplaySystems.dll in full.

Has anyone ever managed to decompile the core dll's to c# from il code so that it can be rebuilt in visual studio. Every attempt at decompiling leaves the code with some fairly ugly irrecoverable syntax errors, including passing uint var to int vars, etc. Impossible to fix by hand.

Anyone know if this has been done?

I'm trying to avoid messing around with il code, and/or injecting redirects to a mod lib.

Thanks very much for you help in advance, even if it is to tell me I'm dreaming and it can't be done! :cry:

Kimsie
17th Jun 2013, 2:15 PM
Does anybody know whether ILSpy has reached the level of Reflector yet?