title: Frida - hook android native C++ api
body: <p>Say android mediaserver has below API:</p>
  
  <pre><code>$ nm --demangle --dynamic libmediaplayerservice.so  |grep setDataSourceAsync
  0005c6f0 T android::NuPlayer::setDataSourceAsync(android::sp&lt;android::DataSource&gt; const&amp;)
  0005c008 T android::NuPlayer::setDataSourceAsync(android::sp&lt;android::IStreamSource&gt; const&amp;)
  0005c18c T android::NuPlayer::setDataSourceAsync(android::sp&lt;android::IMediaHTTPService&gt; const&amp;, char const*, android::KeyedVector&lt;android::String8, android::String8&gt; const*)
  0005c49c T android::NuPlayer::setDataSourceAsync(int, long long, long long)
  
  $ nm -D libmediaplayerservice.so |grep setDataSourceAsync
  0005c6f0 T _ZN7android8NuPlayer18setDataSourceAsyncERKNS_2spINS_10DataSourceEEE
  0005c008 T _ZN7android8NuPlayer18setDataSourceAsyncERKNS_2spINS_13IStreamSourceEEE
  0005c18c T _ZN7android8NuPlayer18setDataSourceAsyncERKNS_2spINS_17IMediaHTTPServiceEEEPKcPKNS_11KeyedVectorINS_7String8ES9_EE
  0005c49c T _ZN7android8NuPlayer18setDataSourceAsyncEixx
  </code></pre>
  
  <p>Now I wish to hook the last one:</p>
  
  <pre><code>0005c49c T android::NuPlayer::setDataSourceAsync(int, long long, long long)
  </code></pre>
  
  <p>Below code will work but the API name is mangled:</p>
  
  <pre><code>var libname = "libmediaplayerservice.so";
  var funame = "_ZN7android8NuPlayer18setDataSourceAsyncEixx";
  
  Interceptor.attach(Module.getExportByName(libname, funame), {
      onEnter: function(args) {
        console.log("onEnter: call fun enter");
      },
      onLeave: function(retval) {
        console.log("onLeave: call fun leave");
      }
  });
  </code></pre>
  
  <p>Two questions:</p>
  
  <ol>
  <li><p>Is it possible to use demangled name just like below in javascript code:</p>
  
  <p>android::NuPlayer::setDataSourceAsync(int, long long, long long)</p></li>
  <li>The first argument <code>int</code> is a file descriptor just like open returned value. how can I use this fd to dump the file to disk in javascript?</li>
  </ol>