1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
* ntdump.c
*
* Copyright (C) 1995-1997 Martin von Lwis
* Copyright (C) 1997 Rgis Duchesne
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "types.h"
#include "struct.h"
#include "util.h"
#include "super.h"
#include "nttools.h"
#include "inode.h"
#include "dump.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#define getopt_long(a,v,o,ol,x) getopt(a,v,o)
#endif
#include <unistd.h>
char *short_opts="vrdf:o:c:Mi:ID:B:A:N:nhV";
#ifdef HAVE_GETOPT_H
struct option options[]={
{"raw",0,0,'r'},
{"filesystem",1,0,'f'},
{"offset",1,0,'o'},
{"cluster",1,0,'c'},
{"mft",0,0,'M'},
{"inode",1,0,'i'},
{"dir",0,0,'d'},
{"info",0,0,'I'},
{"decompress",1,0,'D'},
{"verbose",0,0,'v'},
{"bias",1,0,'B'},
{"attribute-type",1,0,'A'},
{"attribute-name",1,0,'N'},
{"linode",0,0,'n'},
{"help",0,0,'h'},
{"version",0,0,'V'},
{0,0,0,0}
};
#endif
void usage(void)
{
fprintf(stderr,"ntdump: prints low-level structures of an NTFS\n"
" --filesystem, -f device Use device\n"
" --raw, -r Access the raw device\n"
" --offset, -o n Start at offset o\n"
" --cluster, -c n Start at cluster n\n"
" --mft, -M Display as master file table record\n"
" --inode, -i n Display inode n\n"
" --dir, -d Display as directory\n"
" --info, -I Display file system information\n"
" --decompress, -D n Decompress run n\n"
" --bias, -B n Add partition bias n [bytes]\n"
" --attribute-type, -A n Dump type n\n"
" --attribute-name, -N str Dump attribute named str\n"
" --verbose, -v decompress verbose\n"
" --linode, -n show internal inode representation\n"
" --version, -V print version number\n"
);
}
int main(int argc,char *argv[])
{
int c,with_ino,error;
int raw=0,as_mft=0,as_dir=0,inode=0,use_ino=0,get_info=0,cluster=0;
int decompress=0,verbose=0,bias=0,as_inode=0;
int attribute_type=0x80; /* DATA */
char *attribute_name=0;
char *device=0;
ntfs_size_t offset=0;
ntfs_volume *volume;
extern int optind,opterr;
extern char *optarg;
opterr=1;
while((c=getopt_long(argc,argv,short_opts,options,NULL))>0)
switch(c)
{
case 'r': raw=1;break;
case 'f': device=optarg;break;
case 'o': offset=strtol(optarg,NULL,0);break;
case 'c': cluster=strtol(optarg,NULL,0);break;
case 'M': as_mft=1;break;
case 'i': inode=strtol(optarg,NULL,0);use_ino=1;break;
case 'd': as_dir=1;break;
case 'I': get_info=1;break;
case 'D': decompress=1;offset=strtol(optarg,NULL,0);break;
case 'v': verbose=1;break;
case 'B': bias=strtol(optarg,NULL,0);break;
case 'A': attribute_type=strtol(optarg,NULL,0);break;
case 'N': attribute_name=optarg;break;
case 'n': as_inode=1;break;
case 'V': printf("ntdump " NTFS_VERSION "\n");exit(0);break;
default:
usage();
exit(1);
}
with_ino = use_ino || get_info;
volume=ntfs_open_volume(device,bias,0,!with_ino);
if(!volume && !raw)return 1;
if(cluster)
offset=volume->clustersize*cluster;
if(use_ino){
ntfs_inode ino;
ntfs_init_inode(&ino,volume,inode);
if(as_mft){
list_attr_mem(volume,ino.attr);
return 0;
}
if(as_dir){
dumpdir(&ino);
return 0;
}
if(as_inode){
dump_inode(&ino);
return 0;
}
if(decompress){
dump_decompress(&ino,offset,verbose);
return 0;
}
while(1)
{
char buf[4096];
ntfs_io io;
io.fn_put=ntfs_put;
io.fn_get=0;
io.param=buf;
io.size=volume->clustersize;
error=ntfs_read_attr(&ino,attribute_type,
attribute_name,offset,&io);
if(error)return 0;
dump_mem(buf,offset,volume->clustersize);
offset+=io.size;
if(io.size<volume->clustersize)return 0;
}
return 0;
}
if(raw)
{
dump(volume,offset+bias,offset,-1);
}else if(as_mft)
{
list_attributes(volume,offset);
}else if(get_info)
{
printf("Blocksize: %x\nClustersize: %x\nMFT size: %x\n",
volume->blocksize,volume->clustersize,
volume->mft_recordsize);
printf("Total clusters: %d\n",ntfs_get_volumesize(volume));
printf("Free clusters: %d\n",
ntfs_get_free_cluster_count(volume->bitmap));
}else{
usage();
}
return 0;
}
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
|