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
796c3009
Commit
796c3009
authored
Apr 13, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor resetprop
parent
144ff5e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
115 deletions
+133
-115
resetprop.cpp
jni/resetprop/resetprop.cpp
+104
-107
resetprop.h
jni/resetprop/resetprop.h
+21
-0
system_properties.cpp
jni/resetprop/system_properties.cpp
+8
-8
No files found.
jni/resetprop/resetprop.cpp
View file @
796c3009
/*
/* resetprop.cpp - Manipulate any system props
*
* resetprop.cpp
*
*
* Copyright 2016 nkk71 <nkk71x@gmail.com>
* Copyright 2016 nkk71 <nkk71x@gmail.com>
* Copyright 2016 topjohnwu <topjohnwu@gmail.com>
* Copyright 2016 topjohnwu <topjohnwu@gmail.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* Info:
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include "_system_properties.h"
#include <sys/system_properties.h>
#ifdef INDEP_BINARY
int
resetprop_main
(
int
argc
,
char
*
argv
[]);
int
main
(
int
argc
,
char
*
argv
[])
{
return
resetprop_main
(
argc
,
argv
);
}
#else
#include "magisk.h"
#endif
/* Info:
*
*
* all changes are in
* all changes are in
*
*
...
@@ -90,11 +50,36 @@ int main(int argc, char *argv[]) {
...
@@ -90,11 +50,36 @@ int main(int argc, char *argv[]) {
*
*
*/
*/
int
verbose
=
0
,
del
=
0
,
file
=
0
,
trigger
=
1
;
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include "_system_properties.h"
#include <sys/system_properties.h>
#ifdef INDEP_BINARY
static
bool
is_legal_property_name
(
const
char
*
name
,
size_t
namelen
)
int
resetprop_main
(
int
argc
,
char
*
argv
[]);
{
int
main
(
int
argc
,
char
*
argv
[])
{
size_t
i
;
return
resetprop_main
(
argc
,
argv
);
}
#define LOGD(...) if (verbose) printf(__VA_ARGS__)
#define LOGE(...) fprintf(stderr, __VA_ARGS__)
#else
#include "magisk.h"
#endif
#include "resetprop.h"
static
int
verbose
=
0
;
static
bool
is_legal_property_name
(
const
char
*
name
,
size_t
namelen
)
{
if
(
namelen
>=
PROP_NAME_MAX
)
return
false
;
if
(
namelen
>=
PROP_NAME_MAX
)
return
false
;
if
(
namelen
<
1
)
return
false
;
if
(
namelen
<
1
)
return
false
;
if
(
name
[
0
]
==
'.'
)
return
false
;
if
(
name
[
0
]
==
'.'
)
return
false
;
...
@@ -102,10 +87,10 @@ static bool is_legal_property_name(const char* name, size_t namelen)
...
@@ -102,10 +87,10 @@ static bool is_legal_property_name(const char* name, size_t namelen)
/* Only allow alphanumeric, plus '.', '-', or '_' */
/* Only allow alphanumeric, plus '.', '-', or '_' */
/* Don't allow ".." to appear in a property name */
/* Don't allow ".." to appear in a property name */
for
(
i
=
0
;
i
<
namelen
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
namelen
;
i
++
)
{
if
(
name
[
i
]
==
'.'
)
{
if
(
name
[
i
]
==
'.'
)
{
// i=0 is guaranteed to never have a dot. See above.
// i=0 is guaranteed to never have a dot. See above.
if
(
name
[
i
-
1
]
==
'.'
)
return
false
;
if
(
name
[
i
-
1
]
==
'.'
)
return
false
;
continue
;
continue
;
}
}
if
(
name
[
i
]
==
'_'
||
name
[
i
]
==
'-'
)
continue
;
if
(
name
[
i
]
==
'_'
||
name
[
i
]
==
'-'
)
continue
;
...
@@ -118,54 +103,89 @@ static bool is_legal_property_name(const char* name, size_t namelen)
...
@@ -118,54 +103,89 @@ static bool is_legal_property_name(const char* name, size_t namelen)
return
true
;
return
true
;
}
}
int
x_property_set
(
const
char
*
name
,
const
char
*
value
)
static
int
usage
(
char
*
arg0
)
{
{
fprintf
(
stderr
,
int
ret
;
"Usage: %s [options] [args...]
\n
"
char
value_read
[
PROP_VALUE_MAX
];
"%s <name> <value>: Set property entry <name> with <value>
\n
"
"%s --file <prop file>: Load props from <prop file>
\n
"
"%s --delete <name>: Remove prop entry <name>
\n
"
"
\n
"
"Options:
\n
"
" -v verbose output
\n
"
" -n don't trigger events when changing props
\n
"
,
arg0
,
arg0
,
arg0
,
arg0
);
return
1
;
}
size_t
namelen
=
strlen
(
name
);
int
init_resetprop
()
{
size_t
valuelen
=
strlen
(
value
);
LOGD
(
"resetprop: Initializing...
\n
"
);
if
(
__system_properties_init
())
{
LOGE
(
"resetprop: Initialize error
\n
"
);
return
-
1
;
}
return
0
;
}
if
(
trigger
)
{
// Get prop by name, return string (should free manually!)
printf
(
"Set with property_service: '%s'='%s'
\n
"
,
name
,
value
);
char
*
getprop
(
const
char
*
name
)
{
}
else
{
char
value
[
PROP_VALUE_MAX
];
printf
(
"Modify data structure: '%s'='%s'
\n
"
,
name
,
value
);
LOGD
(
"restprop: getprop [%s]
\n
"
,
name
);
if
(
__system_property_get
(
name
,
value
)
==
0
)
{
LOGE
(
"resetprop: prop not found: [%s]
\n
"
,
name
);
return
NULL
;
}
}
return
strdup
(
value
);
}
__system_property_get
(
name
,
value_read
);
int
setprop
(
const
char
*
name
,
const
char
*
value
)
{
return
setprop2
(
name
,
value
,
1
);
}
if
(
strlen
(
value_read
))
{
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
int
trigger
)
{
printf
(
"Existing property: '%s'='%s'
\n
"
,
name
,
value_read
);
int
ret
;
char
*
check
=
getprop
(
name
);
if
(
check
)
{
LOGD
(
"resetprop: prop [%s] has existing value [%s]
\n
"
,
name
,
value
);
free
(
check
);
if
(
trigger
)
{
if
(
trigger
)
{
if
(
!
strncmp
(
name
,
"ro."
,
3
))
__system_property_del
(
name
);
// Only delete ro props
if
(
!
strncmp
(
name
,
"ro."
,
3
))
deleteprop
(
name
);
ret
=
__system_property_set
(
name
,
value
);
ret
=
__system_property_set
(
name
,
value
);
}
else
{
}
else
{
ret
=
__system_property_update
((
prop_info
*
)
__system_property_find
(
name
),
value
,
valuelen
);
ret
=
__system_property_update
((
prop_info
*
)
__system_property_find
(
name
),
value
,
strlen
(
value
)
);
}
}
}
else
{
}
else
{
LOGD
(
"resetprop: New prop [%s]
\n
"
,
name
);
if
(
trigger
)
{
if
(
trigger
)
{
ret
=
__system_property_set
(
name
,
value
);
ret
=
__system_property_set
(
name
,
value
);
}
else
{
}
else
{
ret
=
__system_property_add
(
name
,
namelen
,
value
,
valuelen
);
ret
=
__system_property_add
(
name
,
strlen
(
name
),
value
,
strlen
(
value
)
);
}
}
}
}
if
(
ret
!=
0
)
{
LOGD
(
"resetprop: setprop [%s]: [%s] by %s
\n
"
,
name
,
value
,
fprintf
(
stderr
,
"Failed to set '%s'='%s'
\n
"
,
name
,
value
);
trigger
?
"property_service"
:
"modifing prop data structure"
);
return
ret
;
}
__system_property_get
(
name
,
value_read
);
if
(
ret
)
printf
(
"Recheck property: '%s'='%s'
\n
"
,
name
,
value_read
);
LOGE
(
"resetprop: setprop error
\n
"
);
return
ret
;
}
int
deleteprop
(
const
char
*
name
)
{
LOGD
(
"resetprop: deleteprop [%s]
\n
"
,
name
);
if
(
__system_property_del
(
name
))
{
LOGE
(
"resetprop: delete prop: [%s] error
\n
"
,
name
);
return
-
1
;
}
return
0
;
return
0
;
}
}
int
read_prop_file
(
const
char
*
filename
)
{
int
read_prop_file
(
const
char
*
filename
)
{
printf
(
"Attempting to read props from
\'
%s
\'
\n
"
,
filename
);
LOGD
(
"resetprop: Load prop file [%s]
\n
"
,
filename
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"Cannot open
\'
%s
\'
\n
"
,
filename
);
LOGE
(
"Cannot open [%s]
\n
"
,
filename
);
return
1
;
return
1
;
}
}
char
*
line
=
NULL
,
*
pch
;
char
*
line
=
NULL
,
*
pch
;
...
@@ -194,27 +214,16 @@ int read_prop_file(const char* filename) {
...
@@ -194,27 +214,16 @@ int read_prop_file(const char* filename) {
if
(
((
pch
==
NULL
)
||
(
i
>=
(
pch
-
line
)))
||
(
pch
>=
line
+
read
-
1
)
)
continue
;
if
(
((
pch
==
NULL
)
||
(
i
>=
(
pch
-
line
)))
||
(
pch
>=
line
+
read
-
1
)
)
continue
;
// Separate the string
// Separate the string
*
pch
=
'\0'
;
*
pch
=
'\0'
;
x_property_set
(
line
+
i
,
pch
+
1
);
setprop
(
line
+
i
,
pch
+
1
);
}
}
free
(
line
);
free
(
line
);
fclose
(
fp
);
fclose
(
fp
);
return
0
;
return
0
;
}
}
int
usage
(
char
*
name
)
{
fprintf
(
stderr
,
"usage: %s [-v] [-n] [--file propfile] [--delete name] [ name value ]
\n
"
,
name
);
fprintf
(
stderr
,
" -v :
\n
"
);
fprintf
(
stderr
,
" verbose output (Default: Disabled)
\n
"
);
fprintf
(
stderr
,
" -n :
\n
"
);
fprintf
(
stderr
,
" no event triggers when changing props (Default: Will trigger events)
\n
"
);
fprintf
(
stderr
,
" --file propfile :
\n
"
);
fprintf
(
stderr
,
" Read props from prop files (e.g. build.prop)
\n
"
);
fprintf
(
stderr
,
" --delete name :
\n
"
);
fprintf
(
stderr
,
" Remove a prop entry
\n\n
"
);
return
1
;
}
int
resetprop_main
(
int
argc
,
char
*
argv
[])
{
int
resetprop_main
(
int
argc
,
char
*
argv
[])
{
int
del
=
0
,
file
=
0
,
trigger
=
1
;
int
exp_arg
=
2
,
stdout_bak
,
null
;
int
exp_arg
=
2
,
stdout_bak
,
null
;
char
*
name
,
*
value
,
*
filename
;
char
*
name
,
*
value
,
*
filename
;
...
@@ -243,13 +252,13 @@ int resetprop_main(int argc, char *argv[]) {
...
@@ -243,13 +252,13 @@ int resetprop_main(int argc, char *argv[]) {
break
;
break
;
}
else
{
}
else
{
if
(
!
is_legal_property_name
(
argv
[
i
],
strlen
(
argv
[
i
])))
{
if
(
!
is_legal_property_name
(
argv
[
i
],
strlen
(
argv
[
i
])))
{
fprintf
(
stderr
,
"Illegal property name
\'
%s
\'
\n
"
,
argv
[
i
]);
LOGE
(
"Illegal property name: [%s]
\n
"
,
argv
[
i
]);
return
1
;
return
1
;
}
}
name
=
argv
[
i
];
name
=
argv
[
i
];
if
(
exp_arg
>
1
)
{
if
(
exp_arg
>
1
)
{
if
(
strlen
(
argv
[
i
+
1
])
>=
PROP_VALUE_MAX
)
{
if
(
strlen
(
argv
[
i
+
1
])
>=
PROP_VALUE_MAX
)
{
fprintf
(
stderr
,
"Value too long
\'
%s
\'
\n
"
,
argv
[
i
+
1
]);
LOGE
(
"Value too long: [%s]
\n
"
,
argv
[
i
+
1
]);
return
1
;
return
1
;
}
}
value
=
argv
[
i
+
1
];
value
=
argv
[
i
+
1
];
...
@@ -259,30 +268,18 @@ int resetprop_main(int argc, char *argv[]) {
...
@@ -259,30 +268,18 @@ int resetprop_main(int argc, char *argv[]) {
}
}
}
}
if
(
!
verbose
)
{
LOGD
(
"resetprop by nkk71 & topjohnwu
\n
"
);
fflush
(
stdout
);
stdout_bak
=
dup
(
1
);
null
=
open
(
"/dev/null"
,
O_WRONLY
);
dup2
(
null
,
1
);
}
printf
(
"resetprop by nkk71 & topjohnwu
\n
"
);
if
(
init_resetprop
())
return
-
1
;
printf
(
"Initializing...
\n
"
);
if
(
__system_properties_init
())
{
fprintf
(
stderr
,
"Error during init
\n
"
);
return
1
;
}
if
(
file
)
{
if
(
file
)
{
if
(
read_prop_file
(
filename
))
return
1
;
return
read_prop_file
(
filename
)
;
}
else
if
(
del
)
{
}
else
if
(
del
)
{
printf
(
"Attempting to delete '%s'
\n
"
,
name
);
return
deleteprop
(
name
);
if
(
__system_property_del
(
name
))
return
1
;
}
else
{
}
else
{
if
(
x_property_set
(
name
,
value
))
return
1
;
return
setprop2
(
name
,
value
,
trigger
)
;
}
}
printf
(
"Done!
\n\n
"
);
return
0
;
return
0
;
}
}
jni/resetprop/resetprop.h
0 → 100644
View file @
796c3009
/* resetprop.h - API for resetprop
*/
#ifndef _RESETPROP_H_
#define _RESETPROP_H_
#ifdef __cplusplus
extern
"C"
{
#endif
int
init_resetprop
();
int
setprop
(
const
char
*
name
,
const
char
*
value
);
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
int
trigger
);
char
*
getprop
(
const
char
*
name
);
int
deleteprop
(
const
char
*
name
);
#ifdef __cplusplus
}
#endif
#endif
jni/resetprop/system_properties.cpp
View file @
796c3009
...
@@ -572,17 +572,17 @@ const prop_info *prop_area::find_property_and_del(prop_bt *const trie, const cha
...
@@ -572,17 +572,17 @@ const prop_info *prop_area::find_property_and_del(prop_bt *const trie, const cha
uint_least32_t
prop_offset
=
atomic_load_explicit
(
&
current
->
prop
,
memory_order_relaxed
);
uint_least32_t
prop_offset
=
atomic_load_explicit
(
&
current
->
prop
,
memory_order_relaxed
);
if
(
prop_offset
!=
0
)
{
if
(
prop_offset
!=
0
)
{
printf
(
"[bt] found at %p: name='%s' prop='%llu' left='%llu' right='%llu' children='%llu'
\n
"
,
//
printf("[bt] found at %p: name='%s' prop='%llu' left='%llu' right='%llu' children='%llu'\n",
static_cast
<
void
*>
(
current
),
current
->
name
,
//
static_cast<void*>(current), current->name,
static_cast
<
unsigned
long
long
>
(
atomic_load_explicit
(
&
current
->
prop
,
memory_order_relaxed
)),
//
static_cast<unsigned long long>(atomic_load_explicit(¤t->prop, memory_order_relaxed)),
static_cast
<
unsigned
long
long
>
(
atomic_load_explicit
(
&
current
->
left
,
memory_order_relaxed
)),
//
static_cast<unsigned long long>(atomic_load_explicit(¤t->left, memory_order_relaxed)),
static_cast
<
unsigned
long
long
>
(
atomic_load_explicit
(
&
current
->
right
,
memory_order_relaxed
)),
//
static_cast<unsigned long long>(atomic_load_explicit(¤t->right, memory_order_relaxed)),
static_cast
<
unsigned
long
long
>
(
atomic_load_explicit
(
&
current
->
children
,
memory_order_relaxed
))
//
static_cast<unsigned long long>(atomic_load_explicit(¤t->children, memory_order_relaxed))
);
//
);
atomic_store_explicit
(
&
current
->
prop
,
0
,
memory_order_release
);
atomic_store_explicit
(
&
current
->
prop
,
0
,
memory_order_release
);
return
to_prop_info
(
&
current
->
prop
);
return
to_prop_info
(
&
current
->
prop
);
}
else
{
}
else
{
printf
(
"[bt] property not found
\n
"
);
//
printf("[bt] property not found\n");
return
NULL
;
return
NULL
;
}
}
}
}
...
...
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