pidl: handle datablob for wireshark generator
[Samba/bjacke.git] / pidl / lib / Parse / Pidl / Wireshark / NDR.pm
blob8c236a6020e92adda1d8f7b627aff8473fd212cd
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 Parse::Pidl qw(error warning);
25 use Parse::Pidl::Typelist qw(getType);
26 use Parse::Pidl::Util qw(has_property property_matches make_str);
27 use Parse::Pidl::NDR qw(ContainsString GetNextLevel);
28 use Parse::Pidl::Dump qw(DumpType DumpFunction);
29 use Parse::Pidl::Wireshark::Conformance qw(ReadConformance);
30 use File::Basename;
32 use vars qw($VERSION);
33 $VERSION = '0.01';
35 my %return_types = ();
36 my %dissector_used = ();
38 my %ptrtype_mappings = (
39 "unique" => "NDR_POINTER_UNIQUE",
40 "ref" => "NDR_POINTER_REF",
41 "ptr" => "NDR_POINTER_PTR"
44 sub StripPrefixes($$)
46 my ($s, $prefixes) = @_;
48 foreach (@$prefixes) {
49 $s =~ s/^$_\_//g;
52 return $s;
55 # Convert a IDL structure field name (e.g access_mask) to a prettier
56 # string like 'Access Mask'.
58 sub field2name($)
60 my($field) = shift;
62 $field =~ s/_/ /g; # Replace underscores with spaces
63 $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word
65 return $field;
68 sub new($)
70 my ($class) = @_;
71 my $self = {res => {hdr => "", def => "", code => ""}, tabs => "", cur_fn => undef,
72 hf_used => {}, ett => [], conformance => undef
75 bless($self, $class);
78 sub pidl_fn_start($$)
80 my ($self, $fn) = @_;
81 $self->{cur_fn} = $fn;
83 sub pidl_fn_end($$)
85 my ($self, $fn) = @_;
86 die("Inconsistent state: $fn != $self->{cur_fn}") if ($fn ne $self->{cur_fn});
87 $self->{cur_fn} = undef;
90 sub pidl_code($$)
92 my ($self, $d) = @_;
93 return if (defined($self->{cur_fn}) and defined($self->{conformance}->{manual}->{$self->{cur_fn}}));
95 if ($d) {
96 $self->{res}->{code} .= $self->{tabs};
97 $self->{res}->{code} .= $d;
99 $self->{res}->{code} .="\n";
102 sub pidl_hdr($$) { my ($self,$x) = @_; $self->{res}->{hdr} .= "$x\n"; }
103 sub pidl_def($$) { my ($self,$x) = @_; $self->{res}->{def} .= "$x\n"; }
105 sub indent($)
107 my ($self) = @_;
108 $self->{tabs} .= "\t";
111 sub deindent($)
113 my ($self) = @_;
114 $self->{tabs} = substr($self->{tabs}, 0, -1);
117 sub PrintIdl($$)
119 my ($self, $idl) = @_;
121 foreach (split /\n/, $idl) {
122 $self->pidl_code("/* IDL: $_ */");
125 $self->pidl_code("");
128 #####################################################################
129 # parse the interface definitions
130 sub Interface($$)
132 my($self, $interface) = @_;
133 $self->Const($_,$interface->{NAME}) foreach (@{$interface->{CONSTS}});
134 $self->Type($_, $_->{NAME}, $interface->{NAME}) foreach (@{$interface->{TYPES}});
135 $self->Function($_,$interface->{NAME}) foreach (@{$interface->{FUNCTIONS}});
138 sub Enum($$$$)
140 my ($self, $e,$name,$ifname) = @_;
141 my $valsstring = "$ifname\_$name\_vals";
142 my $dissectorname = "$ifname\_dissect\_enum\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
144 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
146 foreach (@{$e->{ELEMENTS}}) {
147 if (/([^=]*)=(.*)/) {
148 $self->pidl_hdr("#define $1 ($2)");
152 $self->pidl_hdr("extern const value_string $valsstring\[];");
153 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_);");
155 $self->pidl_def("const value_string ".$valsstring."[] = {");
156 foreach (@{$e->{ELEMENTS}}) {
157 next unless (/([^=]*)=(.*)/);
158 $self->pidl_def("\t{ $1, \"$1\" },");
161 $self->pidl_def("{ 0, NULL }");
162 $self->pidl_def("};");
164 $self->pidl_fn_start($dissectorname);
165 $self->pidl_code("int");
166 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 *param _U_)");
167 $self->pidl_code("{");
168 $self->indent;
169 $self->pidl_code("g$e->{BASE_TYPE} parameter=0;");
170 $self->pidl_code("if(param){");
171 $self->indent;
172 $self->pidl_code("parameter=(g$e->{BASE_TYPE})*param;");
173 $self->deindent;
174 $self->pidl_code("}");
175 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, &parameter);");
176 $self->pidl_code("if(param){");
177 $self->indent;
178 $self->pidl_code("*param=(guint32)parameter;");
179 $self->deindent;
180 $self->pidl_code("}");
181 $self->pidl_code("return offset;");
182 $self->deindent;
183 $self->pidl_code("}\n");
184 $self->pidl_fn_end($dissectorname);
186 my $enum_size = $e->{BASE_TYPE};
187 $enum_size =~ s/uint//g;
188 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8);
191 sub Bitmap($$$$)
193 my ($self,$e,$name,$ifname) = @_;
194 my $dissectorname = "$ifname\_dissect\_bitmap\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
196 $self->register_ett("ett_$ifname\_$name");
198 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);");
200 $self->pidl_fn_start($dissectorname);
201 $self->pidl_code("int");
202 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)");
203 $self->pidl_code("{");
204 $self->indent;
205 $self->pidl_code("proto_item *item = NULL;");
206 $self->pidl_code("proto_tree *tree = NULL;");
207 $self->pidl_code("");
209 $self->pidl_code("g$e->{BASE_TYPE} flags;");
210 if ($e->{ALIGN} > 1) {
211 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
214 $self->pidl_code("");
216 $self->pidl_code("if (parent_tree) {");
217 $self->indent;
218 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);");
219 $self->pidl_code("tree = proto_item_add_subtree(item,ett_$ifname\_$name);");
220 $self->deindent;
221 $self->pidl_code("}\n");
223 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, NULL, drep, -1, &flags);");
225 $self->pidl_code("proto_item_append_text(item, \": \");\n");
226 $self->pidl_code("if (!flags)");
227 $self->pidl_code("\tproto_item_append_text(item, \"(No values set)\");\n");
229 foreach (@{$e->{ELEMENTS}}) {
230 next unless (/([^ ]*) (.*)/);
231 my ($en,$ev) = ($1,$2);
232 my $hf_bitname = "hf_$ifname\_$name\_$en";
233 my $filtername = "$ifname\.$name\.$en";
235 $self->{hf_used}->{$hf_bitname} = 1;
237 $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
239 $self->pidl_def("static const true_false_string $name\_$en\_tfs = {");
240 if (defined($self->{conformance}->{tfs}->{$hf_bitname})) {
241 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{TRUE_STRING},");
242 $self->pidl_def(" $self->{conformance}->{tfs}->{$hf_bitname}->{FALSE_STRING},");
243 $self->{conformance}->{tfs}->{$hf_bitname}->{USED} = 1;
244 } else {
245 $self->pidl_def(" \"$en is SET\",");
246 $self->pidl_def(" \"$en is NOT SET\",");
248 $self->pidl_def("};");
250 $self->pidl_code("proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);");
251 $self->pidl_code("if (flags&$ev){");
252 $self->pidl_code("\tproto_item_append_text(item, \"$en\");");
253 $self->pidl_code("\tif (flags & (~$ev))");
254 $self->pidl_code("\t\tproto_item_append_text(item, \", \");");
255 $self->pidl_code("}");
256 $self->pidl_code("flags&=(~$ev);");
257 $self->pidl_code("");
260 $self->pidl_code("if (flags) {");
261 $self->pidl_code("\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);");
262 $self->pidl_code("}\n");
263 $self->pidl_code("return offset;");
264 $self->deindent;
265 $self->pidl_code("}\n");
266 $self->pidl_fn_end($dissectorname);
268 my $size = $e->{BASE_TYPE};
269 $size =~ s/uint//g;
270 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
273 sub ElementLevel($$$$$$$)
275 my ($self,$e,$l,$hf,$myname,$pn,$ifname) = @_;
277 my $param = 0;
279 if (defined($self->{conformance}->{dissectorparams}->{$myname})) {
280 $param = $self->{conformance}->{dissectorparams}->{$myname}->{PARAM};
283 if ($l->{TYPE} eq "POINTER") {
284 my $type;
285 if ($l->{LEVEL} eq "TOP") {
286 $type = "toplevel";
287 } elsif ($l->{LEVEL} eq "EMBEDDED") {
288 $type = "embedded";
290 $self->pidl_code("offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes})) . " ($e->{TYPE})\",$hf);");
291 } elsif ($l->{TYPE} eq "ARRAY") {
292 if ($l->{IS_INLINE}) {
293 error($e->{ORIGINAL}, "Inline arrays not supported");
294 } elsif ($l->{IS_FIXED}) {
295 $self->pidl_code("int i;");
296 $self->pidl_code("for (i = 0; i < $l->{SIZE_IS}; i++)");
297 $self->pidl_code("\toffset = $myname\_(tvb, offset, pinfo, tree, drep);");
298 } else {
299 my $type = "";
300 $type .= "c" if ($l->{IS_CONFORMANT});
301 $type .= "v" if ($l->{IS_VARYING});
303 unless ($l->{IS_ZERO_TERMINATED}) {
304 $self->pidl_code("offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);");
305 } else {
306 my $nl = GetNextLevel($e,$l);
307 $self->pidl_code("char *data;");
308 $self->pidl_code("");
309 $self->pidl_code("offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);");
310 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
313 } elsif ($l->{TYPE} eq "DATA") {
314 if ($l->{DATA_TYPE} eq "string") {
315 my $bs = 2; # Byte size defaults to that of UCS2
318 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
320 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
321 $self->pidl_code("char *data;\n");
322 $self->pidl_code("offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);");
323 $self->pidl_code("proto_item_append_text(tree, \": %s\", data);");
324 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
325 $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);");
326 } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) {
327 if ($bs == 2) {
328 $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);")
329 } else {
330 $self->pidl_code("offset = dissect_null_term_string(tvb, offset, pinfo, tree, drep, $hf , 0);")
332 } else {
333 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
335 } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") {
336 my $remain = 0;
337 $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*"));
338 $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, drep, $hf, $remain);");
339 } else {
340 my $call;
342 if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) {
343 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA};
344 $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
345 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) {
346 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA};
347 $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
349 } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) {
350 $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
351 $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
352 } else {
353 $self->pidl_code("offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);");
355 return;
358 $call =~ s/\@HF\@/$hf/g;
359 $call =~ s/\@PARAM\@/$param/g;
360 $self->pidl_code($call);
362 } elsif ($_->{TYPE} eq "SUBCONTEXT") {
363 my $num_bits = ($l->{HEADER_SIZE}*8);
364 $self->pidl_code("guint$num_bits size;");
365 $self->pidl_code("int start_offset = offset;");
366 $self->pidl_code("tvbuff_t *subtvb;");
367 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);");
368 $self->pidl_code("proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");");
370 $self->pidl_code("subtvb = tvb_new_subset(tvb, offset, size, -1);");
371 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);");
372 } else {
373 die("Unknown type `$_->{TYPE}'");
377 sub Element($$$)
379 my ($self,$e,$pn,$ifname) = @_;
381 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes});
383 my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);";
385 my $type = $self->find_type($e->{TYPE});
387 if (not defined($type)) {
388 # default settings
389 $type = {
390 MASK => 0,
391 VALSSTRING => "NULL",
392 FT_TYPE => "FT_NONE",
393 BASE_TYPE => "BASE_NONE"
397 if (ContainsString($e)) {
398 $type = {
399 MASK => 0,
400 VALSSTRING => "NULL",
401 FT_TYPE => "FT_STRING",
402 BASE_TYPE => "BASE_NONE"
406 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}, "");
407 $self->{hf_used}->{$hf} = 1;
409 my $eltname = StripPrefixes($pn, $self->{conformance}->{strip_prefixes}) . ".$e->{NAME}";
410 if (defined($self->{conformance}->{noemit}->{$eltname})) {
411 return $call_code;
414 my $add = "";
416 foreach (@{$e->{LEVELS}}) {
417 next if ($_->{TYPE} eq "SWITCH");
418 $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_);");
419 $self->pidl_fn_start("$dissectorname$add");
420 $self->pidl_code("static int");
421 $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)");
422 $self->pidl_code("{");
423 $self->indent;
425 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname);
427 $self->pidl_code("");
428 $self->pidl_code("return offset;");
429 $self->deindent;
430 $self->pidl_code("}\n");
431 $self->pidl_fn_end("$dissectorname$add");
432 $add.="_";
433 last if ($_->{TYPE} eq "ARRAY" and $_->{IS_ZERO_TERMINATED});
436 return $call_code;
439 sub Function($$$)
441 my ($self, $fn,$ifname) = @_;
443 my %dissectornames;
445 foreach (@{$fn->{ELEMENTS}}) {
446 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname) if not defined($dissectornames{$_->{NAME}});
449 my $fn_name = $_->{NAME};
450 $fn_name =~ s/^${ifname}_//;
452 $self->PrintIdl(DumpFunction($fn->{ORIGINAL}));
453 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_response");
454 $self->pidl_code("static int");
455 $self->pidl_code("$ifname\_dissect\_${fn_name}_response(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)");
456 $self->pidl_code("{");
457 $self->indent;
458 if ( not defined($fn->{RETURN_TYPE})) {
459 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR")
461 $self->pidl_code("guint32 status;\n");
462 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
463 if ($type->{DATA}->{TYPE} eq "ENUM") {
464 $self->pidl_code("g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA}) . " status;\n");
465 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
466 $self->pidl_code("g$fn->{RETURN_TYPE} status;\n");
467 } else {
468 error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported");
470 } else {
471 error($fn, "unknown return type `$fn->{RETURN_TYPE}'");
474 $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";");
475 foreach (@{$fn->{ELEMENTS}}) {
476 if (grep(/out/,@{$_->{DIRECTION}})) {
477 $self->pidl_code("$dissectornames{$_->{NAME}}");
478 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);");
479 $self->pidl_code("");
483 if (not defined($fn->{RETURN_TYPE})) {
484 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") {
485 $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n");
486 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");
487 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n");
488 $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"];
489 } elsif ($fn->{RETURN_TYPE} eq "WERROR") {
490 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n");
491 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");
492 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n");
494 $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"];
495 } elsif (my $type = getType($fn->{RETURN_TYPE})) {
496 if ($type->{DATA}->{TYPE} eq "ENUM") {
497 my $return_type = "g".Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
498 my $return_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($type->{DATA});
500 $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
501 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");
502 $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");
503 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
504 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") {
505 $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);");
506 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");
507 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n");
508 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}];
512 $self->pidl_code("return offset;");
513 $self->deindent;
514 $self->pidl_code("}\n");
515 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_response");
517 $self->pidl_fn_start("$ifname\_dissect\_$fn_name\_request");
518 $self->pidl_code("static int");
519 $self->pidl_code("$ifname\_dissect\_${fn_name}_request(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)");
520 $self->pidl_code("{");
521 $self->indent;
522 $self->pidl_code("pinfo->dcerpc_procedure_name=\"${fn_name}\";");
523 foreach (@{$fn->{ELEMENTS}}) {
524 if (grep(/in/,@{$_->{DIRECTION}})) {
525 $self->pidl_code("$dissectornames{$_->{NAME}}");
526 $self->pidl_code("offset = dissect_deferred_pointers(pinfo, tvb, offset, drep);");
531 $self->pidl_code("return offset;");
532 $self->deindent;
533 $self->pidl_code("}\n");
534 $self->pidl_fn_end("$ifname\_dissect\_$fn_name\_request");
537 sub Struct($$$$)
539 my ($self,$e,$name,$ifname) = @_;
540 my $dissectorname = "$ifname\_dissect\_struct\_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
542 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
544 $self->register_ett("ett_$ifname\_$name");
546 my $res = "";
547 ($res.="\t".$self->Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}});
549 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);");
551 $self->pidl_fn_start($dissectorname);
552 $self->pidl_code("int");
553 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)");
554 $self->pidl_code("{");
555 $self->indent;
556 $self->pidl_code("proto_item *item = NULL;");
557 $self->pidl_code("proto_tree *tree = NULL;");
558 if ($e->{ALIGN} > 1) {
559 $self->pidl_code("dcerpc_info *di = pinfo->private_data;");
561 $self->pidl_code("int old_offset;");
562 $self->pidl_code("");
564 if ($e->{ALIGN} > 1) {
565 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
567 $self->pidl_code("");
569 $self->pidl_code("old_offset = offset;");
570 $self->pidl_code("");
571 $self->pidl_code("if (parent_tree) {");
572 $self->indent;
573 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);");
574 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
575 $self->deindent;
576 $self->pidl_code("}");
578 $self->pidl_code("\n$res");
580 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
581 if ($e->{ALIGN} > 1) {
582 $self->pidl_code("");
583 $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
584 $self->indent;
585 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
586 $self->deindent;
587 $self->pidl_code("}");
589 $self->pidl_code("");
590 $self->pidl_code("return offset;");
591 $self->deindent;
592 $self->pidl_code("}\n");
593 $self->pidl_fn_end($dissectorname);
595 $self->register_type($name, "offset = $dissectorname(tvb,offset,pinfo,tree,drep,\@HF\@,\@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
598 sub Union($$$$)
600 my ($self,$e,$name,$ifname) = @_;
602 my $dissectorname = "$ifname\_dissect_".StripPrefixes($name, $self->{conformance}->{strip_prefixes});
604 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})}));
606 $self->register_ett("ett_$ifname\_$name");
608 my $res = "";
609 foreach (@{$e->{ELEMENTS}}) {
610 $res.="\n\t\t$_->{CASE}:\n";
611 if ($_->{TYPE} ne "EMPTY") {
612 $res.="\t\t\t".$self->Element($_, $name, $ifname)."\n";
614 $res.="\t\tbreak;\n";
617 my $switch_type;
618 my $switch_dissect;
619 my $switch_dt = getType($e->{SWITCH_TYPE});
620 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") {
621 $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
622 $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA});
623 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") {
624 $switch_type = "g$e->{SWITCH_TYPE}";
625 $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}";
628 $self->pidl_fn_start($dissectorname);
629 $self->pidl_code("static int");
630 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_)");
631 $self->pidl_code("{");
632 $self->indent;
633 $self->pidl_code("proto_item *item = NULL;");
634 $self->pidl_code("proto_tree *tree = NULL;");
635 $self->pidl_code("int old_offset;");
636 $self->pidl_code("$switch_type level;");
637 $self->pidl_code("");
639 $self->pidl_code("old_offset = offset;");
640 $self->pidl_code("if (parent_tree) {");
641 $self->indent;
642 $self->pidl_code("item = proto_tree_add_text(parent_tree, tvb, offset, -1, \"$name\");");
643 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);");
644 $self->deindent;
645 $self->pidl_code("}");
647 $self->pidl_code("");
649 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);");
651 if ($e->{ALIGN} > 1) {
652 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
653 $self->pidl_code("");
657 $self->pidl_code("switch(level) {$res\t}");
658 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
659 $self->pidl_code("");
661 $self->pidl_code("return offset;");
662 $self->deindent;
663 $self->pidl_code("}");
664 $self->pidl_fn_end($dissectorname);
666 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_NONE", "BASE_NONE", 0, "NULL", 0);
669 sub Const($$$)
671 my ($self,$const,$ifname) = @_;
673 if (!defined($const->{ARRAY_LEN}[0])) {
674 $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n");
675 } else {
676 $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n");
680 sub Typedef($$$$)
682 my ($self,$e,$name,$ifname) = @_;
684 $self->Type($e->{DATA}, $name, $ifname);
687 sub Type($$$$)
689 my ($self, $e, $name, $ifname) = @_;
691 $self->PrintIdl(DumpType($e->{ORIGINAL}));
694 ENUM => \&Enum,
695 STRUCT => \&Struct,
696 UNION => \&Union,
697 BITMAP => \&Bitmap,
698 TYPEDEF => \&Typedef
699 }->{$e->{TYPE}}->($self, $e, $name, $ifname);
702 sub RegisterInterface($$)
704 my ($self, $x) = @_;
706 $self->pidl_fn_start("proto_register_dcerpc_$x->{NAME}");
707 $self->pidl_code("void proto_register_dcerpc_$x->{NAME}(void)");
708 $self->pidl_code("{");
709 $self->indent;
711 $self->{res}->{code}.=$self->DumpHfList()."\n";
712 $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n";
714 if (defined($x->{UUID})) {
715 # These can be changed to non-pidl_code names if the old dissectors
716 # in epan/dissctors are deleted.
718 my $name = uc($x->{NAME}) . " (pidl)";
719 my $short_name = uc($x->{NAME});
720 my $filter_name = $x->{NAME};
722 if (has_property($x, "helpstring")) {
723 $name = $x->{PROPERTIES}->{helpstring};
726 if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) {
727 $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME};
728 $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME};
729 $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME};
732 $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");");
734 $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));");
735 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
736 } else {
737 $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");");
738 $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));");
739 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));");
742 $self->deindent;
743 $self->pidl_code("}\n");
744 $self->pidl_fn_end("proto_register_dcerpc_$x->{NAME}");
747 sub RegisterInterfaceHandoff($$)
749 my ($self,$x) = @_;
751 if (defined($x->{UUID})) {
752 $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}");
753 $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)");
754 $self->pidl_code("{");
755 $self->indent;
756 $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},");
757 $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},");
758 $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);");
759 $self->deindent;
760 $self->pidl_code("}");
761 $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}");
763 $self->{hf_used}->{"hf_$x->{NAME}_opnum"} = 1;
767 sub ProcessInclude
769 my $self = shift;
770 my @includes = @_;
771 foreach (@includes) {
772 $self->pidl_hdr("#include \"$_\"");
774 $self->pidl_hdr("");
777 sub ProcessImport
779 my $self = shift;
780 my @imports = @_;
781 foreach (@imports) {
782 next if($_ eq "security");
783 s/^\"//;
784 s/\.idl"?$//;
785 $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\"");
787 $self->pidl_hdr("");
790 sub ProcessInterface($$)
792 my ($self, $x) = @_;
794 push(@{$self->{conformance}->{strip_prefixes}}, $x->{NAME});
796 my $define = "__PACKET_DCERPC_" . uc($_->{NAME}) . "_H";
797 $self->pidl_hdr("#ifndef $define");
798 $self->pidl_hdr("#define $define");
799 $self->pidl_hdr("");
801 $self->pidl_def("static gint proto_dcerpc_$x->{NAME} = -1;");
802 $self->register_ett("ett_dcerpc_$x->{NAME}");
803 $self->register_hf_field("hf_$x->{NAME}_opnum", "Operation", "$x->{NAME}.opnum", "FT_UINT16", "BASE_DEC", "NULL", 0, "");
805 if (defined($x->{UUID})) {
806 my $if_uuid = $x->{UUID};
808 $self->pidl_def("/* Version information */\n\n");
810 $self->pidl_def("static e_uuid_t uuid_dcerpc_$x->{NAME} = {");
811 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8)
812 . ", 0x" . substr($if_uuid, 10, 4)
813 . ", 0x" . substr($if_uuid, 15, 4) . ",");
814 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2)
815 . ", 0x" . substr($if_uuid, 22, 2)
816 . ", 0x" . substr($if_uuid, 25, 2)
817 . ", 0x" . substr($if_uuid, 27, 2)
818 . ", 0x" . substr($if_uuid, 29, 2)
819 . ", 0x" . substr($if_uuid, 31, 2)
820 . ", 0x" . substr($if_uuid, 33, 2)
821 . ", 0x" . substr($if_uuid, 35, 2) . " }");
822 $self->pidl_def("};");
824 my $maj = $x->{VERSION};
825 $maj =~ s/\.(.*)$//g;
826 $self->pidl_def("static guint32 ver_dcerpc_$x->{NAME} = $maj;");
827 $self->pidl_def("");
830 $return_types{$x->{NAME}} = {};
832 $self->Interface($x);
834 $self->pidl_code("\n".DumpFunctionTable($x));
836 foreach (keys %{$return_types{$x->{NAME}}}) {
837 my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}};
838 my $dt = $self->find_type($type);
839 $dt or die("Unable to find information about return type `$type'");
840 $self->register_hf_field("hf_$x->{NAME}_$_", $desc, "$x->{NAME}.$_", $dt->{FT_TYPE}, "BASE_HEX", $dt->{VALSSTRING}, 0, "");
841 $self->{hf_used}->{"hf_$x->{NAME}_$_"} = 1;
844 $self->RegisterInterface($x);
845 $self->RegisterInterfaceHandoff($x);
847 $self->pidl_hdr("#endif /* $define */");
850 sub find_type($$)
852 my ($self, $n) = @_;
854 return $self->{conformance}->{types}->{$n};
857 sub register_type($$$$$$$$)
859 my ($self, $type,$call,$ft,$base,$mask,$vals,$length) = @_;
861 return if (defined($self->{conformance}->{types}->{$type}));
863 $self->{conformance}->{types}->{$type} = {
864 NAME => $type,
865 DISSECTOR_NAME => $call,
866 FT_TYPE => $ft,
867 BASE_TYPE => $base,
868 MASK => $mask,
869 VALSSTRING => $vals,
870 ALIGNMENT => $length
874 # Loads the default types
875 sub Initialize($$)
877 my ($self, $cnf_file) = @_;
879 $self->{conformance} = {
880 imports => {},
881 header_fields=> {}
884 ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n";
886 foreach my $bytes (qw(1 2 4 8)) {
887 my $bits = $bytes * 8;
888 $self->register_type("uint$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$bits", "BASE_DEC", 0, "NULL", $bytes);
889 $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes);
892 $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
893 $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
894 $self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
895 $self->register_type("long", "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT32", "BASE_DEC", 0, "NULL", 4);
896 $self->register_type("dlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_INT64", "BASE_DEC", 0, "NULL", 8);
897 $self->register_type("GUID", "offset = dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);","FT_GUID", "BASE_NONE", 0, "NULL", 4);
898 $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4);
899 $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
900 $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
901 $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
902 $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4);
903 $self->register_type("SID", "
904 dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
906 di->hf_index = \@HF\@;
908 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
909 ","FT_STRING", "BASE_NONE", 0, "NULL", 4);
910 $self->register_type("WERROR",
911 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4);
912 $self->register_type("NTSTATUS",
913 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4);
917 #####################################################################
918 # Generate Wireshark parser and header code
919 sub Parse($$$$$)
921 my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_;
923 $self->Initialize($cnf_file);
925 return (undef, undef) if defined($self->{conformance}->{noemit_dissector});
927 my $notice =
928 "/* DO NOT EDIT
929 This filter was automatically generated
930 from $idl_file and $cnf_file.
932 Pidl is a perl based IDL compiler for DCE/RPC idl files.
933 It is maintained by the Samba team, not the Wireshark team.
934 Instructions on how to download and install Pidl can be
935 found at http://wiki.wireshark.org/Pidl
940 $self->pidl_hdr($notice);
942 $self->{res}->{headers} = "\n";
943 $self->{res}->{headers} .= "#ifdef HAVE_CONFIG_H\n";
944 $self->{res}->{headers} .= "#include \"config.h\"\n";
945 $self->{res}->{headers} .= "#endif\n\n";
947 $self->{res}->{headers} .= "#ifdef _MSC_VER\n";
948 $self->{res}->{headers} .= "#pragma warning(disable:4005)\n";
949 $self->{res}->{headers} .= "#pragma warning(disable:4013)\n";
950 $self->{res}->{headers} .= "#pragma warning(disable:4018)\n";
951 $self->{res}->{headers} .= "#pragma warning(disable:4101)\n";
952 $self->{res}->{headers} .= "#endif\n\n";
954 $self->{res}->{headers} .= "#include <glib.h>\n";
955 $self->{res}->{headers} .= "#include <string.h>\n";
956 $self->{res}->{headers} .= "#include <epan/packet.h>\n\n";
958 $self->{res}->{headers} .= "#include \"packet-dcerpc.h\"\n";
959 $self->{res}->{headers} .= "#include \"packet-dcerpc-nt.h\"\n";
960 $self->{res}->{headers} .= "#include \"packet-windows-common.h\"\n";
962 my $h_basename = basename($h_filename);
964 $self->{res}->{headers} .= "#include \"$h_basename\"\n";
965 $self->pidl_code("");
967 if (defined($self->{conformance}->{ett})) {
968 register_ett($self,$_) foreach(@{$self->{conformance}->{ett}})
971 # Wireshark protocol registration
973 foreach (@$ndr) {
974 $self->ProcessInterface($_) if ($_->{TYPE} eq "INTERFACE");
975 $self->ProcessImport(@{$_->{PATHS}}) if ($_->{TYPE} eq "IMPORT");
976 $self->ProcessInclude(@{$_->{PATHS}}) if ($_->{TYPE} eq "INCLUDE");
979 $self->{res}->{ett} = DumpEttDeclaration($self->{ett});
980 $self->{res}->{hf} = $self->DumpHfDeclaration();
982 my $parser = $notice;
983 $parser.= $self->{res}->{headers};
984 $parser.=$self->{res}->{ett};
985 $parser.=$self->{res}->{hf};
986 $parser.=$self->{res}->{def};
987 if (exists ($self->{conformance}->{override})) {
988 $parser.=$self->{conformance}->{override};
990 $parser.=$self->{res}->{code};
992 my $header = "/* autogenerated by pidl */\n\n";
993 $header.=$self->{res}->{hdr};
995 $self->CheckUsed($self->{conformance});
997 return ($parser,$header);
1000 ###############################################################################
1001 # ETT
1002 ###############################################################################
1004 sub register_ett($$)
1006 my ($self, $name) = @_;
1008 push (@{$self->{ett}}, $name);
1011 sub DumpEttList
1013 my ($ett) = @_;
1014 my $res = "\tstatic gint *ett[] = {\n";
1015 foreach (@$ett) {
1016 $res .= "\t\t&$_,\n";
1019 return "$res\t};\n";
1022 sub DumpEttDeclaration
1024 my ($ett) = @_;
1025 my $res = "\n/* Ett declarations */\n";
1026 foreach (@$ett) {
1027 $res .= "static gint $_ = -1;\n";
1030 return "$res\n";
1033 ###############################################################################
1034 # HF
1035 ###############################################################################
1037 sub register_hf_field($$$$$$$$$)
1039 my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_;
1041 if (defined ($self->{conformance}->{hf_renames}->{$index})) {
1042 $self->{conformance}->{hf_renames}->{$index}->{USED} = 1;
1043 return $self->{conformance}->{hf_renames}->{$index}->{NEWNAME};
1046 $self->{conformance}->{header_fields}->{$index} = {
1047 INDEX => $index,
1048 NAME => $name,
1049 FILTER => $filter_name,
1050 FT_TYPE => $ft_type,
1051 BASE_TYPE => $base_type,
1052 VALSSTRING => $valsstring,
1053 MASK => $mask,
1054 BLURB => $blurb
1057 if ((not defined($blurb) or $blurb eq "") and
1058 defined($self->{conformance}->{fielddescription}->{$index})) {
1059 $self->{conformance}->{header_fields}->{$index}->{BLURB} =
1060 $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION};
1061 $self->{conformance}->{fielddescription}->{$index}->{USED} = 1;
1064 return $index;
1067 sub DumpHfDeclaration($)
1069 my ($self) = @_;
1070 my $res = "";
1072 $res = "\n/* Header field declarations */\n";
1074 foreach (keys %{$self->{conformance}->{header_fields}})
1076 $res .= "static gint $_ = -1;\n";
1079 return "$res\n";
1082 sub make_str_or_null($)
1084 my $str = shift;
1085 if (substr($str, 0, 1) eq "\"") {
1086 $str = substr($str, 1, length($str)-2);
1088 $str =~ s/^\s*//;
1089 $str =~ s/\s*$//;
1090 if ($str eq "") {
1091 return "NULL";
1093 return make_str($str);
1096 sub DumpHfList($)
1098 my ($self) = @_;
1099 my $res = "\tstatic hf_register_info hf[] = {\n";
1101 foreach (values %{$self->{conformance}->{header_fields}})
1103 $res .= "\t{ &$_->{INDEX},
1104 { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }},
1108 return $res."\t};\n";
1112 ###############################################################################
1113 # Function table
1114 ###############################################################################
1116 sub DumpFunctionTable($)
1118 my $if = shift;
1120 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n";
1121 foreach (@{$if->{FUNCTIONS}}) {
1122 my $fn_name = $_->{NAME};
1123 $fn_name =~ s/^$if->{NAME}_//;
1124 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n";
1125 $res.= "\t $if->{NAME}_dissect_${fn_name}_request, $if->{NAME}_dissect_${fn_name}_response},\n";
1128 $res .= "\t{ 0, NULL, NULL, NULL }\n";
1130 return "$res};\n";
1133 sub CheckUsed($$)
1135 my ($self, $conformance) = @_;
1136 foreach (values %{$conformance->{header_fields}}) {
1137 if (not defined($self->{hf_used}->{$_->{INDEX}})) {
1138 warning($_->{POS}, "hf field `$_->{INDEX}' not used");
1142 foreach (values %{$conformance->{hf_renames}}) {
1143 if (not $_->{USED}) {
1144 warning($_->{POS}, "hf field `$_->{OLDNAME}' not used");
1148 foreach (values %{$conformance->{dissectorparams}}) {
1149 if (not $_->{USED}) {
1150 warning($_->{POS}, "dissector param never used");
1154 foreach (values %{$conformance->{imports}}) {
1155 if (not $_->{USED}) {
1156 warning($_->{POS}, "import never used");
1160 foreach (values %{$conformance->{types}}) {
1161 if (not $_->{USED} and defined($_->{POS})) {
1162 warning($_->{POS}, "type never used");
1166 foreach (values %{$conformance->{fielddescription}}) {
1167 if (not $_->{USED}) {
1168 warning($_->{POS}, "description never used");
1172 foreach (values %{$conformance->{tfs}}) {
1173 if (not $_->{USED}) {
1174 warning($_->{POS}, "True/False description never used");