title: C: Casting function pointers to edit executable code
body: <p>Suppose the following code:</p>
  
  <pre><code>int f1(int x, int y);
  
  int main(void) {
      printf("%d", f1(2,3));
      char* x = (char*)&amp;f1;
      //edit the stuff here?
      printf("%d", f1(2,3));
      return 0;
  }
  
  int f1(int x, int y){
      return x*y;
  }
  </code></pre>
  
  <p>Now, despite the fact that this is really stupid and you'd never <em>practically</em> do it, how would you go about this? If I wanted to make this function add the two numbers, rather than subtract, or even go about something more complex, what steps should I take? How do I figure out what the correct machine code is to get the desired result?</p>