forked from chrisridd/opendj-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumpber
executable file
·112 lines (80 loc) · 1.92 KB
/
dumpber
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
#!/usr/bin/perl -w
use strict;
use warnings;
use Convert::ASN1;
$::VERSION = 0.1;
sub version()
{
print STDERR "$0 version $::VERSION\n";
exit 0;
}
sub usage()
{
print STDERR "Usage: $0 [-base64|-hex] [-h] [-v]\n";
exit 1;
}
my %opt = (
'base64' => 0, # Base64-encoded input
'hex' => 0, # Hex-encoded input
'h' => 0,
'v' => 0,
);
while (@ARGV) {
my $arg = shift @ARGV;
if ($arg =~ m{^-base64$}) {
$opt{base64} = 1;
require MIME::Base64;
} elsif ($arg =~ m{^-hex$}) {
$opt{hex} = 1;
} elsif ($arg =~ m{^-h$|^--help$}) {
$opt{h} = 1;
} elsif ($arg =~ m{^-v$|^--version$}) {
$opt{v} = 1;
} else {
unshift @ARGV, $arg;
last;
}
}
version if $opt{v};
usage if $opt{h};
my $str;
{
local $/ = undef;
$str = <>;
}
if ($opt{base64}) {
$str = MIME::Base64::decode($str);
} elsif ($opt{hex}) {
$str =~ s/[^0-9a-fA-F]//g;
$str =~ s/([0-9a-fA-F][0-9a-fA-F])/pack('C',hex $1)/ge;
}
Convert::ASN1::asn_dump(*STDOUT, $str);
exit 0;
__END__
=head1 NAME
dumpber - pretty-print BER-encoded data
=head1 SYNOPSIS
dumpber [-base64|-hex] [-h] [-v]
=head1 DESCRIPTION
Attempt to decode and pretty-print the BER-encoded input. The input can be
base64- or hex-encoded, but the default is raw binary.
=head1 OPTIONS
=over
=item B<-base64> base64-decode the data first.
=item B<-hex> hex-decode the data first.
=item B<-h> display help text.
=item B<-v> display version information.
=back
=head1 EXAMPLE
$ dumpber /tmp/test.bin
0000 30: SEQUENCE {
0002 13: [UNIVERSAL 23]
0004 : 31 33 30 36 30 36 30 38 32 30 34 39 5A __ __ __ 130606082049Z
0011 13: [UNIVERSAL 23]
0013 : 31 33 30 39 30 34 30 38 32 30 34 39 5A __ __ __ 130904082049Z
0020 : }
=head1 AUTHOR
Chris Ridd E<lt>[email protected]<gt>
=head1 COPYRIGHT
Copyright (c) 2013 Chris Ridd. All rights reserved. This tool is free software;
you can redistribute it and/or modify it under the same terms as Perl itself.