1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-18 17:57:55 +03:00

Don't pass down drep (data representation) arg from top level fn.

Decided to use tridge's PARSE_SCALARS and PARSE_BUFFERS pattern for
generating code for structures and function calls.  For functions, dissect
sub-structures with PARSE_SCALARS|PARSE_BUFFERS.  For arrays and structures
in structures (?) use PARSE_SCALARS on each element of the structure then
PARSE_BUFFERS.

Determine whether a type is a "simple" type or a struct/union.
This commit is contained in:
Tim Potter -
parent e5ca478614
commit bb5bab5817

View File

@ -10,6 +10,15 @@ use Data::Dumper;
my($res);
sub is_simple_type($)
{
my($type) = shift;
return 1, if ($type eq "uint32");
return 0;
}
#####################################################################
# parse a properties list
sub ParseProperties($)
@ -53,24 +62,28 @@ sub ParseStruct($)
# Parse scalars
$res .= "\t/* Parse scalars */\n\n";
$res .= "\tif (flags & PARSE_SCALARS) {\n";
foreach my $e (@{$struct->{ELEMENTS}}) {
if (defined $e->{POINTERS}) {
$res .= "\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, drep, \"$e->{NAME}\");\n";
$res .= "\t\toffset = dissect_ptr(tvb, offset, pinfo, tree, &ptr_$e->{NAME}, \"$e->{NAME}\");\n";
} else {
$res .= "\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, drep, \"$e->{NAME}\");\n";
$res .= "\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n";
}
}
$res .= "\t}\n\n";
# Parse buffers
$res .= "\n\t/* Parse buffers */\n\n";
$res .= "\tif (flags & PARSE_BUFFERS) {\n";
foreach my $e (@{$struct->{ELEMENTS}}) {
$res .= "\tif (ptr_$e->{NAME})\n\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, drep, \"$e->{NAME}\");\n\n",
$res .= "\t\tif (ptr_$e->{NAME})\n\t\t\toffset = dissect_$e->{TYPE}(tvb, offset, pinfo, tree, \"$e->{NAME}\");\n\n",
if (defined $e->{POINTERS});
}
$res .= "\t}\n\n";
}
}
@ -86,7 +99,7 @@ sub ParseUnionElement($)
# $res .= "}\n\n";
$res .= "\tcase $element->{DATA}->{NAME}: \n";
$res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, drep, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
$res .= "\t\toffset = dissect_$element->{DATA}->{TYPE}(tvb, offset, pinfo, tree, \"$element->{DATA}->{NAME}\");\n\t\tbreak;\n";
# $res .= "[case($element->{CASE})] ";
# ParseElement($element->{DATA});
@ -132,7 +145,7 @@ sub ParseTypedef($)
my($typedef) = shift;
$res .= "static int dissect_$typedef->{NAME}(tvbuff_t *tvb, int offset,\
\tpacket_info *pinfo, proto_tree *tree, char *drep)\n{\n";
\tpacket_info *pinfo, proto_tree *tree)\n{\n";
ParseType($typedef->{DATA});
$res .= "}\n\n";
}
@ -151,18 +164,23 @@ sub ParseFunctionArg($$)
foreach my $prop (@{$arg->{PROPERTIES}}) {
if ($prop =~ /context_handle/) {
$res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree, drep);\n";
$res .= "\toffset = dissect_policy_hnd(tvb, offset, pinfo, tree);\n";
$is_pol = 1;
}
}
if (!$is_pol) {
if ($arg->{POINTERS}) {
$res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n";
$res .= "\tif (ptr_$arg->{NAME})\
\t\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n\n";
$res .= "\tptr_$arg->{NAME} = dissect_dcerpc_ptr(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
$res .= "\tif (ptr_$arg->{NAME})\n\t\toffset = ";
if (is_simple_type($arg->{TYPE})) {
$res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}}\");\n\n";
} else {
$res .= "dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, PARSE_SCALARS|PARSE_BUFFERS, \"$arg->{NAME}\");\n\n";
}
} else {
$res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, drep, \"$arg->{NAME}\");\n";
$res .= "\toffset = dissect_dcerpc_$arg->{TYPE}(tvb, offset, pinfo, tree, \"$arg->{NAME}\");\n";
}
}
}
@ -194,7 +212,7 @@ sub ParseFunction($)
ParseFunctionArg($arg, "out");
}
$res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree, drep);\n";
$res .= "\n\toffset = dissect_ntstatus(tvb, offset, pinfo, tree);\n";
$res .= "\n\treturn 0;\n}\n\n";