From 48c3cc33a46edab03cc093ea7ef56956e1d802f0 Mon Sep 17 00:00:00 2001 From: vlm Date: Thu, 28 Apr 2005 02:55:35 +0000 Subject: [PATCH] binary decoders git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@877 59561ff5-6e30-0410-9f3c-9617f08c8826 --- asn1c/webcgi/asn1c.cgi | 141 +++++++++++++++++++++++++++++++++-------- 1 file changed, 115 insertions(+), 26 deletions(-) diff --git a/asn1c/webcgi/asn1c.cgi b/asn1c/webcgi/asn1c.cgi index 07966774..3a39df0f 100755 --- a/asn1c/webcgi/asn1c.cgi +++ b/asn1c/webcgi/asn1c.cgi @@ -47,6 +47,56 @@ use CGI qw/param cookie header upload escapeHTML/; $|=1; # Enable AutoFlush (for older versions of Perl) +my %binaryDecoders = ( + x509 => { order => 1, + type => 'X.509 Certificate', + typeExt => 'X.509 Certificate', + exe => 'x509dump', + cmdopts => '-x', + msg => '' + }, + + tap0311 => { order => 2, + type => TAP3, + typeExt => 'GSM TAP3-11 data', + exe => 'tap3dump-11', + cmdopts => '-x', + msg => '' + }, + + tap0310 => { order => 3, + type => TAP3, + typeExt => 'GSM TAP3-10 data', + exe => 'tap3dump-10', + cmdopts => '-x', + msg => '' + }, + + tap0309 => { order => 4, + type => TAP3, + typeExt => 'GSM TAP3-09 data', + exe => 'tap3dump-09', + cmdopts => '-x', + msg => '' + }, + + mheg5 => { order => 5, + type => 'MHEG-5', + typeExt => 'ISO MHEG-5 data', + exe => 'mheg5dump', + cmdopts => '-x', + msg => '' + }, + + ber => { order => 6, + type => BER, + typeExt => 'BER encoded data', + exe => 'unber', + cmdopts => '', + msg => "\n" + } +); + my $redirect = ''; # No redirection by default my $redirect_bottom = ''; # No redirection text by default my $content = ''; # Default content is empty @@ -412,33 +462,54 @@ if($#gotSafeNames >= 0) { . "; ec=\$?; echo \$ec > $sandbox/+ExitCode" . "; exit \$ec"; - my $ec = (256 * $DataERR); # Simulate EX_DATAERR my $fType = param('fileType'); + $fType = 'auto' unless $fType; # Compile as ASN.1 text - if($fType ne 'ber') { - $ec = system($CompileASN); + if($fType eq 'auto' || $fType eq 'asn1') { + my $ec = system($CompileASN); bark("Failed to initiate compilation process: $!") if(!-r $sandbox . '/+ExitCode'); + if($ec != (256 * $DataERR)) { + makeArchive($TMPDIR, $sandbox) unless $ec; + goto REGET; # Issue a clean GET request. + } } - if($ec == (256 * $DataERR) and $fType ne 'asn') { - # Unrecognized ASN.1 module format. - # Try out BER decoding. - my $uec = system("$SUIDHelper $TMPDIR $inChDir unber @gotSafeNames > $TMPDIR/$inChDir/+UNBER.tmp 2>&1"); - if(($uec == 0 or $fType eq 'ber') - and open(U, "> $TMPDIR/$inChDir/+UNBER")) { - my $fnames = escapeHTML(join(", ", @gotNames)); - open(T, "< $TMPDIR/$inChDir/+UNBER.tmp"); - print U "\n"; - print U while ; + # Unrecognized ASN.1 module format. + # Try out several BER decoders. + foreach my $t (sort { $binaryDecoders{$a} cmp $binaryDecoders{$b} } + keys %binaryDecoders) { + next unless ($fType eq 'auto' or $fType eq $t); + my %dec = %{$binaryDecoders{$t}}; + my $ec = system("$SUIDHelper $TMPDIR $inChDir $dec{exe} $dec{cmdopts} @gotSafeNames > $TMPDIR/$inChDir/+UNBER.tmp 2>&1"); + next if ($ec != 0 and $t ne $fType + and (-s "$TMPDIR/$inChDir/+UNBER.tmp" < 1000)); + last unless open(U, "> $TMPDIR/$inChDir/+UNBER"); + my $fnames = escapeHTML(join(", ", @gotNames)); + print U "\n" + . $dec{msg}; + open(T, "< $TMPDIR/$inChDir/+UNBER.tmp"); + print U while ; + close(U); + close(T); + open(U, "> $TMPDIR/$inChDir/+UNBER.TYPE"); + print U $dec{typeExt}; + close(U); + if($ec) { + # Indicate unclean exit. + open(U, "> $TMPDIR/$inChDir/+UNBER.EXIT"); + print U $ec; close(U); - close(T); } - unlink("$TMPDIR/$inChDir/+UNBER.tmp"); - } else { - makeArchive($TMPDIR, $sandbox); + last; } + unlink("$TMPDIR/$inChDir/+UNBER.tmp"); + +REGET: + if($ENV{REQUEST_METHOD} ne 'GET') { print "Status: 303 See Other\n"; print "Location: $myName\n"; @@ -461,8 +532,13 @@ $form = . "" . "" . "" . "" @@ -571,13 +647,26 @@ foreach my $trans (sort { $b cmp $a } @transactions) { if($ec eq "0") { $results = "" . "Compiled OK
\n"; - } elsif(-f $sessionDir . '/' . $trans . '/+UNBER') { - my $msg = 'This looks like a BER-encoded data'; - $msg = "Treating input as BER-encoded data" if $ec eq ''; + } elsif(open(U, $sessionDir . '/' . $trans . '/+UNBER.TYPE')) { + my $type = ; close(U); + my $msg; + if($ec eq '') { + $msg = 'Treating input as ' . $type; + } else { + $msg = 'This looks like ' . $type; + } $results = "$msg
\n"; - $resText = "Show BER structure"; + if(-f $sessionDir . '/' . $trans . '/+UNBER.EXIT') { + $results = "" + . "$type: " + . "Broken encoding
\n"; + $ec = 'broken-input'; + $resText = "Show $type decoding attempt"; + } else { + $ec = 0; + $resText = "Show $type contents"; + } $resCode = "unber"; - $ec = 0; } else { my $why = $ec; $why = "Broken input file" if $ec == $DataERR; @@ -648,7 +737,7 @@ foreach my $trans (sort { $b cmp $a } @transactions) { $history .= "" . "$tNum" - . "
[[Bottom line: ASN.1 compiler was unable to process some of the input.
" . "This is typically caused by syntax errors in the input files.\n" . "Such errors are normally fixed by removing or adding a couple of characters in the ASN.1 module.
\n" - . "
Please consider clicking on the appropriate "Help me fix it!" button above.
\n" + . "
⇒ Please consider clicking on the appropriate "Help me fix it!" button above.
\n" . "An email will be sent to a live person who will fix the ASN.1 module for you. (The typical turn-around time is less than 24 hours.)\n" . "
This is free, and highly advisable.\n" . "
Your request will help us make a better compiler!\n" @@ -725,7 +814,7 @@ $content .= . "$history \n" . "" . "Privacy Note: this page is tailored " - . "to your browser using a cryprographically strong cookie. " + . "to your browser. " . "Other users will see their own (different) data. " . "(
Read more...)" . "";