summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FAQ-cd.txt9
-rwxr-xr-xXenogears/Makefile5
-rw-r--r--Xenogears/reinsert.cpp21
-rw-r--r--cd-tool.cpp29
-rw-r--r--cdutils.cpp493
-rw-r--r--cdutils.h18
-rw-r--r--fileutils.cpp25
-rw-r--r--fileutils.h3
8 files changed, 572 insertions, 31 deletions
diff --git a/FAQ-cd.txt b/FAQ-cd.txt
index 4a3a92b..778b0d7 100644
--- a/FAQ-cd.txt
+++ b/FAQ-cd.txt
@@ -131,10 +131,11 @@ A: Firstly, when you have a raw sector, you have to understand its primary form.
in packed BCD format. You may know what the BCD format is if you are "old"
enough for that. I won't enter into the details so if you want a more
description of the BCD format, look into the net. You only have to know that:
-
-unsigned char from_BCD(unsigned char x) {return ((x & 15) + (x & 240) * 10));}
-unsigned char to_BCD(unsigned char x) {return ((x / 10) << 4) | (x % 10));}
-int is_valid_BCD(unsigned char x) {return (((x & 15) < 10) && ((x >> 4) < 10));}
+
+typedef unsigned char uchar;
+uchar from_BCD(uchar x) {return ((x & 15) + ((x & 240) >> 4) * 10));}
+uchar to_BCD(uchar x) {return ((x / 10) << 4) | (x % 10));}
+int is_valid_BCD(uchar x) {return (((x & 15) < 10) && ((x >> 4) < 10));}
Last thing: when you look at a BCD packed number, you have to read it in
hexadecimal, and then you will see a "decimal" number. So when you count
diff --git a/Xenogears/Makefile b/Xenogears/Makefile
index 22d6392..14c48ff 100755
--- a/Xenogears/Makefile
+++ b/Xenogears/Makefile
@@ -3,7 +3,7 @@
CPPFLAGS=-Wall -g -I. -O3 -mcpu=i686
CXX=g++
-TARGET = lz77 dlz77 yazedc cd-tool
+TARGET = lz77 dlz77 yazedc cd-tool reinsert
all: ${TARGET}
@@ -19,5 +19,8 @@ yazedc: yazedc.cpp crctables crctable.out
cd-tool: cd-tool.cpp cdutils.cpp cdutils.h fileutils.cpp fileutils.h generic.cpp generic.h yazedc.cpp yazedc.h
${CXX} ${CPPFLAGS} ${LDFLAGAS} cd-tool.cpp cdutils.cpp fileutils.cpp yazedc.cpp generic.cpp -o cd-tool
+reinsert: reinsert.cpp cdutils.cpp cdutils.h fileutils.cpp fileutils.h generic.cpp generic.h yazedc.cpp yazedc.h
+ ${CXX} ${CPPFLAGS} ${LDFLAGS} reinsert.cpp cdutils.cpp fileutils.cpp yazedc.cpp generic.cpp -o reinsert
+
clean:
rm -f *.o ${TARGET} compil.c
diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp
index e58b871..d6e0a4c 100644
--- a/Xenogears/reinsert.cpp
+++ b/Xenogears/reinsert.cpp
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include "fileutils.h"
#include "cdutils.h"
#include "generic.h"
@@ -22,7 +23,7 @@ struct t_sequence {
int type;
};
-char *title, *iso_filename, *tbl_filename, *prefix, *in_filename;
+char *title, *iso_filename, *prefix, *in_filename;
unsigned long iso_size;
unsigned int nb_records, nb_seqs = 0;
struct t_sequence sequences[1000];
@@ -31,7 +32,7 @@ int slus_index = -1, force = 0;
long check_iso(int f_iso);
void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex);
-int process_def_file(int f_def);
+int process_def_file(int f_def);
unsigned char user_data[2352];
@@ -87,10 +88,16 @@ int main(int argc, char **argv)
printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename);
exit(-1);
}
+
+ if (lseek(f_iso_w, 0, SEEK_SET)) {
+ printm(M_ERROR, "Can't rewind the file\n");
+ exit(-1);
+ }
if (check_iso(f_iso_r)) {
printm(M_ERROR, "Invalid iso file for %s\n", title);
printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
+ exit(-1);
} else {
printm(M_INFO, "Genuine %s iso detected.\n", title);
}
@@ -112,11 +119,11 @@ int main(int argc, char **argv)
/*
* Ugly but working... for now
*/
-int process_def_file(int h_f_def)
+int process_def_file(int ff_def)
{
char t[1024], *p;
+ FILE * f_def = fdopen(ff_def, "r");
unsigned int n, sum = 0;
- FILE * f_def = fdopen(h_f_def, "r");
if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
return 1;
@@ -131,12 +138,6 @@ int process_def_file(int h_f_def)
if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
return 1;
*p = 0;
- printm(M_INFO, "Read index table filename: %s\n", t);
- tbl_filename = strdup(t);
-
- if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
- return 1;
- *p = 0;
printm(M_INFO, "Read global directory prefix: %s\n", t);
prefix = strdup(t);
diff --git a/cd-tool.cpp b/cd-tool.cpp
index 8cd5d6e..4b601ba 100644
--- a/cd-tool.cpp
+++ b/cd-tool.cpp
@@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
+#include <unistd.h>
#include "cdutils.h"
#include "generic.h"
#include "fileutils.h"
@@ -57,7 +58,7 @@ void showhelp(void) {
int main(int argc, char ** argv) {
int type = GUESS, c, size, force = 0, sector;
- FILE * iso_r, * iso_w;
+ int iso_r, iso_w;
char * ppf = 0, * iso_name = 0, * arg1 = 0, * arg2 = 0, * f;
verbosity = M_WARNING;
@@ -89,7 +90,7 @@ int main(int argc, char ** argv) {
iso_name = argv[optind++];
- if (!(iso_r = fopen(iso_name, "r"))) {
+ if ((iso_r = open(iso_name, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for reading.\n", iso_name);
exit(-1);
}
@@ -129,7 +130,7 @@ int main(int argc, char ** argv) {
show_dir(iso_r, &dir);
} else if (!strcmp(argv[optind], "extract-file")) {
struct DirEntry dir;
- FILE * file;
+ int file;
optind++;
if ((argc - 2) != optind) {
@@ -139,7 +140,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if (!(file = fopen(arg1, "w"))) {
+ if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
exit(-1);
}
@@ -152,7 +153,7 @@ int main(int argc, char ** argv) {
printm(M_STATUS, "Reading path %s to file %s.\n", arg2, arg1);
read_file(iso_r, file, type, dir.Sector, dir.Size);
} else if (!strcmp(argv[optind], "extract")) {
- FILE * file;
+ int file;
optind++;
if ((argc - 3) != optind) {
@@ -163,7 +164,7 @@ int main(int argc, char ** argv) {
arg1 = argv[optind++];
size = atoi(argv[optind++]);
sector = atoi(argv[optind++]);
- if (!(file = fopen(arg1, "w"))) {
+ if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
exit(-1);
}
@@ -172,13 +173,13 @@ int main(int argc, char ** argv) {
} else if (!strcmp(argv[optind], "insert-file")) {
struct DirEntry dir, * d;
unsigned char * buffer;
- FILE * file;
+ int file;
int old_type;
- if (!(iso_w = fopen(iso_name, "wa"))) {
+ if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
exit(-1);
}
- fseek(iso_w, 0, SEEK_SET);
+ lseek(iso_w, 0, SEEK_SET);
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
@@ -194,7 +195,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if (!(file = fopen(arg1, "r"))) {
+ if ((file = open(arg1, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
exit(-1);
}
@@ -234,12 +235,12 @@ int main(int argc, char ** argv) {
write_datas(iso_r, iso_w, buffer, GUESS, dir.Sector, dir.Size);
free(buffer);
} else if (!strcmp(argv[optind], "insert")) {
- FILE * file;
- if (!(iso_w = fopen(iso_name, "wa"))) {
+ int file;
+ if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
exit(-1);
}
- fseek(iso_w, 0, SEEK_SET);
+ lseek(iso_w, 0, SEEK_SET);
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
@@ -255,7 +256,7 @@ int main(int argc, char ** argv) {
}
arg1 = argv[optind++];
sector = atoi(argv[optind++]);
- if (!(file = fopen(arg1, "r"))) {
+ if ((file = open(arg1, O_RDONLY)) < 0) {
printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
exit(-1);
}
diff --git a/cdutils.cpp b/cdutils.cpp
index bba473a..230099c 100644
--- a/cdutils.cpp
+++ b/cdutils.cpp
@@ -20,6 +20,8 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
+#include <stdlib.h>
+#include <unistd.h>
#include "cdutils.h"
#include "fileutils.h"
#include "generic.h"
@@ -86,6 +88,34 @@ FILE * open_ppf(char * ppf, FILE * iso, char * comment) {
return ppf_file;
}
+FILE * open_ppf(char * ppf, int iso, char * comment) {
+ int i, l;
+ char buffer[1024];
+
+ if (!(ppf_file = fopen(ppf, "w")))
+ return ppf_file;
+ fwrite("PPF20\001", 1, 6, ppf_file);
+
+ l = strlen(comment);
+ if (l >= 50) {
+ fwrite(comment, 1, 50, ppf_file);
+ } else {
+ char * t = " ";
+ fwrite(comment, 1, l, ppf_file);
+ for (i = l; i < 50; i++) {
+ fwrite(t, 1, 1, ppf_file);
+ }
+ }
+
+ l = filesize(iso);
+ fwrite(&l, 1, 4, ppf_file);
+
+ lseek(iso, 0x9320, SEEK_SET);
+ read(iso, buffer, 1024);
+ fwrite(buffer, 1, 1024, ppf_file);
+ return ppf_file;
+}
+
void write_ppf(unsigned char * old_sec, unsigned char * new_sec, int sec_num) {
int i, l = 0, o;
@@ -144,7 +174,23 @@ void sector_seek(FILE * f_iso, long sector) {
long curpos;
curpos = (2352 * (long) sector);
- fseek(f_iso, curpos, SEEK_SET);
+ if (fseek(f_iso, curpos, SEEK_SET)) {
+ printm(M_ERROR, "Unable to seek at %i\n", curpos);
+ exit(-1);
+ } else if (ftell(f_iso) != curpos) {
+ printm(M_ERROR, "Seek slipped when seeking at %i\n", curpos);
+ exit(-1);
+ }
+}
+
+void sector_seek(int f_iso, long sector) {
+ long curpos;
+
+ curpos = (2352 * (long) sector);
+ if (lseek(f_iso, curpos, SEEK_SET) != curpos) {
+ printm(M_ERROR, "Unable to seek at %i\n", curpos);
+ exit(-1);
+ }
}
int guess_type(FILE * f_iso, int number) {
@@ -174,6 +220,33 @@ int guess_type(FILE * f_iso, int number) {
return MODE_0;
}
+int guess_type(int f_iso, int number) {
+ unsigned char header[24];
+
+ if (number >= 0) {
+ sector_seek(f_iso, number);
+ }
+
+ read(f_iso, header, 24);
+ lseek(f_iso, -24, SEEK_CUR);
+ if (header[15] == 1) {
+ return MODE_1;
+ } else if (header[15] == 2) {
+ if (*((unsigned long *) &(header[16])) == *((unsigned long *) &(header[20]))) {
+ if ((header[16] == 0) && (header[17] == 0) && (header[19] == 0)) {
+ if (header[18] & 0x20) {
+ return MODE_2_FORM_2;
+ } else {
+ return MODE_2_FORM_1;
+ }
+ }
+ }
+ return MODE_2;
+ }
+
+ return MODE_0;
+}
+
long read_sector(FILE * f_iso, unsigned char * buffer, char type, int number) {
if (number >= 0) {
sector_seek(f_iso, number);
@@ -189,6 +262,21 @@ long read_sector(FILE * f_iso, unsigned char * buffer, char type, int number) {
return sec_sizes[type];
}
+long read_sector(int f_iso, unsigned char * buffer, char type, int number) {
+ if (number >= 0) {
+ sector_seek(f_iso, number);
+ }
+
+ if (type == GUESS) {
+ type = guess_type(f_iso, number);
+ }
+
+ lseek(f_iso, sec_offsts[type], SEEK_CUR);
+ read(f_iso, buffer, sec_sizes[type]);
+ lseek(f_iso, 2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR);
+ return sec_sizes[type];
+}
+
void read_datas(FILE * f_iso, unsigned char * buffer, int type, int number, long size) {
unsigned char sector[2352];
int i, n, reste;
@@ -211,6 +299,28 @@ void read_datas(FILE * f_iso, unsigned char * buffer, int type, int number, long
}
}
+void read_datas(int f_iso, unsigned char * buffer, int type, int number, long size) {
+ unsigned char sector[2352];
+ int i, n, reste;
+
+ if (type == GUESS) {
+ type = guess_type(f_iso, number);
+ }
+
+ n = size / sec_sizes[type];
+ reste = size - n * sec_sizes[type];
+
+ sector_seek(f_iso, number);
+ for (i = 0; i < n; i++) {
+ read_sector(f_iso, buffer + i * sec_sizes[type], type);
+ }
+
+ if (reste) {
+ read_sector(f_iso, sector, type);
+ bcopy((char *) sector, (char *) (buffer + n * sec_sizes[type]), reste);
+ }
+}
+
void read_file(FILE * f_iso, FILE * file, char type, int number, long size) {
unsigned char sector[2352];
int i, n, reste;
@@ -234,6 +344,29 @@ void read_file(FILE * f_iso, FILE * file, char type, int number, long size) {
}
}
+void read_file(int f_iso, int file, char type, int number, long size) {
+ unsigned char sector[2352];
+ int i, n, reste;
+
+ if (type == GUESS) {
+ type = guess_type(f_iso, number);
+ }
+
+ n = size / sec_sizes[type];
+ reste = size - n * sec_sizes[type];
+
+ sector_seek(f_iso, number);
+ for (i = 0; i < n; i++) {
+ read_sector(f_iso, sector, type);
+ write(file, sector, sec_sizes[type]);
+ }
+
+ if (reste) {
+ read_sector(f_iso, sector, type);
+ write(file, sector, reste);
+ }
+}
+
void write_sector(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number) {
unsigned char old_sector[2352], new_sector[2352];
@@ -256,13 +389,42 @@ void write_sector(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char t
bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]);
do_encode_L2(new_sector, type, 0);
- if (ppf_file < 0) {
+ if (!ppf_file) {
fwrite(new_sector, 1, 2352, f_iso_w);
} else {
write_ppf(old_sector, new_sector, number);
}
}
+void write_sector(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number) {
+ unsigned char old_sector[2352], new_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);
+ }
+
+ read(f_iso_r, old_sector, 2352);
+
+ minute = old_sector[12];
+ second = old_sector[13];
+ frame = old_sector[14];
+
+ bcopy((char *) old_sector, (char *) new_sector, 2532);
+ bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]);
+
+ do_encode_L2(new_sector, type, 0);
+ if (!ppf_file) {
+ write(f_iso_w, new_sector, 2352);
+ } else {
+ write_ppf(old_sector, new_sector, number);
+ }
+}
+
void write_datas(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number, long size) {
long nbsectors, i;
unsigned char sector[2352];
@@ -289,6 +451,32 @@ void write_datas(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char ty
}
}
+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) {
long size, nbsectors, i;
unsigned char buffer[2352];
@@ -316,6 +504,33 @@ void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int numb
}
}
+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]);
+ write_sector(f_iso_r, f_iso_w, buffer, type);
+ }
+}
+
void show_head_entry(void) {
printm(M_BARE, "Sector - Size - Date - Time - Flags - Name\n");
}
@@ -356,6 +571,26 @@ 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;
@@ -385,6 +620,35 @@ struct DirEntry find_dir_entry(FILE * f_iso, struct DirEntry * dir, char * name)
return r;
}
+struct DirEntry find_dir_entry(int 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(FILE * f_iso, unsigned char ** bufout, struct DirEntry * dir, char * name) {
unsigned int ptr, size;
unsigned char * buffer;
@@ -419,6 +683,40 @@ 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];
char pbuff[130];
@@ -491,6 +789,78 @@ 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) {
unsigned char buffer[2048];
char pbuff[130];
@@ -519,6 +889,34 @@ 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;
@@ -575,6 +973,35 @@ 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};
@@ -602,6 +1029,33 @@ struct DirEntry find_path(FILE * f_iso, char * path) {
return dir;
}
+struct DirEntry find_path(int 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_parent(FILE * f_iso, char * path) {
char ** pts, * p;
struct DirEntry dir = {0, 0, 0, 0, 0};
@@ -636,3 +1090,38 @@ struct DirEntry find_parent(FILE * f_iso, char * path) {
return dir;
}
+
+struct DirEntry find_parent(int 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))
+ 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;
+}
diff --git a/cdutils.h b/cdutils.h
index 6ae1620..af899b9 100644
--- a/cdutils.h
+++ b/cdutils.h
@@ -54,27 +54,45 @@ extern long sec_offsts[];
extern char * sec_modes[];
FILE * open_ppf(char * ppf, FILE * iso, char * comment);
+FILE * open_ppf(char * ppf, int iso, char * comment);
unsigned short int swap_word(unsigned short int i);
unsigned long int swap_dword(unsigned long int i);
int guess_type(FILE * f_iso, int number);
+int guess_type(int f_iso, int number);
void sector_seek(FILE * f_iso, long sector);
+void sector_seek(int f_iso, long sector);
long read_sector(FILE * f_iso, unsigned char * buffer, char type, int number = -1);
+long read_sector(int f_iso, unsigned char * buffer, char type, int number = -1);
void read_datas(FILE * f_iso, unsigned char * buffer, int type, int number, long size);
+void read_datas(int f_iso, unsigned char * buffer, int type, int number, long size);
void read_file(FILE * f_iso, FILE * file, char type, int number, long size);
+void read_file(int f_iso, int file, char type, int number, long size);
void write_sector(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number = -1);
+void write_sector(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number = -1);
void write_datas(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number, long size);
+void write_datas(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number, long size);
void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int number = -1);
+void write_file(int f_iso_r, int f_iso_w, int file, char type, int number = -1);
int get_iso_infos(FILE * h);
+int get_iso_infos(int h);
int show_iso_infos(FILE * h);
+int show_iso_infos(int h);
int get_pt_infos(FILE * h);
+int get_pt_infos(int h);
int show_pt_infos(FILE * h);
+int show_pt_infos(int h);
struct DirEntry find_path(FILE * h, char * path);
+struct DirEntry find_path(int h, char * path);
struct DirEntry find_parent(FILE * h, char * path);
+struct DirEntry find_parent(int h, char * path);
void show_head_entry(void);
int show_entry(struct DirEntry * dir);
int show_dir(FILE * h, struct DirEntry * dir);
+int show_dir(int h, struct DirEntry * dir);
struct DirEntry find_dir_entry(FILE * h, struct DirEntry * dir, char * name);
+struct DirEntry find_dir_entry(int h, struct DirEntry * dir, char * name);
struct DirEntry * find_dir_entry(FILE * h, unsigned char ** buffer, struct DirEntry * dir, char * name);
+struct DirEntry * find_dir_entry(int h, unsigned char ** buffer, struct DirEntry * dir, char * name);
unsigned char from_BCD(unsigned char x);
unsigned char to_BCD(unsigned char x);
int is_valid_BCD(unsigned char x);
diff --git a/fileutils.cpp b/fileutils.cpp
index 62e2c0b..b04a414 100644
--- a/fileutils.cpp
+++ b/fileutils.cpp
@@ -21,8 +21,33 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include "generic.h"
+unsigned long filesize(int f_iso)
+{
+ long curpos, length;
+
+ curpos = lseek(f_iso, 0, SEEK_CUR);
+ length = lseek(f_iso, 0, SEEK_END);
+ lseek(f_iso, curpos, SEEK_SET);
+ return length;
+}
+
+void copy(int s, int d, long size) {
+ long i;
+ unsigned char c;
+ long r;
+
+ for (i = 0; (i < size) || (size < 0); i++) {
+ r = read(s, &c, 1);
+ if (r == 0) {
+ break;
+ }
+ write(d, &c, 1);
+ }
+}
+
unsigned long filesize(FILE * f_iso)
{
long curpos, length;
diff --git a/fileutils.h b/fileutils.h
index 071da66..a552477 100644
--- a/fileutils.h
+++ b/fileutils.h
@@ -25,6 +25,9 @@
#include <sys/types.h>
#include <fcntl.h>
+unsigned long filesize(int f_iso);
+void copy(int s, int d, long size = -1);
+
unsigned long filesize(FILE * f_iso);
void copy(FILE * s, FILE * d, long size = -1);