Skip to content

Patch Segment #549

Closed Answered by Washi1337
dashne asked this question in Q&A
Apr 15, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Something in the lines of the following should do the trick:

// Compute method header size.
ulong headerSize = m.CilMethodBody.IsFat ? 12ul : 1ul;

// Determine file offset to patch.
ulong offset = m.CilMethodBody.Address.Offset + headerSize + (ulong) i.Offset;

// Patch section contents (Note: first param is relative to start of section contents).
sec.Contents = sec.Contents
    .AsPatchedSegment()
    .Patch((uint)(offset - sec.Offset), new[] { CilCode.Ldc_I4_0.ToOpCode().Byte1 });

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@dashne
Comment options

@Washi1337
Comment options

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
None yet
2 participants