Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: courgette/disassembler.h

Issue 1543643002: Switch to standard integer types in courgette/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/difference_estimator.cc ('k') | courgette/disassembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COURGETTE_DISASSEMBLER_H_ 5 #ifndef COURGETTE_DISASSEMBLER_H_
6 #define COURGETTE_DISASSEMBLER_H_ 6 #define COURGETTE_DISASSEMBLER_H_
7 7
8 #include "base/basictypes.h" 8 #include <stddef.h>
9 #include <stdint.h>
9 10
11 #include "base/macros.h"
10 #include "courgette/courgette.h" 12 #include "courgette/courgette.h"
11 #include "courgette/image_utils.h" 13 #include "courgette/image_utils.h"
12 14
13 namespace courgette { 15 namespace courgette {
14 16
15 class AssemblyProgram; 17 class AssemblyProgram;
16 18
17 class Disassembler { 19 class Disassembler {
18 public: 20 public:
19 virtual ~Disassembler(); 21 virtual ~Disassembler();
20 22
21 virtual ExecutableType kind() { return EXE_UNKNOWN; } 23 virtual ExecutableType kind() { return EXE_UNKNOWN; }
22 24
23 // ok() may always be called but returns 'true' only after ParseHeader 25 // ok() may always be called but returns 'true' only after ParseHeader
24 // succeeds. 26 // succeeds.
25 bool ok() const { return failure_reason_ == NULL; } 27 bool ok() const { return failure_reason_ == NULL; }
26 28
27 // Returns 'true' if the buffer appears to be a valid executable of the 29 // Returns 'true' if the buffer appears to be a valid executable of the
28 // expected type. It is not required that this be called before Disassemble. 30 // expected type. It is not required that this be called before Disassemble.
29 virtual bool ParseHeader() = 0; 31 virtual bool ParseHeader() = 0;
30 32
31 // Disassembles the item passed to the factory method into the output 33 // Disassembles the item passed to the factory method into the output
32 // parameter 'program'. 34 // parameter 'program'.
33 virtual bool Disassemble(AssemblyProgram* program) = 0; 35 virtual bool Disassemble(AssemblyProgram* program) = 0;
34 36
35 // Returns the length of the source executable. May reduce after ParseHeader. 37 // Returns the length of the source executable. May reduce after ParseHeader.
36 size_t length() const { return length_; } 38 size_t length() const { return length_; }
37 const uint8* start() const { return start_; } 39 const uint8_t* start() const { return start_; }
38 const uint8* end() const { return end_; } 40 const uint8_t* end() const { return end_; }
39 41
40 // Returns a pointer into the memory copy of the file format. 42 // Returns a pointer into the memory copy of the file format.
41 // FileOffsetToPointer(0) returns a pointer to the start of the file format. 43 // FileOffsetToPointer(0) returns a pointer to the start of the file format.
42 const uint8* OffsetToPointer(size_t offset) const; 44 const uint8_t* OffsetToPointer(size_t offset) const;
43 45
44 protected: 46 protected:
45 Disassembler(const void* start, size_t length); 47 Disassembler(const void* start, size_t length);
46 48
47 bool Good(); 49 bool Good();
48 bool Bad(const char *reason); 50 bool Bad(const char *reason);
49 51
50 // Returns true if the array lies within our memory region. 52 // Returns true if the array lies within our memory region.
51 bool IsArrayInBounds(size_t offset, size_t elements, size_t element_size) { 53 bool IsArrayInBounds(size_t offset, size_t elements, size_t element_size) {
52 return offset <= length() && elements <= (length() - offset) / element_size; 54 return offset <= length() && elements <= (length() - offset) / element_size;
53 } 55 }
54 56
55 // Reduce the length of the image in memory. Does not actually free 57 // Reduce the length of the image in memory. Does not actually free
56 // (or realloc) any memory. Usually only called via ParseHeader() 58 // (or realloc) any memory. Usually only called via ParseHeader()
57 void ReduceLength(size_t reduced_length); 59 void ReduceLength(size_t reduced_length);
58 60
59 private: 61 private:
60 const char* failure_reason_; 62 const char* failure_reason_;
61 63
62 // 64 //
63 // Basic information that is always valid after Construction, though 65 // Basic information that is always valid after Construction, though
64 // ParseHeader may shorten the length if the executable is shorter than 66 // ParseHeader may shorten the length if the executable is shorter than
65 // the total data. 67 // the total data.
66 // 68 //
67 size_t length_; // In current memory. 69 size_t length_; // In current memory.
68 const uint8* start_; // In current memory, base for 'file offsets'. 70 const uint8_t* start_; // In current memory, base for 'file offsets'.
69 const uint8* end_; // In current memory. 71 const uint8_t* end_; // In current memory.
70 72
71 DISALLOW_COPY_AND_ASSIGN(Disassembler); 73 DISALLOW_COPY_AND_ASSIGN(Disassembler);
72 }; 74 };
73 75
74 } // namespace courgette 76 } // namespace courgette
75 77
76 #endif // COURGETTE_DISASSEMBLER_H_ 78 #endif // COURGETTE_DISASSEMBLER_H_
OLDNEW
« no previous file with comments | « courgette/difference_estimator.cc ('k') | courgette/disassembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698