Line data Source code
1 : #include "../../burp.h"
2 : #include "../../attribs.h"
3 : #include "../../base64.h"
4 : #include "../../fzp.h"
5 : #include "../../handy.h"
6 : #include "../../hexmap.h"
7 : #include "../../iobuf.h"
8 : #include "../../log.h"
9 : #include "../../protocol2/blk.h"
10 :
11 : static const char *path=NULL;
12 :
13 0 : static int usage(void)
14 : {
15 0 : printf("\nUsage: %s [filename]\n\n", prog);
16 0 : return 1;
17 : }
18 :
19 0 : static int parse_cmd(struct iobuf *rbuf, struct blk *blk, struct sbuf *sb)
20 : {
21 0 : int ret=-1;
22 :
23 0 : printf("%c%04X", rbuf->cmd, (unsigned int)rbuf->len);
24 0 : switch(rbuf->cmd)
25 : {
26 : case CMD_SIG:
27 0 : if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf))
28 0 : goto end;
29 : printf("%016"PRIX64"%s%s\n",
30 : blk->fingerprint,
31 : bytes_to_md5str(blk->md5sum),
32 0 : uint64_to_savepathstr_with_sig(blk->savepath));
33 0 : break;
34 : case CMD_FINGERPRINT:
35 0 : if(blk_set_from_iobuf_fingerprint(blk, rbuf))
36 0 : goto end;
37 0 : printf("%016"PRIX64"\n", blk->fingerprint);
38 0 : break;
39 : case CMD_SAVE_PATH:
40 0 : if(blk_set_from_iobuf_savepath(blk, rbuf))
41 0 : goto end;
42 0 : printf("%s\n", uint64_to_savepathstr(blk->savepath));
43 0 : break;
44 : case CMD_DATA:
45 0 : logp("\n%s looks like a data file\n", path);
46 0 : goto end;
47 : /*
48 : FIX THIS - give a flag to tell it to decode attributes.
49 : case CMD_ATTRIBS:
50 : memcpy(&sb->attr, rbuf, sizeof(struct iobuf));
51 : attribs_decode(sb);
52 : printf("compression: %d\n", sb->compression);
53 : break;
54 : */
55 : default:
56 0 : printf("%s\n", rbuf->buf);
57 0 : break;
58 : }
59 0 : ret=0;
60 : end:
61 0 : return ret;;
62 : }
63 :
64 0 : int run_bsigs(int argc, char *argv[])
65 : {
66 0 : int ret=1;
67 0 : fzp *fzp=NULL;
68 : struct iobuf rbuf;
69 : struct blk blk;
70 0 : struct sbuf *sb=sbuf_alloc(PROTO_1);
71 0 : memset(&rbuf, 0, sizeof(struct iobuf));
72 :
73 0 : base64_init();
74 :
75 0 : if(argc!=2)
76 0 : return usage();
77 0 : path=argv[1];
78 :
79 0 : if(!(fzp=fzp_gzopen(path, "rb")))
80 0 : goto end;
81 : while(1)
82 : {
83 0 : iobuf_free_content(&rbuf);
84 0 : switch(iobuf_fill_from_fzp(&rbuf, fzp))
85 : {
86 0 : case 1: ret=0; // Finished OK.
87 0 : case -1: goto end; // Error.
88 : }
89 :
90 0 : if(parse_cmd(&rbuf, &blk, sb)) goto end;
91 : }
92 :
93 : end:
94 0 : iobuf_free_content(&rbuf);
95 0 : fzp_close(&fzp);
96 0 : return ret;
97 : }
|