public void PrepareEncryptNativeMethods(ModuleWriterBase moduleWriter) { if (methodToNativeMethod.Count == 0) { return; } validNativeMethods = new List <MethodDef>(methodToNativeMethod.Count); int len = 12; foreach (var kv in methodToNativeMethod) { if (kv.Key.DeclaringType == null) { continue; // Method was removed } if (kv.Key.DeclaringType.Module != module) { continue; // method.DeclaringType was removed } validNativeMethods.Add(kv.Key); len += 3 * 4 + kv.Value.Length; } if (validNativeMethods.Count == 0) { return; } len = (len & ~15) + 16; encryptedResource.SetNewResource(new byte[len]); }