aboutsummaryrefslogtreecommitdiffstats
path: root/asn1c/unber.c
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2005-09-30 05:23:40 +0000
committerLev Walkin <vlm@lionet.info>2005-09-30 05:23:40 +0000
commit904477967a15abfcf8ac1fd67b1c39a672dc9160 (patch)
treeabf6175e22265b249cd340d0811019f8f92dc4d2 /asn1c/unber.c
parentef62540d72b133d2263fc0741a6c91ab88e58ab3 (diff)
-s <skip> feature
Diffstat (limited to 'asn1c/unber.c')
-rw-r--r--asn1c/unber.c65
1 files changed, 47 insertions, 18 deletions
diff --git a/asn1c/unber.c b/asn1c/unber.c
index 5768a588..c573cfdb 100644
--- a/asn1c/unber.c
+++ b/asn1c/unber.c
@@ -47,6 +47,7 @@ static int decode_tlv_from_string(const char *datastring);
static int single_type_decoding = 0; /* -1 enables that */
static int minimalistic = 0; /* -m enables that */
static int pretty_printing = 1; /* -p disables that */
+static int skip_bytes = 0; /* -s controls that */
static char *indent_buffer = " "; /* -i controls that */
int
@@ -57,21 +58,11 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
- while((ch = getopt(ac, av, "1hi:mpt:v")) != -1)
+ while((ch = getopt(ac, av, "1hi:mps:t:v")) != -1)
switch(ch) {
case '1':
single_type_decoding = 1;
break;
- case 't':
- if(decode_tlv_from_string(optarg))
- exit(EX_DATAERR);
- exit(0);
- case 'm':
- minimalistic = 1;
- break;
- case 'p':
- pretty_printing = 0;
- break;
case 'i':
i = atoi(optarg);
if(i >= 0 && i < 16) {
@@ -83,6 +74,24 @@ main(int ac, char **av) {
exit(EX_USAGE);
}
break;
+ case 'm':
+ minimalistic = 1;
+ break;
+ case 'p':
+ pretty_printing = 0;
+ break;
+ case 's':
+ skip_bytes = atoi(optarg);
+ if(skip_bytes < 0) {
+ fprintf(stderr, "-s %s: positive value expected\n",
+ optarg);
+ exit(EX_USAGE);
+ }
+ break;
+ case 't':
+ if(decode_tlv_from_string(optarg))
+ exit(EX_DATAERR);
+ exit(0);
case 'v':
fprintf(stderr, "ASN.1 BER Decoder, v" VERSION "\n" COPYRIGHT);
exit(0);
@@ -126,11 +135,12 @@ usage(const char *av0) {
"ASN.1 BER Decoder, v" VERSION "\n" COPYRIGHT
"Usage: %s [options] [-] [file ...]\n"
"Options:\n"
-" -1 Decode only the first BER structure (otherwise, until EOF)\n"
-" -i <indent> Amount of spaces for output indentation (default is 4)\n"
-" -m Minimalistic mode: print as little as possible\n"
-" -p Do not attempt pretty-printing of known ASN.1 types\n"
-" -t <data-string> Decode the given tag[/length] sequence (e.g. -t \"bf20\")\n"
+" -1 Decode only the first BER structure (otherwise, until EOF)\n"
+" -i <indent> Amount of spaces for output indentation (default is 4)\n"
+" -m Minimalistic mode: print as little as possible\n"
+" -p Do not attempt pretty-printing of known ASN.1 types\n"
+" -s <skip> Ignore first <skip> bytes of input\n"
+" -t <hex-string> Decode the given tag[/length] sequence (e.g. -t \"bf20\")\n"
"\n"
"The XML opening tag format is as follows:\n"
" <tform O=\"off\" T=\"tag\" TL=\"tl_len\" V=\"{Indefinite|v_len}\" [A=\"type\"] [F]>\n"
@@ -177,6 +187,21 @@ process(const char *fname) {
}
/*
+ * Skip the requested amount of bytes.
+ */
+ for(; offset < skip_bytes; offset++) {
+ if(fgetc(fp) == -1) {
+ fprintf(stderr,
+ "%s: input source (%" PRIdASN " bytes) "
+ "has less data than \"-s %d\" switch "
+ "wants to skip\n",
+ fname, offset, skip_bytes);
+ if(fp != stdin) fclose(fp);
+ return -1;
+ }
+ }
+
+ /*
* Fetch out BER-encoded data until EOF or error.
*/
do {
@@ -205,7 +230,7 @@ process_deeper(const char *fname, FILE *fp, asn1c_integer_t *offset, int level,
ssize_t t_len;
ssize_t l_len;
- do {
+ for(;;) {
ber_tlv_len_t local_esize = 0;
int constr;
int ch;
@@ -348,7 +373,11 @@ process_deeper(const char *fname, FILE *fp, asn1c_integer_t *offset, int level,
tlv_tag, tlv_len, local_esize);
tblen = 0;
- } while(1);
+
+ /* Report success for a single top level TLV */
+ if(level == 0 && limit == -1 && !expect_eoc)
+ break;
+ } /* for(;;) */
return pdc;
}