Imported Upstream version 3.7.7+git20160511.4fd23a
Joao Eriberto Mota Filho
8 years ago
29 | 29 | |
30 | 30 | - raw or "dd" |
31 | 31 | - splitraw (in which a single image is split between mulitple files) |
32 | - EnCase or "E01" format | |
33 | 32 | - AFF format (in which the entire disk image is stored in a single file.) |
34 | 33 | - AFD format (in which a disk image is stored in mulitple AFF files |
35 | 34 | stored in a single directory.) |
80 | 80 | |
81 | 81 | |
82 | 82 | # Specific headers that I plan to use |
83 | AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h dmalloc.h err.h errno.h fcntl.h getopt.h inttypes.h linux/fs.h malloc.h netinet/in.h regex.h signal.h stdint.h stdio.h stdlib.h string.h sys/cdefs.h sys/disk.h sys/file.h sys/ioctl.h sys/ioctl.h sys/param.h sys/param.h sys/socket.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/vfs.h sysexits.h term.h time.h unistd.h zlib.h _mingw.h]) | |
83 | AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h dmalloc.h err.h errno.h fcntl.h getopt.h inttypes.h linux/fs.h malloc.h netinet/in.h regex.h signal.h stdint.h stdio.h stdlib.h string.h sys/cdefs.h sys/disk.h sys/file.h sys/ioctl.h sys/ioctl.h sys/param.h sys/param.h sys/socket.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/vfs.h sysexits.h time.h unistd.h zlib.h _mingw.h]) | |
84 | 84 | |
85 | 85 | AC_CHECK_LIB([regex],[regcomp]) # see if we need -lregex |
86 | 86 | |
112 | 112 | ################################################################ |
113 | 113 | # For AFF tools |
114 | 114 | AC_CHECK_HEADERS([readline/readline.h]) |
115 | AC_CHECK_HEADERS([curses.h termcap.h]) | |
116 | 115 | AC_CHECK_LIB([readline],[readline],, AC_MSG_RESULT([readline not installed])) |
117 | 116 | AC_CHECK_LIB([z],[uncompress],, AC_MSG_ERROR([zlib not installed; cannot continue. Try adding zlib-dev or zlib1g-dev.])) |
118 | 117 | AC_CHECK_LIB([rt],[aio_error64]) |
119 | AC_SEARCH_LIBS(tgetent, termlib termcap curses) | |
120 | AC_CHECK_FUNCS(putp tputs tgoto tgetstr tgetnum gotorc beep endwin setupterm printw) | |
121 | 118 | |
122 | 119 | ################################################################ |
123 | 120 | ## Expat |
49 | 49 | uint32_t name_len = ntohl(segh.name_len); |
50 | 50 | uint32_t datasize = ntohl(segh.data_len); |
51 | 51 | if(name_len>AF_MAX_NAME_LEN){ |
52 | snprintf(af->error_str,sizeof(af->error_str),"afflib: name_len=%"PRIu32" (an outrageous value)",name_len); | |
52 | snprintf(af->error_str,sizeof(af->error_str),"afflib: name_len=%" PRIu32 " (an outrageous value)",name_len); | |
53 | 53 | return AF_ERROR_NAME; |
54 | 54 | } |
55 | 55 |
28 | 28 | printf("AF DIRECTORY:\n"); |
29 | 29 | for(int i=0;i<af->toc_count;i++){ |
30 | 30 | if(af->toc[i].name){ |
31 | printf("%-32s @%"I64u" len: %"I64u" \n",af->toc[i].name, af->toc[i].offset,af->toc[i].segment_len); | |
31 | printf("%-32s @%" I64u " len: %" I64u " \n",af->toc[i].name, af->toc[i].offset,af->toc[i].segment_len); | |
32 | 32 | } |
33 | 33 | } |
34 | 34 | } |
454 | 454 | uint64_t af_seek(AFFILE *af,int64_t pos,int whence) |
455 | 455 | { |
456 | 456 | AF_WRLOCK(af); |
457 | if(af_trace) fprintf(af_trace,"af_seek(%p,%"I64d",%d)\n",af,pos,whence); | |
457 | if(af_trace) fprintf(af_trace,"af_seek(%p,%" I64d ",%d)\n",af,pos,whence); | |
458 | 458 | uint64_t new_pos=0; |
459 | 459 | switch(whence){ |
460 | 460 | case SEEK_SET: |
787 | 787 | int af_update_segf(AFFILE *af, const char *segname, |
788 | 788 | uint32_t arg,const u_char *data,uint32_t datalen,uint32_t flag) |
789 | 789 | { |
790 | if(af_trace) fprintf(af_trace,"af_update_segf(%p,segname=%s,arg=%"PRIu32",datalen=%d)\n", | |
790 | if(af_trace) fprintf(af_trace,"af_update_segf(%p,segname=%s,arg=%" PRIu32 ",datalen=%d)\n", | |
791 | 791 | af,segname,arg,datalen); |
792 | 792 | AF_WRLOCK(af); |
793 | 793 | if(af->v->update_seg==0){ |
953 | 953 | { |
954 | 954 | AF_READLOCK(af); |
955 | 955 | fprintf(f,"AFSTATS for %s\n",af_filename(af)); |
956 | fprintf(f,"Pages read: %"I64u"\n",af->pages_read); | |
957 | fprintf(f,"Pages written: %"I64u"\n",af->pages_written); | |
958 | fprintf(f,"Pages compressed: %"I64u"\n",af->pages_compressed); | |
959 | fprintf(f,"Pages decompressed: %"I64u"\n",af->pages_decompressed); | |
960 | fprintf(f,"Cache hits: %"I64u"\n",af->cache_hits); | |
961 | fprintf(f,"Cache misses: %"I64u"\n",af->cache_misses); | |
962 | fprintf(f,"Bytes copied: %"I64u"\n",af->bytes_memcpy); | |
956 | fprintf(f,"Pages read: %" I64u "\n",af->pages_read); | |
957 | fprintf(f,"Pages written: %" I64u "\n",af->pages_written); | |
958 | fprintf(f,"Pages compressed: %" I64u "\n",af->pages_compressed); | |
959 | fprintf(f,"Pages decompressed: %" I64u "\n",af->pages_decompressed); | |
960 | fprintf(f,"Cache hits: %" I64u "\n",af->cache_hits); | |
961 | fprintf(f,"Cache misses: %" I64u "\n",af->cache_misses); | |
962 | fprintf(f,"Bytes copied: %" I64u "\n",af->bytes_memcpy); | |
963 | 963 | AF_UNLOCK(af); |
964 | 964 | } |
965 | 965 |
405 | 405 | #define AF_SECTORSIZE "sectorsize" // in bytes, stored in arg |
406 | 406 | #define AF_DEVICE_SECTORS "devicesectors"// stored as a 64-bit number |
407 | 407 | #define AF_BADFLAG "badflag" // data used to mark a bad sector |
408 | #define AF_PAGE "page%"I64d // segment flag indicates compression (replaces seg%d) | |
408 | #define AF_PAGE "page%" I64d // segment flag indicates compression (replaces seg%d) | |
409 | 409 | #define AF_PAGE_MD5 AF_PAGE"_md5" // md5 hash of page |
410 | 410 | #define AF_PAGE_SHA1 AF_PAGE"_sha1" // sha1 hash of page |
411 | 411 | #define AF_PAGE_SHA256 AF_PAGE"_sha256"// sha256 hash of page |
427 | 427 | #define AF_BOM_SEG "affbom%d" |
428 | 428 | |
429 | 429 | /* Deprecated terminology; pages were originally called data segments */ |
430 | #define AF_SEG_D "seg%"I64d // segment flag indicates compression (deprecated) | |
430 | #define AF_SEG_D "seg%" I64d // segment flag indicates compression (deprecated) | |
431 | 431 | #define AF_SEGSIZE_D "segsize" // segment data size (deprecated) |
432 | 432 | |
433 | 433 | /* Bill of Materials */ |
167 | 167 | size_t page_len=0; |
168 | 168 | |
169 | 169 | if (af_trace){ |
170 | fprintf(af_trace,"af_get_page(%p,pagenum=%"I64d",buf=%p,bytes=%u)\n",af,pagenum,data,(int)*bytes); | |
170 | fprintf(af_trace,"af_get_page(%p,pagenum=%" I64d ",buf=%p,bytes=%u)\n",af,pagenum,data,(int)*bytes); | |
171 | 171 | } |
172 | 172 | |
173 | 173 | /* Find out the size of the segment and if it is compressed or not. |
246 | 246 | case Z_OK: |
247 | 247 | break; |
248 | 248 | case Z_ERRNO: |
249 | (*af->error_reporter)("Z_ERRNOR decompressing segment %"I64d,pagenum); | |
249 | (*af->error_reporter)("Z_ERRNOR decompressing segment %" I64d,pagenum); | |
250 | 250 | case Z_STREAM_ERROR: |
251 | (*af->error_reporter)("Z_STREAM_ERROR decompressing segment %"I64d,pagenum); | |
251 | (*af->error_reporter)("Z_STREAM_ERROR decompressing segment %" I64d,pagenum); | |
252 | 252 | case Z_DATA_ERROR: |
253 | (*af->error_reporter)("Z_DATA_ERROR decompressing segment %"I64d,pagenum); | |
253 | (*af->error_reporter)("Z_DATA_ERROR decompressing segment %" I64d,pagenum); | |
254 | 254 | case Z_MEM_ERROR: |
255 | (*af->error_reporter)("Z_MEM_ERROR decompressing segment %"I64d,pagenum); | |
255 | (*af->error_reporter)("Z_MEM_ERROR decompressing segment %" I64d,pagenum); | |
256 | 256 | case Z_BUF_ERROR: |
257 | (*af->error_reporter)("Z_BUF_ERROR decompressing segment %"I64d,pagenum); | |
257 | (*af->error_reporter)("Z_BUF_ERROR decompressing segment %" I64d,pagenum); | |
258 | 258 | case Z_VERSION_ERROR: |
259 | (*af->error_reporter)("Z_VERSION_ERROR decompressing segment %"I64d,pagenum); | |
259 | (*af->error_reporter)("Z_VERSION_ERROR decompressing segment %" I64d,pagenum); | |
260 | 260 | default: |
261 | 261 | (*af->error_reporter)("uncompress returned an invalid value in get_segment"); |
262 | 262 | } |
265 | 265 | #ifdef USE_LZMA |
266 | 266 | case AF_PAGE_COMP_ALG_LZMA: |
267 | 267 | res = lzma_uncompress(data,bytes,compressed_data,compressed_data_len); |
268 | if (af_trace) fprintf(af_trace," LZMA decompressed page %"I64d". %d bytes => %u bytes\n", | |
268 | if (af_trace) fprintf(af_trace," LZMA decompressed page %" I64d ". %d bytes => %u bytes\n", | |
269 | 269 | pagenum,(int)compressed_data_len,(int)*bytes); |
270 | 270 | switch(res){ |
271 | 271 | case 0:break; // OK |
272 | case 1:(*af->error_reporter)("LZMA header error decompressing segment %"I64d"\n",pagenum); | |
272 | case 1:(*af->error_reporter)("LZMA header error decompressing segment %" I64d "\n",pagenum); | |
273 | 273 | break; |
274 | case 2:(*af->error_reporter)("LZMA memory error decompressing segment %"I64d"\n",pagenum); | |
274 | case 2:(*af->error_reporter)("LZMA memory error decompressing segment %" I64d "\n",pagenum); | |
275 | 275 | break; |
276 | 276 | } |
277 | 277 | break; |
552 | 552 | ret = -1; // got an error; keep going, though |
553 | 553 | } |
554 | 554 | p->pagebuf_dirty = 0; |
555 | if(af_trace) fprintf(af_trace,"af_cache_flush: slot %d page %"PRIu64" flushed.\n",i,p->pagenum); | |
555 | if(af_trace) fprintf(af_trace,"af_cache_flush: slot %d page %" PRIu64 " flushed.\n",i,p->pagenum); | |
556 | 556 | } |
557 | 557 | } |
558 | 558 | return ret; // now return the error that I might have gotten |
569 | 569 | struct aff_pagebuf *p = &af->pbcache[i]; |
570 | 570 | if(p->pagenum_valid && p->pagenum == pagenum){ |
571 | 571 | if(p->pagebuf_dirty){ |
572 | (*af->error_reporter)("af_cache_writethrough: overwriting page %"I64u".\n",pagenum); | |
572 | (*af->error_reporter)("af_cache_writethrough: overwriting page %" I64u ".\n",pagenum); | |
573 | 573 | exit(-1); // this shouldn't happen |
574 | 574 | } |
575 | 575 | memcpy(p->pagebuf,buf,bufflen); |
592 | 592 | |
593 | 593 | struct aff_pagebuf *af_cache_alloc(AFFILE *af,int64_t pagenum) |
594 | 594 | { |
595 | if(af_trace) fprintf(af_trace,"af_cache_alloc(%p,%"I64d")\n",af,pagenum); | |
595 | if(af_trace) fprintf(af_trace,"af_cache_alloc(%p,%" I64d ")\n",af,pagenum); | |
596 | 596 | |
597 | 597 | /* Make sure nothing in the cache is dirty */ |
598 | 598 | if(af_cache_flush(af) < 0) |
603 | 603 | struct aff_pagebuf *p = &af->pbcache[i]; |
604 | 604 | if(p->pagenum_valid && p->pagenum==pagenum){ |
605 | 605 | af->cache_hits++; |
606 | if(af_trace) fprintf(af_trace," page %"I64d" satisfied fromcache\n",pagenum); | |
606 | if(af_trace) fprintf(af_trace," page %" I64d " satisfied fromcache\n",pagenum); | |
607 | 607 | p->last = cachetime++; |
608 | 608 | return p; |
609 | 609 | } |
616 | 616 | struct aff_pagebuf *p = &af->pbcache[i]; |
617 | 617 | if(p->pagenum_valid==0){ |
618 | 618 | slot = i; |
619 | if(af_trace) fprintf(af_trace," slot %d given to page %"I64d"\n",slot,pagenum); | |
619 | if(af_trace) fprintf(af_trace," slot %d given to page %" I64d "\n",slot,pagenum); | |
620 | 620 | break; |
621 | 621 | } |
622 | 622 | } |
631 | 631 | } |
632 | 632 | } |
633 | 633 | slot = oldest_i; |
634 | if(af_trace) fprintf(af_trace," slot %d assigned to page %"I64d"\n",slot,pagenum); | |
634 | if(af_trace) fprintf(af_trace," slot %d assigned to page %" I64d "\n",slot,pagenum); | |
635 | 635 | } |
636 | 636 | /* take over this slot */ |
637 | 637 | struct aff_pagebuf *p = &af->pbcache[slot]; |
655 | 655 | if(af_trace){ |
656 | 656 | fprintf(af_trace," current pages in cache: "); |
657 | 657 | for(int i=0;i<af->num_pbufs;i++){ |
658 | fprintf(af_trace," %"I64d,af->pbcache[i].pagenum); | |
658 | fprintf(af_trace," %" I64d,af->pbcache[i].pagenum); | |
659 | 659 | } |
660 | 660 | fprintf(af_trace,"\n"); |
661 | 661 | } |
28 | 28 | { |
29 | 29 | AF_WRLOCK(af); |
30 | 30 | if(af->image_size>0){ |
31 | (*af->error_reporter)("Cannot set maxsize as imagesize is already set (%"I64d")",af->image_size); | |
31 | (*af->error_reporter)("Cannot set maxsize as imagesize is already set (%" I64d ")",af->image_size); | |
32 | 32 | AF_UNLOCK(af); |
33 | 33 | return -1; // now allowed to set if imagesize is bigger than 0 |
34 | 34 | } |
35 | 35 | if((af->image_pagesize!=0) |
36 | 36 | && (af->v->type & AF_VNODE_MAXSIZE_MULTIPLE) |
37 | 37 | && (maxsize % af->image_pagesize != 0)){ |
38 | (*af->error_reporter)("Cannot set maxsize to %"I64d" --- not multiple of pagesize=%d\n", | |
38 | (*af->error_reporter)("Cannot set maxsize to %" I64d " --- not multiple of pagesize=%d\n", | |
39 | 39 | maxsize,af->image_pagesize); |
40 | 40 | AF_UNLOCK(af); |
41 | 41 | return -1; |
82 | 82 | int total = 0; |
83 | 83 | |
84 | 84 | AF_WRLOCK(af); // wrlock because cache may change |
85 | if (af_trace) fprintf(af_trace,"af_read(%p,%p,%d) (pos=%"I64d")\n",af,buf,(int)count,af->pos); | |
85 | if (af_trace) fprintf(af_trace,"af_read(%p,%p,%d) (pos=%" I64d ")\n",af,buf,(int)count,af->pos); | |
86 | 86 | if (af->v->read){ // check for bypass |
87 | 87 | int r = (af->v->read)(af, buf, af->pos, count); |
88 | 88 | if(r>0) af->pos += r; |
161 | 161 | { |
162 | 162 | AF_WRLOCK(af); |
163 | 163 | if (af_trace){ |
164 | fprintf(af_trace,"af_write(af=%p,buf=%p,count=%d) pos=%"I64d"\n", af,buf,(int)count,af->pos); | |
164 | fprintf(af_trace,"af_write(af=%p,buf=%p,count=%d) pos=%" I64d "\n", af,buf,(int)count,af->pos); | |
165 | 165 | } |
166 | 166 | /* Invalidate caches */ |
167 | 167 | af_invalidate_vni_cache(af); |
763 | 763 | uint32_t siglen = sizeof(sig); |
764 | 764 | |
765 | 765 | BIO *bp = BIO_new_file("signing_key.pem","r"); |
766 | if (!bp) { | |
767 | perror("BIO_new_file"); | |
768 | return; | |
769 | } | |
766 | 770 | |
767 | 771 | EVP_MD_CTX md; |
768 | 772 | EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bp,0,0,0); |
773 | 777 | |
774 | 778 | /* let's try to verify it */ |
775 | 779 | bp = BIO_new_file("signing_cert.pem","r"); |
780 | if (!bp) { | |
781 | perror("BIO_new_file"); | |
782 | return; | |
783 | } | |
784 | ||
776 | 785 | X509 *x = 0; |
777 | 786 | PEM_read_bio_X509(bp,&x,0,0); |
778 | 787 | EVP_PKEY *pubkey = X509_get_pubkey(x); |
110 | 110 | |
111 | 111 | int aff_write_seg(AFFILE *af, const char *segname,uint32_t arg,const u_char *data,size_t datalen) |
112 | 112 | { |
113 | if(af_trace) fprintf(af_trace,"aff_write_seg(%p,%s,%"PRIu32",%p,len=%u)\n", | |
113 | if(af_trace) fprintf(af_trace,"aff_write_seg(%p,%s,%" PRIu32 ",%p,len=%u)\n", | |
114 | 114 | af,segname,arg,data,(int)datalen); |
115 | 115 | |
116 | 116 | struct af_segment_head segh; |
140 | 140 | aff_toc_update(af,segname,ftello(af->aseg),datalen); |
141 | 141 | |
142 | 142 | |
143 | if(af_trace) fprintf(af_trace,"aff_write_seg: putting segment %s (datalen=%d) offset=%"PRId64"\n", | |
143 | if(af_trace) fprintf(af_trace,"aff_write_seg: putting segment %s (datalen=%d) offset=%" PRId64 "\n", | |
144 | 144 | segname,(int)datalen,ftello(af->aseg)); |
145 | 145 | |
146 | 146 | if(fwrite(&segh,sizeof(segh),1,af->aseg)!=1) return -10; |
306 | 306 | return AF_ERROR_TAIL; |
307 | 307 | } |
308 | 308 | if(stl != calculated_segment_len){ |
309 | snprintf(af->error_str,sizeof(af->error_str),"af_get_next_segv: AF file corrupt (%"PRIu32"!=%"PRIu32")/!", | |
309 | snprintf(af->error_str,sizeof(af->error_str),"af_get_next_segv: AF file corrupt (%" PRIu32 "!=%" PRIu32 ")/!", | |
310 | 310 | stl,calculated_segment_len); |
311 | 311 | fseeko(af->aseg,start,SEEK_SET); // go back to last good position |
312 | 312 | return AF_ERROR_TAIL; |
362 | 362 | size_t size_needed = vallen+aff_segment_overhead(name); |
363 | 363 | struct aff_toc_mem *adm = aff_toc(af,name); |
364 | 364 | |
365 | if(af_trace) fprintf(af_trace,"aff_update_seg(name=%s,arg=%"PRIu32",vallen=%u)\n",name,arg,vallen); | |
365 | if(af_trace) fprintf(af_trace,"aff_update_seg(name=%s,arg=%" PRIu32 ",vallen=%u)\n",name,arg,vallen); | |
366 | 366 | |
367 | 367 | if(adm) |
368 | 368 | { |
186 | 186 | return -1; |
187 | 187 | } |
188 | 188 | if (af->maxsize % af->image_pagesize) { |
189 | (*af->error_reporter)("afm_split_raw_setup: maxsize (%"I64d") " | |
189 | (*af->error_reporter)("afm_split_raw_setup: maxsize (%" I64d ") " | |
190 | 190 | "not a multiple of image_pagesize (%d)\n", |
191 | 191 | af->maxsize,af->image_pagesize); |
192 | 192 | return -1; |
211 | 211 | */ |
212 | 212 | if (ap->aff->image_size && ap->aff->image_size != ap->sr->image_size) { |
213 | 213 | (*af->error_reporter)("afm_split_raw_setup: internal error. " |
214 | "AFF image_size %"I64d" != SR image_size %"I64d"\n", | |
214 | "AFF image_size %" I64d " != SR image_size %" I64d "\n", | |
215 | 215 | ap->aff->image_size,ap->sr->image_size); |
216 | 216 | return -1; |
217 | 217 | } |
224 | 224 | /* Verify that the parameters make sense */ |
225 | 225 | if (ap->sr->maxsize != (pages_per_file * af->image_pagesize) && pages_per_file>0) { |
226 | 226 | (*af->error_reporter)("afm_split_raw_setup: %s: per size indicated by metadata (%d * %d) " |
227 | "doesn't match maxsize (%"I64d")\n", | |
227 | "doesn't match maxsize (%" I64d ")\n", | |
228 | 228 | af_filename(af),pages_per_file,af->image_pagesize,ap->sr->maxsize); |
229 | 229 | return -1; |
230 | 230 | } |
168 | 168 | { |
169 | 169 | struct split_raw_private *srp = SPLIT_RAW_PRIVATE(af); |
170 | 170 | for(uint32_t i=0;i<srp->num_raw_files;i++){ |
171 | fprintf(stderr," fds[%d]=%d pos[%d]=%"I64d"\n",i,srp->fds[i],i,srp->pos[i]); | |
171 | fprintf(stderr," fds[%d]=%d pos[%d]=%" I64d "\n",i,srp->fds[i],i,srp->pos[i]); | |
172 | 172 | } |
173 | 173 | srp_validate(af); |
174 | 174 | fprintf(stderr,"===================\n"); |
286 | 286 | af->image_pagesize *= 2; |
287 | 287 | |
288 | 288 | if ((ret == 0) && (af->maxsize % af->image_pagesize!=0)) { |
289 | (*af->error_reporter)("split_raw_open: %s: raw_file_size (%"I64d" not a multiple of pagesize %lu\n", | |
289 | (*af->error_reporter)("split_raw_open: %s: raw_file_size (%" I64d " not a multiple of pagesize %lu\n", | |
290 | 290 | af->fname, af->maxsize,af->image_pagesize); |
291 | 291 | split_raw_close (af); |
292 | 292 | return -1; |
416 | 416 | for(int i = 0; i < _length; i++) |
417 | 417 | if (s.Find(_chars[i]) >= 0) |
418 | 418 | return i; |
419 | return -1; | |
419 | return -1; | |
420 | 420 | } |
421 | 421 | |
422 | 422 | void TrimLeft(T c) |
177 | 177 | for(int i = 0; i < Size(); i++) |
178 | 178 | if (item == (*this)[i]) |
179 | 179 | return i; |
180 | return -1; | |
180 | return -1; | |
181 | 181 | } |
182 | 182 | int FindInSorted(const T& item) const |
183 | 183 | { |
27 | 27 | .IP "-n" |
28 | 28 | Noisy mode. Tell when pages are skipped. |
29 | 29 | .IP "-l" |
30 | List all the segment names, rather than outputing data. | |
30 | List all the segment names, rather than outputting data. | |
31 | 31 | .IP "-L" |
32 | 32 | List Long. Prints segment names, lengths, and args. |
33 | 33 | .IP "-d" |
77 | 77 | .TP |
78 | 78 | .B |
79 | 79 | \fB-r\fP |
80 | Force raw output. | |
80 | Generate raw output. | |
81 | 81 | .RE |
82 | 82 | .PP |
83 | 83 | Dangerous input \fIoptions\fP: |
103 | 103 | |
104 | 104 | .fam T |
105 | 105 | .fi |
106 | Convert file1.aff to file1.raw: | |
107 | .PP | |
108 | .nf | |
109 | .fam C | |
110 | $ affconvert -r file1.aff | |
111 | ||
112 | .fam T | |
113 | .fi | |
106 | 114 | Batch convert \fIfiles\fP: |
107 | 115 | .PP |
108 | 116 | .nf |
109 | 117 | .fam C |
110 | 118 | $ affconvert file1.raw file2.raw file3.raw |
119 | ||
120 | .fam T | |
121 | .fi | |
122 | .PP | |
123 | .nf | |
124 | .fam C | |
125 | $ affconvert -r file1.aff file2.aff file3.aff | |
111 | 126 | |
112 | 127 | .fam T |
113 | 128 | .fi |
12 | 12 | * United States Government and/or for any works created by United |
13 | 13 | * States Government employees. User acknowledges that this software |
14 | 14 | * contains work which was created by NPS employee(s) and is therefore |
15 | * in the public domain and not subject to copyright. | |
15 | * in the public domain and not subject to copyright. | |
16 | 16 | * -------------------------------------------------------------------- |
17 | 17 | * |
18 | 18 | * Change History: |
96 | 96 | while(notes){ |
97 | 97 | char buf2[1024]; |
98 | 98 | char *val=0; |
99 | ||
99 | ||
100 | 100 | #ifdef HAVE_LIBREADLINE |
101 | 101 | if(isatty(fileno(stdin))){ |
102 | 102 | val = readline(""); |
119 | 119 | int aff_bom::read_files(const char *cert_file,const char *key_file) |
120 | 120 | { |
121 | 121 | BIO *bp_cert = BIO_new_file(cert_file,"r"); // read the certfile |
122 | if (!bp_cert) | |
123 | return -1; | |
122 | 124 | PEM_read_bio_X509(bp_cert,&cert,0,0); // get an x509 cert |
123 | 125 | BIO_free(bp_cert); |
124 | 126 | if(!cert) return -1; // can't read certificate file |
125 | ||
127 | ||
126 | 128 | /* Now read the private key */ |
127 | 129 | BIO *bp_privkey = BIO_new_file(key_file,"r"); |
128 | 130 | privkey = PEM_read_bio_PrivateKey(bp_privkey,0,0,0); |
132 | 134 | cert = 0; |
133 | 135 | return -1; |
134 | 136 | } |
135 | ||
137 | ||
136 | 138 | bom_open = true; |
137 | 139 | xml = BIO_new(BIO_s_mem()); // where we are writing |
138 | 140 | time_t clock = time(0); |
139 | 141 | struct tm *tm = localtime(&clock); |
140 | 142 | char timebuf[1024]; |
141 | 143 | strftime(timebuf,sizeof(timebuf),"<date type='ISO 8601'>%FT%T</date>",tm); |
142 | ||
144 | ||
143 | 145 | BIO_printf(xml,"<%s version=\"1\">\n",AF_XML_AFFBOM); |
144 | 146 | BIO_printf(xml," %s\n",timebuf); |
145 | 147 | BIO_printf(xml," <program>afcopy</program>\n"); |
184 | 186 | size_t xlen = BIO_get_mem_data(xml,&xbuf); |
185 | 187 | unsigned char sig[1024]; |
186 | 188 | u_int siglen = sizeof(sig); |
187 | ||
189 | ||
188 | 190 | EVP_MD_CTX md; |
189 | 191 | EVP_SignInit(&md,sha256); |
190 | 192 | EVP_SignUpdate(&md,xbuf,xlen); |
191 | 193 | EVP_SignFinal(&md,sig,&siglen,privkey); |
192 | ||
194 | ||
193 | 195 | /* Write the signature in base64 encoding... */ |
194 | 196 | BIO *b64 = BIO_new(BIO_f_base64()); |
195 | 197 | xml = BIO_push(b64,xml); |
196 | 198 | BIO_write(xml,sig,siglen); |
197 | 199 | if(BIO_flush(xml)!=1) return; // something wrong |
198 | ||
200 | ||
199 | 201 | /* Remove the base64 bio */ |
200 | 202 | xml = BIO_pop(b64); |
201 | 203 | } |
236 | 238 | size_t datalen = 0; |
237 | 239 | if(af_get_seg(af,segname,0,0,&datalen)<0) return -1; |
238 | 240 | uint32_t arg; |
239 | u_char *segdata = (u_char *)malloc(datalen);/* Allocate memory */ | |
240 | if(segdata<0) return -1; | |
241 | u_char *segdata = (u_char *)malloc(datalen); | |
242 | if(!segdata) return -1; | |
241 | 243 | if(af_get_seg(af,segname,&arg,segdata,&datalen)<0){ |
242 | 244 | free(segdata); |
243 | 245 | return -1; |
247 | 249 | add(segname,AF_SIGNATURE_MODE0,seghash,sizeof(seghash)); |
248 | 250 | free(segdata); |
249 | 251 | return(0); |
250 | ||
252 | ||
251 | 253 | } |
252 | 254 | |
253 | 255 |
60 | 60 | { |
61 | 61 | fprintf(stderr,"affcat "); |
62 | 62 | if(current_fname) fprintf(stderr,"%s: ",current_fname); |
63 | if(current_page>=0) fprintf(stderr,"[%"PRId64"] ",current_page); | |
63 | if(current_page>=0) fprintf(stderr,"[%" PRId64 "] ",current_page); | |
64 | 64 | fflush(stderr); |
65 | 65 | } |
66 | 66 | |
98 | 98 | int bytes = af_read(af,buf,af->image_pagesize); // read what we can |
99 | 99 | |
100 | 100 | if(bytes<0){ |
101 | if(opt_debug) fprintf(stderr,"affcat: cannot read page %"I64d"\n",pagenum); | |
101 | if(opt_debug) fprintf(stderr,"affcat: cannot read page %" I64d "\n",pagenum); | |
102 | 102 | return -1; |
103 | 103 | } |
104 | 104 | |
105 | 105 | if(opt_debug){ |
106 | fprintf(stderr,"affcat: page:%"I64d" bytes: %d offset:%"I64d"\n", | |
106 | fprintf(stderr,"affcat: page:%" I64d" bytes: %d offset:%" I64d "\n", | |
107 | 107 | pagenum, bytes,offset); |
108 | 108 | } |
109 | 109 | |
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | if(opt_debug) fprintf(stderr," outputing %d bytes\n",bytes); | |
119 | if(opt_debug) fprintf(stderr," outputting %d bytes\n",bytes); | |
120 | 120 | int count = fwrite(buf,1,bytes,outfile); // send to the output |
121 | 121 | if(count!=bytes) fprintf(stderr,"fwrite(buf,1,%d,outfile) only wrote %d bytes\n",bytes,count); |
122 | 122 | free(buf); |
195 | 195 | const char *opt = opts.c_str(); |
196 | 196 | uint64_t offset=0; |
197 | 197 | int count=0; |
198 | if(sscanf(opt,"%"I64u":%d",&offset,&count)!=2){ | |
198 | if(sscanf(opt,"%" I64u ":%d",&offset,&count)!=2){ | |
199 | 199 | err(1,"Cannot decode '%s'\n",opt); |
200 | 200 | } |
201 | 201 | af_seek(af,offset,SEEK_SET); |
226 | 226 | if(opt_list){ |
227 | 227 | printf("%s",segname); |
228 | 228 | if(opt_list_long){ |
229 | printf("\targ:%"PRIu32"\tlen:%d",arg,(int)datalen); | |
229 | printf("\targ:%" PRIu32 "\tlen:%d",arg,(int)datalen); | |
230 | 230 | } |
231 | 231 | putchar('\n'); |
232 | 232 | } |
269 | 269 | |
270 | 270 | //fprintf(stderr,"bytes written=%qd imagesize=%qd\n",total_bytes_written,imagesize); |
271 | 271 | if((total_bytes_written > imagesize) && (imagesize>0)){ |
272 | err(1,"affcat internal error. bytes written=%"I64d" imagesize=%" I64d, | |
272 | err(1,"affcat internal error. bytes written=%" I64d " imagesize=%" I64d, | |
273 | 273 | (int64_t)total_bytes_written, |
274 | 274 | (int64_t)imagesize); |
275 | 275 | return -1; |
283 | 283 | { |
284 | 284 | int64_t r=0; |
285 | 285 | char ch; |
286 | if(sscanf(buf,"%"I64d"%c",&r,&ch)==1) return r; | |
286 | if(sscanf(buf,"%" I64d "%c",&r,&ch)==1) return r; | |
287 | 287 | fprintf(stderr,"Cannot parse '%s'\n",buf); |
288 | 288 | exit(0); |
289 | 289 | } |
152 | 152 | void print_info(char dir,const char *segname,uint32_t arg,size_t len, |
153 | 153 | unsigned char *data,int mcr) |
154 | 154 | { |
155 | printf(" %c %s arg=%"PRIu32" len=%d\n",dir,segname,arg,(int)len); | |
155 | printf(" %c %s arg=%" PRIu32 " len=%d\n",dir,segname,arg,(int)len); | |
156 | 156 | printf(" "); |
157 | 157 | if((arg == AF_SEG_QUADWORD) && (len==8)){ |
158 | printf("data=%"I64d" as a 64-bit value\n",af_decode_q(data)); | |
158 | printf("data=%" I64d " as a 64-bit value\n",af_decode_q(data)); | |
159 | 159 | return; |
160 | 160 | } |
161 | 161 | /* Otherwise, just print some stuff... */ |
289 | 289 | |
290 | 290 | /* Find the size of each page, then get the page */ |
291 | 291 | if(af_get_page(af1,pagenum,0,&data1_len)<0) |
292 | err(1,"Cannot read page %"I64d" size from %s\n",pagenum,af_filename(af1)); | |
292 | err(1,"Cannot read page %" I64d " size from %s\n",pagenum,af_filename(af1)); | |
293 | 293 | if(af_get_page(af1,pagenum,data1,&data1_len)<0) |
294 | err(1,"Cannot read page %"I64d" from %s",pagenum,af_filename(af1)); | |
294 | err(1,"Cannot read page %" I64d " from %s",pagenum,af_filename(af1)); | |
295 | 295 | |
296 | 296 | if(af_get_page(af2,pagenum,0,&data2_len)<0) |
297 | err(1,"Cannot read page %"I64d" size from %s\n",pagenum,af_filename(af2)); | |
297 | err(1,"Cannot read page %" I64d " size from %s\n",pagenum,af_filename(af2)); | |
298 | 298 | if(af_get_page(af2,pagenum,data2,&data2_len)<0) |
299 | err(1,"Cannot read page %"I64d" from %s",pagenum,af_filename(af2)); | |
299 | err(1,"Cannot read page %" I64d " from %s",pagenum,af_filename(af2)); | |
300 | 300 | |
301 | 301 | if(data1_len != data2_len){ |
302 | printf("page %"I64d" size %d != size %d\n",pagenum,(int)data1_len,(int)data2_len); | |
302 | printf("page %" I64d " size %d != size %d\n",pagenum,(int)data1_len,(int)data2_len); | |
303 | 303 | return 1; |
304 | 304 | } |
305 | 305 | |
340 | 340 | outline[0] = 0; |
341 | 341 | if(opt_all || (no_match>0) || af1_bad || af2_bad){ |
342 | 342 | snprintf(outline,sizeof(outline), |
343 | " page%"I64d" sectors:%4d matching: %3d different:%3d", | |
343 | " page%" I64d " sectors:%4d matching: %3d different:%3d", | |
344 | 344 | pagenum,total_sectors,matching_sectors,no_match); |
345 | 345 | } |
346 | 346 | if(af1_bad){ |
372 | 372 | if(i==0){ |
373 | 373 | printf("\n "); |
374 | 374 | } |
375 | printf(" %"I64d,*j); | |
375 | printf(" %" I64d,*j); | |
376 | 376 | i = (i+1) % 10; |
377 | 377 | } |
378 | 378 | putchar('\n'); |
390 | 390 | memcpy(b2,data1+offset,16); |
391 | 391 | b2[15]=0; |
392 | 392 | |
393 | printf("=== sector %"I64d" (offset=%d) ===\n",*j,offset); | |
393 | printf("=== sector %" I64d " (offset=%d) ===\n",*j,offset); | |
394 | 394 | printf(" %s:\n",af_filename(af1)); |
395 | 395 | print_sector(af1,data1+offset); |
396 | 396 | printf("-------------------------------------\n"); |
428 | 428 | size_t len1,len2; |
429 | 429 | |
430 | 430 | if(af_get_page_raw(af1,*i,&arg1,0,&len1)){ |
431 | err(1,"Could not read page %"I64d" in file %s\n",*i,af_filename(af1)); | |
431 | err(1,"Could not read page %" I64d " in file %s\n",*i,af_filename(af1)); | |
432 | 432 | } |
433 | 433 | if(af_get_page_raw(af2,*i,&arg2,0,&len2)){ |
434 | err(1,"Page %"I64d" is in file %s but not in %s\n",*i,af_filename(af1), | |
434 | err(1,"Page %" I64d " is in file %s but not in %s\n",*i,af_filename(af1), | |
435 | 435 | af_filename(af2)); |
436 | 436 | } |
437 | 437 | if(arg1==arg2 && len1==len2){ |
449 | 449 | continue; |
450 | 450 | } |
451 | 451 | } |
452 | printf("%s -> %s Nochg: %d NUL: %d LZMA: %d old: %"I64d" new: %"I64d" LZred: %6.2f%%\n", | |
452 | printf("%s -> %s Nochg: %d NUL: %d LZMA: %d old: %" I64d " new: %" I64d " LZred: %6.2f%%\n", | |
453 | 453 | af_filename(af1), |
454 | 454 | af_filename(af2), |
455 | 455 | comp_unchanged,comp_zero,comp_lzma,bytes_old,bytes_new,(bytes_old-bytes_new)*100.0/bytes_old); |
491 | 491 | if(af1->image_pagesize != af2->image_pagesize){ |
492 | 492 | fprintf(stderr,"Currently, %s requires that both images have the " |
493 | 493 | "same image datsegsize.\n" |
494 | " pagesize(%s)=%"PRIu32"\n" | |
495 | " pagesize(%s)=%"PRIu32"\n", | |
494 | " pagesize(%s)=%" PRIu32 "\n" | |
495 | " pagesize(%s)=%" PRIu32 "\n", | |
496 | 496 | progname,file1,af1->image_pagesize, file2,af2->image_pagesize); |
497 | 497 | fprintf(stderr,"Data segments will be ignored.\n"); |
498 | 498 | no_data_segments = true; |
501 | 501 | if(af1->image_sectorsize != af2->image_sectorsize){ |
502 | 502 | fprintf(stderr,"Currently, %s requires that both images have the " |
503 | 503 | "same image sectorsize.\n" |
504 | " sectorsize(%s)=%"PRIu32"\n" | |
505 | " sectorsize(%s)=%"PRIu32"\n", | |
504 | " sectorsize(%s)=%" PRIu32 "\n" | |
505 | " sectorsize(%s)=%" PRIu32 "\n", | |
506 | 506 | progname,file1,af1->image_sectorsize, file2,af2->image_sectorsize); |
507 | 507 | fprintf(stderr,"Data segments will be ignored.\n"); |
508 | 508 | no_data_segments = true; |
20 | 20 | #ifdef WIN32 |
21 | 21 | #include "unix4win32.h" |
22 | 22 | #endif |
23 | ||
24 | #ifdef HAVE_CURSES_H | |
25 | #include <curses.h> | |
26 | #endif | |
27 | ||
28 | #ifdef HAVE_TERM_H | |
29 | #include <term.h> | |
30 | #endif | |
31 | ||
32 | 23 | |
33 | 24 | #ifdef HAVE_SYS_TIME_H |
34 | 25 | #include <sys/time.h> |
422 | 413 | |
423 | 414 | int64_t pagenum = *i; |
424 | 415 | |
425 | if(!opt_quiet) printf("Converting page %"I64d" of %"I64d"\r",pagenum,highest_pagenum);fflush(stdout); | |
416 | if(!opt_quiet) { printf("Converting page %" I64d " of %" I64d "\r",pagenum,highest_pagenum); fflush(stdout); } | |
426 | 417 | |
427 | 418 | size_t data_len = image_pagesize; |
428 | 419 | if(af_get_page(a_in,pagenum,data,&data_len)){ |
429 | err(1,"af_get_page(file=%s,page=%"I64d")", | |
420 | err(1,"af_get_page(file=%s,page=%" I64d ")", | |
430 | 421 | af_filename(a_in),pagenum); |
431 | 422 | } |
432 | 423 | if(af_update_page(a_out,pagenum,data,data_len)){ |
433 | err(1,"af_update_page(file=%s,page=%"I64d")", | |
424 | err(1,"af_update_page(file=%s,page=%" I64d ")", | |
434 | 425 | af_filename(a_out),pagenum); |
435 | 426 | } |
436 | 427 | |
447 | 438 | /* Go back and update the image size (necessary since I have been writing page-by-page) */ |
448 | 439 | if(af_update_segq(a_out,AF_IMAGESIZE,last_byte_in_image) |
449 | 440 | && errno!=ENOTSUP){ |
450 | err(1,"Could not upate AF_IMAGESIZE"); | |
441 | err(1,"Could not update AF_IMAGESIZE"); | |
451 | 442 | } |
452 | 443 | } else { |
453 | 444 | /* No page support; Copy from beginning to end */ |
498 | 489 | |
499 | 490 | /* Finish the hash calculations and write to the db */ |
500 | 491 | if(!opt_quiet){ |
501 | printf("bytes converted: %"I64d" \n",total_bytes_converted); | |
492 | printf("bytes converted: %" I64d " \n",total_bytes_converted); | |
502 | 493 | /* If the vnode implementation tracked segments written, report it. */ |
503 | 494 | if(a_out->pages_written || a_out->pages_compressed){ |
504 | printf("Total pages: %"I64u" (%"I64u" compressed)\n", | |
495 | printf("Total pages: %" I64u " (%" I64u " compressed)\n", | |
505 | 496 | a_out->pages_written,a_out->pages_compressed); |
506 | 497 | } |
507 | 498 | } |
551 | 542 | int64_t atoi64(const char *buf) |
552 | 543 | { |
553 | 544 | int64_t r=0; |
554 | sscanf(buf,"%"I64d,&r); | |
545 | sscanf(buf,"%" I64d,&r); | |
555 | 546 | return r; |
556 | 547 | } |
557 | 548 |
36 | 36 | |
37 | 37 | #ifdef HAVE_UNISTD_H |
38 | 38 | #include <unistd.h> |
39 | #endif | |
40 | ||
41 | #ifdef HAVE_TERM_H | |
42 | #include <term.h> | |
43 | 39 | #endif |
44 | 40 | |
45 | 41 | #ifdef WIN32 |
468 | 464 | AFFILE *af = afouts.begin()->af; |
469 | 465 | uint64_t w = af->bytes_written; |
470 | 466 | double sec = ((t1.tv_sec-t0.tv_sec)+(t1.tv_usec-t0.tv_usec)/1000000.0); |
471 | printf("%s: %"I64d" bytes transferred in %.2f seconds. xfer rate: %.2f MBytes/sec\n", | |
467 | printf("%s: %" I64d " bytes transferred in %.2f seconds. xfer rate: %.2f MBytes/sec\n", | |
472 | 468 | af_filename(af),w,sec,(w/1000000.0) / sec); |
473 | 469 | } |
474 | 470 |
96 | 96 | uint64_t atoi64(const char *buf) |
97 | 97 | { |
98 | 98 | uint64_t ret=0; |
99 | sscanf(buf,"%"PRIu64,&ret); | |
99 | sscanf(buf,"%" PRIu64,&ret); | |
100 | 100 | return ret; |
101 | 101 | } |
102 | 102 | |
200 | 200 | int64_t imagesize = af_get_imagesize(af); |
201 | 201 | if(imagesize>0){ |
202 | 202 | char buf[32]; |
203 | snprintf(buf,sizeof(buf),"%"PRIu64,imagesize); | |
203 | snprintf(buf,sizeof(buf),"%" PRIu64,imagesize); | |
204 | 204 | out_xmlstr(cout,2,AF_IMAGESIZE,buf); |
205 | 205 | cout << "\n"; |
206 | 206 | } |
211 | 211 | int64_t sectors = imagesize/sectorsize; |
212 | 212 | if(sectors>0){ |
213 | 213 | char buf[32]; |
214 | snprintf(buf,sizeof(buf),"%"PRIu32"",sectorsize); | |
214 | snprintf(buf,sizeof(buf),"%" PRIu32,sectorsize); | |
215 | 215 | out_xmlstr(cout,2,AF_SECTORSIZE,buf); |
216 | 216 | cout << "\n"; |
217 | 217 | } |
31 | 31 | #endif |
32 | 32 | |
33 | 33 | using namespace std; |
34 | ||
35 | #ifdef HAVE_CURSES_H | |
36 | #include <curses.h> | |
37 | #endif | |
38 | ||
39 | #ifdef HAVE_TERM_H | |
40 | #include <term.h> | |
41 | #endif | |
42 | 34 | |
43 | 35 | #ifdef WIN32 |
44 | 36 | #include "unix4win32.h" |
78 | 70 | |
79 | 71 | vector<string> opt_seglist; // just info these segments |
80 | 72 | bool something_was_decrypted = false; |
81 | const char *term = 0; | |
82 | ||
83 | ||
84 | /** | |
85 | * select bold on or off | |
86 | */ | |
87 | void bold(int on) | |
88 | { | |
89 | if(!term) return; | |
90 | #ifdef HAVE_ISATTY | |
91 | if(!isatty(fileno(stdout))) return; | |
92 | #endif | |
93 | #if defined(HAVE_TPUTS) && defined(HAVE_CURSES_H) && defined(HAVE_TERM_H) | |
94 | if(on) tputs(enter_bold_mode,1,putchar); | |
95 | else tputs(exit_attribute_mode,0,putchar); | |
96 | #endif | |
97 | } | |
98 | ||
99 | /** | |
100 | * select a color. | |
101 | * @param num - 0 is black; 1 red; 2 green; 3 yellow; 4 blue; 5 magenta; 6 cyan; 7 white; | |
102 | */ | |
103 | ||
104 | #define RED 1 | |
105 | #define WHITE 7 | |
106 | ||
107 | void color(int num) | |
108 | { | |
109 | #ifdef HAVE_ISATTY | |
110 | if(!isatty(fileno(stdout))) return; | |
111 | #endif | |
112 | #if defined(HAVE_TIGETSTR) && defined(HAVE_PUTP) && defined(HAVE_TPARM) | |
113 | char *setf = tigetstr((char *)"setf"); | |
114 | if(!setf) setf = tigetstr((char *)"setaf"); | |
115 | if(setf){ | |
116 | putp(tparm(setf,num)); | |
117 | } | |
118 | #endif | |
119 | } | |
120 | ||
121 | 73 | |
122 | 74 | void usage() |
123 | 75 | { |
163 | 115 | #endif |
164 | 116 | printf("\n"); |
165 | 117 | |
166 | if(opt_debug){ | |
167 | for(int i=0;i<9;i++){ | |
168 | color(i);printf("Color %d\n",i);color(7); | |
169 | } | |
170 | } | |
171 | ||
172 | 118 | exit(0); |
173 | 119 | } |
174 | 120 | |
178 | 124 | void sig_info(int arg) |
179 | 125 | { |
180 | 126 | if(af==0) return; |
181 | printf("Validating %"I64d" of %"I64d"\n", af->pos,af->image_size); | |
127 | printf("Validating %" I64d" of %" I64d"\n", af->pos,af->image_size); | |
182 | 128 | } |
183 | 129 | |
184 | 130 | |
407 | 353 | af_set_option(af,AF_OPTION_AUTO_DECRYPT,prev); |
408 | 354 | |
409 | 355 | if(was_decrypted){ |
410 | bold(1); | |
411 | 356 | something_was_decrypted = true; // print key at bottom |
412 | 357 | } |
413 | 358 | |
416 | 361 | memset(output_line,0,sizeof(output_line)); |
417 | 362 | |
418 | 363 | /* Now append the arg and the data len */ |
419 | sprintf(output_line,"%-24s %8"PRIu32" %8d ",segname,arg,(int)data_len); | |
364 | sprintf(output_line,"%-24s %8" PRIu32 " %8d ",segname,arg,(int)data_len); | |
420 | 365 | |
421 | 366 | if(opt_no_preview){ |
422 | 367 | printf("%s\n",output_line); |
446 | 391 | */ |
447 | 392 | switch(data_len){ |
448 | 393 | case 8: |
449 | printf("%s= %"I64d" (64-bit value)\n", | |
394 | printf("%s= %" I64d" (64-bit value)\n", | |
450 | 395 | output_line,af_decode_q(data)); |
451 | 396 | break; |
452 | 397 | case 0: |
551 | 496 | putchar('\n'); |
552 | 497 | done: |
553 | 498 | if(data) free(data); |
554 | bold(0); // make sure bold is off | |
555 | ||
556 | //color(WHITE); // make sure we are back to normal color | |
557 | 499 | } |
558 | 500 | |
559 | 501 | |
665 | 607 | |
666 | 608 | /* Print the key */ |
667 | 609 | if(something_was_decrypted){ |
668 | bold(1); | |
669 | printf("Bold indicates segments that were decrypted.\n"); | |
670 | bold(0); | |
610 | printf("Some segments were decrypted.\n"); | |
671 | 611 | } |
672 | 612 | |
673 | 613 | |
674 | 614 | printf("\n"); |
675 | printf("Total segments: %8"PRIu32" (%"PRIu32" real)\n", total_segs,(total_segs-total_nulls)); | |
615 | printf("Total segments: %8" PRIu32 " (%" PRIu32" real)\n", total_segs,(total_segs-total_nulls)); | |
676 | 616 | if(aes_segs){ |
677 | 617 | printf(" Encrypted segments: %8u\n",aes_segs); |
678 | 618 | } |
679 | printf(" Page segments: %8"PRIu32"\n",total_pages); | |
680 | printf(" Hash segments: %8"PRIu32"\n",total_hashes); | |
681 | printf(" Signature segments: %8"PRIu32"\n",total_signatures); | |
682 | printf(" Null segments: %8"PRIu32"\n",total_nulls); | |
619 | printf(" Page segments: %8" PRIu32 "\n",total_pages); | |
620 | printf(" Hash segments: %8" PRIu32 "\n",total_hashes); | |
621 | printf(" Signature segments: %8" PRIu32 "\n",total_signatures); | |
622 | printf(" Null segments: %8" PRIu32 "\n",total_nulls); | |
683 | 623 | if(opt_all){ |
684 | printf(" Empty segments: %8"PRIu32"\n",total_nulls); | |
624 | printf(" Empty segments: %8" PRIu32 "\n",total_nulls); | |
685 | 625 | printf("\n"); |
686 | printf("Total data bytes in segments: %"I64d"\n",total_datalen); | |
626 | printf("Total data bytes in segments: %" I64d"\n",total_datalen); | |
687 | 627 | |
688 | 628 | printf("Total space in file dedicated to segment names: %zd\n", |
689 | 629 | total_segname_len); |
690 | printf("Total overhead for %"PRIu32" segments: %zd bytes (%"PRIu32"*(%zd+%zd))\n", | |
630 | printf("Total overhead for %" PRIu32 " segments: %zd bytes (%" PRIu32 "*(%zd+%zd))\n", | |
691 | 631 | total_segs, |
692 | 632 | (size_t) total_segs*(sizeof(struct af_segment_head) +sizeof(struct af_segment_tail)), |
693 | 633 | total_segs, |
719 | 659 | //printf("device_bytes=%"I64d"\n",device_bytes); |
720 | 660 | //printf("device_pages=%"I64d"\n",device_pages); |
721 | 661 | if(missing_pages!=0){ |
722 | printf("Missing page segments: %8"I64u"\n",missing_pages); | |
662 | printf("Missing page segments: %8" I64u"\n",missing_pages); | |
723 | 663 | } |
724 | 664 | else { |
725 | 665 | some_missing_pages=0; |
734 | 674 | |
735 | 675 | if(some_missing_pages && opt_debug){ |
736 | 676 | printf("Cannot calculate missing pages\n"); |
737 | printf(" device_sectors=%"I64d" image_pagesize=%"PRIu32" sectorsize=%"PRIu32"\n", | |
677 | printf(" device_sectors=%" I64d" image_pagesize=%" PRIu32 " sectorsize=%" PRIu32 "\n", | |
738 | 678 | device_sectors,af->image_pagesize,af->image_sectorsize); |
739 | 679 | } |
740 | 680 | af_close(af); |
755 | 695 | printf("<!DOCTYPE Server >\n"); |
756 | 696 | printf("<device name='%s'>\n",fn); |
757 | 697 | printf(" <sector_size>%d</sector_size>\n",afb.sector_size); |
758 | printf(" <total_sectors>%"PRId64"</total_sectors>\n",afb.total_sectors); | |
759 | printf(" <max_read_blocks>%"PRIu64"</max_read_blocks>\n",afb.max_read_blocks); | |
698 | printf(" <total_sectors>%" PRId64 "</total_sectors>\n",afb.total_sectors); | |
699 | printf(" <max_read_blocks>%" PRIu64 "</max_read_blocks>\n",afb.max_read_blocks); | |
760 | 700 | printf("</device>\n"); |
761 | 701 | close(fd); |
762 | 702 | } |
21 | 21 | |
22 | 22 | #ifdef HAVE_UNISTD_H |
23 | 23 | #include <unistd.h> |
24 | #endif | |
25 | ||
26 | #ifdef HAVE_TERM_H | |
27 | #include <term.h> | |
28 | 24 | #endif |
29 | 25 | |
30 | 26 | #ifdef WIN32 |
92 | 88 | r = (*af->v->open)(af); |
93 | 89 | /* See if we can build a TOC */ |
94 | 90 | if(r<0){ |
95 | printf("AFF file corrupt at %"I64d" out of %"I64d" (%"I64d" bytes from end)\n", | |
91 | printf("AFF file corrupt at %" I64d " out of %" I64d " (%" I64d " bytes from end)\n", | |
96 | 92 | ftello(af->aseg),(int64_t)len,len-ftello(af->aseg)); |
97 | 93 | if(opt_fix){ |
98 | 94 | printf("Truncating... %d \n",fileno(af->aseg)); |
20 | 20 | |
21 | 21 | #ifdef HAVE_UNISTD_H |
22 | 22 | #include <unistd.h> |
23 | #endif | |
24 | ||
25 | #ifdef HAVE_TERM_H | |
26 | #include <term.h> | |
27 | 23 | #endif |
28 | 24 | |
29 | 25 | #ifdef WIN32 |
229 | 229 | free(buf); |
230 | 230 | continue; |
231 | 231 | } |
232 | if(opt_debug) fprintf(stderr," arg=%"PRIu32" len=%zd\n",arg,len); | |
232 | if(opt_debug) fprintf(stderr," arg=%" PRIu32 " len=%zd\n",arg,len); | |
233 | 233 | int p = 1; |
234 | 234 | |
235 | 235 | if(filecount>1) printf("%s:",fn); |
236 | 236 | if(print_segs.size()>1) printf("%s=",segname); |
237 | 237 | if(opt_quad && len==8){ |
238 | 238 | uint64_t quad = af_decode_q(buf); |
239 | printf("%"I64u"\n",quad); | |
239 | printf("%" I64u "\n",quad); | |
240 | 240 | p = 0; |
241 | 241 | } |
242 | 242 | |
243 | 243 | if(opt_arg){ |
244 | printf("%"PRIu32"\n",arg); | |
244 | printf("%" PRIu32 "\n",arg); | |
245 | 245 | p = 0; |
246 | 246 | } |
247 | 247 |
64 | 64 | #include <unistd.h> |
65 | 65 | #endif |
66 | 66 | |
67 | #ifdef HAVE_TERM_H | |
68 | #include <term.h> | |
69 | #endif | |
70 | ||
71 | 67 | #ifdef WIN32 |
72 | 68 | #include "unix4win32.h" |
73 | 69 | #include <malloc.h> |
97 | 93 | printf("%u",(unsigned int)(s/(1024*1024))); |
98 | 94 | return; |
99 | 95 | } |
100 | printf("%"I64u,s); | |
96 | printf("%" I64u,s); | |
101 | 97 | } |
102 | 98 | |
103 | 99 | void affstats_title() |
149 | 145 | print_size(compressed_bytes); |
150 | 146 | printf("\t"); |
151 | 147 | print_size(uncompressed_bytes); |
152 | printf(" %"I64d" %"I64d,blanksectors,badsectors); | |
148 | printf(" %" I64d " %" I64d,blanksectors,badsectors); | |
153 | 149 | putchar('\n'); |
154 | 150 | |
155 | 151 |
450 | 450 | printf("\n"); |
451 | 451 | do { |
452 | 452 | double frac = (double)total_read / af_get_imagesize(af); |
453 | printf(" Read %14zd/%14"PRId64" bytes; done in %s\n", | |
453 | printf(" Read %14zd/%14" PRId64" bytes; done in %s\n", | |
454 | 454 | total_read, |
455 | 455 | af_get_imagesize(af), |
456 | 456 | t.eta_text(frac).c_str()); |
134 | 134 | |
135 | 135 | void print_xml64(const char *name,int64_t val) |
136 | 136 | { |
137 | printf(" <%s coding='base10'>%"I64d"</%s>\n\n",name,val,name); | |
137 | printf(" <%s coding='base10'>%" I64d"</%s>\n\n",name,val,name); | |
138 | 138 | } |
139 | 139 | |
140 | 140 | int xml_info(const char *infile) |
190 | 190 | size_t pagesize = af_page_size(af); |
191 | 191 | size_t sectorsize = af_get_sectorsize(af); |
192 | 192 | if(af_get_page(af,*it,data,&pagesize)){ |
193 | err(1,"Can't read page %"PRId64,*it); | |
193 | err(1,"Can't read page %" PRId64,*it); | |
194 | 194 | } |
195 | 195 | psb.pages++; |
196 | 196 | bool allblank = true; |
249 | 249 | * The strcmp is there because early AF_IMAGESIZE segs didn't set |
250 | 250 | * AF_SEG_QUADWORD... |
251 | 251 | */ |
252 | printf(" <%s coding='base10'>%"I64d"</%s>\n",segname,af_decode_q(data),segname); | |
252 | printf(" <%s coding='base10'>%" I64d"</%s>\n",segname,af_decode_q(data),segname); | |
253 | 253 | free(data); |
254 | 254 | continue; |
255 | 255 | } |
256 | 256 | |
257 | 257 | /* If datalen==0, just print the arg as an unsigned number */ |
258 | 258 | if(datalen==0){ |
259 | printf(" <%s coding='base10'>%"PRIu32"</%s>\n",segname,arg,segname); | |
259 | printf(" <%s coding='base10'>%" PRIu32 "</%s>\n",segname,arg,segname); | |
260 | 260 | free(data); |
261 | 261 | continue; |
262 | 262 | } |
264 | 264 | /* Just handle it as binhex ... */ |
265 | 265 | printf(" <%s",segname); |
266 | 266 | if(datalen==0){ |
267 | printf(" arg='%"PRIu32"' />\n",arg); | |
267 | printf(" arg='%" PRIu32 "' />\n",arg); | |
268 | 268 | free(data); |
269 | 269 | continue; |
270 | 270 | } |