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
9 package Parse::Pidl::Ethereal::NDR;
12 use Parse::Pidl::Typelist;
13 use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str);
15 use Parse::Pidl::Dump qw(DumpTypedef DumpFunction);
16 use Parse::Pidl::Ethereal::Conformance qw(ReadConformance);
18 use vars qw($VERSION);
24 my %dissector_used = ();
26 my $conformance = undef;
28 my %ptrtype_mappings = (
29 "unique" => "NDR_POINTER_UNIQUE",
30 "ref" => "NDR_POINTER_REF",
31 "ptr" => "NDR_POINTER_PTR"
38 return "FT_UINT$1" if $t =~ /uint(8|16|32|64)/;
39 return "FT_INT$1" if $t =~ /int(8|16|32|64)/;
40 return "FT_UINT64", if $t eq "HYPER_T" or $t eq "NTTIME_hyper"
43 # TODO: should NTTIME_hyper be a FT_ABSOLUTE_TIME as well?
45 return "FT_ABSOLUTE_TIME" if $t eq "NTTIME" or $t eq "NTTIME_1sec";
47 return "FT_STRING" if ($t eq "string");
56 foreach (@{$conformance->{strip_prefixes}}) {
63 # Convert a IDL structure field name (e.g access_mask) to a prettier
64 # string like 'Access Mask'.
70 $field =~ s/_/ /g; # Replace underscores with spaces
71 $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word
88 sub pidl_hdr($) { my $x = shift; $res{hdr} .= "$x\n"; }
89 sub pidl_def($) { my $x = shift; $res{def} .= "$x\n"; }
98 $tabs = substr($tabs, 0, -1);
105 foreach (split /\n/, $idl) {
106 pidl_code "/* IDL: $_ */";
112 #####################################################################
113 # parse the interface definitions
117 Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
118 Typedef($_,$interface->{NAME}) foreach (@{$interface->{TYPEDEFS}});
119 Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
124 my ($e,$name,$ifname) = @_;
125 my $valsstring = "$ifname\_$name\_vals";
126 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name);
128 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
130 foreach (@{$e->{ELEMENTS}}) {
131 if (/([^=]*)=(.*)/) {
132 pidl_hdr "#define $1 ($2)";
136 pidl_hdr "extern const value_string $valsstring\[];";
137 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
139 pidl_def "const value_string ".$valsstring."[] = {";
140 foreach (@{$e->{ELEMENTS}}) {
141 next unless (/([^=]*)=(.*)/);
142 pidl_def "\t{ $1, \"$1\" },";
145 pidl_def "{ 0, NULL }";
149 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)";
152 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, NULL);";
153 pidl_code "return offset;";
157 my $enum_size = $e->{BASE_TYPE};
158 $enum_size =~ s/uint//g;
159 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", type2ft($e->{BASE_TYPE}), "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8);
164 my ($e,$name,$ifname) = @_;
165 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name);
167 register_ett("ett_$ifname\_$name");
169 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);";
172 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
175 pidl_code "proto_item *item = NULL;";
176 pidl_code "proto_tree *tree = NULL;";
179 pidl_code "g$e->{BASE_TYPE} flags;";
180 if ($e->{ALIGN} > 1) {
181 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
186 pidl_code "if(parent_tree) {";
188 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);";
189 pidl_code "tree = proto_item_add_subtree(item,ett_$ifname\_$name);";
193 pidl_code "offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);";
195 pidl_code "proto_item_append_text(item, \": \");\n";
196 pidl_code "if (!flags)";
197 pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n";
199 foreach (@{$e->{ELEMENTS}}) {
200 next unless (/([^ ]*) (.*)/);
201 my ($en,$ev) = ($1,$2);
202 my $hf_bitname = "hf_$ifname\_$name\_$en";
203 my $filtername = "$ifname\.$name\.$en";
205 $hf_used{$hf_bitname} = 1;
207 register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
209 pidl_def "static const true_false_string $name\_$en\_tfs = {";
210 pidl_def " \"$en is SET\",";
211 pidl_def " \"$en is NOT SET\",";
214 pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);";
215 pidl_code "if (flags&$ev){";
216 pidl_code "\tproto_item_append_text(item, \"$en\");";
217 pidl_code "\tif (flags & (~$ev))";
218 pidl_code "\t\tproto_item_append_text(item, \", \");";
220 pidl_code "flags&=(~$ev);";
224 pidl_code "if(flags){";
225 pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);";
227 pidl_code "return offset;";
231 my $size = $e->{BASE_TYPE};
233 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", type2ft($e->{BASE_TYPE}), "BASE_DEC", "0", "NULL", $size/8);
236 sub ElementLevel($$$$$)
238 my ($e,$l,$hf,$myname,$pn) = @_;
242 if (defined($conformance->{dissectorparams}->{$myname})) {
243 $conformance->{dissectorparams}->{$myname}->{PARAM} = 1;
244 $param = $conformance->{dissectorparams}->{$myname}->{PARAM};
247 if ($l->{TYPE} eq "POINTER") {
249 if ($l->{LEVEL} eq "TOP") {
251 } elsif ($l->{LEVEL} eq "EMBEDDED") {
254 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);";
255 } elsif ($l->{TYPE} eq "ARRAY") {
257 if ($l->{IS_INLINE}) {
258 warn ("Inline arrays not supported");
259 pidl_code "/* FIXME: Handle inline array */";
260 } elsif ($l->{IS_FIXED}) {
262 pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)";
263 pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);";
266 ($af = "ucarray") if ($l->{IS_CONFORMANT});
267 ($af = "uvarray") if ($l->{IS_VARYING});
268 ($af = "ucvarray") if ($l->{IS_CONFORMANT} and $l->{IS_VARYING});
270 pidl_code "offset = dissect_ndr_$af(tvb, offset, pinfo, tree, drep, $myname\_);";
272 } elsif ($l->{TYPE} eq "DATA") {
273 if ($l->{DATA_TYPE} eq "string") {
274 my $bs = 2; # Byte size defaults to that of UCS2
277 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
279 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
280 pidl_code "char *data;\n";
281 pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);";
282 pidl_code "proto_item_append_text(tree, \": %s\", data);";
283 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
284 pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);";
286 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
291 if ($conformance->{imports}->{$l->{DATA_TYPE}}) {
292 $call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA};
293 $conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
294 } elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) {
295 $call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
296 $conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
298 if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/)
300 pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);";
306 $call =~ s/\@HF\@/$hf/g;
307 $call =~ s/\@PARAM\@/$param/g;
310 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
311 my $num_bits = ($l->{HEADER_SIZE}*8);
312 pidl_code "guint$num_bits size;";
313 pidl_code "int start_offset = offset;";
314 pidl_code "tvbuff_t *subtvb;";
315 pidl_code "offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);";
316 pidl_code "proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");";
318 pidl_code "subtvb = tvb_new_subset(tvb, offset, size, -1);";
319 pidl_code "$myname\_(subtvb, 0, pinfo, tree, drep);";
321 die("Unknown type `$_->{TYPE}'");
327 my ($e,$pn,$ifname) = @_;
329 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn)."\_".StripPrefixes($e->{NAME});
331 my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);";
333 my $hf = register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", type2ft($e->{TYPE}), "BASE_HEX", "NULL", 0, "");
336 my $eltname = StripPrefixes($pn) . ".$e->{NAME}";
337 if (defined($conformance->{noemit}->{$eltname})) {
343 foreach (@{$e->{LEVELS}}) {
344 next if ($_->{TYPE} eq "SWITCH");
345 pidl_def "static int $dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep);";
346 pidl_code "static int";
347 pidl_code "$dissectorname$add(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)";
351 ElementLevel($e,$_,$hf,$dissectorname.$add,$pn);
354 pidl_code "return offset;";
365 my ($fn,$ifname) = @_;
369 foreach (@{$fn->{ELEMENTS}}) {
370 $dissectornames{$_->{NAME}} = Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}});
373 my $fn_name = $_->{NAME};
374 $fn_name =~ s/^${ifname}_//;
376 PrintIdl DumpFunction($fn->{ORIGINAL});
377 pidl_code "static int";
378 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_)";
381 foreach (@{$fn->{ELEMENTS}}) {
382 if (grep(/out/,@{$_->{DIRECTION}})) {
383 pidl_code "$dissectornames{$_->{NAME}}";
384 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
389 if (not defined($fn->{RETURN_TYPE})) {
390 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
391 pidl_code "offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, NULL);";
392 $hf_used{"hf\_$ifname\_status"} = 1;
393 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
394 pidl_code "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, NULL);";
395 $hf_used{"hf\_$ifname\_werror"} = 1;
397 print "$fn->{FILE}:$fn->{LINE}: error: return type `$fn->{RETURN_TYPE}' not yet supported\n";
401 pidl_code "return offset;";
405 pidl_code "static int";
406 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_)";
409 foreach (@{$fn->{ELEMENTS}}) {
410 if (grep(/in/,@{$_->{DIRECTION}})) {
411 pidl_code "$dissectornames{$_->{NAME}}";
412 pidl_code "offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);";
417 pidl_code "return offset;";
424 my ($e,$name,$ifname) = @_;
425 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name);
427 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
429 register_ett("ett_$ifname\_$name");
432 ($res.="\t".Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}});
434 pidl_hdr "int $dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_);";
437 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
440 pidl_code "proto_item *item = NULL;";
441 pidl_code "proto_tree *tree = NULL;";
442 pidl_code "int old_offset;";
445 if ($e->{ALIGN} > 1) {
446 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
450 pidl_code "old_offset = offset;";
452 pidl_code "if(parent_tree){";
454 pidl_code "item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);";
455 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
461 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
462 pidl_code "return offset;";
466 register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
471 my ($e,$name,$ifname) = @_;
473 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name);
475 return if (defined($conformance->{noemit}->{StripPrefixes($name)}));
477 register_ett("ett_$ifname\_$name");
480 foreach (@{$e->{ELEMENTS}}) {
481 $res.="\n\t\t$_->{CASE}:\n";
482 if ($_->{TYPE} ne "EMPTY") {
483 $res.="\t\t\t".Element($_, $name, $ifname)."\n";
485 $res.="\t\tbreak;\n";
488 my $switch_type = $e->{SWITCH_TYPE};
490 pidl_code "static int";
491 pidl_code "$dissectorname(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)";
494 pidl_code "proto_item *item = NULL;";
495 pidl_code "proto_tree *tree = NULL;";
496 pidl_code "int old_offset;";
497 pidl_code "g$switch_type level;";
500 if ($e->{ALIGN} > 1) {
501 pidl_code "ALIGN_TO_$e->{ALIGN}_BYTES;";
506 pidl_code "old_offset = offset;";
507 pidl_code "if(parent_tree){";
509 pidl_code "item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");";
510 pidl_code "tree = proto_item_add_subtree(item, ett_$ifname\_$name);";
516 pidl_code "offset = dissect_ndr_$switch_type(tvb, offset, pinfo, tree, drep, hf_index, &level);";
518 pidl_code "switch(level) {$res\t}";
519 pidl_code "proto_item_set_len(item, offset-old_offset);\n";
520 pidl_code "return offset;";
524 register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
529 my ($const,$ifname) = @_;
531 if (!defined($const->{ARRAY_LEN}[0])) {
532 pidl_hdr "#define $const->{NAME}\t( $const->{VALUE} )\n";
534 pidl_hdr "#define $const->{NAME}\t $const->{VALUE}\n";
540 my ($e,$ifname) = @_;
542 PrintIdl DumpTypedef($e->{ORIGINAL});
549 }->{$e->{DATA}->{TYPE}}->($e->{DATA}, $e->{NAME}, $ifname);
552 sub RegisterInterface($)
556 pidl_code "void proto_register_dcerpc_$x->{NAME}(void)";
560 $res{code}.=DumpHfList()."\n";
561 $res{code}.="\n".DumpEttList()."\n";
563 if (defined($x->{UUID})) {
564 # These can be changed to non-pidl_code names if the old dissectors
565 # in epan/dissctors are deleted.
567 my $name = uc($x->{NAME}) . " (pidl)";
568 my $short_name = uc($x->{NAME});
569 my $filter_name = $x->{NAME};
571 if (has_property($x, "helpstring")) {
572 $name = $x->{PROPERTIES}->{helpstring};
575 if (defined($conformance->{protocols}->{$x->{NAME}})) {
576 $short_name = $conformance->{protocols}->{$x->{NAME}}->{SHORTNAME};
577 $name = $conformance->{protocols}->{$x->{NAME}}->{LONGNAME};
578 $filter_name = $conformance->{protocols}->{$x->{NAME}}->{FILTERNAME};
581 pidl_code "proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");";
583 pidl_code "proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));";
584 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
586 pidl_code "proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");";
587 pidl_code "proto_register_field_array(proto_dcerpc, hf, array_length(hf));";
588 pidl_code "proto_register_subtree_array(ett, array_length(ett));";
595 sub RegisterInterfaceHandoff($)
599 if (defined($x->{UUID})) {
600 pidl_code "void proto_reg_handoff_dcerpc_$x->{NAME}(void)";
603 pidl_code "dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},";
604 pidl_code "\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},";
605 pidl_code "\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);";
609 $hf_used{"hf_$x->{NAME}_opnum"} = 1;
613 sub ProcessInterface($)
617 push(@{$conformance->{strip_prefixes}}, $x->{NAME});
619 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
620 pidl_hdr "#ifndef $define";
621 pidl_hdr "#define $define";
624 if (defined $x->{PROPERTIES}->{depends}) {
625 foreach (split / /, $x->{PROPERTIES}->{depends}) {
626 next if($_ eq "security");
627 pidl_hdr "#include \"packet-dcerpc-$_\.h\"\n";
631 pidl_def "static gint proto_dcerpc_$x->{NAME} = -1;";
632 register_ett("ett_dcerpc_$x->{NAME}");
633 register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
635 if (defined($x->{UUID})) {
636 my $if_uuid = $x->{UUID};
638 pidl_def "/* Version information */\n\n";
640 pidl_def "static e_uuid_t uuid_dcerpc_$x->{NAME} = {";
641 pidl_def "\t0x" . substr($if_uuid, 1, 8)
642 . ", 0x" . substr($if_uuid, 10, 4)
643 . ", 0x" . substr($if_uuid, 15, 4) . ",";
644 pidl_def "\t{ 0x" . substr($if_uuid, 20, 2)
645 . ", 0x" . substr($if_uuid, 22, 2)
646 . ", 0x" . substr($if_uuid, 25, 2)
647 . ", 0x" . substr($if_uuid, 27, 2)
648 . ", 0x" . substr($if_uuid, 29, 2)
649 . ", 0x" . substr($if_uuid, 31, 2)
650 . ", 0x" . substr($if_uuid, 33, 2)
651 . ", 0x" . substr($if_uuid, 35, 2) . " }";
654 my $maj = $x->{VERSION};
655 $maj =~ s/\.(.*)$//g;
656 pidl_def "static guint16 ver_dcerpc_$x->{NAME} = $maj;";
662 pidl_code "\n".DumpFunctionTable($x);
664 # Only register these two return types if they were actually used
665 if (defined($hf_used{"hf_$x->{NAME}_status"})) {
666 register_hf_field("hf_$x->{NAME}_status", "Status", "$x->{NAME}.status", "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", 0, "");
669 if (defined($hf_used{"hf_$x->{NAME}_werror"})) {
670 register_hf_field("hf_$x->{NAME}_werror", "Windows Error", "$x->{NAME}.werror", "FT_UINT32", "BASE_HEX", "NULL", 0, "");
673 RegisterInterface($x);
674 RegisterInterfaceHandoff($x);
676 pidl_hdr "#endif /* $define */";
680 sub register_type($$$$$$$)
682 my ($type,$call,$ft,$base,$mask,$vals,$length) = @_;
684 $conformance->{types}->{$type} = {
686 DISSECTOR_NAME => $call,
695 # Loads the default types
698 my $cnf_file = shift;
705 ReadConformance($cnf_file, $conformance) or print "Warning: No conformance file `$cnf_file'\n";
707 foreach my $bytes (qw(1 2 4 8)) {
708 my $bits = $bytes * 8;
709 register_type("uint$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@,NULL);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
710 register_type("int$bits", "offset = dissect_ndr_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
713 register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
714 register_type("bool8", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
715 register_type("char", "offset = dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
716 register_type("long", "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
717 register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
718 register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
719 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);
720 register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
721 register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
722 register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4);
723 register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
724 register_type("SID", "
725 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
727 di->hf_index = \@HF\@;
729 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
730 ","FT_STRING", "BASE_DEC", 0, "NULL", 4);
731 register_type("WERROR",
732 "offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4);
736 #####################################################################
737 # Generate ethereal parser and header code
740 my($ndr,$idl_file,$h_filename,$cnf_file) = @_;
741 Initialize($cnf_file);
743 return (undef, undef) if defined($conformance->{noemit_dissector});
747 %res = (code=>"",def=>"",hdr=>"");
752 This filter was automatically generated
753 from $idl_file and $cnf_file.
755 Pidl is a perl based IDL compiler for DCE/RPC idl files.
756 It is maintained by the Samba team, not the Ethereal team.
757 Instructions on how to download and install Pidl can be
758 found at http://wiki.ethereal.com/Pidl
765 $res{headers} = "\n";
766 $res{headers} .= "#ifdef HAVE_CONFIG_H\n";
767 $res{headers} .= "#include \"config.h\"\n";
768 $res{headers} .= "#endif\n\n";
769 $res{headers} .= "#include <glib.h>\n";
770 $res{headers} .= "#include <string.h>\n";
771 $res{headers} .= "#include <epan/packet.h>\n\n";
773 $res{headers} .= "#include \"packet-dcerpc.h\"\n";
774 $res{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
775 $res{headers} .= "#include \"packet-windows-common.h\"\n";
778 my $h_basename = basename($h_filename);
780 $res{headers} .= "#include \"$h_basename\"\n";
783 # Ethereal protocol registration
785 ProcessInterface($_) foreach (@$ndr);
787 $res{ett} = DumpEttDeclaration();
788 $res{hf} = DumpHfDeclaration();
790 my $parser = $notice;
791 $parser.= $res{headers};
795 $parser.=$conformance->{override};
798 my $header = "/* autogenerated by pidl */\n\n";
801 CheckUsed($conformance);
803 return ($parser,$header);
806 ###############################################################################
808 ###############################################################################
819 my $res = "\tstatic gint *ett[] = {\n";
821 $res .= "\t\t&$_,\n";
827 sub DumpEttDeclaration()
829 my $res = "\n/* Ett declarations */\n";
831 $res .= "static gint $_ = -1;\n";
837 ###############################################################################
839 ###############################################################################
841 sub register_hf_field($$$$$$$$)
843 my ($index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
845 if (defined ($conformance->{hf_renames}->{$index})) {
846 $conformance->{hf_renames}->{$index}->{USED} = 1;
847 return $conformance->{hf_renames}->{$index}->{NEWNAME};
850 $conformance->{header_fields}->{$index} = {
853 FILTER => $filter_name,
855 BASE_TYPE => $base_type,
856 VALSSTRING => $valsstring,
861 if ((not defined($blurb) or $blurb eq "") and
862 defined($conformance->{fielddescription}->{$index})) {
863 $conformance->{header_fields}->{$index}->{BLURB} =
864 $conformance->{fielddescription}->{$index}->{DESCRIPTION};
865 $conformance->{fielddescription}->{$index}->{USED} = 1;
871 sub DumpHfDeclaration()
875 $res = "\n/* Header field declarations */\n";
877 foreach (keys %{$conformance->{header_fields}})
879 $res .= "static gint $_ = -1;\n";
887 my $res = "\tstatic hf_register_info hf[] = {\n";
889 foreach (values %{$conformance->{header_fields}})
891 $res .= "\t{ &$_->{INDEX},
892 { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str($_->{BLURB}).", HFILL }},
896 return $res."\t};\n";
900 ###############################################################################
902 ###############################################################################
904 sub DumpFunctionTable($)
908 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
909 foreach (@{$if->{FUNCTIONS}}) {
910 my $fn_name = $_->{NAME};
911 $fn_name =~ s/^$if->{NAME}_//;
912 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
913 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
916 $res .= "\t{ 0, NULL, NULL, NULL }\n";
923 my $conformance = shift;
924 foreach (values %{$conformance->{header_fields}}) {
925 if (not defined($hf_used{$_->{INDEX}})) {
926 print "$_->{POS}: warning: hf field `$_->{INDEX}' not used\n";
930 foreach (values %{$conformance->{hf_renames}}) {
931 if (not $_->{USED}) {
932 print "$_->{POS}: warning: hf field `$_->{OLDNAME}' not used\n";
936 foreach (values %{$conformance->{dissectorparams}}) {
937 if (not $_->{USED}) {
938 print "$_->{POS}: warning: dissector param never used\n";
942 foreach (values %{$conformance->{imports}}) {
943 if (not $_->{USED}) {
944 print "$_->{POS}: warning: import never used\n";
948 foreach (values %{$conformance->{types}}) {
949 if (not $_->{USED} and defined($_->{POS})) {
950 print "$_->{POS}: warning: type never used\n";
954 foreach (values %{$conformance->{fielddescription}}) {
955 if (not $_->{USED}) {
956 print "$_->{POS}: warning: description never used\n";