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
96284a67
Commit
96284a67
authored
Jan 22, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Function挿入順の変更による電子透かし埋め込みを実装
parent
b89b43e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
8 deletions
+59
-8
FunctionWatermarkPass.cpp
src/nykk/pass/FunctionWatermarkPass.cpp
+59
-8
No files found.
src/nykk/pass/FunctionWatermarkPass.cpp
View file @
96284a67
...
...
@@ -9,6 +9,14 @@
namespace
{
const
llvm
::
cl
::
opt
<
nykk
::
pass
::
RangeOptValue
<
std
::
size_t
>
,
false
,
nykk
::
pass
::
RangeOptParser
<
std
::
size_t
,
2
,
13
>>
fpartition_opt
{
"fpartition"
,
llvm
::
cl
::
desc
(
"Function partition number (2 ~ 10 default 10)"
),
llvm
::
cl
::
value_desc
(
"size"
),
llvm
::
cl
::
init
(
nykk
::
pass
::
RangeOptValue
<
std
::
size_t
>
{
10
}),
};
/**
* @brief Watermarking pass by function ordering methods.
*/
...
...
@@ -47,20 +55,63 @@ namespace
const
auto
bit_stream
=
nykk
::
CircularBitStream
::
from_string
(
nykk
::
pass
::
watermark_opt
);
std
::
size_t
num_embedded_bits
=
0
;
bool
is_changed
=
false
;
auto
functions
=
std
::
vector
<
std
::
reference_wrapper
<
llvm
::
Function
>>
(
module
.
getFunctionList
().
rbegin
(),
module
.
getFunctionList
().
rend
());
auto
functions
=
std
::
vector
<
std
::
reference_wrapper
<
llvm
::
Function
>>
();
functions
.
reserve
(
module
.
size
());
for
(
auto
&
func
:
module
.
functions
())
{
if
(
!
func
.
empty
())
{
functions
.
emplace_back
(
std
::
ref
(
func
));
}
}
if
(
functions
.
size
()
<
2
)
{
llvm
::
errs
()
<<
module
.
getName
()
<<
", "
<<
functions
.
size
()
<<
", "
<<
num_embedded_bits
<<
"
\n
"
;
return
false
;
}
const
auto
partition
=
fpartition_opt
.
getValue
().
value
;
const
auto
perm_table
=
nykk
::
create_permutation_table
(
partition
);
// Table of {log2 x! | x < 13}
constexpr
auto
possible_embedding_bits
=
std
::
array
<
std
::
size_t
,
13
>
{
0
,
0
,
1
,
2
,
4
,
6
,
9
,
12
,
15
,
18
,
21
,
25
,
28
,
};
std
::
size_t
index
=
0
;
for
(;
index
+
partition
<=
functions
.
size
();
index
+=
partition
)
{
// Part of watermark to embed.
const
auto
data
=
bit_stream
->
read
(
possible_embedding_bits
[
partition
]);
// Shuffles each `partition` functions.
for
(
std
::
size_t
i
=
0
;
i
<
partition
;
i
++
)
{
const
auto
n
=
index
+
perm_table
.
at
(
data
).
at
(
i
);
functions
[
n
].
get
().
removeFromParent
();
module
.
getFunctionList
().
push_back
(
&
functions
[
n
].
get
());
}
num_embedded_bits
+=
possible_embedding_bits
[
partition
];
}
for
(
const
auto
&
func
:
functions
)
// Inserts rest functions.
for
(;
index
<
functions
.
size
();
index
++
)
{
is_changed
=
true
;
func
.
get
().
removeFromParent
();
module
.
getFunctionList
().
push_back
(
&
func
.
get
());
functions
[
index
].
get
().
removeFromParent
();
module
.
getFunctionList
().
push_back
(
&
functions
[
index
].
get
());
}
llvm
::
errs
()
<<
module
.
getName
()
<<
", "
<<
module
.
size
()
<<
", "
<<
num_embedded_bits
<<
"
\n
"
;
llvm
::
errs
()
<<
module
.
getName
()
<<
", "
<<
functions
.
size
()
<<
", "
<<
num_embedded_bits
<<
"
\n
"
;
return
is_changed
;
return
true
;
}
};
...
...
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