Rev 7843 | Rev 7868 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7843 | Rev 7867 | ||
---|---|---|---|
Line 327... | Line 327... | ||
327 | this->sectorsPerFat = *(uint16_t *)((uintptr_t)this->image + 0x16); |
327 | this->sectorsPerFat = *(uint16_t *)((uintptr_t)this->image + 0x16); |
328 | this->firstFat = (0 + this->reservedSectorCount) * this->bytesPerSector; |
328 | this->firstFat = (0 + this->reservedSectorCount) * this->bytesPerSector; |
329 | this->rootDirectory = this->firstFat + this->numberOfFats |
329 | this->rootDirectory = this->firstFat + this->numberOfFats |
330 | * this->sectorsPerFat * this->bytesPerSector; |
330 | * this->sectorsPerFat * this->bytesPerSector; |
331 | this->dataRegion = this->rootDirectory + this->maxRootEntries * 32; |
331 | this->dataRegion = this->rootDirectory + this->maxRootEntries * 32; |
332 | con_printf("Bytes per sector: %d\n", this->bytesPerSector); |
332 | con_printf("\nBytes per sector: %d\n", this->bytesPerSector); |
333 | con_printf("Sectors per claster: %d\n", this->sectorsPerClaster); |
333 | con_printf("Sectors per claster: %d\n", this->sectorsPerClaster); |
334 | con_printf("Reserver sector count: %d\n", this->reservedSectorCount); |
334 | con_printf("Reserver sector count: %d\n", this->reservedSectorCount); |
335 | con_printf("Number of FATs: %d\n", this->numberOfFats); |
335 | con_printf("Number of FATs: %d\n", this->numberOfFats); |
336 | con_printf("Max root entries: %d\n", this->maxRootEntries); |
336 | con_printf("Max root entries: %d\n", this->maxRootEntries); |
337 | con_printf("Total sectors: %d\n", this->totalSectors); |
337 | con_printf("Total sectors: %d\n", this->totalSectors); |
338 | con_printf("Sectors per FAT: %d\n", this->sectorsPerFat); |
338 | con_printf("Sectors per FAT: %d\n", this->sectorsPerFat); |
339 | con_printf("First FAT: %d\n", this->firstFat); |
339 | con_printf("First FAT: %d\n", this->firstFat); |
340 | con_printf("Root directory: %d\n", this->rootDirectory); |
340 | con_printf("Root directory: %d\n", this->rootDirectory); |
341 | con_printf("Data region: %d\n", this->dataRegion); |
341 | con_printf("Data region: %d\n\n", this->dataRegion); |
342 | return 1; |
342 | return 1; |
343 | } |
343 | } |
Line 344... | Line 344... | ||
344 | 344 | ||
345 | static int fat12__error(Fat12 *this, const char *errorMessage) { |
345 | static int fat12__error(Fat12 *this, const char *errorMessage) { |
Line 371... | Line 371... | ||
371 | *fileNameDelim = '\0'; |
371 | *fileNameDelim = '\0'; |
372 | mkdir_p(outputPath->data); |
372 | mkdir_p(outputPath->data); |
373 | *fileNameDelim = '/'; |
373 | *fileNameDelim = '/'; |
374 | } |
374 | } |
375 | } |
375 | } |
376 | con_printf("Extracting \"%s\"\n", outputPath->data); |
376 | con_printf("Extracting %s\n", outputPath->data); |
377 | if (!(fp = fopen(outputPath->data, "wb"))) { perror(NULL); } |
377 | if (!(fp = fopen(outputPath->data, "wb"))) { perror(NULL); } |
378 | fwrite(data, 1, size, fp); |
378 | fwrite(data, 1, size, fp); |
379 | fclose(fp); |
379 | fclose(fp); |
380 | outputPath->data[outputPath->length] = '\0'; |
380 | outputPath->data[outputPath->length] = '\0'; |
381 | return 0; |
381 | return 0; |
382 | } |
382 | } |
Line 383... | Line -... | ||
383 | - | ||
384 | 383 | ||
385 | 384 | ||
386 | 385 | ||
387 | int main(int argc, char **argv) { |
386 | int main(int argc, char **argv) { |
388 | Fat12 fat12 = { 0 }; |
387 | Fat12 fat12 = { 0 }; |
Line 389... | Line 388... | ||
389 | char *imageFile = NULL; |
388 | char *imageFile = NULL; |
390 | String outputFolder = { 0 }; |
389 | String outputFolder = { 0 }; |
Line 391... | Line 390... | ||
391 | int exit = 0; |
390 | int exit = 0; |
- | 391 | ||
392 | 392 | char app_title[] = "UnImg - kolibri.img file unpacker"; |
|
393 | if (con_init_console_dll()) return -1; |
393 | if (con_init_console_dll_param(-1, -1, -1, 350, app_title)) return -1; |
394 | con_set_title("UnImg - kolibri.img file unpacker"); |
394 | |
395 | 395 | if (argc < 2) { |
|
- | 396 | con_write_asciiz(" Usage:\n"); |
|
- | 397 | con_write_asciiz(" unimg \"/path/to/kolibri.img\" \"/optional/extract/path\" [-e]\n"); |
|
- | 398 | con_write_asciiz(" where optional key [-e] is exit on success"); |
|
396 | if (argc < 2) { |
399 | con_exit(0); |
Line 397... | Line -... | ||
397 | con_write_asciiz("Usage: unimg \"/path/to/kolibri.img\" \"/optional/extract/path\" [-e]"); |
- | |
Line 398... | Line 400... | ||
398 | con_write_asciiz("-e\tExit on success"); |
400 | return -1; |
399 | con_exit(0); |
401 | } else { |
Line 400... | Line 402... | ||
400 | return -1; |
402 | imageFile = argv[1]; |
401 | } |
403 | con_printf("File: %s\n", imageFile); |
- | 404 | } |
|
402 | 405 | ||
- | 406 | ||
- | 407 | outputFolder.capacity = 4096; |
|
Line 403... | Line 408... | ||
403 | imageFile = argv[1]; |
408 | outputFolder.data = malloc(outputFolder.capacity); |
Line 404... | Line 409... | ||
404 | 409 | ||
405 | outputFolder.capacity = 4096; |
410 | //! ACHTUNG: possible buffer overflow, is 4096 enough in KolibriOS? |