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
233da654
Commit
233da654
authored
Jul 11, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write doc comments
parent
e870b63b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
16 deletions
+33
-16
FunctionOrderingWatermarker.cpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
+23
-14
FunctionOrderingWatermarker.hpp
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
+10
-2
No files found.
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
View file @
233da654
...
@@ -9,13 +9,26 @@
...
@@ -9,13 +9,26 @@
namespace
kyut
::
watermarker
{
namespace
kyut
::
watermarker
{
namespace
{
namespace
{
// Number of bits that can be embedded in a chunk
// {floor(log2(x!)) | x in [2, 21)}
constexpr
auto
factorialBitLengthTable
=
std
::
array
<
std
::
size_t
,
21
>
{
0
,
0
,
1
,
2
,
4
,
6
,
9
,
12
,
15
,
18
,
21
,
25
,
28
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
61
,
};
/**
/**
* Move the `element` in [begin, end) to the beginning of the range.
* @brief Move the `element` in [begin, end) to the beginning of the range.
* The order of elements other than `element` is maintained.
* The order of elements other than `element` is maintained.
*
* @tparam BidirectionalIterator Bidirectional iterator type.
* @param begin Bidirectional iterator to the initial position in a sequence.
* @param end Bidirectional iterator to the final position in a sequence.
* @param element Bidirectional iterator to the element to be moved.
* `element` must be in the range of [begin, end).
*/
*/
template
<
typename
RandomAccessIterator
>
template
<
typename
BidirectionalIterator
>
void
moveToFront
(
RandomAccessIterator
begin
,
RandomAccessIterator
end
,
RandomAccessIterator
element
)
{
void
moveToFront
(
BidirectionalIterator
begin
,
BidirectionalIterator
end
,
BidirectionalIterator
element
)
{
assert
(
begin
<=
element
&&
element
<
end
);
assert
(
std
::
distance
(
begin
,
element
)
>=
0
);
assert
(
std
::
distance
(
begin
,
element
)
<
std
::
distance
(
begin
,
end
));
auto
tmp
=
std
::
move
(
*
element
);
auto
tmp
=
std
::
move
(
*
element
);
std
::
move_backward
(
begin
,
element
,
std
::
next
(
element
));
std
::
move_backward
(
begin
,
element
,
std
::
next
(
element
));
...
@@ -23,8 +36,8 @@ namespace kyut::watermarker {
...
@@ -23,8 +36,8 @@ namespace kyut::watermarker {
}
}
}
// namespace
}
// namespace
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
divisions
)
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
maxChunkSize
)
{
assert
(
2
<=
divisions
&&
divisions
<
21
&&
"because 21! > 2^64"
);
assert
(
2
<=
maxChunkSize
&&
maxChunkSize
<
21
&&
"because 21! > 2^64"
);
// Number of bits embedded in the module
// Number of bits embedded in the module
std
::
size_t
numBits
=
0
;
std
::
size_t
numBits
=
0
;
...
@@ -36,17 +49,13 @@ namespace kyut::watermarker {
...
@@ -36,17 +49,13 @@ namespace kyut::watermarker {
const
size_t
count
=
std
::
distance
(
start
,
std
::
end
(
module
.
functions
));
const
size_t
count
=
std
::
distance
(
start
,
std
::
end
(
module
.
functions
));
for
(
size_t
i
=
0
;
i
<
count
;
i
+=
divisions
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
+=
maxChunkSize
)
{
const
auto
chunkSize
=
(
std
::
min
)(
divisions
,
count
-
i
);
const
auto
chunkSize
=
(
std
::
min
)(
maxChunkSize
,
count
-
i
);
const
auto
chunkBegin
=
start
+
i
;
const
auto
chunkBegin
=
start
+
i
;
const
auto
chunkEnd
=
chunkBegin
+
chunkSize
;
const
auto
chunkEnd
=
chunkBegin
+
chunkSize
;
// Number of bits that can be embedded in the chunk
// Number of bits that can be embedded in the chunk
// {floor(log2(x!)) | x in [2, 21)}
const
auto
numBitsEmbeddedInChunk
=
factorialBitLengthTable
[
chunkSize
];
constexpr
auto
bitLengthTable
=
std
::
array
<
std
::
size_t
,
21
>
{
0
,
0
,
1
,
2
,
4
,
6
,
9
,
12
,
15
,
18
,
21
,
25
,
28
,
32
,
36
,
40
,
44
,
48
,
52
,
56
,
61
,
};
const
auto
numBitsEmbeddedInChunk
=
bitLengthTable
[
chunkSize
];
// Sort functions in the chunk
// Sort functions in the chunk
std
::
sort
(
chunkBegin
,
chunkEnd
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
std
::
sort
(
chunkBegin
,
chunkEnd
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
...
...
src/kyut/watermarker/FunctionOrderingWatermarker.hpp
View file @
233da654
...
@@ -8,7 +8,15 @@ namespace kyut {
...
@@ -8,7 +8,15 @@ namespace kyut {
}
}
namespace
kyut
::
watermarker
{
namespace
kyut
::
watermarker
{
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
divisions
);
/**
}
* @brief Embed watermarks by changing the order of functions.
*
* @param module A reference to the WebAssembly module in which watermarks will be embeded.
* @param stream Input stream containing watermarks to embed.
* @param maxChunkSize The maximum number of functions in the watermark chunk.
* @return Number of watermark bits embedded in the module.
*/
std
::
size_t
embedFunctionOrdering
(
wasm
::
Module
&
module
,
CircularBitStreamReader
&
stream
,
std
::
size_t
maxChunkSize
);
}
// namespace kyut::watermarker
#endif // INCLUDE_kyut_watermark_FunctionOrderingWatermarker_hpp
#endif // INCLUDE_kyut_watermark_FunctionOrderingWatermarker_hpp
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