1 ##################################################
2 # Wireshark 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-2007
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;
21 @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);
24 use Parse::Pidl qw(error warning);
25 use Parse::Pidl::Typelist qw(getType);
26 use Parse::Pidl::Util qw(has_property property_matches make_str);
27 use Parse::Pidl::NDR qw(ContainsString GetNextLevel);
28 use Parse::Pidl::Dump qw(DumpType DumpFunction);
29 use Parse::Pidl::Wireshark::Conformance qw(ReadConformance);
32 use vars qw($VERSION);
35 my %return_types = ();
36 my %dissector_used = ();
38 my %ptrtype_mappings = (
39 "unique" => "NDR_POINTER_UNIQUE",
40 "ref" => "NDR_POINTER_REF",
41 "ptr" => "NDR_POINTER_PTR"
46 my ($s, $prefixes) = @_;
48 foreach (@$prefixes) {
55 # Convert a IDL structure field name (e.g access_mask) to a prettier
56 # string like 'Access Mask'.
62 $field =~ s/_/ /g; # Replace underscores with spaces
63 $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word
71 my $self = {res => {hdr => "", def => "", code => ""}, tabs => "", cur_fn => undef,
72 hf_used => {}, ett => [], conformance => undef
81 $self->{cur_fn} = $fn;
86 die("Inconsistent state: $fn != $self->{cur_fn}") if ($fn ne $self->{cur_fn});
87 $self->{cur_fn} = undef;
93 return if (defined($self->{cur_fn}) and defined($self->{conformance}->{manual}->{$self->{cur_fn}}));
96 $self->{res}->{code} .= $self->{tabs};
97 $self->{res}->{code} .= $d;
99 $self->{res}->{code} .="\n";
102 sub pidl_hdr($$) { my ($self,$x) = @_; $self->{res}->{hdr} .= "$x\n"; }
103 sub pidl_def($$) { my ($self,$x) = @_; $self->{res}->{def} .= "$x\n"; }
108 $self->{tabs} .= "\t";
114 $self->{tabs} = substr($self->{tabs}, 0, -1);
119 my ($self, $idl) = @_;
121 foreach (split /\n/, $idl) {
122 $self->pidl_code("/* IDL: $_ */");
125 $self->pidl_code("");
128 #####################################################################
129 # parse the interface definitions
132 my($self, $interface) = @_;
133 $self->Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
134 $self->Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}});
135 $self->Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
140 my ($self, $e,$name,$ifname) = @_;
141 my $valsstring = "$ifname\_$name\_vals";
142 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
144 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
146 foreach (@{$e->{ELEMENTS}}) {
147 if (/([^=]*)=(.*)/) {
148 $self->pidl_hdr("#define $1 ($2)");
152 $self->pidl_hdr("extern const value_string $valsstring\[];");
153 $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_, g$e->{BASE_TYPE} *param _U_);");
155 $self->pidl_def("const value_string ".$valsstring."[] = {");
156 foreach (@{$e->{ELEMENTS}}) {
157 next unless (/([^=]*)=(.*)/);
158 $self->pidl_def("\t{ $1, \"$1\" },");
161 $self->pidl_def("{ 0, NULL }");
162 $self->pidl_def("};");
164 $self->pidl_fn_start($dissectorname);
165 $self->pidl_code("int");
166 $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_, g$e->{BASE_TYPE} *param _U_)");
167 $self->pidl_code("{");
169 $self->pidl_code("g$e->{BASE_TYPE} parameter=0;");
170 $self->pidl_code("if (param) {");
172 $self->pidl_code("parameter = *param;");
174 $self->pidl_code("}");
175 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);");
176 $self->pidl_code("if (param) {");
178 $self->pidl_code("*param = parameter;");
180 $self->pidl_code("}");
181 $self->pidl_code("return offset;");
183 $self->pidl_code("}\n");
184 $self->pidl_fn_end($dissectorname);
186 my $enum_size = $e->{BASE_TYPE};
187 $enum_size =~ s/uint//g;
188 $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);
193 my ($self,$e,$name,$ifname) = @_;
194 error($e->{ORIGINAL}, "Pipe not yet supported");
200 my ($self,$e,$name,$ifname) = @_;
201 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
203 $self->register_ett("ett_$ifname\_$name");
205 $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_);");
207 $self->pidl_fn_start($dissectorname);
208 $self->pidl_code("int");
209 $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_)");
210 $self->pidl_code("{");
212 $self->pidl_code("proto_item *item = NULL;");
213 $self->pidl_code("proto_tree *tree = NULL;");
214 $self->pidl_code("");
216 $self->pidl_code("g$e->{BASE_TYPE} flags;");
217 if ($e->{ALIGN} > 1) {
218 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
221 $self->pidl_code("");
223 $self->pidl_code("if (parent_tree) {");
225 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, DREP_ENC_INTEGER(drep));");
226 $self->pidl_code("tree = proto_item_add_subtree(item,ett_$ifname\_$name);");
228 $self->pidl_code("}\n");
230 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, di, drep, -1, &flags);");
232 $self->pidl_code("proto_item_append_text(item, \": \");\n");
233 $self->pidl_code("if (!flags)");
234 $self->pidl_code("\tproto_item_append_text(item, \"(No values set)\");\n");
236 foreach (@{$e->{ELEMENTS}}) {
237 next unless (/([^ ]*) (.*)/);
238 my ($en,$ev) = ($1,$2);
239 my $hf_bitname = "hf_$ifname\_$name\_$en";
240 my $filtername = "$ifname\.$name\.$en";
242 $self->{hf_used}->{$hf_bitname} = 1;
244 $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
246 $self->pidl_def("static const true_false_string $name\_$en\_tfs = {");
247 if (defined($self->{conformance}->{tfs}->{$hf_bitname})) {
248 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{TRUE_STRING},");
249 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{FALSE_STRING},");
250 $self->{conformance}->{tfs}->{$hf_bitname}->{USED} = 1;
252 $self->pidl_def(" \"$en is SET\",");
253 $self->pidl_def(" \"$en is NOT SET\",");
255 $self->pidl_def("};");
257 $self->pidl_code("proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);");
258 $self->pidl_code("if (flags&$ev){");
259 $self->pidl_code("\tproto_item_append_text(item, \"$en\");");
260 $self->pidl_code("\tif (flags & (~$ev))");
261 $self->pidl_code("\t\tproto_item_append_text(item, \", \");");
262 $self->pidl_code("}");
263 $self->pidl_code("flags&=(~$ev);");
264 $self->pidl_code("");
267 $self->pidl_code("if (flags) {");
268 $self->pidl_code("\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);");
269 $self->pidl_code("}\n");
270 $self->pidl_code("return offset;");
272 $self->pidl_code("}\n");
273 $self->pidl_fn_end($dissectorname);
275 my $size = $e->{BASE_TYPE};
277 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
280 sub ElementLevel($$$$$$$$)
282 my ($self,$e,$l,$hf,$myname,$pn,$ifname,$param) = @_;
284 if (defined($self->{conformance}->{dissectorparams}->{$myname})) {
285 $param = $self->{conformance}->{dissectorparams}->{$myname}->{PARAM};
288 if ($l->{TYPE} eq "POINTER") {
290 if ($l->{LEVEL} eq "TOP") {
292 } elsif ($l->{LEVEL} eq "EMBEDDED") {
295 $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);");
296 } elsif ($l->{TYPE} eq "ARRAY") {
297 if ($l->{IS_INLINE}) {
298 error($e->{ORIGINAL}, "Inline arrays not supported");
299 } elsif ($l->{IS_FIXED}) {
300 $self->pidl_code("int i;");
301 $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)");
302 $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, drep);");
305 $type .= "c" if ($l->{IS_CONFORMANT});
306 $type .= "v" if ($l->{IS_VARYING});
308 unless ($l->{IS_ZERO_TERMINATED}) {
309 $self->pidl_code("offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);");
311 my $nl = GetNextLevel($e,$l);
312 $self->pidl_code("char *data;");
313 $self->pidl_code("");
314 $self->pidl_code("offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);");
315 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
318 } elsif ($l->{TYPE} eq "DATA") {
319 if ($l->{DATA_TYPE} eq "string") {
320 my $bs = 2; # Byte size defaults to that of UCS2
323 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
325 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
326 $self->pidl_code("char *data;\n");
327 $self->pidl_code("offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);");
328 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
329 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
330 $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);");
331 } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) {
333 $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);")
335 $self->pidl_code("offset = dissect_null_term_string(tvb, offset, pinfo, tree, drep, $hf , 0);")
338 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
340 } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") {
342 $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*"));
343 $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, drep, $hf, $remain);");
347 if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) {
348 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA};
349 $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
351 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) {
352 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA};
353 $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
355 } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) {
356 $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
357 $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
360 if (ref($l->{DATA_TYPE}) eq "HASH" ) {
361 $t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}";
363 $t = $l->{DATA_TYPE};
366 $self->pidl_code("offset = $ifname\_dissect_struct_" . $t . "(tvb,offset,pinfo,tree,drep,$hf,$param);");
371 $call =~ s/\@HF\@/$hf/g;
372 $call =~ s/\@PARAM\@/$param/g;
373 $self->pidl_code($call);
375 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
377 if (has_property($e, "switch_is")) {
378 $varswitch = $e->{PROPERTIES}->{switch_is};
380 my $num_bits = ($l->{HEADER_SIZE}*8);
381 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, "");
382 $num_bits = 3264 if ($num_bits == 32);
383 $self->{hf_used}->{$hf2} = 1;
384 $self->pidl_code("dcerpc_info *di = (dcerpc_info*)pinfo->private_data;");
385 $self->pidl_code("guint$num_bits size;");
386 $self->pidl_code("int conformant = di->conformant_run;");
387 $self->pidl_code("tvbuff_t *subtvb;");
388 $self->pidl_code("");
389 # We need to be able to dissect the length of the context in every case
390 # and conformant run skips the dissections of scalars ...
391 $self->pidl_code("if (!conformant) {");
393 $self->pidl_code("guint32 saved_flags = di->call_data->flags;");
394 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf2, &size);");
395 # This is a subcontext, there is normally no such thing as
396 # 64 bit NDR is subcontext so we clear the flag so that we can
397 # continue to dissect handmarshalled stuff with pidl
398 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;");
400 $self->pidl_code("subtvb = tvb_new_subset(tvb, offset, size, -1);");
402 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep, $param);");
404 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);");
406 $self->pidl_code("offset += size;");
407 $self->pidl_code("di->call_data->flags = saved_flags;");
409 $self->pidl_code("}");
410 } elsif ($_->{TYPE} eq "PIPE") {
411 error($e->{ORIGINAL}, "Type PIPE not yet supported");
413 die("Unknown type `$_->{TYPE}'");
419 my ($e, $type, $nodiscriminant) = @_;
421 my $switch_dt = getType($type);
422 my $switch_type = undef;
423 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
424 $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
425 } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") {
426 $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA});
427 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
428 if (defined $e->{SWITCH_TYPE}) {
429 $switch_type = "$e->{SWITCH_TYPE}";
431 $switch_type = "$switch_dt->{DATA}->{NAME}";
433 } elsif (not defined $e->{SWITCH_TYPE}) {
434 $switch_type = $nodiscriminant;
442 my ($self,$e,$pn,$ifname,$isoruseswitch) = @_;
444 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes});
446 my ($call_code, $moreparam);
448 if (defined $isoruseswitch) {
449 my $type = $isoruseswitch->[0];
450 my $name = $isoruseswitch->[1];
452 my $switch_raw_type = SwitchType($e, $type, "uint32");
453 if (not defined($switch_raw_type)) {
454 die("Unknown type[$type]\n");
456 my $switch_type = "g${switch_raw_type}";
458 $moreparam = ", $switch_type *".$name;
460 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep, &$name);";
463 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);";
467 my $type = $self->find_type($e->{TYPE});
469 if (not defined($type)) {
473 VALSSTRING => "NULL",
474 FT_TYPE => "FT_NONE",
475 BASE_TYPE => "BASE_NONE"
479 if (ContainsString($e)) {
482 VALSSTRING => "NULL",
483 FT_TYPE => "FT_STRING",
484 BASE_TYPE => "BASE_NONE"
487 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) {
488 my $align_flag = $e->{PROPERTIES}->{flag};
489 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) {
490 $call_code = "ALIGN_TO_$1_BYTES; ".$call_code;
494 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}, "");
495 $self->{hf_used}->{$hf} = 1;
497 my $eltname = StripPrefixes($pn, $self->{conformance}->{strip_prefixes}) . ".$e->{NAME}";
498 if (defined($self->{conformance}->{noemit}->{$eltname})) {
504 my $oldparam = undef;
505 foreach (@{$e->{LEVELS}}) {
506 if (defined $_->{SWITCH_IS}) {
510 next if ($_->{TYPE} eq "SWITCH");
511 next if (defined($self->{conformance}->{noemit}->{"$dissectorname$add"}));
512 $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_$moreparam);");
513 $self->pidl_fn_start("$dissectorname$add");
514 $self->pidl_code("static int");
515 $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_$moreparam)");
516 $self->pidl_code("{");
519 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param);
520 if (defined $oldparam) {
524 $self->pidl_code("");
525 $self->pidl_code("return offset;");
527 $self->pidl_code("}\n");
528 $self->pidl_fn_end("$dissectorname$add");
530 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
538 my ($self, $fn,$ifname) = @_;
542 foreach (@{$fn->{ELEMENTS}}) {
543 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, undef) if not defined($dissectornames{$_->{NAME}});
546 my $fn_name = $_->{NAME};
547 $fn_name =~ s/^${ifname}_//;
549 $self->PrintIdl(DumpFunction($fn->{ORIGINAL}));
550 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response");
551 $self->pidl_code("static int");
552 $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_)");
553 $self->pidl_code("{");
555 if ( not defined($fn->{RETURN_TYPE})) {
556 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR")
558 $self->pidl_code("guint32 status;\n");
559 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
560 if ($type->{DATA}->{TYPE} eq "ENUM") {
561 $self->pidl_code("g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n");
562 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
563 $self->pidl_code("g$fn->{RETURN_TYPE} status;\n");
565 error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported");
568 error($fn, "unknown return type `$fn->{RETURN_TYPE}'");
571 $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";");
572 foreach (@{$fn->{ELEMENTS}}) {
573 if (grep(/out/,@{$_->{DIRECTION}})) {
574 $self->pidl_code("$dissectornames{$_->{NAME}}");
575 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);");
576 $self->pidl_code("");
580 if (not defined($fn->{RETURN_TYPE})) {
581 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
582 $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n");
583 $self->pidl_code("if (status != 0)");
584 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n");
585 $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"];
586 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
587 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n");
588 $self->pidl_code("if (status != 0)");
589 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n");
591 $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"];
592 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
593 if ($type->{DATA}->{TYPE} eq "ENUM") {
594 my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
595 my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
597 $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
598 $self->pidl_code("if (status != 0)");
599 $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");
600 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
601 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
602 $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
603 $self->pidl_code("if (status != 0)");
604 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n");
605 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
609 $self->pidl_code("return offset;");
611 $self->pidl_code("}\n");
612 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_response");
614 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request");
615 $self->pidl_code("static int");
616 $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_)");
617 $self->pidl_code("{");
619 $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";");
620 foreach (@{$fn->{ELEMENTS}}) {
621 if (grep(/in/,@{$_->{DIRECTION}})) {
622 $self->pidl_code("$dissectornames{$_->{NAME}}");
623 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);");
628 $self->pidl_code("return offset;");
630 $self->pidl_code("}\n");
631 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_request");
636 my ($self,$e,$name,$ifname) = @_;
637 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
639 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
641 $self->register_ett("ett_$ifname\_$name");
645 # will contain the switch var declaration;
647 foreach (@{$e->{ELEMENTS}}) {
648 if (has_property($_, "switch_is")) {
649 $varswitchs->{$_->{PROPERTIES}->{switch_is}} = [];
652 foreach (@{$e->{ELEMENTS}}) {
653 my $switch_info = undef;
656 if (scalar(grep {/^$v$/} keys(%$varswitchs)) == 1) {
657 # This element is one of the switch attribute
658 my $switch_raw_type = SwitchType($e, $_->{TYPE}, "uint32");
659 if (not defined($switch_raw_type)) {
660 die("Unknown type[$_->{TYPE}]\n");
662 my $switch_type = "g${switch_raw_type}";
664 push @$vars, "$switch_type $v = 0;";
665 $switch_info = [ $_->{TYPE}, $v ];
666 $varswitchs->{$v} = $switch_info;
669 if (has_property($_, "switch_is")) {
670 my $varswitch = $_->{PROPERTIES}->{switch_is};
671 $switch_info = $varswitchs->{$varswitch};
674 $res.="\t".$self->Element($_, $name, $ifname, $switch_info)."\n\n";
678 if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
680 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
684 $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_);");
686 $self->pidl_fn_start($dissectorname);
687 $self->pidl_code("int");
688 $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_)");
689 $self->pidl_code("{");
691 $self->pidl_code($_) foreach (@$vars);
692 $self->pidl_code("proto_item *item = NULL;");
694 $self->pidl_code("proto_tree *tree = NULL;");
696 if (defined($doalign)) {
697 $self->pidl_code("dcerpc_info *di = (dcerpc_info *)pinfo->private_data;");
699 $self->pidl_code("gboolean oldalign = di->no_align;");
702 $self->pidl_code("int old_offset;");
703 $self->pidl_code("");
705 if (defined($doalign)) {
707 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
710 $self->pidl_code("di->no_align = TRUE;");
712 $self->pidl_code("");
715 $self->pidl_code("old_offset = offset;");
716 $self->pidl_code("");
717 $self->pidl_code("if (parent_tree) {");
719 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);");
721 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
724 $self->pidl_code("}");
726 $self->pidl_code("\n$res");
728 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
729 if (defined($doalign) and $doalign == 1) {
730 $self->pidl_code("");
731 $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
733 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
735 $self->pidl_code("}");
737 if (defined($doalign) and $doalign == 0) {
738 $self->pidl_code("");
739 $self->pidl_code("di->no_align = oldalign;");
741 $self->pidl_code("");
742 $self->pidl_code("return offset;");
744 $self->pidl_code("}\n");
745 $self->pidl_fn_end($dissectorname);
747 $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
752 my ($self,$e,$name,$ifname) = @_;
754 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
756 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
758 $self->register_ett("ett_$ifname\_$name");
761 foreach (@{$e->{ELEMENTS}}) {
762 $res.="\n\t\t$_->{CASE}:\n";
763 if ($_->{TYPE} ne "EMPTY") {
764 $res.="\t\t\t".$self->Element($_, $name, $ifname, undef)."\n";
766 $res.="\t\tbreak;\n";
769 my $switch_type = undef;
770 my $switch_dissect = undef;
771 my $switch_raw_type = SwitchType($e, $e->{SWITCH_TYPE});
772 if (defined($switch_raw_type)) {
773 $switch_type = "g${switch_raw_type}";
774 $switch_dissect = "dissect_ndr_${switch_raw_type}";
777 $self->pidl_fn_start($dissectorname);
778 $self->pidl_code("static int");
779 $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_)");
780 $self->pidl_code("{");
782 $self->pidl_code("proto_item *item = NULL;");
783 $self->pidl_code("proto_tree *tree = NULL;");
784 $self->pidl_code("int old_offset;");
785 if (!defined $switch_type) {
786 $self->pidl_code("guint32 level = param;");
788 $self->pidl_code("$switch_type level;");
790 $self->pidl_code("");
792 $self->pidl_code("old_offset = offset;");
793 $self->pidl_code("if (parent_tree) {");
795 $self->pidl_code("item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");");
796 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
798 $self->pidl_code("}");
800 $self->pidl_code("");
802 if (defined $switch_type) {
803 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);");
805 if ($e->{ALIGN} > 1) {
806 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
807 $self->pidl_code("");
812 $self->pidl_code("switch(level) {$res\t}");
813 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
814 $self->pidl_code("");
816 $self->pidl_code("return offset;");
818 $self->pidl_code("}");
819 $self->pidl_fn_end($dissectorname);
821 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
826 my ($self,$const,$ifname) = @_;
828 if (!defined($const->{ARRAY_LEN}[0])) {
829 $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n");
831 $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n");
837 my ($self,$e,$name,$ifname) = @_;
839 $self->Type($e->{DATA}, $name, $ifname);
844 my ($self, $e, $name, $ifname) = @_;
846 $self->PrintIdl(DumpType($e->{ORIGINAL}));
852 TYPEDEF => \&Typedef,
854 }->{$e->{TYPE}}->($self, $e, $name, $ifname);
857 sub RegisterInterface($$)
861 $self->pidl_fn_start("proto_register_dcerpc_$x->{NAME}");
862 $self->pidl_code("void proto_register_dcerpc_$x->{NAME}(void)");
863 $self->pidl_code("{");
866 $self->{res}->{headers} .= "void proto_register_dcerpc_$x->{NAME}(void);\n";
868 $self->{res}->{code}.=$self->DumpHfList()."\n";
869 $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n";
871 if (defined($x->{UUID})) {
872 # These can be changed to non-pidl_code names if the old
873 # dissectors in epan/dissectors are deleted.
875 my $name = uc($x->{NAME}) . " (pidl)";
876 my $short_name = uc($x->{NAME});
877 my $filter_name = $x->{NAME};
879 if (has_property($x, "helpstring")) {
880 $name = $x->{PROPERTIES}->{helpstring};
883 if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) {
884 $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME};
885 $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME};
886 $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME};
889 $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");");
891 $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));");
892 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
894 $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");");
895 $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));");
896 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
900 $self->pidl_code("}\n");
901 $self->pidl_fn_end("proto_register_dcerpc_$x->{NAME}");
904 sub RegisterInterfaceHandoff($$)
908 if (defined($x->{UUID})) {
909 $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}");
910 $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)");
911 $self->pidl_code("{");
913 $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},");
914 $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},");
915 $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);");
917 $self->pidl_code("}");
918 $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}");
920 $self->{res}->{headers} .= "void proto_reg_handoff_dcerpc_$x->{NAME}(void);\n";
922 $self->{hf_used}->{"hf_$x->{NAME}_opnum"} = 1;
930 foreach (@includes) {
931 $self->pidl_hdr("#include \"$_\"");
941 next if($_ eq "security");
944 $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\"");
949 sub ProcessInterface($$)
953 push(@{$self->{conformance}->{strip_prefixes}}, $x->{NAME});
955 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
956 $self->pidl_hdr("#ifndef $define");
957 $self->pidl_hdr("#define $define");
960 $self->pidl_def("static gint proto_dcerpc_$x->{NAME} = -1;");
961 $self->register_ett("ett_dcerpc_$x->{NAME}");
962 $self->register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
964 if (defined($x->{UUID})) {
965 my $if_uuid = $x->{UUID};
967 $self->pidl_def("/* Version information */\n\n");
969 $self->pidl_def("static e_uuid_t uuid_dcerpc_$x->{NAME} = {");
970 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8)
971 . ", 0x" . substr($if_uuid, 10, 4)
972 . ", 0x" . substr($if_uuid, 15, 4) . ",");
973 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2)
974 . ", 0x" . substr($if_uuid, 22, 2)
975 . ", 0x" . substr($if_uuid, 25, 2)
976 . ", 0x" . substr($if_uuid, 27, 2)
977 . ", 0x" . substr($if_uuid, 29, 2)
978 . ", 0x" . substr($if_uuid, 31, 2)
979 . ", 0x" . substr($if_uuid, 33, 2)
980 . ", 0x" . substr($if_uuid, 35, 2) . " }");
981 $self->pidl_def("};");
983 my $maj = 0x0000FFFF & $x->{VERSION};
984 $maj =~ s/\.(.*)$//g;
985 $self->pidl_def("static guint16 ver_dcerpc_$x->{NAME} = $maj;");
989 $return_types{$x->{NAME}} = {};
991 $self->Interface($x);
992 $self->pidl_code("\n".DumpFunctionTable($x));
994 foreach (sort(keys %{$return_types{$x->{NAME}}})) {
995 my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}};
996 my $dt = $self->find_type($type);
997 $dt or die("Unable to find information about return type `$type'");
998 $self->register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, "");
999 $self->{hf_used}->{"hf_$x->{NAME}_$_"} = 1;
1002 $self->RegisterInterface($x);
1003 $self->RegisterInterfaceHandoff($x);
1005 $self->pidl_hdr("#endif /* $define */");
1010 my ($self, $n) = @_;
1012 return $self->{conformance}->{types}->{$n};
1015 sub register_type($$$$$$$$)
1017 my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_;
1019 return if (defined($self->{conformance}->{types}->{$type}));
1021 $self->{conformance}->{types}->{$type} = {
1023 DISSECTOR_NAME => $call,
1027 VALSSTRING => $vals,
1028 ALIGNMENT => $length
1032 # Loads the default types
1035 my ($self, $cnf_file) = @_;
1037 $self->{conformance} = {
1042 ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n";
1044 foreach my $bytes (qw(1 2 4 8)) {
1045 my $bits = $bytes * 8;
1046 $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);
1047 $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);
1050 $self->register_type("uint3264", "offset = dissect_ndr_uint3264(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8);
1051 $self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8);
1052 $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
1053 $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1054 $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1055 $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
1056 $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
1057 $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
1058 $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4);
1059 $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1060 $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1061 $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1062 $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1063 $self->register_type("dom_sid28", "{
1064 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
1065 di->hf_index = \@HF\@;
1067 offset = dissect_ndr_nt_SID28(tvb, offset, pinfo, tree, drep);
1068 }", "FT_STRING", "BASE_NONE", 0, "NULL", 4);
1069 $self->register_type("SID", "{
1070 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
1072 di->hf_index = \@HF\@;
1074 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
1075 }", "FT_STRING", "BASE_NONE", 0, "NULL", 4);
1076 $self->register_type("WERROR",
1077 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4);
1078 $self->register_type("NTSTATUS",
1079 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4);
1080 $self->register_type("ipv6address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 16, ENC_NA); offset += 16;", "FT_IPv6", "BASE_NONE", 0, "NULL", 16);
1081 $self->register_type("ipv4address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;", "FT_IPv4", "BASE_NONE", 0, "NULL", 4);
1085 #####################################################################
1086 # Generate Wireshark parser and header code
1089 my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_;
1091 $self->Initialize($cnf_file);
1093 return (undef, undef) if defined($self->{conformance}->{noemit_dissector});
1097 This filter was automatically generated
1098 from $idl_file and $cnf_file.
1100 Pidl is a perl based IDL compiler for DCE/RPC idl files.
1101 It is maintained by the Samba team, not the Wireshark team.
1102 Instructions on how to download and install Pidl can be
1103 found at http://wiki.wireshark.org/Pidl
1108 $self->pidl_hdr($notice);
1110 $self->{res}->{headers} = "\n";
1111 $self->{res}->{headers} .= "#include \"config.h\"\n";
1113 $self->{res}->{headers} .= "#include <glib.h>\n";
1114 $self->{res}->{headers} .= "#include <string.h>\n";
1115 $self->{res}->{headers} .= "#include <epan/packet.h>\n\n";
1117 $self->{res}->{headers} .= "#include \"packet-dcerpc.h\"\n";
1118 $self->{res}->{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
1119 $self->{res}->{headers} .= "#include \"packet-windows-common.h\"\n";
1121 my $h_basename = basename($h_filename);
1123 $self->{res}->{headers} .= "#include \"$h_basename\"\n";
1125 $self->pidl_code("");
1127 if (defined($self->{conformance}->{ett})) {
1128 register_ett($self,$_) foreach(@{$self->{conformance}->{ett}})
1130 # Wireshark protocol registration
1133 $self->ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE");
1134 $self->ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT");
1135 $self->ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE");
1138 $self->{res}->{ett} = DumpEttDeclaration($self->{ett});
1139 $self->{res}->{hf} = $self->DumpHfDeclaration();
1141 my $parser = $notice;
1142 $parser.= $self->{res}->{headers};
1143 $parser.=$self->{res}->{ett};
1144 $parser.=$self->{res}->{hf};
1145 $parser.=$self->{res}->{def};
1146 if (exists ($self->{conformance}->{override})) {
1147 $parser.=$self->{conformance}->{override};
1149 $parser.=$self->{res}->{code};
1151 my $header = "/* autogenerated by pidl */\n\n";
1152 $header.=$self->{res}->{hdr};
1154 $self->CheckUsed($self->{conformance});
1156 return ($parser,$header);
1159 ###############################################################################
1161 ###############################################################################
1163 sub register_ett($$)
1165 my ($self, $name) = @_;
1167 push (@{$self->{ett}}, $name);
1173 my $res = "\tstatic gint *ett[] = {\n";
1175 $res .= "\t\t&$_,\n";
1178 return "$res\t};\n";
1181 sub DumpEttDeclaration
1184 my $res = "\n/* Ett declarations */\n";
1186 $res .= "static gint $_ = -1;\n";
1192 ###############################################################################
1194 ###############################################################################
1196 sub register_hf_field($$$$$$$$$)
1198 my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
1200 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1201 $self->{conformance}->{hf_renames}->{$index}->{USED} = 1;
1202 return $self->{conformance}->{hf_renames}->{$index}->{NEWNAME};
1205 $self->{conformance}->{header_fields}->{$index} = {
1208 FILTER => $filter_name,
1209 FT_TYPE => $ft_type,
1210 BASE_TYPE => $base_type,
1211 VALSSTRING => $valsstring,
1216 if ((not defined($blurb) or $blurb eq "") and
1217 defined($self->{conformance}->{fielddescription}->{$index})) {
1218 $self->{conformance}->{header_fields}->{$index}->{BLURB} =
1219 $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION};
1220 $self->{conformance}->{fielddescription}->{$index}->{USED} = 1;
1226 sub change_hf_field_type($$$$)
1228 my ($self,$index,$ft_type,$base_type) = @_;
1229 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1230 print "Field $index has been renamed to ".$self->{conformance}->{hf_renames}->{$index}->{NEWNAME}." you can't change it's type";
1234 if (!defined ($self->{conformance}->{header_fields}->{$index})) {
1235 print "Field $index doesn't exists";
1238 $self->{conformance}->{header_fields}->{$index}->{FT_TYPE} = $ft_type;
1239 $self->{conformance}->{header_fields}->{$index}->{BASE_TYPE} = $base_type;
1243 sub DumpHfDeclaration($)
1248 $res = "\n/* Header field declarations */\n";
1250 foreach (sort(keys %{$self->{conformance}->{header_fields}}))
1252 $res .= "static gint $_ = -1;\n";
1258 sub make_str_or_null($)
1261 if (substr($str, 0, 1) eq "\"") {
1262 $str = substr($str, 1, length($str)-2);
1269 return make_str($str);
1275 my $res = "\tstatic hf_register_info hf[] = {\n";
1277 foreach (sort {$a->{INDEX} cmp $b->{INDEX}} values %{$self->{conformance}->{header_fields}})
1279 $res .= "\t{ &$_->{INDEX},
1280 { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }},
1284 return $res."\t};\n";
1288 ###############################################################################
1290 ###############################################################################
1292 sub DumpFunctionTable($)
1296 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
1297 foreach (@{$if->{FUNCTIONS}}) {
1298 my $fn_name = $_->{NAME};
1299 $fn_name =~ s/^$if->{NAME}_//;
1300 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
1301 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
1304 $res .= "\t{ 0, NULL, NULL, NULL }\n";
1311 my ($self, $conformance) = @_;
1312 foreach (values %{$conformance->{header_fields}}) {
1313 if (not defined($self->{hf_used}->{$_->{INDEX}})) {
1314 warning($_->{POS}, "hf field `$_->{INDEX}' not used");
1318 foreach (values %{$conformance->{hf_renames}}) {
1319 if (not $_->{USED}) {
1320 warning($_->{POS}, "hf field `$_->{OLDNAME}' not used");
1324 foreach (values %{$conformance->{dissectorparams}}) {
1325 if (not $_->{USED}) {
1326 warning($_->{POS}, "dissector param never used");
1330 foreach (values %{$conformance->{imports}}) {
1331 if (not $_->{USED}) {
1332 warning($_->{POS}, "import never used");
1336 foreach (values %{$conformance->{types}}) {
1337 if (not $_->{USED} and defined($_->{POS})) {
1338 warning($_->{POS}, "type never used");
1342 foreach (values %{$conformance->{fielddescription}}) {
1343 if (not $_->{USED}) {
1344 warning($_->{POS}, "description never used");
1348 foreach (values %{$conformance->{tfs}}) {
1349 if (not $_->{USED}) {
1350 warning($_->{POS}, "True/False description never used");