开发者

How is it posible to read the complete source code from .dll?

开发者 https://www.devze.com 2023-01-22 20:16 出处:网络
Our team has developed the Tool which is used to find the reference\'s of a Changed method in a Project.

Our team has developed the Tool which is used to find the reference's of a Changed method in a Project. 1.We used reflection to read the Namespace,Class Name and Method name's e.t.c. 2.We started to search the method'sbody in cs file's and we stored in a List. 3.We have taken each and every method for finding the Reference's But i have seen the reflector tool which reads the complete source code using .dll's . How to would happen? Is there any way to read the source code from reflection?Please help me regarding th开发者_Python百科is Thanks in advance


Reflector doesn't actually read the source code - because it's not there. Instead, it takes the IL and decompiles it, working out what the source code might have looked like.

That's how it's able to show you code in multiple languages - obviously the code isn't actually written in (say) both VB and C#, but Reflector can show you both by working out what the code does and trying to find source code which would do the same thing.

(It's not always successful, by the way. Sometimes there are bits of IL which are generated by the C# compiler from things like iterator blocks or async methods where there is no direct equivalent valid C#.)


Doing this is actually a multi-step process. All you will get from the DLL or EXE is IL bytecode, which is essentially an abstract machine-language. That IL bytecode may be translated one-to-one to IL assembly language (such as by ILDASM or Reflector's raw IL mode).

The C# language decompiler mode of Reflector takes it a step farther and picks out structure from the code that resembles if/else, while loops, switch statements, etc. and translates that to the corresponding statements. Information about local variable names is not preserved in the IL, so it has to make those up as it goes along; also, some control structures may have been optimized beyond easy recognition, so that tends to result in the production of goto statements. There are also some constructs that don't have direct parallels in the C# language, so you may find unofficial extension keywords such as methodof in the decompiled code.

An interesting exercise is to examine how newer C# code is translated when decompiling to earlier versions of the language. For example, LINQ query comprehensions are translated as method chains over IEnumerable<T>, and lambdas passed to Expression<T> arguments are replaced by a whole bunch of goo to build and pass the abstract syntax tree corresponding to the lambda -- which is in fact what such constructs are translated to by the compiler.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号