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
844bc2d8
Commit
844bc2d8
authored
Aug 13, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused code
parent
27f7fa71
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
101 deletions
+6
-101
ramdisk.cpp
native/jni/magiskboot/ramdisk.cpp
+6
-64
cpio.cpp
native/jni/utils/cpio.cpp
+0
-28
cpio.hpp
native/jni/utils/include/cpio.hpp
+0
-9
No files found.
native/jni/magiskboot/ramdisk.cpp
View file @
844bc2d8
...
@@ -6,8 +6,6 @@
...
@@ -6,8 +6,6 @@
using
namespace
std
;
using
namespace
std
;
constexpr
char
RAMDISK_XZ
[]
=
"ramdisk.cpio.xz"
;
static
const
char
*
UNSUPPORT_LIST
[]
=
static
const
char
*
UNSUPPORT_LIST
[]
=
{
"sbin/launch_daemonsu.sh"
,
"sbin/su"
,
"init.xposed.rc"
,
{
"sbin/launch_daemonsu.sh"
,
"sbin/su"
,
"init.xposed.rc"
,
"boot/sbin/launch_daemonsu.sh"
};
"boot/sbin/launch_daemonsu.sh"
};
...
@@ -18,15 +16,12 @@ static const char *MAGISK_LIST[] =
...
@@ -18,15 +16,12 @@ static const char *MAGISK_LIST[] =
class
magisk_cpio
:
public
cpio_rw
{
class
magisk_cpio
:
public
cpio_rw
{
public
:
public
:
magisk_cpio
()
=
default
;
using
cpio_rw
::
cpio_rw
;
explicit
magisk_cpio
(
const
char
*
filename
)
:
cpio_rw
(
filename
)
{}
void
patch
();
void
patch
();
int
test
();
int
test
();
char
*
sha1
();
char
*
sha1
();
void
restore
();
void
restore
();
void
backup
(
const
char
*
orig
);
void
backup
(
const
char
*
orig
);
void
compress
();
void
decompress
();
};
};
bool
check_env
(
const
char
*
name
)
{
bool
check_env
(
const
char
*
name
)
{
...
@@ -68,35 +63,25 @@ void magisk_cpio::patch() {
...
@@ -68,35 +63,25 @@ void magisk_cpio::patch() {
#define STOCK_BOOT 0
#define STOCK_BOOT 0
#define MAGISK_PATCHED (1 << 0)
#define MAGISK_PATCHED (1 << 0)
#define UNSUPPORTED_CPIO (1 << 1)
#define UNSUPPORTED_CPIO (1 << 1)
#define COMPRESSED_CPIO (1 << 2)
int
magisk_cpio
::
test
()
{
int
magisk_cpio
::
test
()
{
for
(
auto
file
:
UNSUPPORT_LIST
)
for
(
auto
file
:
UNSUPPORT_LIST
)
{
if
(
exists
(
file
))
if
(
exists
(
file
))
{
return
UNSUPPORTED_CPIO
;
return
UNSUPPORTED_CPIO
;
}
int
flags
=
STOCK_BOOT
;
if
(
exists
(
RAMDISK_XZ
))
{
flags
|=
COMPRESSED_CPIO
|
MAGISK_PATCHED
;
decompress
();
}
}
for
(
auto
file
:
MAGISK_LIST
)
{
for
(
auto
file
:
MAGISK_LIST
)
{
if
(
exists
(
file
))
{
if
(
exists
(
file
))
{
flags
|=
MAGISK_PATCHED
;
return
MAGISK_PATCHED
;
break
;
}
}
}
}
return
STOCK_BOOT
;
return
flags
;
}
}
#define for_each_line(line, buf, size) \
#define for_each_line(line, buf, size) \
for (line = (char *) buf; line < (char *) buf + size && line[0]; line = strchr(line + 1, '\n') + 1)
for (line = (char *) buf; line < (char *) buf + size && line[0]; line = strchr(line + 1, '\n') + 1)
char
*
magisk_cpio
::
sha1
()
{
char
*
magisk_cpio
::
sha1
()
{
decompress
();
char
sha1
[
41
];
char
sha1
[
41
];
char
*
line
;
char
*
line
;
for
(
auto
&
e
:
entries
)
{
for
(
auto
&
e
:
entries
)
{
...
@@ -127,8 +112,6 @@ char *magisk_cpio::sha1() {
...
@@ -127,8 +112,6 @@ char *magisk_cpio::sha1() {
for (str = (char *) buf; str < (char *) buf + size; str = str += strlen(str) + 1)
for (str = (char *) buf; str < (char *) buf + size; str = str += strlen(str) + 1)
void
magisk_cpio
::
restore
()
{
void
magisk_cpio
::
restore
()
{
decompress
();
if
(
auto
it
=
entries
.
find
(
".backup/.rmlist"
);
it
!=
entries
.
end
())
{
if
(
auto
it
=
entries
.
find
(
".backup/.rmlist"
);
it
!=
entries
.
end
())
{
char
*
file
;
char
*
file
;
for_each_str
(
file
,
it
->
second
->
data
,
it
->
second
->
filesize
)
for_each_str
(
file
,
it
->
second
->
data
,
it
->
second
->
filesize
)
...
@@ -231,43 +214,6 @@ void magisk_cpio::backup(const char *orig) {
...
@@ -231,43 +214,6 @@ void magisk_cpio::backup(const char *orig) {
entries
.
merge
(
bkup_entries
);
entries
.
merge
(
bkup_entries
);
}
}
void
magisk_cpio
::
compress
()
{
if
(
exists
(
RAMDISK_XZ
))
return
;
fprintf
(
stderr
,
"Compressing cpio -> [%s]
\n
"
,
RAMDISK_XZ
);
auto
init
=
entries
.
extract
(
"init"
);
uint8_t
*
data
;
size_t
len
;
auto
strm
=
make_stream_fp
(
get_encoder
(
XZ
,
make_unique
<
byte_stream
>
(
data
,
len
)));
dump
(
strm
.
release
());
entries
.
clear
();
entries
.
insert
(
std
::
move
(
init
));
auto
xz
=
new
cpio_entry
(
RAMDISK_XZ
,
S_IFREG
);
xz
->
data
=
data
;
xz
->
filesize
=
len
;
insert
(
xz
);
}
void
magisk_cpio
::
decompress
()
{
auto
it
=
entries
.
find
(
RAMDISK_XZ
);
if
(
it
==
entries
.
end
())
return
;
fprintf
(
stderr
,
"Decompressing cpio [%s]
\n
"
,
RAMDISK_XZ
);
char
*
data
;
size_t
len
;
{
auto
strm
=
get_decoder
(
XZ
,
make_unique
<
byte_stream
>
(
data
,
len
));
strm
->
write
(
it
->
second
->
data
,
it
->
second
->
filesize
);
}
entries
.
erase
(
it
);
load_cpio
(
data
,
len
);
free
(
data
);
}
int
cpio_commands
(
int
argc
,
char
*
argv
[])
{
int
cpio_commands
(
int
argc
,
char
*
argv
[])
{
char
*
incpio
=
argv
[
0
];
char
*
incpio
=
argv
[
0
];
++
argv
;
++
argv
;
...
@@ -305,10 +251,6 @@ int cpio_commands(int argc, char *argv[]) {
...
@@ -305,10 +251,6 @@ int cpio_commands(int argc, char *argv[]) {
char
*
sha1
=
cpio
.
sha1
();
char
*
sha1
=
cpio
.
sha1
();
if
(
sha1
)
printf
(
"%s
\n
"
,
sha1
);
if
(
sha1
)
printf
(
"%s
\n
"
,
sha1
);
return
0
;
return
0
;
}
else
if
(
cmdv
[
0
]
==
"compress"
sv
){
cpio
.
compress
();
}
else
if
(
cmdv
[
0
]
==
"decompress"
sv
){
cpio
.
decompress
();
}
else
if
(
cmdv
[
0
]
==
"patch"
sv
)
{
}
else
if
(
cmdv
[
0
]
==
"patch"
sv
)
{
cpio
.
patch
();
cpio
.
patch
();
}
else
if
(
cmdc
==
2
&&
cmdv
[
0
]
==
"exists"
sv
)
{
}
else
if
(
cmdc
==
2
&&
cmdv
[
0
]
==
"exists"
sv
)
{
...
...
native/jni/utils/cpio.cpp
View file @
844bc2d8
...
@@ -243,31 +243,3 @@ void cpio_rw::load_cpio(const char *buf, size_t sz) {
...
@@ -243,31 +243,3 @@ void cpio_rw::load_cpio(const char *buf, size_t sz) {
pos_align
(
pos
);
pos_align
(
pos
);
}
}
}
}
cpio_mmap
::
cpio_mmap
(
const
char
*
file
)
{
mmap_ro
(
file
,
buf
,
sz
);
fprintf
(
stderr
,
"Loading cpio: [%s]
\n
"
,
file
);
size_t
pos
=
0
;
cpio_newc_header
*
header
;
unique_ptr
<
cpio_entry_base
>
entry
;
while
(
pos
<
sz
)
{
header
=
(
cpio_newc_header
*
)(
buf
+
pos
);
entry
=
make_unique
<
cpio_entry_base
>
(
header
);
pos
+=
sizeof
(
*
header
);
string_view
name_view
(
buf
+
pos
);
pos
+=
x8u
(
header
->
namesize
);
pos_align
(
pos
);
if
(
name_view
==
"."
||
name_view
==
".."
)
continue
;
if
(
name_view
==
"TRAILER!!!"
)
break
;
entry
->
data
=
buf
+
pos
;
pos
+=
entry
->
filesize
;
entries
[
name_view
]
=
std
::
move
(
entry
);
pos_align
(
pos
);
}
}
cpio_mmap
::~
cpio_mmap
()
{
munmap
(
buf
,
sz
);
}
native/jni/utils/include/cpio.hpp
View file @
844bc2d8
...
@@ -66,12 +66,3 @@ protected:
...
@@ -66,12 +66,3 @@ protected:
void
mv
(
entry_map
::
iterator
&
it
,
const
char
*
to
);
void
mv
(
entry_map
::
iterator
&
it
,
const
char
*
to
);
void
load_cpio
(
const
char
*
buf
,
size_t
sz
);
void
load_cpio
(
const
char
*
buf
,
size_t
sz
);
};
};
class
cpio_mmap
:
public
cpio
{
public
:
explicit
cpio_mmap
(
const
char
*
file
);
~
cpio_mmap
();
private
:
char
*
buf
;
size_t
sz
;
};
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