From 9be56ad8481cdf7e892289bb41af13e4e4aa4dda Mon Sep 17 00:00:00 2001 From: szaka Date: Sun, 23 Oct 2005 14:00:37 +0000 Subject: [PATCH] ntfscat can display named attributes, streams too --- ChangeLog | 1 + ntfsprogs/ntfscat.8.in | 31 +++++++++++++--------- ntfsprogs/ntfscat.c | 60 ++++++++++++++++++++++++------------------ ntfsprogs/ntfscat.h | 2 ++ 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 751192a3..7550e059 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,7 @@ xx/xx/2005 - 1.12.2-WIP - ntfsmount: Add 'streams_interface=' option to select named data streams access interface. Currently supported interfaces are 'none' and 'windows'. (Yura) + - ntfscat can display named attributes, streams too. (Szaka) 10/10/2005 - 1.12.1 - Minor fix to location of mount.ntfs-fuse and mkfs.ntfs. diff --git a/ntfsprogs/ntfscat.8.in b/ntfsprogs/ntfscat.8.in index 253e4e34..038d07e3 100644 --- a/ntfsprogs/ntfscat.8.in +++ b/ntfsprogs/ntfscat.8.in @@ -2,9 +2,9 @@ .\" Copyright (c) 2003 Richard Russon. All Rights Reserved. .\" This file may be copied under the terms of the GNU Public License. .\" -.TH NTFSCAT 8 "October 2003" "ntfsprogs version @VERSION@" +.TH NTFSCAT 8 "October 2005" "ntfsprogs version @VERSION@" .SH NAME -ntfscat \- concatenate files and print them on the standard output +ntfscat \- print NTFS files and streams on the standard output .SH SYNOPSIS .B ntfscat [ @@ -13,7 +13,8 @@ ntfscat \- concatenate files and print them on the standard output .B device file .SH DESCRIPTION .B ntfscat -will read a file from an NTFS volume and display the contents on the standard output. +will read a file or stream from an NTFS volume and display the contents +on the standard output. .PP The case of the filename passed to .B ntfscat @@ -32,14 +33,14 @@ is equivalent to .BR "\-f \-v" . Long named options can be abbreviated to any unique prefix of their name. .TP -.B "\-a " desc +.B "\-a " type .br .ns .TP -.B "\-\-attribute " desc -Display the contents of a particular attribute. By default, the unname $DATA -attribute will be shown. The attribute can be specified by number (in decimal -or hexadecimal), or by name. +.B "\-\-attribute " type +Display the contents of a particular attribute type. By default, the unnamed +$DATA attribute will be shown. The attribute can be specified by a number +in decimal or hexadecimal, or by name. .TS lB lB lB l l l. @@ -68,6 +69,13 @@ The attribute names may be given without the leading $ symbol. .br If you use the $ symbol, you must escape it from the shell. .TP +.B "\-n " name +.br +.ns +.TP +.B "\-\-attribute-name " name +Display this named attribute, stream. +.TP .B "\-i " num .br .ns @@ -122,10 +130,9 @@ Display the contents of the $INDEX_ROOT attribute of the root directory (inode .sp .B ntfscat /dev/hda1 \-a INDEX_ROOT \-i 5 | hexdump \-C .RE -.SH BUGS -.B ntfscat -was written in a short time, to get something "out there". It needs a lot more work. -If you find any bugs, please send an email to +.SH KNOWN ISSUES +There are no known problems. If you think you had found any then +please report it to .nh .hy diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index 1964fa25..2a939279 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -3,6 +3,7 @@ * * Copyright (c) 2003-2005 Richard Russon * Copyright (c) 2003-2005 Anton Altaparmakov + * Copyright (c) 2003-2005 Szabolcs Szakacsits * * This utility will concatenate files and print on the standard output. * @@ -80,16 +81,15 @@ static void version (void) static void usage (void) { Printf ("\nUsage: %s [options] device [file]\n\n" - " -a, --attribute desc Display this attribute (name or number)\n" - " -i, --inode num Display this inode\n\n" - " -f --force Use less caution\n" - " -h --help Print this help\n" - " -q --quiet Less output\n" - " -V --version Version information\n" - " -v --verbose More output\n\n", - //" -N --name Display this attribute name", - //" -F --file Display this file", - //" -r --raw Display the compressed or encrypted file", + " -a, --attribute type Display this attribute type\n" + " -n, --attribute-name name Display this attribute name\n" + " -i, --inode num Display this inode\n\n" + " -f --force Use less caution\n" + " -h --help Print this help\n" + " -q --quiet Less output\n" + " -V --version Version information\n" + " -v --verbose More output\n\n", + //" -r --raw Display the compressed or encrypted file", EXEC_NAME); Printf ("%s%s\n", ntfs_bugs, ntfs_home); } @@ -159,18 +159,17 @@ static int parse_attribute (const char *value, ATTR_TYPES *attr) */ static int parse_options (int argc, char **argv) { - static const char *sopt = "-a:fh?i:qVv"; // F:N: + static const char *sopt = "-a:fh?i:n:qVv"; static const struct option lopt[] = { - { "attribute", required_argument, NULL, 'a' }, - { "force", no_argument, NULL, 'f' }, - { "help", no_argument, NULL, 'h' }, - { "inode", required_argument, NULL, 'i' }, - { "quiet", no_argument, NULL, 'q' }, - { "version", no_argument, NULL, 'V' }, - { "verbose", no_argument, NULL, 'v' }, - // { "file", required_argument, NULL, 'F' }, - // { "name", required_argument, NULL, 'N' }, - { NULL, 0, NULL, 0 } + { "attribute", required_argument, NULL, 'a' }, + { "attribute-name", required_argument, NULL, 'n' }, + { "force", no_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { "inode", required_argument, NULL, 'i' }, + { "quiet", no_argument, NULL, 'q' }, + { "version", no_argument, NULL, 'V' }, + { "verbose", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } }; char c = -1; @@ -183,6 +182,8 @@ static int parse_options (int argc, char **argv) opts.inode = -1; opts.attr = -1; + opts.attr_name = NULL; + opts.attr_name_len = 0; while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) { switch (c) { @@ -223,6 +224,16 @@ static int parse_options (int argc, char **argv) Eprintf("Couldn't parse inode number.\n"); err++; break; + + case 'n': + opts.attr_name_len = ntfs_mbstoucs(optarg, + &opts.attr_name, 0); + if (opts.attr_name_len < 0) { + Eprintf("Invalid attribute name '%s': %s\n", + optarg, strerror(errno)); + usage(); + } + case 'q': opts.quiet++; break; @@ -298,8 +309,7 @@ static int index_get_size (ntfs_inode *inode) * cat */ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type, - ntfschar *name __attribute__((unused)), - int namelen __attribute__((unused))) + ntfschar *name, int namelen) { const int bufsize = 4096; char *buffer; @@ -312,7 +322,7 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type, if (!buffer) return 1; - attr = ntfs_attr_open (inode, type, NULL, 0); + attr = ntfs_attr_open (inode, type, name, namelen); if (!attr) { Eprintf ("Cannot find attribute type 0x%lx.\n", (long) type); free (buffer); @@ -396,7 +406,7 @@ int main (int argc, char *argv[]) if (opts.attr != (ATTR_TYPES)-1) attr = opts.attr; - result = cat (vol, inode, attr, NULL, 0); + result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); ntfs_inode_close (inode); ntfs_umount (vol, FALSE); diff --git a/ntfsprogs/ntfscat.h b/ntfsprogs/ntfscat.h index a69df80c..75b2b068 100644 --- a/ntfsprogs/ntfscat.h +++ b/ntfsprogs/ntfscat.h @@ -33,6 +33,8 @@ struct options { char *file; /* File to display */ s64 inode; /* Inode to work with */ ATTR_TYPES attr; /* Attribute type to display */ + ntfschar *attr_name; /* Attribute name to display */ + int attr_name_len; /* Attribute name length */ int force; /* Override common sense */ int quiet; /* Less output */ int verbose; /* Extra output */