Patch Segment
#549
-
Hi everyone, Please can you help me with this code below, why the patch is not working, it says nothing when executing this code below: /*
simply make : IsSunccessful => true; to IsSunccessful =>false;
*/
var shell = @"path_to_the_assemblyl";
var pe = PEFile.FromFile(shell);
var ad = AssemblyDefinition.FromFile(pe);
var types = ad.Modules[0].GetAllTypes();
var f = types.FirstOrDefault(q => q.FullName.Equals("Application.Result"));
if (f != null)
{
var m = f.Methods.FirstOrDefault(q => q.Name.Equals("IsSuccessful"));
if (m != null)
{
foreach (var i in m.CilMethodBody.Instructions)
{
if (i.OpCode.Code == CilCode.Ldc_I4_1)
{
var sec = pe.Sections.FirstOrDefault(q => q.Name.Equals(".text"));
if (sec != null)
{
var seg = sec.Contents.AsPatchedSegment();
var bb1 = CilCode.Ldc_I4_0.ToOpCode().Byte1;
var bb2 = CilCode.Ldc_I4_0.ToOpCode().Byte1;
var b1 = i.OpCode.Byte1;
var b2 = i.OpCode.Byte2;
var offset = (uint)(m.CilMethodBody.Address.Rva + i.Offset);
seg.Patch(offset, new[] { bb1, bb2 });
sec.Contents = seg;
}
}
}
}
}
pe.Write(@"new_path_to_Assembly"); Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
Washi1337
Apr 15, 2024
Replies: 1 comment 2 replies
-
A couple notes:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something in the lines of the following should do the trick: