Comments (1)
I wrote some code that tests this and peverify complains if caller's method signature doesn't include the 0 lower bounds that matches the called method's 0 lower bounds.
The reason that the code you're investigating might work is that it seems from your info above that it's a Babel.NET obfuscated assembly. The obfuscator resolves the correct method and then creates the correct code.
C:\arytest>peverify theexe.exe
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
[IL]: Error: [C:\arytest\theexe.exe : main.Start::Method][offset 0x00000001] Unable to resolve token.
1 Error(s) Verifying theexe.exe
C:\arytest>theexe.exe
Unhandled Exception: System.MissingMethodException: Method not found: 'Int32 ns.Class1.Method(Double[,])'.
at main.Start.Method()
Fixing the signature results in everything working again:
C:\arytest>theexe.exe
C:\arytest>peverify theexe.exe
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
All Classes and Methods in theexe.exe Verified.
Here's the code I used:
using dnlib.DotNet;
using dnlib.DotNet.Emit;
....
{
var mod = new ModuleDefUser("themod", Guid.NewGuid());
var asm = new AssemblyDefUser("themod", new Version(0, 0, 0, 0));
asm.Modules.Add(mod);
mod.Kind = ModuleKind.Dll;
var cl = new TypeDefUser("ns", "Class1", mod.CorLibTypes.Object.TypeDefOrRef);
mod.Types.Add(cl);
cl.Visibility = TypeAttributes.Public;
var arg1 = new ArraySig(mod.CorLibTypes.Double, 2);
arg1.LowerBounds.Add(0);
arg1.LowerBounds.Add(0);
var meth = new MethodDefUser("Method", MethodSig.CreateStatic(mod.CorLibTypes.Int32, arg1),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public | MethodAttributes.Static);
cl.Methods.Add(meth);
var body = new CilBody();
meth.Body = body;
body.Instructions.Add(OpCodes.Ldc_I4_3.ToInstruction());
body.Instructions.Add(OpCodes.Ret.ToInstruction());
mod.Write(@"C:\arytest\themod.dll");
}
{
var mod = new ModuleDefUser("theexe", Guid.NewGuid());
var asm = new AssemblyDefUser("theexe", new Version(0, 0, 0, 0));
asm.Modules.Add(mod);
mod.Kind = ModuleKind.Console;
var cl = new TypeDefUser("main", "Start", mod.CorLibTypes.Object.TypeDefOrRef);
mod.Types.Add(cl);
var asmRef = new AssemblyRefUser("themod", new Version(0, 0, 0, 0));
var tr = new TypeRefUser(mod, "ns", "Class1", asmRef);
var arg1 = new ArraySig(mod.CorLibTypes.Double, 2);
// Comment these and the program will fail because the correct method can't be found
arg1.LowerBounds.Add(0);
arg1.LowerBounds.Add(0);
var mr = new MemberRefUser(mod, "Method", MethodSig.CreateStatic(mod.CorLibTypes.Int32, arg1), tr);
var meth = new MethodDefUser("Method", MethodSig.CreateStatic(mod.CorLibTypes.Void),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public | MethodAttributes.Static);
cl.Methods.Add(meth);
mod.EntryPoint = meth;
var body = new CilBody();
meth.Body = body;
body.Instructions.Add(OpCodes.Ldnull.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(mr));
body.Instructions.Add(OpCodes.Pop.ToInstruction());
body.Instructions.Add(OpCodes.Ret.ToInstruction());
mod.Write(@"C:\arytest\theexe.exe");
}
from dnlib.
Related Issues (20)
- Optimize properties on `TypeRef` and `TypeDef` HOT 3
- Import property without using typeof
- HasOverrides Generic Type HOT 2
- PDB Generated is wrong HOT 7
- Linux R2R mixed dll can't be saved. HOT 2
- Single File Executable Error: .NET data directory RVA is 0
- Potential feature: Support for 64 bit offsets and length in dnlib.IO HOT 2
- The precise method for calculating 'RVA'
- Can ITypeOrMethodDef implement IMemberDef? HOT 1
- InvalidOperationException when md rva isn't alignment HOT 5
- dnlib is missing NuGet package README file
- ModuleWriterException: Invalid section RVA HOT 1
- Should we update ReturnParameter when updating ReturnType? HOT 2
- .NET cannot install (UAC prompt when running installer)
- dnlib.DotNet.Writer.ModuleWriterException HOT 2
- "Expected a null constant." error when saving assembly with pdb HOT 6
- Why don't CreateGenericInstMethodSig HOT 25
- I already know how UnknownDeclaringType happen HOT 1
- Sort `ExportedType` table in the same way as the `TypeDef` table HOT 3
- Need to dispose of enumerators
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dnlib.