summaryrefslogtreecommitdiff
path: root/utils/MTP/beastpatcher/beastpatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/MTP/beastpatcher/beastpatcher.c')
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 72de1b57b8..d6c49ac596 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -127,12 +127,40 @@ static void create_single_boot(unsigned char* boot, int bootlen,
127 return; 127 return;
128} 128}
129 129
130int beastpatcher(void) 130int beastpatcher(const unsigned char* bootfile)
131{ 131{
132 char yesno[4]; 132 char yesno[4];
133 unsigned char* fwbuf; 133 unsigned char* fwbuf;
134 int fwsize; 134 int fwsize;
135 struct mtp_info_t mtp_info; 135 struct mtp_info_t mtp_info;
136 unsigned char* bootloader = bootimg;
137 unsigned int len_bootloader = LEN_bootimg;
138
139 if (bootfile) {
140 int res;
141 FILE* fp;
142 size_t bread;
143#ifdef _LARGEFILE64_SOURCE
144 struct stat64 sb;
145 res = stat64(bootfile, &sb);
146#else
147 struct stat sb;
148 res = stat(bootfile, &sb);
149#endif
150 if(res == -1) {
151 fprintf(stderr, "[ERR] Getting bootloader file size failed!\n");
152 return 1;
153 }
154 len_bootloader = sb.st_size;
155 bootloader = (unsigned char*)malloc(len_bootloader);
156 /* load bootloader binary to memory. */
157 fp = fopen(bootfile, "rb");
158 bread = fread(bootloader, sizeof(unsigned char), len_bootloader, fp);
159 if(bread * sizeof(unsigned char) != len_bootloader) {
160 fprintf(stderr, "[ERR] Error reading firmware file!\n");
161 return 1;
162 }
163 }
136 164
137 if (mtp_init(&mtp_info) < 0) { 165 if (mtp_init(&mtp_info) < 0) {
138 fprintf(stderr,"[ERR] Can not init MTP\n"); 166 fprintf(stderr,"[ERR] Can not init MTP\n");
@@ -158,7 +186,7 @@ int beastpatcher(void)
158 if (yesno[0]=='i') 186 if (yesno[0]=='i')
159 { 187 {
160 /* Create a single-boot bootloader from the embedded bootloader */ 188 /* Create a single-boot bootloader from the embedded bootloader */
161 create_single_boot(bootimg, LEN_bootimg, &fwbuf, &fwsize); 189 create_single_boot(bootloader, len_bootloader, &fwbuf, &fwsize);
162 190
163 if (fwbuf == NULL) 191 if (fwbuf == NULL)
164 return 1; 192 return 1;
@@ -180,6 +208,9 @@ int beastpatcher(void)
180 fprintf(stderr,"[INFO] Installation cancelled.\n"); 208 fprintf(stderr,"[INFO] Installation cancelled.\n");
181 } 209 }
182 } 210 }
211 if(bootfile) {
212 free(bootloader);
213 }
183 214
184 mtp_finished(&mtp_info); 215 mtp_finished(&mtp_info);
185 216