Commit 95667ed1 authored by nagayama15's avatar nagayama15

🚧 Add an empty watermarking function

parent adbbc308
(module
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f3" (func $f3))
(func $f1 (result i32)
(i32.add
(i32.const 1)
(i32.const 2)
)
)
(func $f2 (result i32)
(i32.add
(i32.add
(i32.const 1)
(i32.const 2)
)
(i32.const 3)
)
)
(func $f3 (result i32)
(i32.add
(i32.add
(i32.const 1)
(i32.const 2)
)
(i32.add
(i32.const 4)
(i32.const 3)
)
)
)
)
add_library(kyut
kyut/watermarker/FunctionOrderingWatermarker.cpp
kyut/watermarker/OperandSwappingWatermarker.cpp
)
target_link_libraries(kyut
......
#include "OperandSwappingWatermarker.hpp"
namespace kyut::watermarker {
std::size_t embedOperandSwapping(wasm::Module &module, CircularBitStreamReader &stream) {
(void)module;
(void)stream;
return 0;
}
std::size_t extractOperandSwapping(wasm::Module &module, BitStreamWriter &stream) {
(void)module;
(void)stream;
return 0;
}
} // namespace kyut::watermarker
#ifndef INCLUDE_kyut_watermark_OperandSwappingWatermarker_hpp
#define INCLUDE_kyut_watermark_OperandSwappingWatermarker_hpp
#include <wasm.h>
namespace kyut {
class BitStreamWriter;
class CircularBitStreamReader;
} // namespace kyut
namespace kyut::watermarker {
/**
* @brief Embed watermarks by operand swapping.
*
* @param module A reference to the WebAssembly module in which watermarks will be embedded.
* @param stream Input stream containing watermarks to embed.
* @return Number of watermark bits embedded in the module.
*/
std::size_t embedOperandSwapping(wasm::Module &module, CircularBitStreamReader &stream);
/**
* @brief Extract watermarks by operand swapping.
*
* @param module A reference to the WebAssembly module with embedded watermarks.
* @param stream Output stream to save the watermarks.
* @return Number of watermark bits extracted from the module.
*/
std::size_t extractOperandSwapping(wasm::Module &module, BitStreamWriter &stream);
} // namespace kyut::watermarker
#endif // INCLUDE_kyut_watermark_OperandSwappingWatermarker_hpp
......@@ -3,6 +3,7 @@ add_executable(test_kyut
kyut/test_CircularBitStreamReader.cpp
kyut/test_BitStreamWriter.cpp
kyut/watermarker/test_FunctionOrderingWatermarker.cpp
kyut/watermarker/test_OperandSwappingWatermarker.cpp
)
target_compile_definitions(test_kyut
......
#include <kyut/watermarker/OperandSwappingWatermarker.hpp>
#include <boost/test/unit_test.hpp>
#include <wasm-io.h>
#include <kyut/BitStreamWriter.hpp>
#include <kyut/CircularBitStreamReader.hpp>
#ifndef KYUT_TEST_SOURCE_DIR
#define KYUT_TEST_SOURCE_DIR "."
#endif
BOOST_AUTO_TEST_SUITE(kyut)
BOOST_AUTO_TEST_SUITE(watermarker)
BOOST_AUTO_TEST_CASE(embed_operand_swapping) {
wasm::Module module;
wasm::ModuleReader{}.read(KYUT_TEST_SOURCE_DIR "/example/test2.wast", module);
BOOST_REQUIRE_EQUAL(module.functions.size(), std::size_t{3});
BOOST_REQUIRE_EQUAL(module.functions[0]->name, "f1");
BOOST_REQUIRE_EQUAL(module.functions[1]->name, "f2");
BOOST_REQUIRE_EQUAL(module.functions[2]->name, "f3");
// Embed 0b0000'00
{
CircularBitStreamReader s{{0b0000'0000}};
const auto numBitsEmbedded = embedOperandSwapping(module, s);
BOOST_REQUIRE_EQUAL(numBitsEmbedded, std::size_t{6});
BOOST_REQUIRE_EQUAL(module.functions.size(), std::size_t{3});
BOOST_REQUIRE_EQUAL(module.functions[0]->name, "f1");
BOOST_REQUIRE_EQUAL(module.functions[1]->name, "f2");
BOOST_REQUIRE_EQUAL(module.functions[2]->name, "f3");
// f1
{
const auto bin = module.functions[0]->body->cast<wasm::Binary>();
BOOST_REQUIRE_EQUAL(bin->left->cast<wasm::Const>()->value.geti32(), 1);
BOOST_REQUIRE_EQUAL(bin->right->cast<wasm::Const>()->value.geti32(), 2);
}
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment