TODO tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm \@VALUEREF\@
[wireshark-sm.git] / tools / pidl / lib / Parse / Pidl / Wireshark / NDR.pm
blob585275efa3c252d77307b78d3baadc69311c8367
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_, uint32_t *param _U_, " . mapWireScalarType($e->{BASE_TYPE}) ." *pval _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_, guint32 param _U_, " . mapWireScalarType($e->{BASE_TYPE}) . " *pval _U_)");
207 $self->pidl_code("{");
208 $self->indent;
209 $self->pidl_code("return PIDL_dissect_$e->{BASE_TYPE}_val(tvb, offset, pinfo, tree, di, drep, hf_index, param, pval);");
210 $self->deindent;
211 $self->pidl_code("}\n");
212 $self->pidl_fn_end($dissectorname);
214 my $enum_size = $e->{BASE_TYPE};
215 $enum_size =~ s/uint//g;
216 my $ws_base = "BASE_DEC";
217 $ws_base = "BASE_HEX" if (property_matches($e, "flag", ".*LIBNDR_PRINT_ARRAY_HEX.*"));
218 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_UINT$enum_size", $ws_base, "0", "VALS($valsstring)", $enum_size / 8);
221 sub Pipe($$$$)
223 my ($self,$e,$name,$ifname) = @_;
224 error($e->{ORIGINAL}, "Pipe not yet supported");
225 return;
228 sub Bitmap($$$$)
230 my ($self,$e,$name,$ifname) = @_;
231 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
232 my $element_count = 0;
233 my $total_ev = 0;
235 $self->register_ett("ett_$ifname\_$name");
237 $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_, uint32_t *pval _U_);");
239 $self->pidl_fn_start($dissectorname);
240 $self->pidl_code("int");
241 $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_, uint32_t *pval _U_)");
242 $self->pidl_code("{");
243 $self->indent;
244 foreach (@{$e->{ELEMENTS}}) {
245 next unless (/([^ ]*) (.*)/);
246 $element_count++;
248 if ($element_count > 0) {
249 $self->pidl_code("proto_item *item;");
250 $self->pidl_code("static int * const $ifname\_$name\_fields[] = {");
251 $self->indent;
252 foreach (@{$e->{ELEMENTS}}) {
253 next unless (/([^ ]*) (.*)/);
254 my ($en,$ev) = ($1,$2);
255 my $hf_bitname = "hf_$ifname\_$name\_$1";
257 $ev =~ s/[()\s]//g;
258 if (hex($ev) != 0) {
259 $total_ev += hex($ev);
260 $self->pidl_code("&$hf_bitname,");
263 $self->pidl_code("NULL");
264 $self->deindent;
265 $self->pidl_code("};");
268 $self->pidl_code(mapWireScalarType($e->{BASE_TYPE}) . " flags;");
269 if ($e->{ALIGN} > 1) {
270 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
273 $self->pidl_code("");
275 if ($element_count > 0) {
276 $self->pidl_code("item = proto_tree_add_bitmask_with_flags(parent_tree, tvb, offset, hf_index,");
277 $self->pidl_code("\t\t\tett_$ifname\_$name, $ifname\_$name\_fields, DREP_ENC_INTEGER(drep), BMT_NO_FALSE);");
278 $self->pidl_code("");
280 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, parent_tree, di, drep, -1, &flags);");
281 $self->pidl_code("");
283 $self->pidl_code("if (!flags)");
284 $self->pidl_code("\tproto_item_append_text(item, \": (No values set)\");\n");
285 } else {
286 $self->pidl_code("proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, DREP_ENC_INTEGER(drep));");
287 $self->pidl_code("");
289 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, parent_tree, di, drep, -1, &flags);");
290 $self->pidl_code("");
293 foreach (@{$e->{ELEMENTS}}) {
294 next unless (/([^ ]*) (.*)/);
295 my ($en,$ev) = ($1,$2);
296 my $hf_bitname = "hf_$ifname\_$name\_$en";
297 my $filtername = "$ifname\.$name\.$en";
299 $self->{hf_used}->{$hf_bitname} = 1;
301 $ev =~ s/[()\s]//g;
302 if (hex($ev) != 0) {
303 $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", "( $ev )", "");
305 $self->pidl_def("static const true_false_string $name\_$en\_tfs = {");
306 if (defined($self->{conformance}->{tfs}->{$hf_bitname})) {
307 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{TRUE_STRING},");
308 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{FALSE_STRING},");
309 $self->{conformance}->{tfs}->{$hf_bitname}->{USED} = 1;
310 } else {
311 $self->pidl_def(" \"$en is SET\",");
312 $self->pidl_def(" \"$en is NOT SET\",");
314 $self->pidl_def("};");
318 # Note that if bitmask is full, some compilers would complain about flags &= (~0xffffffff)
319 if ($element_count > 0 && $element_count < 32) {
320 my $total_ev_hex = sprintf("0x%08x", $total_ev);
321 $self->pidl_code("if (flags & (~$total_ev_hex)) {");
322 $self->pidl_code("\tflags &= (~$total_ev_hex);");
323 $self->pidl_code("\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);");
324 $self->pidl_code("}\n");
326 $self->pidl_code("return offset;");
327 $self->deindent;
328 $self->pidl_code("}\n");
329 $self->pidl_fn_end($dissectorname);
331 my $size = $e->{BASE_TYPE};
332 $size =~ s/uint//g;
333 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
336 sub ElementLevel($$$$$$$$)
338 my ($self,$e,$l,$hf,$myname,$pn,$ifname,$param) = @_;
340 if (defined($self->{conformance}->{dissectorparams}->{$myname})) {
341 $param = $self->{conformance}->{dissectorparams}->{$myname}->{PARAM};
344 if ($l->{TYPE} eq "POINTER") {
345 my $type;
346 my $nl = undef;
347 if ($l->{LEVEL} eq "TOP") {
348 $type = "toplevel";
349 } elsif ($l->{LEVEL} eq "EMBEDDED") {
350 $type = "embedded";
351 $nl = GetNextLevel($e,$l);
354 if (defined($nl) and $nl->{TYPE} eq "SWITCH") {
355 $self->pidl_code("guint64 saved_switch_level = di->switch_level;");
356 $self->pidl_code("");
357 $self->pidl_code("di->switch_level = $param;");
358 $self->pidl_code("");
361 $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);");
362 if (defined($nl) and $nl->{TYPE} eq "SWITCH") {
363 $self->pidl_code("");
364 $self->pidl_code("di->switch_level = saved_switch_level;");
366 } elsif ($l->{TYPE} eq "ARRAY") {
367 if ($l->{IS_INLINE}) {
368 #print Parse::Pidl::Util::MyDumper($e);
369 #print Parse::Pidl::Util::MyDumper($l);
370 print Parse::Pidl::Util::MyDumper($param);
371 $self->pidl_code("/* TODO $myname IS_INLINE */");
372 error($e->{ORIGINAL}, "Inline arrays not supported");
373 } elsif ($l->{IS_FIXED}) {
374 $self->pidl_code("int i;");
375 $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)");
376 $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, di, drep);");
377 } else {
378 if ($l->{IS_ZERO_TERMINATED}) {
379 $self->pidl_code("char *data = NULL;");
381 my $ngavar = "nga";
382 if (!$l->{IS_SURROUNDING}) {
383 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = FALSE, };");
384 $ngavar = "&nga";
386 if (!$l->{IS_SURROUNDING} and $l->{IS_CONFORMANT}) {
387 $self->pidl_code("");
388 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, $ngavar);");
390 if ($l->{IS_VARYING}) {
391 $self->pidl_code("");
392 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, $ngavar);");
395 unless ($l->{IS_ZERO_TERMINATED}) {
396 $self->pidl_code("");
397 $self->pidl_code("offset = dissect_ndr_generic_array_bytes(tvb, offset, pinfo, tree, di, drep, $ngavar, $myname\_);");
398 } else {
399 my $nl = GetNextLevel($e,$l);
400 my $nl_ctype = mapScalarType($nl->{DATA_TYPE});
401 $self->pidl_code("char *data;");
402 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, sizeof($nl_ctype), $hf, FALSE, $ngavar, &data);");
403 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
406 } elsif ($l->{TYPE} eq "DATA") {
407 if ($l->{DATA_TYPE} eq "string") {
408 my $bs = 2; # Byte size defaults to that of UCS2
411 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
413 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
414 $self->pidl_code("char *data = NULL;");
415 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = FALSE, };");
416 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
417 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
418 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
419 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
420 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
421 $self->pidl_code("char *data = NULL;");
422 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
423 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
424 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
425 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
426 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
427 $self->pidl_code("char *data = NULL;");
428 $self->pidl_code("struct ndr_generic_array nga = { .is_conformant = false, };");
429 $self->pidl_code("offset = dissect_ndr_varying_array_hdr(tvb, offset, pinfo, tree, di, drep, &nga);");
430 $self->pidl_code("offset = dissect_ndr_generic_array_string(tvb, offset, pinfo, tree, di, drep, $bs, $hf, false, &nga, &data);");
431 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
432 } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) {
433 if ($bs == 2) {
434 $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);")
435 } else {
436 $self->pidl_code("offset = dissect_null_term_string(tvb, offset, pinfo, tree, drep, $hf , 0);")
438 } else {
439 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
441 } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") {
442 my $remain = 0;
443 $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*"));
444 $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, di, drep, $hf, $remain);");
445 } else {
446 my $call;
448 my $within = ContainsWithinEmbeddedPointer($e, $l);
449 my $pl = GetPrevLevel($e,$l);
450 if ($param ne "0" and $within != 0 and defined($pl) and $pl->{TYPE} eq "SWITCH") {
451 $param = "di->switch_level";
454 if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) {
455 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA};
456 $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
457 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) {
458 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA};
459 $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
460 } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) {
461 $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
462 $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
463 } else {
464 my $t;
465 if (ref($l->{DATA_TYPE}) eq "HASH" ) {
466 $t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}";
467 } else {
468 $t = $l->{DATA_TYPE};
471 $self->pidl_code("offset = $ifname\_dissect_struct_" . $t . "(tvb,offset,pinfo,tree,di,drep,$hf,$param);");
473 return;
476 $call =~ s/\@HF\@/$hf/g;
477 $call =~ s/\@PARAM\@/$param/g;
478 $self->pidl_code($call);
480 } elsif ($_->{TYPE} eq "SUBCONTEXT" and $l->{HEADER_SIZE} == 0xFFFFFC01) {
481 my $varswitch;
482 if (has_property($e, "switch_is")) {
483 $varswitch = $e->{PROPERTIES}->{switch_is};
485 my $num_bits = 32;
486 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, "");
487 $num_bits = 3264 if ($num_bits == 32);
488 $self->{hf_used}->{$hf2} = 1;
489 $self->pidl_code("guint$num_bits size;");
490 $self->pidl_code("int conformant = di->conformant_run;");
491 $self->pidl_code("tvbuff_t *subtvb;");
492 $self->pidl_code("");
493 # We need to be able to dissect the length of the context in every case
494 # and conformant run skips the dissections of scalars ...
495 $self->pidl_code("if (!conformant) {");
496 $self->indent;
497 $self->pidl_code("guint32 saved_flags = di->call_data->flags;");
498 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, di, drep, $hf2, &size);");
499 # This is a subcontext, there is normally no such thing as
500 # 64 bit NDR is subcontext so we clear the flag so that we can
501 # continue to dissect handmarshalled stuff with pidl
502 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;");
504 $self->pidl_code("subtvb = tvb_new_subset_length_caplen(tvb, offset, (gint)size, (gint)size);");
505 if ($param ne 0) {
506 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep, $param);");
507 } else {
508 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep);");
510 $self->pidl_code("offset += (int)size;");
511 $self->pidl_code("di->call_data->flags = saved_flags;");
512 $self->deindent;
513 $self->pidl_code("}");
514 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
515 my $varswitch;
516 if (has_property($e, "switch_is")) {
517 $varswitch = $e->{PROPERTIES}->{switch_is};
519 my $num_bits = ($l->{HEADER_SIZE}*8);
520 if ($num_bits == 0) {
521 $num_bits = 32;
523 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, "");
524 $num_bits = 3264 if ($num_bits == 32);
525 $self->{hf_used}->{$hf2} = 1;
526 $self->pidl_code("uint${num_bits}_t size;");
527 $self->pidl_code("int conformant = di->conformant_run;");
528 $self->pidl_code("tvbuff_t *subtvb;");
529 $self->pidl_code("");
530 # We need to be able to dissect the length of the context in every case
531 # and conformant run skips the dissections of scalars ...
532 $self->pidl_code("if (!conformant) {");
533 $self->indent;
534 $self->pidl_code("uint32_t saved_flags = di->call_data->flags;");
535 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, di, drep, $hf2, &size);");
536 # This is a subcontext, there is normally no such thing as
537 # 64 bit NDR is subcontext so we clear the flag so that we can
538 # continue to dissect handmarshalled stuff with pidl
539 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;");
541 $self->pidl_code("subtvb = tvb_new_subset_length_caplen(tvb, offset, (int)size, (int)size);");
542 if ($param ne 0) {
543 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep, $param);");
544 } else {
545 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, di, drep);");
547 $self->pidl_code("offset += (int)size;");
548 $self->pidl_code("di->call_data->flags = saved_flags;");
549 $self->deindent;
550 $self->pidl_code("}");
551 } elsif ($_->{TYPE} eq "PIPE") {
552 error($e->{ORIGINAL}, "Type PIPE not yet supported");
553 } else {
554 die("Unknown type `$_->{TYPE}'");
558 sub SwitchType($$;$)
560 my ($e, $type, $nodiscriminant) = @_;
562 my $switch_dt = getType($type);
563 my $switch_type = undef;
564 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
565 $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
566 } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") {
567 $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA});
568 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
569 if (defined $e->{SWITCH_TYPE}) {
570 $switch_type = "$e->{SWITCH_TYPE}";
571 } else {
572 $switch_type = "$switch_dt->{DATA}->{NAME}";
574 } elsif (not defined $e->{SWITCH_TYPE}) {
575 $switch_type = $nodiscriminant;
578 return $switch_type
581 sub Element($$$$$$)
583 my ($self,$e,$pn,$ifname,$isoruseswitch,%switchvars) = @_;
585 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes});
587 my ($call_code, $moreparam);
588 my $l = @{$e->{LEVELS}}[0];
589 my $param = 0;
590 my $moreparam_once = 0;
591 if (defined $isoruseswitch) {
592 my $type = $isoruseswitch->[0];
593 my $name = $isoruseswitch->[1];
595 my $switch_dt = getType($type);
596 my $switch_raw_type = SwitchType($e, $type, "uint32");
597 if (not defined($switch_raw_type)) {
598 die("Unknown type[$type]\n");
600 my $switch_type = mapWireScalarType(${switch_raw_type});
602 if ($name ne "") {
603 if (has_property($e, "switch_is")) {
604 $moreparam = ", $switch_type ".$name;
605 } else {
606 $moreparam = ", $switch_type *".$name;
608 } else {
609 $moreparam = "";
611 if (($e->{PROPERTIES}->{switch_is} eq "") && ($switchvars{$name}) &&
612 #not a "native" type
613 (!($type =~ /^uint(8|16|1632|32|3264|64)/))) {
614 $param = $name;
615 } elsif ( $switch_dt->{DATA}->{TYPE} eq "ENUM") {
616 $param = $name;
617 } elsif ($name ne "") {
618 if (has_property($e, "switch_is")) {
619 $param = $name;
620 } else {
621 $param = "*".$name;
625 if ($name ne "") {
626 if (has_property($e, "switch_is")) {
627 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, $name);";
628 } else {
629 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, &$name);";
631 } else {
632 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep);";
634 } elsif ($l->{IS_SURROUNDING} and $l->{IS_CONFORMANT}) {
635 my $cfvarname = "nga_$e->{NAME}";
636 $moreparam = ", struct ndr_generic_array *nga";
637 $moreparam_once = 1;
638 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, &$cfvarname);";
639 } else {
640 $moreparam = "";
641 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep);";
645 my $type = $self->find_type($e->{TYPE});
647 if (not defined($type)) {
648 # default settings
649 $type = {
650 MASK => 0,
651 VALSSTRING => "NULL",
652 FT_TYPE => "FT_NONE",
653 BASE_TYPE => "BASE_NONE"
657 if (ContainsString($e)) {
658 $type = {
659 MASK => 0,
660 VALSSTRING => "NULL",
661 FT_TYPE => "FT_STRING",
662 BASE_TYPE => "BASE_NONE"
665 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) {
666 my $align_flag = $e->{PROPERTIES}->{flag};
667 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) {
668 $call_code = "ALIGN_TO_$1_BYTES; ".$call_code;
672 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}, "");
673 $self->{hf_used}->{$hf} = 1;
675 my $eltname = StripPrefixes($pn, $self->{conformance}->{strip_prefixes}) . ".$e->{NAME}";
676 if (defined($self->{conformance}->{noemit}->{$eltname})) {
677 return $call_code;
680 my $add = "";
682 my $oldparam = undef;
683 foreach (@{$e->{LEVELS}}) {
684 if (defined $_->{SWITCH_IS}) {
685 $oldparam = $param;
686 #if (($param ne "0") && (!($param =~ /\*/))) {
687 # $param = "*$param";
690 next if ($_->{TYPE} eq "SWITCH");
691 next if (defined($self->{conformance}->{noemit}->{"$dissectorname$add"}));
692 my $within = ContainsWithinEmbeddedPointer($e, $_);
693 my $saved_moreparam = $moreparam;
694 if ($within != 0) {
695 $moreparam = "";
697 $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);");
698 $self->pidl_fn_start("$dissectorname$add");
699 $self->pidl_code("static int");
700 $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)");
701 $self->pidl_code("{");
702 $self->indent;
704 $moreparam = $saved_moreparam;
706 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param);
707 if (defined $oldparam) {
708 $param = $oldparam;
711 $self->pidl_code("");
712 $self->pidl_code("return offset;");
713 $self->deindent;
714 $self->pidl_code("}\n");
715 $self->pidl_fn_end("$dissectorname$add");
716 $add.="_";
717 $moreparam="" if $moreparam_once;
718 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
721 return $call_code;
724 sub Function($$$)
726 my ($self, $fn,$ifname) = @_;
728 my %dissectornames;
730 foreach (@{$fn->{ELEMENTS}}) {
731 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, undef, ()) if not defined($dissectornames{$_->{NAME}});
734 my $fn_name = $_->{NAME};
735 $fn_name =~ s/^${ifname}_//;
737 $self->PrintIdl(DumpFunction($fn->{ORIGINAL}));
738 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response");
739 $self->pidl_code("static int");
740 $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_)");
741 $self->pidl_code("{");
742 $self->indent;
743 if ( not defined($fn->{RETURN_TYPE})) {
744 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "HRESULT")
746 $self->pidl_code("uint32_t status;\n");
747 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
748 if ($type->{DATA}->{TYPE} eq "ENUM") {
749 $self->pidl_code(Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . "_t status;\n");
750 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
751 $self->pidl_code(mapWireScalarType($fn->{RETURN_TYPE}) . " status;\n");
752 } else {
753 error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported");
755 } else {
756 error($fn, "unknown return type `$fn->{RETURN_TYPE}'");
759 $self->pidl_code("di->dcerpc_procedure_name=\"${fn_name}\";");
760 foreach (@{$fn->{ELEMENTS}}) {
761 if (grep(/out/,@{$_->{DIRECTION}})) {
762 $self->pidl_code("$dissectornames{$_->{NAME}}");
763 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);");
764 $self->pidl_code("");
768 if (not defined($fn->{RETURN_TYPE})) {
769 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
770 $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_status, &status);\n");
771 $self->pidl_code("if (status != 0)");
772 $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");
773 $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"];
774 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
775 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_werror, &status);\n");
776 $self->pidl_code("if (status != 0)");
777 $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");
779 $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"];
780 } elsif ($fn->{RETURN_TYPE} eq "HRESULT") {
781 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_hresult, &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, &HRES_errors_ext, \"Unknown HRES error 0x%08x\"));\n");
784 $return_types{$ifname}->{"hresult"} = ["HRESULT", "HRES Windows Error"];
785 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
786 if ($type->{DATA}->{TYPE} eq "ENUM") {
787 my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
789 $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
790 $self->pidl_code("if (status != 0)");
791 $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");
792 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
793 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
794 $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, di, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
795 $self->pidl_code("if (status != 0)");
796 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n");
797 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
801 $self->pidl_code("return offset;");
802 $self->deindent;
803 $self->pidl_code("}\n");
804 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_response");
806 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request");
807 $self->pidl_code("static int");
808 $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_)");
809 $self->pidl_code("{");
810 $self->indent;
811 $self->pidl_code("di->dcerpc_procedure_name=\"${fn_name}\";");
812 foreach (@{$fn->{ELEMENTS}}) {
813 if (grep(/in/,@{$_->{DIRECTION}})) {
814 $self->pidl_code("$dissectornames{$_->{NAME}}");
815 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, di, drep);");
820 $self->pidl_code("return offset;");
821 $self->deindent;
822 $self->pidl_code("}\n");
823 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_request");
826 sub Struct($$$$)
828 my ($self,$e,$name,$ifname) = @_;
829 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
831 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
833 $self->register_ett("ett_$ifname\_$name");
835 my $res = "";
836 my $paramsrefs = {};
837 # will contain the switch var declaration;
838 my $vars = [];
839 my %paramshash;
840 foreach (@{$e->{ELEMENTS}}) {
841 my $paramvar = undef;
843 if (has_property($_, "switch_is")) {
844 $paramvar = $_->{PROPERTIES}->{switch_is};
847 if ($_->{LEVELS}[0]{IS_INLINE}) {
848 $paramvar = $_->{LEVELS}[0]{SIZE_IS};
851 if (defined($paramvar)) {
852 $paramsrefs->{$paramvar} = [];
853 $paramshash{$paramvar} = $paramvar;
855 #$VAR1 = {
856 # 'IS_CONFORMANT' => 0,
857 # 'IS_DEFERRED' => 0,
858 # 'IS_FIXED' => 0,
859 # 'IS_INLINE' => 1,
860 # 'IS_SURROUNDING' => 0,
861 # 'IS_TO_NULL' => 0,
862 # 'IS_VARYING' => 0,
863 # 'IS_ZERO_TERMINATED' => 0,
864 # 'LENGTH_IS' => 'name_len',
865 # 'LEVEL_INDEX' => 0,
866 # 'SIZE_IS' => 'name_len',
867 # 'TYPE' => 'ARRAY'
868 # };
871 foreach (@{$e->{ELEMENTS}}) {
872 my $paraminfo = undef;
874 my $v = $_->{NAME};
875 if (scalar(grep {/^$v$/} keys(%$paramsrefs)) == 1) {
876 # This element is one of the switch attribute
877 my $switch_raw_type = SwitchType($e, $_->{TYPE}, "uint32");
878 if (not defined($switch_raw_type)) {
879 die("Unknown type[$_->{TYPE}]\n");
881 my $switch_type = mapWireScalarType(${switch_raw_type});
883 if ($switch_type ne "") {
884 push @$vars, "$switch_type $v = 0;";
886 $paraminfo = [ $_->{TYPE}, $v ];
887 $paramsrefs->{$v} = $paraminfo;
890 my $paramvar = undef;
891 if (has_property($_, "switch_is")) {
892 $paramvar = $_->{PROPERTIES}->{switch_is};
895 if ($_->{LEVELS}[0]{IS_INLINE}) {
896 $paramvar = $_->{LEVELS}[0]{SIZE_IS};
899 if (defined($paramvar)) {
900 $paraminfo = $paramsrefs->{$paramvar};
903 $res.="\t".$self->Element($_, $name, $ifname, $paraminfo, %paramshash)."\n\n";
906 my $doalign = undef;
907 if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
908 $doalign = 1;
909 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
910 $doalign = 0;
913 my $cfdissectorname = undef;
914 my $cfvarname = undef;
915 if (defined $e->{SURROUNDING_ELEMENT}) {
916 my $se = $e->{SURROUNDING_ELEMENT};
917 my $pn = $name;
918 $cfdissectorname = "$ifname\_dissect\_conformant\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($se->{NAME}, $self->{conformance}->{strip_prefixes});
919 $cfvarname = "nga_$se->{NAME}";
920 push @$vars, "struct ndr_generic_array $cfvarname = { .is_conformant = FALSE, };";
921 unless (defined($self->{conformance}->{noemit}->{"$cfdissectorname"})) {
923 $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);");
924 $self->pidl_fn_start("$dissectorname");
925 $self->pidl_code("static int");
926 $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)");
927 $self->pidl_code("{");
928 $self->indent;
930 $self->pidl_code("offset = dissect_ndr_conformant_array_hdr(tvb, offset, pinfo, tree, di, drep, nga);");
932 $self->pidl_code("");
933 $self->pidl_code("return offset;");
934 $self->deindent;
935 $self->pidl_code("}\n");
939 $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_);");
941 $self->pidl_fn_start($dissectorname);
942 $self->pidl_code("int");
943 $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_)");
944 $self->pidl_code("{");
945 $self->indent;
946 $self->pidl_code($_) foreach (@$vars);
947 $self->pidl_code("proto_item *item = NULL;");
948 if($res) {
949 $self->pidl_code("proto_tree *tree = NULL;");
951 if (defined($doalign) and $doalign == 0) {
952 $self->pidl_code("bool oldalign = di->no_align;");
954 $self->pidl_code("int old_offset;");
955 $self->pidl_code("");
957 if (defined $cfdissectorname) {
958 $self->pidl_code("offset = $cfdissectorname(tvb, offset, pinfo, parent_tree, di, drep, &$cfvarname);");
959 $self->pidl_code("");
962 if (defined($doalign)) {
963 if ($doalign == 1) {
964 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
966 if ($doalign == 0) {
967 $self->pidl_code("di->no_align = true;");
969 $self->pidl_code("");
972 $self->pidl_code("old_offset = offset;");
973 $self->pidl_code("");
974 $self->pidl_code("if (parent_tree) {");
975 $self->indent;
976 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);");
977 if($res) {
978 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
980 $self->deindent;
981 $self->pidl_code("}");
982 $self->pidl_code("");
984 $self->deindent;
985 $self->pidl_code("$res");
986 $self->indent;
988 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
989 if (defined($doalign) and $doalign == 1 and not defined($e->{SURROUNDING_ELEMENT})) {
990 $self->pidl_code("");
991 $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
992 $self->indent;
993 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
994 $self->deindent;
995 $self->pidl_code("}");
997 if (defined($doalign) and $doalign == 0) {
998 $self->pidl_code("");
999 $self->pidl_code("di->no_align = oldalign;");
1001 $self->pidl_code("");
1002 $self->pidl_code("return offset;");
1003 $self->deindent;
1004 $self->pidl_code("}\n");
1005 $self->pidl_fn_end($dissectorname);
1007 $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,di,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
1010 sub Union($$$$)
1012 my ($self,$e,$name,$ifname) = @_;
1014 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
1016 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
1018 $self->register_ett("ett_$ifname\_$name");
1020 my $res = "";
1021 foreach (@{$e->{ELEMENTS}}) {
1022 $res.="\n\t\t$_->{CASE}:\n";
1023 if ($_->{TYPE} ne "EMPTY") {
1024 $res.="\t\t\t".$self->Element($_, $name, $ifname, undef, ())."\n";
1026 $res.="\t\tbreak;\n";
1029 my $switch_type = undef;
1030 my $switch_dissect = undef;
1031 my $switch_raw_type = SwitchType($e, $e->{SWITCH_TYPE});
1032 if (defined($switch_raw_type)) {
1033 $switch_type = mapWireScalarType(${switch_raw_type});
1034 $switch_dissect = "dissect_ndr_${switch_raw_type}";
1037 $self->pidl_fn_start($dissectorname);
1038 $self->pidl_code("static int");
1039 $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_)");
1040 $self->pidl_code("{");
1041 $self->indent;
1042 $self->pidl_code("proto_item *item = NULL;");
1043 $self->pidl_code("proto_tree *tree = NULL;");
1044 $self->pidl_code("int old_offset;");
1045 if (!defined $switch_type) {
1046 $self->pidl_code("uint32_t level = param;");
1047 } else {
1048 $self->pidl_code("$switch_type level;");
1050 $self->pidl_code("");
1052 $self->pidl_code("old_offset = offset;");
1053 $self->pidl_code("if (parent_tree) {");
1054 $self->indent;
1055 $self->pidl_code("tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_$ifname\_$name, &item, \"$name\");");
1056 $self->deindent;
1057 $self->pidl_code("}");
1059 $self->pidl_code("");
1061 my $alignValue = $e->{ALIGN};
1062 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) {
1063 my $align_flag = $e->{PROPERTIES}->{flag};
1064 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) {
1065 $alignValue = $1;
1069 if (defined $switch_type) {
1070 if ($alignValue > 1) {
1071 $self->pidl_code("UNION_ALIGN_TO_".$alignValue."_BYTES;");
1074 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, di, drep, hf_index, &level);");
1077 if ($alignValue > 1) {
1078 if ($e->{IS_MS_UNION}) {
1079 $self->pidl_code("/* ms_union is always aligned to the largest union arm*/");
1080 $self->pidl_code("ALIGN_TO_".$alignValue."_BYTES;");
1081 } else {
1082 $self->pidl_code("UNION_ALIGN_TO_".$alignValue."_BYTES;");
1084 $self->pidl_code("");
1087 $self->pidl_code("switch(level) {$res\t}");
1088 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
1089 $self->pidl_code("");
1091 $self->pidl_code("return offset;");
1092 $self->deindent;
1093 $self->pidl_code("}");
1094 $self->pidl_fn_end($dissectorname);
1096 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
1099 sub Const($$$)
1101 my ($self,$const,$ifname) = @_;
1103 if (!defined($const->{ARRAY_LEN}[0])) {
1104 $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n");
1105 } else {
1106 $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n");
1110 sub Typedef($$$$)
1112 my ($self,$e,$name,$ifname) = @_;
1114 $self->Type($e->{DATA}, $name, $ifname);
1117 sub Type($$$$)
1119 my ($self, $e, $name, $ifname) = @_;
1121 $self->PrintIdl(DumpType($e->{ORIGINAL}));
1123 ENUM => \&Enum,
1124 STRUCT => \&Struct,
1125 UNION => \&Union,
1126 BITMAP => \&Bitmap,
1127 TYPEDEF => \&Typedef,
1128 PIPE => \&Pipe
1129 }->{$e->{TYPE}}->($self, $e, $name, $ifname);
1132 sub RegisterInterface($$)
1134 my ($self, $x) = @_;
1136 $self->pidl_fn_start("proto_register_dcerpc_$x->{NAME}");
1137 $self->pidl_code("void proto_register_dcerpc_$x->{NAME}(void)");
1138 $self->pidl_code("{");
1139 $self->indent;
1141 $self->{res}->{headers} .= "void proto_register_dcerpc_$x->{NAME}(void);\n";
1143 $self->{res}->{code}.=$self->DumpHfList()."\n";
1144 $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n";
1146 if (defined($x->{UUID})) {
1147 # These can be changed to non-pidl_code names if the old
1148 # dissectors in epan/dissectors are deleted.
1150 my $name = uc($x->{NAME}) . " (pidl)";
1151 my $short_name = uc($x->{NAME});
1152 my $filter_name = $x->{NAME};
1154 if (has_property($x, "helpstring")) {
1155 $name = $x->{PROPERTIES}->{helpstring};
1158 if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) {
1159 $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME};
1160 $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME};
1161 $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME};
1164 $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");");
1166 $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));");
1167 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
1168 } else {
1169 $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");");
1170 $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));");
1171 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
1174 $self->deindent;
1175 $self->pidl_code("}\n");
1176 $self->pidl_fn_end("proto_register_dcerpc_$x->{NAME}");
1179 sub RegisterInterfaceHandoff($$)
1181 my ($self,$x) = @_;
1183 if (defined($x->{UUID})) {
1184 $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}");
1185 $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)");
1186 $self->pidl_code("{");
1187 $self->indent;
1188 $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},");
1189 $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},");
1190 $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);");
1191 $self->deindent;
1192 $self->pidl_code("}");
1193 $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}");
1195 $self->{res}->{headers} .= "void proto_reg_handoff_dcerpc_$x->{NAME}(void);\n";
1197 $self->{hf_used}->{"hf_$x->{NAME}_opnum"} = 1;
1201 sub ProcessInclude
1203 my $self = shift;
1204 my @includes = @_;
1205 foreach (@includes) {
1206 $self->pidl_hdr("#include \"$_\"");
1208 $self->pidl_hdr("");
1211 sub ProcessImport
1213 my $self = shift;
1214 my @imports = @_;
1215 foreach (@imports) {
1216 next if($_ eq "security");
1217 s/^\"//;
1218 s/\.idl"?$//;
1219 s/^.*\///;
1220 $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\"");
1222 $self->pidl_hdr("");
1225 sub ProcessInterface($$)
1227 my ($self, $x) = @_;
1229 push(@{$self->{conformance}->{strip_prefixes}}, $x->{NAME});
1231 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
1232 $self->pidl_hdr("#ifndef $define");
1233 $self->pidl_hdr("#define $define");
1234 $self->pidl_hdr("");
1236 $self->pidl_def("static int proto_dcerpc_$x->{NAME};");
1237 $self->register_ett("ett_dcerpc_$x->{NAME}");
1238 $self->register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
1240 if (defined($x->{UUID})) {
1241 my $if_uuid = $x->{UUID};
1243 $self->pidl_def("/* Version information */\n\n");
1245 $self->pidl_def("static e_guid_t uuid_dcerpc_$x->{NAME} = {");
1246 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8)
1247 . ", 0x" . substr($if_uuid, 10, 4)
1248 . ", 0x" . substr($if_uuid, 15, 4) . ",");
1249 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2)
1250 . ", 0x" . substr($if_uuid, 22, 2)
1251 . ", 0x" . substr($if_uuid, 25, 2)
1252 . ", 0x" . substr($if_uuid, 27, 2)
1253 . ", 0x" . substr($if_uuid, 29, 2)
1254 . ", 0x" . substr($if_uuid, 31, 2)
1255 . ", 0x" . substr($if_uuid, 33, 2)
1256 . ", 0x" . substr($if_uuid, 35, 2) . " }");
1257 $self->pidl_def("};");
1259 my $maj = 0x0000FFFF & $x->{VERSION};
1260 $maj =~ s/\.(.*)$//g;
1261 $self->pidl_def("static uint16_t ver_dcerpc_$x->{NAME} = $maj;");
1262 $self->pidl_def("");
1265 $return_types{$x->{NAME}} = {};
1267 $self->Interface($x);
1268 $self->pidl_code("\n".DumpFunctionTable($x));
1270 foreach (sort(keys %{$return_types{$x->{NAME}}})) {
1271 my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}};
1272 my $dt = $self->find_type($type);
1273 $dt or die("Unable to find information about return type `$type'");
1274 $self->register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, $dt->{BASE_TYPE}, $dt->{VALSSTRING}, 0, "");
1275 $self->{hf_used}->{"hf_$x->{NAME}_$_"} = 1;
1278 $self->RegisterInterface($x);
1279 $self->RegisterInterfaceHandoff($x);
1281 if (exists ($self->{conformance}->{header})) {
1282 $self->pidl_hdr($self->{conformance}->{header});
1285 $self->pidl_hdr("#endif /* $define */");
1288 sub find_type($$)
1290 my ($self, $n) = @_;
1292 return $self->{conformance}->{types}->{$n};
1295 sub register_type($$$$$$$$)
1297 my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_;
1299 return if (defined($self->{conformance}->{types}->{$type}));
1301 $self->{conformance}->{types}->{$type} = {
1302 NAME => $type,
1303 DISSECTOR_NAME => $call,
1304 FT_TYPE => $ft,
1305 BASE_TYPE => $base,
1306 MASK => $mask,
1307 VALSSTRING => $vals,
1308 ALIGNMENT => $length
1312 # Loads the default types
1313 sub Initialize($$)
1315 my ($self, $cnf_file) = @_;
1317 $self->{conformance} = {
1318 imports => {},
1319 header_fields=> {}
1322 ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n";
1324 foreach my $bytes (qw(1 2 4 8)) {
1325 my $bits = $bytes * 8;
1326 $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits\_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
1327 $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits\_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
1330 $self->register_type("uint3264", "offset = PIDL_dissect_uint3264_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8);
1331 $self->register_type("hyper", "offset = PIDL_dissect_uint64_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8);
1332 $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@VALUEREF\@);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
1333 $self->register_type("bool8", "offset = PIDL_dissect_uint8_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1334 $self->register_type("char", "offset = PIDL_dissect_uint8_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
1335 $self->register_type("long", "offset = PIDL_dissect_uint32_val(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@, \@VALUEREF\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
1336 $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@VALUEREF\@);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
1337 $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
1338 $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);
1339 $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);
1340 $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);
1341 $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);
1342 $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);
1343 $self->register_type("dom_sid28",
1344 "offset = dissect_ndr_nt_SID28(tvb, offset, pinfo, tree, di, drep, \@HF\@);", "FT_STRING", "BASE_NONE", 0, "NULL", 4);
1345 $self->register_type("SID",
1346 "offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, di, drep, param, \@HF\@);","FT_STRING", "BASE_NONE", 0, "NULL", 4);
1347 $self->register_type("WERROR",
1348 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&WERR_errors_ext", 4);
1349 $self->register_type("NTSTATUS",
1350 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&NT_errors_ext", 4);
1351 $self->register_type("HRESULT",
1352 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_HEX|BASE_EXT_STRING", 0, "&HRES_errors_ext", 4);
1353 $self->register_type("ipv6address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 16, ENC_NA); offset += 16;", "FT_IPv6", "BASE_NONE", 0, "NULL", 16);
1354 $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);
1358 #####################################################################
1359 # Generate Wireshark parser and header code
1360 sub Parse($$$$$)
1362 my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_;
1364 $self->Initialize($cnf_file);
1366 return (undef, undef) if defined($self->{conformance}->{noemit_dissector});
1368 my $notice =
1369 "/* DO NOT EDIT
1370 This file was automatically generated by Pidl
1371 from $idl_file and $cnf_file.
1373 Pidl is a perl based IDL compiler for DCE/RPC idl files.
1374 It is maintained by the Samba team, not the Wireshark team.
1375 Instructions on how to download and install Pidl can be
1376 found at https://wiki.wireshark.org/Pidl
1381 $self->{res}->{headers} = "\n";
1382 $self->{res}->{headers} .= "#include \"config.h\"\n";
1384 $self->{res}->{headers} .= "#include <string.h>\n";
1385 $self->{res}->{headers} .= "#include <wsutil/array.h>\n";
1386 $self->{res}->{headers} .= "#include <epan/packet.h>\n";
1387 $self->{res}->{headers} .= "#include <epan/tfs.h>\n\n";
1389 $self->{res}->{headers} .= "#include \"packet-dcerpc.h\"\n";
1390 $self->{res}->{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
1391 $self->{res}->{headers} .= "#include \"packet-windows-common.h\"\n";
1393 my $h_basename = basename($h_filename);
1395 $self->{res}->{headers} .= "#include \"$h_basename\"\n";
1396 $self->pidl_code("");
1398 if (defined($self->{conformance}->{ett})) {
1399 register_ett($self,$_) foreach(@{$self->{conformance}->{ett}})
1402 # Wireshark protocol registration
1404 foreach (@$ndr) {
1405 $self->ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE");
1406 $self->ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT");
1407 $self->ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE");
1410 $self->{res}->{ett} = DumpEttDeclaration($self->{ett});
1411 $self->{res}->{hf} = $self->DumpHfDeclaration();
1413 my $parser = $notice;
1414 $parser.= $self->{res}->{headers};
1415 $parser.=$self->{res}->{ett};
1416 $parser.=$self->{res}->{hf};
1417 $parser.=$self->{res}->{def};
1418 if (exists ($self->{conformance}->{override})) {
1419 $parser.=$self->{conformance}->{override};
1421 $parser.=$self->{res}->{code};
1423 my $header = $notice;
1424 $header.=$self->{res}->{hdr};
1426 $self->CheckUsed($self->{conformance});
1428 return ($parser,$header);
1431 ###############################################################################
1432 # ETT
1433 ###############################################################################
1435 sub register_ett($$)
1437 my ($self, $name) = @_;
1439 push (@{$self->{ett}}, $name);
1442 sub DumpEttList
1444 my ($ett) = @_;
1445 my $res = "\tstatic int *ett[] = {\n";
1446 foreach (@$ett) {
1447 $res .= "\t\t&$_,\n";
1450 return "$res\t};\n";
1453 sub DumpEttDeclaration
1455 my ($ett) = @_;
1456 my $res = "\n/* Ett declarations */\n";
1457 foreach (@$ett) {
1458 $res .= "static int $_;\n";
1461 return "$res\n";
1464 ###############################################################################
1465 # HF
1466 ###############################################################################
1468 sub register_hf_field($$$$$$$$$)
1470 my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
1472 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1473 $self->{conformance}->{hf_renames}->{$index}->{USED} = 1;
1474 return $self->{conformance}->{hf_renames}->{$index}->{NEWNAME};
1477 $self->{conformance}->{header_fields}->{$index} = {
1478 INDEX => $index,
1479 NAME => $name,
1480 FILTER => $filter_name,
1481 FT_TYPE => $ft_type,
1482 BASE_TYPE => $base_type,
1483 VALSSTRING => $valsstring,
1484 MASK => $mask,
1485 BLURB => $blurb
1488 if ((not defined($blurb) or $blurb eq "") and
1489 defined($self->{conformance}->{fielddescription}->{$index})) {
1490 $self->{conformance}->{header_fields}->{$index}->{BLURB} =
1491 $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION};
1492 $self->{conformance}->{fielddescription}->{$index}->{USED} = 1;
1495 return $index;
1498 sub change_hf_field_type($$$$)
1500 my ($self,$index,$ft_type,$base_type) = @_;
1501 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1502 print "Field $index has been renamed to ".$self->{conformance}->{hf_renames}->{$index}->{NEWNAME}." you can't change it's type";
1503 return 0;
1506 if (!defined ($self->{conformance}->{header_fields}->{$index})) {
1507 print "Field $index doesn't exists";
1508 return 0;
1510 $self->{conformance}->{header_fields}->{$index}->{FT_TYPE} = $ft_type;
1511 $self->{conformance}->{header_fields}->{$index}->{BASE_TYPE} = $base_type;
1512 return 1;
1515 sub DumpHfDeclaration($)
1517 my ($self) = @_;
1518 my $res = "";
1520 $res = "\n/* Header field declarations */\n";
1522 foreach (sort(keys %{$self->{conformance}->{header_fields}}))
1524 $res .= "static int $_;\n";
1527 return "$res\n";
1530 sub make_str_or_null($)
1532 my $str = shift;
1533 if (substr($str, 0, 1) eq "\"") {
1534 $str = substr($str, 1, length($str)-2);
1536 $str =~ s/^\s*//;
1537 $str =~ s/\s*$//;
1538 if ($str eq "") {
1539 return "NULL";
1541 return make_str($str);
1544 sub DumpHfList($)
1546 my ($self) = @_;
1547 my $res = "\tstatic hf_register_info hf[] = {\n";
1549 foreach (sort {$a->{INDEX} cmp $b->{INDEX}} values %{$self->{conformance}->{header_fields}})
1551 $res .= "\t{ &$_->{INDEX},\n".
1552 "\t { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }},\n";
1555 return $res."\t};\n";
1559 ###############################################################################
1560 # Function table
1561 ###############################################################################
1563 sub DumpFunctionTable($)
1565 my $if = shift;
1567 my $res = "static const dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
1568 foreach (@{$if->{FUNCTIONS}}) {
1569 my $fn_name = $_->{NAME};
1570 $fn_name =~ s/^$if->{NAME}_//;
1571 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
1572 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
1575 $res .= "\t{ 0, NULL, NULL, NULL }\n";
1577 return "$res};\n";
1580 sub CheckUsed($$)
1582 my ($self, $conformance) = @_;
1583 foreach (values %{$conformance->{header_fields}}) {
1584 if (not defined($self->{hf_used}->{$_->{INDEX}})) {
1585 warning($_->{POS}, "hf field `$_->{INDEX}' not used");
1589 foreach (values %{$conformance->{hf_renames}}) {
1590 if (not $_->{USED}) {
1591 warning($_->{POS}, "hf field `$_->{OLDNAME}' not used");
1595 foreach (values %{$conformance->{dissectorparams}}) {
1596 if (not $_->{USED}) {
1597 warning($_->{POS}, "dissector param never used");
1601 foreach (values %{$conformance->{imports}}) {
1602 if (not $_->{USED}) {
1603 warning($_->{POS}, "import never used");
1607 foreach (values %{$conformance->{types}}) {
1608 if (not $_->{USED} and defined($_->{POS})) {
1609 warning($_->{POS}, "type never used");
1613 foreach (values %{$conformance->{fielddescription}}) {
1614 if (not $_->{USED}) {
1615 warning($_->{POS}, "description never used");
1619 foreach (values %{$conformance->{tfs}}) {
1620 if (not $_->{USED}) {
1621 warning($_->{POS}, "True/False description never used");