Skip to content
汘浪 edited this page Jul 30, 2019 · 7 revisions

NewStringUTF

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0'

static std::u16string UTF8StringToUTF16String(const std::string& string) {
  return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}
      .from_bytes(string);
}

ScopedJavaLocalRef<jstring> StringToJavaString(JNIEnv* env,
                                               const std::string& u8_string) {
  std::u16string u16_string = UTF8StringToUTF16String(u8_string);
  auto result = ScopedJavaLocalRef<jstring>(
      env, env->NewString(reinterpret_cast<const jchar*>(u16_string.data()),
                          u16_string.length()));
  ASSERT_NO_EXCEPTION();
  return result;
}

dumpReferenceTables

反射dalvik.system.VMDebug的dumpReferenceTables方法

    /**
     * Dumps the contents of the VM reference tables (e.g. JNI locals and
     * globals) to the log file.
     */
    public static native void dumpReferenceTables();

addr2line

Android NDK so crash,定位目标代码使用 arm-linux-androideabi-addr2line 命令行位于:

$NDK_HOME/toolchains/arm-Linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-addr2line

用法示意:

arm-linux-androideabi-addr2line -e 有符号的so crash内存地址

另外IDA也是一个强大的工具。

What is IDA all about?

IDA is a Windows, Linux or Mac OS X hosted multi-processor disassembler and debugger that offers so many features it is hard to describe them all. Just grab an evaluation version if you want a test drive. An executive summary is provided for the non-technical user.


更多参考:

Clone this wiki locally