Monday, May 14, 2007

System Calls

Found a simple way to isolate system calls versus non-framework calls.

In MSIL, a call instruction includes the fully qualified name. Therefore, using Cecil you can do the following:

if (i.OpCode == Mono.Cecil.Cil.OpCodes.Call)
MethodReference rf = (MethodReference)i.Operand;
if (rf.DeclaringType.Namespace.StartsWith("System"))

Currently considering what architecture is best for storing type/method call frequency which would be more complicated than simple system-calls frequency.


poupou said...

That seems rather a weak way to achieve detection as namespace aren't restricted. Anyone can create their own System.* stuff (even if they shouldn't pollute the namespace) and the core assemblies also include Microsoft.* stuff (generally less important).

In the case of Mono we include non System.* classes into the core libraries (as internals) but they may count, somewhere, toward the importance of the public "system calls".

A better way to detect them would be to find the assembly (.Module.Assembly) and the compare the public key token with the one MS (and Mono) use for ECMA and MS assemblies.

Chris said...

Thanks for the suggestion.