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
14f6bdee
Verified
Commit
14f6bdee
authored
Oct 03, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ordering): add export-ordering method
parent
7d57b57f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
3 deletions
+50
-3
ExportOrdering.hpp
lib/kyut/methods/ExportOrdering.hpp
+40
-0
FunctionOrdering.hpp
lib/kyut/methods/FunctionOrdering.hpp
+1
-0
pisn.cpp
src/pisn.cpp
+4
-1
snpi.cpp
src/snpi.cpp
+5
-2
No files found.
lib/kyut/methods/ExportOrdering.hpp
0 → 100644
View file @
14f6bdee
#ifndef INCLUDE_kyut_methods_ExportOrdering_hpp
#define INCLUDE_kyut_methods_ExportOrdering_hpp
#include "../Ordering.hpp"
#include "wasm.h"
namespace
kyut
{
class
CircularBitStreamReader
;
class
BitStreamWriter
;
}
// namespace kyut
namespace
kyut
::
methods
::
export_ordering
{
std
::
size_t
embed
(
CircularBitStreamReader
&
r
,
wasm
::
Module
&
module
,
std
::
size_t
chunk_size
)
{
const
auto
size_bits
=
embed_by_ordering
(
r
,
chunk_size
,
std
::
begin
(
module
.
exports
),
std
::
end
(
module
.
exports
),
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
return
size_bits
;
}
std
::
size_t
extract
(
BitStreamWriter
&
w
,
wasm
::
Module
&
module
,
std
::
size_t
chunk_size
)
{
const
auto
size_bits
=
extract_by_ordering
(
w
,
chunk_size
,
std
::
begin
(
module
.
exports
),
std
::
end
(
module
.
exports
),
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
return
size_bits
;
}
}
// namespace kyut::methods::export_ordering
#endif // INCLUDE_kyut_methods_ExportOrdering_hpp
lib/kyut/methods/FunctionOrdering.hpp
View file @
14f6bdee
...
@@ -46,6 +46,7 @@ namespace kyut::methods::function_ordering {
...
@@ -46,6 +46,7 @@ namespace kyut::methods::function_ordering {
[](
const
auto
&
a
,
const
auto
&
b
)
{
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
return
a
->
name
<
b
->
name
;
});
});
return
size_bits
;
return
size_bits
;
}
}
}
// namespace kyut::methods::function_ordering
}
// namespace kyut::methods::function_ordering
...
...
src/pisn.cpp
View file @
14f6bdee
#include <fmt/printf.h>
#include <fmt/printf.h>
#include "cmdline.h"
#include "cmdline.h"
#include "kyut/methods/ExportOrdering.hpp"
#include "kyut/methods/FunctionOrdering.hpp"
#include "kyut/methods/FunctionOrdering.hpp"
#include "wasm-io.h"
#include "wasm-io.h"
...
@@ -14,7 +15,7 @@ int main(int argc, char* argv[]) {
...
@@ -14,7 +15,7 @@ int main(int argc, char* argv[]) {
options
.
add
(
"help"
,
'h'
,
"Print help message"
);
options
.
add
(
"help"
,
'h'
,
"Print help message"
);
options
.
add
(
"version"
,
'v'
,
"Print version"
);
options
.
add
(
"version"
,
'v'
,
"Print version"
);
options
.
add
<
std
::
string
>
(
"method"
,
'm'
,
"Embedding method (function-ordering
)"
,
true
,
""
,
cmdline
::
oneof
<
std
::
string
>
(
"function
-ordering"
));
options
.
add
<
std
::
string
>
(
"method"
,
'm'
,
"Embedding method (function-ordering
, export-ordering)"
,
true
,
""
,
cmdline
::
oneof
<
std
::
string
>
(
"function-ordering"
,
"export
-ordering"
));
options
.
add
<
std
::
size_t
>
(
"chunk-size"
,
'c'
,
"Chunk size [2~20]"
,
false
,
20
,
cmdline
::
range
<
std
::
size_t
>
(
2
,
20
));
options
.
add
<
std
::
size_t
>
(
"chunk-size"
,
'c'
,
"Chunk size [2~20]"
,
false
,
20
,
cmdline
::
range
<
std
::
size_t
>
(
2
,
20
));
options
.
add
<
std
::
string
>
(
"dump"
,
0
,
"Output format (ascii, hex)"
,
false
,
"ascii"
,
cmdline
::
oneof
<
std
::
string
>
(
"ascii"
,
"hex"
));
options
.
add
<
std
::
string
>
(
"dump"
,
0
,
"Output format (ascii, hex)"
,
false
,
"ascii"
,
cmdline
::
oneof
<
std
::
string
>
(
"ascii"
,
"hex"
));
...
@@ -52,6 +53,8 @@ int main(int argc, char* argv[]) {
...
@@ -52,6 +53,8 @@ int main(int argc, char* argv[]) {
std
::
size_t
size_bits
;
std
::
size_t
size_bits
;
if
(
method
==
"function-ordering"
)
{
if
(
method
==
"function-ordering"
)
{
size_bits
=
kyut
::
methods
::
function_ordering
::
extract
(
w
,
module
,
chunk_size
);
size_bits
=
kyut
::
methods
::
function_ordering
::
extract
(
w
,
module
,
chunk_size
);
}
else
if
(
method
==
"export-ordering"
)
{
size_bits
=
kyut
::
methods
::
export_ordering
::
extract
(
w
,
module
,
chunk_size
);
}
else
{
}
else
{
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
}
}
...
...
src/snpi.cpp
View file @
14f6bdee
#include <fmt/printf.h>
#include <fmt/printf.h>
#include "cmdline.h"
#include "cmdline.h"
#include "kyut/methods/ExportOrdering.hpp"
#include "kyut/methods/FunctionOrdering.hpp"
#include "kyut/methods/FunctionOrdering.hpp"
#include "support/colors.h"
#include "support/colors.h"
#include "wasm-io.h"
#include "wasm-io.h"
...
@@ -16,7 +17,7 @@ int main(int argc, char* argv[]) {
...
@@ -16,7 +17,7 @@ int main(int argc, char* argv[]) {
options
.
add
(
"version"
,
'v'
,
"Print version"
);
options
.
add
(
"version"
,
'v'
,
"Print version"
);
options
.
add
<
std
::
string
>
(
"output"
,
'o'
,
"Output filename"
,
true
);
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
>
(
"method"
,
'm'
,
"Embedding method (function-ordering
, export-ordering)"
,
true
,
""
,
cmdline
::
oneof
<
std
::
string
>
(
"function-ordering"
,
"export
-ordering"
));
options
.
add
<
std
::
string
>
(
"watermark"
,
'w'
,
"Watermark to embed"
,
true
);
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
.
add
<
std
::
size_t
>
(
"chunk-size"
,
'c'
,
"Chunk size [2~20]"
,
false
,
20
,
cmdline
::
range
<
std
::
size_t
>
(
2
,
20
));
...
@@ -69,12 +70,14 @@ int main(int argc, char* argv[]) {
...
@@ -69,12 +70,14 @@ int main(int argc, char* argv[]) {
std
::
size_t
size_bits
;
std
::
size_t
size_bits
;
if
(
method
==
"function-ordering"
)
{
if
(
method
==
"function-ordering"
)
{
size_bits
=
kyut
::
methods
::
function_ordering
::
embed
(
r
,
module
,
chunk_size
);
size_bits
=
kyut
::
methods
::
function_ordering
::
embed
(
r
,
module
,
chunk_size
);
}
else
if
(
method
==
"export-ordering"
)
{
size_bits
=
kyut
::
methods
::
export_ordering
::
embed
(
r
,
module
,
chunk_size
);
}
else
{
}
else
{
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
}
}
Colors
::
setEnabled
(
false
);
Colors
::
setEnabled
(
false
);
wasm
::
ModuleWriter
{}.
write
Text
(
module
,
output
);
wasm
::
ModuleWriter
{}.
write
Binary
(
module
,
output
);
fmt
::
print
(
"{} bits
\n
"
,
size_bits
);
fmt
::
print
(
"{} bits
\n
"
,
size_bits
);
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
...
...
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