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 idl2eth.c by Ronnie Sahlberg
7 # released under the GNU GPL
13 Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark
17 package Parse
::Pidl
::Wireshark
::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
::Wireshark
::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
84 die("Inconsistent state: $fn != $cur_fn") if ($fn ne $cur_fn);
91 return if (defined($cur_fn) and defined($conformance->{manual}->{$cur_fn}));
100 sub pidl_hdr($) { my $x = shift; $res{hdr} .= "$x\n"; }
101 sub pidl_def($) { my $x = shift; $res{def} .= "$x\n"; }
110 $tabs = substr($tabs, 0, -1);
117 foreach (split /\n/, $idl) {
118 pidl_code "/* IDL: $_ */";
124 #####################################################################
125 # parse the interface definitions
129 Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
130 Typedef($_,$interface->{NAME}) foreach (@{$interface->{TYPES}});
131 Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
136 my ($e,$name,$ifname) = @_;
137 my $valsstring = "$ifname\_$name\_vals";
138 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name);
140 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
142 foreach (@{$e->{ELEMENTS}}) {
143 if (/([^=]*)=(.*)/) {
144 pidl_hdr "#define $1 ($2)";
148 pidl_hdr "extern const value_string $valsstring\[];";
149 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
151 pidl_def "const value_string ".$valsstring."[] = {";
152 foreach (@{$e->{ELEMENTS}}) {
153 next unless (/([^=]*)=(.*)/);
154 pidl_def "\t{ $1, \"$1\" },";
157 pidl_def "{ 0, NULL }";
160 pidl_fn_start $dissectorname;
162 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)";
165 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, NULL);";
166 pidl_code "return offset;";
169 pidl_fn_end $dissectorname;
171 my $enum_size = $e->{BASE_TYPE};
172 $enum_size =~ s/uint//g;
173 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8);
178 my ($e,$name,$ifname) = @_;
179 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name);
181 register_ett("ett_$ifname\_$name");
183 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
185 pidl_fn_start $dissectorname;
187 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
190 pidl_code "proto_item *item = NULL;";
191 pidl_code "proto_tree *tree = NULL;";
194 pidl_code "g$e->{BASE_TYPE} flags;";
195 if ($e->{ALIGN} > 1) {
196 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
201 pidl_code "if (parent_tree) {";
203 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);";
204 pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);";
208 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);";
210 pidl_code "proto_item_append_text(item, \": \");\n";
211 pidl_code "if (!flags)";
212 pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n";
214 foreach (@{$e->{ELEMENTS}}) {
215 next unless (/([^ ]*) (.*)/);
216 my ($en,$ev) = ($1,$2);
217 my $hf_bitname = "hf_$ifname\_$name\_$en";
218 my $filtername = "$ifname\.$name\.$en";
220 $hf_used{$hf_bitname} = 1;
222 register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
224 pidl_def "static const true_false_string $name\_$en\_tfs = {";
225 if (defined($conformance->{tfs}->{$hf_bitname})) {
226 pidl_def " $conformance->{tfs}->{$hf_bitname}->{TRUE_STRING},";
227 pidl_def " $conformance->{tfs}->{$hf_bitname}->{FALSE_STRING},";
228 $conformance->{tfs}->{$hf_bitname}->{USED} = 1;
230 pidl_def " \"$en is SET\",";
231 pidl_def " \"$en is NOT SET\",";
235 pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);";
236 pidl_code "if (flags&$ev){";
237 pidl_code "\tproto_item_append_text(item, \"$en\");";
238 pidl_code "\tif (flags & (~$ev))";
239 pidl_code "\t\tproto_item_append_text(item, \", \");";
241 pidl_code "flags&=(~$ev);";
245 pidl_code "if (flags) {";
246 pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);";
248 pidl_code "return offset;";
251 pidl_fn_end $dissectorname;
253 my $size = $e->{BASE_TYPE};
255 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
258 sub ElementLevel($$$$$)
260 my ($e,$l,$hf,$myname,$pn) = @_;
264 if (defined($conformance->{dissectorparams}->{$myname})) {
265 $conformance->{dissectorparams}->{$myname}->{PARAM} = 1;
266 $param = $conformance->{dissectorparams}->{$myname}->{PARAM};
269 if ($l->{TYPE} eq "POINTER") {
271 if ($l->{LEVEL} eq "TOP") {
273 } elsif ($l->{LEVEL} eq "EMBEDDED") {
276 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);";
277 } elsif ($l->{TYPE} eq "ARRAY") {
278 if ($l->{IS_INLINE}) {
279 error($e->{ORIGINAL}, "Inline arrays not supported");
280 } elsif ($l->{IS_FIXED}) {
282 pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)";
283 pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);";
286 $type .= "c" if ($l->{IS_CONFORMANT});
287 $type .= "v" if ($l->{IS_VARYING});
289 unless ($l->{IS_ZERO_TERMINATED}) {
290 pidl_code "offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);";
292 my $nl = GetNextLevel($e,$l);
293 pidl_code "char *data;";
295 pidl_code "offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);";
296 pidl_code "proto_item_append_text(tree, \": %s\", data);";
299 } elsif ($l->{TYPE} eq "DATA") {
300 if ($l->{DATA_TYPE} eq "string") {
301 my $bs = 2; # Byte size defaults to that of UCS2
304 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
306 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
307 pidl_code "char *data;\n";
308 pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);";
309 pidl_code "proto_item_append_text(tree, \": %s\", data);";
310 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
311 pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);";
313 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
318 if ($conformance->{imports}->{$l->{DATA_TYPE}}) {
319 $call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA};
320 $conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
321 } elsif (defined($conformance->{imports}->{"$pn.$e->{NAME}"})) {
322 $call = $conformance->{imports}->{"$pn.$e->{NAME}"}->{DATA};
323 $conformance->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
325 } elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) {
326 $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
327 $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
329 if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/)
331 pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);";
337 $call =~ s/\@HF\@/$hf/g;
338 $call =~ s/\@PARAM\@/$param/g;
341 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
342 my $num_bits = ($l->{HEADER_SIZE}*8);
343 pidl_code "guint$num_bits size;";
344 pidl_code "int start_offset = offset;";
345 pidl_code "tvbuff_t *subtvb;";
346 pidl_code "offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);";
347 pidl_code "proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");";
349 pidl_code "subtvb = tvb_new_subset(tvb, offset, size, -1);";
350 pidl_code "$myname\_(subtvb, 0, pinfo, tree, drep);";
352 die("Unknown type `$_->{TYPE}'");
358 my ($e,$pn,$ifname) = @_;
360 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn)."\_".StripPrefixes($e->{NAME});
362 my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);";
364 my $type = find_type($e->{TYPE});
366 if (not defined($type)) {
370 VALSSTRING => "NULL",
371 FT_TYPE => "FT_NONE",
372 BASE_TYPE => "BASE_HEX"
376 if (ContainsString($e)) {
379 VALSSTRING => "NULL",
380 FT_TYPE => "FT_STRING",
381 BASE_TYPE => "BASE_DEC"
385 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}, "");
388 my $eltname = StripPrefixes($pn) . ".$e->{NAME}";
389 if (defined($conformance->{noemit}->{$eltname})) {
395 foreach (@{$e->{LEVELS}}) {
396 next if ($_->{TYPE} eq "SWITCH");
397 pidl_def "static int $dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep);";
398 pidl_fn_start "$dissectorname$add";
399 pidl_code "static int";
400 pidl_code "$dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)";
404 ElementLevel($e,$_,$hf,$dissectorname.$add,$pn);
407 pidl_code "return offset;";
410 pidl_fn_end "$dissectorname$add";
412 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
420 my ($fn,$ifname) = @_;
424 foreach (@{$fn->{ELEMENTS}}) {
425 $dissectornames{$_->{NAME}} = Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}});
428 my $fn_name = $_->{NAME};
429 $fn_name =~ s/^${ifname}_//;
431 PrintIdl DumpFunction($fn->{ORIGINAL});
432 pidl_fn_start "$ifname\_dissect\_$fn_name\_response";
433 pidl_code "static int";
434 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_)";
437 pidl_code "guint32 status;\n";
438 foreach (@{$fn->{ELEMENTS}}) {
439 if (grep(/out/,@{$_->{DIRECTION}})) {
440 pidl_code "$dissectornames{$_->{NAME}}";
441 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
446 if (not defined($fn->{RETURN_TYPE})) {
447 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
448 pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n";
449 pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))";
450 pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n";
451 $hf_used{"hf\_$ifname\_status"} = 1;
452 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
453 pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n";
454 pidl_code "if (status != 0 && check_col(pinfo->cinfo, COL_INFO))";
455 pidl_code "\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, DOS_errors, \"Unknown DOS error 0x%08x\"));\n";
457 $hf_used{"hf\_$ifname\_werror"} = 1;
459 print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n";
463 pidl_code "return offset;";
466 pidl_fn_end "$ifname\_dissect\_$fn_name\_response";
468 pidl_fn_start "$ifname\_dissect\_$fn_name\_request";
469 pidl_code "static int";
470 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_)";
473 foreach (@{$fn->{ELEMENTS}}) {
474 if (grep(/in/,@{$_->{DIRECTION}})) {
475 pidl_code "$dissectornames{$_->{NAME}}";
476 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
481 pidl_code "return offset;";
484 pidl_fn_end "$ifname\_dissect\_$fn_name\_request";
489 my ($e,$name,$ifname) = @_;
490 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name);
492 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
494 register_ett("ett_$ifname\_$name");
497 ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}});
499 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_);";
501 pidl_fn_start $dissectorname;
503 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
506 pidl_code "proto_item *item = NULL;";
507 pidl_code "proto_tree *tree = NULL;";
508 pidl_code "int old_offset;";
511 if ($e->{ALIGN} > 1) {
512 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
516 pidl_code "old_offset = offset;";
518 pidl_code "if (parent_tree) {";
520 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);";
521 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
527 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
528 pidl_code "return offset;";
531 pidl_fn_end $dissectorname;
533 register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
538 my ($e,$name,$ifname) = @_;
540 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name);
542 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
544 register_ett("ett_$ifname\_$name");
547 foreach (@{$e->{ELEMENTS}}) {
548 $res.="\n\t\t$_->{CASE}:\n";
549 if ($_->{TYPE} ne "EMPTY") {
550 $res.="\t\t\t".Element($_, $name, $ifname)."\n";
552 $res.="\t\tbreak;\n";
557 my $switch_dt = getType($e->{SWITCH_TYPE});
558 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
559 $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt);
560 $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt);
561 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
562 $switch_type = "g$e->{SWITCH_TYPE}";
563 $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}";
566 pidl_fn_start $dissectorname;
567 pidl_code "static int";
568 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
571 pidl_code "proto_item *item = NULL;";
572 pidl_code "proto_tree *tree = NULL;";
573 pidl_code "int old_offset;";
574 pidl_code "$switch_type level;";
577 if ($e->{ALIGN} > 1) {
578 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
583 pidl_code "old_offset = offset;";
584 pidl_code "if (parent_tree) {";
586 pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");";
587 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
593 pidl_code "offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);";
595 pidl_code "switch(level) {$res\t}";
596 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
597 pidl_code "return offset;";
600 pidl_fn_end $dissectorname;
602 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
607 my ($const,$ifname) = @_;
609 if (!defined($const->{ARRAY_LEN}[0])) {
610 pidl_hdr "#define $const->{NAME}\t( $const->{VALUE} )\n";
612 pidl_hdr "#define $const->{NAME}\t $const->{VALUE}\n";
618 my ($e,$ifname) = @_;
620 PrintIdl DumpTypedef($e->{ORIGINAL});
627 }->{$e->{DATA}->{TYPE}}->($e->{DATA}, $e->{NAME}, $ifname);
630 sub RegisterInterface($)
634 pidl_fn_start "proto_register_dcerpc_$x->{NAME}";
635 pidl_code "void proto_register_dcerpc_$x->{NAME}(void)";
639 $res{code}.=DumpHfList()."\n";
640 $res{code}.="\n".DumpEttList()."\n";
642 if (defined($x->{UUID})) {
643 # These can be changed to non-pidl_code names if the old dissectors
644 # in epan/dissctors are deleted.
646 my $name = uc($x->{NAME}) . " (pidl)";
647 my $short_name = uc($x->{NAME});
648 my $filter_name = $x->{NAME};
650 if (has_property($x, "helpstring")) {
651 $name = $x->{PROPERTIES}->{helpstring};
654 if (defined($conformance->{protocols}->{$x->{NAME}})) {
655 $short_name = $conformance->{protocols}->{$x->{NAME}}->{SHORTNAME};
656 $name = $conformance->{protocols}->{$x->{NAME}}->{LONGNAME};
657 $filter_name = $conformance->{protocols}->{$x->{NAME}}->{FILTERNAME};
660 pidl_code "proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");";
662 pidl_code "proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));";
663 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
665 pidl_code "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");";
666 pidl_code "proto_register_field_array(proto_dcerpc, hf, array_length(hf));";
667 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
672 pidl_fn_end "proto_register_dcerpc_$x->{NAME}";
675 sub RegisterInterfaceHandoff($)
679 if (defined($x->{UUID})) {
680 pidl_fn_start "proto_reg_handoff_dcerpc_$x->{NAME}";
681 pidl_code "void proto_reg_handoff_dcerpc_$x->{NAME}(void)";
684 pidl_code "dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},";
685 pidl_code "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},";
686 pidl_code "\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);";
689 pidl_fn_end "proto_reg_handoff_dcerpc_$x->{NAME}";
691 $hf_used{"hf_$x->{NAME}_opnum"} = 1;
695 sub ProcessInterface($)
699 push(@{$conformance->{strip_prefixes}}, $x->{NAME});
701 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
702 pidl_hdr "#ifndef $define";
703 pidl_hdr "#define $define";
706 if (defined $x->{PROPERTIES}->{depends}) {
707 foreach (split / /, $x->{PROPERTIES}->{depends}) {
708 next if($_ eq "security");
709 pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n";
713 pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;";
714 register_ett("ett_dcerpc_$x->{NAME}");
715 register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
717 if (defined($x->{UUID})) {
718 my $if_uuid = $x->{UUID};
720 pidl_def "/* Version information */\n\n";
722 pidl_def "static e_uuid_t uuid_dcerpc_$x->{NAME} = {";
723 pidl_def "\t0x" . substr($if_uuid, 1, 8)
724 . ", 0x" . substr($if_uuid, 10, 4)
725 . ", 0x" . substr($if_uuid, 15, 4) . ",";
726 pidl_def "\t{ 0x" . substr($if_uuid, 20, 2)
727 . ", 0x" . substr($if_uuid, 22, 2)
728 . ", 0x" . substr($if_uuid, 25, 2)
729 . ", 0x" . substr($if_uuid, 27, 2)
730 . ", 0x" . substr($if_uuid, 29, 2)
731 . ", 0x" . substr($if_uuid, 31, 2)
732 . ", 0x" . substr($if_uuid, 33, 2)
733 . ", 0x" . substr($if_uuid, 35, 2) . " }";
736 my $maj = $x->{VERSION};
737 $maj =~ s/\.(.*)$//g;
738 pidl_def "static guint16 ver_dcerpc_$x->{NAME} = $maj;";
744 pidl_code "\n".DumpFunctionTable($x);
746 # Only register these two return types if they were actually used
747 if (defined($hf_used{"hf_$x->{NAME}_status"})) {
748 register_hf_field("hf_$x->{NAME}_status", "Status", "$x->{NAME}.status", "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", 0, "");
751 if (defined($hf_used{"hf_$x->{NAME}_werror"})) {
752 register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "VALS(DOS_errors)", 0, "");
755 RegisterInterface($x);
756 RegisterInterfaceHandoff($x);
758 pidl_hdr "#endif /* $define */";
765 return $conformance->{types}->{$n};
768 sub register_type($$$$$$$)
770 my ($type,$call,$ft,$base,$mask,$vals,$length) = @_;
772 $conformance->{types}->{$type} = {
774 DISSECTOR_NAME => $call,
783 # Loads the default types
786 my $cnf_file = shift;
793 ReadConformance($cnf_file, $conformance) or print "Warning: No conformance file `$cnf_file'\n";
795 foreach my $bytes (qw(1 2 4 8)) {
796 my $bits = $bytes * 8;
797 register_type
("uint$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@,NULL);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
798 register_type
("int$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
801 register_type
("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
802 register_type
("bool8", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
803 register_type
("char", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
804 register_type
("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
805 register_type
("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
806 register_type
("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
807 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);
808 register_type
("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
809 register_type
("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
810 register_type
("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4);
811 register_type
("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
812 register_type
("SID", "
813 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
815 di->hf_index = \@HF\@;
817 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
818 ","FT_STRING", "BASE_DEC", 0, "NULL", 4);
819 register_type
("WERROR",
820 "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4);
824 #####################################################################
825 # Generate Wireshark parser and header code
828 my($ndr,$idl_file,$h_filename,$cnf_file) = @_;
829 Initialize
($cnf_file);
831 return (undef, undef) if defined($conformance->{noemit_dissector
});
835 %res = (code
=>"",def
=>"",hdr
=>"");
840 This filter was automatically generated
841 from $idl_file and $cnf_file.
843 Pidl is a perl based IDL compiler for DCE/RPC idl files.
844 It is maintained by the Samba team, not the Wireshark team.
845 Instructions on how to download and install Pidl can be
846 found at http://wiki.wireshark.org/Pidl
853 $res{headers
} = "\n";
854 $res{headers
} .= "#ifdef HAVE_CONFIG_H\n";
855 $res{headers
} .= "#include \"config.h\"\n";
856 $res{headers
} .= "#endif\n\n";
857 $res{headers
} .= "#include <glib.h>\n";
858 $res{headers
} .= "#include <string.h>\n";
859 $res{headers
} .= "#include <epan/packet.h>\n\n";
861 $res{headers
} .= "#include \"packet-dcerpc.h\"\n";
862 $res{headers
} .= "#include \"packet-dcerpc-nt.h\"\n";
863 $res{headers
} .= "#include \"packet-windows-common.h\"\n";
865 my $h_basename = basename
($h_filename);
867 $res{headers
} .= "#include \"$h_basename\"\n";
870 # Wireshark protocol registration
872 ProcessInterface
($_) foreach (@
$ndr);
874 $res{ett
} = DumpEttDeclaration
();
875 $res{hf
} = DumpHfDeclaration
();
877 my $parser = $notice;
878 $parser.= $res{headers
};
882 $parser.=$conformance->{override
};
885 my $header = "/* autogenerated by pidl */\n\n";
888 CheckUsed
($conformance);
890 return ($parser,$header);
893 ###############################################################################
895 ###############################################################################
906 my $res = "\tstatic gint *ett[] = {\n";
908 $res .= "\t\t&$_,\n";
914 sub DumpEttDeclaration
()
916 my $res = "\n/* Ett declarations */\n";
918 $res .= "static gint $_ = -1;\n";
924 ###############################################################################
926 ###############################################################################
928 sub register_hf_field
($$$$$$$$)
930 my ($index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
932 if (defined ($conformance->{hf_renames
}->{$index})) {
933 $conformance->{hf_renames
}->{$index}->{USED
} = 1;
934 return $conformance->{hf_renames
}->{$index}->{NEWNAME
};
937 $conformance->{header_fields
}->{$index} = {
940 FILTER
=> $filter_name,
942 BASE_TYPE
=> $base_type,
943 VALSSTRING
=> $valsstring,
948 if ((not defined($blurb) or $blurb eq "") and
949 defined($conformance->{fielddescription
}->{$index})) {
950 $conformance->{header_fields
}->{$index}->{BLURB
} =
951 $conformance->{fielddescription
}->{$index}->{DESCRIPTION
};
952 $conformance->{fielddescription
}->{$index}->{USED
} = 1;
958 sub DumpHfDeclaration
()
962 $res = "\n/* Header field declarations */\n";
964 foreach (keys %{$conformance->{header_fields
}})
966 $res .= "static gint $_ = -1;\n";
974 my $res = "\tstatic hf_register_info hf[] = {\n";
976 foreach (values %{$conformance->{header_fields
}})
978 $res .= "\t{ &$_->{INDEX},
979 { ".make_str
($_->{NAME
}).", ".make_str
($_->{FILTER
}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str
($_->{BLURB
}).", HFILL }},
983 return $res."\t};\n";
987 ###############################################################################
989 ###############################################################################
991 sub DumpFunctionTable
($)
995 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
996 foreach (@
{$if->{FUNCTIONS
}}) {
997 my $fn_name = $_->{NAME
};
998 $fn_name =~ s/^$if->{NAME}_//;
999 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
1000 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
1003 $res .= "\t{ 0, NULL, NULL, NULL }\n";
1010 my $conformance = shift;
1011 foreach (values %{$conformance->{header_fields
}}) {
1012 if (not defined($hf_used{$_->{INDEX
}})) {
1013 print "$_->{POS}: warning: hf field `$_->{INDEX}' not used\n";
1017 foreach (values %{$conformance->{hf_renames
}}) {
1018 if (not $_->{USED
}) {
1019 print "$_->{POS}: warning: hf field `$_->{OLDNAME}' not used\n";
1023 foreach (values %{$conformance->{dissectorparams
}}) {
1024 if (not $_->{USED
}) {
1025 print "$_->{POS}: warning: dissector param never used\n";
1029 foreach (values %{$conformance->{imports
}}) {
1030 if (not $_->{USED
}) {
1031 print "$_->{POS}: warning: import never used\n";
1035 foreach (values %{$conformance->{types
}}) {
1036 if (not $_->{USED
} and defined($_->{POS
})) {
1037 print "$_->{POS}: warning: type never used\n";
1041 foreach (values %{$conformance->{fielddescription
}}) {
1042 if (not $_->{USED
}) {
1043 print "$_->{POS}: warning: description never used\n";
1047 foreach (values %{$conformance->{tfs
}}) {
1048 if (not $_->{USED
}) {
1049 print "$_->{POS}: warning: True/False description never used\n";