diff options
Diffstat (limited to 'lib/cdutils.cpp')
-rw-r--r-- | lib/cdutils.cpp | 436 |
1 files changed, 64 insertions, 372 deletions
diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 57c1068..e4d7749 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -24,14 +24,14 @@ #include <unistd.h> #include "generic.h" #include "cdutils.h" -#include "Input.h" +#include "Output.h" Output * ppf_file = 0; int pt1 = -1, pt2 = -1, snum = 0, ptl = 0, root = 0; long sec_sizes[5] = {0, 2048, 2336, 2048, 2324}; long sec_offsts[5] = {0, 16, 16, 24, 24}; -char * sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; +String sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; struct DirEntry rootDir; @@ -60,7 +60,7 @@ unsigned long from_MSF(unsigned long msf, unsigned long start) { return from_MSF(m, s, f, start); } -Input * open_ppf(String ppf, Handle * iso, String comment) { +Output * open_ppf(String ppf, Handle * iso, String comment) { int i, l; Byte buffer[1024]; @@ -69,10 +69,10 @@ Input * open_ppf(String ppf, Handle * iso, String comment) { l = comment.strlen(); if (l >= 50) { - ppf_file->write(comment.to_char(), 50); + ppf_file->write(comment.to_charp(), 50); } else { char * t = " "; - ppf_file->write(comment, l); + ppf_file->write(comment.to_charp(), l); for (i = l; i < 50; i++) { ppf_file->write(t, 1); } @@ -122,7 +122,7 @@ String format_date(String input) { output += input.extract(10, 11) + ':'; output += input.extract(12, 13) + '.'; output += input.extract(14, 15); - output += String("").set("%+3.1f", ((float) (*(((char *)input) + 16))) / 4); + output += String("").set("%+3.1f", ((float) (*((input.to_charp()) + 16))) / 4); return output; } @@ -161,6 +161,10 @@ int guess_type(Handle * f_iso, int number) { return MODE_0; } +void sector_seek(Handle * f_iso, long sector) { + f_iso->seek(2336 * sector); +} + long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { if (number >= 0) { sector_seek(f_iso, number); @@ -171,7 +175,7 @@ long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { } f_iso->seek(sec_offsts[type], SEEK_CUR); - f_iso->read(buffer, sec_sizes[type], f_iso); + f_iso->read(buffer, sec_sizes[type]); f_iso->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); return sec_sizes[type]; } @@ -221,7 +225,7 @@ void read_file(Handle * f_iso, Handle * file, int type, int number, long size) { } } -void write_sector(Handle * f_iso_r, Handle * f_iso_w, Buffer * buffer, int type, int number) { +void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number) { Byte old_sector[2352], new_sector[2352]; if (type == GUESS) { @@ -276,33 +280,7 @@ void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, in } } -void write_datas(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number, long size) { - long nbsectors, i; - unsigned char sector[2352]; - - if (type == GUESS) { - type = guess_type(f_iso_r, number); - } - - if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); - } - - nbsectors = size / sec_sizes[type]; - - for (i = 0; i < nbsectors; i++) { - write_sector(f_iso_r, f_iso_w, buffer + i * sec_sizes[type], type, number + i); - } - - if (size % sec_sizes[type]) { - memset(sector, 0, 2352); - bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, sector, type, number + i); - } -} - -void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int number) { +void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int number) { long size, nbsectors, i; unsigned char buffer[2352]; @@ -315,7 +293,7 @@ void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int numb sector_seek(f_iso_w, number); } - size = filesize(file); + size = file->GetSize(); nbsectors = size / sec_sizes[type]; if (size % sec_sizes[type]) { @@ -324,34 +302,7 @@ void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int numb for (i = 0; i < nbsectors; i++) { memset(buffer, 0, 2352); - fread(buffer, 1, sec_sizes[type], file); - write_sector(f_iso_r, f_iso_w, buffer, type); - } -} - -void write_file(int f_iso_r, int f_iso_w, int file, char type, int number) { - long size, nbsectors, i; - unsigned char buffer[2352]; - - if (type == GUESS) { - type = guess_type(f_iso_r, number); - } - - if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); - } - - size = filesize(file); - nbsectors = size / sec_sizes[type]; - - if (size % sec_sizes[type]) { - nbsectors++; - } - - for (i = 0; i < nbsectors; i++) { - memset(buffer, 0, 2352); - read(file, buffer, sec_sizes[type]); + file->read(buffer, sec_sizes[type]); write_sector(f_iso_r, f_iso_w, buffer, type); } } @@ -376,15 +327,15 @@ int show_entry(struct DirEntry * dir) { return dir->R; } -int show_dir(FILE * f_iso, struct DirEntry * dir) { +int show_dir(Handle * f_iso, struct DirEntry * dir) { unsigned int ptr; - unsigned char * buffer; + Byte * buffer; if (!(dir->Flags & 2)) { return 0; } - buffer = (unsigned char *) malloc(dir->Size); + buffer = (Byte *) malloc(dir->Size); read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); ptr = 0; @@ -396,56 +347,7 @@ int show_dir(FILE * f_iso, struct DirEntry * dir) { return 1; } -int show_dir(int f_iso, struct DirEntry * dir) { - unsigned int ptr; - unsigned char * buffer; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (unsigned char *) malloc(dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < dir->Size) { - ptr += show_entry((struct DirEntry *) &(buffer[ptr])); - } - - free(buffer); - return 1; -} - -struct DirEntry find_dir_entry(FILE * f_iso, struct DirEntry * dir, char * name) { - unsigned int ptr, size; - unsigned char * buffer; - struct DirEntry r = {0, 0, 0, 0, 0}; - - if (!(dir->Flags & 2)) { - return r; - } - - buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { - r = *dir; - } - ptr += dir->R; - } - } - - free(buffer); - return r; -} - -struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { +struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String name) { unsigned int ptr, size; unsigned char * buffer; struct DirEntry r = {0, 0, 0, 0, 0}; @@ -463,7 +365,7 @@ struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { if (!dir->R) { ptr++; } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { r = *dir; } ptr += dir->R; @@ -474,9 +376,9 @@ struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { return r; } -struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct DirEntry * dir, char * name) { +struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry * dir, String name) { unsigned int ptr, size; - unsigned char * buffer; + Byte * buffer; struct DirEntry * rdir = 0; *bufout = 0; @@ -484,7 +386,7 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D return 0; } - buffer = (unsigned char *) malloc(size = dir->Size); + buffer = (Byte *) malloc(size = dir->Size); read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); ptr = 0; @@ -493,7 +395,7 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D if (!dir->R) { ptr++; } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { rdir = dir; } ptr += dir->R; @@ -508,48 +410,14 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D return rdir; } -struct DirEntry * find_dir_entry(int f_iso, unsigned char ** bufout, struct DirEntry * dir, char * name) { - unsigned int ptr, size; - unsigned char * buffer; - struct DirEntry * rdir = 0; - *bufout = 0; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { - rdir = dir; - } - ptr += dir->R; - } - } - - if (rdir->R) { - *bufout = buffer; - } else { - free(buffer); - } - return rdir; -} - -int show_iso_infos(FILE * f_iso) { - unsigned char buffer[2048]; +int show_iso_infos(Handle * f_iso) { + char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, buffer, GUESS, 16); + read_sector(f_iso, (Byte *) buffer, GUESS, 16); - printm(M_BARE, "Sector guessed mode : %s\n", sec_modes[guess_type(f_iso, 16)]); + printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(f_iso, 16)] + "\n"); printm(M_BARE, "offset-size-info : contents\n"); printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); memcpy(pbuff, buffer + 1, 5); @@ -602,10 +470,10 @@ int show_iso_infos(FILE * f_iso) { memcpy(pbuff, buffer + 776, 37); pbuff[37] = 0; printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813])); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830])); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847])); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864])); + printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813]).to_charp()); + printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830]).to_charp()); + printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847]).to_charp()); + printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864]).to_charp()); printm(M_BARE, "Root record:\n"); show_head_entry(); @@ -614,79 +482,7 @@ int show_iso_infos(FILE * f_iso) { return 1; } -int show_iso_infos(int f_iso) { - unsigned char buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - - read_sector(f_iso, buffer, GUESS, 16); - - printm(M_BARE, "Sector guessed mode : %s\n", sec_modes[guess_type(f_iso, 16)]); - printm(M_BARE, "offset-size-info : contents\n"); - printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - printm(M_BARE, " 1 - 5-`CD001' : %s\n", pbuff); - printm(M_BARE, " 6 - 2- 1 : %i\n", s = *((short int *) &(buffer[6]))); - printm(M_BARE, "(*this was the signature*)\n"); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_BARE, "Not a valid iso9660 file.\n"); - return 0; - } - - memcpy(pbuff, buffer + 8, 32); - pbuff[32] = 0; - printm(M_BARE, " 8 - 32- SYSID : %s\n", pbuff); - memcpy(pbuff, buffer + 40, 32); - pbuff[32] = 0; - printm(M_BARE, " 40 - 32- VOLID : %s\n", pbuff); - printm(M_BARE, " 80 - 8- SNum : %li\n", *((long int *) &(buffer[80]))); - printm(M_BARE, " 120 - 4- VOLSiz : %i\n", *((short int *) &(buffer[120]))); - printm(M_BARE, " 124 - 4- VOLNum : %i\n", *((short int *) &(buffer[124]))); - printm(M_BARE, " 128 - 4- SSize : %i\n", *((short int *) &(buffer[128]))); - printm(M_BARE, " 132 - 8- PSize : %li\n", *((long int *) &(buffer[132]))); - printm(M_BARE, " 140 - 4- 1SLPath: %i\n", *((short int *) &(buffer[140]))); - printm(M_BARE, " 144 - 4- 2SLPath: %i\n", *((short int *) &(buffer[144]))); - printm(M_BARE, " 148 - 4- 1SBPath: %i\n", swap_dword(*((short int *) &(buffer[148])))); - printm(M_BARE, " 152 - 4- 2SBPath: %i\n", swap_dword(*((short int *) &(buffer[152])))); - memcpy(pbuff, buffer + 190, 128); - pbuff[128] = 0; - printm(M_BARE, " 190 - 128- VStId : %s\n", pbuff); - memcpy(pbuff, buffer + 318, 128); - pbuff[128] = 0; - printm(M_BARE, " 318 - 128- PubId : %s\n", pbuff); - memcpy(pbuff, buffer + 446, 128); - pbuff[128] = 0; - printm(M_BARE, " 446 - 128- DPrId : %s\n", pbuff); - memcpy(pbuff, buffer + 574, 128); - pbuff[128] = 0; - printm(M_BARE, " 574 - 128- AppId : %s\n", pbuff); - memcpy(pbuff, buffer + 702, 37); - pbuff[37] = 0; - printm(M_BARE, " 702 - 37- CpyFile: %s\n", pbuff); - memcpy(pbuff, buffer + 739, 37); - pbuff[37] = 0; - printm(M_BARE, " 739 - 37- AbsFile: %s\n", pbuff); - memcpy(pbuff, buffer + 776, 37); - pbuff[37] = 0; - printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813])); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830])); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847])); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864])); - - printm(M_BARE, "Root record:\n"); - show_head_entry(); - show_entry((DirEntry *) &(buffer[156])); - - return 1; -} - -int get_iso_infos(FILE * f_iso) { +int get_iso_infos(Handle * f_iso) { unsigned char buffer[2048]; char pbuff[130]; short int s, nogood = 0; @@ -714,36 +510,8 @@ int get_iso_infos(FILE * f_iso) { return 1; } -int get_iso_infos(int f_iso) { - unsigned char buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - - read_sector(f_iso, buffer, GUESS, 16); - - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - - s = *((short int *) &(buffer[6])); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_ERROR, "Not a valid iso9660 file.\n"); - return 0; - } - - pt1 = *((short int *) &(buffer[140])); - pt2 = *((short int *) &(buffer[144])); - snum = *((int *) &(buffer[80])); - ptl = *((long int *) &(buffer[132])); - rootDir = *((struct DirEntry *) &(buffer[156])); - return 1; -} - -int get_pt_infos(FILE * f_iso) { - unsigned char * buffer; +int get_pt_infos(Handle * f_iso) { + Byte * buffer; if ((pt1 <= 0) && (pt2 <= 0)) if (!get_iso_infos(f_iso)) @@ -754,7 +522,7 @@ int get_pt_infos(FILE * f_iso) { return 0; } - buffer = (unsigned char *) malloc(ptl); + buffer = (Byte *) malloc(ptl); read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); if (buffer[0] == 1) @@ -769,8 +537,8 @@ int get_pt_infos(FILE * f_iso) { return root ? 1 : 0; } -int show_pt_infos(FILE * f_iso) { - unsigned char * buffer; +int show_pt_infos(Handle * f_iso) { + Byte * buffer; char pbuf[100]; int i, ptr; @@ -783,7 +551,7 @@ int show_pt_infos(FILE * f_iso) { return 0; } - buffer = (unsigned char *) malloc(ptl); + buffer = (Byte *) malloc(ptl); read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); printm(M_BARE, "node^paren@sector : name\n"); @@ -798,107 +566,20 @@ int show_pt_infos(FILE * f_iso) { return 1; } -int show_pt_infos(int f_iso) { - unsigned char * buffer; - char pbuf[100]; - int i, ptr; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return 0; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return 0; - } - - buffer = (unsigned char *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); - - printm(M_BARE, "node^paren@sector : name\n"); - for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { - strncpy(pbuf, (char *) &(buffer[8 + ptr]), buffer[ptr]); - pbuf[buffer[ptr]] = 0; - printm(M_BARE, "%3i ^ %3i @ %6i: %s\n", i, *((unsigned short *) &(buffer[6 + ptr])), *((unsigned long *) &(buffer[2 + ptr])), pbuf); - ptr += 8 + buffer[ptr]; - } - - free(buffer); - return 1; -} - -struct DirEntry find_path(FILE * f_iso, char * path) { - char ** pts = split(path, '/'); - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return dir; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return dir; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) - return dir; - } - - return dir; -} - -struct DirEntry find_path(int f_iso, char * path) { - char ** pts = split(path, '/'); +struct DirEntry find_path(Handle * f_iso, String path) { + char * newpath = path.strdup(); + char ** pts = split(newpath, '/'); struct DirEntry dir = {0, 0, 0, 0, 0}; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return dir; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return dir; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) - return dir; - } - - return dir; -} - -struct DirEntry find_parent(FILE * f_iso, char * path) { - char ** pts, * p; - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((p = strchr(path, '/'))) { - *p = 0; - } - if (!*path) { - return rootDir; - } - pts = split(path, '/'); - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos(f_iso)) { + free(newpath); return dir; + } if ((!pt1) & (!pt2)) { printm(M_ERROR, "No path table defined.\n"); + free(newpath); return dir; } @@ -909,31 +590,39 @@ struct DirEntry find_parent(FILE * f_iso, char * path) { if (!strlen(*pts)) continue; dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) + if (!dir.R) { + free(newpath); return dir; + } } + free(newpath); return dir; } -struct DirEntry find_parent(int f_iso, char * path) { +struct DirEntry find_parent(Handle * f_iso, String path) { + char * newpath = path.strdup(); char ** pts, * p; struct DirEntry dir = {0, 0, 0, 0, 0}; - if ((p = strchr(path, '/'))) { + if ((p = strchr(newpath, '/'))) { *p = 0; } - if (!*path) { + if (!*newpath) { + free(newpath); return rootDir; } - pts = split(path, '/'); + pts = split(newpath, '/'); if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos(f_iso)) { + free(newpath); return dir; + } if ((!pt1) & (!pt2)) { printm(M_ERROR, "No path table defined.\n"); + free(newpath); return dir; } @@ -944,9 +633,12 @@ struct DirEntry find_parent(int f_iso, char * path) { if (!strlen(*pts)) continue; dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) + if (!dir.R) { + free(newpath); return dir; + } } + free(newpath); return dir; } |