Perfect crime
So, there's a tiny logic bug in someone's code that you need to fix but the code has changed quite significantly and you don't want to have to go back through subversion logs?
- Download the existing dll from the production server
- Disassmble the dll using ildasm (ildasm /out:code.msil code.dll)
- Use notepad to insert the fix you need in MSIL. Ildasm conveniently pads line numbers in the disassembled code so if you're lucky you can insert code without having to change any existing line number references.
- Reassemble the code and deploy (ilasm /DLL code.msil)
- Try not to act surprised that all those years of writing compiler and reflection.emit code came in handy yet again!
- Hope no-one notices.
// Original C#
ViewData["CODE"] = string.IsNullOrEmpty(id)
? GetCookieValue("CODE") : id.ToUpper();
// Original IL
IL_001b: ldarg.0
IL_001c: ldstr "InviteCode"
IL_0021: call instance string GetCookieValue(string)
IL_0022: dup
IL_0023: starg 1
IL_0026: callvirt instance void set_Item(string, object)
// Fixed C#
id = string.IsNullOrEmpty(id)
? GetCookieValue("CODE") : id.ToUpper();
ViewData["CODE"] = id;
// Fixed C# (more compact)
ViewData["CODE"] = string.IsNullOrEmpty(id)
? id = GetCookieValue("CODE") : id.ToUpper();
// Fixed IL
IL_001b: ldarg.0
IL_001c: ldstr "InviteCode"
IL_0021: call instance string GetCookieValue(string)
IL_0022: dup
IL_0023: starg 1
IL_0026: callvirt instance void set_Item(string, object)