RetroZilla/security/nss/lib/ckfw/builtins/certdata.perl

182 lines
3.7 KiB
Plaintext
Raw Normal View History

2015-10-21 05:03:22 +02:00
#!perl -w
#
2018-05-04 16:08:28 +02:00
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
2015-10-21 05:03:22 +02:00
use strict;
my %constants;
my $count = 0;
my $o;
my @objects = ();
my @objsize;
$constants{CKO_DATA} = "static const CK_OBJECT_CLASS cko_data = CKO_DATA;\n";
$constants{CK_TRUE} = "static const CK_BBOOL ck_true = CK_TRUE;\n";
$constants{CK_FALSE} = "static const CK_BBOOL ck_false = CK_FALSE;\n";
while(<>) {
my @fields = ();
my $size;
s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
next if (/^\s*$/);
# This was taken from the perl faq #4.
my $text = $_;
push(@fields, $+) while $text =~ m{
"([^\"\\]*(?:\\.[^\"\\]*)*)"\s? # groups the phrase inside the quotes
| ([^\s]+)\s?
| \s
}gx;
push(@fields, undef) if substr($text,-1,1) eq '\s';
if( $fields[0] =~ /BEGINDATA/ ) {
next;
}
if( $fields[1] =~ /MULTILINE/ ) {
$fields[2] = "";
while(<>) {
last if /END/;
chomp;
$fields[2] .= "\"$_\"\n";
}
}
if( $fields[1] =~ /UTF8/ ) {
if( $fields[2] =~ /^"/ ) {
;
} else {
$fields[2] = "\"" . $fields[2] . "\"";
}
2018-05-04 16:08:28 +02:00
my $scratch = eval($fields[2]);
$size = length($scratch) + 1; # null terminate
2015-10-21 05:03:22 +02:00
}
if( $fields[1] =~ /OCTAL/ ) {
if( $fields[2] =~ /^"/ ) {
;
} else {
$fields[2] = "\"" . $fields[2] . "\"";
}
my $scratch = $fields[2];
$size = $scratch =~ tr/\\//;
# no null termination
}
if( $fields[1] =~ /^CK_/ ) {
my $lcv = $fields[2];
$lcv =~ tr/A-Z/a-z/;
if( !defined($constants{$fields[2]}) ) {
$constants{$fields[2]} = "static const $fields[1] $lcv = $fields[2];\n";
}
$size = "sizeof($fields[1])";
$fields[2] = "&$lcv";
}
if( $fields[0] =~ /CKA_CLASS/ ) {
$count++;
$objsize[$count] = 0;
}
@{$objects[$count][$objsize[$count]++]} = ( "$fields[0]", $fields[2], "$size" );
# print "$fields[0] | $fields[1] | $size | $fields[2]\n";
}
doprint();
sub dudump {
my $i;
2018-05-04 16:08:28 +02:00
for( $i = 1; $i <= $count; $i++ ) {
2015-10-21 05:03:22 +02:00
print "\n";
$o = $objects[$i];
my @ob = @{$o};
my $l;
my $j;
for( $j = 0; $j < @ob; $j++ ) {
$l = $ob[$j];
my @a = @{$l};
print "$a[0] ! $a[1] ! $a[2]\n";
}
}
}
sub doprint {
my $i;
2018-05-04 16:08:28 +02:00
print <<EOD
2015-10-21 05:03:22 +02:00
/* THIS IS A GENERATED FILE */
2018-05-04 16:08:28 +02:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2015-10-21 05:03:22 +02:00
#ifndef BUILTINS_H
#include "builtins.h"
#endif /* BUILTINS_H */
EOD
;
foreach $b (sort values(%constants)) {
2018-05-04 16:08:28 +02:00
print $b;
2015-10-21 05:03:22 +02:00
}
2018-05-04 16:08:28 +02:00
for( $i = 1; $i <= $count; $i++ ) {
print "static const CK_ATTRIBUTE_TYPE nss_builtins_types_$i [] = {\n";
2015-10-21 05:03:22 +02:00
$o = $objects[$i];
my @ob = @{$o};
my $j;
for( $j = 0; $j < @ob; $j++ ) {
my $l = $ob[$j];
my @a = @{$l};
2018-05-04 16:08:28 +02:00
print " $a[0]";
2015-10-21 05:03:22 +02:00
if( $j+1 != @ob ) {
2018-05-04 16:08:28 +02:00
print ", ";
2015-10-21 05:03:22 +02:00
}
}
2018-05-04 16:08:28 +02:00
print "\n};\n";
2015-10-21 05:03:22 +02:00
}
2018-05-04 16:08:28 +02:00
for( $i = 1; $i <= $count; $i++ ) {
print "static const NSSItem nss_builtins_items_$i [] = {\n";
2015-10-21 05:03:22 +02:00
$o = $objects[$i];
my @ob = @{$o};
my $j;
for( $j = 0; $j < @ob; $j++ ) {
my $l = $ob[$j];
my @a = @{$l};
2018-05-04 16:08:28 +02:00
print " { (void *)$a[1], (PRUint32)$a[2] }";
2015-10-21 05:03:22 +02:00
if( $j+1 != @ob ) {
2018-05-04 16:08:28 +02:00
print ",\n";
2015-10-21 05:03:22 +02:00
} else {
2018-05-04 16:08:28 +02:00
print "\n";
2015-10-21 05:03:22 +02:00
}
}
2018-05-04 16:08:28 +02:00
print "};\n";
2015-10-21 05:03:22 +02:00
}
2018-05-04 16:08:28 +02:00
print "\nbuiltinsInternalObject\n";
print "nss_builtins_data[] = {\n";
2015-10-21 05:03:22 +02:00
2018-05-04 16:08:28 +02:00
for( $i = 1; $i <= $count; $i++ ) {
print " { $objsize[$i], nss_builtins_types_$i, nss_builtins_items_$i, {NULL} }";
2015-10-21 05:03:22 +02:00
if( $i == $count ) {
2018-05-04 16:08:28 +02:00
print "\n";
2015-10-21 05:03:22 +02:00
} else {
2018-05-04 16:08:28 +02:00
print ",\n";
2015-10-21 05:03:22 +02:00
}
}
2018-05-04 16:08:28 +02:00
print "};\n";
2015-10-21 05:03:22 +02:00
2018-05-04 16:08:28 +02:00
print "const PRUint32\n";
print "nss_builtins_nObjects = $count;\n";
2015-10-21 05:03:22 +02:00
}