Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
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
Administrator
Magisk
Commits
117ae710
Commit
117ae710
authored
Mar 03, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use custom class instead of std::map
parent
027ec702
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
28 deletions
+33
-28
compress.cpp
native/jni/magiskboot/compress.cpp
+4
-4
format.cpp
native/jni/magiskboot/format.cpp
+15
-18
format.hpp
native/jni/magiskboot/format.hpp
+6
-2
main.cpp
native/jni/magiskboot/main.cpp
+8
-4
No files found.
native/jni/magiskboot/compress.cpp
View file @
117ae710
...
...
@@ -607,8 +607,8 @@ void decompress(char *infile, const char *outfile) {
}
void
compress
(
const
char
*
method
,
const
char
*
infile
,
const
char
*
outfile
)
{
auto
it
=
name2fmt
.
find
(
method
)
;
if
(
it
==
name2fmt
.
end
()
)
format_t
fmt
=
name2fmt
[
method
]
;
if
(
fmt
==
UNKNOWN
)
LOGE
(
"Unknown compression method: [%s]
\n
"
,
method
);
bool
in_std
=
infile
==
"-"
sv
;
...
...
@@ -624,7 +624,7 @@ void compress(const char *method, const char *infile, const char *outfile) {
/* If user does not provide outfile and infile is not
* STDIN, output to <infile>.[ext] */
string
tmp
(
infile
);
tmp
+=
fmt2ext
[
it
->
second
];
tmp
+=
fmt2ext
[
fmt
];
out_fp
=
xfopen
(
tmp
.
data
(),
"we"
);
fprintf
(
stderr
,
"Compressing to [%s]
\n
"
,
tmp
.
data
());
rm_in
=
true
;
...
...
@@ -633,7 +633,7 @@ void compress(const char *method, const char *infile, const char *outfile) {
out_fp
=
outfile
==
"-"
sv
?
stdout
:
xfopen
(
outfile
,
"we"
);
}
auto
strm
=
get_encoder
(
it
->
second
,
make_unique
<
fp_stream
>
(
out_fp
));
auto
strm
=
get_encoder
(
fmt
,
make_unique
<
fp_stream
>
(
out_fp
));
char
buf
[
4096
];
size_t
len
;
...
...
native/jni/magiskboot/format.cpp
View file @
117ae710
#include <string.h>
#include "format.hpp"
std
::
map
<
std
::
string_view
,
format_t
>
name2fmt
;
Name2Fmt
name2fmt
;
Fmt2Name
fmt2name
;
Fmt2Ext
fmt2ext
;
class
FormatInit
{
public
:
FormatInit
()
{
name2fmt
[
"gzip"
]
=
GZIP
;
name2fmt
[
"xz"
]
=
XZ
;
name2fmt
[
"lzma"
]
=
LZMA
;
name2fmt
[
"bzip2"
]
=
BZIP2
;
name2fmt
[
"lz4"
]
=
LZ4
;
name2fmt
[
"lz4_legacy"
]
=
LZ4_LEGACY
;
name2fmt
[
"lz4_lg"
]
=
LZ4_LG
;
}
};
static
FormatInit
init
;
#define CHECKED_MATCH(s) (len >= (sizeof(s) - 1) && BUFFER_MATCH(buf, s))
format_t
check_fmt
(
const
void
*
buf
,
size_t
len
)
{
...
...
@@ -103,3 +86,17 @@ const char *Fmt2Ext::operator[](format_t fmt) {
return
""
;
}
}
#define CHECK(s, f) else if (name == s) return f;
format_t
Name2Fmt
::
operator
[](
std
::
string_view
name
)
{
if
(
0
)
{}
CHECK
(
"gzip"
,
GZIP
)
CHECK
(
"xz"
,
XZ
)
CHECK
(
"lzma"
,
LZMA
)
CHECK
(
"bzip2"
,
BZIP2
)
CHECK
(
"lz4"
,
LZ4
)
CHECK
(
"lz4_legacy"
,
LZ4_LEGACY
)
CHECK
(
"lz4_lg"
,
LZ4_LG
)
else
return
UNKNOWN
;
}
native/jni/magiskboot/format.hpp
View file @
117ae710
#pragma once
#include <map>
#include <string_view>
typedef
enum
{
...
...
@@ -69,8 +68,13 @@ public:
const
char
*
operator
[](
format_t
fmt
);
};
class
Name2Fmt
{
public
:
format_t
operator
[](
std
::
string_view
name
);
};
format_t
check_fmt
(
const
void
*
buf
,
size_t
len
);
extern
std
::
map
<
std
::
string_view
,
format_t
>
name2fmt
;
extern
Name2Fmt
name2fmt
;
extern
Fmt2Name
fmt2name
;
extern
Fmt2Ext
fmt2ext
;
native/jni/magiskboot/main.cpp
View file @
117ae710
...
...
@@ -12,6 +12,12 @@
using
namespace
std
;
static
void
print_methods
()
{
for
(
int
fmt
=
GZIP
;
fmt
<
LZOP
;
++
fmt
)
{
fprintf
(
stderr
,
"%s "
,
fmt2name
[(
format_t
)
fmt
]);
}
}
static
void
usage
(
char
*
arg0
)
{
fprintf
(
stderr
,
R"EOF(MagiskBoot - Boot Image Modification Tool
...
...
@@ -96,8 +102,7 @@ Supported actions:
<infile>/[outfile] can be '-' to be STDIN/STDOUT
Supported methods: )EOF"
,
arg0
);
for
(
auto
&
it
:
name2fmt
)
fprintf
(
stderr
,
"%s "
,
it
.
first
.
data
());
print_methods
();
fprintf
(
stderr
,
R"EOF(
...
...
@@ -106,8 +111,7 @@ Supported actions:
<infile>/[outfile] can be '-' to be STDIN/STDOUT
Supported methods: )EOF"
);
for
(
auto
&
it
:
name2fmt
)
fprintf
(
stderr
,
"%s "
,
it
.
first
.
data
());
print_methods
();
fprintf
(
stderr
,
"
\n\n
"
);
exit
(
1
);
...
...
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