Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
llvm-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
llvm-watermarker
Commits
2cc70c02
Commit
2cc70c02
authored
Dec 09, 2018
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
任意の長さの文字列を透かしとして埋め込めるように機能拡張
parent
5637f0cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
26 deletions
+24
-26
CircularBitStream.hpp
src/nykk/CircularBitStream.hpp
+6
-5
BlockWatermarkPass.cpp
src/nykk/pass/BlockWatermarkPass.cpp
+5
-8
Opts.hpp
src/nykk/pass/Opts.hpp
+1
-1
TestCircularBitStream.hpp
test/TestCircularBitStream.hpp
+12
-12
No files found.
src/nykk/CircularBitStream.hpp
View file @
2cc70c02
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include <cassert>
#include <cassert>
#include <cstddef>
#include <cstddef>
#include <cstdint>
#include <cstdint>
#include <memory>
#include <string_view>
#include <string_view>
#include <vector>
#include <vector>
...
@@ -12,9 +13,9 @@ namespace nykk
...
@@ -12,9 +13,9 @@ namespace nykk
class
CircularBitStream
class
CircularBitStream
{
{
public
:
public
:
static
CircularBitStream
from_string
(
std
::
string_view
s
)
static
std
::
unique_ptr
<
CircularBitStream
>
from_string
(
std
::
string_view
s
)
{
{
return
CircularBitStream
{
reinterpret_cast
<
const
std
::
byte
*>
(
s
.
data
()),
s
.
size
()
}
;
return
std
::
make_unique
<
CircularBitStream
>
(
reinterpret_cast
<
const
std
::
byte
*>
(
s
.
data
()),
s
.
size
())
;
}
}
explicit
CircularBitStream
(
const
std
::
byte
*
pointer
,
std
::
size_t
length
)
explicit
CircularBitStream
(
const
std
::
byte
*
pointer
,
std
::
size_t
length
)
...
@@ -24,12 +25,12 @@ namespace nykk
...
@@ -24,12 +25,12 @@ namespace nykk
assert
(
pointer
!=
nullptr
||
length
==
0
);
assert
(
pointer
!=
nullptr
||
length
==
0
);
}
}
// Uncopyable, movable.
// Uncopyable,
un
movable.
CircularBitStream
(
const
CircularBitStream
&
)
=
delete
;
CircularBitStream
(
const
CircularBitStream
&
)
=
delete
;
CircularBitStream
(
CircularBitStream
&&
)
=
de
fault
;
CircularBitStream
(
CircularBitStream
&&
)
=
de
lete
;
CircularBitStream
&
operator
=
(
const
CircularBitStream
&
)
=
delete
;
CircularBitStream
&
operator
=
(
const
CircularBitStream
&
)
=
delete
;
CircularBitStream
&
operator
=
(
CircularBitStream
&&
)
=
de
fault
;
CircularBitStream
&
operator
=
(
CircularBitStream
&&
)
=
de
lete
;
~
CircularBitStream
()
=
default
;
~
CircularBitStream
()
=
default
;
...
...
src/nykk/pass/BlockWatermarkPass.cpp
View file @
2cc70c02
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <llvm/Pass.h>
#include <llvm/Pass.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/raw_ostream.h>
#include "../CircularBitStream.hpp"
#include "../PermutationTable.hpp"
#include "../PermutationTable.hpp"
#include "Opts.hpp"
#include "Opts.hpp"
...
@@ -65,8 +66,8 @@ namespace
...
@@ -65,8 +66,8 @@ namespace
explicit
BlockWatermarkPass
()
explicit
BlockWatermarkPass
()
:
FunctionPass
(
ID
)
:
FunctionPass
(
ID
)
,
module_name_
()
,
module_name_
()
,
bit_stream_
()
,
perm_table_
()
,
perm_table_
()
,
bit_pos_
(
0
)
{
{
}
}
...
@@ -89,8 +90,8 @@ namespace
...
@@ -89,8 +90,8 @@ namespace
bool
doInitialization
(
llvm
::
Module
&
module
)
override
bool
doInitialization
(
llvm
::
Module
&
module
)
override
{
{
module_name_
=
module
.
getName
();
module_name_
=
module
.
getName
();
bit_stream_
=
nykk
::
CircularBitStream
::
from_string
(
nykk
::
pass
::
watermark_opt
);
perm_table_
=
nykk
::
create_permutation_table
(
partition_opt
.
getValue
().
value
);
perm_table_
=
nykk
::
create_permutation_table
(
partition_opt
.
getValue
().
value
);
bit_pos_
=
0
;
llvm
::
errs
()
<<
"func"
<<
", "
<<
"blocks"
<<
", "
<<
"bits"
<<
"
\n
"
;
llvm
::
errs
()
<<
"func"
<<
", "
<<
"blocks"
<<
", "
<<
"bits"
<<
"
\n
"
;
...
@@ -144,12 +145,10 @@ namespace
...
@@ -144,12 +145,10 @@ namespace
std
::
size_t
num_embedded_bits
=
0
;
std
::
size_t
num_embedded_bits
=
0
;
std
::
size_t
block_index
=
1
;
// Without entry block.
std
::
size_t
block_index
=
1
;
// Without entry block.
const
auto
bit_mask
=
(
1
<<
possible_embedding_bits
[
partition
])
-
1
;
for
(;
block_index
+
partition
<=
blocks
.
size
();
block_index
+=
partition
)
for
(;
block_index
+
partition
<=
blocks
.
size
();
block_index
+=
partition
)
{
{
// Part of watermark to embed.
// Part of watermark to embed.
const
auto
data
=
(
nykk
::
pass
::
watermark_opt
>>
bit_pos_
)
&
bit_mask
;
const
auto
data
=
bit_stream_
->
read
(
possible_embedding_bits
[
partition
])
;
// Shuffles each `partition` blocks.
// Shuffles each `partition` blocks.
for
(
std
::
size_t
i
=
0
;
i
<
partition
;
i
++
)
for
(
std
::
size_t
i
=
0
;
i
<
partition
;
i
++
)
...
@@ -161,8 +160,6 @@ namespace
...
@@ -161,8 +160,6 @@ namespace
}
}
num_embedded_bits
+=
possible_embedding_bits
[
partition
];
num_embedded_bits
+=
possible_embedding_bits
[
partition
];
bit_pos_
+=
possible_embedding_bits
[
partition
];
bit_pos_
%=
sizeof
(
std
::
uint32_t
)
*
8
;
}
}
// Inserts rest blocks.
// Inserts rest blocks.
...
@@ -179,8 +176,8 @@ namespace
...
@@ -179,8 +176,8 @@ namespace
private
:
private
:
std
::
string
module_name_
;
std
::
string
module_name_
;
std
::
unique_ptr
<
nykk
::
CircularBitStream
>
bit_stream_
;
std
::
vector
<
std
::
vector
<
std
::
uint8_t
>>
perm_table_
;
std
::
vector
<
std
::
vector
<
std
::
uint8_t
>>
perm_table_
;
std
::
uint32_t
bit_pos_
;
};
};
char
BlockWatermarkPass
::
ID
;
char
BlockWatermarkPass
::
ID
;
...
...
src/nykk/pass/Opts.hpp
View file @
2cc70c02
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
namespace
nykk
::
pass
namespace
nykk
::
pass
{
{
const
llvm
::
cl
::
opt
<
int
>
watermark_opt
const
llvm
::
cl
::
opt
<
std
::
string
>
watermark_opt
{
{
"watermark"
,
"watermark"
,
llvm
::
cl
::
desc
(
"Watermark (32bit)"
),
llvm
::
cl
::
desc
(
"Watermark (32bit)"
),
...
...
test/TestCircularBitStream.hpp
View file @
2cc70c02
...
@@ -7,22 +7,22 @@ inline void run_test_circular_bit_stream()
...
@@ -7,22 +7,22 @@ inline void run_test_circular_bit_stream()
{
{
auto
s
=
nykk
::
CircularBitStream
::
from_string
(
u8"
\xab\xcd\xef\x98
"
);
auto
s
=
nykk
::
CircularBitStream
::
from_string
(
u8"
\xab\xcd\xef\x98
"
);
assert
(
s
.
size_bytes
()
==
4
);
assert
(
s
->
size_bytes
()
==
4
);
assert
(
s
.
size_bits
()
==
32
);
assert
(
s
->
size_bits
()
==
32
);
assert
(
s
.
read_bit
()
==
true
);
assert
(
s
->
read_bit
()
==
true
);
assert
(
s
.
read_bit
()
==
true
);
assert
(
s
->
read_bit
()
==
true
);
assert
(
s
.
read_bit
()
==
false
);
assert
(
s
->
read_bit
()
==
false
);
assert
(
s
.
pos_bit
()
==
3
);
assert
(
s
->
pos_bit
()
==
3
);
assert
(
s
.
read
(
17
)
==
0x1f9b5
);
assert
(
s
->
read
(
17
)
==
0x1f9b5
);
assert
(
s
.
pos_bit
()
==
20
);
assert
(
s
->
pos_bit
()
==
20
);
assert
(
s
.
read
(
16
)
==
0xb98e
);
assert
(
s
->
read
(
16
)
==
0xb98e
);
assert
(
s
.
pos_bit
()
==
4
);
assert
(
s
->
pos_bit
()
==
4
);
assert
(
s
.
read
(
64
)
==
0xb98efcdab98efcda
);
assert
(
s
->
read
(
64
)
==
0xb98efcdab98efcda
);
assert
(
s
.
pos_bit
()
==
4
);
assert
(
s
->
pos_bit
()
==
4
);
}
}
#endif
#endif
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