1 ##################################################
2 # Samba4 NDR parser generator for IDL structures
3 # Copyright tridge@samba.org 2000-2003
4 # Copyright tpot@samba.org 2001,2005
5 # Copyright jelmer@samba.org 2004-2005
6 # Portions based on idl2wrs.c by Ronnie Sahlberg
7 # released under the GNU GPL
13 Parse::Pidl::Ethereal::NDR - Parser generator for Wireshark
17 package Parse::Pidl::Ethereal::NDR;
20 use Parse::Pidl::Typelist qw(getType);
21 use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str);
22 use Parse::Pidl::NDR qw(ContainsString GetNextLevel);
23 use Parse::Pidl::Dump qw(DumpTypedef DumpFunction);
24 use Parse::Pidl::Ethereal::Conformance qw(ReadConformance);
27 use vars qw($VERSION);
33 print "$e->{FILE}:$e->{LINE}: $t\n";
39 my %dissector_used = ();
41 my $conformance = undef;
43 my %ptrtype_mappings = (
44 "unique" => "NDR_POINTER_UNIQUE",
45 "ref" => "NDR_POINTER_REF",
46 "ptr" => "NDR_POINTER_PTR"
53 foreach (@{$conformance->{strip_prefixes}}) {
60 # Convert a IDL structure field name (e.g access_mask) to a prettier
61 # string like 'Access Mask'.
67 $field =~ s/_/ /g; # Replace underscores with spaces
68 $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word
85 sub pidl_hdr($) { my $x = shift; $res{hdr} .= "$x\n"; }
86 sub pidl_def($) { my $x = shift; $res{def} .= "$x\n"; }
95 $tabs = substr($tabs, 0, -1);
102 foreach (split /\n/, $idl) {
103 pidl_code "/* IDL: $_ */";
109 #####################################################################
110 # parse the interface definitions
114 Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
115 Typedef($_,$interface->{NAME}) foreach (@{$interface->{TYPES}});
116 Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
121 my ($e,$name,$ifname) = @_;
122 my $valsstring = "$ifname\_$name\_vals";
123 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name);
125 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
127 foreach (@{$e->{ELEMENTS}}) {
128 if (/([^=]*)=(.*)/) {
129 pidl_hdr "#define $1 ($2)";
133 pidl_hdr "extern const value_string $valsstring\[];";
134 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
136 pidl_def "const value_string ".$valsstring."[] = {";
137 foreach (@{$e->{ELEMENTS}}) {
138 next unless (/([^=]*)=(.*)/);
139 pidl_def "\t{ $1, \"$1\" },";
142 pidl_def "{ 0, NULL }";
146 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)";
149 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, NULL);";
150 pidl_code "return offset;";
154 my $enum_size = $e->{BASE_TYPE};
155 $enum_size =~ s/uint//g;
156 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8);
161 my ($e,$name,$ifname) = @_;
162 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name);
164 register_ett("ett_$ifname\_$name");
166 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
169 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
172 pidl_code "proto_item *item = NULL;";
173 pidl_code "proto_tree *tree = NULL;";
176 pidl_code "g$e->{BASE_TYPE} flags;";
177 if ($e->{ALIGN} > 1) {
178 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
183 pidl_code "if (parent_tree) {";
185 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);";
186 pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);";
190 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);";
192 pidl_code "proto_item_append_text(item, \": \");\n";
193 pidl_code "if (!flags)";
194 pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n";
196 foreach (@{$e->{ELEMENTS}}) {
197 next unless (/([^ ]*) (.*)/);
198 my ($en,$ev) = ($1,$2);
199 my $hf_bitname = "hf_$ifname\_$name\_$en";
200 my $filtername = "$ifname\.$name\.$en";
202 $hf_used{$hf_bitname} = 1;
204 register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
206 pidl_def "static const true_false_string $name\_$en\_tfs = {";
207 if (defined($conformance->{tfs}->{$hf_bitname})) {
208 pidl_def " $conformance->{tfs}->{$hf_bitname}->{TRUE_STRING},";
209 pidl_def " $conformance->{tfs}->{$hf_bitname}->{FALSE_STRING},";
210 $conformance->{tfs}->{$hf_bitname}->{USED} = 1;
212 pidl_def " \"$en is SET\",";
213 pidl_def " \"$en is NOT SET\",";
217 pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);";
218 pidl_code "if (flags&$ev){";
219 pidl_code "\tproto_item_append_text(item, \"$en\");";
220 pidl_code "\tif (flags & (~$ev))";
221 pidl_code "\t\tproto_item_append_text(item, \", \");";
223 pidl_code "flags&=(~$ev);";
227 pidl_code "if (flags) {";
228 pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);";
230 pidl_code "return offset;";
234 my $size = $e->{BASE_TYPE};
236 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
239 sub ElementLevel($$$$$)
241 my ($e,$l,$hf,$myname,$pn) = @_;
245 if (defined($conformance->{dissectorparams}->{$myname})) {
246 $conformance->{dissectorparams}->{$myname}->{PARAM} = 1;
247 $param = $conformance->{dissectorparams}->{$myname}->{PARAM};
250 if ($l->{TYPE} eq "POINTER") {
252 if ($l->{LEVEL} eq "TOP") {
254 } elsif ($l->{LEVEL} eq "EMBEDDED") {
257 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);";
258 } elsif ($l->{TYPE} eq "ARRAY") {
259 if ($l->{IS_INLINE}) {
260 error($e->{ORIGINAL}, "Inline arrays not supported");
261 } elsif ($l->{IS_FIXED}) {
263 pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)";
264 pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);";
267 $type .= "c" if ($l->{IS_CONFORMANT});
268 $type .= "v" if ($l->{IS_VARYING});
270 unless ($l->{IS_ZERO_TERMINATED}) {
271 pidl_code "offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);";
273 my $nl = GetNextLevel($e,$l);
274 pidl_code "char *data;";
276 pidl_code "offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);";
277 pidl_code "proto_item_append_text(tree, \": %s\", data);";
280 } elsif ($l->{TYPE} eq "DATA") {
281 if ($l->{DATA_TYPE} eq "string") {
282 my $bs = 2; # Byte size defaults to that of UCS2
285 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
287 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
288 pidl_code "char *data;\n";
289 pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);";
290 pidl_code "proto_item_append_text(tree, \": %s\", data);";
291 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
292 pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);";
294 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
299 if ($conformance->{imports}->{$l->{DATA_TYPE}}) {
300 $call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA};
301 $conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
302 } elsif (defined($conformance->{imports}->{"$pn.$e->{NAME}"})) {
303 $call = $conformance->{imports}->{"$pn.$e->{NAME}"}->{DATA};
304 $conformance->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
306 } elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) {
307 $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
308 $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
310 if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/)
312 pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);";
318 $call =~ s/\@HF\@/$hf/g;
319 $call =~ s/\@PARAM\@/$param/g;
322 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
323 my $num_bits = ($l->{HEADER_SIZE}*8);
324 pidl_code "guint$num_bits size;";
325 pidl_code "int start_offset = offset;";
326 pidl_code "tvbuff_t *subtvb;";
327 pidl_code "offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);";
328 pidl_code "proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");";
330 pidl_code "subtvb = tvb_new_subset(tvb, offset, size, -1);";
331 pidl_code "$myname\_(subtvb, 0, pinfo, tree, drep);";
333 die("Unknown type `$_->{TYPE}'");
339 my ($e,$pn,$ifname) = @_;
341 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn)."\_".StripPrefixes($e->{NAME});
343 my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);";
345 my $type = find_type($e->{TYPE});
347 if (not defined($type)) {
351 VALSSTRING => "NULL",
352 FT_TYPE => "FT_NONE",
353 BASE_TYPE => "BASE_HEX"
357 if (ContainsString($e)) {
360 VALSSTRING => "NULL",
361 FT_TYPE => "FT_STRING",
362 BASE_TYPE => "BASE_DEC"
366 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}, "");
369 my $eltname = StripPrefixes($pn) . ".$e->{NAME}";
370 if (defined($conformance->{noemit}->{$eltname})) {
376 foreach (@{$e->{LEVELS}}) {
377 next if ($_->{TYPE} eq "SWITCH");
378 pidl_def "static int $dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep);";
379 pidl_code "static int";
380 pidl_code "$dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)";
384 ElementLevel($e,$_,$hf,$dissectorname.$add,$pn);
387 pidl_code "return offset;";
391 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
399 my ($fn,$ifname) = @_;
403 foreach (@{$fn->{ELEMENTS}}) {
404 $dissectornames{$_->{NAME}} = Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}});
407 my $fn_name = $_->{NAME};
408 $fn_name =~ s/^${ifname}_//;
410 PrintIdl DumpFunction($fn->{ORIGINAL});
411 pidl_code "static int";
412 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_)";
415 pidl_code "guint32 status;\n";
416 foreach (@{$fn->{ELEMENTS}}) {
417 if (grep(/out/,@{$_->{DIRECTION}})) {
418 pidl_code "$dissectornames{$_->{NAME}}";
419 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
424 if (not defined($fn->{RETURN_TYPE})) {
425 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
426 pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n";
427 pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))";
428 pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n";
429 $hf_used{"hf\_$ifname\_status"} = 1;
430 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
431 pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n";
432 pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))";
433 pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, DOS_errors, \"Unknown DOS error 0x%08x\"));\n";
435 $hf_used{"hf\_$ifname\_werror"} = 1;
437 print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n";
441 pidl_code "return offset;";
445 pidl_code "static int";
446 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_)";
449 foreach (@{$fn->{ELEMENTS}}) {
450 if (grep(/in/,@{$_->{DIRECTION}})) {
451 pidl_code "$dissectornames{$_->{NAME}}";
452 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
457 pidl_code "return offset;";
464 my ($e,$name,$ifname) = @_;
465 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name);
467 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
469 register_ett("ett_$ifname\_$name");
472 ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}});
474 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_);";
477 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
480 pidl_code "proto_item *item = NULL;";
481 pidl_code "proto_tree *tree = NULL;";
482 pidl_code "int old_offset;";
485 if ($e->{ALIGN} > 1) {
486 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
490 pidl_code "old_offset = offset;";
492 pidl_code "if (parent_tree) {";
494 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);";
495 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
501 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
502 pidl_code "return offset;";
506 register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
511 my ($e,$name,$ifname) = @_;
513 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name);
515 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
517 register_ett("ett_$ifname\_$name");
520 foreach (@{$e->{ELEMENTS}}) {
521 $res.="\n\t\t$_->{CASE}:\n";
522 if ($_->{TYPE} ne "EMPTY") {
523 $res.="\t\t\t".Element($_, $name, $ifname)."\n";
525 $res.="\t\tbreak;\n";
530 my $switch_dt = getType($e->{SWITCH_TYPE});
531 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
532 $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt);
533 $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt);
534 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
535 $switch_type = "g$e->{SWITCH_TYPE}";
536 $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}";
539 pidl_code "static int";
540 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
543 pidl_code "proto_item *item = NULL;";
544 pidl_code "proto_tree *tree = NULL;";
545 pidl_code "int old_offset;";
546 pidl_code "$switch_type level;";
549 if ($e->{ALIGN} > 1) {
550 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
555 pidl_code "old_offset = offset;";
556 pidl_code "if (parent_tree) {";
558 pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");";
559 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
565 pidl_code "offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);";
567 pidl_code "switch(level) {$res\t}";
568 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
569 pidl_code "return offset;";
573 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
578 my ($const,$ifname) = @_;
580 if (!defined($const->{ARRAY_LEN}[0])) {
581 pidl_hdr "#define $const->{NAME}\t( $const->{VALUE} )\n";
583 pidl_hdr "#define $const->{NAME}\t $const->{VALUE}\n";
589 my ($e,$ifname) = @_;
591 PrintIdl DumpTypedef($e->{ORIGINAL});
598 }->{$e->{DATA}->{TYPE}}->($e->{DATA}, $e->{NAME}, $ifname);
601 sub RegisterInterface($)
605 pidl_code "void proto_register_dcerpc_$x->{NAME}(void)";
609 $res{code}.=DumpHfList()."\n";
610 $res{code}.="\n".DumpEttList()."\n";
612 if (defined($x->{UUID})) {
613 # These can be changed to non-pidl_code names if the old dissectors
614 # in epan/dissctors are deleted.
616 my $name = uc($x->{NAME}) . " (pidl)";
617 my $short_name = uc($x->{NAME});
618 my $filter_name = $x->{NAME};
620 if (has_property($x, "helpstring")) {
621 $name = $x->{PROPERTIES}->{helpstring};
624 if (defined($conformance->{protocols}->{$x->{NAME}})) {
625 $short_name = $conformance->{protocols}->{$x->{NAME}}->{SHORTNAME};
626 $name = $conformance->{protocols}->{$x->{NAME}}->{LONGNAME};
627 $filter_name = $conformance->{protocols}->{$x->{NAME}}->{FILTERNAME};
630 pidl_code "proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");";
632 pidl_code "proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));";
633 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
635 pidl_code "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");";
636 pidl_code "proto_register_field_array(proto_dcerpc, hf, array_length(hf));";
637 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
644 sub RegisterInterfaceHandoff($)
648 if (defined($x->{UUID})) {
649 pidl_code "void proto_reg_handoff_dcerpc_$x->{NAME}(void)";
652 pidl_code "dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},";
653 pidl_code "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},";
654 pidl_code "\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);";
658 $hf_used{"hf_$x->{NAME}_opnum"} = 1;
662 sub ProcessInterface($)
666 push(@{$conformance->{strip_prefixes}}, $x->{NAME});
668 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
669 pidl_hdr "#ifndef $define";
670 pidl_hdr "#define $define";
673 if (defined $x->{PROPERTIES}->{depends}) {
674 foreach (split / /, $x->{PROPERTIES}->{depends}) {
675 next if($_ eq "security");
676 pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n";
680 pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;";
681 register_ett("ett_dcerpc_$x->{NAME}");
682 register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
684 if (defined($x->{UUID})) {
685 my $if_uuid = $x->{UUID};
687 pidl_def "/* Version information */\n\n";
689 pidl_def "static e_uuid_t uuid_dcerpc_$x->{NAME} = {";
690 pidl_def "\t0x" . substr($if_uuid, 1, 8)
691 . ", 0x" . substr($if_uuid, 10, 4)
692 . ", 0x" . substr($if_uuid, 15, 4) . ",";
693 pidl_def "\t{ 0x" . substr($if_uuid, 20, 2)
694 . ", 0x" . substr($if_uuid, 22, 2)
695 . ", 0x" . substr($if_uuid, 25, 2)
696 . ", 0x" . substr($if_uuid, 27, 2)
697 . ", 0x" . substr($if_uuid, 29, 2)
698 . ", 0x" . substr($if_uuid, 31, 2)
699 . ", 0x" . substr($if_uuid, 33, 2)
700 . ", 0x" . substr($if_uuid, 35, 2) . " }";
703 my $maj = $x->{VERSION};
704 $maj =~ s/\.(.*)$//g;
705 pidl_def "static guint16 ver_dcerpc_$x->{NAME} = $maj;";
711 pidl_code "\n".DumpFunctionTable($x);
713 # Only register these two return types if they were actually used
714 if (defined($hf_used{"hf_$x->{NAME}_status"})) {
715 register_hf_field("hf_$x->{NAME}_status", "Status", "$x->{NAME}.status", "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", 0, "");
718 if (defined($hf_used{"hf_$x->{NAME}_werror"})) {
719 register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(DOS_errors)", 0, "");
722 RegisterInterface($x);
723 RegisterInterfaceHandoff($x);
725 pidl_hdr "#endif /* $define */";
732 return $conformance->{types}->{$n};
735 sub register_type($$$$$$$)
737 my ($type,$call,$ft,$base,$mask,$vals,$length) = @_;
739 $conformance->{types}->{$type} = {
741 DISSECTOR_NAME => $call,
750 # Loads the default types
753 my $cnf_file = shift;
760 ReadConformance($cnf_file, $conformance) or print "Warning: No conformance file `$cnf_file'\n";
762 foreach my $bytes (qw(1 2 4 8)) {
763 my $bits = $bytes * 8;
764 register_type("uint$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@,NULL);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
765 register_type("int$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
768 register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
769 register_type("bool8", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
770 register_type("char", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
771 register_type("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
772 register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
773 register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
774 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);
775 register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
776 register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
777 register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4);
778 register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
779 register_type("SID", "
780 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
782 di->hf_index = \@HF\@;
784 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
785 ","FT_STRING", "BASE_DEC", 0, "NULL", 4);
786 register_type("WERROR",
787 "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4);
791 #####################################################################
792 # Generate ethereal parser and header code
795 my($ndr,$idl_file,$h_filename,$cnf_file) = @_;
796 Initialize($cnf_file);
798 return (undef, undef) if defined($conformance->{noemit_dissector});
802 %res = (code=>"",def=>"",hdr=>"");
807 This filter was automatically generated
808 from $idl_file and $cnf_file.
810 Pidl is a perl based IDL compiler for DCE/RPC idl files.
811 It is maintained by the Samba team, not the Wireshark team.
812 Instructions on how to download and install Pidl can be
813 found at http://wiki.wireshark.org/Pidl
820 $res{headers} = "\n";
821 $res{headers} .= "#ifdef HAVE_CONFIG_H\n";
822 $res{headers} .= "#include \"config.h\"\n";
823 $res{headers} .= "#endif\n\n";
824 $res{headers} .= "#include <glib.h>\n";
825 $res{headers} .= "#include <string.h>\n";
826 $res{headers} .= "#include <epan/packet.h>\n\n";
828 $res{headers} .= "#include \"packet-dcerpc.h\"\n";
829 $res{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
830 $res{headers} .= "#include \"packet-windows-common.h\"\n";
832 my $h_basename = basename($h_filename);
834 $res{headers} .= "#include \"$h_basename\"\n";
837 # Ethereal protocol registration
839 ProcessInterface($_) foreach (@$ndr);
841 $res{ett} = DumpEttDeclaration();
842 $res{hf} = DumpHfDeclaration();
844 my $parser = $notice;
845 $parser.= $res{headers};
849 $parser.=$conformance->{override};
852 my $header = "/* autogenerated by pidl */\n\n";
855 CheckUsed($conformance);
857 return ($parser,$header);
860 ###############################################################################
862 ###############################################################################
873 my $res = "\tstatic gint *ett[] = {\n";
875 $res .= "\t\t&$_,\n";
881 sub DumpEttDeclaration()
883 my $res = "\n/* Ett declarations */\n";
885 $res .= "static gint $_ = -1;\n";
891 ###############################################################################
893 ###############################################################################
895 sub register_hf_field($$$$$$$$)
897 my ($index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
899 if (defined ($conformance->{hf_renames}->{$index})) {
900 $conformance->{hf_renames}->{$index}->{USED} = 1;
901 return $conformance->{hf_renames}->{$index}->{NEWNAME};
904 $conformance->{header_fields}->{$index} = {
907 FILTER => $filter_name,
909 BASE_TYPE => $base_type,
910 VALSSTRING => $valsstring,
915 if ((not defined($blurb) or $blurb eq "") and
916 defined($conformance->{fielddescription}->{$index})) {
917 $conformance->{header_fields}->{$index}->{BLURB} =
918 $conformance->{fielddescription}->{$index}->{DESCRIPTION};
919 $conformance->{fielddescription}->{$index}->{USED} = 1;
925 sub DumpHfDeclaration()
929 $res = "\n/* Header field declarations */\n";
931 foreach (keys %{$conformance->{header_fields}})
933 $res .= "static gint $_ = -1;\n";
941 my $res = "\tstatic hf_register_info hf[] = {\n";
943 foreach (values %{$conformance->{header_fields}})
945 $res .= "\t{ &$_->{INDEX},
946 { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str($_->{BLURB}).", HFILL }},
950 return $res."\t};\n";
954 ###############################################################################
956 ###############################################################################
958 sub DumpFunctionTable($)
962 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
963 foreach (@{$if->{FUNCTIONS}}) {
964 my $fn_name = $_->{NAME};
965 $fn_name =~ s/^$if->{NAME}_//;
966 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
967 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
970 $res .= "\t{ 0, NULL, NULL, NULL }\n";
977 my $conformance = shift;
978 foreach (values %{$conformance->{header_fields}}) {
979 if (not defined($hf_used{$_->{INDEX}})) {
980 print "$_->{POS}: warning: hf field `$_->{INDEX}' not used\n";
984 foreach (values %{$conformance->{hf_renames}}) {
985 if (not $_->{USED}) {
986 print "$_->{POS}: warning: hf field `$_->{OLDNAME}' not used\n";
990 foreach (values %{$conformance->{dissectorparams}}) {
991 if (not $_->{USED}) {
992 print "$_->{POS}: warning: dissector param never used\n";
996 foreach (values %{$conformance->{imports}}) {
997 if (not $_->{USED}) {
998 print "$_->{POS}: warning: import never used\n";
1002 foreach (values %{$conformance->{types}}) {
1003 if (not $_->{USED} and defined($_->{POS})) {
1004 print "$_->{POS}: warning: type never used\n";
1008 foreach (values %{$conformance->{fielddescription}}) {
1009 if (not $_->{USED}) {
1010 print "$_->{POS}: warning: description never used\n";
1014 foreach (values %{$conformance->{tfs}}) {
1015 if (not $_->{USED}) {
1016 print "$_->{POS}: warning: True/False description never used\n";