300 likes | 468 Vues
Source Code Inspection and Software Reuse. Chapter 7 – Digging into source code Coder To Developer - Mike Gunderloy Respected Professor: Dr. James Fawcett Presented By: Ghanashyam N. Digging Into Source Code.
E N D
Source Code Inspection andSoftware Reuse Chapter 7 – Digging into source code Coder To Developer - Mike Gunderloy Respected Professor: Dr. James Fawcett Presented By: Ghanashyam N
Digging Into Source Code • Looking more deeply at available code can clarify several details that are not immediately evident regarding this code’s functioning • Code inspection helps us use existing code efficiently • Seeing how someone else solved a particular problem can be very helpful in producing more elegant and efficient code
.NET Fundamentals • All .NET code is executed by the CLR • Each of the .NET language compilers (C#, VB .NET, Managed C++ etc.) convert source code into MSIL (and Metadata) • CLR understands only MSIL code and knows nothing about the .NET language that was used to generate this MSIL code
.NET Code Is Open • There are several utilities (Ildasm, .NET Reflector etc.) that allow you to work on MSIL code directly • Thus it is possible to find out quite a bit about .NET code for a library or an application even if its source code is not available
.NET Code Is Open • All the code for .NET FCL is present in the form of MSIL (and Metadata) on any machine that has .NET installed • Thus it is possible to look more closely at the implementation of the .NET FCL • Looking at code for the .NET FCL can prove extremely useful especially when the documentation for a certain FCL class or method is obscure
Using Ildasm • The .NET Framework SDK comes with a tool named Ildasm that allows you to work directly with MSIL code • It displays MSIL code in a somewhat human readable format • Ildasm’s output cannot be easily deciphered even though it is much more readable than MSIL itself
Using Ildasm • Ildasm • Start Menu ► Programs ► Microsoft Visual Studio .NET 2003 ► Visual Studio .NET Tools ► Visual Studio .NET 2003 Command Prompt • Type ‘ildasm’ on command prompt and press enter
Using .NET Reflector • .NET Reflector is available at http://www.aisto.com/roeder/dotnet • It is much easier to use than Ildasm since it displays the source code that was used to generate a supplied .NET assembly • It also has many useful features like decompilation to either C# or VB .NET and display of call trees for any selected method
Reflection | Obfuscation • MSIL, Metadata and Reflection make it possible to do a deep analysis of any .NET application or library, even without source code • Obfuscation aims at protecting intellectual property by taking source code and automatically changing it to make it difficult to understand • Obfuscators typically change class names, member names etc. in the source code to make it very difficult to decipher the assembly generated using this code
Some Obfuscators • Demanor for .NET http://www.wiseowl.com/products/Products.aspx • Salamander http://www.remotesoft.com/salamander/obfuscator.html • Dotfuscator http://www.preemptive.com/dotfuscator/index.html • Species .NET http://www.9rays.net/cgi-bin/components.cgi
Experimenting With Code • There are times when you need to actually run the code to gain a complete understanding of its functioning • But writing a complete VS .NET solution to test the behavior of a simple component is a lot of work
Experimenting With Code • Snippet Compiler http://www.sliver.com/dotnet/SnippetCompiler/ • An IDE that allows you to write code to exercise some small piece of code with minimal overhead • Supports C# and VB .NET • Supports Winforms and ASP .NET • Modest set of features • Gets code up and running quickly
Software Reuse • Try to avoid “reinventing the wheel” • Try and find code that you don’t have to write • There is an astonishing amount of free, high-quality, reusable code out there
Software Reuse • Make full use of the .NET FCL • Code for most of the common programming tasks already exists in the FCL • Hashtables, queues etc. – System.Collections • Event log, performance counters – System.Diagnostics • WMI – System.Management • XML – System.XML • Sending SMTP mail – System.Web.Mail • Reqular Expressions – System.Text.RegularExpressions
Software Reuse • Some Libraries • SQLXML Library http://www.msdn.microsoft.com/sqlxml/ Add-on XML functionality for Microsoft SQL Server 2003 • WSE (Web Services Enhancements) http://www.msdn.microsoft.com/webservices/building/wse/default.aspx Set of implementations of web services specifications such as WS-Security, WS-Routing, WS-Referral etc.
Software Reuse • Some Libraries • Logidex .NET Library http://www.msdn.microsoft.com/sqlxml/ Add-in to VS .NET that lets you locate and download .NET patterns and sample code from within Visual Studio .NET
Software Reuse • More sources of free code • The Code Project http://www.codeproject.com • GotDotNet User Samples http://www.gotdotnet.com/Community/UserSamples
Evaluating Code • Using FxCop http://www.gotdotnet.com/team/fxcop • A code analysis tool that checks .NET managed code assemblies for conformance to the Microsoft .NET Framework Design Guidelines • Can check conformance for third party libraries as well as own classes