revenge-tweak/Sources/JSI.mm

50 lines
1.3 KiB
Text
Raw Normal View History

fix: replace speculative Bridgeless hook with RainTweak's verified approach The RCTInstance/-_loadScriptFromSource: + fake-RCTSource hook from the previous commit was a plausible guess from RN's public source, but codeberg.org/raincord/RainTweak - an actively-shipping loader for a sibling Revenge/Bunny fork - proves both the Bridgeless diagnosis correct (its %ctor refuses to run below Discord v332, i.e. pre-Bridgeless) and shows a cleaner, verified mechanism: hook RCTHost/-instance:didInitializeRuntime:, let Discord's own bundle load untouched via %orig, then evaluate Revenge's scripts directly against the live JSI runtime instead of faking another bundle load. - Add Headers/JSI.h + Sources/JSI.mm (ported from RainTweak's JSI.mm): evaluates NSData as JS or Hermes bytecode directly against a facebook::jsi::Runtime. - Add Headers/RCTHost.h declaring the hook target's signature (RN ships no public header for this internal class). - Vendor Headers/jsi/{jsi.h,jsi-inl.h,instrumentation.h} - Meta's MIT-licensed JSI headers, which Theos doesn't provide; RainTweak vendors the same files. - Rewrite Tweak.x -> Tweak.xm (needs C++ for jsi::Runtime&): runRevengeInjection now takes a plain data/async execute callback, driven by either the new RCTHost+JSI hook or the legacy RCTCxxBridge hook (kept as a no-cost fallback), guarded by a didInject flag so only one path actually injects. - Makefile: build .xm/.mm sources, add -std=c++17 CCFLAGS matching RainTweak. Still unverified against a real device, but the mechanism itself is no longer a guess - it's the one running in a comparable, currently-shipping mod.
2026-08-03 10:10:32 -04:00
#import "JSI.h"
#import "Logger.h"
#import "Utils.h"
using namespace facebook;
namespace {
class NSDataBuffer : public jsi::Buffer {
public:
explicit NSDataBuffer(NSData *data) : data_(data) {}
size_t size() const override {
return data_.length;
}
const uint8_t *data() const override {
return static_cast<const uint8_t *>(data_.bytes);
}
private:
NSData *data_;
};
}
@implementation JSI
+ (void)evaluate:(NSData *)scriptData tag:(NSString *)tag runtime:(jsi::Runtime &)runtime {
if (scriptData.length == 0) return;
try {
if (isHermesBytecode(scriptData)) {
auto buffer = std::make_shared<NSDataBuffer>(scriptData);
auto prepared = runtime.prepareJavaScript(buffer, std::string(tag.UTF8String));
runtime.evaluatePreparedJavaScript(prepared);
} else {
std::string source((const char *)scriptData.bytes, scriptData.length);
auto buffer = std::make_shared<jsi::StringBuffer>(std::move(source));
runtime.evaluateJavaScript(buffer, std::string(tag.UTF8String));
}
} catch (const jsi::JSError &e) {
RevengeLog(@"[JSI] evaluate error: JSError for '%@': %s", tag, e.what());
} catch (const std::exception &e) {
RevengeLog(@"[JSI] evaluate error: exception for '%@': %s", tag, e.what());
}
}
@end