title: Inject shared library into a running process
body: <p>I just started to learn injection techniques in Linux and want to write a simple program to inject a shared library into a running process (app using QT). However, after a couple of hours research, I couldn't find any complete example.</p>
  
  <p>Why dlsym can't find qt_startup_hook?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;dlfcn.h&gt;
  
  
  void hello()
  {
      printf("Call hello\n");
      void *func = dlsym(RTLD_NEXT, "qt_startup_hook");
  
      if (!func) {
          printf("Error\n");
      }
  }
  </code></pre>
  
  <p>Gdb:</p>
  
  <pre><code>b main
  run
  call dlopen("/linux-inject/sample-library.so",2)
  &gt;&gt; $1 = 108781344
  call hello()
  &gt;&gt; Call hello
  &gt;&gt; Error
  </code></pre>
  
  <p>Gdb found qt_startup_hook:</p>
  
  <pre><code>info functions qt_startup_hook
  &gt;&gt; Non-debugging symbols:
  &gt;&gt; 0x00007ffff7b0ae40  qt_startup_hook
  </code></pre>