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
10ca4db0
Verified
Commit
10ca4db0
authored
Oct 03, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(snpi): implement embedding using function-ordering method
parent
711fa790
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletion
+63
-1
FunctionOrdering.hpp
lib/kyut/methods/FunctionOrdering.hpp
+32
-0
snpi.cpp
src/snpi.cpp
+31
-1
No files found.
lib/kyut/methods/FunctionOrdering.hpp
0 → 100644
View file @
10ca4db0
#ifndef INCLUDE_kyut_methods_FunctionOrdering_hpp
#define INCLUDE_kyut_methods_FunctionOrdering_hpp
#include "../Ordering.hpp"
#include "wasm.h"
namespace
kyut
{
class
CircularBitStreamReader
;
class
BitStreamWriter
;
}
// namespace kyut
namespace
kyut
::
methods
{
std
::
size_t
embed_by_function_ordering
(
CircularBitStreamReader
&
r
,
wasm
::
Module
&
module
,
std
::
size_t
chunk_size
)
{
const
auto
begin
=
std
::
begin
(
module
.
functions
);
const
auto
end
=
std
::
end
(
module
.
functions
);
const
auto
start
=
std
::
partition
(
begin
,
end
,
[](
const
auto
&
f
)
{
return
f
->
body
==
nullptr
;
});
return
embed_by_ordering
(
r
,
chunk_size
,
start
,
end
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
}
}
// namespace kyut::methods
#endif // INCLUDE_kyut_methods_FunctionOrdering_hpp
src/snpi.cpp
View file @
10ca4db0
#include <fmt/printf.h>
#include "cmdline.h"
#include "kyut/methods/FunctionOrdering.hpp"
#include "wasm-io.h"
namespace
{
...
...
@@ -15,6 +16,7 @@ int main(int argc, char* argv[]) {
options
.
add
<
std
::
string
>
(
"output"
,
'o'
,
"Output filename"
,
true
);
options
.
add
<
std
::
string
>
(
"method"
,
'm'
,
"Embedding method (function-ordering)"
,
true
,
""
,
cmdline
::
oneof
<
std
::
string
>
(
"function-ordering"
));
options
.
add
<
std
::
string
>
(
"watermark"
,
'w'
,
"Watermark to embed"
,
true
);
options
.
add
<
std
::
size_t
>
(
"chunk-size"
,
'c'
,
"Chunk size [2~20]"
,
false
,
20
,
cmdline
::
range
<
std
::
size_t
>
(
2
,
20
));
options
.
set_program_name
(
program_name
);
...
...
@@ -30,21 +32,49 @@ int main(int argc, char* argv[]) {
std
::
exit
(
EXIT_SUCCESS
);
}
if
(
options
.
rest
().
empty
())
{
if
(
options
.
get
<
std
::
string
>
(
"watermark"
).
empty
())
{
// Zero-length watermark.
fmt
::
print
(
std
::
cerr
,
"no watermark
\n
"
);
fmt
::
print
(
std
::
cerr
,
"{}"
,
options
.
usage
());
std
::
exit
(
EXIT_FAILURE
);
}
if
(
options
.
rest
().
size
()
==
0
)
{
// No input file specified.
fmt
::
print
(
std
::
cerr
,
"no input file
\n
"
);
fmt
::
print
(
std
::
cerr
,
"{}"
,
options
.
usage
());
std
::
exit
(
EXIT_FAILURE
);
}
if
(
options
.
rest
().
size
()
>
1
)
{
// Too many input files.
fmt
::
print
(
std
::
cerr
,
"too many input files
\n
"
);
fmt
::
print
(
std
::
cerr
,
"{}"
,
options
.
usage
());
std
::
exit
(
EXIT_FAILURE
);
}
const
auto
input
=
options
.
rest
()[
0
];
const
auto
output
=
options
.
get
<
std
::
string
>
(
"output"
);
const
auto
method
=
options
.
get
<
std
::
string
>
(
"method"
);
const
auto
watermark
=
options
.
get
<
std
::
string
>
(
"watermark"
);
[[
maybe_unused
]]
const
auto
chunk_size
=
options
.
get
<
std
::
size_t
>
(
"chunk-size"
);
try
{
kyut
::
CircularBitStreamReader
r
{
watermark
};
wasm
::
Module
module
{};
wasm
::
ModuleReader
{}.
read
(
input
,
module
);
std
::
size_t
size_bits
;
if
(
method
==
"function-ordering"
)
{
size_bits
=
kyut
::
methods
::
embed_by_function_ordering
(
r
,
module
,
chunk_size
);
}
else
{
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
}
wasm
::
ModuleWriter
{}.
write
(
module
,
output
);
fmt
::
print
(
"{} bits
\n
"
,
size_bits
);
}
catch
(
const
std
::
exception
&
e
)
{
fmt
::
print
(
std
::
cerr
,
"error: {}
\n
"
,
e
.
what
());
std
::
exit
(
EXIT_FAILURE
);
...
...
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