Nathan A
Nathan A

Reputation: 11319

Determine if Assembly References Certain Classes

I'm trying to write a function that determines if an assembly contains any code that uses known references. For example, determine if a given assembly uses the Thread class (as part of a method, an argument, etc).

I'm writing a program that consumes third-party assemblies. I am already running the assemblies in a sandbox, but that doesn't stop the code from doing other things, like starting threads (which one of my requirements does not allow). I thought was to scan the assembly once it's loaded into the sandbox, and determine if the Thread class is ever used.

I've done some initial research on using IL to determine that, but I'm wondering if there is an easier way than reconstructing the results of GetMethodBody.

Upvotes: 1

Views: 65

Answers (1)

Zenexer
Zenexer

Reputation: 19613

Try Mono.Cecil. You can inspect everything the code does at the bytecode level.

Upvotes: 1

Related Questions