/
hwprops.c
executable file
·52 lines (42 loc) · 1.15 KB
/
hwprops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <string.h>
#include <fcntl.h>
#include <sys/mount.h>
/* Set baseband and serialnumber properties on FIH devices, since they're
* not exported by the bootloader to cmdline as expected */
/* Ugly hack is ugly...
*
* There's a very narrow window in which the hardware properties
* can be written, since init sets them immediately after launching
* the property service, and they can only be set once.
* So our only chance to overwrite them is to set them during that
* launch, by inserting them into default.prop */
int main() {
int fd;
char b[256];
int bc;
mount("rootfs","/","rootfs",MS_REMOUNT|0,NULL);
fd = open("/proc/baseband",O_RDONLY);
if (fd<0)
return 0;
bc = read(fd, b, sizeof(b)-1);
close(fd);
fd = open("/default.prop", O_WRONLY|O_APPEND);
if (fd>0){
write(fd,"ro.baseband=",12);
write(fd,b,bc);
close (fd);
}
fd = open("/proc/serialnumber",O_RDONLY);
if (fd<0)
return 0;
bc = read(fd, b, sizeof(b)-1);
close(fd);
fd = open("/default.prop", O_WRONLY|O_APPEND);
if (fd>0){
write(fd,"ro.serialno=",12);
write(fd,b,bc);
close (fd);
}
//mount("rootfs","/","rootfs",MS_REMOUNT|MS_RDONLY,NULL);
return 0;
}