Skip to content

Commit b82eb4e

Browse files
author
jpacg
committed
dev
1 parent dc49c34 commit b82eb4e

19 files changed

+1765
-313
lines changed

.gitignore

+9-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
1-
# Object files
2-
*.o
3-
*.d
4-
*.ko
5-
*.obj
6-
*.elf
7-
8-
# Precompiled Headers
9-
*.gch
10-
*.pch
11-
12-
# Libraries
13-
*.lib
14-
*.a
15-
*.la
16-
*.lo
17-
18-
# Shared objects (inc. Windows DLLs)
19-
*.dll
20-
*.so
21-
*.so.*
22-
*.dylib
23-
24-
# Executables
25-
*.exe
26-
*.out
27-
*.app
28-
*.i*86
29-
*.x86_64
30-
*.hex
1+
bin
2+
armeabi
3+
x86
4+
obj
5+
local.properties
6+
gen
7+
.DS_Store
8+
.settings
9+
libs

Application.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
APP_ABI := armeabi-v7a
2-
APP_PLATFORM := android-19
2+
APP_PLATFORM := android-25

README.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
su binary
22
===
33

4-
####说明
4+
Note
5+
========
56

6-
- 源码是通过CyanogenMod su修改,修改CyanogenMod su N多问题
7-
- 支持4.3及上机型,需要使用 `su --daemon`方式运行
7+
* Source code is modified by CyanogenMod su, https://github.com/CyanogenMod/android_system_extras_su
88

9-
####编译说明
10-
- 安装最新版的android ndk,并把ndk目录增加到环境变量
11-
- 运行make编译su
9+
* Supports android 4.3+ devices and need to use `su--daemon`
1210

11+
12+
Building
13+
========
14+
15+
* Download the Android Native Development Kit (NDK): https://developer.android.com/ndk/downloads/index.html
16+
17+
* Extract into some directory and put that in your path:
18+
`export PATH=NDK_DIR:$PATH`
19+
20+
* In another directory clone this repo:
21+
`git clone https://github.com/jpacg/su-binary`
22+
23+
* Change to the directory where the repo was cloned
24+
`cd su-binary`
25+
26+
* To start build process use the following
27+
`make` or `ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk`
28+
29+
* If all goes well you will get the compiled binary at:
30+
`./libs/armeabi-v7a/su`

common.c

+21-98
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
#include "utils.h"
1414

1515
#define BUFFSIZE 4096
16-
#define DDEXE "/system/bin/ddexe"
17-
#define DDEXEREAL "/system/bin/ddexereal"
18-
#define DDEXE_REAL "/system/bin/ddexe_real"
16+
#define MULTIUSER_APP_PER_USER_RANGE 100000
1917

20-
int exists(const char *path) {
21-
return !access(path, R_OK);
18+
typedef uid_t userid_t;
19+
userid_t multiuser_get_user_id(uid_t uid) {
20+
return uid / MULTIUSER_APP_PER_USER_RANGE;
21+
}
22+
23+
int file_exists(const char *path) {
24+
return access(path, R_OK) == 0;
2225
}
2326

2427
int setxattr(const char *path, const char *value) {
25-
if (!exists("/sys/fs/selinux")) {
28+
if (!file_exists("/sys/fs/selinux")) {
2629
return 0;
2730
}
2831
return syscall(__NR_setxattr, path, "security.selinux", value, strlen(value), 0);
@@ -114,11 +117,11 @@ int mount_system() {
114117

115118
ret = get_mounts_dev_dir("/system", &dev, &dir);
116119
if (ret < 0) {
117-
system("mount -o remount rw /system");
120+
system("mount -o remount,rw /system");
118121
return mount("ro", "/system", NULL, 32800, NULL);
119122
}
120123

121-
system("mount -o remount rw /system");
124+
system("mount -o remount,rw /system");
122125
ret = mount(dev, dir, "none", MS_REMOUNT, NULL);
123126
free(dev);
124127
free(dir);
@@ -139,91 +142,8 @@ static int write_file(const char *path, const char *data, uid_t owner, gid_t gro
139142
return n == len ? 0 : -1;;
140143
}
141144

142-
int OPPO() {
143-
char brand[PROPERTY_VALUE_MAX];
144-
char *data = read_file("/system/build.prop");
145-
get_property(data, brand, "ro.product.brand", "0");
146-
free(data);
147-
148-
if (strstr(brand, "OPPO")) {
149-
return write_file("/system/etc/install_recovery.sh", \
150-
"#!/system/bin/sh\n/system/xbin/su --daemon &\n", \
151-
0, 0, 0755);
152-
}
153-
154-
return 0;
155-
}
156-
157-
int install_recovery_sh() {
158-
if (getuid() != 0 || getgid() != 0) {
159-
PLOGE("install_recovery_sh requires root. uid/gid not root");
160-
return -1;
161-
}
162-
mount_system();
163-
164-
write_file("/system/etc/install-recovery.sh", \
165-
"#!/system/bin/sh\n/system/xbin/su --daemon &\n", \
166-
0, 0, 0755);
167-
168-
return OPPO();
169-
}
170-
171-
int install() {
172-
if (getuid() != 0 || getgid() != 0) {
173-
PLOGE("install requires root. uid/gid not root");
174-
return -1;
175-
}
176-
mount_system();
177-
install_recovery_sh();
178-
179-
if (exists(DDEXE)) {
180-
if (!exists(DDEXE_REAL) && !exists(DDEXEREAL)) {
181-
copy_file(DDEXE, DDEXE_REAL);
182-
}
183-
else if (exists(DDEXEREAL)){
184-
copy_file(DDEXEREAL, DDEXE_REAL);
185-
unlink(DDEXEREAL);
186-
}
187-
else {
188-
}
189-
}
190-
chown(DDEXE_REAL, 0, 2000);
191-
chmod(DDEXE_REAL, 0755);
192-
193-
if (exists(DDEXE_REAL)) {
194-
unlink(DDEXE);
195-
write_file(DDEXE, \
196-
"#!/system/bin/sh\n/system/xbin/su --daemon &\n/system/bin/ddexe_real\n", \
197-
0, 2000, 0755);
198-
}
199-
200-
setxattr(DDEXE, "u:object_r:system_file:s0");
201-
setxattr(DDEXE_REAL, "u:object_r:system_file:s0");
202-
return 0;
203-
}
204-
205-
int uninstall() {
206-
if (getuid() != 0 || getgid() != 0) {
207-
PLOGE("uninstall requires root. uid/gid not root");
208-
return -1;
209-
}
210-
mount_system();
211-
212-
if (exists(DDEXEREAL)) {
213-
copy_file(DDEXEREAL, DDEXE);
214-
unlink(DDEXEREAL);
215-
}
216-
else if (exists(DDEXE_REAL)) {
217-
copy_file(DDEXE_REAL, DDEXE);
218-
unlink(DDEXE_REAL);
219-
}
220-
else {
221-
}
222-
223-
chown(DDEXE, 0, 2000);
224-
chmod(DDEXE, 0755);
225-
226-
setxattr(DDEXE, "u:object_r:system_file:s0");
145+
int fix_unused(const char* fmt, ...)
146+
{
227147
return 0;
228148
}
229149

@@ -233,8 +153,10 @@ char* format(const char* fmt, ...) {
233153
char *buffer;
234154
va_start( args, fmt );
235155
len = vsnprintf(NULL, 0, fmt, args ) + 1;
236-
buffer = (char*)malloc(len * sizeof(char));
237-
vsprintf( buffer, fmt, args );
156+
buffer = (char*)malloc(len);
157+
vsnprintf( buffer, len, fmt, args );
158+
va_end( args );
159+
238160
return buffer;
239161
}
240162

@@ -243,9 +165,10 @@ int tolog(const char* fmt, ...) {
243165
int len;
244166
char *buffer;
245167
va_start( args, fmt );
246-
len = vsnprintf(NULL, 0, fmt, args ) + 1;
247-
buffer = (char*)malloc(len * sizeof(char));
248-
vsprintf( buffer, fmt, args );
168+
len = vsnprintf( NULL, 0, fmt, args ) + 1;
169+
buffer = (char*)malloc( len );
170+
vsnprintf( buffer, len, fmt, args );
171+
va_end( args );
249172

250173
printf("%s\n", buffer);
251174
free(buffer);

common.h

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
#ifndef COMMON_H
22
#define COMMON_H
33

4+
#include <sys/types.h>
5+
46
#define AID_ROOT 0 /* traditional unix root user */
57
#define AID_SHELL 2000 /* adb and debug shell user */
68

7-
int exists(const char *path);
9+
int file_exists(const char *path);
810
int setxattr(const char *path, const char *value);
911
int selinux_attr_set_priv();
1012
int copy_file(const char *src_file, const char *dst_file);
1113
int get_mounts_dev_dir(const char *arg, char **dev, char **dir);
1214

1315
int mount_system();
14-
int install();
15-
int uninstall();
16+
17+
int fix_unused(const char* fmt, ...);
1618
int tolog(const char* fmt, ...);
1719
char* format(const char* fmt, ...);
1820

21+
typedef uid_t userid_t;
22+
userid_t multiuser_get_user_id(uid_t uid);
23+
1924
#include <errno.h>
2025
#include <string.h>
2126
#ifndef PLOGE
2227
#define PLOGE(fmt,args...) ALOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
2328
#define PLOGEV(fmt,err,args...) ALOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
2429
#endif // !PLOGE
2530

26-
#define ALOGW
27-
#define ALOGE
28-
#define ALOGD
29-
#define ALOGV
31+
#define ALOGW fix_unused
32+
#define ALOGE fix_unused
33+
#define ALOGD fix_unused
34+
#define ALOGV fix_unused
35+
36+
#ifndef MS_SLAVE
37+
#define MS_SLAVE 1<<19 /* Slave */
38+
#endif
3039

3140
#endif

0 commit comments

Comments
 (0)