Upx_Doxygen
https://github.com/upx/upx
mem.h
1 /* mem.h --
2 
3  This file is part of the UPX executable compressor.
4 
5  Copyright (C) 1996-2016 Markus Franz Xaver Johannes Oberhumer
6  Copyright (C) 1996-2016 Laszlo Molnar
7  All Rights Reserved.
8 
9  UPX and the UCL library are free software; you can redistribute them
10  and/or modify them under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of
12  the License, or (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING.
21  If not, write to the Free Software Foundation, Inc.,
22  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Markus F.X.J. Oberhumer Laszlo Molnar
25  <markus@oberhumer.com> <ezerotven+github@gmail.com>
26  */
27 
28 
29 #ifndef __UPX_MEM_H
30 #define __UPX_MEM_H 1
31 
32 
33 /*************************************************************************
34 //
35 **************************************************************************/
36 
37 class MemBuffer
38 {
39 public:
40  MemBuffer() : b(NULL), b_size(0) { }
41  explicit MemBuffer(upx_uint64_t size);
42  ~MemBuffer();
43 
44  static unsigned getSizeForCompression(unsigned uncompressed_size, unsigned extra=0);
45  static unsigned getSizeForUncompression(unsigned uncompressed_size, unsigned extra=0);
46 
47  void alloc(upx_uint64_t size);
48  void allocForCompression(unsigned uncompressed_size, unsigned extra=0);
49  void allocForUncompression(unsigned uncompressed_size, unsigned extra=0);
50 
51  void dealloc();
52 
53  void checkState() const;
54 
55  unsigned getSize() const { return b_size; }
56 
57  operator unsigned char * () { return b; }
58  operator const unsigned char * () const { return b; }
59 
60  void *getVoidPtr() { return (void *) b; }
61  const void *getVoidPtr() const { return (const void *) b; }
62 
63  void fill(unsigned off, unsigned len, int value);
64  void clear(unsigned off, unsigned len) { fill(off, len, 0); }
65  void clear() { fill(0, b_size, 0); }
66 
67 private:
68  unsigned char *b;
69  unsigned b_size;
70 
71  static unsigned global_alloc_counter;
72 
73  // disable copy and assignment
74  MemBuffer(const MemBuffer &); // {}
75  MemBuffer& operator= (const MemBuffer &); // { return *this; }
76 
77  // disable dynamic allocation
78  DISABLE_NEW_DELETE
79 };
80 
81 #endif /* already included */
82 
83 /* vim:set ts=4 sw=4 et: */
Definition: mem.h:37