使用 Hermes 反汇编 index.android.bundle 的 React-native 0.61.2 [英] React-native 0.61.2 with hermes disassembling index.android.bundle
问题描述
我使用 react-native 0.61.2 创建了我的应用程序的发布版本并启用了 Hermes.在我的 Crashlytics 中,我收到有关崩溃的信息以及堆栈跟踪.以前我曾经应用 apktool 从我的 apk 中提取 index.android.bundle,它包含我能够通过堆栈跟踪找到问题的 js 代码.
I created a release build of my app with react-native 0.61.2 and enabled Hermes. In my Crashlytics I receive information about crashes along with stacktraces. Perviously I used to apply apktool to extract index.android.bundle from my apk, and it contained js code where I was able to find the issue by stacktrace.
但现在使用 Hermes index.android.bundle 似乎包含字节码而不是 js,我浪费了一天试图反汇编它.我尝试的最后一件事是 中提到的 hbcdump 工具https://github.com/facebook/hermes/blob/master/doc/BuildingAndRunning.md,但我得到的只是错误:无法反序列化字节码:字节码版本错误.预期为 73,但得到 62"
But now using Hermes index.android.bundle seems to contain bytecode rather than js and I wasted a day trying to disassemble it. The last thing I tried was hbcdump tool mentioned in https://github.com/facebook/hermes/blob/master/doc/BuildingAndRunning.md, but all I get is "Error: fail to deserializing bytecode: Wrong bytecode version. Expected 73 but got 62"
如何反汇编用 Hermes 创建的 index.android.bundle?非常感谢任何帮助!
What should I do to disassemble index.android.bundle created with Hermes? Any help is highly appreciated!
推荐答案
从 Hermes v0.5.0 开始,还有一个 hermes-engine-cli
包含字节码反汇编程序的 NPM.它只与对应的hermes-engine
版本兼容(即hermes-engine-cli@0.5.0
与hermes-engine@0.5.0
兼容代码>).
As of Hermes v0.5.0, there's also a hermes-engine-cli
NPM that contains a bytecode disassembler. It is only compatible with the corresponding hermes-engine
version (i.e. hermes-engine-cli@0.5.0
works with hermes-engine@0.5.0
).
它仍然主要对编译器开发人员有用,而不是用于调试应用崩溃.
It's still primarily useful for compiler developers, and not for debugging app crashes.
Hermes 工具不向后兼容,因此您需要先检查正确的版本.对于字节码版本 62
,您可以使用 git checkout v0.2.1
签出 v0.2.1
版本.对于任意字节码版本,git log -p include/hermes/BCGen/HBC/BytecodeFileFormat.h
将显示哪些提交将格式更新为哪些版本.
Hermes tools are not backwards compatible, so you need to check out the correct version first. For bytecode version 62
, you can checkout the the v0.2.1
release with git checkout v0.2.1
. For arbitrary bytecode versions, git log -p include/hermes/BCGen/HBC/BytecodeFileFormat.h
will show which commits updated the format to which versions.
一旦构建,您可以在提示符下使用 hbcdump myfile.hbc
后跟 disassemble
来显示文件的禁用版本.
Once built, you can use hbcdump myfile.hbc
followed by disassemble
at the prompt to show a disabled version of the file.
请注意,hbcdump
用于开发/调试编译器,与 javap -c
和 objdump -d
一样.以下是您可以期待的输出类型:
Be aware that hbcdump
is intended for developing/debugging compilers, in the same vein as javap -c
and objdump -d
. Here's the kind of output you can expect:
Function<fizzbuzz>1(1 params, 22 registers, 0 symbols):
Offset in debug table: src 0xd, vars 0x0
fizzbuzz.js[1:21]
LoadConstZero r11
LoadConstUInt8 r10, 15
LoadConstUInt8 r9, 3
LoadConstString r8, "Fizzbuzz"
LoadConstString r7, "Fizz"
LoadConstString r6, "Buzz"
GetGlobalObject r5
LoadConstUndefined r0
LoadConstUInt8 r4, 1
LoadConstUInt8 r3, 100
LoadConstUInt8 r2, 5
LoadConstZero r1
L2:
fizzbuzz.js[1:21]
Mod r12, r1, r10
Mov r13, r8
JStrictEqual L1, r12, r11
Mod r12, r1, r9
Mov r13, r7
JStrictEqual L1, r12, r11
Mod r12, r1, r2
Mov r13, r6
JStrictEqual L1, r12, r11
AddEmptyString r13, r1
L1:
fizzbuzz.js[8:5]
TryGetById r12, r5, 1, "print"
Call2 r12, r12, r0, r13
AddN r1, r1, r4
JLessN L2, r1, r3
Ret r0
这篇关于使用 Hermes 反汇编 index.android.bundle 的 React-native 0.61.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!