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
5024f460
Verified
Commit
5024f460
authored
Jan 09, 2021
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
insert a watermark as a static memory segment
parent
ed66defc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
kyuk.cpp
src/kyuk.cpp
+43
-0
No files found.
src/kyuk.cpp
View file @
5024f460
...
...
@@ -8,6 +8,44 @@ namespace {
const
std
::
string
program_name
=
"kyuk"
;
const
std
::
string
version
=
"0.1.0"
;
std
::
uint32_t
insert_data
(
wasm
::
Module
&
module
,
const
std
::
string
&
watermark
)
{
// Calculate new data offset for watermark storage (and counter)
std
::
uint32_t
offset
=
0
;
for
(
const
auto
&
seg
:
module
.
memory
.
segments
)
{
std
::
uint32_t
begin
=
seg
.
offset
->
cast
<
wasm
::
Const
>
()
->
value
.
geti32
();
std
::
uint32_t
size
=
seg
.
data
.
size
();
offset
=
(
std
::
max
)(
begin
+
size
,
offset
);
}
const
std
::
uint32_t
align
=
16
;
offset
=
offset
%
align
==
0
?
offset
:
(
offset
/
align
+
1
)
*
align
;
std
::
vector
<
char
>
data
;
// Insert the counter area
// counter has type of i32
data
.
emplace_back
(
0x00
);
data
.
emplace_back
(
0x00
);
data
.
emplace_back
(
0x00
);
data
.
emplace_back
(
0x00
);
// Insert the watermark
for
(
const
auto
&
x
:
watermark
)
{
data
.
emplace_back
(
x
);
// Watermark cannot contain null character (in the current implementation)
}
data
.
emplace_back
(
'\0'
);
// Need null terminated (in the current implementation)
// Add the memory segment to the module
const
auto
offset_expr
=
module
.
allocator
.
alloc
<
wasm
::
Const
>
();
offset_expr
->
set
(
wasm
::
Literal
{
static_cast
<
std
::
int32_t
>
(
offset
)});
module
.
memory
.
segments
.
emplace_back
(
offset_expr
,
data
);
return
offset
;
}
void
add_parameter
(
wasm
::
Function
&
f
)
{
wasm
::
Type
new_param
{
wasm
::
Type
::
i32
};
...
...
@@ -342,6 +380,11 @@ int main(int argc, char* argv[]) {
wasm
::
Module
module
{};
wasm
::
ModuleReader
{}.
read
(
input
,
module
);
// Insert a watermark data
const
std
::
uint32_t
offset
=
insert_data
(
module
,
watermark
);
(
void
)
offset
;
// Embedding
for
(
const
auto
&
f
:
module
.
functions
)
{
if
(
f
->
body
==
nullptr
)
{
...
...
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