📄 mkdef.pl
字号:
$tmp_ =~ /!defined\(([^\)]+)\)/; print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; push(@tag,$1); $tag{$1}=-1; } } else { print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O... print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug; push(@tag,$1); $tag{$1}=-1; } } elsif (/^\#\s*ifdef\s+(\S*)/) { push(@tag,"-"); push(@tag,$1); $tag{$1}=1; print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) { push(@tag,"-"); if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) { my $tmp_1 = $1; my $tmp_; foreach $tmp_ (split '\|\|',$tmp_1) { $tmp_ =~ /defined\(([^\)]+)\)/; print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; push(@tag,$1); $tag{$1}=1; } } else { print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O... print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug; push(@tag,$1); $tag{$1}=1; } } elsif (/^\#\s*error\s+(\w+) is disabled\./) { my $tag_i = $#tag; while($tag[$tag_i] ne "-") { if ($tag[$tag_i] eq "OPENSSL_NO_".$1) { $tag{$tag[$tag_i]}=2; print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug; } $tag_i--; } } elsif (/^\#\s*endif/) { my $tag_i = $#tag; while($tag_i > 0 && $tag[$tag_i] ne "-") { my $t=$tag[$tag_i]; print STDERR "DEBUG: \$t=\"$t\"\n" if $debug; if ($tag{$t}==2) { $tag{$t}=-1; } else { $tag{$t}=0; } print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; pop(@tag); if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) { $t=$1; } else { $t=""; } if ($t ne "" && !grep(/^$t$/, @known_algorithms)) { $unknown_algorithms{$t} = 1; #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug; } $tag_i--; } pop(@tag); } elsif (/^\#\s*else/) { my $tag_i = $#tag; while($tag[$tag_i] ne "-") { my $t=$tag[$tag_i]; $tag{$t}= -$tag{$t}; print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug; $tag_i--; } } elsif (/^\#\s*if\s+1/) { push(@tag,"-"); # Dummy tag push(@tag,"TRUE"); $tag{"TRUE"}=1; print STDERR "DEBUG: $file: found 1\n" if $debug; } elsif (/^\#\s*if\s+0/) { push(@tag,"-"); # Dummy tag push(@tag,"TRUE"); $tag{"TRUE"}=-1; print STDERR "DEBUG: $file: found 0\n" if $debug; } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/ && $symhacking && $tag{'TRUE'} != -1) { # This is for aliasing. When we find an alias, # we have to invert &$make_variant($1,$2); print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug; } if (/^\#/) { @current_platforms = grep(!/^$/, map { $tag{$_} == 1 ? $_ : $tag{$_} == -1 ? "!".$_ : "" } @known_platforms); push @current_platforms , grep(!/^$/, map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" } @known_ossl_platforms); @current_algorithms = grep(!/^$/, map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" } @known_algorithms); $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; next; } if ($tag{'TRUE'} != -1) { if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { next; } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { $def .= "int d2i_$3(void);"; $def .= "int i2d_$3(void);"; # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $2_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$2_it","$2_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) { $def .= "int d2i_$3(void);"; $def .= "int i2d_$3(void);"; $def .= "int $3_free(void);"; $def .= "int $3_new(void);"; # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $2_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$2_it","$2_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ || /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) { $def .= "int d2i_$1(void);"; $def .= "int i2d_$1(void);"; $def .= "int $1_free(void);"; $def .= "int $1_new(void);"; # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $1_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$1_it","$1_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { $def .= "int d2i_$2(void);"; $def .= "int i2d_$2(void);"; # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $2_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$2_it","$2_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_ALLOC_FUNCTIONS\s*\(\s*(\w*)\s*\)/) { $def .= "int $1_free(void);"; $def .= "int $1_new(void);"; next; } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { $def .= "int d2i_$2(void);"; $def .= "int i2d_$2(void);"; $def .= "int $2_free(void);"; $def .= "int $2_new(void);"; # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $2_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$2_it","$2_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) { # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int $1_it;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("$1_it","$1_it", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); next; } elsif (/^\s*DECLARE_ASN1_NDEF_FUNCTION\s*\(\s*(\w*)\s*\)/) { $def .= "int i2d_$1_NDEF(void);"; } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { next; } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) { next; } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ || /^DECLARE_PEM_rw_const\s*\(\s*(\w*)\s*,/ ) { # Things not in Win16 $def .= "#INFO:" .join(',',"!WIN16",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "int PEM_read_$1(void);"; $def .= "int PEM_write_$1(void);"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Things that are everywhere $def .= "int PEM_read_bio_$1(void);"; $def .= "int PEM_write_bio_$1(void);"; next; } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ || /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) { # Things not in Win16 $def .= "#INFO:" .join(',',"!WIN16",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "int PEM_write_$1(void);"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Things that are everywhere $def .= "int PEM_write_bio_$1(void);"; next; } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ || /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) { # Things not in Win16 $def .= "#INFO:" .join(',',"!WIN16",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "int PEM_read_$1(void);"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Things that are everywhere $def .= "int PEM_read_bio_$1(void);"; next; } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) { # Variant for platforms that do not # have to access globale variables # in shared libraries through functions $def .= "#INFO:" .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":" .join(',',@current_algorithms).";"; $def .= "OPENSSL_EXTERN int _shadow_$2;"; $def .= "#INFO:" .join(',',@current_platforms).":" .join(',',@current_algorithms).";"; # Variant for platforms that have to # access globale variables in shared # libraries through functions &$make_variant("_shadow_$2","_shadow_$2", "EXPORT_VAR_AS_FUNCTION", "FUNCTION"); } elsif ($tag{'CONST_STRICT'} != 1) { if (/\{|\/\*|\([^\)]*$/) { $line = $_; } else { $def .= $_; } } } } close(IN); my $algs; my $plays; print STDERR "DEBUG: postprocessing ----------\n" if $debug; foreach (split /;/, $def) { my $s; my $k = "FUNCTION"; my $p; my $a; s/^[\n\s]*//g; s/[\n\s]*$//g; next if(/\#undef/); next if(/typedef\W/); next if(/\#define/); print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug; if (/^\#INFO:([^:]*):(.*)$/) { $plats = $1; $algs = $2; print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug; next; } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) { $s = $1; $k = "VARIABLE"; print STDERR "DEBUG: found external variable $s\n" if $debug; } elsif (/\(\*(\w*(\{[0-9]+\})?)\([^\)]+/) { $s = $1; print STDERR "DEBUG: found ANSI C function $s\n" if $debug; } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s) { # K&R C print STDERR "DEBUG: found K&R C function $s\n" if $debug; next; } elsif (/\w+\W+\w+(\{[0-9]+\})?\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) { while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) { s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s; s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s; } s/\(void\)//; /(\w+(\{[0-9]+\})?)\W*\(\)/s; $s = $1; print STDERR "DEBUG: found function $s\n" if $debug; } elsif (/TYPEDEF_\w+_OF/) { next; } elsif (/\(/ and not (/=/)) { print STDERR "File $file: cannot parse: $_;\n"; next; } else { next; } $syms{$s} = 1; $kind{$s} = $k; $p = $plats; $a = $algs; $a .= ",BF" if($s =~ /EVP_bf/); $a .= ",CAST" if($s =~ /EVP_cast/); $a .= ",DES" if($s =~ /EVP_des/); $a .= ",DSA" if($s =~ /EVP_dss/); $a .= ",IDEA" if($s =~ /EVP_idea/); $a .= ",MD2" if($s =~ /EVP_md2/); $a .= ",MD4" if($s =~ /EVP_md4/); $a .= ",MD5" if($s =~ /EVP_md5/); $a .= ",RC2" if($s =~ /EVP_rc2/); $a .= ",RC4" if($s =~ /EVP_rc4/); $a .= ",RC5" if($s =~ /EVP_rc5/); $a .= ",RIPEMD" if($s =~ /EVP_ripemd/); $a .= ",SHA" if($s =~ /EVP_sha/); $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/); $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/); $a .= ",RSA" if($s =~ /RSAPrivateKey/); $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/); $platform{$s} = &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p); $algorithm{$s} .= ','.$a; if (defined($variant{$s})) { foreach $v (split /;/,$variant{$s}) { (my $r, my $p, my $k) = split(/:/,$v); my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p); $syms{$r} = 1; if (!defined($k)) { $k = $kind{$s}; } $kind{$r} = $k."(".$s.")"; $algorithm{$r} = $algorithm{$s}; $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p); $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip); print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug; } } print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug; } } # Prune the returned symbols delete $syms{"bn_dump1"}; $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh"; $platform{"PEM_read_NS_CERT_SEQ"} = "VMS"; $platform{"PEM_write_NS_CERT_SEQ"} = "VMS"; $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS"; $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS"; # Info we know about push @ret, map { $_."\\".&info_string($_,"EXIST", $platform{$_}, $kind{$_}, $algorithm{$_}) } keys %syms; if (keys %unknown_algorithms) { print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n"; print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n"; } return(@ret);}# Param: string of comma-separated platform-specs.sub reduce_platforms{ my ($platforms) = @_; my $pl = defined($platforms) ? $platforms : ""; my %p = map { $_ => 0 } split /,/, $pl; my $ret; print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n" if $debug; # We do this, because if there's code like the following, it really # means the function exists in all cases and should therefore be # everywhere. By increasing and decreasing, we may attain 0: # # ifndef WIN16 # int foo(); # else # int _fat foo();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -