diff options
Diffstat (limited to 'utils/samsungtools/samsung.c')
-rw-r--r-- | utils/samsungtools/samsung.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/utils/samsungtools/samsung.c b/utils/samsungtools/samsung.c index decf34f208..2d45b6f068 100644 --- a/utils/samsungtools/samsung.c +++ b/utils/samsungtools/samsung.c | |||
@@ -117,6 +117,57 @@ struct samsung_firmware_t *samsung_read(samsung_read_t read, | |||
117 | return fw; | 117 | return fw; |
118 | } | 118 | } |
119 | 119 | ||
120 | enum samsung_error_t samsung_write(samsung_write_t write, samsung_printf_t printf, | ||
121 | void *user, struct samsung_firmware_t *fw) | ||
122 | { | ||
123 | struct yp_header_t yp_hdr; | ||
124 | struct yp_md5_t yp_md5; | ||
125 | |||
126 | // write header | ||
127 | strncpy(yp_hdr.signature, YP_SIGNATURE, sizeof(yp_hdr.signature)); | ||
128 | strncpy(yp_hdr.version, fw->version, sizeof(yp_hdr.version)); | ||
129 | strncpy(yp_hdr.region, fw->region, sizeof(yp_hdr.region)); | ||
130 | strncpy(yp_hdr.extra, fw->extra, sizeof(yp_hdr.extra)); | ||
131 | strncpy(yp_hdr.model, fw->model, sizeof(yp_hdr.model)); | ||
132 | yp_hdr.datasize = fw->data_size; | ||
133 | |||
134 | printf(user, false, "Model: %s\n", yp_hdr.model); | ||
135 | printf(user, false, "Version: %s %s %s\n", yp_hdr.version, yp_hdr.region, yp_hdr.extra); | ||
136 | |||
137 | if(write(user, 0, &yp_hdr, sizeof(yp_hdr)) != sizeof(yp_hdr)) | ||
138 | { | ||
139 | printf(user, true, "Cannot write header\n"); | ||
140 | return SAMSUNG_WRITE_ERROR; | ||
141 | } | ||
142 | |||
143 | // encrypt data | ||
144 | cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key)); | ||
145 | // compute MD5 | ||
146 | MD5_CTX c; | ||
147 | MD5_Init(&c); | ||
148 | MD5_Update(&c, fw->data, fw->data_size); | ||
149 | MD5_Final(yp_md5.md5, &c); | ||
150 | |||
151 | // write data | ||
152 | if(write(user, sizeof(yp_hdr), fw->data, fw->data_size) != fw->data_size) | ||
153 | { | ||
154 | // decrypt data so that the firmware data is the same after the call | ||
155 | cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key)); | ||
156 | printf(user, true, "Cannot write data\n"); | ||
157 | return SAMSUNG_WRITE_ERROR; | ||
158 | } | ||
159 | // decrypt data so that the firmware data is the same after the call | ||
160 | cyclic_xor(fw->data, fw->data_size, g_yp_key, sizeof(g_yp_key)); | ||
161 | // write md5 | ||
162 | if(write(user, sizeof(yp_hdr) + fw->data_size, &yp_md5, sizeof(yp_md5)) != sizeof(yp_md5)) | ||
163 | { | ||
164 | printf(user, true, "Cannot write md5\n"); | ||
165 | return SAMSUNG_WRITE_ERROR; | ||
166 | } | ||
167 | |||
168 | return SAMSUNG_SUCCESS; | ||
169 | } | ||
170 | |||
120 | void samsung_free(struct samsung_firmware_t *fw) | 171 | void samsung_free(struct samsung_firmware_t *fw) |
121 | { | 172 | { |
122 | if(fw) | 173 | if(fw) |