Parse-Pidl
view release on metacpan or search on metacpan
lib/Parse/Pidl/Ethereal/NDR.pm view on Meta::CPAN
pidl_code "\tproto_item_append_text(item, \"(No values set)\");\n";
foreach (@{$e->{ELEMENTS}}) {
next unless (/([^ ]*) (.*)/);
my ($en,$ev) = ($1,$2);
my $hf_bitname = "hf_$ifname\_$name\_$en";
my $filtername = "$ifname\.$name\.$en";
$hf_used{$hf_bitname} = 1;
register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, "");
pidl_def "static const true_false_string $name\_$en\_tfs = {";
if (defined($conformance->{tfs}->{$hf_bitname})) {
pidl_def " $conformance->{tfs}->{$hf_bitname}->{TRUE_STRING},";
pidl_def " $conformance->{tfs}->{$hf_bitname}->{FALSE_STRING},";
$conformance->{tfs}->{$hf_bitname}->{USED} = 1;
} else {
pidl_def " \"$en is SET\",";
pidl_def " \"$en is NOT SET\",";
}
pidl_def "};";
pidl_code "proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);";
pidl_code "if (flags&$ev){";
pidl_code "\tproto_item_append_text(item, \"$en\");";
pidl_code "\tif (flags & (~$ev))";
pidl_code "\t\tproto_item_append_text(item, \", \");";
pidl_code "}";
pidl_code "flags&=(~$ev);";
pidl_code "";
}
pidl_code "if(flags){";
pidl_code "\tproto_item_append_text(item, \"Unknown bitmap value 0x%x\", flags);";
pidl_code "}\n";
pidl_code "return offset;";
deindent;
pidl_code "}\n";
my $size = $e->{BASE_TYPE};
$size =~ s/uint//g;
register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$size", "BASE_HEX", "0", "NULL", $size/8);
}
sub ElementLevel($$$$$)
{
my ($e,$l,$hf,$myname,$pn) = @_;
my $param = 0;
if (defined($conformance->{dissectorparams}->{$myname})) {
$conformance->{dissectorparams}->{$myname}->{PARAM} = 1;
$param = $conformance->{dissectorparams}->{$myname}->{PARAM};
}
if ($l->{TYPE} eq "POINTER") {
my $type;
if ($l->{LEVEL} eq "TOP") {
$type = "toplevel";
} elsif ($l->{LEVEL} eq "EMBEDDED") {
$type = "embedded";
}
pidl_code "offset = dissect_ndr_$type\_pointer(tvb, offset, pinfo, tree, drep, $myname\_, $ptrtype_mappings{$l->{POINTER_TYPE}}, \"Pointer to ".field2name(StripPrefixes($e->{NAME})) . " ($e->{TYPE})\",$hf);";
} elsif ($l->{TYPE} eq "ARRAY") {
if ($l->{IS_INLINE}) {
error($e->{ORIGINAL}, "Inline arrays not supported");
} elsif ($l->{IS_FIXED}) {
pidl_code "int i;";
pidl_code "for (i = 0; i < $l->{SIZE_IS}; i++)";
pidl_code "\toffset = $myname\_(tvb, offset, pinfo, tree, drep);";
} else {
my $type = "";
$type .= "c" if ($l->{IS_CONFORMANT});
$type .= "v" if ($l->{IS_VARYING});
unless ($l->{IS_ZERO_TERMINATED}) {
pidl_code "offset = dissect_ndr_u" . $type . "array(tvb, offset, pinfo, tree, drep, $myname\_);";
} else {
my $nl = GetNextLevel($e,$l);
pidl_code "char *data;";
pidl_code "";
pidl_code "offset = dissect_ndr_$type" . "string(tvb, offset, pinfo, tree, drep, sizeof(g$nl->{DATA_TYPE}), $hf, FALSE, &data);";
pidl_code "proto_item_append_text(tree, \": %s\", data);";
}
}
} elsif ($l->{TYPE} eq "DATA") {
if ($l->{DATA_TYPE} eq "string") {
my $bs = 2; # Byte size defaults to that of UCS2
($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*"));
if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) {
pidl_code "char *data;\n";
pidl_code "offset = dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, &data);";
pidl_code "proto_item_append_text(tree, \": %s\", data);";
} elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) {
pidl_code "offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);";
} else {
warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}");
}
} else {
my $call;
if ($conformance->{imports}->{$l->{DATA_TYPE}}) {
$call = $conformance->{imports}->{$l->{DATA_TYPE}}->{DATA};
$conformance->{imports}->{$l->{DATA_TYPE}}->{USED} = 1;
} elsif (defined($conformance->{imports}->{"$pn.$e->{NAME}"})) {
$call = $conformance->{imports}->{"$pn.$e->{NAME}"}->{DATA};
$conformance->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1;
} elsif (defined($conformance->{types}->{$l->{DATA_TYPE}})) {
$call= $conformance->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME};
$conformance->{types}->{$l->{DATA_TYPE}}->{USED} = 1;
} else {
if ($l->{DATA_TYPE} =~ /^([a-z]+)\_(.*)$/)
{
pidl_code "offset = $1_dissect_struct_$2(tvb,offset,pinfo,tree,drep,$hf,$param);";
}
( run in 0.639 second using v1.01-cache-2.11-cpan-71847e10f99 )