Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 236 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generating assembly code from C# code?

#1
Is there any way to generate assembly code from C# code? I know that it is possible with C code with GAS, but does anybody know if it's possible with C#?
Reply

#2
C# is normally compiled to the .NET bytecode (called [CIL or MSIL](

[To see links please register here]

)) and then [JIT](

[To see links please register here]

) ("Just In Time") compiled to native code when the program is actually run. There exist ahead of time compilers for C# like [Mono's AOT](

[To see links please register here]

), so you could possibly compile a C# program through one of those and then disassemble it. The result is likely to be very difficult to follow.

More likely, you may want to look at the bytecodes which are somewhat higher level than a CPU's assembly code, which you can do by using [ILdasm](

[To see links please register here]

) on a compiled `.exe` of a C# program.
Reply

#3
C# code compiles into MSIL (MS Intermediate Language) which is actually not really asm-code you get from C compiler. Read more about about how .NET Framework applications run.

If you want to look at generated IL code see [this question][1].


[1]:

[To see links please register here]

Reply

#4
You can do this in a bit of an indirect way using the [NGEN][1] tool and then disassemble the binary that is produced. Alternatively you can use a debugger to inspect the JIT code created from the MSIL, [Ollydbg 2][2] is one such debugger able to do this.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#5
You can use [BenchmarkDotNet][1] with the printAsm flag set to true.

[DisassemblyDiagnoser(printAsm: true, printSource: true)] // !!! use the new diagnoser!!
[RyuJitX64Job]
public class Simple
{
int[] field = Enumerable.Range(0, 100).ToArray();

[Benchmark]
public int SumLocal()
{
var local = field; // we use local variable that points to the field

int sum = 0;
for (int i = 0; i < local.Length; i++)
sum += local[i];

return sum;
}

[Benchmark]
public int SumField()
{
int sum = 0;
for (int i = 0; i < field.Length; i++)
sum += field[i];

return sum;
}
}

Which produces:
[![enter image description here][2]][2]


[1]:

[To see links please register here]

[2]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through