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 : #include "bsigs.h"
11 :
12 : static const char *path=NULL;
13 :
14 : static int usage(void)
15 : {
16 0 : printf("\nUsage: %s [filename]\n\n", prog);
17 : return 1;
18 : }
19 :
20 0 : static int parse_cmd(struct iobuf *rbuf, struct blk *blk)
21 : {
22 0 : int ret=-1;
23 :
24 0 : printf("%c%04X", rbuf->cmd, (unsigned int)rbuf->len);
25 0 : switch(rbuf->cmd)
26 : {
27 : case CMD_SIG:
28 0 : if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf))
29 : goto end;
30 0 : printf("%016" PRIX64 "%s%s\n",
31 : blk->fingerprint,
32 0 : bytes_to_md5str(blk->md5sum),
33 : uint64_to_savepathstr_with_sig(blk->savepath));
34 0 : break;
35 : case CMD_FINGERPRINT:
36 0 : if(blk_set_from_iobuf_fingerprint(blk, rbuf))
37 : goto end;
38 0 : printf("%016" PRIX64 "\n", blk->fingerprint);
39 0 : break;
40 : case CMD_SAVE_PATH:
41 0 : if(blk_set_from_iobuf_savepath(blk, rbuf))
42 : goto end;
43 0 : printf("%s\n", uint64_to_savepathstr(blk->savepath));
44 0 : break;
45 : case CMD_DATA:
46 0 : logp("\n%s looks like a data file\n", path);
47 0 : goto end;
48 : /*
49 : FIX THIS - give a flag to tell it to decode attributes.
50 : case CMD_ATTRIBS:
51 : memcpy(&sb->attr, rbuf, sizeof(struct iobuf));
52 : attribs_decode(sb);
53 : printf("compression: %d\n", sb->compression);
54 : break;
55 : */
56 : default:
57 0 : printf("%s\n", rbuf->buf);
58 0 : break;
59 : }
60 : ret=0;
61 : end:
62 0 : return ret;
63 : }
64 :
65 0 : int run_bsigs(int argc, char *argv[])
66 : {
67 0 : int ret=1;
68 0 : struct fzp *fzp=NULL;
69 : struct iobuf rbuf;
70 : struct blk blk;
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 : 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 : case -1: goto end; // Error.
88 : }
89 :
90 0 : if(parse_cmd(&rbuf, &blk)) goto end;
91 : }
92 :
93 : end:
94 0 : iobuf_free_content(&rbuf);
95 0 : fzp_close(&fzp);
96 0 : return ret;
97 : }
|