Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. public class TestClass
  2. {
  3. public int Value { get; set; }
  4. }
  5.  
  6. public class InjectorClass
  7. {
  8. public int Value { get; set; }
  9.  
  10. public void SetterInjecter(int Data)
  11. {
  12. Value = ~Data;
  13. Console.WriteLine("Hello from injected setter!");
  14. }
  15. }
  16.  
  17. Type testType = typeof(TestClass);
  18. Type injectType = typeof(InjectorClass);
  19. Injector.Inject(testType.GetMethod("set_Value"), injectType.GetMethod("SetterInjecter"));
  20. TestClass test = new TestClass();
  21. test.Value = int.MinValue;
  22. Console.WriteLine("test.Value == {0}", test.Value);
  23.  
  24. [StructLayout(LayoutKind.Explicit, Size = 4)]
  25. public struct IntByte
  26. {
  27. [FieldOffset(0), MarshalAs(UnmanagedType.I1)]
  28. public byte _0;
  29. [FieldOffset(1), MarshalAs(UnmanagedType.I1)]
  30. public byte _1;
  31. [FieldOffset(2), MarshalAs(UnmanagedType.I1)]
  32. public byte _2;
  33. [FieldOffset(3), MarshalAs(UnmanagedType.I1)]
  34. public byte _3;
  35.  
  36. public IntByte(int From)
  37. {
  38. string bits = Convert.ToString(From, 2).PadLeft(32, '0');
  39. _3 = Convert.ToByte(bits.Substring(0, 8), 2);
  40. _2 = Convert.ToByte(bits.Substring(8, 8), 2);
  41. _1 = Convert.ToByte(bits.Substring(16, 8), 2);
  42. _0 = Convert.ToByte(bits.Substring(24, 8), 2);
  43. }
  44. }
  45.  
  46. public class InjectorClass
  47. {
  48. public IntByte Value { get; set; }
  49.  
  50. public void SetterInjecter(int Data)
  51. {
  52. Value = new IntByte(~Data);
  53. Console.WriteLine("Hello from injected setter!nnbyte 0: {0};nbyte 1: {1};nbyte 2: {2};nbyte 3: {3};nn", Value._0, Value._1, Value._2, Value._3);
  54. }
  55. }
  56.  
  57. dynamic a = new IntByte(1);
  58. int b = a;
  59.  
  60. public class InjectorClass
  61. {
  62. public IntByte X { get; set; }
  63.  
  64. public void SetterInjecter(int Data)
  65. {
  66. X = new IntByte(~Data);
  67. Console.WriteLine("Hello from injected setter!nnbyte 0: {0};nbyte 1: {1};nbyte 2: {2};nbyte 3: {3};nn", X._0, X._1, X._2, X._3);
  68. }
  69. }
Add Comment
Please, Sign In to add comment