add trailer alignment to structures
[ira/wip.git] / pidl / lib / Parse / Pidl / Wireshark / NDR.pm
index 8846b740ab745fc2922122456093690108a893d0..b8adf2dc4eb16d520587a39ae1b93ff1a12560f2 100644 (file)
@@ -1,5 +1,5 @@
 ##################################################
-# Samba4 NDR parser generator for IDL structures
+# Wireshark NDR parser generator for IDL structures
 # Copyright tridge@samba.org 2000-2003
 # Copyright tpot@samba.org 2001,2005
 # Copyright jelmer@samba.org 2004-2007
@@ -380,7 +380,7 @@ sub Element($$$)
                        MASK => 0,
                        VALSSTRING => "NULL",
                        FT_TYPE => "FT_NONE",
-                       BASE_TYPE => "BASE_HEX"
+                       BASE_TYPE => "BASE_NONE"
                };
        }
 
@@ -389,7 +389,7 @@ sub Element($$$)
                        MASK => 0,
                        VALSSTRING => "NULL",
                        FT_TYPE => "FT_STRING",
-                       BASE_TYPE => "BASE_DEC"
+                       BASE_TYPE => "BASE_NONE"
                };
        }
 
@@ -545,6 +545,9 @@ sub Struct($$$$)
        $self->indent;
        $self->pidl_code("proto_item *item = NULL;");
        $self->pidl_code("proto_tree *tree = NULL;");
+       if ($e->{ALIGN} > 1) {
+               $self->pidl_code("dcerpc_info *di = pinfo->private_data;");
+       }
        $self->pidl_code("int old_offset;");
        $self->pidl_code("");
 
@@ -565,6 +568,15 @@ sub Struct($$$$)
        $self->pidl_code("\n$res");
 
        $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
+       if ($e->{ALIGN} > 1) {
+               $self->pidl_code("");
+               $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
+               $self->indent;
+               $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
+               $self->deindent;
+               $self->pidl_code("}");
+       }
+       $self->pidl_code("");
        $self->pidl_code("return offset;");
        $self->deindent;
        $self->pidl_code("}\n");
@@ -634,6 +646,8 @@ sub Union($$$$)
 
        $self->pidl_code("switch(level) {$res\t}");
        $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
+       $self->pidl_code("");
+
        $self->pidl_code("return offset;");
        $self->deindent;
        $self->pidl_code("}");
@@ -874,7 +888,7 @@ sub Initialize($$)
        $self->register_type("policy_handle", "offset = PIDL_dissect_policy_hnd(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_BYTES", "BASE_NONE", 0, "NULL", 4);
        $self->register_type("NTTIME", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
        $self->register_type("NTTIME_hyper", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
-       $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_DEC", 0, "NULL", 4);
+       $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
        $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "BASE_NONE", 0, "NULL", 4);
        $self->register_type("SID", "
                dcerpc_info *di = (dcerpc_info *)pinfo->private_data;
@@ -882,7 +896,7 @@ sub Initialize($$)
                di->hf_index = \@HF\@;
 
                offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);
-       ","FT_STRING", "BASE_DEC", 0, "NULL", 4);
+       ","FT_STRING", "BASE_NONE", 0, "NULL", 4);
        $self->register_type("WERROR", 
                "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4);
        $self->register_type("NTSTATUS", 
@@ -895,7 +909,7 @@ sub Initialize($$)
 sub Parse($$$$$)
 {
        my($self,$ndr,$idl_file,$h_filename,$cnf_file) = @_;
-       
+
        $self->Initialize($cnf_file);
 
        return (undef, undef) if defined($self->{conformance}->{noemit_dissector});
@@ -1055,6 +1069,20 @@ sub DumpHfDeclaration($)
        return "$res\n";
 }
 
+sub make_str_or_null($)
+{
+      my $str = shift;
+      if (substr($str, 0, 1) eq "\"") {
+              $str = substr($str, 1, length($str)-2);
+      }
+      $str =~ s/^\s*//;
+      $str =~ s/\s*$//;
+      if ($str eq "") {
+              return "NULL";
+      }
+      return make_str($str);
+}
+
 sub DumpHfList($)
 {
        my ($self) = @_;
@@ -1063,7 +1091,7 @@ sub DumpHfList($)
        foreach (values %{$self->{conformance}->{header_fields}}) 
        {
                $res .= "\t{ &$_->{INDEX}, 
-         { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str($_->{BLURB}).", HFILL }},
+         { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }},
 ";
        }