mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-01-21 18:48:34 +08:00
add MDBPATH search
fix segfault in mdb-tables
This commit is contained in:
10
TODO
10
TODO
@@ -3,7 +3,7 @@ Things to Do
|
|||||||
|
|
||||||
file format:
|
file format:
|
||||||
|
|
||||||
. how does global allocation map work?
|
. how does global allocation map work? (done)
|
||||||
. export VBA script
|
. export VBA script
|
||||||
. re-examine KKD records for form design (OLE streams?)
|
. re-examine KKD records for form design (OLE streams?)
|
||||||
. write support
|
. write support
|
||||||
@@ -17,8 +17,7 @@ libmdb:
|
|||||||
. Sargs need to support all datatypes
|
. Sargs need to support all datatypes
|
||||||
. Need a way to express logical relationships between sargs (tree)
|
. Need a way to express logical relationships between sargs (tree)
|
||||||
. Add support for index scanning when using sargs
|
. Add support for index scanning when using sargs
|
||||||
. Use allocation maps to read tables, should be more efficient (done
|
. Use allocation maps to read tables, should be more efficient (done)
|
||||||
if -DFAST_READ specified)
|
|
||||||
. write support
|
. write support
|
||||||
|
|
||||||
utils:
|
utils:
|
||||||
@@ -45,6 +44,7 @@ ODBC:
|
|||||||
GMDB:
|
GMDB:
|
||||||
|
|
||||||
. Finish debug dissectors
|
. Finish debug dissectors
|
||||||
. Export schema not implemented
|
. Export schema not implemented (done)
|
||||||
. Printing not implemented
|
. Printing not implemented
|
||||||
. Export needs finishing
|
. Export needs finishing (done)
|
||||||
|
. Fix bitmask size bug in debugger
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
AC_INIT(src/extras/mdb-dump.c)
|
AC_INIT(src/extras/mdb-dump.c)
|
||||||
AM_INIT_AUTOMAKE(mdbtools,0.4)
|
AM_INIT_AUTOMAKE(mdbtools,0.5)
|
||||||
|
|
||||||
AC_PROG_CC(gcc)
|
AC_PROG_CC(gcc)
|
||||||
dnl Checks for programs.
|
dnl Checks for programs.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ OPTIONS
|
|||||||
-H Supress header row.
|
-H Supress header row.
|
||||||
-F Supress footer row.
|
-F Supress footer row.
|
||||||
-p Turn off pretty printing. By default results are printed in an
|
-p Turn off pretty printing. By default results are printed in an
|
||||||
ascii table format which looks nice but is not condusive to manipulating the
|
ascii table format which looks nice but is not conducive to manipulating the
|
||||||
output with unix tools. This option prints output plainly in a tab separated
|
output with unix tools. This option prints output plainly in a tab separated
|
||||||
format.
|
format.
|
||||||
-d Specify an alternative column delimiter. If no delimiter is
|
-d Specify an alternative column delimiter. If no delimiter is
|
||||||
@@ -43,7 +43,7 @@ SQL LANGUAGE
|
|||||||
|
|
||||||
column list: <column> [, <column list>]
|
column list: <column> [, <column list>]
|
||||||
|
|
||||||
where clause: <column> <operator> <literal> [AND <where clause>]
|
where clause: <column> <operator> <literal> [AND <where clause>]
|
||||||
|
|
||||||
operator: =, =>, =<, <>, like, <, >
|
operator: =, =>, =<, <>, like, <, >
|
||||||
|
|
||||||
|
|||||||
@@ -27,36 +27,89 @@ MdbFormatConstants MdbJet3Constants = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static size_t _mdb_read_pg(MdbHandle *mdb, unsigned char *pg_buf, unsigned long pg);
|
static size_t _mdb_read_pg(MdbHandle *mdb, unsigned char *pg_buf, unsigned long pg);
|
||||||
|
static int mdb_find_file(char *file_name, char *file_path, int bufsize)
|
||||||
|
{
|
||||||
|
struct stat status;
|
||||||
|
gchar *s, *mdbpath;
|
||||||
|
gchar *dir, *tmpfname;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* try the provided file name first */
|
||||||
|
if (!stat(file_name, &status)) {
|
||||||
|
if (strlen(file_name)> bufsize)
|
||||||
|
return strlen(file_name);
|
||||||
|
strcpy(file_path, file_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now pull apart $MDBPATH and try those */
|
||||||
|
s = (gchar *) getenv("MDBPATH");
|
||||||
|
if (!s || !strlen(s)) return -1; /* no path, can't find file */
|
||||||
|
|
||||||
|
mdbpath = g_strdup(s);
|
||||||
|
dir = strtok(mdbpath,":");
|
||||||
|
do {
|
||||||
|
tmpfname = (gchar *) g_malloc(strlen(dir)+strlen(file_name)+2);
|
||||||
|
strcpy(tmpfname, dir);
|
||||||
|
if (dir[strlen(dir)-1]!='/') strcat(tmpfname, "/");
|
||||||
|
strcat(tmpfname, file_name);
|
||||||
|
if (!stat(tmpfname, &status)) {
|
||||||
|
if (strlen(tmpfname)> bufsize) {
|
||||||
|
ret = strlen(tmpfname);
|
||||||
|
g_free(tmpfname);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
strcpy(file_path, tmpfname);
|
||||||
|
g_free(tmpfname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
g_free(tmpfname);
|
||||||
|
} while (dir = strtok(NULL, ":"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
MdbHandle *_mdb_open(char *filename, gboolean writable)
|
MdbHandle *_mdb_open(char *filename, gboolean writable)
|
||||||
{
|
{
|
||||||
MdbHandle *mdb;
|
MdbHandle *mdb;
|
||||||
int key[] = {0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13, 0xb6};
|
int key[] = {0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13, 0xb6};
|
||||||
int j,pos;
|
int j,pos;
|
||||||
|
int bufsize;
|
||||||
|
MdbFile *f;
|
||||||
|
|
||||||
mdb = mdb_alloc_handle();
|
mdb = mdb_alloc_handle();
|
||||||
/* need something to bootstrap with, reassign after page 0 is read */
|
/* need something to bootstrap with, reassign after page 0 is read */
|
||||||
mdb->fmt = &MdbJet3Constants;
|
mdb->fmt = &MdbJet3Constants;
|
||||||
mdb->f = mdb_alloc_file();
|
mdb->f = mdb_alloc_file();
|
||||||
mdb->f->filename = (char *) malloc(strlen(filename)+1);
|
f = mdb->f;
|
||||||
strcpy(mdb->f->filename, filename);
|
f->filename = (char *) malloc(strlen(filename)+1);
|
||||||
|
bufsize = strlen(filename)+1;
|
||||||
|
bufsize = mdb_find_file(filename, f->filename, bufsize);
|
||||||
|
if (bufsize) {
|
||||||
|
f->filename = (char *) realloc(f->filename, bufsize+1);
|
||||||
|
bufsize = mdb_find_file(filename, f->filename, bufsize);
|
||||||
|
if (bufsize) {
|
||||||
|
fprintf(stderr, "Can't alloc filename\n");
|
||||||
|
mdb_free_handle(mdb);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//strcpy(f->filename, filename);
|
||||||
if (writable) {
|
if (writable) {
|
||||||
mdb->f->writable = TRUE;
|
f->writable = TRUE;
|
||||||
mdb->f->fd = open(filename,O_RDWR);
|
f->fd = open(f->filename,O_RDWR);
|
||||||
} else {
|
} else {
|
||||||
mdb->f->fd = open(filename,O_RDONLY);
|
f->fd = open(f->filename,O_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mdb->f->fd==-1) {
|
if (f->fd==-1) {
|
||||||
/* fprintf(stderr,"Couldn't open file %s\n",filename); */
|
fprintf(stderr,"Couldn't open file %s\n",f->filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mdb->f->refs++;
|
f->refs++;
|
||||||
if (!mdb_read_pg(mdb, 0)) {
|
if (!mdb_read_pg(mdb, 0)) {
|
||||||
fprintf(stderr,"Couldn't read first page.\n");
|
fprintf(stderr,"Couldn't read first page.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mdb->f->jet_version = mdb_get_int32(mdb, 0x14);
|
f->jet_version = mdb_get_int32(mdb, 0x14);
|
||||||
if (IS_JET4(mdb)) {
|
if (IS_JET4(mdb)) {
|
||||||
mdb->fmt = &MdbJet4Constants;
|
mdb->fmt = &MdbJet4Constants;
|
||||||
} else {
|
} else {
|
||||||
@@ -64,8 +117,8 @@ int j,pos;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get the db encryption key and xor it back to clear text */
|
/* get the db encryption key and xor it back to clear text */
|
||||||
mdb->f->db_key = mdb_get_int32(mdb, 0x3e);
|
f->db_key = mdb_get_int32(mdb, 0x3e);
|
||||||
mdb->f->db_key ^= 0xe15e01b9;
|
f->db_key ^= 0xe15e01b9;
|
||||||
|
|
||||||
|
|
||||||
/* get the db password located at 0x42 bytes into the file */
|
/* get the db password located at 0x42 bytes into the file */
|
||||||
@@ -73,9 +126,9 @@ int j,pos;
|
|||||||
j = mdb_get_int32(mdb,0x42+pos);
|
j = mdb_get_int32(mdb,0x42+pos);
|
||||||
j ^= key[pos];
|
j ^= key[pos];
|
||||||
if ( j != 0)
|
if ( j != 0)
|
||||||
mdb->f->db_passwd[pos] = j;
|
f->db_passwd[pos] = j;
|
||||||
else
|
else
|
||||||
mdb->f->db_passwd[pos] = '\0';
|
f->db_passwd[pos] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return mdb;
|
return mdb;
|
||||||
|
|||||||
@@ -56,7 +56,11 @@ int opt;
|
|||||||
mdb_init();
|
mdb_init();
|
||||||
|
|
||||||
/* open the database */
|
/* open the database */
|
||||||
mdb = mdb_open (argv[optind]);
|
if (!(mdb = mdb_open (argv[optind]))) {
|
||||||
|
fprintf(stderr,"Couldn't open database.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* read the catalog */
|
/* read the catalog */
|
||||||
mdb_read_catalog (mdb, MDB_TABLE);
|
mdb_read_catalog (mdb, MDB_TABLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user