steghide  0.5.1
BinaryIO.h
Go to the documentation of this file.
1 /*
2  * steghide 0.5.1 - a steganography program
3  * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20 
21 #ifndef SH_BINARYIO_H
22 #define SH_BINARYIO_H
23 
24 #include <cstdio>
25 #include <string>
26 
27 #include "common.h"
28 
33 class BinaryIO {
34  public:
35  enum MODE { READ, WRITE } ;
36 
37  BinaryIO (void) ;
38 
46  BinaryIO (const std::string& fn, MODE m) ;
47 
48  ~BinaryIO (void) ;
49 
53  const std::string& getName (void) const
54  { return Name ; } ;
55 
59  bool is_open (void) const
60  { return FileOpen ; } ;
61 
65  bool is_std (void) const
66  { return (getStream() != NULL && getName() == "") ; } ;
67 
71  unsigned long getPos (void) const
72  { return ftell(getStream()) ; } ;
73 
77  bool eof (void) const ;
78 
84  void open (const std::string& fn, MODE m) ;
85 
89  void close (void) ;
90 
94  BYTE read8 (void) ;
95 
99  UWORD16 read16_le (void) ;
100 
104  UWORD16 read16_be (void) ;
105 
109  UWORD32 read32_le (void) ;
110 
114  UWORD32 read32_be (void) ;
115 
120  UWORD32 read_le (unsigned short n) ;
121 
125  std::string readstring (unsigned int len) ;
126 
130  void write8 (BYTE val) ;
131 
135  void write16_le (UWORD16 val) ;
136 
140  void write16_be (UWORD16 val) ;
141 
145  void write32_le (UWORD32 val) ;
146 
150  void write32_be (UWORD32 val) ;
151 
157  void write_le (UWORD32 val, unsigned short n) ;
158 
159  void writestring (const std::string& s) ;
160 
164  FILE* getStream (void) const
165  { return Stream ; } ;
166 
167  protected:
168  void setStream (FILE* s)
169  { Stream = s ; } ;
170 
171  void setName (const std::string& fn)
172  { Name = fn ; } ;
173 
174  MODE getMode (void) const
175  { return Mode ; } ;
176 
177  void setMode (MODE m)
178  { Mode = m ; } ;
179 
180  private:
181  std::string Name ;
182  FILE *Stream ;
183  bool FileOpen ;
185 
186  void init (void) ;
187 
188  void set_open (bool o)
189  { FileOpen = o ; } ;
190 
194  void checkForce (const std::string& fn) const ;
195 
200  bool Fileexists (const std::string& fn) const ;
201 } ;
202 
203 #endif /* ndef SH_BINARYIO_H */