Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / tools / pidl / lib / Parse / Pidl / Wireshark / NDR.pm
blobcfdf827b547135ad835141d81b8c6ac31846833e
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
9 =pod
11 =head1 NAME
13 Parse::Pidl::Wireshark::NDR - Parser generator for Wireshark
15 =cut
17 package Parse::Pidl::Wireshark::NDR;
19 use Exporter;
20 @ISA = qw(Exporter);
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);
23 use strict;
24 use warnings;
25 use Parse::Pidl qw(error warning);
26 use Parse::Pidl::Typelist qw(getType mapScalarType);
27 use Parse::Pidl::Util qw(has_property property_matches make_str);
28 use Parse::Pidl::NDR qw(ContainsString GetNextLevel GetPrevLevel);
29 use Parse::Pidl::Dump qw(DumpType DumpFunction);
30 use Parse::Pidl::Wireshark::Conformance qw(ReadConformance);
31 use File::Basename;
33 use vars qw($VERSION);
34 $VERSION = '0.01';
36 my %return_types = ();
37 my %dissector_used = ();
39 my %ptrtype_mappings = (
40 "unique" => "NDR_POINTER_UNIQUE",
41 "ref" => "NDR_POINTER_REF",
42 "ptr" => "NDR_POINTER_PTR",
43 "full" => "NDR_POINTER_PTR"
46 my %variable_scalars = (
47 "int1632" => "int32_t",
48 "uint1632" => "uint32_t",
49 "int3264" => "int64_t",
50 "uint3264" => "uint64_t",
53 # map from an IDL type to a C header type, using the on-the-wire length.
54 # Produces different results than mapScalarType in Parse::Pidl::Typelist
55 # for the types that have different wire lengths in NDR and NDR64 (i.e.,
56 # includes the padding for uint1632 and uint3264, unlike that function.)
57 sub mapWireScalarType($)
59 my ($name) = shift;
61 return $variable_scalars{$name} if defined($variable_scalars{$name});
63 return mapScalarType($name);
66 sub StripPrefixes($$)
68 my ($s, $prefixes) = @_;
70 foreach (@$prefixes) {
71 $s =~ s/^$_\_//g;
74 return $s;
77 sub ContainsWithinEmbeddedPointer($$)
79 my ($e,$l) = @_;
81 my $ret = 0;
83 while ($l = GetPrevLevel($e,$l))
85 $ret += 1;
86 next if ($l->{TYPE} eq "SWITCH");
87 return 0 if ($l->{TYPE} ne "POINTER");
88 return $ret if ($l->{LEVEL} eq "EMBEDDED");
91 return 0;
94 # Convert a IDL structure field name (e.g access_mask) to a prettier
95 # string like 'Access Mask'.
97 sub field2name($)
99 my($field) = shift;
101 $field =~ s/^(_)*//g; # Remove any starting underscores
102 $field =~ s/_/ /g; # Replace underscores with spaces
103 $field =~ s/(\w+)/\u$1/g; # Capitalise each word
105 return $field;
108 sub new($)
110 my ($class) = @_;
111 my $self = {res => {hdr => "", def => "", code => ""}, tabs => "", cur_fn => undef,
112 hf_used => {}, ett => [], conformance => undef
115 bless($self, $class);
118 sub pidl_fn_start($$)
120 my ($self, $fn) = @_;
121 $self->{cur_fn} = $fn;
123 sub pidl_fn_end($$)
125 my ($self, $fn) = @_;
126 die("Inconsistent state: $fn != $self->{cur_fn}") if ($fn ne $self->{cur_fn});
127 $self->{cur_fn} = undef;
130 sub pidl_code($$)
132 my ($self, $d) = @_;
133 return if (defined($self->{cur_fn}) and defined($self->{conformance}->{manual}->{$self->{cur_fn}}));
135 if ($d) {
136 $self->{res}->{code} .= $self->{tabs};
137 $self->{res}->{code} .= $d;
139 $self->{res}->{code} .="\n";
142 sub pidl_hdr($$) { my ($self,$x) = @_; $self->{res}->{hdr} .= "$x\n"; }
143 sub pidl_def($$) { my ($self,$x) = @_; $self->{res}->{def} .= "$x\n"; }
145 sub indent($)
147 my ($self) = @_;
148 $self->{tabs} .= "\t";
151 sub deindent($)
153 my ($self) = @_;
154 $self->{tabs} = substr($self->{tabs}, 0, -1);
157 sub PrintIdl($$)
159 my ($self, $idl) = @_;
161 foreach (split /\n/, $idl) {
162 $self->pidl_code("/* IDL: $_ */");
165 $self->pidl_code("");
168 #####################################################################
169 # parse the interface definitions
170 sub Interface($$)
172 my($self, $interface) = @_;
173 $self->Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
174 $self->Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}});
175 $self->Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
178 sub Enum($$$$)
180 my ($self, $e,$name,$ifname) = @_;
181 my $valsstring = "$ifname\_$name\_vals";
182 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
184 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
186 foreach (@{$e->{ELEMENTS}}) {
187 if (/([^=]*)=(.*)/) {
188 $self->pidl_hdr("#define $1 ($2)");
192 $self->pidl_hdr("extern const value_string $valsstring\[];");
193 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, " . mapWireScalarType($e->{BASE_TYPE}) ." *param _U_);");
195 $self->pidl_def("const value_string ".$valsstring."[] = {");
196 foreach (@{$e->{ELEMENTS}}) {
197 next unless (/([^=]*)=(.*)/);
198 $self->pidl_def("\t{ $1, \"$1\" },");
201 $self->pidl_def("{ 0, NULL }");
202 $self->pidl_def("};");
204 $self->pidl_fn_start($dissectorname);
205 $self->pidl_code("int");
206 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, " . mapWireScalarType($e->{BASE_TYPE}) . " *param _U_)");
207 $self->pidl_code("{");
208 $self->indent;
209 $self->pidl_code(mapWireScalarType($e->{BASE_TYPE}) . " parameter=0;");
210 $self->pidl_code("if (param) {");
211 $self->indent;
212 $self->pidl_code("parameter = *param;");
213 $self->deindent;
214 $self->pidl_code("}");
215 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, di, drep, hf_index, &parameter);");
216 $self->pidl_code("if (param) {");
217 $self->indent;
218 $self->pidl_code("*param = parameter;");
219 $self->deindent;
220 $self->pidl_code("}");
221 $self->pidl_code("return offset;");
222 $self->deindent;
223 $self->pidl_code("}\n");
224 $self->pidl_fn_end($dissectorname);
226 my $enum_size = $e->{BASE_TYPE};
227 $enum_size =~ s/uint//g;
228 my $ws_base = "BASE_DEC";
229 $ws_base = "BASE_HEX" if (property_matches($e, "flag", ".*LIBNDR_PRINT_ARRAY_HEX.*"));
230 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", $ws_base, "0", "VALS($valsstring)", $enum_size / 8);
233 sub Pipe($$$$)
235 my ($self,$e,$name,$ifname) = @_;
236 error($e->{ORIGINAL}, "Pipe not yet supported");
237 return;
240 sub Bitmap($$$$)
242 my ($self,$e,$name,$ifname) = @_;
243 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
244 my $element_count = 0;
245 my $total_ev = 0;
247 $self->register_ett("ett_$ifname\_$name");
249 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, uint32_t param _U_);");
251 $self->pidl_fn_start($dissectorname);
252 $self->pidl_code("int");
253 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, uint32_t param _U_)");
254 $self->pidl_code("{");
255 $self->indent;
256 foreach (@{$e->{ELEMENTS}}) {
257 next unless (/([^ ]*) (.*)/);
258 $element_count++;
260 if ($element_count > 0) {
261 $self->pidl_code("proto_item *item;");
262 $self->pidl_code("static int * const $ifname\_$name\_fields[] = {");
263 $self->indent;
264 foreach (@{$e->{ELEMENTS}}) {
265 next unless (/([^ ]*) (.*)/);
266 my ($en,$ev) = ($1,$2);
267 my $hf_bitname = "hf_$ifname\_$name\_$1";
269 $ev =~ s/[()\s]//g;
270 if (hex($ev) != 0) {
271 $total_ev += hex($ev);
272 $self->pidl_code("&$hf_bitname,");
275 $self->pidl_code("NULL");
276 $self->deindent;
277 $self->pidl_code("};");
280 $self->pidl_code(mapWireScalarType($e->{BASE_TYPE}) . " flags;");
281 if ($e->{ALIGN} > 1) {
282 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
285 $self->pidl_code("");
287 if ($element_count > 0) {
288 $self->pidl_code("item = proto_tree_add_bitmask_with_flags(parent_tree, tvb, offset, hf_index,");
289 $self->pidl_code("\t\t\tett_$ifname\_$name, $ifname\_$name\_fields, DREP_ENC_INTEGER(drep), BMT_NO_FALSE);");
290 $self->pidl_code("");
292 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, parent_tree, di, drep, -1, &flags);");
293 $self->pidl_code("");
295 $self->pidl_code("if (!flags)");
296 $self->pidl_code("\tproto_item_append_text(item, \": (No values set)\");\n");
297 } else {
298 $self->pidl_code("proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, DREP_ENC_INTEGER(drep));");
299 $self->pidl_code("");
301 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, parent_tree, di, drep, -1, &flags);");
302 $self->pidl_code("");
305 foreach (@{$e->{ELEMENTS}}) {
306 next unless (/([^ ]*) (.*)/);
307 my ($en,$ev) = ($1,$2);
308 my $hf_bitname = "hf_$ifname\_$name\_$en";
309 my $filtername = "$ifname\.$name\.$en";
311 $self->{hf_used}->{$hf_bitname} = 1;
313 $ev =~ s/[()\s]//g;
314 if (hex($ev) != 0) {
315 $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", "( $ev )", "");
317 $self->pidl_def("static const true_false_string $name\_$en\_tfs = {");
318 if (defined($self->{conformance}->{tfs}->{$hf_bitname})) {
319 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{TRUE_STRING},");
320 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{FALSE_STRING},");
321 $self->{conformance}->{tfs}->{$hf_bitname}->{USED} = 1;
322 } else {
323 $self->pidl_def(" \"$en is SET\",");
324 $self->pidl_def(" \"$en is NOT SET\",");
326 $self->pidl_def("};");
330 # Note that if bitmask is full, some compilers would complain about flags &= (~0xffffffff)
331 if ($element_count > 0 && $element_count < 32) {
332 my $total_ev_hex = sprintf("0x%08x", $total_ev);
333 $self->pidl_code("if (flags & (~$total_ev_hex)) {");
334 $self->pidl_code("\tflags &= (~$total_ev_hex);");
335 $self->pidl_code("\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);");
336 $self->pidl_code("}\n");
338 $self->pidl_code("return offset;");
339 $self->deindent;
340 $self->pidl_code("}\n");
341 $self->pidl_fn_end($dissectorname);
343 my $size = $e->{BASE_TYPE};
344 $size =~ s/uint//g;
345 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
348 sub ElementLevel($$$$$$$$)
350 my ($self,$e,$l,$hf,$myname,$pn,$ifname,$param) = @_;
352 if (defined($self->{conformance}->{dissectorparams}->{$myname})) {
353 $param = $self->{conformance}->{dissectorparams}->{$myname}->{PARAM};
356 if ($l->{TYPE} eq "POINTER") {
357 my $type;
358 my $nl = undef;
359 if ($l->{LEVEL} eq "TOP") {
360 $type = "toplevel";
361 } elsif ($l->{LEVEL} eq "EMBEDDED") {
362 $type = "embedded";
363 $nl = GetNextLevel($e,$l);
366 if (defined($nl) and $nl->{TYPE} eq "SWITCH") {
367 $self->pidl_code("uint64_t saved_switch_level = di->switch_level;");
368 $self->pidl_code("");
369 $self->pidl_code("di->switch_level = $param;");
370 $self->pidl_code("");
373 $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, di, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);");
374 if (defined($nl) and $nl->{TYPE} eq "SWITCH") {
375 $self->pidl_code("");
376 $self->pidl_code("di->switch_level = saved_switch_level;");
378 } elsif ($l->{TYPE} eq "ARRAY") {
379 if ($l->{IS_INLINE}) {
380 #print Parse::Pidl::Util::MyDumper($e);
381 #print Parse::Pidl::Util::MyDumper($l);
382 print Parse::Pidl::Util::MyDumper($param);
383 $self->pidl_code("/* TODO $myname IS_INLINE */");
384 error($e->{ORIGINAL}, "Inline arrays not supported");
385 } elsif ($l->{IS_FIXED}) {
386 $self->pidl_code("int i;");
387 $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)");
388 $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, di, drep);");
389 } else {
390 if ($l->{IS_ZERO_TERMINATED}) {
391 $self->pidl_code("char *data = NULL;");
393 my $ngavar = "nga";
394 if (!$l->{IS_SURROUNDING}) {
395 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
396 $ngavar = "&nga";
398 if (!$l->{IS_SURROUNDING} and $l->{IS_CONFORMANT}) {
399 $self->pidl_code("");
400 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, $ngavar);");
402 if ($l->{IS_VARYING}) {
403 $self->pidl_code("");
404 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, $ngavar);");
407 unless ($l->{IS_ZERO_TERMINATED}) {
408 $self->pidl_code("");
409 $self->pidl_code("offset = dissect_ndr_generic_array_bytes(tvb, offset, pinfo, tree, di, drep, $ngavar, $myname\_);");
410 } else {
411 my $nl = GetNextLevel($e,$l);
412 my $nl_ctype = mapScalarType($nl->{DATA_TYPE});
413 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, sizeof($nl_ctype), $hf, false, $ngavar, &data);");
414 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
417 } elsif ($l->{TYPE} eq "DATA") {
418 if ($l->{DATA_TYPE} eq "string") {
419 my $bs = 2; # Byte size defaults to that of UCS2
422 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
424 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
425 $self->pidl_code("char *data = NULL;");
426 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
427 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
428 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
429 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
430 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
431 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
432 $self->pidl_code("char *data = NULL;");
433 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
434 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
435 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
436 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
437 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
438 $self->pidl_code("char *data = NULL;");
439 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
440 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
441 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
442 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
443 } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) {
444 if ($bs == 2) {
445 $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);")
446 } else {
447 $self->pidl_code("offset = dissect_null_term_string(tvb, offset, pinfo, tree, drep, $hf , 0);")
449 } else {
450 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
452 } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") {
453 my $remain = 0;
454 $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*"));
455 $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, di, drep, $hf, $remain);");
456 } else {
457 my $call;
459 my $within = ContainsWithinEmbeddedPointer($e, $l);
460 my $pl = GetPrevLevel($e,$l);
461 if ($param ne "0" and $within != 0 and defined($pl) and $pl->{TYPE} eq "SWITCH") {
462 $param = "di->switch_level";
465 if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) {
466 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA};
467 $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
468 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) {
469 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA};
470 $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
471 } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) {
472 $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
473 $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
474 } else {
475 my $t;
476 if (ref($l->{DATA_TYPE}) eq "HASH" ) {
477 $t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}";
478 } else {
479 $t = $l->{DATA_TYPE};
482 $self->pidl_code("offset = $ifname\_dissect_struct_" . $t . "(tvb,offset,pinfo,tree,di,drep,$hf,$param);");
484 return;
487 $call =~ s/\@HF\@/$hf/g;
488 $call =~ s/\@PARAM\@/$param/g;
489 $self->pidl_code($call);
491 } elsif ($_->{TYPE} eq "SUBCONTEXT" and $l->{HEADER_SIZE} == 0xFFFFFC01) {
492 my $varswitch;
493 if (has_property($e, "switch_is")) {
494 $varswitch = $e->{PROPERTIES}->{switch_is};
496 my $num_bits = 32;
497 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, "");
498 $num_bits = 3264 if ($num_bits == 32);
499 $self->{hf_used}->{$hf2} = 1;
500 $self->pidl_code("uint64_t size;");
501 $self->pidl_code("int conformant = di->conformant_run;");
502 $self->pidl_code("tvbuff_t *subtvb;");
503 $self->pidl_code("");
504 # We need to be able to dissect the length of the context in every case
505 # and conformant run skips the dissections of scalars ...
506 $self->pidl_code("if (!conformant) {");
507 $self->indent;
508 $self->pidl_code("uint32_t saved_flags = di->call_data->flags;");
509 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, di, drep, $hf2, &size);");
510 # This is a subcontext, there is normally no such thing as
511 # 64 bit NDR is subcontext so we clear the flag so that we can
512 # continue to dissect handmarshalled stuff with pidl
513 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;");
515 $self->pidl_code("subtvb = tvb_new_subset_length_caplen(tvb, offset, (int)size, (int)size);");
516 if ($param ne 0) {
517 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep, $param);");
518 } else {
519 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep);");
521 $self->pidl_code("offset += (int)size;");
522 $self->pidl_code("di->call_data->flags = saved_flags;");
523 $self->deindent;
524 $self->pidl_code("}");
525 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
526 my $varswitch;
527 if (has_property($e, "switch_is")) {
528 $varswitch = $e->{PROPERTIES}->{switch_is};
530 my $num_bits = ($l->{HEADER_SIZE}*8);
531 if ($num_bits == 0) {
532 $num_bits = 32;
534 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, "");
535 $num_bits = 3264 if ($num_bits == 32);
536 $self->{hf_used}->{$hf2} = 1;
537 $self->pidl_code("uint64_t size;");
538 $self->pidl_code("int conformant = di->conformant_run;");
539 $self->pidl_code("tvbuff_t *subtvb;");
540 $self->pidl_code("");
541 # We need to be able to dissect the length of the context in every case
542 # and conformant run skips the dissections of scalars ...
543 $self->pidl_code("if (!conformant) {");
544 $self->indent;
545 $self->pidl_code("uint32_t saved_flags = di->call_data->flags;");
546 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, di, drep, $hf2, &size);");
547 # This is a subcontext, there is normally no such thing as
548 # 64 bit NDR is subcontext so we clear the flag so that we can
549 # continue to dissect handmarshalled stuff with pidl
550 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;");
552 $self->pidl_code("subtvb = tvb_new_subset_length_caplen(tvb, offset, (int)size, (int)size);");
553 if ($param ne 0) {
554 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep, $param);");
555 } else {
556 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep);");
558 $self->pidl_code("offset += (int)size;");
559 $self->pidl_code("di->call_data->flags = saved_flags;");
560 $self->deindent;
561 $self->pidl_code("}");
562 } elsif ($_->{TYPE} eq "PIPE") {
563 error($e->{ORIGINAL}, "Type PIPE not yet supported");
564 } else {
565 die("Unknown type `$_->{TYPE}'");
569 sub SwitchType($$;$)
571 my ($e, $type, $nodiscriminant) = @_;
573 my $switch_dt = getType($type);
574 my $switch_type = undef;
575 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
576 $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
577 } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") {
578 $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA});
579 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
580 if (defined $e->{SWITCH_TYPE}) {
581 $switch_type = "$e->{SWITCH_TYPE}";
582 } else {
583 $switch_type = "$switch_dt->{DATA}->{NAME}";
585 } elsif (not defined $e->{SWITCH_TYPE}) {
586 $switch_type = $nodiscriminant;
589 return $switch_type
592 sub Element($$$$$$)
594 my ($self,$e,$pn,$ifname,$isoruseswitch,%switchvars) = @_;
596 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes});
598 my ($call_code, $moreparam);
599 my $l = @{$e->{LEVELS}}[0];
600 my $param = 0;
601 my $moreparam_once = 0;
602 if (defined $isoruseswitch) {
603 my $type = $isoruseswitch->[0];
604 my $name = $isoruseswitch->[1];
606 my $switch_dt = getType($type);
607 my $switch_raw_type = SwitchType($e, $type, "uint32");
608 if (not defined($switch_raw_type)) {
609 die("Unknown type[$type]\n");
611 my $switch_type = mapWireScalarType(${switch_raw_type});
613 if ($name ne "") {
614 if (has_property($e, "switch_is")) {
615 $moreparam = ", $switch_type ".$name;
616 } else {
617 $moreparam = ", $switch_type *".$name;
619 } else {
620 $moreparam = "";
622 if (($e->{PROPERTIES}->{switch_is} eq "") && ($switchvars{$name}) &&
623 #not a "native" type
624 (!($type =~ /^uint(8|16|1632|32|3264|64)/))) {
625 $param = $name;
626 } elsif ( $switch_dt->{DATA}->{TYPE} eq "ENUM") {
627 $param = $name;
628 } elsif ($name ne "") {
629 if (has_property($e, "switch_is")) {
630 $param = $name;
631 } else {
632 $param = "*".$name;
636 if ($name ne "") {
637 if (has_property($e, "switch_is")) {
638 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, $name);";
639 } else {
640 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, &$name);";
642 } else {
643 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep);";
645 } elsif ($l->{IS_SURROUNDING} and $l->{IS_CONFORMANT}) {
646 my $cfvarname = "nga_$e->{NAME}";
647 $moreparam = ", struct ndr_generic_array *nga";
648 $moreparam_once = 1;
649 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, &$cfvarname);";
650 } else {
651 $moreparam = "";
652 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep);";
656 my $type = $self->find_type($e->{TYPE});
658 if (not defined($type)) {
659 # default settings
660 $type = {
661 MASK => 0,
662 VALSSTRING => "NULL",
663 FT_TYPE => "FT_NONE",
664 BASE_TYPE => "BASE_NONE"
668 if (ContainsString($e)) {
669 $type = {
670 MASK => 0,
671 VALSSTRING => "NULL",
672 FT_TYPE => "FT_STRING",
673 BASE_TYPE => "BASE_NONE"
676 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) {
677 my $align_flag = $e->{PROPERTIES}->{flag};
678 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) {
679 $call_code = "ALIGN_TO_$1_BYTES; ".$call_code;
683 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}, "");
684 $self->{hf_used}->{$hf} = 1;
686 my $eltname = StripPrefixes($pn, $self->{conformance}->{strip_prefixes}) . ".$e->{NAME}";
687 if (defined($self->{conformance}->{noemit}->{$eltname})) {
688 return $call_code;
691 my $add = "";
693 my $oldparam = undef;
694 foreach (@{$e->{LEVELS}}) {
695 if (defined $_->{SWITCH_IS}) {
696 $oldparam = $param;
697 #if (($param ne "0") && (!($param =~ /\*/))) {
698 # $param = "*$param";
701 next if ($_->{TYPE} eq "SWITCH");
702 next if (defined($self->{conformance}->{noemit}->{"$dissectorname$add"}));
703 my $within = ContainsWithinEmbeddedPointer($e, $_);
704 my $saved_moreparam = $moreparam;
705 if ($within != 0) {
706 $moreparam = "";
708 $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_$moreparam);");
709 $self->pidl_fn_start("$dissectorname$add");
710 $self->pidl_code("static int");
711 $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_$moreparam)");
712 $self->pidl_code("{");
713 $self->indent;
715 $moreparam = $saved_moreparam;
717 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param);
718 if (defined $oldparam) {
719 $param = $oldparam;
722 $self->pidl_code("");
723 $self->pidl_code("return offset;");
724 $self->deindent;
725 $self->pidl_code("}\n");
726 $self->pidl_fn_end("$dissectorname$add");
727 $add.="_";
728 $moreparam="" if $moreparam_once;
729 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
732 return $call_code;
735 sub Function($$$)
737 my ($self, $fn,$ifname) = @_;
739 my %dissectornames;
741 foreach (@{$fn->{ELEMENTS}}) {
742 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, undef, ()) if not defined($dissectornames{$_->{NAME}});
745 my $fn_name = $_->{NAME};
746 $fn_name =~ s/^${ifname}_//;
748 $self->PrintIdl(DumpFunction($fn->{ORIGINAL}));
749 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response");
750 $self->pidl_code("static int");
751 $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_)");
752 $self->pidl_code("{");
753 $self->indent;
754 if ( not defined($fn->{RETURN_TYPE})) {
755 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "HRESULT")
757 $self->pidl_code("uint32_t status;\n");
758 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
759 if ($type->{DATA}->{TYPE} eq "ENUM") {
760 $self->pidl_code(Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . "_t status;\n");
761 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
762 $self->pidl_code(mapWireScalarType($fn->{RETURN_TYPE}) . " status;\n");
763 } else {
764 error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported");
766 } else {
767 error($fn, "unknown return type `$fn->{RETURN_TYPE}'");
770 $self->pidl_code("di->dcerpc_procedure_name=\"${fn_name}\";");
771 foreach (@{$fn->{ELEMENTS}}) {
772 if (grep(/out/,@{$_->{DIRECTION}})) {
773 $self->pidl_code("$dissectornames{$_->{NAME}}");
774 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);");
775 $self->pidl_code("");
779 if (not defined($fn->{RETURN_TYPE})) {
780 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
781 $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_status, &status);\n");
782 $self->pidl_code("if (status != 0)");
783 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str_ext(status, &NT_errors_ext, \"Unknown NT status 0x%08x\"));\n");
784 $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"];
785 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
786 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_werror, &status);\n");
787 $self->pidl_code("if (status != 0)");
788 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str_ext(status, &WERR_errors_ext, \"Unknown DOS error 0x%08x\"));\n");
790 $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"];
791 } elsif ($fn->{RETURN_TYPE} eq "HRESULT") {
792 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_hresult, &status);\n");
793 $self->pidl_code("if (status != 0)");
794 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str_ext(status, &HRES_errors_ext, \"Unknown HRES error 0x%08x\"));\n");
795 $return_types{$ifname}->{"hresult"} = ["HRESULT", "HRES Windows Error"];
796 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
797 if ($type->{DATA}->{TYPE} eq "ENUM") {
798 my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
800 $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
801 $self->pidl_code("if (status != 0)");
802 $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");
803 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
804 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
805 $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
806 $self->pidl_code("if (status != 0)");
807 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n");
808 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
812 $self->pidl_code("return offset;");
813 $self->deindent;
814 $self->pidl_code("}\n");
815 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_response");
817 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request");
818 $self->pidl_code("static int");
819 $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_)");
820 $self->pidl_code("{");
821 $self->indent;
822 $self->pidl_code("di->dcerpc_procedure_name=\"${fn_name}\";");
823 foreach (@{$fn->{ELEMENTS}}) {
824 if (grep(/in/,@{$_->{DIRECTION}})) {
825 $self->pidl_code("$dissectornames{$_->{NAME}}");
826 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);");
831 $self->pidl_code("return offset;");
832 $self->deindent;
833 $self->pidl_code("}\n");
834 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_request");
837 sub Struct($$$$)
839 my ($self,$e,$name,$ifname) = @_;
840 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
842 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
844 $self->register_ett("ett_$ifname\_$name");
846 my $res = "";
847 my $paramsrefs = {};
848 # will contain the switch var declaration;
849 my $vars = [];
850 my %paramshash;
851 foreach (@{$e->{ELEMENTS}}) {
852 my $paramvar = undef;
854 if (has_property($_, "switch_is")) {
855 $paramvar = $_->{PROPERTIES}->{switch_is};
858 if ($_->{LEVELS}[0]{IS_INLINE}) {
859 $paramvar = $_->{LEVELS}[0]{SIZE_IS};
862 if (defined($paramvar)) {
863 $paramsrefs->{$paramvar} = [];
864 $paramshash{$paramvar} = $paramvar;
866 #$VAR1 = {
867 # 'IS_CONFORMANT' => 0,
868 # 'IS_DEFERRED' => 0,
869 # 'IS_FIXED' => 0,
870 # 'IS_INLINE' => 1,
871 # 'IS_SURROUNDING' => 0,
872 # 'IS_TO_NULL' => 0,
873 # 'IS_VARYING' => 0,
874 # 'IS_ZERO_TERMINATED' => 0,
875 # 'LENGTH_IS' => 'name_len',
876 # 'LEVEL_INDEX' => 0,
877 # 'SIZE_IS' => 'name_len',
878 # 'TYPE' => 'ARRAY'
879 # };
882 foreach (@{$e->{ELEMENTS}}) {
883 my $paraminfo = undef;
885 my $v = $_->{NAME};
886 if (scalar(grep {/^$v$/} keys(%$paramsrefs)) == 1) {
887 # This element is one of the switch attribute
888 my $switch_raw_type = SwitchType($e, $_->{TYPE}, "uint32");
889 if (not defined($switch_raw_type)) {
890 die("Unknown type[$_->{TYPE}]\n");
892 my $switch_type = mapWireScalarType(${switch_raw_type});
894 if ($switch_type ne "") {
895 push @$vars, "$switch_type $v = 0;";
897 $paraminfo = [ $_->{TYPE}, $v ];
898 $paramsrefs->{$v} = $paraminfo;
901 my $paramvar = undef;
902 if (has_property($_, "switch_is")) {
903 $paramvar = $_->{PROPERTIES}->{switch_is};
906 if ($_->{LEVELS}[0]{IS_INLINE}) {
907 $paramvar = $_->{LEVELS}[0]{SIZE_IS};
910 if (defined($paramvar)) {
911 $paraminfo = $paramsrefs->{$paramvar};
914 $res.="\t".$self->Element($_, $name, $ifname, $paraminfo, %paramshash)."\n\n";
917 my $doalign = undef;
918 if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
919 $doalign = 1;
920 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
921 $doalign = 0;
924 my $cfdissectorname = undef;
925 my $cfvarname = undef;
926 if (defined $e->{SURROUNDING_ELEMENT}) {
927 my $se = $e->{SURROUNDING_ELEMENT};
928 my $pn = $name;
929 $cfdissectorname = "$ifname\_dissect\_conformant\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($se->{NAME}, $self->{conformance}->{strip_prefixes});
930 $cfvarname = "nga_$se->{NAME}";
931 push @$vars, "struct ndr_generic_array $cfvarname = { .is_conformant = false, };";
932 unless (defined($self->{conformance}->{noemit}->{"$cfdissectorname"})) {
934 $self->pidl_def("static int $cfdissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, struct ndr_generic_array *nga);");
935 $self->pidl_fn_start("$dissectorname");
936 $self->pidl_code("static int");
937 $self->pidl_code("$cfdissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, struct ndr_generic_array *nga)");
938 $self->pidl_code("{");
939 $self->indent;
941 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, nga);");
943 $self->pidl_code("");
944 $self->pidl_code("return offset;");
945 $self->deindent;
946 $self->pidl_code("}\n");
950 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, uint32_t param _U_);");
952 $self->pidl_fn_start($dissectorname);
953 $self->pidl_code("int");
954 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, uint32_t param _U_)");
955 $self->pidl_code("{");
956 $self->indent;
957 $self->pidl_code($_) foreach (@$vars);
958 $self->pidl_code("proto_item *item = NULL;");
959 if($res) {
960 $self->pidl_code("proto_tree *tree = NULL;");
962 if (defined($doalign) and $doalign == 0) {
963 $self->pidl_code("bool oldalign = di->no_align;");
965 $self->pidl_code("int old_offset;");
966 $self->pidl_code("");
968 if (defined $cfdissectorname) {
969 $self->pidl_code("offset = $cfdissectorname(tvb, offset, pinfo, parent_tree, di, drep, &$cfvarname);");
970 $self->pidl_code("");
973 if (defined($doalign)) {
974 if ($doalign == 1) {
975 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
977 if ($doalign == 0) {
978 $self->pidl_code("di->no_align = true;");
980 $self->pidl_code("");
983 $self->pidl_code("old_offset = offset;");
984 $self->pidl_code("");
985 $self->pidl_code("if (parent_tree) {");
986 $self->indent;
987 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);");
988 if($res) {
989 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
991 $self->deindent;
992 $self->pidl_code("}");
993 $self->pidl_code("");
995 $self->deindent;
996 $self->pidl_code("$res");
997 $self->indent;
999 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
1000 if (defined($doalign) and $doalign == 1 and not defined($e->{SURROUNDING_ELEMENT})) {
1001 $self->pidl_code("");
1002 $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
1003 $self->indent;
1004 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
1005 $self->deindent;
1006 $self->pidl_code("}");
1008 if (defined($doalign) and $doalign == 0) {
1009 $self->pidl_code("");
1010 $self->pidl_code("di->no_align = oldalign;");
1012 $self->pidl_code("");
1013 $self->pidl_code("return offset;");
1014 $self->deindent;
1015 $self->pidl_code("}\n");
1016 $self->pidl_fn_end($dissectorname);
1018 $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,di,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
1021 sub Union($$$$)
1023 my ($self,$e,$name,$ifname) = @_;
1025 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
1027 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
1029 $self->register_ett("ett_$ifname\_$name");
1031 my $res = "";
1032 foreach (@{$e->{ELEMENTS}}) {
1033 $res.="\n\t\t$_->{CASE}:\n";
1034 if ($_->{TYPE} ne "EMPTY") {
1035 $res.="\t\t\t".$self->Element($_, $name, $ifname, undef, ())."\n";
1037 $res.="\t\tbreak;\n";
1040 my $switch_type = undef;
1041 my $switch_dissect = undef;
1042 my $switch_raw_type = SwitchType($e, $e->{SWITCH_TYPE});
1043 if (defined($switch_raw_type)) {
1044 $switch_type = mapWireScalarType(${switch_raw_type});
1045 $switch_dissect = "dissect_ndr_${switch_raw_type}";
1048 $self->pidl_fn_start($dissectorname);
1049 $self->pidl_code("static int");
1050 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_, int hf_index _U_, uint32_t param _U_)");
1051 $self->pidl_code("{");
1052 $self->indent;
1053 $self->pidl_code("proto_item *item = NULL;");
1054 $self->pidl_code("proto_tree *tree = NULL;");
1055 $self->pidl_code("int old_offset;");
1056 if (!defined $switch_type) {
1057 $self->pidl_code("uint32_t level = param;");
1058 } else {
1059 $self->pidl_code("$switch_type level;");
1061 $self->pidl_code("");
1063 $self->pidl_code("old_offset = offset;");
1064 $self->pidl_code("if (parent_tree) {");
1065 $self->indent;
1066 $self->pidl_code("tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_$ifname\_$name, &item, \"$name\");");
1067 $self->deindent;
1068 $self->pidl_code("}");
1070 $self->pidl_code("");
1072 my $alignValue = $e->{ALIGN};
1073 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) {
1074 my $align_flag = $e->{PROPERTIES}->{flag};
1075 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) {
1076 $alignValue = $1;
1080 if (defined $switch_type) {
1081 if ($alignValue > 1) {
1082 $self->pidl_code("UNION_ALIGN_TO_".$alignValue."_BYTES;");
1085 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, di, drep, hf_index, &level);");
1088 if ($alignValue > 1) {
1089 if ($e->{IS_MS_UNION}) {
1090 $self->pidl_code("/* ms_union is always aligned to the largest union arm*/");
1091 $self->pidl_code("ALIGN_TO_".$alignValue."_BYTES;");
1092 } else {
1093 $self->pidl_code("UNION_ALIGN_TO_".$alignValue."_BYTES;");
1095 $self->pidl_code("");
1098 $self->pidl_code("switch(level) {$res\t}");
1099 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
1100 $self->pidl_code("");
1102 $self->pidl_code("return offset;");
1103 $self->deindent;
1104 $self->pidl_code("}");
1105 $self->pidl_fn_end($dissectorname);
1107 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
1110 sub Const($$$)
1112 my ($self,$const,$ifname) = @_;
1114 if (!defined($const->{ARRAY_LEN}[0])) {
1115 $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n");
1116 } else {
1117 $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n");
1121 sub Typedef($$$$)
1123 my ($self,$e,$name,$ifname) = @_;
1125 $self->Type($e->{DATA}, $name, $ifname);
1128 sub Type($$$$)
1130 my ($self, $e, $name, $ifname) = @_;
1132 $self->PrintIdl(DumpType($e->{ORIGINAL}));
1134 ENUM => \&Enum,
1135 STRUCT => \&Struct,
1136 UNION => \&Union,
1137 BITMAP => \&Bitmap,
1138 TYPEDEF => \&Typedef,
1139 PIPE => \&Pipe
1140 }->{$e->{TYPE}}->($self, $e, $name, $ifname);
1143 sub RegisterInterface($$)
1145 my ($self, $x) = @_;
1147 $self->pidl_fn_start("proto_register_dcerpc_$x->{NAME}");
1148 $self->pidl_code("void proto_register_dcerpc_$x->{NAME}(void)");
1149 $self->pidl_code("{");
1150 $self->indent;
1152 $self->{res}->{headers} .= "void proto_register_dcerpc_$x->{NAME}(void);\n";
1154 $self->{res}->{code}.=$self->DumpHfList()."\n";
1155 $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n";
1157 if (defined($x->{UUID})) {
1158 # These can be changed to non-pidl_code names if the old
1159 # dissectors in epan/dissectors are deleted.
1161 my $name = uc($x->{NAME}) . " (pidl)";
1162 my $short_name = uc($x->{NAME});
1163 my $filter_name = $x->{NAME};
1165 if (has_property($x, "helpstring")) {
1166 $name = $x->{PROPERTIES}->{helpstring};
1169 if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) {
1170 $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME};
1171 $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME};
1172 $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME};
1175 $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");");
1177 $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));");
1178 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
1179 } else {
1180 $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");");
1181 $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));");
1182 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
1185 $self->deindent;
1186 $self->pidl_code("}\n");
1187 $self->pidl_fn_end("proto_register_dcerpc_$x->{NAME}");
1190 sub RegisterInterfaceHandoff($$)
1192 my ($self,$x) = @_;
1194 if (defined($x->{UUID})) {
1195 $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}");
1196 $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)");
1197 $self->pidl_code("{");
1198 $self->indent;
1199 $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},");
1200 $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},");
1201 $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);");
1202 $self->deindent;
1203 $self->pidl_code("}");
1204 $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}");
1206 $self->{res}->{headers} .= "void proto_reg_handoff_dcerpc_$x->{NAME}(void);\n";
1208 $self->{hf_used}->{"hf_$x->{NAME}_opnum"} = 1;
1212 sub ProcessInclude
1214 my $self = shift;
1215 my @includes = @_;
1216 foreach (@includes) {
1217 $self->pidl_hdr("#include \"$_\"");
1219 $self->pidl_hdr("");
1222 sub ProcessImport
1224 my $self = shift;
1225 my @imports = @_;
1226 foreach (@imports) {
1227 next if($_ eq "security");
1228 s/^\"//;
1229 s/\.idl"?$//;
1230 s/^.*\///;
1231 $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\"");
1233 $self->pidl_hdr("");
1236 sub ProcessInterface($$)
1238 my ($self, $x) = @_;
1240 push(@{$self->{conformance}->{strip_prefixes}}, $x->{NAME});
1242 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
1243 $self->pidl_hdr("#ifndef $define");
1244 $self->pidl_hdr("#define $define");
1245 $self->pidl_hdr("");
1247 $self->pidl_def("static int proto_dcerpc_$x->{NAME};");
1248 $self->register_ett("ett_dcerpc_$x->{NAME}");
1249 $self->register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
1251 if (defined($x->{UUID})) {
1252 my $if_uuid = $x->{UUID};
1254 $self->pidl_def("/* Version information */\n\n");
1256 $self->pidl_def("static e_guid_t uuid_dcerpc_$x->{NAME} = {");
1257 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8)
1258 . ", 0x" . substr($if_uuid, 10, 4)
1259 . ", 0x" . substr($if_uuid, 15, 4) . ",");
1260 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2)
1261 . ", 0x" . substr($if_uuid, 22, 2)
1262 . ", 0x" . substr($if_uuid, 25, 2)
1263 . ", 0x" . substr($if_uuid, 27, 2)
1264 . ", 0x" . substr($if_uuid, 29, 2)
1265 . ", 0x" . substr($if_uuid, 31, 2)
1266 . ", 0x" . substr($if_uuid, 33, 2)
1267 . ", 0x" . substr($if_uuid, 35, 2) . " }");
1268 $self->pidl_def("};");
1270 my $maj = 0x0000FFFF & $x->{VERSION};
1271 $maj =~ s/\.(.*)$//g;
1272 $self->pidl_def("static uint16_t ver_dcerpc_$x->{NAME} = $maj;");
1273 $self->pidl_def("");
1276 $return_types{$x->{NAME}} = {};
1278 $self->Interface($x);
1279 $self->pidl_code("\n".DumpFunctionTable($x));
1281 foreach (sort(keys %{$return_types{$x->{NAME}}})) {
1282 my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}};
1283 my $dt = $self->find_type($type);
1284 $dt or die("Unable to find information about return type `$type'");
1285 $self->register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, $dt->{BASE_TYPE}, $dt->{VALSSTRING}, 0, "");
1286 $self->{hf_used}->{"hf_$x->{NAME}_$_"} = 1;
1289 $self->RegisterInterface($x);
1290 $self->RegisterInterfaceHandoff($x);
1292 if (exists ($self->{conformance}->{header})) {
1293 $self->pidl_hdr($self->{conformance}->{header});
1296 $self->pidl_hdr("#endif /* $define */");
1299 sub find_type($$)
1301 my ($self, $n) = @_;
1303 return $self->{conformance}->{types}->{$n};
1306 sub register_type($$$$$$$$)
1308 my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_;
1310 return if (defined($self->{conformance}->{types}->{$type}));
1312 $self->{conformance}->{types}->{$type} = {
1313 NAME => $type,
1314 DISSECTOR_NAME => $call,
1315 FT_TYPE => $ft,
1316 BASE_TYPE => $base,
1317 MASK => $mask,
1318 VALSSTRING => $vals,
1319 ALIGNMENT => $length
1323 # Loads the default types
1324 sub Initialize($$)
1326 my ($self, $cnf_file) = @_;
1328 $self->{conformance} = {
1329 imports => {},
1330 header_fields=> {}
1333 ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n";
1335 foreach my $bytes (qw(1 2 4 8)) {
1336 my $bits = $bytes * 8;
1337 $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
1338 $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
1341 $self->register_type("uint3264", "offset = dissect_ndr_uint3264(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8);
1342 $self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8);
1343 $self->register_type("int64", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_INT64", "BASE_DEC", 0, "NULL", 8);
1344 $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
1345 $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1346 $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1347 $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
1348 $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
1349 $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
1350 $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4);
1351 $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1352 $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME_hyper(tvb, offset, pinfo, tree, di, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1353 $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, di, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1354 $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME_1sec(tvb, offset, pinfo, tree, di, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
1355 $self->register_type("dom_sid28",
1356 "offset = dissect_ndr_nt_SID28(tvb, offset, pinfo, tree, di, drep, \@HF\@);", "FT_STRING", "BASE_NONE", 0, "NULL", 4);
1357 $self->register_type("SID",
1358 "offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, di, drep, param, \@HF\@);","FT_STRING", "BASE_NONE", 0, "NULL", 4);
1359 $self->register_type("WERROR",
1360 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&WERR_errors_ext", 4);
1361 $self->register_type("NTSTATUS",
1362 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&NT_errors_ext", 4);
1363 $self->register_type("HRESULT",
1364 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&HRES_errors_ext", 4);
1365 $self->register_type("ipv6address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 16, ENC_NA); offset += 16;", "FT_IPv6", "BASE_NONE", 0, "NULL", 16);
1366 $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);
1370 #####################################################################
1371 # Generate Wireshark parser and header code
1372 sub Parse($$$$$)
1374 my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_;
1376 $self->Initialize($cnf_file);
1378 return (undef, undef) if defined($self->{conformance}->{noemit_dissector});
1380 my $notice =
1381 "/* DO NOT EDIT
1382 This file was automatically generated by Pidl
1383 from $idl_file and $cnf_file.
1385 Pidl is a perl based IDL compiler for DCE/RPC idl files.
1386 It is maintained by the Samba team, not the Wireshark team.
1387 Instructions on how to download and install Pidl can be
1388 found at https://wiki.wireshark.org/Pidl
1393 $self->{res}->{headers} = "\n";
1394 $self->{res}->{headers} .= "#include \"config.h\"\n";
1396 $self->{res}->{headers} .= "#include <string.h>\n";
1397 $self->{res}->{headers} .= "#include <wsutil/array.h>\n";
1398 $self->{res}->{headers} .= "#include <epan/packet.h>\n";
1399 $self->{res}->{headers} .= "#include <epan/tfs.h>\n\n";
1401 $self->{res}->{headers} .= "#include \"packet-dcerpc.h\"\n";
1402 $self->{res}->{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
1403 $self->{res}->{headers} .= "#include \"packet-windows-common.h\"\n";
1405 my $h_basename = basename($h_filename);
1407 $self->{res}->{headers} .= "#include \"$h_basename\"\n";
1408 $self->pidl_code("");
1410 if (defined($self->{conformance}->{ett})) {
1411 register_ett($self,$_) foreach(@{$self->{conformance}->{ett}})
1414 # Wireshark protocol registration
1416 foreach (@$ndr) {
1417 $self->ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE");
1418 $self->ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT");
1419 $self->ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE");
1422 $self->{res}->{ett} = DumpEttDeclaration($self->{ett});
1423 $self->{res}->{hf} = $self->DumpHfDeclaration();
1425 my $parser = $notice;
1426 $parser.= $self->{res}->{headers};
1427 $parser.=$self->{res}->{ett};
1428 $parser.=$self->{res}->{hf};
1429 $parser.=$self->{res}->{def};
1430 if (exists ($self->{conformance}->{override})) {
1431 $parser.=$self->{conformance}->{override};
1433 $parser.=$self->{res}->{code};
1435 my $header = $notice;
1436 $header.=$self->{res}->{hdr};
1438 $self->CheckUsed($self->{conformance});
1440 return ($parser,$header);
1443 ###############################################################################
1444 # ETT
1445 ###############################################################################
1447 sub register_ett($$)
1449 my ($self, $name) = @_;
1451 push (@{$self->{ett}}, $name);
1454 sub DumpEttList
1456 my ($ett) = @_;
1457 my $res = "\tstatic int *ett[] = {\n";
1458 foreach (@$ett) {
1459 $res .= "\t\t&$_,\n";
1462 return "$res\t};\n";
1465 sub DumpEttDeclaration
1467 my ($ett) = @_;
1468 my $res = "\n/* Ett declarations */\n";
1469 foreach (@$ett) {
1470 $res .= "static int $_;\n";
1473 return "$res\n";
1476 ###############################################################################
1477 # HF
1478 ###############################################################################
1480 sub register_hf_field($$$$$$$$$)
1482 my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
1484 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1485 $self->{conformance}->{hf_renames}->{$index}->{USED} = 1;
1486 return $self->{conformance}->{hf_renames}->{$index}->{NEWNAME};
1489 $self->{conformance}->{header_fields}->{$index} = {
1490 INDEX => $index,
1491 NAME => $name,
1492 FILTER => $filter_name,
1493 FT_TYPE => $ft_type,
1494 BASE_TYPE => $base_type,
1495 VALSSTRING => $valsstring,
1496 MASK => $mask,
1497 BLURB => $blurb
1500 if ((not defined($blurb) or $blurb eq "") and
1501 defined($self->{conformance}->{fielddescription}->{$index})) {
1502 $self->{conformance}->{header_fields}->{$index}->{BLURB} =
1503 $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION};
1504 $self->{conformance}->{fielddescription}->{$index}->{USED} = 1;
1507 return $index;
1510 sub change_hf_field_type($$$$)
1512 my ($self,$index,$ft_type,$base_type) = @_;
1513 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1514 print "Field $index has been renamed to ".$self->{conformance}->{hf_renames}->{$index}->{NEWNAME}." you can't change it's type";
1515 return 0;
1518 if (!defined ($self->{conformance}->{header_fields}->{$index})) {
1519 print "Field $index doesn't exists";
1520 return 0;
1522 $self->{conformance}->{header_fields}->{$index}->{FT_TYPE} = $ft_type;
1523 $self->{conformance}->{header_fields}->{$index}->{BASE_TYPE} = $base_type;
1524 return 1;
1527 sub DumpHfDeclaration($)
1529 my ($self) = @_;
1530 my $res = "";
1532 $res = "\n/* Header field declarations */\n";
1534 foreach (sort(keys %{$self->{conformance}->{header_fields}}))
1536 $res .= "static int $_;\n";
1539 return "$res\n";
1542 sub make_str_or_null($)
1544 my $str = shift;
1545 if (substr($str, 0, 1) eq "\"") {
1546 $str = substr($str, 1, length($str)-2);
1548 $str =~ s/^\s*//;
1549 $str =~ s/\s*$//;
1550 if ($str eq "") {
1551 return "NULL";
1553 return make_str($str);
1556 sub DumpHfList($)
1558 my ($self) = @_;
1559 my $res = "\tstatic hf_register_info hf[] = {\n";
1561 foreach (sort {$a->{INDEX} cmp $b->{INDEX}} values %{$self->{conformance}->{header_fields}})
1563 $res .= "\t{ &$_->{INDEX},\n".
1564 "\t { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }},\n";
1567 return $res."\t};\n";
1571 ###############################################################################
1572 # Function table
1573 ###############################################################################
1575 sub DumpFunctionTable($)
1577 my $if = shift;
1579 my $res = "static const dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
1580 foreach (@{$if->{FUNCTIONS}}) {
1581 my $fn_name = $_->{NAME};
1582 $fn_name =~ s/^$if->{NAME}_//;
1583 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
1584 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
1587 $res .= "\t{ 0, NULL, NULL, NULL }\n";
1589 return "$res};\n";
1592 sub CheckUsed($$)
1594 my ($self, $conformance) = @_;
1595 foreach (values %{$conformance->{header_fields}}) {
1596 if (not defined($self->{hf_used}->{$_->{INDEX}})) {
1597 warning($_->{POS}, "hf field `$_->{INDEX}' not used");
1601 foreach (values %{$conformance->{hf_renames}}) {
1602 if (not $_->{USED}) {
1603 warning($_->{POS}, "hf field `$_->{OLDNAME}' not used");
1607 foreach (values %{$conformance->{dissectorparams}}) {
1608 if (not $_->{USED}) {
1609 warning($_->{POS}, "dissector param never used");
1613 foreach (values %{$conformance->{imports}}) {
1614 if (not $_->{USED}) {
1615 warning($_->{POS}, "import never used");
1619 foreach (values %{$conformance->{types}}) {
1620 if (not $_->{USED} and defined($_->{POS})) {
1621 warning($_->{POS}, "type never used");
1625 foreach (values %{$conformance->{fielddescription}}) {
1626 if (not $_->{USED}) {
1627 warning($_->{POS}, "description never used");
1631 foreach (values %{$conformance->{tfs}}) {
1632 if (not $_->{USED}) {
1633 warning($_->{POS}, "True/False description never used");