Commit 656d164c authored by nagayama15's avatar nagayama15

Update watermarker driver

parent f649775a
...@@ -4,16 +4,18 @@ ...@@ -4,16 +4,18 @@
#include "kyut/BitStreamWriter.hpp" #include "kyut/BitStreamWriter.hpp"
#include "kyut/watermarker/FunctionOrderingWatermarker.hpp" #include "kyut/watermarker/FunctionOrderingWatermarker.hpp"
#include "kyut/watermarker/OperandSwappingWatermarker.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Parse command line options // Parse command line options
if (argc != 2) { if (argc != 3) {
fmt::print(std::cerr, "{} <input file>\n", argv[0]); fmt::print(std::cerr, "{} <input file> <method>\n", argv[0]);
return 1; return 1;
} }
const std::string inputFile = argv[1]; const std::string inputFile = argv[1];
const std::string method = argv[2];
try { try {
// Read the input module // Read the input module
...@@ -22,7 +24,15 @@ int main(int argc, char *argv[]) { ...@@ -22,7 +24,15 @@ int main(int argc, char *argv[]) {
// Embed watermarks // Embed watermarks
kyut::BitStreamWriter stream; kyut::BitStreamWriter stream;
kyut::watermarker::extractFunctionOrdering(module, stream, 10); std::size_t numBits;
if (method == "opswap") {
numBits = kyut::watermarker::extractOperandSwapping(module, stream);
} else if (method == "funcord") {
numBits = kyut::watermarker::extractFunctionOrdering(module, stream, 10);
} else {
throw std::runtime_error{fmt::format("unknown embedding method: {}", method)};
}
// Output watermarks extracted // Output watermarks extracted
std::cout << stream.dataAsString(); std::cout << stream.dataAsString();
......
...@@ -4,17 +4,19 @@ ...@@ -4,17 +4,19 @@
#include "kyut/CircularBitStreamReader.hpp" #include "kyut/CircularBitStreamReader.hpp"
#include "kyut/watermarker/FunctionOrderingWatermarker.hpp" #include "kyut/watermarker/FunctionOrderingWatermarker.hpp"
#include "kyut/watermarker/OperandSwappingWatermarker.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Parse command line options // Parse command line options
if (argc != 3) { if (argc != 4) {
fmt::print(std::cerr, "{} <input file> <watermark>\n", argv[0]); fmt::print(std::cerr, "{} <input file> <method> <watermark>\n", argv[0]);
return 1; return 1;
} }
const std::string inputFile = argv[1]; const std::string inputFile = argv[1];
const std::string watermark = argv[2]; const std::string method = argv[2];
const std::string watermark = argv[3];
try { try {
// Read the input module // Read the input module
...@@ -24,7 +26,13 @@ int main(int argc, char *argv[]) { ...@@ -24,7 +26,13 @@ int main(int argc, char *argv[]) {
// Embed watermarks // Embed watermarks
const auto stream = kyut::CircularBitStreamReader::fromString(watermark); const auto stream = kyut::CircularBitStreamReader::fromString(watermark);
if (method == "opswap") {
kyut::watermarker::embedOperandSwapping(module, *stream);
} else if (method == "funcord") {
kyut::watermarker::embedFunctionOrdering(module, *stream, 10); kyut::watermarker::embedFunctionOrdering(module, *stream, 10);
} else {
throw std::runtime_error{fmt::format("unknown embedding method: {}", method)};
}
// Output the result // Output the result
wasm::ModuleWriter{}.writeText(module, ""); wasm::ModuleWriter{}.writeText(module, "");
......
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