Skip to main content
deleted 2 characters in body
Source Link

What I am trying to do:

I have a programan .exe written in C#. Ilspy shows the code. Inside it has a class DoWork with static field SomeValue:

// Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

// Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have a program written in C#. Ilspy shows the code. Inside it has a class DoWork with static field SomeValue:

// Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

// Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have an .exe written in C#. Ilspy shows the code. Inside it has a class DoWork with static field SomeValue:

// Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

// Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?
added 1 character in body
Source Link
NirIzr
  • 11.8k
  • 1
  • 38
  • 87

What I am trying to do:

I have a program.exe which is written in C#. Ilspy shows the code. Inside it has a class DoWorkDoWork with static field SomeValueSomeValue:

// Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

// Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValueSomeValue is 1515.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have program.exe which is written in C#. Ilspy shows the code. Inside it has class DoWork with static field SomeValue:

//Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

//Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have a program written in C#. Ilspy shows the code. Inside it has a class DoWork with static field SomeValue:

// Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

// Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?
deleted 1 character in body
Source Link

What I am trying to do:

I have program.exe which is written in C#. Ilspy shows the code. Inside it has class DoWork with static field SomeValue:

//Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of thisthe function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

//Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have program.exe which is written in C#. Ilspy shows the code. Inside it has class DoWork with static field SomeValue:

//Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of this function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

//Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?

What I am trying to do:

I have program.exe which is written in C#. Ilspy shows the code. Inside it has class DoWork with static field SomeValue:

//Program.DoWork
public static int SomeValue => 15;

In code, however, it's not a field but a getter function:

// return 15;
IL_0000: ldc.i4.s 15
IL_0002: ret

and I want to modify this function to return 127 instead. I've found the location of the function inside .exe binary dump:

0x123456  1f 0f 2a

I've modified .exe in HxD editor so new binary dump has this:

0x123456  1f 7f 2a

When I open modified .exe with Ilspy it shows:

//Program.DoWork
public static int SomeValue => 127;

So all seems well, but it doesn't work. The modified .exe still runs as if SomeValue is 15.

Questions:

  1. Is this a valid approach to modifying .net assembly?
  2. If yes, what am I missing?
edited title
Source Link
Loading
Source Link
Loading