Commit d6dc6169 authored by nagayama15's avatar nagayama15

Display number of bits embedded or extracted

parent 49bcfa57
......@@ -44,10 +44,8 @@ namespace kyut {
return false;
}
const auto pos = pos_read_;
pos_read_ = (pos_read_ + 1) % (data_.size() * 8);
return ((data_[pos / 8] << (pos % 8)) & 0x80) != 0;
const auto pos = pos_read_++;
return ((data_[pos / 8 % data_.size()] << (pos % 8)) & 0x80) != 0;
}
std::uint64_t read(std::size_t countBits) {
......
......@@ -24,18 +24,18 @@ int main(int argc, char *argv[]) {
// Embed watermarks
kyut::BitStreamWriter stream;
std::size_t numBits;
if (method == "opswap") {
numBits = kyut::watermarker::extractOperandSwapping(module, stream);
kyut::watermarker::extractOperandSwapping(module, stream);
} else if (method == "funcord") {
numBits = kyut::watermarker::extractFunctionOrdering(module, stream, 10);
kyut::watermarker::extractFunctionOrdering(module, stream, 10);
} else {
throw std::runtime_error{fmt::format("unknown embedding method: {}", method)};
}
// Output watermarks extracted
std::cout << stream.dataAsString();
fmt::print("{}", stream.dataAsString());
fmt::print(std::cerr, "{} bits extracted\n", stream.tell());
} catch (const wasm::ParseException &e) {
e.dump(std::cerr);
......
......@@ -36,6 +36,8 @@ int main(int argc, char *argv[]) {
// Output the result
wasm::ModuleWriter{}.writeText(module, "");
fmt::print(std::cerr, "{} bits embedded\n", stream->tell());
} catch (const wasm::ParseException &e) {
e.dump(std::cerr);
......
......@@ -27,15 +27,15 @@ BOOST_AUTO_TEST_CASE(read_bit) {
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{7});
BOOST_REQUIRE_EQUAL(reader.readBit(), true);
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{0});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{8});
BOOST_REQUIRE_EQUAL(reader.readBit(), true);
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{1});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{9});
BOOST_REQUIRE_EQUAL(reader.readBit(), false);
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{2});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{10});
BOOST_REQUIRE_EQUAL(reader.readBit(), false);
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{3});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{11});
BOOST_REQUIRE_EQUAL(reader.readBit(), false);
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{4});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{12});
}
BOOST_AUTO_TEST_CASE(read) {
......@@ -53,10 +53,10 @@ BOOST_AUTO_TEST_CASE(read) {
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{16});
BOOST_REQUIRE_EQUAL(reader.read(16), std::uint64_t{0xcdef});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{0});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{32});
BOOST_REQUIRE_EQUAL(reader.read(24), std::uint64_t{0x89abcd});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{24});
BOOST_REQUIRE_EQUAL(reader.tell(), std::size_t{56});
}
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