mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
working!
This commit is contained in:
@@ -12,9 +12,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ripple/protocol/digest.h>
|
#include <ripple/protocol/digest.h>
|
||||||
#include <wasmedge/wasmedge.h>
|
|
||||||
#include <ripple/app/tx/applyHookMacro.h>
|
#include <ripple/app/tx/applyHookMacro.h>
|
||||||
|
#include <wasmedge/wasmedge.h>
|
||||||
|
|
||||||
namespace hook
|
namespace hook
|
||||||
{
|
{
|
||||||
@@ -408,6 +407,9 @@ namespace hook
|
|||||||
static WasmEdge_String cbakFunctionName = WasmEdge_StringCreateByCString("cbak");
|
static WasmEdge_String cbakFunctionName = WasmEdge_StringCreateByCString("cbak");
|
||||||
static WasmEdge_String hookFunctionName = WasmEdge_StringCreateByCString("hook");
|
static WasmEdge_String hookFunctionName = WasmEdge_StringCreateByCString("hook");
|
||||||
|
|
||||||
|
// see: lib/system/allocator.cpp
|
||||||
|
#define WasmEdge_kPageSize 65536ULL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HookExecutor is effectively a two-part function:
|
* HookExecutor is effectively a two-part function:
|
||||||
* The first part sets up the Hook Api inside the wasm import, ready for use
|
* The first part sets up the Hook Api inside the wasm import, ready for use
|
||||||
@@ -483,6 +485,21 @@ namespace hook
|
|||||||
WasmEdge_Value params[1] = { WasmEdge_ValueGenI32((int64_t)wasmParam) };
|
WasmEdge_Value params[1] = { WasmEdge_ValueGenI32((int64_t)wasmParam) };
|
||||||
WasmEdge_Value returns[1];
|
WasmEdge_Value returns[1];
|
||||||
|
|
||||||
|
/*
|
||||||
|
printf("executing hook wasm:\n");
|
||||||
|
for (int j = 0; j < len; j++)
|
||||||
|
{
|
||||||
|
if (j % 16 == 0)
|
||||||
|
printf("0x%08X:\t", j);
|
||||||
|
|
||||||
|
printf("%02X%s", (reinterpret_cast<const uint8_t*>(wasm))[j],
|
||||||
|
(j % 16 == 15 ? "\n" :
|
||||||
|
(j % 4 == 3 ? " " :
|
||||||
|
(j % 2 == 1 ? " " : ""))));
|
||||||
|
}
|
||||||
|
printf("\n----\n");
|
||||||
|
*/
|
||||||
|
|
||||||
res =
|
res =
|
||||||
WasmEdge_VMRunWasmFromBuffer(vmCtx, reinterpret_cast<const uint8_t*>(wasm), len,
|
WasmEdge_VMRunWasmFromBuffer(vmCtx, reinterpret_cast<const uint8_t*>(wasm), len,
|
||||||
callback ? cbakFunctionName : hookFunctionName,
|
callback ? cbakFunctionName : hookFunctionName,
|
||||||
@@ -500,14 +517,6 @@ namespace hook
|
|||||||
|
|
||||||
auto* statsCtx= WasmEdge_VMGetStatisticsContext(vmCtx);
|
auto* statsCtx= WasmEdge_VMGetStatisticsContext(vmCtx);
|
||||||
hookCtx.result.instructionCount = WasmEdge_StatisticsGetInstrCount(statsCtx);
|
hookCtx.result.instructionCount = WasmEdge_StatisticsGetInstrCount(statsCtx);
|
||||||
|
|
||||||
JLOG(j.trace())
|
|
||||||
<< "HookInfo[" << HC_ACC() << "]: "
|
|
||||||
<< (hookCtx.result.exitType == hook_api::ExitType::ROLLBACK ? "ROLLBACK" : "ACCEPT")
|
|
||||||
<< " RS: '" << hookCtx.result.exitReason.c_str()
|
|
||||||
<< "' RC: " << hookCtx.result.exitCode;
|
|
||||||
|
|
||||||
//WasmEdge_ValueGetI64(returns[0]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,6 +530,8 @@ namespace hook
|
|||||||
{
|
{
|
||||||
ctx.module = this;
|
ctx.module = this;
|
||||||
|
|
||||||
|
WasmEdge_LogSetDebugLevel();
|
||||||
|
|
||||||
ADD_HOOK_FUNCTION(_g, ctx);
|
ADD_HOOK_FUNCTION(_g, ctx);
|
||||||
ADD_HOOK_FUNCTION(accept, ctx);
|
ADD_HOOK_FUNCTION(accept, ctx);
|
||||||
ADD_HOOK_FUNCTION(rollback, ctx);
|
ADD_HOOK_FUNCTION(rollback, ctx);
|
||||||
|
|||||||
@@ -145,7 +145,8 @@
|
|||||||
[[maybe_unused]] auto& view = applyCtx.view();\
|
[[maybe_unused]] auto& view = applyCtx.view();\
|
||||||
[[maybe_unused]] auto j = applyCtx.app.journal("View");\
|
[[maybe_unused]] auto j = applyCtx.app.journal("View");\
|
||||||
[[maybe_unused]] unsigned char* memory = WasmEdge_MemoryInstanceGetPointer(&memoryCtx, 0, 0);\
|
[[maybe_unused]] unsigned char* memory = WasmEdge_MemoryInstanceGetPointer(&memoryCtx, 0, 0);\
|
||||||
[[maybe_unused]] const uint64_t memory_length = WasmEdge_MemoryInstanceGetPageSize(&memoryCtx);
|
[[maybe_unused]] const uint64_t memory_length = WasmEdge_MemoryInstanceGetPageSize(&memoryCtx) * \
|
||||||
|
WasmEdge_kPageSize;
|
||||||
|
|
||||||
#define WRITE_WASM_MEMORY(bytes_written, guest_dst_ptr, guest_dst_len,\
|
#define WRITE_WASM_MEMORY(bytes_written, guest_dst_ptr, guest_dst_len,\
|
||||||
host_src_ptr, host_src_len, host_memory_ptr, guest_memory_length)\
|
host_src_ptr, host_src_len, host_memory_ptr, guest_memory_length)\
|
||||||
|
|||||||
Reference in New Issue
Block a user