Skip to content

CilInstruction raw Bytes #599

Answered by Washi1337
dashne asked this question in Q&A
Discussion options

You must be logged in to vote

It depends on what you need / what your situation is.

If the instruction is stored in a method body that exists in an input binary, you can just read out the raw bytes of a method body and carve out the instruction from there:

CilMethodBody body = ...;
CilInstruction instruction = ...;

// Get a raw method body code reader.
var bodyReader = body.Address.CreateReader();
var rawBody = CilRawMethodBody.FromReader(ref bodyReader);
var codeReader = rawBody.Code.CreateReader();

// Read raw bytes of single instruction.
byte[] instructionBytes = new byte[instruction.Size];
codeReader.RelativeOffset = (uint) instruction.Offset;
codeReader.ReadBytes(instructionBytes);

// Print
Console.WriteLine($"I…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dashne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question dotnet Issues related to AsmResolver.DotNet
2 participants