From 927cbf74ae1c08876a717f739449177d03740f2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 5 Jul 2006 20:49:50 +0000 Subject: r16824: Rename Ethereal -> Wireshark (patch from Joerg Mayer) (This used to be commit a789aa468b2b2b631289dd65888b352de46ad900) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 1054 ++++++++++++++++++++++++++ 1 file changed, 1054 insertions(+) create mode 100644 source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm new file mode 100644 index 0000000000..872a149274 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -0,0 +1,1054 @@ +################################################## +# Samba4 NDR parser generator for IDL structures +# Copyright tridge@samba.org 2000-2003 +# Copyright tpot@samba.org 2001,2005 +# Copyright jelmer@samba.org 2004-2005 +# Portions based on idl2eth.c by Ronnie Sahlberg +# released under the GNU GPL + +=pod + +=head1 NAME + +Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark + +=cut + +package Parse::Pidl::Wireshark::NDR; + +use strict; +use Parse::Pidl::Typelist qw(getType); +use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str); +use Parse::Pidl::NDR qw(ContainsString GetNextLevel); +use Parse::Pidl::Dump qw(DumpTypedef DumpFunction); +use Parse::Pidl::Wireshark::Conformance qw(ReadConformance); +use File::Basename; + +use vars qw($VERSION); +$VERSION = '0.01'; + +sub error($$) +{ + my ($e,$t) = @_; + print "$e->{FILE}:$e->{LINE}: $t\n"; +} + +my @ett; + +my %hf_used = (); +my %dissector_used = (); + +my $conformance = undef; + +my %ptrtype_mappings = ( + "unique" => "NDR_POINTER_UNIQUE", + "ref" => "NDR_POINTER_REF", + "ptr" => "NDR_POINTER_PTR" +); + +sub StripPrefixes($) +{ + my ($s) = @_; + + foreach (@{$conformance->{strip_prefixes}}) { + $s =~ s/^$_\_//g; + } + + return $s; +} + +# Convert a IDL structure field name (e.g access_mask) to a prettier +# string like 'Access Mask'. + +sub field2name($) +{ + my($field) = shift; + + $field =~ s/_/ /g; # Replace underscores with spaces + $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word + + return $field; +} + +my %res = (); +my $tabs = ""; +my $cur_fn = undef; +sub pidl_fn_start($) +{ + my $fn = shift; + $cur_fn = $fn; +} +sub pidl_fn_end($) +{ + my $fn = shift; + die("Inconsistent state: $fn != $cur_fn") if ($fn ne $cur_fn); + $cur_fn = undef; +} + +sub pidl_code($) +{ + my $d = shift; + return if (defined($cur_fn) and defined($conformance->{manual}->{$cur_fn})); + + if ($d) { + $res{code} .= $tabs; + $res{code} .= $d; + } + $res{code} .="\n"; +} + +sub pidl_hdr($) { my $x = shift; $res{hdr} .= "$x\n"; } +sub pidl_def($) { my $x = shift; $res{def} .= "$x\n"; } + +sub indent() +{ + $tabs .= "\t"; +} + +sub deindent() +{ + $tabs = substr($tabs, 0, -1); +} + +sub PrintIdl($) +{ + my $idl = shift; + + foreach (split /\n/, $idl) { + pidl_code "/* IDL: $_ */"; + } + + pidl_code ""; +} + +##################################################################### +# parse the interface definitions +sub Interface($) +{ + my($interface) = @_; + Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}}); + Typedef($_,$interface->{NAME}) foreach (@{$interface->{TYPES}}); + Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}}); +} + +sub Enum($$$) +{ + my ($e,$name,$ifname) = @_; + my $valsstring = "$ifname\_$name\_vals"; + my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name); + + return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + + foreach (@{$e->{ELEMENTS}}) { + if (/([^=]*)=(.*)/) { + pidl_hdr "#define $1 ($2)"; + } + } + + pidl_hdr "extern const value_string $valsstring\[];"; + pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);"; + + pidl_def "const value_string ".$valsstring."[] = {"; + foreach (@{$e->{ELEMENTS}}) { + next unless (/([^=]*)=(.*)/); + pidl_def "\t{ $1, \"$1\" },"; + } + + pidl_def "{ 0, NULL }"; + pidl_def "};"; + + pidl_fn_start $dissectorname; + pidl_code "int"; + pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "{"; + indent; + pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, NULL);"; + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end $dissectorname; + + my $enum_size = $e->{BASE_TYPE}; + $enum_size =~ s/uint//g; + register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); +} + +sub Bitmap($$$) +{ + my ($e,$name,$ifname) = @_; + my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name); + + register_ett("ett_$ifname\_$name"); + + pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);"; + + pidl_fn_start $dissectorname; + pidl_code "int"; + pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "{"; + indent; + pidl_code "proto_item *item = NULL;"; + pidl_code "proto_tree *tree = NULL;"; + pidl_code ""; + + pidl_code "g$e->{BASE_TYPE} flags;"; + if ($e->{ALIGN} > 1) { + pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + } + + pidl_code ""; + + pidl_code "if (parent_tree) {"; + indent; + pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);"; + pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);"; + deindent; + pidl_code "}\n"; + + pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);"; + + pidl_code "proto_item_append_text(item, \": \");\n"; + pidl_code "if (!flags)"; + pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n"; + + foreach (@{$e->{ELEMENTS}}) { + next unless (/([^ ]*) (.*)/); + my ($en,$ev) = ($1,$2); + my $hf_bitname = "hf_$ifname\_$name\_$en"; + my $filtername = "$ifname\.$name\.$en"; + + $hf_used{$hf_bitname} = 1; + + register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, ""); + + pidl_def "static const true_false_string $name\_$en\_tfs = {"; + if (defined($conformance->{tfs}->{$hf_bitname})) { + pidl_def " $conformance->{tfs}->{$hf_bitname}->{TRUE_STRING},"; + pidl_def " $conformance->{tfs}->{$hf_bitname}->{FALSE_STRING},"; + $conformance->{tfs}->{$hf_bitname}->{USED} = 1; + } else { + pidl_def " \"$en is SET\","; + pidl_def " \"$en is NOT SET\","; + } + pidl_def "};"; + + pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);"; + pidl_code "if (flags&$ev){"; + pidl_code "\tproto_item_append_text(item, \"$en\");"; + pidl_code "\tif (flags & (~$ev))"; + pidl_code "\t\tproto_item_append_text(item, \", \");"; + pidl_code "}"; + pidl_code "flags&=(~$ev);"; + pidl_code ""; + } + + pidl_code "if (flags) {"; + pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);"; + pidl_code "}\n"; + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end $dissectorname; + + my $size = $e->{BASE_TYPE}; + $size =~ s/uint//g; + register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); +} + +sub ElementLevel($$$$$) +{ + my ($e,$l,$hf,$myname,$pn) = @_; + + my $param = 0; + + if (defined($conformance->{dissectorparams}->{$myname})) { + $conformance->{dissectorparams}->{$myname}->{PARAM} = 1; + $param = $conformance->{dissectorparams}->{$myname}->{PARAM}; + } + + if ($l->{TYPE} eq "POINTER") { + my $type; + if ($l->{LEVEL} eq "TOP") { + $type = "toplevel"; + } elsif ($l->{LEVEL} eq "EMBEDDED") { + $type = "embedded"; + } + pidl_code "offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME})) . " ($e->{TYPE})\",$hf);"; + } elsif ($l->{TYPE} eq "ARRAY") { + if ($l->{IS_INLINE}) { + error($e->{ORIGINAL}, "Inline arrays not supported"); + } elsif ($l->{IS_FIXED}) { + pidl_code "int i;"; + pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)"; + pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);"; + } else { + my $type = ""; + $type .= "c" if ($l->{IS_CONFORMANT}); + $type .= "v" if ($l->{IS_VARYING}); + + unless ($l->{IS_ZERO_TERMINATED}) { + pidl_code "offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);"; + } else { + my $nl = GetNextLevel($e,$l); + pidl_code "char *data;"; + pidl_code ""; + pidl_code "offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);"; + pidl_code "proto_item_append_text(tree, \": %s\", data);"; + } + } + } elsif ($l->{TYPE} eq "DATA") { + if ($l->{DATA_TYPE} eq "string") { + my $bs = 2; # Byte size defaults to that of UCS2 + + + ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*")); + + if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) { + pidl_code "char *data;\n"; + pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);"; + pidl_code "proto_item_append_text(tree, \": %s\", data);"; + } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) { + pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);"; + } else { + warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}"); + } + } else { + my $call; + + if ($conformance->{imports}->{$l->{DATA_TYPE}}) { + $call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA}; + $conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1; + } elsif (defined($conformance->{imports}->{"$pn.$e->{NAME}"})) { + $call = $conformance->{imports}->{"$pn.$e->{NAME}"}->{DATA}; + $conformance->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1; + + } elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) { + $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; + $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1; + } else { + if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/) + { + pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);"; + } + + return; + } + + $call =~ s/\@HF\@/$hf/g; + $call =~ s/\@PARAM\@/$param/g; + pidl_code "$call"; + } + } elsif ($_->{TYPE} eq "SUBCONTEXT") { + my $num_bits = ($l->{HEADER_SIZE}*8); + pidl_code "guint$num_bits size;"; + pidl_code "int start_offset = offset;"; + pidl_code "tvbuff_t *subtvb;"; + pidl_code "offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);"; + pidl_code "proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");"; + + pidl_code "subtvb = tvb_new_subset(tvb, offset, size, -1);"; + pidl_code "$myname\_(subtvb, 0, pinfo, tree, drep);"; + } else { + die("Unknown type `$_->{TYPE}'"); + } +} + +sub Element($$$) +{ + my ($e,$pn,$ifname) = @_; + + my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn)."\_".StripPrefixes($e->{NAME}); + + my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; + + my $type = find_type($e->{TYPE}); + + if (not defined($type)) { + # default settings + $type = { + MASK => 0, + VALSSTRING => "NULL", + FT_TYPE => "FT_NONE", + BASE_TYPE => "BASE_HEX" + }; + } + + if (ContainsString($e)) { + $type = { + MASK => 0, + VALSSTRING => "NULL", + FT_TYPE => "FT_STRING", + BASE_TYPE => "BASE_DEC" + }; + } + + my $hf = register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", $type->{FT_TYPE}, $type->{BASE_TYPE}, $type->{VALSSTRING}, $type->{MASK}, ""); + $hf_used{$hf} = 1; + + my $eltname = StripPrefixes($pn) . ".$e->{NAME}"; + if (defined($conformance->{noemit}->{$eltname})) { + return $call_code; + } + + my $add = ""; + + foreach (@{$e->{LEVELS}}) { + next if ($_->{TYPE} eq "SWITCH"); + pidl_def "static int $dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep);"; + pidl_fn_start "$dissectorname$add"; + pidl_code "static int"; + pidl_code "$dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)"; + pidl_code "{"; + indent; + + ElementLevel($e,$_,$hf,$dissectorname.$add,$pn); + + pidl_code ""; + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end "$dissectorname$add"; + $add.="_"; + last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED}); + } + + return $call_code; +} + +sub Function($$$) +{ + my ($fn,$ifname) = @_; + + my %dissectornames; + + foreach (@{$fn->{ELEMENTS}}) { + $dissectornames{$_->{NAME}} = Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}}); + } + + my $fn_name = $_->{NAME}; + $fn_name =~ s/^${ifname}_//; + + PrintIdl DumpFunction($fn->{ORIGINAL}); + pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; + pidl_code "static int"; + pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "{"; + indent; + pidl_code "guint32 status;\n"; + foreach (@{$fn->{ELEMENTS}}) { + if (grep(/out/,@{$_->{DIRECTION}})) { + pidl_code "$dissectornames{$_->{NAME}}"; + pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"; + pidl_code ""; + } + } + + if (not defined($fn->{RETURN_TYPE})) { + } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { + pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"; + pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; + pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"; + $hf_used{"hf\_$ifname\_status"} = 1; + } elsif ($fn->{RETURN_TYPE} eq "WERROR") { + pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"; + pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; + pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, DOS_errors, \"Unknown DOS error 0x%08x\"));\n"; + + $hf_used{"hf\_$ifname\_werror"} = 1; + } else { + print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; + } + + + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end "$ifname\_dissect\_$fn_name\_response"; + + pidl_fn_start "$ifname\_dissect\_$fn_name\_request"; + pidl_code "static int"; + pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "{"; + indent; + foreach (@{$fn->{ELEMENTS}}) { + if (grep(/in/,@{$_->{DIRECTION}})) { + pidl_code "$dissectornames{$_->{NAME}}"; + pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"; + } + + } + + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end "$ifname\_dissect\_$fn_name\_request"; +} + +sub Struct($$$) +{ + my ($e,$name,$ifname) = @_; + my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name); + + return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + + register_ett("ett_$ifname\_$name"); + + my $res = ""; + ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}}); + + pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_);"; + + pidl_fn_start $dissectorname; + pidl_code "int"; + pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "{"; + indent; + pidl_code "proto_item *item = NULL;"; + pidl_code "proto_tree *tree = NULL;"; + pidl_code "int old_offset;"; + pidl_code ""; + + if ($e->{ALIGN} > 1) { + pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + } + pidl_code ""; + + pidl_code "old_offset = offset;"; + pidl_code ""; + pidl_code "if (parent_tree) {"; + indent; + pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);"; + pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);"; + deindent; + pidl_code "}"; + + pidl_code "\n$res"; + + pidl_code "proto_item_set_len(item, offset-old_offset);\n"; + pidl_code "return offset;"; + deindent; + pidl_code "}\n"; + pidl_fn_end $dissectorname; + + register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); +} + +sub Union($$$) +{ + my ($e,$name,$ifname) = @_; + + my $dissectorname = "$ifname\_dissect_".StripPrefixes($name); + + return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + + register_ett("ett_$ifname\_$name"); + + my $res = ""; + foreach (@{$e->{ELEMENTS}}) { + $res.="\n\t\t$_->{CASE}:\n"; + if ($_->{TYPE} ne "EMPTY") { + $res.="\t\t\t".Element($_, $name, $ifname)."\n"; + } + $res.="\t\tbreak;\n"; + } + + my $switch_type; + my $switch_dissect; + my $switch_dt = getType($e->{SWITCH_TYPE}); + if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { + $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt); + $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt); + } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { + $switch_type = "g$e->{SWITCH_TYPE}"; + $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}"; + } + + pidl_fn_start $dissectorname; + pidl_code "static int"; + pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "{"; + indent; + pidl_code "proto_item *item = NULL;"; + pidl_code "proto_tree *tree = NULL;"; + pidl_code "int old_offset;"; + pidl_code "$switch_type level;"; + pidl_code ""; + + if ($e->{ALIGN} > 1) { + pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + } + + pidl_code ""; + + pidl_code "old_offset = offset;"; + pidl_code "if (parent_tree) {"; + indent; + pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");"; + pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);"; + deindent; + pidl_code "}"; + + pidl_code ""; + + pidl_code "offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"; + + pidl_code "switch(level) {$res\t}"; + pidl_code "proto_item_set_len(item, offset-old_offset);\n"; + pidl_code "return offset;"; + deindent; + pidl_code "}"; + pidl_fn_end $dissectorname; + + register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); +} + +sub Const($$) +{ + my ($const,$ifname) = @_; + + if (!defined($const->{ARRAY_LEN}[0])) { + pidl_hdr "#define $const->{NAME}\t( $const->{VALUE} )\n"; + } else { + pidl_hdr "#define $const->{NAME}\t $const->{VALUE}\n"; + } +} + +sub Typedef($$) +{ + my ($e,$ifname) = @_; + + PrintIdl DumpTypedef($e->{ORIGINAL}); + + { + ENUM => \&Enum, + STRUCT => \&Struct, + UNION => \&Union, + BITMAP => \&Bitmap + }->{$e->{DATA}->{TYPE}}->($e->{DATA}, $e->{NAME}, $ifname); +} + +sub RegisterInterface($) +{ + my ($x) = @_; + + pidl_fn_start "proto_register_dcerpc_$x->{NAME}"; + pidl_code "void proto_register_dcerpc_$x->{NAME}(void)"; + pidl_code "{"; + indent; + + $res{code}.=DumpHfList()."\n"; + $res{code}.="\n".DumpEttList()."\n"; + + if (defined($x->{UUID})) { + # These can be changed to non-pidl_code names if the old dissectors + # in epan/dissctors are deleted. + + my $name = uc($x->{NAME}) . " (pidl)"; + my $short_name = uc($x->{NAME}); + my $filter_name = $x->{NAME}; + + if (has_property($x, "helpstring")) { + $name = $x->{PROPERTIES}->{helpstring}; + } + + if (defined($conformance->{protocols}->{$x->{NAME}})) { + $short_name = $conformance->{protocols}->{$x->{NAME}}->{SHORTNAME}; + $name = $conformance->{protocols}->{$x->{NAME}}->{LONGNAME}; + $filter_name = $conformance->{protocols}->{$x->{NAME}}->{FILTERNAME}; + } + + pidl_code "proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");"; + + pidl_code "proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));"; + pidl_code "proto_register_subtree_array(ett, array_length(ett));"; + } else { + pidl_code "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");"; + pidl_code "proto_register_field_array(proto_dcerpc, hf, array_length(hf));"; + pidl_code "proto_register_subtree_array(ett, array_length(ett));"; + } + + deindent; + pidl_code "}\n"; + pidl_fn_end "proto_register_dcerpc_$x->{NAME}"; +} + +sub RegisterInterfaceHandoff($) +{ + my $x = shift; + + if (defined($x->{UUID})) { + pidl_fn_start "proto_reg_handoff_dcerpc_$x->{NAME}"; + pidl_code "void proto_reg_handoff_dcerpc_$x->{NAME}(void)"; + pidl_code "{"; + indent; + pidl_code "dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},"; + pidl_code "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},"; + pidl_code "\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);"; + deindent; + pidl_code "}"; + pidl_fn_end "proto_reg_handoff_dcerpc_$x->{NAME}"; + + $hf_used{"hf_$x->{NAME}_opnum"} = 1; + } +} + +sub ProcessInterface($) +{ + my ($x) = @_; + + push(@{$conformance->{strip_prefixes}}, $x->{NAME}); + + my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H"; + pidl_hdr "#ifndef $define"; + pidl_hdr "#define $define"; + pidl_hdr ""; + + if (defined $x->{PROPERTIES}->{depends}) { + foreach (split / /, $x->{PROPERTIES}->{depends}) { + next if($_ eq "security"); + pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n"; + } + } + + pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;"; + register_ett("ett_dcerpc_$x->{NAME}"); + register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, ""); + + if (defined($x->{UUID})) { + my $if_uuid = $x->{UUID}; + + pidl_def "/* Version information */\n\n"; + + pidl_def "static e_uuid_t uuid_dcerpc_$x->{NAME} = {"; + pidl_def "\t0x" . substr($if_uuid, 1, 8) + . ", 0x" . substr($if_uuid, 10, 4) + . ", 0x" . substr($if_uuid, 15, 4) . ","; + pidl_def "\t{ 0x" . substr($if_uuid, 20, 2) + . ", 0x" . substr($if_uuid, 22, 2) + . ", 0x" . substr($if_uuid, 25, 2) + . ", 0x" . substr($if_uuid, 27, 2) + . ", 0x" . substr($if_uuid, 29, 2) + . ", 0x" . substr($if_uuid, 31, 2) + . ", 0x" . substr($if_uuid, 33, 2) + . ", 0x" . substr($if_uuid, 35, 2) . " }"; + pidl_def "};"; + + my $maj = $x->{VERSION}; + $maj =~ s/\.(.*)$//g; + pidl_def "static guint16 ver_dcerpc_$x->{NAME} = $maj;"; + pidl_def ""; + } + + Interface($x); + + pidl_code "\n".DumpFunctionTable($x); + + # Only register these two return types if they were actually used + if (defined($hf_used{"hf_$x->{NAME}_status"})) { + register_hf_field("hf_$x->{NAME}_status", "Status", "$x->{NAME}.status", "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", 0, ""); + } + + if (defined($hf_used{"hf_$x->{NAME}_werror"})) { + register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(DOS_errors)", 0, ""); + } + + RegisterInterface($x); + RegisterInterfaceHandoff($x); + + pidl_hdr "#endif /* $define */"; +} + +sub find_type($) +{ + my $n = shift; + + return $conformance->{types}->{$n}; +} + +sub register_type($$$$$$$) +{ + my ($type,$call,$ft,$base,$mask,$vals,$length) = @_; + + $conformance->{types}->{$type} = { + NAME => $type, + DISSECTOR_NAME => $call, + FT_TYPE => $ft, + BASE_TYPE => $base, + MASK => $mask, + VALSSTRING => $vals, + ALIGNMENT => $length + }; +} + +# Loads the default types +sub Initialize($) +{ + my $cnf_file = shift; + + $conformance = { + imports => {}, + header_fields=> {} + }; + + ReadConformance($cnf_file, $conformance) or print "Warning: No conformance file `$cnf_file'\n"; + + foreach my $bytes (qw(1 2 4 8)) { + my $bits = $bytes * 8; + register_type("uint$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@,NULL);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); + register_type("int$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); + } + + register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); + register_type("bool8", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + register_type("char", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + register_type("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4); + register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); + register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); + register_type("policy_handle", "offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, NULL, NULL, \@PARAM\@&0x01, \@PARAM\@&0x02);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); + register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4); + register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + register_type("SID", " + dcerpc_info *di = (dcerpc_info *)pinfo->private_data; + + di->hf_index = \@HF\@; + + offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); + ","FT_STRING", "BASE_DEC", 0, "NULL", 4); + register_type("WERROR", + "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); + +} + +##################################################################### +# Generate Wireshark parser and header code +sub Parse($$$$) +{ + my($ndr,$idl_file,$h_filename,$cnf_file) = @_; + Initialize($cnf_file); + + return (undef, undef) if defined($conformance->{noemit_dissector}); + + $tabs = ""; + + %res = (code=>"",def=>"",hdr=>""); + @ett = (); + + my $notice = +"/* DO NOT EDIT + This filter was automatically generated + from $idl_file and $cnf_file. + + Pidl is a perl based IDL compiler for DCE/RPC idl files. + It is maintained by the Samba team, not the Wireshark team. + Instructions on how to download and install Pidl can be + found at http://wiki.wireshark.org/Pidl +*/ + +"; + + pidl_hdr $notice; + + $res{headers} = "\n"; + $res{headers} .= "#ifdef HAVE_CONFIG_H\n"; + $res{headers} .= "#include \"config.h\"\n"; + $res{headers} .= "#endif\n\n"; + $res{headers} .= "#include \n"; + $res{headers} .= "#include \n"; + $res{headers} .= "#include \n\n"; + + $res{headers} .= "#include \"packet-dcerpc.h\"\n"; + $res{headers} .= "#include \"packet-dcerpc-nt.h\"\n"; + $res{headers} .= "#include \"packet-windows-common.h\"\n"; + + my $h_basename = basename($h_filename); + + $res{headers} .= "#include \"$h_basename\"\n"; + pidl_code ""; + + # Wireshark protocol registration + + ProcessInterface($_) foreach (@$ndr); + + $res{ett} = DumpEttDeclaration(); + $res{hf} = DumpHfDeclaration(); + + my $parser = $notice; + $parser.= $res{headers}; + $parser.=$res{ett}; + $parser.=$res{hf}; + $parser.=$res{def}; + $parser.=$conformance->{override}; + $parser.=$res{code}; + + my $header = "/* autogenerated by pidl */\n\n"; + $header.=$res{hdr}; + + CheckUsed($conformance); + + return ($parser,$header); +} + +############################################################################### +# ETT +############################################################################### + +sub register_ett($) +{ + my $name = shift; + + push (@ett, $name); +} + +sub DumpEttList() +{ + my $res = "\tstatic gint *ett[] = {\n"; + foreach (@ett) { + $res .= "\t\t&$_,\n"; + } + + return "$res\t};\n"; +} + +sub DumpEttDeclaration() +{ + my $res = "\n/* Ett declarations */\n"; + foreach (@ett) { + $res .= "static gint $_ = -1;\n"; + } + + return "$res\n"; +} + +############################################################################### +# HF +############################################################################### + +sub register_hf_field($$$$$$$$) +{ + my ($index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_; + + if (defined ($conformance->{hf_renames}->{$index})) { + $conformance->{hf_renames}->{$index}->{USED} = 1; + return $conformance->{hf_renames}->{$index}->{NEWNAME}; + } + + $conformance->{header_fields}->{$index} = { + INDEX => $index, + NAME => $name, + FILTER => $filter_name, + FT_TYPE => $ft_type, + BASE_TYPE => $base_type, + VALSSTRING => $valsstring, + MASK => $mask, + BLURB => $blurb + }; + + if ((not defined($blurb) or $blurb eq "") and + defined($conformance->{fielddescription}->{$index})) { + $conformance->{header_fields}->{$index}->{BLURB} = + $conformance->{fielddescription}->{$index}->{DESCRIPTION}; + $conformance->{fielddescription}->{$index}->{USED} = 1; + } + + return $index; +} + +sub DumpHfDeclaration() +{ + my $res = ""; + + $res = "\n/* Header field declarations */\n"; + + foreach (keys %{$conformance->{header_fields}}) + { + $res .= "static gint $_ = -1;\n"; + } + + return "$res\n"; +} + +sub DumpHfList() +{ + my $res = "\tstatic hf_register_info hf[] = {\n"; + + foreach (values %{$conformance->{header_fields}}) + { + $res .= "\t{ &$_->{INDEX}, + { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str($_->{BLURB}).", HFILL }}, +"; + } + + return $res."\t};\n"; +} + + +############################################################################### +# Function table +############################################################################### + +sub DumpFunctionTable($) +{ + my $if = shift; + + my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n"; + foreach (@{$if->{FUNCTIONS}}) { + my $fn_name = $_->{NAME}; + $fn_name =~ s/^$if->{NAME}_//; + $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n"; + $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n"; + } + + $res .= "\t{ 0, NULL, NULL, NULL }\n"; + + return "$res};\n"; +} + +sub CheckUsed($) +{ + my $conformance = shift; + foreach (values %{$conformance->{header_fields}}) { + if (not defined($hf_used{$_->{INDEX}})) { + print "$_->{POS}: warning: hf field `$_->{INDEX}' not used\n"; + } + } + + foreach (values %{$conformance->{hf_renames}}) { + if (not $_->{USED}) { + print "$_->{POS}: warning: hf field `$_->{OLDNAME}' not used\n"; + } + } + + foreach (values %{$conformance->{dissectorparams}}) { + if (not $_->{USED}) { + print "$_->{POS}: warning: dissector param never used\n"; + } + } + + foreach (values %{$conformance->{imports}}) { + if (not $_->{USED}) { + print "$_->{POS}: warning: import never used\n"; + } + } + + foreach (values %{$conformance->{types}}) { + if (not $_->{USED} and defined($_->{POS})) { + print "$_->{POS}: warning: type never used\n"; + } + } + + foreach (values %{$conformance->{fielddescription}}) { + if (not $_->{USED}) { + print "$_->{POS}: warning: description never used\n"; + } + } + + foreach (values %{$conformance->{tfs}}) { + if (not $_->{USED}) { + print "$_->{POS}: warning: True/False description never used\n"; + } + } +} + +1; -- cgit From 4d3434ff6e83799a1690b3ad3475beb3ef6f12ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 24 Sep 2006 16:39:28 +0000 Subject: r18873: Use WERR_errors table rather than DOS_errors table for wireshark. (This used to be commit 5a2e103ea0b31e80e4b2c2237b5fd9940820cec6) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 872a149274..b91ba10e98 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -452,7 +452,7 @@ sub Function($$$) } elsif ($fn->{RETURN_TYPE} eq "WERROR") { pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; - pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, DOS_errors, \"Unknown DOS error 0x%08x\"));\n"; + pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"; $hf_used{"hf\_$ifname\_werror"} = 1; } else { @@ -749,7 +749,7 @@ sub ProcessInterface($) } if (defined($hf_used{"hf_$x->{NAME}_werror"})) { - register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(DOS_errors)", 0, ""); + register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(WERR_errors)", 0, ""); } RegisterInterface($x); -- cgit From 36b971bb3c77894bca4f83901f8c673f14480b0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 4 Nov 2006 01:53:29 +0000 Subject: r19545: Allow enums as return types in code generated for wireshark. Originally based on a patch by Julien Kerihuel. (This used to be commit 705cd03c53f097086ef4f5aee9311a45bd19afa2) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 52 ++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index b91ba10e98..2a636139de 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -36,6 +36,7 @@ sub error($$) my @ett; my %hf_used = (); +my %return_types = (); my %dissector_used = (); my $conformance = undef; @@ -146,7 +147,7 @@ sub Enum($$$) } pidl_hdr "extern const value_string $valsstring\[];"; - pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);"; + pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 *param);"; pidl_def "const value_string ".$valsstring."[] = {"; foreach (@{$e->{ELEMENTS}}) { @@ -159,10 +160,10 @@ sub Enum($$$) pidl_fn_start $dissectorname; pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 *param)"; pidl_code "{"; indent; - pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, NULL);"; + pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, param);"; pidl_code "return offset;"; deindent; pidl_code "}\n"; @@ -434,7 +435,20 @@ sub Function($$$) pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; - pidl_code "guint32 status;\n"; + if ( not defined($fn->{RETURN_TYPE})) { + } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR") + { + pidl_code "guint32 status;\n"; + } elsif (my $type = getType($fn->{RETURN_TYPE})) { + if ($type->{DATA}->{TYPE} eq "ENUM") { + pidl_code "g".Parse::Pidl::Typelist::enum_type_fn($type) . " status;\n"; + } else { + print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; + } + } else { + print "$fn->{FILE}:$fn->{LINE}: error: unknown return type `$fn->{RETURN_TYPE}'\n"; + } + foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$_->{DIRECTION}})) { pidl_code "$dissectornames{$_->{NAME}}"; @@ -448,15 +462,23 @@ sub Function($$$) pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"; - $hf_used{"hf\_$ifname\_status"} = 1; + $return_types{$ifname}->{"status"} = ["NTSTATUS", "Windows Error"]; } elsif ($fn->{RETURN_TYPE} eq "WERROR") { pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"; - $hf_used{"hf\_$ifname\_werror"} = 1; - } else { - print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; + $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"]; + } elsif (my $type = getType($fn->{RETURN_TYPE})) { + if ($type->{DATA}->{TYPE} eq "ENUM") { + my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type); + my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type); + + pidl_code "offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"; + pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; + pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"; + $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; + } } @@ -739,17 +761,17 @@ sub ProcessInterface($) pidl_def ""; } + $return_types{$x->{NAME}} = {}; + Interface($x); pidl_code "\n".DumpFunctionTable($x); - # Only register these two return types if they were actually used - if (defined($hf_used{"hf_$x->{NAME}_status"})) { - register_hf_field("hf_$x->{NAME}_status", "Status", "$x->{NAME}.status", "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", 0, ""); - } - - if (defined($hf_used{"hf_$x->{NAME}_werror"})) { - register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(WERR_errors)", 0, ""); + foreach (keys %{$return_types{$x->{NAME}}}) { + my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}}; + my $dt = find_type($type); + register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, ""); + $hf_used{"hf_$x->{NAME}_$_"} = 1; } RegisterInterface($x); -- cgit From 77d1be3e8da0c4796a518e15e16d4083445613c7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 4 Nov 2006 02:54:24 +0000 Subject: r19547: Fix use of v1_enum on enums used in return types. (This used to be commit dbae9b4e4ea38806062ba34dcf05a67c2e7af043) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 2a636139de..8793dd5774 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -441,7 +441,7 @@ sub Function($$$) pidl_code "guint32 status;\n"; } elsif (my $type = getType($fn->{RETURN_TYPE})) { if ($type->{DATA}->{TYPE} eq "ENUM") { - pidl_code "g".Parse::Pidl::Typelist::enum_type_fn($type) . " status;\n"; + pidl_code "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n"; } else { print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; } @@ -471,8 +471,8 @@ sub Function($$$) $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"]; } elsif (my $type = getType($fn->{RETURN_TYPE})) { if ($type->{DATA}->{TYPE} eq "ENUM") { - my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type); - my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type); + my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); + my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); pidl_code "offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; @@ -578,8 +578,8 @@ sub Union($$$) my $switch_dissect; my $switch_dt = getType($e->{SWITCH_TYPE}); if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { - $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt); - $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt); + $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); + $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { $switch_type = "g$e->{SWITCH_TYPE}"; $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}"; -- cgit From 6031841dd8c605af09889ee3c3128224ef833c32 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 4 Nov 2006 20:24:35 +0000 Subject: r19557: Fix lookup table for WERROR. Fix perl warnings when using NTSTATUS as return type. (This used to be commit 577cd1625d97efae7bb397570de81a6a5ac0b1b0) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 8793dd5774..e211a896ad 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -462,7 +462,7 @@ sub Function($$$) pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"; - $return_types{$ifname}->{"status"} = ["NTSTATUS", "Windows Error"]; + $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"]; } elsif ($fn->{RETURN_TYPE} eq "WERROR") { pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"; pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; @@ -770,6 +770,7 @@ sub ProcessInterface($) foreach (keys %{$return_types{$x->{NAME}}}) { my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}}; my $dt = find_type($type); + $dt or die("Unable to find information about return type `$type'"); register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, ""); $hf_used{"hf_$x->{NAME}_$_"} = 1; } @@ -839,6 +840,8 @@ sub Initialize($) offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); ","FT_STRING", "BASE_DEC", 0, "NULL", 4); register_type("WERROR", + "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); + register_type("NTSTATUS", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); } -- cgit From 5b9f1b01ba6880ead4662bb66988bcdf5bf2aa82 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 4 Nov 2006 21:53:00 +0000 Subject: r19559: Fix handling of types where the name isn't prefixed by the interface name. Based on patch by Julien Kerihuel. (This used to be commit 466e9c12a5f9bd2f7bf00c710bd9a537b48e7864) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index e211a896ad..5af7c02032 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -256,9 +256,9 @@ sub Bitmap($$$) register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); } -sub ElementLevel($$$$$) +sub ElementLevel($$$$$$) { - my ($e,$l,$hf,$myname,$pn) = @_; + my ($e,$l,$hf,$myname,$pn,$ifname) = @_; my $param = 0; @@ -327,10 +327,7 @@ sub ElementLevel($$$$$) $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1; } else { - if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/) - { - pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);"; - } + pidl_code "offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);"; return; } @@ -402,7 +399,7 @@ sub Element($$$) pidl_code "{"; indent; - ElementLevel($e,$_,$hf,$dissectorname.$add,$pn); + ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname); pidl_code ""; pidl_code "return offset;"; -- cgit From ae0219cd8148bd01179f1686e8e12cf3ccdbf1a9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Nov 2006 00:03:44 +0000 Subject: r19560: Fix handling of PARAM_VALUE. (This used to be commit dde3d5342cd8b67ec4a0929f3e5577d6b1e7d16b) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 5af7c02032..f72efc7534 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -263,7 +263,7 @@ sub ElementLevel($$$$$$) my $param = 0; if (defined($conformance->{dissectorparams}->{$myname})) { - $conformance->{dissectorparams}->{$myname}->{PARAM} = 1; +# $conformance->{dissectorparams}->{$myname}->{PARAM} = 1; $param = $conformance->{dissectorparams}->{$myname}->{PARAM}; } @@ -426,6 +426,8 @@ sub Function($$$) my $fn_name = $_->{NAME}; $fn_name =~ s/^${ifname}_//; + print "$fn_name\n"; + PrintIdl DumpFunction($fn->{ORIGINAL}); pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; pidl_code "static int"; -- cgit From bdf1f0b0db569f65c1501df67788c4f9b7a66966 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Nov 2006 00:08:39 +0000 Subject: r19561: Remove debug statement. (This used to be commit 910b56e72924661f30e43ca0e832b743e8d78d19) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index f72efc7534..c5a39a4c42 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -263,7 +263,6 @@ sub ElementLevel($$$$$$) my $param = 0; if (defined($conformance->{dissectorparams}->{$myname})) { -# $conformance->{dissectorparams}->{$myname}->{PARAM} = 1; $param = $conformance->{dissectorparams}->{$myname}->{PARAM}; } @@ -426,8 +425,6 @@ sub Function($$$) my $fn_name = $_->{NAME}; $fn_name =~ s/^${ifname}_//; - print "$fn_name\n"; - PrintIdl DumpFunction($fn->{ORIGINAL}); pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; pidl_code "static int"; -- cgit From a7b18e70dd315efc15045d32c0c2bfdb76cf4805 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Nov 2006 00:26:44 +0000 Subject: r19562: Support returning simple scalars. (This used to be commit 8bd12d3fdb23a532bf6b46bc88a21837303a0374) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index c5a39a4c42..8c75d590e0 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -438,6 +438,8 @@ sub Function($$$) } elsif (my $type = getType($fn->{RETURN_TYPE})) { if ($type->{DATA}->{TYPE} eq "ENUM") { pidl_code "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n"; + } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { + pidl_code "g$fn->{RETURN_TYPE} status;\n"; } else { print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; } @@ -474,6 +476,11 @@ sub Function($$$) pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"; $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; + } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { + pidl_code "offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"; + pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; + pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n"; + $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; } } -- cgit From d8ecabe452f36302105c6412ae5ab93cabfe5cf2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 6 Nov 2006 21:54:19 +0000 Subject: r19585: Add support for some more standard IDL instructions: - `include' (replaces helper()) - `import' (replaces depends()) Add support for parsing importlib() - importlib() is now ignored (with a warning), but no longer causes syntax errors. helper() and depends() are now marked deprecated and will cause warnings. (This used to be commit 1ccab71cb8a9e3db9448b6679d01ad00e1c1e9a3) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 33 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 8c75d590e0..7b8691e044 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -717,6 +717,25 @@ sub RegisterInterfaceHandoff($) } } +sub ProcessInclude +{ + my @includes = @_; + foreach (@includes) { + pidl_hdr "#include \"$_\"\n"; + } +} + +sub ProcessImport +{ + my @imports = @_; + foreach (@imports) { + next if($_ eq "security"); + s/\.idl\"$//; + s/^\"//; + pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n"; + } +} + sub ProcessInterface($) { my ($x) = @_; @@ -728,12 +747,8 @@ sub ProcessInterface($) pidl_hdr "#define $define"; pidl_hdr ""; - if (defined $x->{PROPERTIES}->{depends}) { - foreach (split / /, $x->{PROPERTIES}->{depends}) { - next if($_ eq "security"); - pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n"; - } - } + ProcessImport(split / /, $x->{PROPERTIES}->{depends}) if + (defined $x->{PROPERTIES}->{depends}); pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;"; register_ett("ett_dcerpc_$x->{NAME}"); @@ -897,7 +912,11 @@ sub Parse($$$$) # Wireshark protocol registration - ProcessInterface($_) foreach (@$ndr); + foreach (@$ndr) { + ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE"); + ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT"); + ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE"); + } $res{ett} = DumpEttDeclaration(); $res{hf} = DumpHfDeclaration(); -- cgit From 5b05f5f5f1bad489091c715867eddda7eff4c8c6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 16 Nov 2006 22:13:44 +0000 Subject: r19752: Remove support for the `depends' attribute (use "import") instead. (This used to be commit 324395afc725e90f44f286fd776b38a64bdc8e3b) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 7b8691e044..14b922353a 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -747,9 +747,6 @@ sub ProcessInterface($) pidl_hdr "#define $define"; pidl_hdr ""; - ProcessImport(split / /, $x->{PROPERTIES}->{depends}) if - (defined $x->{PROPERTIES}->{depends}); - pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;"; register_ett("ett_dcerpc_$x->{NAME}"); register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, ""); -- cgit From f97f11eab25f0c294ff02b3c4485d7a0a91b5501 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 3 Jan 2007 15:34:01 +0000 Subject: r20511: Combine warnings/errors/fatal functions and move them to Parse::Pidl. (This used to be commit 959adfd0a682a4894c3bdd4ae9c6fc3ebfeeef1f) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 14b922353a..9526d76a37 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -17,6 +17,7 @@ Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark package Parse::Pidl::Wireshark::NDR; use strict; +use Parse::Pidl qw(error); use Parse::Pidl::Typelist qw(getType); use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str); use Parse::Pidl::NDR qw(ContainsString GetNextLevel); @@ -27,12 +28,6 @@ use File::Basename; use vars qw($VERSION); $VERSION = '0.01'; -sub error($$) -{ - my ($e,$t) = @_; - print "$e->{FILE}:$e->{LINE}: $t\n"; -} - my @ett; my %hf_used = (); @@ -441,10 +436,10 @@ sub Function($$$) } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { pidl_code "g$fn->{RETURN_TYPE} status;\n"; } else { - print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n"; + error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported"); } } else { - print "$fn->{FILE}:$fn->{LINE}: error: unknown return type `$fn->{RETURN_TYPE}'\n"; + error($fn, "unknown return type `$fn->{RETURN_TYPE}'"); } foreach (@{$fn->{ELEMENTS}}) { @@ -828,7 +823,7 @@ sub Initialize($) header_fields=> {} }; - ReadConformance($cnf_file, $conformance) or print "Warning: No conformance file `$cnf_file'\n"; + ReadConformance($cnf_file, $conformance) or print STDERR "warning: No conformance file `$cnf_file'\n"; foreach my $bytes (qw(1 2 4 8)) { my $bits = $bytes * 8; @@ -1054,43 +1049,43 @@ sub CheckUsed($) my $conformance = shift; foreach (values %{$conformance->{header_fields}}) { if (not defined($hf_used{$_->{INDEX}})) { - print "$_->{POS}: warning: hf field `$_->{INDEX}' not used\n"; + warning($_->{POS}, "hf field `$_->{INDEX}' not used"); } } foreach (values %{$conformance->{hf_renames}}) { if (not $_->{USED}) { - print "$_->{POS}: warning: hf field `$_->{OLDNAME}' not used\n"; + warning($_->{POS}, "hf field `$_->{OLDNAME}' not used"); } } foreach (values %{$conformance->{dissectorparams}}) { if (not $_->{USED}) { - print "$_->{POS}: warning: dissector param never used\n"; + warning($_->{POS}, "dissector param never used"); } } foreach (values %{$conformance->{imports}}) { if (not $_->{USED}) { - print "$_->{POS}: warning: import never used\n"; + warning($_->{POS}, "import never used"); } } foreach (values %{$conformance->{types}}) { if (not $_->{USED} and defined($_->{POS})) { - print "$_->{POS}: warning: type never used\n"; + warning($_->{POS}, "type never used"); } } foreach (values %{$conformance->{fielddescription}}) { if (not $_->{USED}) { - print "$_->{POS}: warning: description never used\n"; + warning($_->{POS}, "description never used"); } } foreach (values %{$conformance->{tfs}}) { if (not $_->{USED}) { - print "$_->{POS}: warning: True/False description never used\n"; + warning($_->{POS}, "True/False description never used"); } } } -- cgit From a7bc3801f94891880a90b2974dfbadc9e9f8c2ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 20:52:12 +0000 Subject: r20567: Print proper errors with filename and line numbers in ParseExpr() (This used to be commit f5dc1b47ecf18068a47f8f68016463ef4a55dc03) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 9526d76a37..9415c16652 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -19,7 +19,7 @@ package Parse::Pidl::Wireshark::NDR; use strict; use Parse::Pidl qw(error); use Parse::Pidl::Typelist qw(getType); -use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str); +use Parse::Pidl::Util qw(has_property property_matches make_str); use Parse::Pidl::NDR qw(ContainsString GetNextLevel); use Parse::Pidl::Dump qw(DumpTypedef DumpFunction); use Parse::Pidl::Wireshark::Conformance qw(ReadConformance); -- cgit From 45db1030651e69896fdb9e78aa2e2495a7ce7ff5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Feb 2007 23:54:31 +0000 Subject: r21253: Merge some pidl fixes: * Add tests for wireshark dissector generator * Add tests for the header code * Some cleanups * Fix handling of elements without [in] or [out] (This used to be commit 1aecba7100685ed291ea13b0ae47fb0cf9e6a6c8) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 9415c16652..646f5fdabc 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -2,7 +2,7 @@ # Samba4 NDR parser generator for IDL structures # Copyright tridge@samba.org 2000-2003 # Copyright tpot@samba.org 2001,2005 -# Copyright jelmer@samba.org 2004-2005 +# Copyright jelmer@samba.org 2004-2007 # Portions based on idl2eth.c by Ronnie Sahlberg # released under the GNU GPL @@ -918,7 +918,9 @@ sub Parse($$$$) $parser.=$res{ett}; $parser.=$res{hf}; $parser.=$res{def}; - $parser.=$conformance->{override}; + if (exists ($conformance->{override})) { + $parser.=$conformance->{override}; + } $parser.=$res{code}; my $header = "/* autogenerated by pidl */\n\n"; -- cgit From 627fc227916b041de8e1050cab0431467be44b20 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 14 Feb 2007 14:42:42 +0000 Subject: r21340: Fix warning undef (This used to be commit 2669f2c8ad09505b37f64104eefce6f0b10e9ab5) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 646f5fdabc..6bde87c47b 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -17,7 +17,7 @@ Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark package Parse::Pidl::Wireshark::NDR; use strict; -use Parse::Pidl qw(error); +use Parse::Pidl qw(error warning); use Parse::Pidl::Typelist qw(getType); use Parse::Pidl::Util qw(has_property property_matches make_str); use Parse::Pidl::NDR qw(ContainsString GetNextLevel); -- cgit From ec587914ed4df87b6aedab129fb59248b137f07b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Feb 2007 23:38:57 +0000 Subject: r21411: Add some simple tests for the wireshark NDR generator. (This used to be commit 361977448210dfd889abca19b520cd259b9d0855) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 6bde87c47b..4a890fb630 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -16,6 +16,10 @@ Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark package Parse::Pidl::Wireshark::NDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(field2name @ett %res PrintIdl); + use strict; use Parse::Pidl qw(error warning); use Parse::Pidl::Typelist qw(getType); @@ -28,7 +32,7 @@ use File::Basename; use vars qw($VERSION); $VERSION = '0.01'; -my @ett; +our @ett; my %hf_used = (); my %return_types = (); @@ -66,7 +70,7 @@ sub field2name($) return $field; } -my %res = (); +our %res = (); my $tabs = ""; my $cur_fn = undef; sub pidl_fn_start($) @@ -108,7 +112,7 @@ sub deindent() sub PrintIdl($) { - my $idl = shift; + my ($idl) = @_; foreach (split /\n/, $idl) { pidl_code "/* IDL: $_ */"; -- cgit From f9885687878560c21c569a850cb7023b062b4e33 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 Feb 2007 16:46:59 +0000 Subject: r21431: More tests, work on support in wireshark for tagged types. (This used to be commit a91e624af22aae5b460ccf94d2540b8780f90070) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 4a890fb630..9ba6f2f3e0 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -25,7 +25,7 @@ use Parse::Pidl qw(error warning); use Parse::Pidl::Typelist qw(getType); use Parse::Pidl::Util qw(has_property property_matches make_str); use Parse::Pidl::NDR qw(ContainsString GetNextLevel); -use Parse::Pidl::Dump qw(DumpTypedef DumpFunction); +use Parse::Pidl::Dump qw(DumpType DumpFunction); use Parse::Pidl::Wireshark::Conformance qw(ReadConformance); use File::Basename; @@ -127,7 +127,7 @@ sub Interface($) { my($interface) = @_; Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}}); - Typedef($_,$interface->{NAME}) foreach (@{$interface->{TYPES}}); + Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}}); Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}}); } @@ -637,18 +637,26 @@ sub Const($$) } } -sub Typedef($$) +sub Typedef($$$) { - my ($e,$ifname) = @_; + my ($e,$name,$ifname) = @_; + + Type($e->{DATA}, $name, $ifname); +} + +sub Type($$$) +{ + my ($e, $name, $ifname) = @_; - PrintIdl DumpTypedef($e->{ORIGINAL}); + PrintIdl DumpType($e->{ORIGINAL}); { ENUM => \&Enum, STRUCT => \&Struct, UNION => \&Union, - BITMAP => \&Bitmap - }->{$e->{DATA}->{TYPE}}->($e->{DATA}, $e->{NAME}, $ifname); + BITMAP => \&Bitmap, + TYPEDEF => \&Typedef + }->{$e->{TYPE}}->($e, $name, $ifname); } sub RegisterInterface($) -- cgit From f487c24a79223c295afc60e05a0fac9794c3a22d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Feb 2007 20:59:01 +0000 Subject: r21493: Patch from Ronnie Sahlberg. From his email: This patch changes the function name and signature that pidl generate a call for when dissecting a policy handle to a new, more PIDL-friendly function. It also stores the procedure name in a new pinfo-> field so that helpers that want to know the procedure name can finbd out easily. The new PIDL helper function for policy handles use this new field and will show OpenHKU(<...>) opened in frame X closed in frame Y for the policy handle. (This used to be commit 0c4fb484f0e515eb4055c58cd73ca798a8c46d69) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 9ba6f2f3e0..c61a05e90c 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -427,7 +427,7 @@ sub Function($$$) PrintIdl DumpFunction($fn->{ORIGINAL}); pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; if ( not defined($fn->{RETURN_TYPE})) { @@ -446,6 +446,7 @@ sub Function($$$) error($fn, "unknown return type `$fn->{RETURN_TYPE}'"); } + pidl_code "pinfo->dcerpc_procedure_name=\"${fn_name}\";"; foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$_->{DIRECTION}})) { pidl_code "$dissectornames{$_->{NAME}}"; @@ -491,9 +492,10 @@ sub Function($$$) pidl_fn_start "$ifname\_dissect\_$fn_name\_request"; pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; + pidl_code "pinfo->dcerpc_procedure_name=\"${fn_name}\";"; foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$_->{DIRECTION}})) { pidl_code "$dissectornames{$_->{NAME}}"; @@ -849,7 +851,7 @@ sub Initialize($) register_type("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4); register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); - register_type("policy_handle", "offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, NULL, NULL, \@PARAM\@&0x01, \@PARAM\@&0x02);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); + register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4); -- cgit From 882c5a8b43632517d7b6340b17174721a8b7a388 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Feb 2007 09:35:32 +0000 Subject: r21531: Use pidl-specific utility functions. Patch from Ronnie Sahlberg (This used to be commit e6fdcdf95e984a254cebd197269cf3e911009f02) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index c61a05e90c..72d353aa14 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -841,14 +841,14 @@ sub Initialize($) foreach my $bytes (qw(1 2 4 8)) { my $bits = $bytes * 8; - register_type("uint$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@,NULL);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); - register_type("int$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); + register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); + register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); } register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); - register_type("bool8", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - register_type("char", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - register_type("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4); + register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4); register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); @@ -864,9 +864,9 @@ sub Initialize($) offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); ","FT_STRING", "BASE_DEC", 0, "NULL", 4); register_type("WERROR", - "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); + "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); register_type("NTSTATUS", - "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); + "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); } -- cgit From cb8fceab28c71c7513e0732e1a9e2c9f61bfa31b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Feb 2007 09:55:57 +0000 Subject: r21532: Add tests for StripPrefixes utility function. (This used to be commit 365052555e0e9224bdfda0c2a10f78cbeee5b06c) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 72d353aa14..914d54d985 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(field2name @ett %res PrintIdl); +@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes); use strict; use Parse::Pidl qw(error warning); @@ -46,11 +46,11 @@ my %ptrtype_mappings = ( "ptr" => "NDR_POINTER_PTR" ); -sub StripPrefixes($) +sub StripPrefixes($$) { - my ($s) = @_; + my ($s, $prefixes) = @_; - foreach (@{$conformance->{strip_prefixes}}) { + foreach (@$prefixes) { $s =~ s/^$_\_//g; } @@ -135,9 +135,9 @@ sub Enum($$$) { my ($e,$name,$ifname) = @_; my $valsstring = "$ifname\_$name\_vals"; - my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name); + my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $conformance->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); foreach (@{$e->{ELEMENTS}}) { if (/([^=]*)=(.*)/) { @@ -176,7 +176,7 @@ sub Enum($$$) sub Bitmap($$$) { my ($e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name); + my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $conformance->{strip_prefixes}); register_ett("ett_$ifname\_$name"); @@ -272,7 +272,7 @@ sub ElementLevel($$$$$$) } elsif ($l->{LEVEL} eq "EMBEDDED") { $type = "embedded"; } - pidl_code "offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME})) . " ($e->{TYPE})\",$hf);"; + pidl_code "offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $conformance->{strip_prefixes})) . " ($e->{TYPE})\",$hf);"; } elsif ($l->{TYPE} eq "ARRAY") { if ($l->{IS_INLINE}) { error($e->{ORIGINAL}, "Inline arrays not supported"); @@ -353,7 +353,7 @@ sub Element($$$) { my ($e,$pn,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn)."\_".StripPrefixes($e->{NAME}); + my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $conformance->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $conformance->{strip_prefixes}); my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; @@ -381,7 +381,7 @@ sub Element($$$) my $hf = register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", $type->{FT_TYPE}, $type->{BASE_TYPE}, $type->{VALSSTRING}, $type->{MASK}, ""); $hf_used{$hf} = 1; - my $eltname = StripPrefixes($pn) . ".$e->{NAME}"; + my $eltname = StripPrefixes($pn, $conformance->{strip_prefixes}) . ".$e->{NAME}"; if (defined($conformance->{noemit}->{$eltname})) { return $call_code; } @@ -513,9 +513,9 @@ sub Function($$$) sub Struct($$$) { my ($e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name); + my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $conformance->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); register_ett("ett_$ifname\_$name"); @@ -563,9 +563,9 @@ sub Union($$$) { my ($e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect_".StripPrefixes($name); + my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $conformance->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name)})); + return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); register_ett("ett_$ifname\_$name"); -- cgit From b8c219a270e50f165a326c3657618c78e2ff58c5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 Feb 2007 01:03:19 +0000 Subject: r21534: Add some more tests for wireshark. (This used to be commit b10432096181cf8e7d729e58a5ab54fac5eaa5fe) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 914d54d985..db7d2cf241 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes); +@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed); use strict; use Parse::Pidl qw(error warning); @@ -34,11 +34,11 @@ $VERSION = '0.01'; our @ett; -my %hf_used = (); +our %hf_used = (); my %return_types = (); my %dissector_used = (); -my $conformance = undef; +our $conformance = undef; my %ptrtype_mappings = ( "unique" => "NDR_POINTER_UNIQUE", -- cgit From 6f3c968e64ef5677759dafcc88092d3db2b4c6e9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Feb 2007 20:35:56 +0000 Subject: r21567: Add some more wireshark tests. (This used to be commit 40e2956058fe4aaebf3f7269bce90339d7faf24f) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index db7d2cf241..0374b60132 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed); +@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable); use strict; use Parse::Pidl qw(error warning); @@ -671,7 +671,7 @@ sub RegisterInterface($) indent; $res{code}.=DumpHfList()."\n"; - $res{code}.="\n".DumpEttList()."\n"; + $res{code}.="\n".DumpEttList(@ett)."\n"; if (defined($x->{UUID})) { # These can be changed to non-pidl_code names if the old dissectors @@ -730,8 +730,9 @@ sub ProcessInclude { my @includes = @_; foreach (@includes) { - pidl_hdr "#include \"$_\"\n"; + pidl_hdr "#include \"$_\""; } + pidl_hdr ""; } sub ProcessImport @@ -741,8 +742,9 @@ sub ProcessImport next if($_ eq "security"); s/\.idl\"$//; s/^\"//; - pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n"; + pidl_hdr "#include \"packet-dcerpc-$_\.h\""; } + pidl_hdr ""; } sub ProcessInterface($) @@ -924,7 +926,7 @@ sub Parse($$$$) ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE"); } - $res{ett} = DumpEttDeclaration(); + $res{ett} = DumpEttDeclaration(@ett); $res{hf} = DumpHfDeclaration(); my $parser = $notice; @@ -956,8 +958,9 @@ sub register_ett($) push (@ett, $name); } -sub DumpEttList() +sub DumpEttList { + my @ett = @_; my $res = "\tstatic gint *ett[] = {\n"; foreach (@ett) { $res .= "\t\t&$_,\n"; @@ -966,8 +969,9 @@ sub DumpEttList() return "$res\t};\n"; } -sub DumpEttDeclaration() +sub DumpEttDeclaration { + my @ett = @_; my $res = "\n/* Ett declarations */\n"; foreach (@ett) { $res .= "static gint $_ = -1;\n"; -- cgit From f5f0e502b3eadacd3ef1ee382f63e02cbbf9ae58 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Feb 2007 21:37:31 +0000 Subject: r21568: More tests. (This used to be commit c7bde9c1f537cbcf8e71177e6c3969699c046ecb) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 0374b60132..3c38801fae 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable); +@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett); use strict; use Parse::Pidl qw(error warning); -- cgit From 452f8e76cb4ca89db11f882e47dd94af06476da5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Mar 2007 23:04:08 +0000 Subject: r21995: Patch from Ronnie Sahlberg. Change the signatures for all functions it generates to specify _U_ so that GCC "parameter not used" warnings are suppressed. (This used to be commit ec6c503e9d077103c3fecff08400beb2a28e462d) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 3c38801fae..279f4c0cf2 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -146,7 +146,7 @@ sub Enum($$$) } pidl_hdr "extern const value_string $valsstring\[];"; - pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 *param);"; + pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);"; pidl_def "const value_string ".$valsstring."[] = {"; foreach (@{$e->{ELEMENTS}}) { @@ -159,7 +159,7 @@ sub Enum($$$) pidl_fn_start $dissectorname; pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 *param)"; + pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"; pidl_code "{"; indent; pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, param);"; @@ -180,11 +180,11 @@ sub Bitmap($$$) register_ett("ett_$ifname\_$name"); - pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);"; + pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"; pidl_fn_start $dissectorname; pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; pidl_code "{"; indent; pidl_code "proto_item *item = NULL;"; @@ -390,10 +390,10 @@ sub Element($$$) foreach (@{$e->{LEVELS}}) { next if ($_->{TYPE} eq "SWITCH"); - pidl_def "static int $dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep);"; + pidl_def "static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_);"; pidl_fn_start "$dissectorname$add"; pidl_code "static int"; - pidl_code "$dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)"; + pidl_code "$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; @@ -427,7 +427,7 @@ sub Function($$$) PrintIdl DumpFunction($fn->{ORIGINAL}); pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; if ( not defined($fn->{RETURN_TYPE})) { @@ -492,7 +492,7 @@ sub Function($$$) pidl_fn_start "$ifname\_dissect\_$fn_name\_request"; pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo, proto_tree *tree _U_, guint8 *drep _U_)"; + pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; pidl_code "{"; indent; pidl_code "pinfo->dcerpc_procedure_name=\"${fn_name}\";"; @@ -522,11 +522,11 @@ sub Struct($$$) my $res = ""; ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}}); - pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_);"; + pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"; pidl_fn_start $dissectorname; pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; pidl_code "{"; indent; pidl_code "proto_item *item = NULL;"; @@ -591,7 +591,7 @@ sub Union($$$) pidl_fn_start $dissectorname; pidl_code "static int"; - pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)"; + pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; pidl_code "{"; indent; pidl_code "proto_item *item = NULL;"; -- cgit From 256054f4e12ddd2d65734cda8a33ee24e50931e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Mar 2007 23:22:41 +0000 Subject: r21996: Fix a bug for invalid casts of pointers. Patch by Ronnie Sahlberg. (This used to be commit 52a13ddf0242318785b05a8888640b2172435c45) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 279f4c0cf2..e6dd954b74 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -162,7 +162,14 @@ sub Enum($$$) pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"; pidl_code "{"; indent; - pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, param);"; + pidl_code "g$e->{BASE_TYPE} parameter;"; + pidl_code "parameter=(g$e->{BASE_TYPE})*param;"; + pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"; + pidl_code "if(param){"; + indent; + pidl_code "*param=(guint32)parameter;"; + deindent; + pidl_code "}"; pidl_code "return offset;"; deindent; pidl_code "}\n"; -- cgit From cbd42dc5a1a296d0f4038448933d68bc4b94ff22 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Mar 2007 22:52:37 +0000 Subject: r22004: Check for dereferencing null pointers. Patch by Ronnie Sahlberg. (This used to be commit fa5722111dede37d0d6f9a9d227b7ec3ae28f1d4) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index e6dd954b74..51e3933013 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -162,8 +162,12 @@ sub Enum($$$) pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"; pidl_code "{"; indent; - pidl_code "g$e->{BASE_TYPE} parameter;"; + pidl_code "g$e->{BASE_TYPE} parameter=0;"; + pidl_code "if(param){"; + indent; pidl_code "parameter=(g$e->{BASE_TYPE})*param;"; + deindent; + pidl_code "}"; pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"; pidl_code "if(param){"; indent; -- cgit From a0bfcfa55d9f00ffab59e8cf7529cadf108a5629 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 19 Apr 2007 01:26:15 +0000 Subject: r22357: Don't use 'our' (This used to be commit 7989ee2aa015264dc9334b5e15d4fe6cb55f4e09) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 51e3933013..aafaa3cc2b 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -32,13 +32,13 @@ use File::Basename; use vars qw($VERSION); $VERSION = '0.01'; -our @ett; +my @ett; -our %hf_used = (); +my %hf_used = (); my %return_types = (); my %dissector_used = (); -our $conformance = undef; +my $conformance = undef; my %ptrtype_mappings = ( "unique" => "NDR_POINTER_UNIQUE", @@ -70,7 +70,7 @@ sub field2name($) return $field; } -our %res = (); +my %res = (); my $tabs = ""; my $cur_fn = undef; sub pidl_fn_start($) -- cgit From 68d92f0a123374972ee2aa54dd708f089cb59837 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 22 Apr 2007 13:57:07 +0000 Subject: r22456: Merge wireshark and ejs test improvements. (This used to be commit 0375978403dde8ef5052dcca544f118e5387e887) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 919 ++++++++++++++------------- 1 file changed, 461 insertions(+), 458 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index aafaa3cc2b..523fff9537 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -18,7 +18,7 @@ package Parse::Pidl::Wireshark::NDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(field2name @ett %res PrintIdl StripPrefixes %hf_used RegisterInterfaceHandoff $conformance register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett); +@EXPORT_OK = qw(field2name %res PrintIdl StripPrefixes RegisterInterfaceHandoff register_hf_field CheckUsed ProcessImport ProcessInclude find_type DumpEttList DumpEttDeclaration DumpHfList DumpHfDeclaration DumpFunctionTable register_type register_ett); use strict; use Parse::Pidl qw(error warning); @@ -32,14 +32,9 @@ use File::Basename; use vars qw($VERSION); $VERSION = '0.01'; -my @ett; - -my %hf_used = (); my %return_types = (); my %dissector_used = (); -my $conformance = undef; - my %ptrtype_mappings = ( "unique" => "NDR_POINTER_UNIQUE", "ref" => "NDR_POINTER_REF", @@ -70,157 +65,166 @@ sub field2name($) return $field; } -my %res = (); -my $tabs = ""; -my $cur_fn = undef; -sub pidl_fn_start($) +sub new($) { - my $fn = shift; - $cur_fn = $fn; + my ($class) = @_; + my $self = {res => {hdr => "", def => "", code => ""}, tabs => "", cur_fn => undef, + hf_used => {}, ett => [], conformance => undef + + }; + bless($self, $class); } -sub pidl_fn_end($) + +sub pidl_fn_start($$) { - my $fn = shift; - die("Inconsistent state: $fn != $cur_fn") if ($fn ne $cur_fn); - $cur_fn = undef; + my ($self, $fn) = @_; + $self->{cur_fn} = $fn; +} +sub pidl_fn_end($$) +{ + my ($self, $fn) = @_; + die("Inconsistent state: $fn != $self->{cur_fn}") if ($fn ne $self->{cur_fn}); + $self->{cur_fn} = undef; } -sub pidl_code($) +sub pidl_code($$) { - my $d = shift; - return if (defined($cur_fn) and defined($conformance->{manual}->{$cur_fn})); + my ($self, $d) = @_; + return if (defined($self->{cur_fn}) and defined($self->{conformance}->{manual}->{$self->{cur_fn}})); if ($d) { - $res{code} .= $tabs; - $res{code} .= $d; + $self->{res}->{code} .= $self->{tabs}; + $self->{res}->{code} .= $d; } - $res{code} .="\n"; + $self->{res}->{code} .="\n"; } -sub pidl_hdr($) { my $x = shift; $res{hdr} .= "$x\n"; } -sub pidl_def($) { my $x = shift; $res{def} .= "$x\n"; } +sub pidl_hdr($$) { my ($self,$x) = @_; $self->{res}->{hdr} .= "$x\n"; } +sub pidl_def($$) { my ($self,$x) = @_; $self->{res}->{def} .= "$x\n"; } -sub indent() +sub indent($) { - $tabs .= "\t"; + my ($self) = @_; + $self->{tabs} .= "\t"; } -sub deindent() +sub deindent($) { - $tabs = substr($tabs, 0, -1); + my ($self) = @_; + $self->{tabs} = substr($self->{tabs}, 0, -1); } -sub PrintIdl($) +sub PrintIdl($$) { - my ($idl) = @_; + my ($self, $idl) = @_; foreach (split /\n/, $idl) { - pidl_code "/* IDL: $_ */"; + $self->pidl_code("/* IDL: $_ */"); } - pidl_code ""; + $self->pidl_code(""); } ##################################################################### # parse the interface definitions -sub Interface($) +sub Interface($$) { - my($interface) = @_; - Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}}); - Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}}); - Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}}); + my($self, $interface) = @_; + $self->Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}}); + $self->Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}}); + $self->Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}}); } -sub Enum($$$) +sub Enum($$$$) { - my ($e,$name,$ifname) = @_; + my ($self, $e,$name,$ifname) = @_; my $valsstring = "$ifname\_$name\_vals"; - my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $conformance->{strip_prefixes}); + my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); + return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})})); foreach (@{$e->{ELEMENTS}}) { if (/([^=]*)=(.*)/) { - pidl_hdr "#define $1 ($2)"; + $self->pidl_hdr("#define $1 ($2)"); } } - pidl_hdr "extern const value_string $valsstring\[];"; - pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);"; + $self->pidl_hdr("extern const value_string $valsstring\[];"); + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);"); - pidl_def "const value_string ".$valsstring."[] = {"; + $self->pidl_def("const value_string ".$valsstring."[] = {"); foreach (@{$e->{ELEMENTS}}) { next unless (/([^=]*)=(.*)/); - pidl_def "\t{ $1, \"$1\" },"; + $self->pidl_def("\t{ $1, \"$1\" },"); } - pidl_def "{ 0, NULL }"; - pidl_def "};"; - - pidl_fn_start $dissectorname; - pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"; - pidl_code "{"; - indent; - pidl_code "g$e->{BASE_TYPE} parameter=0;"; - pidl_code "if(param){"; - indent; - pidl_code "parameter=(g$e->{BASE_TYPE})*param;"; - deindent; - pidl_code "}"; - pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"; - pidl_code "if(param){"; - indent; - pidl_code "*param=(guint32)parameter;"; - deindent; - pidl_code "}"; - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end $dissectorname; + $self->pidl_def("{ 0, NULL }"); + $self->pidl_def("};"); + + $self->pidl_fn_start($dissectorname); + $self->pidl_code("int"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("g$e->{BASE_TYPE} parameter=0;"); + $self->pidl_code("if(param){"); + $self->indent; + $self->pidl_code("parameter=(g$e->{BASE_TYPE})*param;"); + $self->deindent; + $self->pidl_code("}"); + $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"); + $self->pidl_code("if(param){"); + $self->indent; + $self->pidl_code("*param=(guint32)parameter;"); + $self->deindent; + $self->pidl_code("}"); + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end($dissectorname); my $enum_size = $e->{BASE_TYPE}; $enum_size =~ s/uint//g; - register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); } -sub Bitmap($$$) +sub Bitmap($$$$) { - my ($e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $conformance->{strip_prefixes}); + my ($self,$e,$name,$ifname) = @_; + my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes}); - register_ett("ett_$ifname\_$name"); + $self->register_ett("ett_$ifname\_$name"); - pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"; + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); - pidl_fn_start $dissectorname; - pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; - pidl_code "{"; - indent; - pidl_code "proto_item *item = NULL;"; - pidl_code "proto_tree *tree = NULL;"; - pidl_code ""; + $self->pidl_fn_start($dissectorname); + $self->pidl_code("int"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("proto_item *item = NULL;"); + $self->pidl_code("proto_tree *tree = NULL;"); + $self->pidl_code(""); - pidl_code "g$e->{BASE_TYPE} flags;"; + $self->pidl_code("g$e->{BASE_TYPE} flags;"); if ($e->{ALIGN} > 1) { - pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); } - pidl_code ""; + $self->pidl_code(""); - pidl_code "if (parent_tree) {"; - indent; - pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);"; - pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);"; - deindent; - pidl_code "}\n"; + $self->pidl_code("if (parent_tree) {"); + $self->indent; + $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);"); + $self->pidl_code("tree = proto_item_add_subtree(item,ett_$ifname\_$name);"); + $self->deindent; + $self->pidl_code("}\n"); - pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);"; + $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);"); - pidl_code "proto_item_append_text(item, \": \");\n"; - pidl_code "if (!flags)"; - pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n"; + $self->pidl_code("proto_item_append_text(item, \": \");\n"); + $self->pidl_code("if (!flags)"); + $self->pidl_code("\tproto_item_append_text(item, \"(No values set)\");\n"); foreach (@{$e->{ELEMENTS}}) { next unless (/([^ ]*) (.*)/); @@ -228,52 +232,52 @@ sub Bitmap($$$) my $hf_bitname = "hf_$ifname\_$name\_$en"; my $filtername = "$ifname\.$name\.$en"; - $hf_used{$hf_bitname} = 1; + $self->{hf_used}->{$hf_bitname} = 1; - register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, ""); + $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, ""); - pidl_def "static const true_false_string $name\_$en\_tfs = {"; - if (defined($conformance->{tfs}->{$hf_bitname})) { - pidl_def " $conformance->{tfs}->{$hf_bitname}->{TRUE_STRING},"; - pidl_def " $conformance->{tfs}->{$hf_bitname}->{FALSE_STRING},"; - $conformance->{tfs}->{$hf_bitname}->{USED} = 1; + $self->pidl_def("static const true_false_string $name\_$en\_tfs = {"); + if (defined($self->{conformance}->{tfs}->{$hf_bitname})) { + $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{TRUE_STRING},"); + $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{FALSE_STRING},"); + $self->{conformance}->{tfs}->{$hf_bitname}->{USED} = 1; } else { - pidl_def " \"$en is SET\","; - pidl_def " \"$en is NOT SET\","; + $self->pidl_def(" \"$en is SET\","); + $self->pidl_def(" \"$en is NOT SET\","); } - pidl_def "};"; + $self->pidl_def("};"); - pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);"; - pidl_code "if (flags&$ev){"; - pidl_code "\tproto_item_append_text(item, \"$en\");"; - pidl_code "\tif (flags & (~$ev))"; - pidl_code "\t\tproto_item_append_text(item, \", \");"; - pidl_code "}"; - pidl_code "flags&=(~$ev);"; - pidl_code ""; + $self->pidl_code("proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);"); + $self->pidl_code("if (flags&$ev){"); + $self->pidl_code("\tproto_item_append_text(item, \"$en\");"); + $self->pidl_code("\tif (flags & (~$ev))"); + $self->pidl_code("\t\tproto_item_append_text(item, \", \");"); + $self->pidl_code("}"); + $self->pidl_code("flags&=(~$ev);"); + $self->pidl_code(""); } - pidl_code "if (flags) {"; - pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);"; - pidl_code "}\n"; - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end $dissectorname; + $self->pidl_code("if (flags) {"); + $self->pidl_code("\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);"); + $self->pidl_code("}\n"); + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end($dissectorname); my $size = $e->{BASE_TYPE}; $size =~ s/uint//g; - register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8); } -sub ElementLevel($$$$$$) +sub ElementLevel($$$$$$$) { - my ($e,$l,$hf,$myname,$pn,$ifname) = @_; + my ($self,$e,$l,$hf,$myname,$pn,$ifname) = @_; my $param = 0; - if (defined($conformance->{dissectorparams}->{$myname})) { - $param = $conformance->{dissectorparams}->{$myname}->{PARAM}; + if (defined($self->{conformance}->{dissectorparams}->{$myname})) { + $param = $self->{conformance}->{dissectorparams}->{$myname}->{PARAM}; } if ($l->{TYPE} eq "POINTER") { @@ -283,27 +287,27 @@ sub ElementLevel($$$$$$) } elsif ($l->{LEVEL} eq "EMBEDDED") { $type = "embedded"; } - pidl_code "offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $conformance->{strip_prefixes})) . " ($e->{TYPE})\",$hf);"; + $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);"); } elsif ($l->{TYPE} eq "ARRAY") { if ($l->{IS_INLINE}) { error($e->{ORIGINAL}, "Inline arrays not supported"); } elsif ($l->{IS_FIXED}) { - pidl_code "int i;"; - pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)"; - pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);"; + $self->pidl_code("int i;"); + $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)"); + $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, drep);"); } else { my $type = ""; $type .= "c" if ($l->{IS_CONFORMANT}); $type .= "v" if ($l->{IS_VARYING}); unless ($l->{IS_ZERO_TERMINATED}) { - pidl_code "offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);"; + $self->pidl_code("offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);"); } else { my $nl = GetNextLevel($e,$l); - pidl_code "char *data;"; - pidl_code ""; - pidl_code "offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);"; - pidl_code "proto_item_append_text(tree, \": %s\", data);"; + $self->pidl_code("char *data;"); + $self->pidl_code(""); + $self->pidl_code("offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);"); + $self->pidl_code("proto_item_append_text(tree, \": %s\", data);"); } } } elsif ($l->{TYPE} eq "DATA") { @@ -314,47 +318,47 @@ sub ElementLevel($$$$$$) ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*")); if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) { - pidl_code "char *data;\n"; - pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);"; - pidl_code "proto_item_append_text(tree, \": %s\", data);"; + $self->pidl_code("char *data;\n"); + $self->pidl_code("offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);"); + $self->pidl_code("proto_item_append_text(tree, \": %s\", data);"); } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) { - pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);"; + $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);"); } else { warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}"); } } else { my $call; - if ($conformance->{imports}->{$l->{DATA_TYPE}}) { - $call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA}; - $conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1; - } elsif (defined($conformance->{imports}->{"$pn.$e->{NAME}"})) { - $call = $conformance->{imports}->{"$pn.$e->{NAME}"}->{DATA}; - $conformance->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1; + if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) { + $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA}; + $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1; + } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) { + $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA}; + $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1; - } elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) { - $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; - $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1; + } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) { + $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; + $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1; } else { - pidl_code "offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);"; + $self->pidl_code("offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);"); return; } $call =~ s/\@HF\@/$hf/g; $call =~ s/\@PARAM\@/$param/g; - pidl_code "$call"; + $self->pidl_code($call); } } elsif ($_->{TYPE} eq "SUBCONTEXT") { my $num_bits = ($l->{HEADER_SIZE}*8); - pidl_code "guint$num_bits size;"; - pidl_code "int start_offset = offset;"; - pidl_code "tvbuff_t *subtvb;"; - pidl_code "offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);"; - pidl_code "proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");"; - - pidl_code "subtvb = tvb_new_subset(tvb, offset, size, -1);"; - pidl_code "$myname\_(subtvb, 0, pinfo, tree, drep);"; + $self->pidl_code("guint$num_bits size;"); + $self->pidl_code("int start_offset = offset;"); + $self->pidl_code("tvbuff_t *subtvb;"); + $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);"); + $self->pidl_code("proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");"); + + $self->pidl_code("subtvb = tvb_new_subset(tvb, offset, size, -1);"); + $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);"); } else { die("Unknown type `$_->{TYPE}'"); } @@ -362,13 +366,13 @@ sub ElementLevel($$$$$$) sub Element($$$) { - my ($e,$pn,$ifname) = @_; + my ($self,$e,$pn,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $conformance->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $conformance->{strip_prefixes}); + my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes}); my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; - my $type = find_type($e->{TYPE}); + my $type = $self->find_type($e->{TYPE}); if (not defined($type)) { # default settings @@ -389,11 +393,11 @@ sub Element($$$) }; } - my $hf = register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", $type->{FT_TYPE}, $type->{BASE_TYPE}, $type->{VALSSTRING}, $type->{MASK}, ""); - $hf_used{$hf} = 1; + my $hf = $self->register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", $type->{FT_TYPE}, $type->{BASE_TYPE}, $type->{VALSSTRING}, $type->{MASK}, ""); + $self->{hf_used}->{$hf} = 1; - my $eltname = StripPrefixes($pn, $conformance->{strip_prefixes}) . ".$e->{NAME}"; - if (defined($conformance->{noemit}->{$eltname})) { + my $eltname = StripPrefixes($pn, $self->{conformance}->{strip_prefixes}) . ".$e->{NAME}"; + if (defined($self->{conformance}->{noemit}->{$eltname})) { return $call_code; } @@ -401,20 +405,20 @@ sub Element($$$) foreach (@{$e->{LEVELS}}) { next if ($_->{TYPE} eq "SWITCH"); - pidl_def "static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_);"; - pidl_fn_start "$dissectorname$add"; - pidl_code "static int"; - pidl_code "$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; - pidl_code "{"; - indent; - - ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname); - - pidl_code ""; - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end "$dissectorname$add"; + $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_);"); + $self->pidl_fn_start("$dissectorname$add"); + $self->pidl_code("static int"); + $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"); + $self->pidl_code("{"); + $self->indent; + + $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname); + + $self->pidl_code(""); + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end("$dissectorname$add"); $add.="_"; last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED}); } @@ -424,32 +428,32 @@ sub Element($$$) sub Function($$$) { - my ($fn,$ifname) = @_; + my ($self, $fn,$ifname) = @_; my %dissectornames; foreach (@{$fn->{ELEMENTS}}) { - $dissectornames{$_->{NAME}} = Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}}); + $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}}); } my $fn_name = $_->{NAME}; $fn_name =~ s/^${ifname}_//; - PrintIdl DumpFunction($fn->{ORIGINAL}); - pidl_fn_start "$ifname\_dissect\_$fn_name\_response"; - pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; - pidl_code "{"; - indent; + $self->PrintIdl(DumpFunction($fn->{ORIGINAL})); + $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response"); + $self->pidl_code("static int"); + $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"); + $self->pidl_code("{"); + $self->indent; if ( not defined($fn->{RETURN_TYPE})) { } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR") { - pidl_code "guint32 status;\n"; + $self->pidl_code("guint32 status;\n"); } elsif (my $type = getType($fn->{RETURN_TYPE})) { if ($type->{DATA}->{TYPE} eq "ENUM") { - pidl_code "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n"; + $self->pidl_code("g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n"); } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { - pidl_code "g$fn->{RETURN_TYPE} status;\n"; + $self->pidl_code("g$fn->{RETURN_TYPE} status;\n"); } else { error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported"); } @@ -457,25 +461,25 @@ sub Function($$$) error($fn, "unknown return type `$fn->{RETURN_TYPE}'"); } - pidl_code "pinfo->dcerpc_procedure_name=\"${fn_name}\";"; + $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";"); foreach (@{$fn->{ELEMENTS}}) { if (grep(/out/,@{$_->{DIRECTION}})) { - pidl_code "$dissectornames{$_->{NAME}}"; - pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"; - pidl_code ""; + $self->pidl_code("$dissectornames{$_->{NAME}}"); + $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"); + $self->pidl_code(""); } } if (not defined($fn->{RETURN_TYPE})) { } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { - pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"; - pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; - pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"; + $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"); + $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"); + $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"); $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"]; } elsif ($fn->{RETURN_TYPE} eq "WERROR") { - pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"; - pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; - pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"; + $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"); + $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"); + $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"); $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"]; } elsif (my $type = getType($fn->{RETURN_TYPE})) { @@ -483,108 +487,107 @@ sub Function($$$) my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA}); - pidl_code "offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"; - pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; - pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"; + $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); + $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"); + $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"); $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { - pidl_code "offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"; - pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"; - pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n"; + $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); + $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))"); + $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n"); $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; } } - - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end "$ifname\_dissect\_$fn_name\_response"; - - pidl_fn_start "$ifname\_dissect\_$fn_name\_request"; - pidl_code "static int"; - pidl_code "$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"; - pidl_code "{"; - indent; - pidl_code "pinfo->dcerpc_procedure_name=\"${fn_name}\";"; + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_response"); + + $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request"); + $self->pidl_code("static int"); + $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";"); foreach (@{$fn->{ELEMENTS}}) { if (grep(/in/,@{$_->{DIRECTION}})) { - pidl_code "$dissectornames{$_->{NAME}}"; - pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"; + $self->pidl_code("$dissectornames{$_->{NAME}}"); + $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);"); } } - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end "$ifname\_dissect\_$fn_name\_request"; + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_request"); } -sub Struct($$$) +sub Struct($$$$) { - my ($e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $conformance->{strip_prefixes}); + my ($self,$e,$name,$ifname) = @_; + my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); + return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})})); - register_ett("ett_$ifname\_$name"); + $self->register_ett("ett_$ifname\_$name"); my $res = ""; - ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}}); + ($res.="\t".$self->Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}}); - pidl_hdr "int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"; + $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); - pidl_fn_start $dissectorname; - pidl_code "int"; - pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; - pidl_code "{"; - indent; - pidl_code "proto_item *item = NULL;"; - pidl_code "proto_tree *tree = NULL;"; - pidl_code "int old_offset;"; - pidl_code ""; + $self->pidl_fn_start($dissectorname); + $self->pidl_code("int"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("proto_item *item = NULL;"); + $self->pidl_code("proto_tree *tree = NULL;"); + $self->pidl_code("int old_offset;"); + $self->pidl_code(""); if ($e->{ALIGN} > 1) { - pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); } - pidl_code ""; - - pidl_code "old_offset = offset;"; - pidl_code ""; - pidl_code "if (parent_tree) {"; - indent; - pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);"; - pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);"; - deindent; - pidl_code "}"; - - pidl_code "\n$res"; - - pidl_code "proto_item_set_len(item, offset-old_offset);\n"; - pidl_code "return offset;"; - deindent; - pidl_code "}\n"; - pidl_fn_end $dissectorname; - - register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); + $self->pidl_code(""); + + $self->pidl_code("old_offset = offset;"); + $self->pidl_code(""); + $self->pidl_code("if (parent_tree) {"); + $self->indent; + $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);"); + $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);"); + $self->deindent; + $self->pidl_code("}"); + + $self->pidl_code("\n$res"); + + $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n"); + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end($dissectorname); + + $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); } -sub Union($$$) +sub Union($$$$) { - my ($e,$name,$ifname) = @_; + my ($self,$e,$name,$ifname) = @_; - my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $conformance->{strip_prefixes}); + my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $self->{conformance}->{strip_prefixes}); - return if (defined($conformance->{noemit}->{StripPrefixes($name, $conformance->{strip_prefixes})})); + return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})})); - register_ett("ett_$ifname\_$name"); + $self->register_ett("ett_$ifname\_$name"); my $res = ""; foreach (@{$e->{ELEMENTS}}) { $res.="\n\t\t$_->{CASE}:\n"; if ($_->{TYPE} ne "EMPTY") { - $res.="\t\t\t".Element($_, $name, $ifname)."\n"; + $res.="\t\t\t".$self->Element($_, $name, $ifname)."\n"; } $res.="\t\tbreak;\n"; } @@ -600,68 +603,68 @@ sub Union($$$) $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}"; } - pidl_fn_start $dissectorname; - pidl_code "static int"; - pidl_code "$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"; - pidl_code "{"; - indent; - pidl_code "proto_item *item = NULL;"; - pidl_code "proto_tree *tree = NULL;"; - pidl_code "int old_offset;"; - pidl_code "$switch_type level;"; - pidl_code ""; + $self->pidl_fn_start($dissectorname); + $self->pidl_code("static int"); + $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("proto_item *item = NULL;"); + $self->pidl_code("proto_tree *tree = NULL;"); + $self->pidl_code("int old_offset;"); + $self->pidl_code("$switch_type level;"); + $self->pidl_code(""); if ($e->{ALIGN} > 1) { - pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;"; + $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); } - pidl_code ""; + $self->pidl_code(""); - pidl_code "old_offset = offset;"; - pidl_code "if (parent_tree) {"; - indent; - pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");"; - pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);"; - deindent; - pidl_code "}"; + $self->pidl_code("old_offset = offset;"); + $self->pidl_code("if (parent_tree) {"); + $self->indent; + $self->pidl_code("item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");"); + $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);"); + $self->deindent; + $self->pidl_code("}"); - pidl_code ""; + $self->pidl_code(""); - pidl_code "offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"; + $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"); - pidl_code "switch(level) {$res\t}"; - pidl_code "proto_item_set_len(item, offset-old_offset);\n"; - pidl_code "return offset;"; - deindent; - pidl_code "}"; - pidl_fn_end $dissectorname; + $self->pidl_code("switch(level) {$res\t}"); + $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n"); + $self->pidl_code("return offset;"); + $self->deindent; + $self->pidl_code("}"); + $self->pidl_fn_end($dissectorname); - register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); + $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0); } -sub Const($$) +sub Const($$$) { - my ($const,$ifname) = @_; + my ($self,$const,$ifname) = @_; if (!defined($const->{ARRAY_LEN}[0])) { - pidl_hdr "#define $const->{NAME}\t( $const->{VALUE} )\n"; + $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n"); } else { - pidl_hdr "#define $const->{NAME}\t $const->{VALUE}\n"; + $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n"); } } -sub Typedef($$$) +sub Typedef($$$$) { - my ($e,$name,$ifname) = @_; + my ($self,$e,$name,$ifname) = @_; - Type($e->{DATA}, $name, $ifname); + $self->Type($e->{DATA}, $name, $ifname); } -sub Type($$$) +sub Type($$$$) { - my ($e, $name, $ifname) = @_; + my ($self, $e, $name, $ifname) = @_; - PrintIdl DumpType($e->{ORIGINAL}); + $self->PrintIdl(DumpType($e->{ORIGINAL})); { ENUM => \&Enum, @@ -669,20 +672,20 @@ sub Type($$$) UNION => \&Union, BITMAP => \&Bitmap, TYPEDEF => \&Typedef - }->{$e->{TYPE}}->($e, $name, $ifname); + }->{$e->{TYPE}}->($self, $e, $name, $ifname); } -sub RegisterInterface($) +sub RegisterInterface($$) { - my ($x) = @_; + my ($self, $x) = @_; - pidl_fn_start "proto_register_dcerpc_$x->{NAME}"; - pidl_code "void proto_register_dcerpc_$x->{NAME}(void)"; - pidl_code "{"; - indent; + $self->pidl_fn_start("proto_register_dcerpc_$x->{NAME}"); + $self->pidl_code("void proto_register_dcerpc_$x->{NAME}(void)"); + $self->pidl_code("{"); + $self->indent; - $res{code}.=DumpHfList()."\n"; - $res{code}.="\n".DumpEttList(@ett)."\n"; + $self->{res}->{code}.=$self->DumpHfList()."\n"; + $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n"; if (defined($x->{UUID})) { # These can be changed to non-pidl_code names if the old dissectors @@ -696,140 +699,142 @@ sub RegisterInterface($) $name = $x->{PROPERTIES}->{helpstring}; } - if (defined($conformance->{protocols}->{$x->{NAME}})) { - $short_name = $conformance->{protocols}->{$x->{NAME}}->{SHORTNAME}; - $name = $conformance->{protocols}->{$x->{NAME}}->{LONGNAME}; - $filter_name = $conformance->{protocols}->{$x->{NAME}}->{FILTERNAME}; + if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) { + $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME}; + $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME}; + $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME}; } - pidl_code "proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");"; + $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");"); - pidl_code "proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));"; - pidl_code "proto_register_subtree_array(ett, array_length(ett));"; + $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));"); + $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));"); } else { - pidl_code "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");"; - pidl_code "proto_register_field_array(proto_dcerpc, hf, array_length(hf));"; - pidl_code "proto_register_subtree_array(ett, array_length(ett));"; + $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");"); + $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));"); + $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));"); } - deindent; - pidl_code "}\n"; - pidl_fn_end "proto_register_dcerpc_$x->{NAME}"; + $self->deindent; + $self->pidl_code("}\n"); + $self->pidl_fn_end("proto_register_dcerpc_$x->{NAME}"); } -sub RegisterInterfaceHandoff($) +sub RegisterInterfaceHandoff($$) { - my $x = shift; + my ($self,$x) = @_; if (defined($x->{UUID})) { - pidl_fn_start "proto_reg_handoff_dcerpc_$x->{NAME}"; - pidl_code "void proto_reg_handoff_dcerpc_$x->{NAME}(void)"; - pidl_code "{"; - indent; - pidl_code "dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},"; - pidl_code "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},"; - pidl_code "\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);"; - deindent; - pidl_code "}"; - pidl_fn_end "proto_reg_handoff_dcerpc_$x->{NAME}"; - - $hf_used{"hf_$x->{NAME}_opnum"} = 1; + $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}"); + $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)"); + $self->pidl_code("{"); + $self->indent; + $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},"); + $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},"); + $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);"); + $self->deindent; + $self->pidl_code("}"); + $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}"); + + $self->{hf_used}->{"hf_$x->{NAME}_opnum"} = 1; } } sub ProcessInclude { + my $self = shift; my @includes = @_; foreach (@includes) { - pidl_hdr "#include \"$_\""; + $self->pidl_hdr("#include \"$_\""); } - pidl_hdr ""; + $self->pidl_hdr(""); } sub ProcessImport { + my $self = shift; my @imports = @_; foreach (@imports) { next if($_ eq "security"); s/\.idl\"$//; s/^\"//; - pidl_hdr "#include \"packet-dcerpc-$_\.h\""; + $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\""); } - pidl_hdr ""; + $self->pidl_hdr(""); } -sub ProcessInterface($) +sub ProcessInterface($$) { - my ($x) = @_; + my ($self, $x) = @_; - push(@{$conformance->{strip_prefixes}}, $x->{NAME}); + push(@{$self->{conformance}->{strip_prefixes}}, $x->{NAME}); my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H"; - pidl_hdr "#ifndef $define"; - pidl_hdr "#define $define"; - pidl_hdr ""; + $self->pidl_hdr("#ifndef $define"); + $self->pidl_hdr("#define $define"); + $self->pidl_hdr(""); - pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;"; - register_ett("ett_dcerpc_$x->{NAME}"); - register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, ""); + $self->pidl_def("static gint proto_dcerpc_$x->{NAME} = -1;"); + $self->register_ett("ett_dcerpc_$x->{NAME}"); + $self->register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, ""); if (defined($x->{UUID})) { my $if_uuid = $x->{UUID}; - pidl_def "/* Version information */\n\n"; + $self->pidl_def("/* Version information */\n\n"); - pidl_def "static e_uuid_t uuid_dcerpc_$x->{NAME} = {"; - pidl_def "\t0x" . substr($if_uuid, 1, 8) + $self->pidl_def("static e_uuid_t uuid_dcerpc_$x->{NAME} = {"); + $self->pidl_def("\t0x" . substr($if_uuid, 1, 8) . ", 0x" . substr($if_uuid, 10, 4) - . ", 0x" . substr($if_uuid, 15, 4) . ","; - pidl_def "\t{ 0x" . substr($if_uuid, 20, 2) + . ", 0x" . substr($if_uuid, 15, 4) . ","); + $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2) . ", 0x" . substr($if_uuid, 22, 2) . ", 0x" . substr($if_uuid, 25, 2) . ", 0x" . substr($if_uuid, 27, 2) . ", 0x" . substr($if_uuid, 29, 2) . ", 0x" . substr($if_uuid, 31, 2) . ", 0x" . substr($if_uuid, 33, 2) - . ", 0x" . substr($if_uuid, 35, 2) . " }"; - pidl_def "};"; + . ", 0x" . substr($if_uuid, 35, 2) . " }"); + $self->pidl_def("};"); my $maj = $x->{VERSION}; $maj =~ s/\.(.*)$//g; - pidl_def "static guint16 ver_dcerpc_$x->{NAME} = $maj;"; - pidl_def ""; + $self->pidl_def("static guint16 ver_dcerpc_$x->{NAME} = $maj;"); + $self->pidl_def(""); } $return_types{$x->{NAME}} = {}; - Interface($x); + $self->Interface($x); - pidl_code "\n".DumpFunctionTable($x); + $self->pidl_code("\n".DumpFunctionTable($x)); foreach (keys %{$return_types{$x->{NAME}}}) { my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}}; - my $dt = find_type($type); + my $dt = $self->find_type($type); $dt or die("Unable to find information about return type `$type'"); - register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, ""); - $hf_used{"hf_$x->{NAME}_$_"} = 1; + $self->register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, ""); + $self->{hf_used}->{"hf_$x->{NAME}_$_"} = 1; } - RegisterInterface($x); - RegisterInterfaceHandoff($x); + $self->RegisterInterface($x); + $self->RegisterInterfaceHandoff($x); - pidl_hdr "#endif /* $define */"; + $self->pidl_hdr("#endif /* $define */"); } -sub find_type($) +sub find_type($$) { - my $n = shift; + my ($self, $n) = @_; - return $conformance->{types}->{$n}; + return $self->{conformance}->{types}->{$n}; } -sub register_type($$$$$$$) +sub register_type($$$$$$$$) { - my ($type,$call,$ft,$base,$mask,$vals,$length) = @_; + my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_; - $conformance->{types}->{$type} = { + $self->{conformance}->{types}->{$type} = { NAME => $type, DISSECTOR_NAME => $call, FT_TYPE => $ft, @@ -841,61 +846,57 @@ sub register_type($$$$$$$) } # Loads the default types -sub Initialize($) +sub Initialize($$) { - my $cnf_file = shift; + my ($self, $cnf_file) = @_; - $conformance = { + $self->{conformance} = { imports => {}, header_fields=> {} }; - ReadConformance($cnf_file, $conformance) or print STDERR "warning: No conformance file `$cnf_file'\n"; + ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n"; foreach my $bytes (qw(1 2 4 8)) { my $bits = $bytes * 8; - register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); - register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); + $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes); + $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); } - register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); - register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); - register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4); - register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); - register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); - register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); - register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); - register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); - register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4); - register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); - register_type("SID", " + $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); + $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); + $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4); + $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8); + $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4); + $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4); + $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4); + $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4); + $self->register_type("SID", " dcerpc_info *di = (dcerpc_info *)pinfo->private_data; di->hf_index = \@HF\@; offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); ","FT_STRING", "BASE_DEC", 0, "NULL", 4); - register_type("WERROR", + $self->register_type("WERROR", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); - register_type("NTSTATUS", + $self->register_type("NTSTATUS", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); } ##################################################################### # Generate Wireshark parser and header code -sub Parse($$$$) +sub Parse($$$$$) { - my($ndr,$idl_file,$h_filename,$cnf_file) = @_; - Initialize($cnf_file); - - return (undef, undef) if defined($conformance->{noemit_dissector}); - - $tabs = ""; + my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_; + + $self->Initialize($cnf_file); - %res = (code=>"",def=>"",hdr=>""); - @ett = (); + return (undef, undef) if defined($self->{conformance}->{noemit_dissector}); my $notice = "/* DO NOT EDIT @@ -910,50 +911,50 @@ sub Parse($$$$) "; - pidl_hdr $notice; + $self->pidl_hdr($notice); - $res{headers} = "\n"; - $res{headers} .= "#ifdef HAVE_CONFIG_H\n"; - $res{headers} .= "#include \"config.h\"\n"; - $res{headers} .= "#endif\n\n"; - $res{headers} .= "#include \n"; - $res{headers} .= "#include \n"; - $res{headers} .= "#include \n\n"; + $self->{res}->{headers} = "\n"; + $self->{res}->{headers} .= "#ifdef HAVE_CONFIG_H\n"; + $self->{res}->{headers} .= "#include \"config.h\"\n"; + $self->{res}->{headers} .= "#endif\n\n"; + $self->{res}->{headers} .= "#include \n"; + $self->{res}->{headers} .= "#include \n"; + $self->{res}->{headers} .= "#include \n\n"; - $res{headers} .= "#include \"packet-dcerpc.h\"\n"; - $res{headers} .= "#include \"packet-dcerpc-nt.h\"\n"; - $res{headers} .= "#include \"packet-windows-common.h\"\n"; + $self->{res}->{headers} .= "#include \"packet-dcerpc.h\"\n"; + $self->{res}->{headers} .= "#include \"packet-dcerpc-nt.h\"\n"; + $self->{res}->{headers} .= "#include \"packet-windows-common.h\"\n"; my $h_basename = basename($h_filename); - $res{headers} .= "#include \"$h_basename\"\n"; - pidl_code ""; + $self->{res}->{headers} .= "#include \"$h_basename\"\n"; + $self->pidl_code(""); # Wireshark protocol registration foreach (@$ndr) { - ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE"); - ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT"); - ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE"); + $self->ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE"); + $self->ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT"); + $self->ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE"); } - $res{ett} = DumpEttDeclaration(@ett); - $res{hf} = DumpHfDeclaration(); + $self->{res}->{ett} = DumpEttDeclaration($self->{ett}); + $self->{res}->{hf} = $self->DumpHfDeclaration(); my $parser = $notice; - $parser.= $res{headers}; - $parser.=$res{ett}; - $parser.=$res{hf}; - $parser.=$res{def}; - if (exists ($conformance->{override})) { - $parser.=$conformance->{override}; + $parser.= $self->{res}->{headers}; + $parser.=$self->{res}->{ett}; + $parser.=$self->{res}->{hf}; + $parser.=$self->{res}->{def}; + if (exists ($self->{conformance}->{override})) { + $parser.=$self->{conformance}->{override}; } - $parser.=$res{code}; + $parser.=$self->{res}->{code}; my $header = "/* autogenerated by pidl */\n\n"; - $header.=$res{hdr}; + $header.=$self->{res}->{hdr}; - CheckUsed($conformance); + $self->CheckUsed($self->{conformance}); return ($parser,$header); } @@ -962,18 +963,18 @@ sub Parse($$$$) # ETT ############################################################################### -sub register_ett($) +sub register_ett($$) { - my $name = shift; + my ($self, $name) = @_; - push (@ett, $name); + push (@{$self->{ett}}, $name); } sub DumpEttList { - my @ett = @_; + my ($ett) = @_; my $res = "\tstatic gint *ett[] = {\n"; - foreach (@ett) { + foreach (@$ett) { $res .= "\t\t&$_,\n"; } @@ -982,9 +983,9 @@ sub DumpEttList sub DumpEttDeclaration { - my @ett = @_; + my ($ett) = @_; my $res = "\n/* Ett declarations */\n"; - foreach (@ett) { + foreach (@$ett) { $res .= "static gint $_ = -1;\n"; } @@ -995,16 +996,16 @@ sub DumpEttDeclaration # HF ############################################################################### -sub register_hf_field($$$$$$$$) +sub register_hf_field($$$$$$$$$) { - my ($index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_; + my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_; - if (defined ($conformance->{hf_renames}->{$index})) { - $conformance->{hf_renames}->{$index}->{USED} = 1; - return $conformance->{hf_renames}->{$index}->{NEWNAME}; + if (defined ($self->{conformance}->{hf_renames}->{$index})) { + $self->{conformance}->{hf_renames}->{$index}->{USED} = 1; + return $self->{conformance}->{hf_renames}->{$index}->{NEWNAME}; } - $conformance->{header_fields}->{$index} = { + $self->{conformance}->{header_fields}->{$index} = { INDEX => $index, NAME => $name, FILTER => $filter_name, @@ -1016,22 +1017,23 @@ sub register_hf_field($$$$$$$$) }; if ((not defined($blurb) or $blurb eq "") and - defined($conformance->{fielddescription}->{$index})) { - $conformance->{header_fields}->{$index}->{BLURB} = - $conformance->{fielddescription}->{$index}->{DESCRIPTION}; - $conformance->{fielddescription}->{$index}->{USED} = 1; + defined($self->{conformance}->{fielddescription}->{$index})) { + $self->{conformance}->{header_fields}->{$index}->{BLURB} = + $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION}; + $self->{conformance}->{fielddescription}->{$index}->{USED} = 1; } return $index; } -sub DumpHfDeclaration() +sub DumpHfDeclaration($) { + my ($self) = @_; my $res = ""; $res = "\n/* Header field declarations */\n"; - foreach (keys %{$conformance->{header_fields}}) + foreach (keys %{$self->{conformance}->{header_fields}}) { $res .= "static gint $_ = -1;\n"; } @@ -1039,11 +1041,12 @@ sub DumpHfDeclaration() return "$res\n"; } -sub DumpHfList() +sub DumpHfList($) { + my ($self) = @_; my $res = "\tstatic hf_register_info hf[] = {\n"; - foreach (values %{$conformance->{header_fields}}) + foreach (values %{$self->{conformance}->{header_fields}}) { $res .= "\t{ &$_->{INDEX}, { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str($_->{BLURB}).", HFILL }}, @@ -1075,11 +1078,11 @@ sub DumpFunctionTable($) return "$res};\n"; } -sub CheckUsed($) +sub CheckUsed($$) { - my $conformance = shift; + my ($self, $conformance) = @_; foreach (values %{$conformance->{header_fields}}) { - if (not defined($hf_used{$_->{INDEX}})) { + if (not defined($self->{hf_used}->{$_->{INDEX}})) { warning($_->{POS}, "hf field `$_->{INDEX}' not used"); } } -- cgit From 771b57b3fcd0daeb3731f18e5b4ef95013150b82 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 25 Apr 2007 16:10:54 +0000 Subject: r22520: Fix the TYPE command. (This used to be commit b81b0d3308bf51c2e22d54024b3d6f1a59c6b283) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 523fff9537..ea3f0db961 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -834,6 +834,8 @@ sub register_type($$$$$$$$) { my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_; + return if (defined($self->{conformance}->{types}->{$type})); + $self->{conformance}->{types}->{$type} = { NAME => $type, DISSECTOR_NAME => $call, -- cgit From ac0e2b606f35a43328c2df0280a1612ed19d0dbc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 7 May 2007 12:31:42 +0000 Subject: r22741: Add MSVC-specific pragma's for Wireshark. Patch from Ronnie. (This used to be commit 40d6235b2491462bae480415e2ae075c041b3b7e) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index ea3f0db961..1fb9c4034f 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -919,6 +919,14 @@ sub Parse($$$$$) $self->{res}->{headers} .= "#ifdef HAVE_CONFIG_H\n"; $self->{res}->{headers} .= "#include \"config.h\"\n"; $self->{res}->{headers} .= "#endif\n\n"; + + $res{headers} .= "#ifdef _MSC_VER\n"; + $res{headers} .= "#pragma warning(disable:4005)\n"; + $res{headers} .= "#pragma warning(disable:4013)\n"; + $res{headers} .= "#pragma warning(disable:4018)\n"; + $res{headers} .= "#pragma warning(disable:4101)\n"; + $res{headers} .= "#endif\n\n"; + $self->{res}->{headers} .= "#include \n"; $self->{res}->{headers} .= "#include \n"; $self->{res}->{headers} .= "#include \n\n"; -- cgit From b157580538a26f0b71fb9d06f167e385064432d5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 7 May 2007 12:41:23 +0000 Subject: r22742: Fix tests. (This used to be commit 7240c2d7e30968b751d944f8a9a50573fcbe6671) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index 1fb9c4034f..ac923bef74 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -920,12 +920,12 @@ sub Parse($$$$$) $self->{res}->{headers} .= "#include \"config.h\"\n"; $self->{res}->{headers} .= "#endif\n\n"; - $res{headers} .= "#ifdef _MSC_VER\n"; - $res{headers} .= "#pragma warning(disable:4005)\n"; - $res{headers} .= "#pragma warning(disable:4013)\n"; - $res{headers} .= "#pragma warning(disable:4018)\n"; - $res{headers} .= "#pragma warning(disable:4101)\n"; - $res{headers} .= "#endif\n\n"; + $self->{res}->{headers} .= "#ifdef _MSC_VER\n"; + $self->{res}->{headers} .= "#pragma warning(disable:4005)\n"; + $self->{res}->{headers} .= "#pragma warning(disable:4013)\n"; + $self->{res}->{headers} .= "#pragma warning(disable:4018)\n"; + $self->{res}->{headers} .= "#pragma warning(disable:4101)\n"; + $self->{res}->{headers} .= "#endif\n\n"; $self->{res}->{headers} .= "#include \n"; $self->{res}->{headers} .= "#include \n"; -- cgit From 7bf94150dac76fac39fe0999afe1d596970c5bb4 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 5 Jul 2007 07:19:14 +0000 Subject: r23721: For unions, The TAG and the ARM are aligned independently. Move emitting ALIGN_TO_x_BYTES to after the tag has been dissected so the alignment only affects the ARM. (This used to be commit 22945854d91c87cc17df681db5fd3c6871cdaadc) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index ac923bef74..ffe104c941 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -614,12 +614,6 @@ sub Union($$$$) $self->pidl_code("$switch_type level;"); $self->pidl_code(""); - if ($e->{ALIGN} > 1) { - $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); - } - - $self->pidl_code(""); - $self->pidl_code("old_offset = offset;"); $self->pidl_code("if (parent_tree) {"); $self->indent; @@ -632,6 +626,12 @@ sub Union($$$$) $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"); + if ($e->{ALIGN} > 1) { + $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); + $self->pidl_code(""); + } + + $self->pidl_code("switch(level) {$res\t}"); $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n"); $self->pidl_code("return offset;"); -- cgit From d4006e799ac1305092c2d292c9237f58938268a2 Mon Sep 17 00:00:00 2001 From: Julien Kerihuel Date: Wed, 13 Feb 2008 02:24:11 +0100 Subject: Support ETT_FIELD keyword. (This used to be commit ec8bd3991f76cf8746cf77c277c3491725711f9d) --- source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm index ffe104c941..8846b740ab 100644 --- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm @@ -940,6 +940,10 @@ sub Parse($$$$$) $self->{res}->{headers} .= "#include \"$h_basename\"\n"; $self->pidl_code(""); + if (defined($self->{conformance}->{ett})) { + register_ett($self,$_) foreach(@{$self->{conformance}->{ett}}) + } + # Wireshark protocol registration foreach (@$ndr) { -- cgit