Questions tagged [cil]
Common Intermediate Language is the object-oriented assembly language used by the .NET Framework, .NET Core, and Mono. .NET languages compile to CIL, which is assembled into an object code that has a bytecode-style format.
1,518
questions
0
votes
2
answers
49
views
Is there any personally identifying info in compiled .NET code?
Not that I have anything to hide :), but if I compile and deploy my .NET code, is there any way anyone (MS, government), can determine any information about the author by examining/decompiling the IL? ...
0
votes
0
answers
46
views
Why CIL of lambda is more complex than local function? [duplicate]
C# code:
void Foo() => Console.WriteLine("Foo");
Action a = null;
a += Foo;
a += () => Console.WriteLine("Bar");
Compiled CIL code:
// [10 9 - 10 18]
IL_0001: ...
0
votes
1
answer
72
views
How to compile a .NET Core C# project to raw IL code?
I'm trying to set-up a C# project that outputs raw IL code instead of a .EXE. The output file should either look something like this:
IL_0000: nop
IL_0001: ldc.i4.5
IL_0002: stloc.0 ...
1
vote
0
answers
49
views
Allow only non-assignable variable as function parameter
I have two functions, Source() and Sink().
Source() is creating new objects, Sink() is acquiring them.
As soon as Sink() is called, no other (accidental) use of the object should be possible.
...
0
votes
1
answer
97
views
Weird behaviour with switch statement in catch block
I'm currently working on a .NET Obfuscator and in my control flow obfuscation I'm noticing a weird behaviour. Somehow there is an inconsistent stack size in my generated code.
Original IL:
{
....
0
votes
1
answer
75
views
Why does the C# compiler handle empty async Task methods different to just return Task.CompletedTask?
Hello,
Edit: the post was edited to not use empty methods to be more clear about what I want to know.
Is there a reason why the C# compile does not compile a async Task method without using await to ...
1
vote
1
answer
80
views
Stack merge points and managed pointers in the CLR
My understanding is that the .NET CLR is allowed to run "unverifiable" and "verifiable" bytecode. However, in both cases, the bytecode must be "correct CIL" in terms of ...
0
votes
1
answer
67
views
Is there a way to make debugger work with modified assembly
I am trying to modify assembly before using it.
Main file:
using IlGenTestTarget;
using Lokad.ILPack;
using System.Reflection;
using Mono.Cecil;
using IlGenTest;
Assembly inAssembly = Assembly....
1
vote
1
answer
74
views
How to hide C# class from custom IL Inspector?
I am currently working with a piece of software known as Kofax TotalAgility or KTA for short.
This is Business Process Automation Software, which I have the "pleasure" of expanding with ...
0
votes
1
answer
53
views
How to set Cil.useLogicalOperators to true?
Consider this code
Open Cil
Cil.useLogicalOperators := true
let fct op =
match op with
LAnd|LOr -> true
| _ -> false
I'm trying to use LAnd and LOr from the ...
0
votes
0
answers
64
views
How can I handle an error on installing SELinux policy
Now I'm trying to install SELinux policy that I made.
But I met error like follow:
Failed to resolve filecon statement at /var/lib/selinux/targeted/tmp/modules/400/mypolicy/cil:303
semodule: Failed!
...
0
votes
0
answers
50
views
Is there a way to evaluate individual Msil instructions?
Background:
I am using dnlib to build a deobfuscator for an unknown custom done Obfuscator in c#. The obfuscated code has large amount of mathematical expressions that define constants for things such ...
0
votes
1
answer
143
views
Is there a way to directly decompile a C# program to IL? [duplicate]
I'm creating a program that converts IL byte code to another language. But I'm stuck on the first part: getting that IL byte code.
I want, directly from my program in C#, to be able for the user to ...
0
votes
0
answers
37
views
How Json.Net/NewtonsoftJson decides on how to serialize/deserialize depending on platform AOT or JIT
I'm profiling newtonsoft json inside unity, on my android device with 2 different scripting backend, Mono which supports IL Emit or in another words, code generation. But also IL2CPP, which does not ...
1
vote
1
answer
58
views
Why is callvirt used to call a method on a readonly field of generic type
Consider the following:
interface ISomething
{
void Call(string arg);
}
sealed class A : ISomething
{
public void Call(string arg) => Console.WriteLine($"A, {arg}");
}
sealed ...
0
votes
0
answers
135
views
ByteCode manipulation with ASM on .NET & C#
After using ASM on Java language, is there a faint way to use our byteCode manipulation module (insert some custom code) on .NET and C # platforms, through some sort of workaround? Anyway, we would ...
0
votes
0
answers
80
views
Modify IL during compilation: Workaround for declaring a constant custom struct
I'm writing a library for ternary computing, based on Trits instead of Bits. Trits can have three values. Sometimes represented as 0,1 and 2, sometimes as -1, 0 and 1. I've called them Down, Middle ...
0
votes
0
answers
119
views
How to translate this IL Code to Reflection.Emit in C#?
This is the IL code I'm trying to translate to C# without succes:
.assembly _
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (...
3
votes
1
answer
58
views
Is IL instruction "cpobj" applicable for reference types?
Microsoft Docs says:
The behavior of cpobj is unspecified if ……, or if classTok does not represent a value type.
But ECMA 335 says:
If typeTok is a reference type, the cpobj instruction has the ...
1
vote
0
answers
238
views
How to create "System.Runtime.CompilerServices.DefaultInterpolatedStringHandler" type dynamically in C#?
I am trying to create dynamically a type System.Runtime.CompilerServices.DefaultInterpolatedStringHandler in C#.
I try:
var inst = Activator.CreateInstance(type);
type is System.Type = System....
-1
votes
1
answer
238
views
C# Harmony transpiler crashing when using Call or CallVirt
I'm attempting to mod a game, and I'm using Harmony 1.2.0.1. I've been attempting to use a transpiler to add a separate condition to an if statement, however when the method that I am patching runs, ...
1
vote
1
answer
109
views
IL switch instruction
I am researching IL code which generated from this C# code (RELEASE):
int a = Convert.ToInt32(Console.ReadLine());
switch(a)
{
case 1: Console.WriteLine(); break;
case 2: Console....
0
votes
1
answer
320
views
How to run a .dll test suite with CMake and Microsoft Unit Test Framework
In a CMake project, I generated a C++/CLI project and a testing SHARED library according to this post
CMake for integrated Microsoft Unit Testing Framework (VS2017)
I am trying to run the tests, but ...
0
votes
1
answer
123
views
MSBuild Ignore absent <TargetFrameworks> for every .csproj in .sln?
The project that I've cloned locally uses the following dependencies:
<TargetFrameworks>netstandard2.0;MonoAndroid10.0;Xamarin.iOS10;Xamarin.Mac20;netcoreapp3.0;netcoreapp3.1;net40;net45;net46;...
0
votes
1
answer
94
views
Call a System.Action in a .NET dynamic method
I have a function that is building a dynamic method. As part of this dynamic method, it is calling an action known at generation time. As a minimal reproducible example, consider the following C# code:...
0
votes
0
answers
49
views
On what .NET version can a C#10 assembly run? [duplicate]
I am doing C# again since not touching it a few years. I can't seem to find information about what the minimal .NET requirements are for running a C#10 or 9 assembly. I.e. if I build a .NET core 3.1 ...
1
vote
0
answers
41
views
Is the CIL evaluation stack op change description "PopI8+Pop8" a spec bug?
In the CIL/MSIL ECMA-335 spec, there's a list of descriptions used in the opcode.def file Stack Behaviour column to describe what values are popped off the runtime stack for each op. Page 483 of the ...
0
votes
0
answers
35
views
Automatic stack management in Mono.Cecil
is there a way to make Mono.Cecil automatically pop things off the stack when they're not needed? For example, if I store a value on the stack to a variable and then forget to pop it off the stack, ...
1
vote
1
answer
81
views
Generating modopt using Reflection.Emit in Calli instruction
I'm trying to use Reflection.Emit to generate the code for Call method of following code:
public unsafe class Program
{
public struct ATest
{
public int Test;
}
public ...
1
vote
1
answer
65
views
Why does passing elements of an array by reference explicitly cause assignment operations in IL?
I created the following SSCCE:
Module Module1
Sub Main()
Dim oList As ArrayList = New ArrayList()
oList.Add(New Object())
For Each o As Object In oList
subA(oList)
Next
End ...
0
votes
0
answers
111
views
How to output IL for the CLR to run?
I'm currently designing a CLR-compatible programming language. I wrote the parser in ANTLR and would now like to build a .NET assembly out of the code. Currently I use AssemblyBuilder and co. to ...
1
vote
1
answer
212
views
How to generate C# code from IL Instructions
I'm trying to generate c# code from IL instructions using the dnlib library.
The code I'm trying to generate is this one:
private string GetIp()
{
return new WebClient().DownloadString("https:...
3
votes
1
answer
133
views
How to get the constant string length without making a system call?
A sample code:
const string UtcTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffZ";
public byte[] UtcTimeAscii => Encoding.ASCII.GetBytes(DateTime.UtcNow.ToString(UtcTimeFormat));
Here's what I got ...
1
vote
0
answers
215
views
System.InvalidProgramException: JIT Compiler encountered an internal limitation. (CIL/MSIL)
I am attempting to write a toy CLR compiler for an existing language (Haxe).
When you assign a local/variable to a method (e.g. var x:String->Void = System.Console.WriteLine), it creates a wrapper ...
1
vote
0
answers
50
views
Evaluating a compiled expression tree is sometimes slower
I generate an expression tree containing simple math expressions. The expression types are limited to constants, variables, addition, subtraction, multiplication, division, negation, sqrt and a few ...
0
votes
0
answers
52
views
Add or modify method body CIL code from bytes
I would like to add methods or modify methods body of an assembly.
I have the array of bytes containing the CIL code.
Is there a library that does this job ?
Mono.Cecil does it, but only from the ...
0
votes
0
answers
73
views
How to Reference Edited Interop Assemblies
I have been working through Enumerating Windows Portable Devices in C#, which among other things says to edit a Runtime Callable Wrapper (RCW) generated for the PortableDeviceApi COM object, since the ...
4
votes
1
answer
122
views
Why casting double to double emits conv.r8 IL instruction
Is there any reason for the C# compiler to emit a conv.r8 when casting from double -> double ?
This looks to be completely unnecessary (casting from int -> int, char -> char, etc) does not ...
2
votes
1
answer
1k
views
Dotpeek ISSUE: unable to decompile the method
Why can't dotpeek decompile the method in the dll?(unable to decompile the method
)?
// ISSUE: unable to decompile the method.
public ChildModel ChildModel
{
get => this.\u003CChildModel\...
1
vote
1
answer
256
views
What are the managed stack and the managed heap?
MSDN's C# docs uses the terms stack and heap (eg. when talking about variable allocation).
It is stated that these terms means different memory spaces with well defined purposes (eg. local variables ...
0
votes
0
answers
52
views
Using objects compiled with /NOAUTOINHERIT inside c# projects
I have a DLL containing an empty object which I want to use as a base object. This object was compiled directly from cil using ilasm.exe with /NOAUTOINHERIT, so it does not inherit from System.Object. ...
2
votes
1
answer
130
views
Replacing a class field's value via IL
In my effort to learn and understand IL I'm trying to replace the value of a private field in an object, however it's not working.
public class Example
{
private int _value;
}
private delegate ...
1
vote
0
answers
75
views
How to resolve member addresses of IL code during runtime
I am currently investigating a protected .NET malware.
I am working on a PE file that is using the same kind of protection.
It decrypts its IL code during runtime.
I know a piece of the true IL code.
...
0
votes
2
answers
250
views
How do I compile raw IL code from a single string?
I am trying to write an MSBuild task that lets me inline IL code into methods, similar to Glenn Slayden's answer to this question. I have written code to decompile and modify the IL, but I don't know ...
-2
votes
1
answer
124
views
Could not load file or assembly 'FSharp.Core'
I'm trying to compile a program from IL to exe on GNU/Linux, but can't explain how to dynlink FSharp.Core.dll. I tried to copy and paste it to the same directory where .exe is built, but no luck. I'm ...
-1
votes
1
answer
72
views
I tried to modify the IL of the System.String.Concat method through the ICorProfilerCallback interface, but something went wrong
I try to modify the IL of the System.String.Concat method through the ICorProfilerCallback interface, and add my own tracking code before the method is executed。
I modified the IL of other methods and ...
1
vote
0
answers
171
views
Hooking a function from an injected DLL into an existing method at runtime in C#
First off, i am not trying to hack any game. I want to be able to create mods for games written in C# without mod support.
Lets assume the game contains this simple class:
namespace Game
{
public ...
0
votes
1
answer
98
views
Is generating .pdb files for third-party dlls helping with source-stepping during debugging if IgnoreSymbolStoreSequencePoints flag is set?
Background to my question:
I have a third-party library which I want to debug, it has IgnoreSymbolStoreSequencePoints flag for the DebuggableAttribute. It can be assumed that there were compile-time ...
0
votes
1
answer
49
views
I want to using Cecil to create an Action<,> , but i don`t know how add genericity parameter
I want to add an Action<,> filed On my class create by using Mono.cecill.
But i can`t get the type of uncertainty.
How do i create it?
I wrote it like this, but it's wrong:
var ...
2
votes
2
answers
812
views
How do I use Harmony to repeatedly replace an arbitrary method?
I need to replace a method with a call to a method with the same signature so that I can essentially replace the original method with a new method. Currently, I have the code below, which works, but ...