Hugo Beauzée-Luyssen 9 лет назад
Родитель
Сommit
68ec2d4809
4 измененных файлов с 86 добавлено и 42 удалено
  1. 40 0
      src/bdsm_common.h
  2. 3 2
      src/netbios_defs.h
  3. 5 4
      src/smb_ntlm.h
  4. 38 36
      src/smb_packets.h

+ 40 - 0
src/bdsm_common.h

@@ -0,0 +1,40 @@
+/*****************************************************************************
+ *  __________________    _________  _____            _____  .__         ._.
+ *  \______   \______ \  /   _____/ /     \          /  _  \ |__| ____   | |
+ *   |    |  _/|    |  \ \_____  \ /  \ /  \        /  /_\  \|  _/ __ \  | |
+ *   |    |   \|    `   \/        /    Y    \      /    |    |  \  ___/   \|
+ *   |______  /_______  /_______  \____|__  / /\   \____|__  |__|\___ |   __
+ *          \/        \/        \/        \/  )/           \/        \/   \/
+ *
+ * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
+ *
+ * Author: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
+ *
+ * liBDSM is released under LGPLv2.1 (or later) and is also available
+ * under a commercial license.
+ *****************************************************************************
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef BDSM_COMMON_H
+#define BDSM_COMMON_H
+
+#ifdef _WIN32
+#define SMB_PACKED_STRUCT __attribute__((packed, gcc_struct))
+#else
+#define SMB_PACKED_STRUCT __attribute__((packed))
+#endif
+
+#endif // BDSM_COMMON_H

+ 3 - 2
src/netbios_defs.h

@@ -34,6 +34,7 @@
 #include <stdint.h>
 
 #include "bdsm/netbios_defs.h"
+#include "bdsm_common.h"
 
 #define NETBIOS_PORT_NAME     137 // UDP
 #define NETBIOS_PORT_SESSION  139 // TCP
@@ -72,7 +73,7 @@ typedef struct
     uint16_t                    ns_count;   // Number of authorities (?)
     uint16_t                    ar_count;   // Additionnal (??)
     char                        payload[];
-} __attribute__((packed))   netbios_query_packet;
+} SMB_PACKED_STRUCT   netbios_query_packet;
 
 typedef struct
 {
@@ -81,6 +82,6 @@ typedef struct
     // beginning of the length field (!!)
     uint16_t                    length;     // payload length;
     uint8_t                     payload[];
-} __attribute__((packed))   netbios_session_packet;
+} SMB_PACKED_STRUCT   netbios_session_packet;
 
 #endif

+ 5 - 4
src/smb_ntlm.h

@@ -31,6 +31,7 @@
 #ifndef _SMB_NTLM_H_
 #define _SMB_NTLM_H_
 
+#include "bdsm_common.h"
 #include "smb_defs.h"
 #include "smb_buffer.h"
 
@@ -47,7 +48,7 @@ typedef struct
     uint64_t    challenge;
     uint32_t    unknown;
     uint8_t     target[];
-} __attribute__((packed)) smb_ntlm_blob;
+} SMB_PACKED_STRUCT smb_ntlm_blob;
 
 
 
@@ -70,7 +71,7 @@ typedef struct
     _NTLMSSP_FIELD(domain)
     _NTLMSSP_FIELD(host)
     uint8_t     names[];
-} __attribute__((packed)) smb_ntlmssp_nego;
+} SMB_PACKED_STRUCT smb_ntlmssp_nego;
 
 typedef struct
 {
@@ -81,7 +82,7 @@ typedef struct
     uint64_t    reserved;
     _NTLMSSP_FIELD(tgt) // Target Info
     uint8_t     data[];
-} __attribute__((packed)) smb_ntlmssp_challenge;
+} SMB_PACKED_STRUCT smb_ntlmssp_challenge;
 
 typedef struct
 {
@@ -95,7 +96,7 @@ typedef struct
 
     uint32_t    flags;
     uint8_t     data[];
-} __attribute__((packed)) smb_ntlmssp_auth;
+} SMB_PACKED_STRUCT smb_ntlmssp_auth;
 
 uint64_t    smb_ntlm_generate_challenge();
 void        smb_ntlm_generate_xkey(smb_ntlmh cli_session_key);

+ 38 - 36
src/smb_packets.h

@@ -33,6 +33,8 @@
 
 #include <stdint.h>
 
+#include "bdsm_common.h"
+
 #define SMB_ANDX_MEMBERS  \
   uint8_t         andx;           /* 0xff when no other command (do this :)*/  \
   uint8_t         andx_reserved;  /* 0x00 */                                   \
@@ -56,13 +58,13 @@ typedef struct
     uint16_t        pid;          // Process ID.
     uint16_t        uid;          // User ID.
     uint16_t        mux_id;       // Multiplex ID. Increment it sometimes.
-} __attribute__((packed))       smb_header;
+} SMB_PACKED_STRUCT        smb_header;
 
 typedef struct
 {
     smb_header    header;       // A packet header full of gorgeous goodness.
     uint8_t         payload[];    // Ze yummy data inside. Eat 5 fruits/day !
-} __attribute__((packed))       smb_packet;
+} SMB_PACKED_STRUCT       smb_packet;
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -73,7 +75,7 @@ typedef struct
 {
     uint8_t         wct;              // 0
     uint16_t        bct;
-} __attribute__((packed))   smb_simple_struct;
+} SMB_PACKED_STRUCT   smb_simple_struct;
 
 
 //-> Negotiate Protocol
@@ -83,7 +85,7 @@ typedef struct
     uint16_t        bct;
     char            dialects[];
 
-} __attribute__((packed))   smb_nego_req;
+} SMB_PACKED_STRUCT   smb_nego_req;
 
 
 #define SMB_NEGO_RESP_COMMON \
@@ -106,7 +108,7 @@ typedef struct
     SMB_NEGO_RESP_COMMON
     uint64_t        challenge;      // Normally 8 bytes, if not then wtf monkey
     uint8_t         payload[];      // The rest isn't really meaningfull for us
-} __attribute__((packed))   smb_nego_resp;
+} SMB_PACKED_STRUCT   smb_nego_resp;
 
 //<- Negotiate Protocol
 typedef struct
@@ -114,7 +116,7 @@ typedef struct
     SMB_NEGO_RESP_COMMON
     uint8_t         srv_guid[16];
     uint8_t         gssapi[];
-} __attribute__((packed))   smb_nego_xsec_resp;
+} SMB_PACKED_STRUCT   smb_nego_xsec_resp;
 
 #define SMB_SESSION_REQ_COMMON \
   uint8_t         wct;          /* +-13 :) */                                  \
@@ -134,7 +136,7 @@ typedef struct
     uint32_t        caps;         // Capabilities
     uint16_t        payload_size;
     uint8_t         payload[];
-} __attribute__((packed))   smb_session_req;
+} SMB_PACKED_STRUCT   smb_session_req;
 
 //-> Session Setup
 typedef struct
@@ -145,7 +147,7 @@ typedef struct
     uint32_t        caps;           // Capabilities
     uint16_t        payload_size;
     uint8_t         payload[];
-} __attribute__((packed))   smb_session_xsec_req;
+} SMB_PACKED_STRUCT   smb_session_xsec_req;
 
 
 //<- Session Setup
@@ -156,7 +158,7 @@ typedef struct
     uint16_t        action;
     uint16_t        bct;
     uint8_t         bullshit[];
-} __attribute__((packed))   smb_session_resp;
+} SMB_PACKED_STRUCT   smb_session_resp;
 
 typedef struct
 {
@@ -166,7 +168,7 @@ typedef struct
     uint16_t        xsec_blob_size;
     uint16_t        payload_size;
     uint8_t         payload[];
-} __attribute__((packed))   smb_session_xsec_resp;
+} SMB_PACKED_STRUCT   smb_session_xsec_resp;
 
 
 
@@ -180,7 +182,7 @@ typedef struct
     uint16_t        bct;
     uint8_t         payload[];        // Password | Path | Service
 
-} __attribute__((packed))   smb_tree_connect_req;
+} SMB_PACKED_STRUCT   smb_tree_connect_req;
 
 //<- Tree Connect
 typedef struct
@@ -192,7 +194,7 @@ typedef struct
     uint32_t        guest_rights;
     uint16_t        bct;
     uint8_t         payload[];
-} __attribute__((packed))   smb_tree_connect_resp;
+} SMB_PACKED_STRUCT   smb_tree_connect_resp;
 
 //-> Tree Disconnect / <- Tree Disconnect
 typedef smb_simple_struct smb_tree_disconnect_req;
@@ -217,7 +219,7 @@ typedef struct
     uint8_t         security_flags;
     uint16_t        bct;
     uint8_t         path[];             // UTF16 Path, starting with '\'
-} __attribute__((packed))   smb_create_req;
+} SMB_PACKED_STRUCT   smb_create_req;
 
 //<- Create File
 typedef struct
@@ -238,7 +240,7 @@ typedef struct
     uint16_t        ipc_state;
     uint8_t         is_dir;
     uint16_t        bct;                // 0
-} __attribute__((packed))   smb_create_resp;
+} SMB_PACKED_STRUCT   smb_create_resp;
 
 
 
@@ -249,7 +251,7 @@ typedef struct
     uint16_t        fid;
     uint32_t        last_write;         // Not defined == 0xffffffff
     uint16_t        bct;                // 0
-} __attribute__((packed))   smb_close_req;
+} SMB_PACKED_STRUCT   smb_close_req;
 
 
 
@@ -266,7 +268,7 @@ typedef struct
     uint16_t        remaining;
     uint32_t        offset_high;        // Continuation of offset field'
     uint16_t        bct;                // 0
-} __attribute__((packed))   smb_read_req;
+} SMB_PACKED_STRUCT   smb_read_req;
 
 //<- Read File
 typedef struct
@@ -282,7 +284,7 @@ typedef struct
     uint32_t        reserved2;
     uint16_t        reserved3;
     uint16_t        bct;
-} __attribute__((packed))   smb_read_resp;
+} SMB_PACKED_STRUCT   smb_read_resp;
 
 //-> Write File
 typedef struct
@@ -300,7 +302,7 @@ typedef struct
     uint32_t        offset_high;        // Continuation of offset field'
     uint16_t        bct;
     uint8_t         padding;
-} __attribute__((packed))   smb_write_req;
+} SMB_PACKED_STRUCT   smb_write_req;
 
 //<- Write File
 typedef struct
@@ -312,7 +314,7 @@ typedef struct
     uint16_t        available;
     uint32_t        reserved;
     uint16_t        bct;
-} __attribute__((packed))   smb_write_resp;
+} SMB_PACKED_STRUCT   smb_write_resp;
 
 //-> Remove File
 typedef struct
@@ -321,14 +323,14 @@ typedef struct
     uint16_t        search_attributes;  // 0x0000 for "normal" (not hidden/ystem) files
     uint16_t        bct;                // >= 2
     uint8_t         buffer_format;      // 0x04
-} __attribute__((packed))   smb_file_rm_req;
+} SMB_PACKED_STRUCT   smb_file_rm_req;
 
 //<- Remove File
 typedef struct
 {
     uint8_t         wct;                // 0x00
     uint16_t        bct;                // 0x0000
-} __attribute__((packed))   smb_file_rm_resp;
+} SMB_PACKED_STRUCT   smb_file_rm_resp;
 
 //-> Remove Directory
 typedef struct
@@ -336,14 +338,14 @@ typedef struct
     uint8_t         wct;                // 0x00
     uint16_t        bct;                // >= 2
     uint8_t         buffer_format;      // 0x04
-} __attribute__((packed))   smb_directory_rm_req;
+} SMB_PACKED_STRUCT   smb_directory_rm_req;
 
 //<- Remove Directory
 typedef struct
 {
     uint8_t         wct;                // 0x00
     uint16_t        bct;                // 0x0000
-} __attribute__((packed))   smb_directory_rm_resp;
+} SMB_PACKED_STRUCT   smb_directory_rm_resp;
 
 //-> Move File
 typedef struct
@@ -351,7 +353,7 @@ typedef struct
     uint8_t         wct;                // 0x01
     uint16_t        search_attributes;  // 0x0000 for "normal" (not hidden/ystem) files
     uint16_t        bct;                // >= 2
-} __attribute__((packed))   smb_file_mv_req;
+} SMB_PACKED_STRUCT   smb_file_mv_req;
 
 //<- Move File
 typedef smb_simple_struct smb_file_mv_resp;
@@ -362,7 +364,7 @@ typedef struct
     uint8_t         wct;                // 0x00
     uint16_t        bct;                // >= 2
     uint8_t         buffer_format;      // 0x04
-} __attribute__((packed))   smb_directory_mk_req;
+} SMB_PACKED_STRUCT   smb_directory_mk_req;
 
 //<- Create Directory
 typedef smb_simple_struct smb_directory_mk_resp;
@@ -390,7 +392,7 @@ typedef struct
     uint16_t      fid;
     uint16_t      bct;
     uint8_t       payload[];
-} __attribute__((packed))   smb_trans_req;
+} SMB_PACKED_STRUCT   smb_trans_req;
 
 
 
@@ -419,7 +421,7 @@ typedef struct
     uint16_t      bct;
     uint8_t       padding[3];
     uint8_t       payload[];
-} __attribute__((packed))   smb_trans2_req;
+} SMB_PACKED_STRUCT   smb_trans2_req;
 
 //// -> Trans2|FindFirst2
 typedef struct
@@ -430,7 +432,7 @@ typedef struct
     uint16_t      interest;           // What kind of info do we want ?
     uint32_t      storage;            // ? => 0
     uint8_t       pattern[];          // The queried pattern "\\folder\\*"
-} __attribute__((packed))   smb_tr2_findfirst2;
+} SMB_PACKED_STRUCT   smb_tr2_findfirst2;
 
 //// -> Trans2|FindNext2
 typedef struct
@@ -441,7 +443,7 @@ typedef struct
     uint32_t      resume_key;         // Value returned by previous find2 call
     uint16_t      flags;
     uint8_t       pattern[];          // The queried pattern "\\folder\\*"
-} __attribute__((packed))   smb_tr2_findnext2;
+} SMB_PACKED_STRUCT   smb_tr2_findnext2;
 
 //// -> Trans2|QueryPathInfo
 typedef struct
@@ -449,7 +451,7 @@ typedef struct
     uint16_t      interest;
     uint32_t      reserved;
     uint8_t       path[];
-} __attribute__((packed))   smb_tr2_query;
+} SMB_PACKED_STRUCT   smb_tr2_query;
 
 //<- Trans2
 
@@ -470,7 +472,7 @@ typedef struct
     uint16_t      bct;
     uint8_t       padding;
     uint8_t       payload[];
-} __attribute__((packed))   smb_trans2_resp;
+} SMB_PACKED_STRUCT   smb_trans2_resp;
 
 //// <- Trans2|FindFirst2Params
 typedef struct
@@ -481,7 +483,7 @@ typedef struct
     uint16_t      ea_error_offset;
     uint16_t      last_name_offset;
     uint16_t      padding;
-} __attribute__((packed))   smb_tr2_findfirst2_params;
+} SMB_PACKED_STRUCT   smb_tr2_findfirst2_params;
 
 //// <- Trans2|FindNext2Params
 typedef struct
@@ -490,7 +492,7 @@ typedef struct
     uint16_t      eos;
     uint16_t      ea_error_offset;
     uint16_t      last_name_offset;
-} __attribute__((packed))   smb_tr2_findnext2_params;
+} SMB_PACKED_STRUCT   smb_tr2_findnext2_params;
 
 //// <- Trans2|FindFirst2FileInfo
 typedef struct
@@ -510,7 +512,7 @@ typedef struct
     uint8_t       reserved;
     uint8_t       short_name[24];
     uint8_t       name[];
-} __attribute__((packed))   smb_tr2_find2_entry;
+} SMB_PACKED_STRUCT   smb_tr2_find2_entry;
 
 
 //// <- Trans2|QueryPathInfo
@@ -531,7 +533,7 @@ typedef struct
     uint32_t      ea_list_len;
     uint32_t      name_len;
     uint8_t       name[];
-} __attribute__((packed))   smb_tr2_path_info;
+} SMB_PACKED_STRUCT   smb_tr2_path_info;
 
 //-> Example
 typedef struct
@@ -542,7 +544,7 @@ typedef struct
     uint16_t        bct;
     //uint8_t         padding;
     uint8_t         file[];
-} __attribute__((packed))   smb_example_t;
+} SMB_PACKED_STRUCT   smb_example_t;
 
 
 #endif