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
b2431b98
Commit
b2431b98
authored
Dec 10, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prettify code
parent
8d6d619e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
67 deletions
+71
-67
magiskhide.c
jni/magiskhide.c
+71
-67
No files found.
jni/magiskhide.c
View file @
b2431b98
...
@@ -194,88 +194,92 @@ void *monitor_list(void *path) {
...
@@ -194,88 +194,92 @@ void *monitor_list(void *path) {
return
NULL
;
return
NULL
;
}
}
int
main
(
int
argc
,
char
**
argv
,
char
**
envp
)
{
void
run_as_daemon
()
{
switch
(
fork
())
{
pid_t
forkpid
=
fork
();
case
-
1
:
exit
(
-
1
);
if
(
forkpid
<
0
)
case
0
:
return
1
;
if
(
setsid
()
<
0
)
exit
(
-
1
);
close
(
STDIN_FILENO
);
close
(
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
break
;
default:
exit
(
0
);
}
}
if
(
forkpid
==
0
)
{
int
main
(
int
argc
,
char
**
argv
,
char
**
envp
)
{
if
(
setsid
()
<
0
)
return
1
;
close
(
STDIN_FILENO
);
run_as_daemon
();
close
(
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
logfile
=
fopen
(
LOGFILE
,
"a+"
);
logfile
=
fopen
(
LOGFILE
,
"a+"
);
setbuf
(
logfile
,
NULL
);
setbuf
(
logfile
,
NULL
);
// Fork a child to handle namespace switches and unmounts
// Fork a child to handle namespace switches and unmounts
pipe
(
pipefd
);
pipe
(
pipefd
);
forkpid
=
fork
();
switch
(
fork
())
{
if
(
forkpid
<
0
)
case
-
1
:
return
1
;
exit
(
-
1
)
;
if
(
forkpid
==
0
)
case
0
:
return
hideMagisk
();
return
hideMagisk
();
default:
break
;
}
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
// Start a thread to constantly check the hide list
pthread_t
list_monitor
;
// Start a thread to constantly check the hide list
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_t
list_monitor
;
pthread_create
(
&
list_monitor
,
NULL
,
monitor_list
,
HIDELIST
);
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_create
(
&
list_monitor
,
NULL
,
monitor_list
,
HIDELIST
);
char
buffer
[
512
];
FILE
*
p
=
popen
(
"while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
while
(
!
feof
(
p
))
{
//Format of am_proc_start is (as of Android 5.1 and 6.0)
//UserID, pid, unix uid, processName, hostingType, hostingName
fgets
(
buffer
,
sizeof
(
buffer
),
p
);
char
*
pos
=
buffer
;
char
buffer
[
512
];
while
(
1
)
{
FILE
*
p
=
popen
(
"while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
pos
=
strchr
(
pos
,
','
);
if
(
pos
==
NULL
)
while
(
!
feof
(
p
))
{
break
;
//Format of am_proc_start is (as of Android 5.1 and 6.0)
pos
[
0
]
=
' '
;
//UserID, pid, unix uid, processName, hostingType, hostingName
}
fgets
(
buffer
,
sizeof
(
buffer
),
p
);
char
*
pos
=
buffer
;
while
(
1
)
{
pos
=
strchr
(
pos
,
','
);
if
(
pos
==
NULL
)
break
;
pos
[
0
]
=
' '
;
}
int
user
,
pid
,
uid
;
int
user
,
pid
,
uid
;
char
processName
[
256
],
hostingType
[
16
],
hostingName
[
256
];
char
processName
[
256
],
hostingType
[
16
],
hostingName
[
256
];
int
ret
=
sscanf
(
buffer
,
"[%d %d %d %256s %16s %256s]"
,
int
ret
=
sscanf
(
buffer
,
"[%d %d %d %256s %16s %256s]"
,
&
user
,
&
pid
,
&
uid
,
&
user
,
&
pid
,
&
uid
,
processName
,
hostingType
,
hostingName
);
processName
,
hostingType
,
hostingName
);
if
(
ret
!=
6
)
if
(
ret
!=
6
)
continue
;
continue
;
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
if
(
strstr
(
processName
,
hide_list
[
i
]))
{
if
(
strstr
(
processName
,
hide_list
[
i
]))
{
fprintf
(
logfile
,
"MagiskHide: Disabling for process=%s, PID=%d, UID=%d
\n
"
,
processName
,
pid
,
uid
);
fprintf
(
logfile
,
"MagiskHide: Disabling for process=%s, PID=%d, UID=%d
\n
"
,
processName
,
pid
,
uid
);
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
}
}
}
}
}
}
// Close the logcat monitor
// Close the logcat monitor
pclose
(
p
);
pclose
(
p
);
// Close the config list monitor
// Close the config list monitor
pthread_kill
(
list_monitor
,
SIGQUIT
);
pthread_kill
(
list_monitor
,
SIGQUIT
);
pthread_mutex_destroy
(
&
mutex
);
pthread_mutex_destroy
(
&
mutex
);
// Terminate our children
// Terminate our children
i
=
-
1
;
i
=
-
1
;
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
fprintf
(
logfile
,
"MagiskHide: Cannot read from logcat, abort...
\n
"
);
fprintf
(
logfile
,
"MagiskHide: Cannot read from logcat, abort...
\n
"
);
fclose
(
logfile
);
fclose
(
logfile
);
return
1
;
return
1
;
}
return
0
;
}
}
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