redraskal / r6-dissect

Match Replay API/CLI for Rainbow Six: Siege's Dissect (.rec) format.
MIT License
70 stars 11 forks source link

Invalid Windows .dll #67

Open BadCoder1337 opened 1 year ago

BadCoder1337 commented 1 year ago

Describe the bug Something is wrong with Windows .dll. I'm trying to port r6-dissect-bun to Node.js with node-ffi-napi. It gives a V8 failure:

#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 00000043CB2FBBD0
 1: 00007FF7DAA5815F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114079
 2: 00007FF7DA97343F std::basic_ostream<char,std::char_traits<char> >::operator<<+65023
 3: 00007FF7DB652D52 V8_Fatal+162
 4: 00007FF7DB0BE0CD v8::internal::BackingStore::Reallocate+637
 5: 00007FF7DB307849 v8::ArrayBuffer::GetBackingStore+137
 6: 00007FF7DAA2A3B9 napi_get_typedarray_info+393
 7: 00007FFFB5EC8828
 8: 00007FFFB5EC7C19 
 9: 00007FFFB5ECD003
10: 00007FFFB5ECED79
11: 00007FFFB5ECEF18
12: 00007FFFD6B326E6 FFI::WrapPointerImpl+134 [...\node_modules\ffi-napi\src\ffi.cc]:L28
13: 00007FFFD6B33943 FFI::FFI::InitializeBindings+3571 [...\node_modules\ffi-napi\src\ffi.cc]:L138
14: 00007FFFD6B376E7 FFI::InitializeBindings+471 [...\node_modules\ffi-napi\src\ffi.cc]:L339
15: 00007FFFD6B389C0 Napi::details::WrapCallback<<lambda_4b130013be4a466940e6fe08d32cda83> >+64 [...\node_modules\node-addon-api\napi-inl.h]:L74
16: 00007FFFD6B38918 Napi::details::CallbackData<Napi::Value (__cdecl*)(Napi::CallbackInfo const &),Napi::Value>::Wrapper+40 [...\node_modules\node-addon-api\napi-inl.h]:L115
17: 00007FF7DAA24B9B node::Stop+36395
18: 00007FF7DB2D6256 v8::internal::Builtins::code_handle+172790
19: 00007FF7DB2D5E49 v8::internal::Builtins::code_handle+171753
20: 00007FF7DB2D610C v8::internal::Builtins::code_handle+172460
21: 00007FF7DB2D5F70 v8::internal::Builtins::code_handle+172048
22: 00007FF7DB3A9671 v8::internal::SetupIsolateDelegate::SetupHeap+494673
23: 00007FF7DB33BB1E v8::internal::SetupIsolateDelegate::SetupHeap+45310
24: 00007FF7DB33BB1E v8::internal::SetupIsolateDelegate::SetupHeap+45310
25: 00007FF7DB33BB1E v8::internal::SetupIsolateDelegate::SetupHeap+45310
26: 00000182808B4A3B

node: 16.14.1 ffi-napi: 4.0.3

To Reproduce Steps to reproduce the behavior:

  1. Go to https://speedtesting.herokuapp.com/peviewer/
  2. Import libr6dissect.dll
  3. See error

Expected behavior It should work the same as libr6dissect.so

redraskal commented 1 year ago

so you did get this working with linux?

the ffi function should be reworked soon to expect a buffer, instead of Go freeing the output.

either 1) dll never worked or 2) buffer needs to be implemented

i haven't tested the windows dll because Bun does not yet support windows

BadCoder1337 commented 1 year ago

They released experimental Bun build for Windows along with 1.0.0 release. I got working .so with WSL, but tsc-watch or any watchers don't support WSL 2 well. RIP DX 🥲 Also, I got this V8 failure while tinkering with an HTTP-only Discord bot in serverless environment. Most likely I should compile r6-dissect by myself.

#
#
#
# Check failed: result.second.
# Fatal error in , line 0
#
#FailureMessage Object: 0x7efd7f5dc7d0
1: 0xb75ed1 [/function/runtime/nodejs/bin/node]
2: 0x1c08724 V8_Fatal(char const*, ...) [/function/runtime/nodejs/bin/node]
3: 0xfcd741 v8::internal::GlobalBackingStoreRegistry::Register(std::shared_ptr<v8::internal::BackingStore>) [/function/runtime/nodejs/bin/node]
4: 0xd1ef88 v8::ArrayBuffer::GetBackingStore() [/function/runtime/nodejs/bin/node]
5: 0xabdab0 napi_get_typedarray_info [/function/runtime/nodejs/bin/node]
6: 0x7efd94198566 [/function/code/node_modules/ref-napi/prebuilds/linux-x64/node.napi.node]
7: 0x7efd94198dad [/function/code/node_modules/ref-napi/prebuilds/linux-x64/node.napi.node]
8: 0x7efd7f5ea4f3 FFI::WrapPointerImpl(Napi::Env, char*, unsigned long) [/function/code/node_modules/ffi-napi/build/Release/ffi_bindings.node]
9: 0x7efd7f5ecce4 FFI::FFI::InitializeBindings(Napi::Env, Napi::Object) [/function/code/node_modules/ffi-napi/build/Release/ffi_bindings.node]
10: 0x7efd7f5ee3c5 FFI::InitializeBindings(Napi::CallbackInfo const&) [/function/code/node_modules/ffi-napi/build/Release/ffi_bindings.node]
11: 0x7efd7f5ef3fb Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) [/function/code/node_modules/ffi-napi/build/Release/ffi_bindings.node]
12: 0xab44dd [/function/runtime/nodejs/bin/node]
13: 0xd53d8e [/function/runtime/nodejs/bin/node]
14: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/function/runtime/nodejs/bin/node]
15: 0x15f0bf9 [/function/runtime/nodejs/bin/node]
runtime pid 89: killed by signal 5

node 16.14.1, Ubuntu 18.04 LTS, libc 2.27

BadCoder1337 commented 1 year ago

I compiled valid .dll with these scripts https://github.com/BadCoder1337/r6-dissect/commit/5ed34c8205798f27a5188032f86541173f2dafe6 It works in the main thread, but doesn't in worker_thread due to the issue https://github.com/node-ffi-napi/node-ffi-napi/issues/125 image

redraskal commented 1 year ago

I'm going to look into the Windows DLL myself soon and figure out why GitHub Actions is causing problems. Also, I will likely implement a child process / worker implementation for Node on the r6-dissect npm package. Node FFI just looks a little buggy and slow.

redraskal commented 1 year ago

Thanks for the scripts, I will consider your changes when I look into the release workflow

BadCoder1337 commented 1 year ago

Consider koffi FFI library. According their benchmarks it much faster and also works in a worker thread. Working:

new (require("worker_threads").Worker)(`
  require("fs").writeFileSync("./test/dump.json",
    require("koffi")
      .load("./lib/libr6dissect-windows-amd64.dll")
      .cdecl("dissect_read", "str", ["str"])
      ("./test/Match-2023-09-23_12-03-31-55-R07.rec")
  )`,
  { eval: true }
)

Not working:

new (require("worker_threads").Worker)(`
  require("fs").writeFileSync("./test/dump.json",
    require("ffi-napi")
      .Library("./lib/libr6dissect-windows-amd64.dll",
        { dissect_read: ["string", ["string"]] }
      ).dissect_read("./test/Match-2023-09-23_12-03-31-55-R07.rec")
  )`,
  { eval: true }
)