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
947dae49
Commit
947dae49
authored
Sep 26, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename classes and small adjustments
parent
debd1d7d
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
53 additions
and
57 deletions
+53
-57
getinfo.cpp
native/jni/init/getinfo.cpp
+1
-1
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+1
-1
compress.cpp
native/jni/magiskboot/compress.cpp
+2
-2
compress.h
native/jni/magiskboot/compress.h
+1
-1
ramdisk.cpp
native/jni/magiskboot/ramdisk.cpp
+4
-4
hide_policy.cpp
native/jni/magiskhide/hide_policy.cpp
+1
-1
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+2
-2
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+2
-2
su_daemon.cpp
native/jni/su/su_daemon.cpp
+2
-2
blocking_queue.h
native/jni/utils/include/blocking_queue.h
+27
-31
cpio.h
native/jni/utils/include/cpio.h
+1
-1
stream.h
native/jni/utils/include/stream.h
+2
-2
misc.h
native/jni/utils/misc.h
+7
-7
No files found.
native/jni/init/getinfo.cpp
View file @
947dae49
...
@@ -67,7 +67,7 @@ static bool check_key_combo() {
...
@@ -67,7 +67,7 @@ static bool check_key_combo() {
if
(
events
.
empty
())
if
(
events
.
empty
())
return
false
;
return
false
;
RunF
inally
fin
([
&
]()
->
void
{
run_f
inally
fin
([
&
]()
->
void
{
for
(
const
int
&
fd
:
events
)
for
(
const
int
&
fd
:
events
)
close
(
fd
);
close
(
fd
);
});
});
...
...
native/jni/magiskboot/bootimg.cpp
View file @
947dae49
...
@@ -22,7 +22,7 @@ uint32_t dyn_img_hdr::j32 = 0;
...
@@ -22,7 +22,7 @@ uint32_t dyn_img_hdr::j32 = 0;
uint64_t
dyn_img_hdr
::
j64
=
0
;
uint64_t
dyn_img_hdr
::
j64
=
0
;
static
int64_t
one_step
(
unique_ptr
<
Compression
>
&&
ptr
,
int
fd
,
const
void
*
in
,
size_t
size
)
{
static
int64_t
one_step
(
unique_ptr
<
Compression
>
&&
ptr
,
int
fd
,
const
void
*
in
,
size_t
size
)
{
ptr
->
set
_o
ut
(
make_unique
<
FDOutStream
>
(
fd
));
ptr
->
set
O
ut
(
make_unique
<
FDOutStream
>
(
fd
));
if
(
!
ptr
->
write
(
in
,
size
))
if
(
!
ptr
->
write
(
in
,
size
))
return
-
1
;
return
-
1
;
return
ptr
->
finalize
();
return
ptr
->
finalize
();
...
...
native/jni/magiskboot/compress.cpp
View file @
947dae49
...
@@ -62,7 +62,7 @@ void decompress(char *infile, const char *outfile) {
...
@@ -62,7 +62,7 @@ void decompress(char *infile, const char *outfile) {
out_fd
=
strcmp
(
outfile
,
"-"
)
==
0
?
out_fd
=
strcmp
(
outfile
,
"-"
)
==
0
?
STDOUT_FILENO
:
xopen
(
outfile
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
STDOUT_FILENO
:
xopen
(
outfile
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
cmp
->
set
_o
ut
(
make_unique
<
FDOutStream
>
(
out_fd
));
cmp
->
set
O
ut
(
make_unique
<
FDOutStream
>
(
out_fd
));
if
(
ext
)
*
ext
=
'.'
;
if
(
ext
)
*
ext
=
'.'
;
}
}
if
(
!
cmp
->
write
(
buf
,
len
))
if
(
!
cmp
->
write
(
buf
,
len
))
...
@@ -108,7 +108,7 @@ void compress(const char *method, const char *infile, const char *outfile) {
...
@@ -108,7 +108,7 @@ void compress(const char *method, const char *infile, const char *outfile) {
STDOUT_FILENO
:
xopen
(
outfile
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
STDOUT_FILENO
:
xopen
(
outfile
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
}
}
cmp
->
set
_o
ut
(
make_unique
<
FDOutStream
>
(
out_fd
));
cmp
->
set
O
ut
(
make_unique
<
FDOutStream
>
(
out_fd
));
read_file
(
in_file
,
[
&
](
void
*
buf
,
size_t
len
)
->
void
{
read_file
(
in_file
,
[
&
](
void
*
buf
,
size_t
len
)
->
void
{
if
(
!
cmp
->
write
(
buf
,
len
))
if
(
!
cmp
->
write
(
buf
,
len
))
...
...
native/jni/magiskboot/compress.h
View file @
947dae49
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include <lz4.h>
#include <lz4.h>
#include <lz4frame.h>
#include <lz4frame.h>
#include <lz4hc.h>
#include <lz4hc.h>
#include <
OutS
tream.h>
#include <
s
tream.h>
#include "format.h"
#include "format.h"
...
...
native/jni/magiskboot/ramdisk.cpp
View file @
947dae49
...
@@ -246,13 +246,13 @@ void magisk_cpio::compress() {
...
@@ -246,13 +246,13 @@ void magisk_cpio::compress() {
fprintf
(
stderr
,
"Compressing cpio -> [%s]
\n
"
,
RAMDISK_XZ
);
fprintf
(
stderr
,
"Compressing cpio -> [%s]
\n
"
,
RAMDISK_XZ
);
auto
init
=
entries
.
extract
(
"init"
);
auto
init
=
entries
.
extract
(
"init"
);
XZEncoder
encoder
;
XZEncoder
encoder
;
encoder
.
set
_o
ut
(
make_unique
<
BufOutStream
>
());
encoder
.
set
O
ut
(
make_unique
<
BufOutStream
>
());
output
(
encoder
);
output
(
encoder
);
encoder
.
finalize
();
encoder
.
finalize
();
entries
.
clear
();
entries
.
clear
();
entries
.
insert
(
std
::
move
(
init
));
entries
.
insert
(
std
::
move
(
init
));
auto
xz
=
new
cpio_entry
(
RAMDISK_XZ
,
S_IFREG
);
auto
xz
=
new
cpio_entry
(
RAMDISK_XZ
,
S_IFREG
);
static_cast
<
BufOutStream
*>
(
encoder
.
get
_o
ut
())
->
release
(
xz
->
data
,
xz
->
filesize
);
static_cast
<
BufOutStream
*>
(
encoder
.
get
O
ut
())
->
release
(
xz
->
data
,
xz
->
filesize
);
insert
(
xz
);
insert
(
xz
);
}
}
...
@@ -262,13 +262,13 @@ void magisk_cpio::decompress() {
...
@@ -262,13 +262,13 @@ void magisk_cpio::decompress() {
return
;
return
;
fprintf
(
stderr
,
"Decompressing cpio [%s]
\n
"
,
RAMDISK_XZ
);
fprintf
(
stderr
,
"Decompressing cpio [%s]
\n
"
,
RAMDISK_XZ
);
LZMADecoder
decoder
;
LZMADecoder
decoder
;
decoder
.
set
_o
ut
(
make_unique
<
BufOutStream
>
());
decoder
.
set
O
ut
(
make_unique
<
BufOutStream
>
());
decoder
.
write
(
it
->
second
->
data
,
it
->
second
->
filesize
);
decoder
.
write
(
it
->
second
->
data
,
it
->
second
->
filesize
);
decoder
.
finalize
();
decoder
.
finalize
();
entries
.
erase
(
it
);
entries
.
erase
(
it
);
char
*
buf
;
char
*
buf
;
size_t
sz
;
size_t
sz
;
static_cast
<
BufOutStream
*>
(
decoder
.
get
_o
ut
())
->
getbuf
(
buf
,
sz
);
static_cast
<
BufOutStream
*>
(
decoder
.
get
O
ut
())
->
getbuf
(
buf
,
sz
);
load_cpio
(
buf
,
sz
);
load_cpio
(
buf
,
sz
);
}
}
...
...
native/jni/magiskhide/hide_policy.cpp
View file @
947dae49
...
@@ -36,7 +36,7 @@ static inline void lazy_unmount(const char* mountpoint) {
...
@@ -36,7 +36,7 @@ static inline void lazy_unmount(const char* mountpoint) {
}
}
void
hide_daemon
(
int
pid
)
{
void
hide_daemon
(
int
pid
)
{
RunF
inally
fin
([
=
]()
->
void
{
run_f
inally
fin
([
=
]()
->
void
{
// Send resume signal
// Send resume signal
kill
(
pid
,
SIGCONT
);
kill
(
pid
,
SIGCONT
);
_exit
(
0
);
_exit
(
0
);
...
...
native/jni/magiskhide/hide_utils.cpp
View file @
947dae49
...
@@ -98,7 +98,7 @@ static int add_list(const char *pkg, const char *proc = "") {
...
@@ -98,7 +98,7 @@ static int add_list(const char *pkg, const char *proc = "") {
// Critical region
// Critical region
{
{
MutexG
uard
lock
(
monitor_lock
);
mutex_g
uard
lock
(
monitor_lock
);
hide_set
.
emplace
(
pkg
,
proc
);
hide_set
.
emplace
(
pkg
,
proc
);
}
}
...
@@ -119,7 +119,7 @@ int add_list(int client) {
...
@@ -119,7 +119,7 @@ int add_list(int client) {
static
int
rm_list
(
const
char
*
pkg
,
const
char
*
proc
=
""
)
{
static
int
rm_list
(
const
char
*
pkg
,
const
char
*
proc
=
""
)
{
{
{
// Critical region
// Critical region
MutexG
uard
lock
(
monitor_lock
);
mutex_g
uard
lock
(
monitor_lock
);
bool
remove
=
false
;
bool
remove
=
false
;
auto
next
=
hide_set
.
begin
();
auto
next
=
hide_set
.
begin
();
decltype
(
next
)
cur
;
decltype
(
next
)
cur
;
...
...
native/jni/magiskhide/proc_monitor.cpp
View file @
947dae49
...
@@ -76,7 +76,7 @@ static inline long xptrace(int request, pid_t pid, void *addr = nullptr, intptr_
...
@@ -76,7 +76,7 @@ static inline long xptrace(int request, pid_t pid, void *addr = nullptr, intptr_
}
}
void
update_uid_map
()
{
void
update_uid_map
()
{
MutexG
uard
lock
(
monitor_lock
);
mutex_g
uard
lock
(
monitor_lock
);
uid_proc_map
.
clear
();
uid_proc_map
.
clear
();
string
data_path
(
APP_DATA_DIR
);
string
data_path
(
APP_DATA_DIR
);
data_path
+=
"/0/"
;
data_path
+=
"/0/"
;
...
@@ -336,7 +336,7 @@ void proc_monitor() {
...
@@ -336,7 +336,7 @@ void proc_monitor() {
continue
;
continue
;
}
}
bool
detach
=
false
;
bool
detach
=
false
;
RunFinally
detach_task
([
&
]
{
run_finally
f
([
&
]
{
if
(
detach
)
if
(
detach
)
// Non of our business now
// Non of our business now
detach_pid
(
pid
);
detach_pid
(
pid
);
...
...
native/jni/su/su_daemon.cpp
View file @
947dae49
...
@@ -89,7 +89,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
...
@@ -89,7 +89,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
shared_ptr
<
su_info
>
info
;
shared_ptr
<
su_info
>
info
;
{
{
MutexG
uard
lock
(
cache_lock
);
mutex_g
uard
lock
(
cache_lock
);
if
(
!
cached
||
cached
->
uid
!=
uid
||
!
cached
->
is_fresh
())
if
(
!
cached
||
cached
->
uid
!=
uid
||
!
cached
->
is_fresh
())
cached
=
make_shared
<
su_info
>
(
uid
);
cached
=
make_shared
<
su_info
>
(
uid
);
cached
->
refresh
();
cached
->
refresh
();
...
@@ -97,7 +97,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
...
@@ -97,7 +97,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
}
}
info
->
lock
();
info
->
lock
();
RunF
inally
unlock
([
&
]
{
run_f
inally
unlock
([
&
]
{
info
->
unlock
();
info
->
unlock
();
});
});
...
...
native/jni/utils/include/
BlockingQ
ueue.h
→
native/jni/utils/include/
blocking_q
ueue.h
View file @
947dae49
...
@@ -2,41 +2,41 @@
...
@@ -2,41 +2,41 @@
#include <pthread.h>
#include <pthread.h>
#include <deque>
#include <deque>
#include <misc.h>
template
<
typename
T
>
template
<
typename
T
>
class
BlockingQ
ueue
{
class
blocking_q
ueue
{
std
::
deque
<
T
>
deque
{};
std
::
deque
<
T
>
deque
{};
pthread_mutex_t
lock
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
lock
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_cond_t
cond
=
PTHREAD_COND_INITIALIZER
;
pthread_cond_t
cond
=
PTHREAD_COND_INITIALIZER
;
bool
cancelled
=
false
;
bool
cancelled
=
false
;
public
:
public
:
~
BlockingQ
ueue
();
~
blocking_q
ueue
();
T
take
();
T
take
();
T
&
front
();
T
&
front
()
const
;
T
&
back
();
T
&
back
()
const
;
void
pu
t
(
const
T
&
);
void
pu
sh
(
const
T
&
);
void
pu
t
(
T
&&
);
void
pu
sh
(
T
&&
);
template
<
class
...
Args
>
template
<
class
...
Args
>
void
emplace
_back
(
Args
&&
...
args
);
void
emplace
(
Args
&&
...
args
);
void
clear
();
void
clear
();
void
cancel
();
void
cancel
();
};
};
#define run_and_notify(block) \
#define run_and_notify(block) \
pthread_mutex_lock(&
this->lock); \
mutex_guard g(
this->lock); \
block \
block \
pthread_cond_signal(&this->cond); \
pthread_cond_signal(&this->cond);
pthread_mutex_unlock(&this->lock);
template
<
typename
T
>
template
<
typename
T
>
BlockingQueue
<
T
>::~
BlockingQ
ueue
()
{
blocking_queue
<
T
>::~
blocking_q
ueue
()
{
pthread_mutex_destroy
(
&
lock
);
pthread_mutex_destroy
(
&
lock
);
pthread_cond_destroy
(
&
cond
);
pthread_cond_destroy
(
&
cond
);
}
}
template
<
typename
T
>
template
<
typename
T
>
T
BlockingQ
ueue
<
T
>::
take
()
{
T
blocking_q
ueue
<
T
>::
take
()
{
pthread_mutex_lock
(
&
lock
);
mutex_guard
g
(
lock
);
cancelled
=
false
;
cancelled
=
false
;
while
(
deque
.
empty
()
&&
!
cancelled
)
while
(
deque
.
empty
()
&&
!
cancelled
)
pthread_cond_wait
(
&
cond
,
&
lock
);
pthread_cond_wait
(
&
cond
,
&
lock
);
...
@@ -44,55 +44,51 @@ T BlockingQueue<T>::take() {
...
@@ -44,55 +44,51 @@ T BlockingQueue<T>::take() {
pthread_exit
(
nullptr
);
pthread_exit
(
nullptr
);
T
ret
(
std
::
move
(
deque
.
front
()));
T
ret
(
std
::
move
(
deque
.
front
()));
deque
.
pop_front
();
deque
.
pop_front
();
pthread_mutex_unlock
(
&
lock
);
return
ret
;
return
ret
;
}
}
template
<
typename
T
>
template
<
typename
T
>
void
BlockingQueue
<
T
>::
put
(
const
T
&
s
)
{
void
blocking_queue
<
T
>::
push
(
const
T
&
s
)
{
run_and_notify
({
deque
.
push_back
(
s
);
})
run_and_notify
({
deque
.
push_back
(
s
);
})
}
}
template
<
typename
T
>
template
<
typename
T
>
void
BlockingQueue
<
T
>::
put
(
T
&&
s
)
{
void
blocking_queue
<
T
>::
push
(
T
&&
s
)
{
run_and_notify
({
deque
.
push_back
(
std
::
move
(
s
));
})
run_and_notify
({
deque
.
push_back
(
std
::
move
(
s
));
})
}
}
template
<
typename
T
>
template
<
typename
T
>
T
&
BlockingQueue
<
T
>::
front
()
{
T
&
blocking_queue
<
T
>::
front
()
const
{
pthread_mutex_lock
(
&
lock
);
mutex_guard
g
(
lock
);
auto
&
ret
=
deque
.
front
();
return
deque
.
front
();
pthread_mutex_unlock
(
&
lock
);
return
ret
;
}
}
template
<
typename
T
>
template
<
typename
T
>
T
&
BlockingQueue
<
T
>::
back
()
{
T
&
blocking_queue
<
T
>::
back
()
const
{
pthread_mutex_lock
(
&
lock
);
mutex_guard
g
(
lock
);
auto
&
ret
=
deque
.
back
();
return
deque
.
back
();
pthread_mutex_unlock
(
&
lock
);
return
ret
;
}
}
template
<
typename
T
>
template
<
typename
T
>
template
<
class
...
Args
>
template
<
class
...
Args
>
void
BlockingQueue
<
T
>::
emplace_back
(
Args
&&
...
args
)
{
void
blocking_queue
<
T
>::
emplace
(
Args
&&
...
args
)
{
run_and_notify
({
deque
.
emplace_back
(
std
::
forward
<
Args
>
(
args
)...);
})
run_and_notify
({
deque
.
emplace_back
(
std
::
forward
<
Args
>
(
args
)...);
})
}
}
template
<
typename
T
>
template
<
typename
T
>
void
BlockingQ
ueue
<
T
>::
clear
()
{
void
blocking_q
ueue
<
T
>::
clear
()
{
pthread_mutex_lock
(
&
lock
);
mutex_guard
g
(
lock
);
std
::
deque
<
T
>
t
;
std
::
deque
<
T
>
t
;
deque
.
swap
(
t
);
deque
.
swap
(
t
);
pthread_mutex_unlock
(
&
lock
);
}
}
template
<
typename
T
>
template
<
typename
T
>
void
BlockingQ
ueue
<
T
>::
cancel
()
{
void
blocking_q
ueue
<
T
>::
cancel
()
{
run_and_notify
({
run_and_notify
({
cancelled
=
true
;
cancelled
=
true
;
std
::
deque
<
T
>
t
;
std
::
deque
<
T
>
t
;
deque
.
swap
(
t
);
deque
.
swap
(
t
);
})
})
}
}
#undef run_and_notify
native/jni/utils/include/cpio.h
View file @
947dae49
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include <map>
#include <map>
#include <string_view>
#include <string_view>
#include <
OutS
tream.h>
#include <
s
tream.h>
struct
cpio_newc_header
;
struct
cpio_newc_header
;
...
...
native/jni/utils/include/
OutS
tream.h
→
native/jni/utils/include/
s
tream.h
View file @
947dae49
...
@@ -19,9 +19,9 @@ public:
...
@@ -19,9 +19,9 @@ public:
FilterOutStream
(
strm_ptr
&&
ptr
)
:
out
(
std
::
move
(
ptr
))
{}
FilterOutStream
(
strm_ptr
&&
ptr
)
:
out
(
std
::
move
(
ptr
))
{}
void
set
_o
ut
(
strm_ptr
&&
ptr
)
{
out
=
std
::
move
(
ptr
);
}
void
set
O
ut
(
strm_ptr
&&
ptr
)
{
out
=
std
::
move
(
ptr
);
}
OutStream
*
get
_o
ut
()
{
return
out
.
get
();
}
OutStream
*
get
O
ut
()
{
return
out
.
get
();
}
bool
write
(
const
void
*
buf
,
size_t
len
)
override
{
bool
write
(
const
void
*
buf
,
size_t
len
)
override
{
return
out
?
out
->
write
(
buf
,
len
)
:
false
;
return
out
?
out
->
write
(
buf
,
len
)
:
false
;
...
...
native/jni/utils/misc.h
View file @
947dae49
...
@@ -27,17 +27,17 @@ void gen_rand_str(char *buf, int len, bool varlen = true);
...
@@ -27,17 +27,17 @@ void gen_rand_str(char *buf, int len, bool varlen = true);
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
class
MutexG
uard
{
class
mutex_g
uard
{
public
:
public
:
explicit
MutexG
uard
(
pthread_mutex_t
&
m
)
:
mutex
(
&
m
)
{
explicit
mutex_g
uard
(
pthread_mutex_t
&
m
)
:
mutex
(
&
m
)
{
pthread_mutex_lock
(
mutex
);
pthread_mutex_lock
(
mutex
);
}
}
explicit
MutexG
uard
(
pthread_mutex_t
*
m
)
:
mutex
(
m
)
{
explicit
mutex_g
uard
(
pthread_mutex_t
*
m
)
:
mutex
(
m
)
{
pthread_mutex_lock
(
mutex
);
pthread_mutex_lock
(
mutex
);
}
}
~
MutexG
uard
()
{
~
mutex_g
uard
()
{
pthread_mutex_unlock
(
mutex
);
pthread_mutex_unlock
(
mutex
);
}
}
...
@@ -45,13 +45,13 @@ private:
...
@@ -45,13 +45,13 @@ private:
pthread_mutex_t
*
mutex
;
pthread_mutex_t
*
mutex
;
};
};
class
RunF
inally
{
class
run_f
inally
{
public
:
public
:
explicit
RunF
inally
(
std
::
function
<
void
()
>
&&
fn
)
:
fn
(
std
::
move
(
fn
))
{}
explicit
run_f
inally
(
std
::
function
<
void
()
>
&&
fn
)
:
fn
(
std
::
move
(
fn
))
{}
void
disable
()
{
fn
=
nullptr
;
}
void
disable
()
{
fn
=
nullptr
;
}
~
RunF
inally
()
{
if
(
fn
)
fn
();
}
~
run_f
inally
()
{
if
(
fn
)
fn
();
}
private
:
private
:
std
::
function
<
void
()
>
fn
;
std
::
function
<
void
()
>
fn
;
...
...
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