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
e6723dd1
Commit
e6723dd1
authored
Jul 08, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: Add bit stream reader
parent
c419a4f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
2 deletions
+79
-2
add.wast
example/add.wast
+6
-0
BitStreamReader.hpp
src/kyut/BitStreamReader.hpp
+65
-0
snpi.cpp
src/snpi.cpp
+8
-2
No files found.
example/add.wast
View file @
e6723dd1
...
...
@@ -16,4 +16,10 @@
(local.get $c)
)
)
(func $inc (param $a i32) (result i32)
(i32.add
(local.get $a)
(i32.const 1)
)
)
)
src/kyut/BitStreamReader.hpp
0 → 100644
View file @
e6723dd1
#ifndef INCLUDE_kyut_BitStreamReader_hpp
#define INCLUDE_kyut_BitStreamReader_hpp
#include <cstdint>
#include <memory>
#include <string_view>
#include <vector>
namespace
kyut
{
class
BitStreamReader
{
public
:
explicit
BitStreamReader
(
std
::
vector
<
std
::
uint8_t
>
data
)
:
data_
(
std
::
move
(
data
))
,
pos_read_
(
0
)
{}
template
<
typename
Iterator
>
explicit
BitStreamReader
(
Iterator
begin
,
Iterator
end
)
:
BitStreamReader
({
begin
,
end
})
{}
BitStreamReader
(
const
BitStreamReader
&
)
=
delete
;
BitStreamReader
(
BitStreamReader
&&
)
=
delete
;
BitStreamReader
&
operator
=
(
const
BitStreamReader
&
)
=
delete
;
BitStreamReader
&
operator
=
(
BitStreamReader
&&
)
=
delete
;
~
BitStreamReader
()
noexcept
=
default
;
static
std
::
unique_ptr
<
BitStreamReader
>
fromString
(
std
::
string_view
s
)
{
return
std
::
make_unique
<
BitStreamReader
>
(
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()),
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()
+
s
.
size
()));
}
[[
nodiscard
]]
std
::
size_t
tell
()
const
noexcept
{
return
pos_read_
;
}
bool
readBit
()
{
if
(
data_
.
empty
())
{
return
false
;
}
const
auto
pos
=
pos_read_
;
pos_read_
=
(
pos_read_
+
1
)
%
data_
.
size
();
return
(
data_
[
pos
/
8
]
>>
(
pos
%
8
))
&
1
;
}
std
::
uint64_t
read
(
std
::
size_t
countBits
)
{
std
::
uint64_t
value
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
countBits
;
i
++
)
{
value
<<=
1
;
value
|=
readBit
();
}
return
value
;
}
private
:
std
::
vector
<
std
::
uint8_t
>
data_
;
std
::
size_t
pos_read_
;
};
}
// namespace kyut
#endif // INCLUDE_kyut_BitStreamReader_hpp
src/snpi.cpp
View file @
e6723dd1
...
...
@@ -2,21 +2,27 @@
#include <wasm-io.h>
#include "kyut/BitStreamReader.hpp"
int
main
(
int
argc
,
char
*
argv
[])
{
// Parse command line options
if
(
argc
!=
2
)
{
fmt
::
print
(
std
::
cerr
,
"{} <input file>
\n
"
,
argv
[
0
]);
if
(
argc
!=
3
)
{
fmt
::
print
(
std
::
cerr
,
"{} <input file>
<watermark>
\n
"
,
argv
[
0
]);
return
1
;
}
const
std
::
string
inputFile
=
argv
[
1
];
const
std
::
string
watermark
=
argv
[
2
];
try
{
// Read the input module
wasm
::
Module
module
;
wasm
::
ModuleReader
{}.
read
(
inputFile
,
module
);
// Embed watermarks
const
auto
stream
=
kyut
::
BitStreamReader
::
fromString
(
watermark
);
// Output the result
wasm
::
ModuleWriter
{}.
writeText
(
module
,
""
);
}
catch
(
const
wasm
::
ParseException
&
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