radio_s_off: p7_s-off.c

File p7_s-off.c, 2.8 KB (added by anonymous, 13 years ago)
Line 
1/*
2    Copyright (C) 2010  Guhl
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20
21#define INFILE "/dev/block/mmcblk0p7"
22#define CPYFILE "/sdcard/mmcblk0p7.ori.img"
23#define OUTFILE "/dev/block/mmcblk0p7"
24
25int main(void) {
26        FILE *fdin, *fdout;
27        char ch;
28
29        fdin = fopen(INFILE, "rb");
30        if (fdin == NULL){
31                printf("Error opening input file.\n");
32                return -1;
33        }
34
35        fdout = fopen(CPYFILE, "wb");
36        if (fdout == NULL){
37                printf("Error opening copy file.\n");
38                return -1;
39        }
40
41//  create a copy of the partition
42        while(!feof(fdin)) {
43            ch = fgetc(fdin);
44            if(ferror(fdin)) {
45              printf("Error reading input file.\n");
46              exit(1);
47            }
48            if(!feof(fdin)) fputc(ch, fdout);
49            if(ferror(fdout)) {
50              printf("Error writing copy file.\n");
51              exit(1);
52            }
53        }
54        if(fclose(fdin)==EOF) {
55                printf("Error closing input file.\n");
56                exit(1);
57        }
58
59        if(fclose(fdout)==EOF) {
60                printf("Error closing copy file.\n");
61                exit(1);
62        }
63
64//  copy back and patch
65        long i;
66
67        fdin = fopen(CPYFILE, "rb");
68        if (fdin == NULL){
69                printf("Error opening copy file.\n");
70                return -1;
71        }
72
73        fdout = fopen(OUTFILE, "wb");
74        if (fdout == NULL){
75                printf("Error opening output file.\n");
76                return -1;
77        }
78
79        i = 0;
80
81        while(!feof(fdin)) {
82            ch = fgetc(fdin);
83            if(ferror(fdin)) {
84              printf("Error reading copy file.\n");
85              exit(1);
86            }
87            if (i==0xa00 || (i>0x80003 && i<0x807fc) || (i>=0x80800 && i<=0x82fff)){
88                ch = 0x00;
89            } else if ((i>=0x200 && i<=0x207)) {
90                ch = 0x31;
91            } else if (i==0x80000) {
92                ch = 0x78;
93            } else if (i==0x80001) {
94                ch = 0x56;
95            } else if (i==0x80002) {
96                ch = 0xF3;
97            } else if (i==0x80003) {
98                ch = 0xC9;
99            } else if (i==0x807fc) {
100                ch = 0x49;
101            } else if (i==0x807fd) {
102                ch = 0x53;
103            } else if (i==0x807fe) {
104                ch = 0xF4;
105            } else if (i==0x807ff) {
106                ch = 0x7D;
107            }
108                if(!feof(fdin)) fputc(ch, fdout);
109                if(ferror(fdout)) {
110                  printf("Error writing output file.\n");
111                  exit(1);
112                }
113                i++;
114        }
115        if(fclose(fdin)==EOF) {
116                printf("Error closing copy file.\n");
117                exit(1);
118        }
119
120        if(fclose(fdout)==EOF) {
121                printf("Error closing output file.\n");
122                exit(1);
123        }
124
125        return 0;
126}