Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
7dd3140d
Commit
7dd3140d
authored
Jul 10, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename stream reader
parent
629cc5d1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
15 deletions
+81
-15
CircularBitStreamReader.hpp
src/kyut/CircularBitStreamReader.hpp
+66
-0
FunctionOrderingWatermarker.cpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
+2
-2
FunctionOrderingWatermarker.hpp
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
+2
-2
snpi.cpp
src/snpi.cpp
+2
-2
test_BitStreamReader.cpp
test/kyut/test_BitStreamReader.cpp
+4
-4
test_FunctionOrderingWatermarker.cpp
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
+5
-5
No files found.
src/kyut/BitStreamReader.hpp
→
src/kyut/
Circular
BitStreamReader.hpp
View file @
7dd3140d
#ifndef INCLUDE_kyut_BitStreamReader_hpp
#define INCLUDE_kyut_BitStreamReader_hpp
#ifndef INCLUDE_kyut_
Circular
BitStreamReader_hpp
#define INCLUDE_kyut_
Circular
BitStreamReader_hpp
#include <cstdint>
#include <memory>
...
...
@@ -7,27 +7,28 @@
#include <vector>
namespace
kyut
{
class
BitStreamReader
{
class
Circular
BitStreamReader
{
public
:
explicit
BitStreamReader
(
std
::
vector
<
std
::
uint8_t
>
data
)
explicit
Circular
BitStreamReader
(
std
::
vector
<
std
::
uint8_t
>
data
)
:
data_
(
std
::
move
(
data
))
,
pos_read_
(
0
)
{}
template
<
typename
Iterator
>
explicit
BitStreamReader
(
Iterator
begin
,
Iterator
end
)
:
BitStreamReader
({
begin
,
end
})
{}
explicit
Circular
BitStreamReader
(
Iterator
begin
,
Iterator
end
)
:
Circular
BitStreamReader
({
begin
,
end
})
{}
BitStreamReader
(
const
BitStreamReader
&
)
=
delete
;
BitStreamReader
(
BitStreamReader
&&
)
=
delete
;
CircularBitStreamReader
(
const
Circular
BitStreamReader
&
)
=
delete
;
CircularBitStreamReader
(
Circular
BitStreamReader
&&
)
=
delete
;
BitStreamReader
&
operator
=
(
const
BitStreamReader
&
)
=
delete
;
BitStreamReader
&
operator
=
(
BitStreamReader
&&
)
=
delete
;
CircularBitStreamReader
&
operator
=
(
const
Circular
BitStreamReader
&
)
=
delete
;
CircularBitStreamReader
&
operator
=
(
Circular
BitStreamReader
&&
)
=
delete
;
~
BitStreamReader
()
noexcept
=
default
;
~
Circular
BitStreamReader
()
noexcept
=
default
;
static
std
::
unique_ptr
<
BitStreamReader
>
fromString
(
std
::
string_view
s
)
{
return
std
::
make_unique
<
BitStreamReader
>
(
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()),
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()
+
s
.
size
()));
static
std
::
unique_ptr
<
CircularBitStreamReader
>
fromString
(
std
::
string_view
s
)
{
return
std
::
make_unique
<
CircularBitStreamReader
>
(
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()),
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()
+
s
.
size
()));
}
[[
nodiscard
]]
std
::
size_t
tell
()
const
noexcept
{
...
...
@@ -62,4 +63,4 @@ namespace kyut {
};
}
// namespace kyut
#endif // INCLUDE_kyut_BitStreamReader_hpp
#endif // INCLUDE_kyut_
Circular
BitStreamReader_hpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
View file @
7dd3140d
...
...
@@ -5,7 +5,7 @@
#include <cassert>
#include <iostream>
#include "../BitStreamReader.hpp"
#include "../
Circular
BitStreamReader.hpp"
namespace
kyut
::
watermarker
{
namespace
{
...
...
@@ -23,7 +23,7 @@ namespace kyut::watermarker {
}
}
// namespace
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
BitStreamReader
&
stream
,
std
::
size_t
divisions
)
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
Circular
BitStreamReader
&
stream
,
std
::
size_t
divisions
)
{
assert
(
2
<=
divisions
&&
divisions
<
21
&&
"because 21! > 2^64"
);
// Number of bits embedded in the module
...
...
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
View file @
7dd3140d
...
...
@@ -4,11 +4,11 @@
#include <wasm.h>
namespace
kyut
{
class
BitStreamReader
;
class
Circular
BitStreamReader
;
}
namespace
kyut
::
watermarker
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
BitStreamReader
&
stream
,
std
::
size_t
divisions
);
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
Circular
BitStreamReader
&
stream
,
std
::
size_t
divisions
);
}
#endif // INCLUDE_kyut_watermark_FunctionOrderingWatermarker_hpp
src/snpi.cpp
View file @
7dd3140d
...
...
@@ -2,7 +2,7 @@
#include <wasm-io.h>
#include "kyut/BitStreamReader.hpp"
#include "kyut/
Circular
BitStreamReader.hpp"
#include "kyut/watermarker/FunctionOrderingWatermarker.hpp"
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -22,7 +22,7 @@ int main(int argc, char *argv[]) {
wasm
::
ModuleReader
{}.
read
(
inputFile
,
module
);
// Embed watermarks
const
auto
stream
=
kyut
::
BitStreamReader
::
fromString
(
watermark
);
const
auto
stream
=
kyut
::
Circular
BitStreamReader
::
fromString
(
watermark
);
kyut
::
watermarker
::
embedFunctionOrdering
(
module
,
*
stream
,
10
);
...
...
test/kyut/test_BitStreamReader.cpp
View file @
7dd3140d
#include <kyut/BitStreamReader.hpp>
#include <kyut/
Circular
BitStreamReader.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
bit_stream_reader
)
BOOST_AUTO_TEST_SUITE
(
circular_
bit_stream_reader
)
BOOST_AUTO_TEST_CASE
(
read_bit
)
{
constexpr
std
::
uint8_t
data
[
1
]
=
{
0x89
};
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
Circular
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
// 0x89 == 0b1000'1001
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
});
...
...
@@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(read_bit) {
BOOST_AUTO_TEST_CASE
(
read
)
{
constexpr
std
::
uint8_t
data
[
4
]
=
{
0x89
,
0xab
,
0xcd
,
0xef
};
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
Circular
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
std
::
uint64_t
{
0x8
});
...
...
test/kyut/watermarker/test_FunctionOrderingWatermarker.cpp
View file @
7dd3140d
...
...
@@ -4,7 +4,7 @@
#include <wasm-io.h>
#include <kyut/BitStreamReader.hpp>
#include <kyut/
Circular
BitStreamReader.hpp>
BOOST_AUTO_TEST_SUITE
(
kyut
)
...
...
@@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(function_ordering_watermarker) {
// Embed 0b00
{
BitStreamReader
s
{{
0
b0000
'
0000
}};
Circular
BitStreamReader
s
{{
0
b0000
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
...
...
@@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(function_ordering_watermarker) {
// Embed 0b01
{
BitStreamReader
s
{{
0
b0100
'
0000
}};
Circular
BitStreamReader
s
{{
0
b0100
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
...
...
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(function_ordering_watermarker) {
// Embed 0b10
{
BitStreamReader
s
{{
0
b1000
'
0000
}};
Circular
BitStreamReader
s
{{
0
b1000
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
...
...
@@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(function_ordering_watermarker) {
// Embed 0b11
{
BitStreamReader
s
{{
0
b1100
'
0000
}};
Circular
BitStreamReader
s
{{
0
b1100
'
0000
}};
const
auto
numBitsEmbedded
=
embedFunctionOrdering
(
module
,
s
,
10
);
BOOST_REQUIRE_EQUAL
(
numBitsEmbedded
,
std
::
size_t
{
2
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment