title: What can be read from memory in a C# application
body: <p>I know that any application running (whether it is built with C#, C, C++, Java, etc) will have elements exposed in memory. I'm curious as to how to control what and how it is exposed in memory?</p>
  
  <p>I'm curious because I know that many games get hacked or modified by a user viewing the contents in memory of the game and altering them. I just want to know more details around how this works. I know special programs must be used to even dive into the memory and there are conversions and stuff that must happen for it to even be some what readable.</p>
  
  <p>Let's take a extremely simple example and I'll ask some questions about it.</p>
  
  <pre><code>using System.Security;
  
  static class Program2
  {
      private static SecureString fSecureString;
  
      public static string fPublicString = "Test123";
  
      private static string fPrivateString = "321tesT";
  
      static void Main2()
      {
  
      }
  }
  
  class TestClass
  {
      private string fInstancedPrivateString;
      public TestClass()
      {
          fInstancedPrivateString = "InstancedSet";
      }
  
      private string DoSomething()
      {
          return fInstancedPrivateString.ToLower();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Given the code above, I imagine that fPublicString is pretty visible to see. What elements can someone reading memory see? Can they read the variable name or do they just see an memory address and an assigned value (Test123). What about Functions like DoSomething that are inside an instanced class? Can someone see that in memory and write malicious code to execute it at their will?</p>
  
  <p>I'm just curious as to how much of this I need to keep in mind while writing applications (or games). I understand the general idea of the accessor properties (public/private/etc) and their relation to other code having visibility to it, but I'm curious if they have any bearing on how it is represented in memory.</p>
  
  <p>My final question will be very specific: EverQuest (game) has a hack called MacroQuest which from my understanding reads memory by having the proper offsets and can then execute code from the EQ client side or simply change values stored in memory for the client. How did EQ get this so wrong? Was it poor programming on their end? A technology limitation that is sort of resolved now? Or can this technically be done with virtually every piece of software that is written with the right amount of knowledge?</p>
  
  <p>Over all I guess I could probably use a good tutorial, article, or book that provides some details on how code looks in memory etc.</p>