title: How to access read-only (static const) data of shared library from C/C++ program with known OFFSET
body: <p>I have installed libgcrypt shared library. libgcrypt.so file is generated .
  It has some read-only data.</p>
  
  <pre><code>./configure   ( without -g option for debug symbol)
  make install 
  
  
  static const u32 encT[256] =
    {
      0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6,
      0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
      0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
  ...
  
  }
  
  static const struct
  {
    u32 T[256];
    byte inv_sbox[256];
  } dec_tables =
    {
      {
        0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a,
        0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b,
        0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5,
        .....},
  
      {
        0x52,0x09,0x6a,0xd5,0x30,0x36,0xa5,0x38,
        0xbf,0x40,0xa3,0x9e,0x81,0xf3,0xd7,0xfb,
        0x7c,0xe3,0x39,0x82,0x9b,0x2f,0xff,0x87,
        .....
      }  
   }
  </code></pre>
  
  <p>Using nm command I am able to find the offset of read-only data.</p>
  
  <pre><code>nm /usr/lib/libgcrypt.so | grep encT
  0008ffc0 r encT
  
  nm /usr/lib/libgcrypt.so | grep dec_tables
  0008fac0 r dec_tables
  </code></pre>
  
  <p>I want to access those read-only data from C/C++ program.</p>
  
  <pre><code>    //sample.c
      // gcc sample.c -lgcrypt 
  
      #include &lt;gcrypt.h&gt;
  
      int main()
      {
  
      // ADDRESS of encT[0] = ? + OFFSET  (0008ffc0)
      //print value of encT[0] as 0xa56363c6
      // ADDRESS of dec_tables.T[0] = ? + OFFSET (0008fac0)
      //print value of dec_tables.T[0] as 0x50a7f451
      //print value of dec_tables.inv_sbox[0] as 0x52
  
      }
  </code></pre>
  
  <p>I have following questions </p>
  
  <ol>
  <li><p>How to use those offset to access those read-only data (encT,
  dec_tables.T,dec_tables.inv_sbox)  from C program ?</p>
  
  <p><strong>2. Is there any other way to find the ADDRESS of encT, dec_tables.T,dec_tables.inv_sbox ?</strong></p></li>
  </ol>
  
  <p>EDIT-1 :
  global(extern) function, gcry_cipher_decrypt()  is used to perform decryption and it calls static do_decrypt --> static do_decrypt_fn() which uses dec_tables.T,dec_tables.inv_sbox. So it is possible to find ADDRESS of dec_tables.T,dec_tables.inv_sbox with respect to address of 
  gcry_cipher_decrypt ?    </p>
  
  <p>I am using gcc-4.9, Ubuntu 16.04.</p>
  
  <p>It will be a great help if someone help me to complete the above sample program or any link to understand how I can do that ? Thanks in advance.   </p>