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
7df23ceb
Commit
7df23ceb
authored
May 11, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent undefined behavior in magiskboot
parent
6099f3b0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
45 deletions
+31
-45
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+1
-6
compress.cpp
native/jni/magiskboot/compress.cpp
+28
-27
dtb.cpp
native/jni/magiskboot/dtb.cpp
+0
-2
hexpatch.cpp
native/jni/magiskboot/hexpatch.cpp
+1
-1
main.cpp
native/jni/magiskboot/main.cpp
+0
-6
pattern.cpp
native/jni/magiskboot/pattern.cpp
+0
-2
ramdisk.cpp
native/jni/magiskboot/ramdisk.cpp
+1
-1
No files found.
native/jni/magiskboot/bootimg.cpp
View file @
7df23ceb
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <libfdt.h>
#include <functional>
#include <memory>
#include <libfdt.h>
#include <mincrypt/sha.h>
#include <mincrypt/sha256.h>
#include <utils.hpp>
...
...
native/jni/magiskboot/compress.cpp
View file @
7df23ceb
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <memory>
#include <functional>
...
...
@@ -56,7 +51,8 @@ protected:
ENCODE
}
mode
;
gz_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
)
{
gz_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
),
strm
{},
outbuf
{
0
}
{
switch
(
mode
)
{
case
DECODE
:
inflateInit2
(
&
strm
,
15
|
16
);
...
...
@@ -131,7 +127,8 @@ protected:
ENCODE
}
mode
;
bz_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
)
{
bz_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
),
strm
{},
outbuf
{
0
}
{
switch
(
mode
)
{
case
DECODE
:
BZ2_bzDecompressInit
(
&
strm
,
0
,
0
);
...
...
@@ -200,8 +197,8 @@ protected:
ENCODE_LZMA
}
mode
;
lzma_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
),
strm
(
LZMA_STREAM_INIT
)
{
lzma_strm
(
mode_t
mode
,
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
mode
(
mode
),
strm
(
LZMA_STREAM_INIT
),
outbuf
{
0
}
{
lzma_options_lzma
opt
;
// Initialize preset
...
...
@@ -211,18 +208,21 @@ protected:
{
.
id
=
LZMA_VLI_UNKNOWN
,
.
options
=
nullptr
},
};
lzma_ret
ret
;
lzma_ret
code
;
switch
(
mode
)
{
case
DECODE
:
ret
=
lzma_auto_decoder
(
&
strm
,
UINT64_MAX
,
0
);
code
=
lzma_auto_decoder
(
&
strm
,
UINT64_MAX
,
0
);
break
;
case
ENCODE_XZ
:
ret
=
lzma_stream_encoder
(
&
strm
,
filters
,
LZMA_CHECK_CRC32
);
code
=
lzma_stream_encoder
(
&
strm
,
filters
,
LZMA_CHECK_CRC32
);
break
;
case
ENCODE_LZMA
:
ret
=
lzma_alone_encoder
(
&
strm
,
&
opt
);
code
=
lzma_alone_encoder
(
&
strm
,
&
opt
);
break
;
}
if
(
code
!=
LZMA_OK
)
{
LOGE
(
"LZMA initialization failed (%d)
\n
"
,
code
);
}
}
private
:
...
...
@@ -264,7 +264,8 @@ public:
class
LZ4F_decoder
:
public
cpr_stream
{
public
:
explicit
LZ4F_decoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
outbuf
(
nullptr
)
{
explicit
LZ4F_decoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
ctx
(
nullptr
),
outbuf
(
nullptr
),
outCapacity
(
0
)
{
LZ4F_createDecompressionContext
(
&
ctx
,
LZ4F_VERSION
);
}
...
...
@@ -319,8 +320,8 @@ private:
class
LZ4F_encoder
:
public
cpr_stream
{
public
:
explicit
LZ4F_encoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)
),
outbuf
(
nullptr
),
outCapacity
(
0
)
{
explicit
LZ4F_encoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
ctx
(
nullptr
),
outbuf
(
nullptr
),
outCapacity
(
0
)
{
LZ4F_createCompressionContext
(
&
ctx
,
LZ4F_VERSION
);
}
...
...
@@ -362,14 +363,14 @@ private:
int
write_header
()
{
LZ4F_preferences_t
prefs
{
.
autoFlush
=
1
,
.
compressionLevel
=
9
,
.
frameInfo
=
{
.
blockMode
=
LZ4F_blockIndependent
,
.
blockSizeID
=
LZ4F_max4MB
,
.
blockMode
=
LZ4F_blockIndependent
,
.
contentChecksumFlag
=
LZ4F_contentChecksumEnabled
,
.
blockChecksumFlag
=
LZ4F_noBlockChecksum
,
.
contentChecksumFlag
=
LZ4F_contentChecksumEnabled
}
},
.
compressionLevel
=
9
,
.
autoFlush
=
1
,
};
outCapacity
=
LZ4F_compressBound
(
BLOCK_SZ
,
&
prefs
);
outbuf
=
new
uint8_t
[
outCapacity
];
...
...
@@ -380,9 +381,9 @@ private:
class
LZ4_decoder
:
public
cpr_stream
{
public
:
explicit
LZ4_decoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
out_buf
(
new
char
[
LZ4_UNCOMPRESSED
]),
buf
(
new
char
[
LZ4_COMPRESSED
]),
init
(
false
),
block_sz
(
0
),
buf_off
(
0
)
{}
explicit
LZ4_decoder
(
stream_ptr
&&
base
)
:
cpr_stream
(
std
::
move
(
base
)),
out_buf
(
new
char
[
LZ4_UNCOMPRESSED
]),
buf
(
new
char
[
LZ4_COMPRESSED
]),
init
(
false
),
block_sz
(
0
),
buf_off
(
0
)
{}
~
LZ4_decoder
()
override
{
delete
[]
out_buf
;
...
...
@@ -447,9 +448,9 @@ private:
class
LZ4_encoder
:
public
cpr_stream
{
public
:
explicit
LZ4_encoder
(
stream_ptr
&&
base
,
bool
lg
)
:
cpr_stream
(
std
::
move
(
base
)),
outbuf
(
new
char
[
LZ4_COMPRESSED
]),
buf
(
new
char
[
LZ4_UNCOMPRESSED
]),
init
(
false
),
lg
(
lg
),
buf_off
(
0
),
in_total
(
0
)
{}
explicit
LZ4_encoder
(
stream_ptr
&&
base
,
bool
lg
)
:
cpr_stream
(
std
::
move
(
base
)),
outbuf
(
new
char
[
LZ4_COMPRESSED
]),
buf
(
new
char
[
LZ4_UNCOMPRESSED
]),
init
(
false
),
lg
(
lg
),
buf_off
(
0
),
in_total
(
0
)
{}
int
write
(
const
void
*
in
,
size_t
size
)
override
{
int
ret
=
0
;
...
...
native/jni/magiskboot/dtb.cpp
View file @
7df23ceb
#include <unistd.h>
#include <sys/mman.h>
#include <bitset>
#include <vector>
#include <map>
...
...
native/jni/magiskboot/hexpatch.cpp
View file @
7df23ceb
...
...
@@ -34,7 +34,7 @@ int hexpatch(const char *image, const char *from, const char *to) {
curr
=
static_cast
<
uint8_t
*>
(
memmem
(
curr
,
end
-
curr
,
pattern
.
data
(),
pattern
.
size
()));
if
(
curr
==
nullptr
)
return
patched
;
fprintf
(
stderr
,
"Patch @ %08X [%s] -> [%s]
\n
"
,
curr
-
buf
,
from
,
to
);
fprintf
(
stderr
,
"Patch @ %08X [%s] -> [%s]
\n
"
,
(
unsigned
)(
curr
-
buf
)
,
from
,
to
);
memset
(
curr
,
0
,
pattern
.
size
());
memcpy
(
curr
,
patch
.
data
(),
patch
.
size
());
patched
=
0
;
...
...
native/jni/magiskboot/main.cpp
View file @
7df23ceb
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <sys/mman.h>
#include <mincrypt/sha.h>
#include <utils.hpp>
...
...
native/jni/magiskboot/pattern.cpp
View file @
7df23ceb
#include <malloc.h>
#include <utils.hpp>
#include "magiskboot.hpp"
...
...
native/jni/magiskboot/ramdisk.cpp
View file @
7df23ceb
...
...
@@ -31,7 +31,7 @@ public:
bool
check_env
(
const
char
*
name
)
{
const
char
*
val
=
getenv
(
name
);
return
val
?
val
==
"true"
sv
:
false
;
return
val
!=
nullptr
&&
val
==
"true"
sv
;
}
void
magisk_cpio
::
patch
()
{
...
...
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