title: Getting module name from thread information
body: <p>I'm attempting to get the module name for each thread in a process. Process explorer shows the name of the module associated with each thread no problem. I can enumerate all modules and all threads in my current process with no problems, and get data related to them. My current method of deducing the associated module is the following:</p>
  
  <pre><code>if(module.BaseAddress &lt; thread.StartAddress &amp;&amp; (module.BaseAddress + module.BaseMemorySize) &gt; thread.StartAddress)
  {
      // this is our module ;)
  }
  </code></pre>
  
  <p>Unfortunately, that doesn't seem to be a concrete way of doing it. The xfire_toucan.dll module shows in procexp fine:</p>
  
  <pre><code>1972 : xfire_toucan.dll!ToucanSendGamestatsConsoleLine_V1+0x80
  </code></pre>
  
  <p>In the list of modules, it shows with a base addr of <code>0x10000000</code> and a size of <code>0x26b000</code>, giving us a max memory addr of <code>0x1026b000</code>. However, the associated thread start address is <code>0x775e2ca0</code>, which is part of an allocated block of memory in the process outside the module's main memory range.</p>
  
  <p>Any idea how to get the module like ProcExp does?</p>
  
  <p>I know C and C#, so either is fine, but my project is C# so that's preferred :]</p>