mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
changed mdb_read_catalog() to scan the file for catalog pages.
This commit is contained in:
parent
f9afc55877
commit
5710389374
@ -17,11 +17,18 @@ int main(int argc, char **argv)
|
||||
int j;
|
||||
unsigned char data[17];
|
||||
FILE *in;
|
||||
int length;
|
||||
int length;
|
||||
int pg=0;
|
||||
char addr[10];
|
||||
|
||||
in = fopen(argv[1],"r");
|
||||
while (length = fread(data,1,16,in)) {
|
||||
fprintf(stdout, "%06x ", i);
|
||||
sprintf(addr, "%06x", i);
|
||||
if (!strcmp(&addr[3],"000") || ! strcmp(&addr[3],"800")) {
|
||||
fprintf(stdout,"-- Page 0x%04x (%d) --\n", pg, pg);
|
||||
pg++;
|
||||
}
|
||||
fprintf(stdout,"%s ", addr);
|
||||
i+=length;
|
||||
|
||||
for(j=0; j<length; j++) {
|
||||
|
@ -56,7 +56,7 @@ int i,j;
|
||||
/*
|
||||
** ??? this happens, don't know what it means
|
||||
*/
|
||||
if (offset & 0xF000) return NULL;
|
||||
if (offset & 0xF000) offset &= ~0xF000;
|
||||
|
||||
/*
|
||||
for (j=offset;j<offset+32;j++)
|
||||
@ -90,17 +90,58 @@ int i;
|
||||
int rows;
|
||||
MdbCatalogEntry entry;
|
||||
gpointer data;
|
||||
int next_pg, next_pg_off;
|
||||
|
||||
mdb_read_pg(mdb, MDB_CATALOG_PG);
|
||||
rows = mdb_catalog_rows(mdb);
|
||||
/*
|
||||
** We are doing it the brute force way, since I can't make sense of the page
|
||||
** linkage on catalog pages. What I know (or think I know) is this: some row
|
||||
** offsets in the row offset table (that list of offsets at the begining of
|
||||
** the page) that the high order nibble of 0x4. The offset then represents
|
||||
** the location of a page pointer to another catalog page, however not all
|
||||
** catalog pages are linked in this manner.
|
||||
**
|
||||
** So, we simply read the entire mdb file for pages that start 0x01 0x01 and
|
||||
** have a 32bit value of 2 (02 00 00 00) in bytes 4-7.
|
||||
*/
|
||||
#if 0
|
||||
next_pg = MDB_CATALOG_PG;
|
||||
mdb_free_catalog(mdb);
|
||||
for (i=0;i<rows;i++) {
|
||||
if (mdb_catalog_entry(mdb, i, &entry)) {
|
||||
data = g_memdup(&entry,sizeof(MdbCatalogEntry));
|
||||
mdb->catalog = g_list_append(mdb->catalog, data);
|
||||
|
||||
while (next_pg) {
|
||||
mdb_read_pg(mdb, next_pg);
|
||||
next_pg = 0;
|
||||
rows = mdb_catalog_rows(mdb);
|
||||
for (i=0;i<rows;i++) {
|
||||
if (mdb->pg_buf[11 + 2 * i] & 0x40) {
|
||||
next_pg_off = mdb_get_int16(mdb, 10 + 2 * i) & 0x0FFF;
|
||||
next_pg = mdb_get_int16(mdb, next_pg_off+1);
|
||||
fprintf(stdout,"YES! next pg = %04x %d\n",next_pg, next_pg);
|
||||
continue;
|
||||
}
|
||||
if (mdb_catalog_entry(mdb, i, &entry)) {
|
||||
data = g_memdup(&entry,sizeof(MdbCatalogEntry));
|
||||
mdb->catalog = g_list_append(mdb->catalog, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (mdb->catalog);
|
||||
#endif
|
||||
next_pg=0;
|
||||
while (mdb_read_pg(mdb,next_pg)) {
|
||||
if (mdb->pg_buf[0]==0x01 &&
|
||||
mdb->pg_buf[1]==0x01 &&
|
||||
mdb_get_int32(mdb,4)==2) {
|
||||
rows = mdb_catalog_rows(mdb);
|
||||
for (i=0;i<rows;i++) {
|
||||
if (mdb->pg_buf[11 + 2 * i] & 0x40) continue;
|
||||
if (mdb_catalog_entry(mdb, i, &entry)) {
|
||||
data = g_memdup(&entry,sizeof(MdbCatalogEntry));
|
||||
mdb->catalog = g_list_append(mdb->catalog, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
next_pg++;
|
||||
}
|
||||
}
|
||||
void mdb_dump_catalog(MdbHandle *mdb, int obj_type)
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ struct stat status;
|
||||
return 0;
|
||||
}
|
||||
else if (len<MDB_PGSIZE) {
|
||||
fprintf(stderr,"EOF reached.\n");
|
||||
/* fprintf(stderr,"EOF reached.\n"); */
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
|
Loading…
Reference in New Issue
Block a user