summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authoravi <avi@chromium.org>2015-12-21 11:35:33 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-21 19:36:50 +0000
commitab98dcc986f5a27e972dad1735fe089154186cd9 (patch)
treec706077d103f0d77a1f1f5b1bd9c4712627bd195 /courgette
parent343184883aee8ba06d9ed3244c4adf63577d030c (diff)
downloadchromium_src-ab98dcc986f5a27e972dad1735fe089154186cd9.zip
chromium_src-ab98dcc986f5a27e972dad1735fe089154186cd9.tar.gz
chromium_src-ab98dcc986f5a27e972dad1735fe089154186cd9.tar.bz2
Switch to standard integer types in courgette/.
BUG=138542 TBR=wfh@chromium.org NOPRESUBMIT=true Review URL: https://codereview.chromium.org/1543643002 Cr-Commit-Position: refs/heads/master@{#366439}
Diffstat (limited to 'courgette')
-rw-r--r--courgette/adjustment_method.cc46
-rw-r--r--courgette/adjustment_method.h2
-rw-r--r--courgette/adjustment_method_2.cc62
-rw-r--r--courgette/assembly_program.cc73
-rw-r--r--courgette/assembly_program.h28
-rw-r--r--courgette/bsdiff_memory_unittest.cc2
-rw-r--r--courgette/consecutive_range_visitor.h2
-rw-r--r--courgette/consecutive_range_visitor_unittest.cc2
-rw-r--r--courgette/courgette_tool.cc6
-rw-r--r--courgette/crc.cc8
-rw-r--r--courgette/crc.h5
-rw-r--r--courgette/difference_estimator.cc22
-rw-r--r--courgette/difference_estimator.h3
-rw-r--r--courgette/disassembler.cc9
-rw-r--r--courgette/disassembler.h14
-rw-r--r--courgette/disassembler_elf_32.cc14
-rw-r--r--courgette/disassembler_elf_32.h11
-rw-r--r--courgette/disassembler_elf_32_arm.cc128
-rw-r--r--courgette/disassembler_elf_32_arm.h30
-rw-r--r--courgette/disassembler_elf_32_x86.cc27
-rw-r--r--courgette/disassembler_elf_32_x86.h9
-rw-r--r--courgette/disassembler_elf_32_x86_unittest.cc5
-rw-r--r--courgette/disassembler_win32_x64.cc98
-rw-r--r--courgette/disassembler_win32_x64.h47
-rw-r--r--courgette/disassembler_win32_x64_unittest.cc6
-rw-r--r--courgette/disassembler_win32_x86.cc92
-rw-r--r--courgette/disassembler_win32_x86.h47
-rw-r--r--courgette/disassembler_win32_x86_unittest.cc6
-rw-r--r--courgette/encode_decode_unittest.cc2
-rw-r--r--courgette/encoded_program.cc127
-rw-r--r--courgette/encoded_program.h19
-rw-r--r--courgette/encoded_program_fuzz_unittest.cc2
-rw-r--r--courgette/encoded_program_unittest.cc39
-rw-r--r--courgette/ensemble.cc6
-rw-r--r--courgette/ensemble.h12
-rw-r--r--courgette/ensemble_apply.cc21
-rw-r--r--courgette/ensemble_create.cc3
-rw-r--r--courgette/image_utils.h31
-rw-r--r--courgette/image_utils_unittest.cc4
-rw-r--r--courgette/label_manager.cc7
-rw-r--r--courgette/label_manager.h5
-rw-r--r--courgette/label_manager_unittest.cc31
-rw-r--r--courgette/memory_allocator.cc5
-rw-r--r--courgette/memory_allocator.h15
-rw-r--r--courgette/memory_allocator_unittest.cc2
-rw-r--r--courgette/memory_monitor.cc1
-rw-r--r--courgette/patch_generator_x86_32.h2
-rw-r--r--courgette/patcher_x86_32.h7
-rw-r--r--courgette/region.h19
-rw-r--r--courgette/rel32_finder_win32_x86.cc19
-rw-r--r--courgette/rel32_finder_win32_x86.h11
-rw-r--r--courgette/rel32_finder_win32_x86_unittest.cc13
-rw-r--r--courgette/simple_delta.cc1
-rw-r--r--courgette/streams.cc60
-rw-r--r--courgette/streams.h30
-rw-r--r--courgette/streams_unittest.cc30
-rw-r--r--courgette/third_party/bsdiff.h9
-rw-r--r--courgette/third_party/bsdiff_apply.cc30
-rw-r--r--courgette/third_party/bsdiff_create.cc16
-rw-r--r--courgette/third_party/paged_array.h4
-rw-r--r--courgette/third_party/qsufsort_unittest.cc2
-rw-r--r--courgette/typedrva_unittest.cc28
-rw-r--r--courgette/types_elf.h13
-rw-r--r--courgette/types_win_pe.h28
-rw-r--r--courgette/versioning_unittest.cc3
65 files changed, 797 insertions, 664 deletions
diff --git a/courgette/adjustment_method.cc b/courgette/adjustment_method.cc
index 2bc9269..ce93a21 100644
--- a/courgette/adjustment_method.cc
+++ b/courgette/adjustment_method.cc
@@ -4,6 +4,9 @@
#include "courgette/adjustment_method.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <list>
#include <map>
@@ -11,8 +14,8 @@
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "courgette/assembly_program.h"
@@ -41,10 +44,10 @@ class LabelInfo {
Label* label_; // The label that this info a surrogate for.
// Information used only in debugging messages.
- uint32 is_model_ : 1; // Is the label in the model?
- uint32 debug_index_ : 31; // An unique small number for naming the label.
+ uint32_t is_model_ : 1; // Is the label in the model?
+ uint32_t debug_index_ : 31; // An unique small number for naming the label.
- uint32 refs_; // Number of times this Label is referenced.
+ uint32_t refs_; // Number of times this Label is referenced.
LabelInfo* assignment_; // Label from other program corresponding to this.
@@ -53,7 +56,7 @@ class LabelInfo {
LabelInfo* next_addr_; // Label(Info) at next highest address.
LabelInfo* prev_addr_; // Label(Info) at next lowest address.
- std::vector<uint32> positions_; // Offsets into the trace of references.
+ std::vector<uint32_t> positions_; // Offsets into the trace of references.
// Just a no-argument constructor and copy constructor. Actual LabelInfo
// objects are allocated in std::pair structs in a std::map.
@@ -149,9 +152,7 @@ struct Node {
bool in_queue_;
bool Extended() const { return !edges_.empty(); }
- uint32 Weight() const {
- return edges_in_frequency_order.front()->count_;
- }
+ uint32_t Weight() const { return edges_in_frequency_order.front()->count_; }
};
static std::string ToString(Node* node) {
@@ -190,8 +191,8 @@ struct OrderNodeByWeightDecreasing {
bool operator()(Node* a, Node* b) const {
// (Maybe tie-break on total count, followed by lowest assigned node indexes
// in path.)
- uint32 a_weight = a->Weight();
- uint32 b_weight = b->Weight();
+ uint32_t a_weight = a->Weight();
+ uint32_t b_weight = b->Weight();
if (a_weight != b_weight)
return a_weight > b_weight;
if (a->length_ != b->length_)
@@ -254,7 +255,7 @@ class AssignmentProblem {
void SkipCommittedLabels(Node* node) {
ExtendNode(node, p_trace_);
- uint32 skipped = 0;
+ uint32_t skipped = 0;
while (!node->edges_in_frequency_order.empty() &&
node->edges_in_frequency_order.front()->in_edge_->assignment_) {
++skipped;
@@ -421,9 +422,9 @@ class AssignmentProblem {
}
}
- uint32 TryExtendSequence(uint32 p_pos_start, uint32 m_pos_start) {
- uint32 p_pos = p_pos_start + 1;
- uint32 m_pos = m_pos_start + 1;
+ uint32_t TryExtendSequence(uint32_t p_pos_start, uint32_t m_pos_start) {
+ uint32_t p_pos = p_pos_start + 1;
+ uint32_t m_pos = m_pos_start + 1;
while (p_pos < p_trace_.size() && m_pos < m_trace_.size()) {
LabelInfo* p_info = p_trace_[p_pos];
@@ -456,12 +457,13 @@ class AssignmentProblem {
return p_pos - p_pos_start;
}
- uint32 TryExtendSequenceBackwards(uint32 p_pos_start, uint32 m_pos_start) {
+ uint32_t TryExtendSequenceBackwards(uint32_t p_pos_start,
+ uint32_t m_pos_start) {
if (p_pos_start == 0 || m_pos_start == 0)
return 0;
- uint32 p_pos = p_pos_start - 1;
- uint32 m_pos = m_pos_start - 1;
+ uint32_t p_pos = p_pos_start - 1;
+ uint32_t m_pos = m_pos_start - 1;
while (p_pos > 0 && m_pos > 0) {
LabelInfo* p_info = p_trace_[p_pos];
@@ -522,7 +524,7 @@ class AssignmentProblem {
Node* MakeRootNode(const Trace& trace) {
Node* node = new Node(NULL, NULL);
all_nodes_.push_back(node);
- for (uint32 i = 0; i < trace.size(); ++i) {
+ for (uint32_t i = 0; i < trace.size(); ++i) {
++node->count_;
node->places_.push_back(i);
}
@@ -534,7 +536,7 @@ class AssignmentProblem {
if (node->Extended())
return;
for (size_t i = 0; i < node->places_.size(); ++i) {
- uint32 index = node->places_.at(i);
+ uint32_t index = node->places_.at(i);
if (index < trace.size()) {
LabelInfo* item = trace.at(index);
Node*& slot = node->edges_[item];
@@ -633,11 +635,11 @@ class GraphAdjuster : public AdjustmentMethod {
}
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
- trace->push_back(MakeLabelInfo(label, is_model,
- static_cast<uint32>(trace->size())));
+ trace->push_back(
+ MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size())));
}
- LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
+ LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
diff --git a/courgette/adjustment_method.h b/courgette/adjustment_method.h
index 0ecf04d..a19ec61 100644
--- a/courgette/adjustment_method.h
+++ b/courgette/adjustment_method.h
@@ -5,7 +5,7 @@
#ifndef COURGETTE_ADJUSTMENT_METHOD_H_
#define COURGETTE_ADJUSTMENT_METHOD_H_
-#include "base/basictypes.h"
+#include "base/macros.h"
namespace courgette {
diff --git a/courgette/adjustment_method_2.cc b/courgette/adjustment_method_2.cc
index 57f02ac..d783cda 100644
--- a/courgette/adjustment_method_2.cc
+++ b/courgette/adjustment_method_2.cc
@@ -4,6 +4,9 @@
#include "courgette/adjustment_method.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <limits>
#include <list>
@@ -12,9 +15,9 @@
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "courgette/assembly_program.h"
@@ -176,16 +179,16 @@ class LabelInfo {
Label* label_; // The label that this info a surrogate for.
- uint32 is_model_ : 1; // Is the label in the model?
- uint32 debug_index_ : 31; // A small number for naming the label in debug
- // output. The pair (is_model_, debug_index_) is
- // unique.
+ uint32_t is_model_ : 1; // Is the label in the model?
+ uint32_t debug_index_ : 31; // A small number for naming the label in debug
+ // output. The pair (is_model_, debug_index_) is
+ // unique.
int refs_; // Number of times this Label is referenced.
LabelInfo* assignment_; // Label from other program corresponding to this.
- std::vector<uint32> positions_; // Offsets into the trace of references.
+ std::vector<uint32_t> positions_; // Offsets into the trace of references.
private:
AssignmentCandidates* candidates_;
@@ -213,7 +216,7 @@ class LabelInfoMaker {
public:
LabelInfoMaker() : debug_label_index_gen_(0) {}
- LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32 position) {
+ LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
LabelInfo& slot = label_infos_[label];
if (slot.label_ == NULL) {
slot.label_ = label;
@@ -364,7 +367,7 @@ LabelInfo::~LabelInfo() {
// position of one of the occurrences in the Trace.
class Shingle {
public:
- static const uint8 kWidth = 5;
+ static const uint8_t kWidth = 5;
struct InterningLess {
bool operator()(const Shingle& a, const Shingle& b) const;
@@ -388,7 +391,7 @@ class Shingle {
LabelInfo* at(size_t i) const { return trace_[exemplar_position_ + i]; }
void add_position(size_t position) {
- positions_.push_back(static_cast<uint32>(position));
+ positions_.push_back(static_cast<uint32_t>(position));
}
int position_count() const { return static_cast<int>(positions_.size()); }
@@ -414,7 +417,7 @@ class Shingle {
const Trace& trace_; // The shingle lives inside trace_.
size_t exemplar_position_; // At this position (and other positions).
- std::vector<uint32> positions_; // Includes exemplar_position_.
+ std::vector<uint32_t> positions_; // Includes exemplar_position_.
ShinglePattern* pattern_; // Pattern changes as LabelInfos are assigned.
@@ -430,7 +433,7 @@ class Shingle {
std::string ToString(const Shingle* instance) {
std::string s;
const char* sep = "<";
- for (uint8 i = 0; i < Shingle::kWidth; ++i) {
+ for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
// base::StringAppendF(&s, "%s%x ", sep, instance.at(i)->label_->rva_);
s += sep;
s += ToString(instance->at(i));
@@ -446,7 +449,7 @@ std::string ToString(const Shingle* instance) {
bool Shingle::InterningLess::operator()(
const Shingle& a,
const Shingle& b) const {
- for (uint8 i = 0; i < kWidth; ++i) {
+ for (uint8_t i = 0; i < kWidth; ++i) {
LabelInfo* info_a = a.at(i);
LabelInfo* info_b = b.at(i);
if (info_a->label_->rva_ < info_b->label_->rva_)
@@ -478,11 +481,11 @@ class ShinglePattern {
// --> <kFixed+0, kVariable+1, kFixed+2, kVariable+1, kFixed+0>
struct Index {
explicit Index(const Shingle* instance);
- uint8 kinds_[Shingle::kWidth];
- uint8 variables_;
- uint8 unique_variables_;
- uint8 first_variable_index_;
- uint32 hash_;
+ uint8_t kinds_[Shingle::kWidth];
+ uint8_t variables_;
+ uint8_t unique_variables_;
+ uint8_t first_variable_index_;
+ uint32_t hash_;
int assigned_indexes_[Shingle::kWidth];
};
@@ -526,10 +529,10 @@ std::string ToString(const ShinglePattern::Index* index) {
} else {
base::StringAppendF(&s, "<%d: ", index->variables_);
const char* sep = "";
- for (uint8 i = 0; i < Shingle::kWidth; ++i) {
+ for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
s += sep;
sep = ", ";
- uint32 kind = index->kinds_[i];
+ uint32_t kind = index->kinds_[i];
int offset = kind & ShinglePattern::kOffsetMask;
if (kind & ShinglePattern::kVariable)
base::StringAppendF(&s, "V%d", offset);
@@ -622,7 +625,7 @@ struct ShinglePatternIndexLess {
if (a.hash_ < b.hash_) return true;
if (a.hash_ > b.hash_) return false;
- for (uint8 i = 0; i < Shingle::kWidth; ++i) {
+ for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
if (a.kinds_[i] < b.kinds_[i]) return true;
if (a.kinds_[i] > b.kinds_[i]) return false;
if ((a.kinds_[i] & ShinglePattern::kVariable) == 0) {
@@ -636,22 +639,22 @@ struct ShinglePatternIndexLess {
}
};
-static uint32 hash_combine(uint32 h, uint32 v) {
+static uint32_t hash_combine(uint32_t h, uint32_t v) {
h += v;
return (h * (37 + 0x0000d100)) ^ (h >> 13);
}
ShinglePattern::Index::Index(const Shingle* instance) {
- uint32 hash = 0;
+ uint32_t hash = 0;
variables_ = 0;
unique_variables_ = 0;
first_variable_index_ = 255;
- for (uint8 i = 0; i < Shingle::kWidth; ++i) {
+ for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* info = instance->at(i);
- uint8 kind = 0;
+ uint8_t kind = 0;
int code = -1;
- uint8 j = 0;
+ uint8_t j = 0;
for ( ; j < i; ++j) {
if (info == instance->at(j)) { // Duplicate LabelInfo
kind = kinds_[j];
@@ -942,7 +945,7 @@ class AssignmentProblem {
// For the positions in |info|, find the shingles that overlap that position.
void AddAffectedPositions(LabelInfo* info, ShingleSet* affected_shingles) {
- const uint8 kWidth = Shingle::kWidth;
+ const uint8_t kWidth = Shingle::kWidth;
for (size_t i = 0; i < info->positions_.size(); ++i) {
size_t position = info->positions_[i];
// Find bounds to the subrange of |trace_| we are in.
@@ -1059,7 +1062,7 @@ class AssignmentProblem {
// int score = p1; // ? weigh all equally??
int score = std::min(p1, m1);
- for (uint8 i = 0; i < Shingle::kWidth; ++i) {
+ for (uint8_t i = 0; i < Shingle::kWidth; ++i) {
LabelInfo* program_info = program_instance->at(i);
LabelInfo* model_info = model_instance->at(i);
if ((model_info->assignment_ == NULL) !=
@@ -1275,9 +1278,8 @@ class Adjuster : public AdjustmentMethod {
}
void ReferenceLabel(Trace* trace, Label* label, bool is_model) {
- trace->push_back(
- label_info_maker_.MakeLabelInfo(label, is_model,
- static_cast<uint32>(trace->size())));
+ trace->push_back(label_info_maker_.MakeLabelInfo(
+ label, is_model, static_cast<uint32_t>(trace->size())));
}
AssemblyProgram* prog_; // Program to be adjusted, owned by caller.
diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc
index f050390..0767892 100644
--- a/courgette/assembly_program.cc
+++ b/courgette/assembly_program.cc
@@ -5,6 +5,8 @@
#include "courgette/assembly_program.h"
#include <memory.h>
+#include <stddef.h>
+#include <stdint.h>
#include <algorithm>
#include <map>
#include <set>
@@ -52,22 +54,20 @@ class ElfARMRelocsInstruction : public Instruction {
// Emits a single byte.
class ByteInstruction : public Instruction {
public:
- explicit ByteInstruction(uint8 value) : Instruction(DEFBYTE, value) {}
- uint8 byte_value() const { return info_; }
+ explicit ByteInstruction(uint8_t value) : Instruction(DEFBYTE, value) {}
+ uint8_t byte_value() const { return info_; }
};
// Emits a single byte.
class BytesInstruction : public Instruction {
public:
- BytesInstruction(const uint8* values, size_t len)
- : Instruction(DEFBYTES, 0),
- values_(values),
- len_(len) {}
- const uint8* byte_values() const { return values_; }
+ BytesInstruction(const uint8_t* values, size_t len)
+ : Instruction(DEFBYTES, 0), values_(values), len_(len) {}
+ const uint8_t* byte_values() const { return values_; }
size_t len() const { return len_; }
private:
- const uint8* values_;
+ const uint8_t* values_;
size_t len_;
};
@@ -87,19 +87,25 @@ class InstructionWithLabel : public Instruction {
// a specially-compressed ARM op.
class InstructionWithLabelARM : public InstructionWithLabel {
public:
- InstructionWithLabelARM(OP op, uint16 compressed_op, Label* label,
- const uint8* arm_op, uint16 op_size)
- : InstructionWithLabel(op, label), compressed_op_(compressed_op),
- arm_op_(arm_op), op_size_(op_size) {
+ InstructionWithLabelARM(OP op,
+ uint16_t compressed_op,
+ Label* label,
+ const uint8_t* arm_op,
+ uint16_t op_size)
+ : InstructionWithLabel(op, label),
+ compressed_op_(compressed_op),
+ arm_op_(arm_op),
+ op_size_(op_size) {
if (label == NULL) NOTREACHED();
}
- uint16 compressed_op() const { return compressed_op_; }
- const uint8* arm_op() const { return arm_op_; }
- uint16 op_size() const { return op_size_; }
+ uint16_t compressed_op() const { return compressed_op_; }
+ const uint8_t* arm_op() const { return arm_op_; }
+ uint16_t op_size() const { return op_size_; }
+
private:
- uint16 compressed_op_;
- const uint8* arm_op_;
- uint16 op_size_;
+ uint16_t compressed_op_;
+ const uint8_t* arm_op_;
+ uint16_t op_size_;
};
} // namespace
@@ -143,11 +149,11 @@ CheckBool AssemblyProgram::EmitOriginInstruction(RVA rva) {
return Emit(ScopedInstruction(UncheckedNew<OriginInstruction>(rva)));
}
-CheckBool AssemblyProgram::EmitByteInstruction(uint8 byte) {
+CheckBool AssemblyProgram::EmitByteInstruction(uint8_t byte) {
return EmitShared(GetByteInstruction(byte));
}
-CheckBool AssemblyProgram::EmitBytesInstruction(const uint8* values,
+CheckBool AssemblyProgram::EmitBytesInstruction(const uint8_t* values,
size_t len) {
return Emit(ScopedInstruction(UncheckedNew<BytesInstruction>(values, len)));
}
@@ -157,8 +163,10 @@ CheckBool AssemblyProgram::EmitRel32(Label* label) {
ScopedInstruction(UncheckedNew<InstructionWithLabel>(REL32, label)));
}
-CheckBool AssemblyProgram::EmitRel32ARM(uint16 op, Label* label,
- const uint8* arm_op, uint16 op_size) {
+CheckBool AssemblyProgram::EmitRel32ARM(uint16_t op,
+ Label* label,
+ const uint8_t* arm_op,
+ uint16_t op_size) {
return Emit(ScopedInstruction(UncheckedNew<InstructionWithLabelARM>(
REL32ARM, op, label, arm_op, op_size)));
}
@@ -324,7 +332,7 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
if (prev)
prev_index = prev->index_;
else
- prev_index = static_cast<uint32>(available.size());
+ prev_index = static_cast<uint32_t>(available.size());
if (prev_index != 0 &&
prev_index != Label::kNoIndex &&
available.at(prev_index - 1)) {
@@ -400,14 +408,14 @@ EncodedProgram* AssemblyProgram::Encode() const {
break;
}
case DEFBYTE: {
- uint8 b = static_cast<ByteInstruction*>(instruction)->byte_value();
+ uint8_t b = static_cast<ByteInstruction*>(instruction)->byte_value();
if (!encoded->AddCopy(1, &b))
return NULL;
break;
}
case DEFBYTES: {
- const uint8* byte_values =
- static_cast<BytesInstruction*>(instruction)->byte_values();
+ const uint8_t* byte_values =
+ static_cast<BytesInstruction*>(instruction)->byte_values();
size_t len = static_cast<BytesInstruction*>(instruction)->len();
if (!encoded->AddCopy(len, byte_values))
@@ -423,9 +431,8 @@ EncodedProgram* AssemblyProgram::Encode() const {
case REL32ARM: {
Label* label =
static_cast<InstructionWithLabelARM*>(instruction)->label();
- uint16 compressed_op =
- static_cast<InstructionWithLabelARM*>(instruction)->
- compressed_op();
+ uint16_t compressed_op =
+ static_cast<InstructionWithLabelARM*>(instruction)->compressed_op();
if (!encoded->AddRel32ARM(compressed_op, label->index_))
return NULL;
break;
@@ -466,7 +473,7 @@ EncodedProgram* AssemblyProgram::Encode() const {
return encoded.release();
}
-Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
+Instruction* AssemblyProgram::GetByteInstruction(uint8_t byte) {
if (!byte_instruction_cache_) {
Instruction** ram = nullptr;
if (!base::UncheckedMalloc(sizeof(Instruction*) * 256,
@@ -477,7 +484,7 @@ Instruction* AssemblyProgram::GetByteInstruction(uint8 byte) {
for (int i = 0; i < 256; ++i) {
byte_instruction_cache_[i] =
- UncheckedNew<ByteInstruction>(static_cast<uint8>(i));
+ UncheckedNew<ByteInstruction>(static_cast<uint8_t>(i));
if (!byte_instruction_cache_[i]) {
for (int j = 0; j < i; ++j)
UncheckedDelete(byte_instruction_cache_[j]);
@@ -526,9 +533,9 @@ CheckBool AssemblyProgram::TrimLabels() {
Label* label =
static_cast<InstructionWithLabelARM*>(instruction)->label();
if (label->count_ <= lower_limit) {
- const uint8* arm_op =
+ const uint8_t* arm_op =
static_cast<InstructionWithLabelARM*>(instruction)->arm_op();
- uint16 op_size =
+ uint16_t op_size =
static_cast<InstructionWithLabelARM*>(instruction)->op_size();
if (op_size < 1)
diff --git a/courgette/assembly_program.h b/courgette/assembly_program.h
index 88cf2e8..36dc369 100644
--- a/courgette/assembly_program.h
+++ b/courgette/assembly_program.h
@@ -5,13 +5,15 @@
#ifndef COURGETTE_ASSEMBLY_PROGRAM_H_
#define COURGETTE_ASSEMBLY_PROGRAM_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include <map>
#include <set>
#include <vector>
-#include "base/basictypes.h"
+#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-
#include "courgette/disassembler.h"
#include "courgette/image_utils.h"
#include "courgette/memory_allocator.h"
@@ -47,8 +49,8 @@ class Instruction {
explicit Instruction(OP op) : op_(op), info_(0) {}
Instruction(OP op, unsigned int info) : op_(op), info_(info) {}
- uint32 op_ : 4; // A few bits to store the OP code.
- uint32 info_ : 28; // Remaining bits in first word available to subclass.
+ uint32_t op_ : 4; // A few bits to store the OP code.
+ uint32_t info_ : 28; // Remaining bits in first word available to subclass.
private:
DISALLOW_COPY_AND_ASSIGN(Instruction);
@@ -82,7 +84,7 @@ class AssemblyProgram {
ExecutableType kind() const { return kind_; }
- void set_image_base(uint64 image_base) { image_base_ = image_base; }
+ void set_image_base(uint64_t image_base) { image_base_ = image_base; }
// Instructions will be assembled in the order they are emitted.
@@ -99,19 +101,21 @@ class AssemblyProgram {
CheckBool EmitOriginInstruction(RVA rva) WARN_UNUSED_RESULT;
// Generates a single byte of data or machine instruction.
- CheckBool EmitByteInstruction(uint8 byte) WARN_UNUSED_RESULT;
+ CheckBool EmitByteInstruction(uint8_t byte) WARN_UNUSED_RESULT;
// Generates multiple bytes of data or machine instructions.
- CheckBool EmitBytesInstruction(const uint8* value, size_t len)
- WARN_UNUSED_RESULT;
+ CheckBool EmitBytesInstruction(const uint8_t* value,
+ size_t len) WARN_UNUSED_RESULT;
// Generates 4-byte relative reference to address of 'label'.
CheckBool EmitRel32(Label* label) WARN_UNUSED_RESULT;
// Generates 4-byte relative reference to address of 'label' for
// ARM.
- CheckBool EmitRel32ARM(uint16 op, Label* label, const uint8* arm_op,
- uint16 op_size) WARN_UNUSED_RESULT;
+ CheckBool EmitRel32ARM(uint16_t op,
+ Label* label,
+ const uint8_t* arm_op,
+ uint16_t op_size) WARN_UNUSED_RESULT;
// Generates 4-byte absolute reference to address of 'label'.
CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT;
@@ -171,10 +175,10 @@ class AssemblyProgram {
static void AssignRemainingIndexes(RVAToLabel* labels);
// Sharing instructions that emit a single byte saves a lot of space.
- Instruction* GetByteInstruction(uint8 byte);
+ Instruction* GetByteInstruction(uint8_t byte);
scoped_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_;
- uint64 image_base_; // Desired or mandated base address of image.
+ uint64_t image_base_; // Desired or mandated base address of image.
InstructionVector instructions_; // All the instructions in program.
diff --git a/courgette/bsdiff_memory_unittest.cc b/courgette/bsdiff_memory_unittest.cc
index fe9fae6..5274565 100644
--- a/courgette/bsdiff_memory_unittest.cc
+++ b/courgette/bsdiff_memory_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/third_party/bsdiff.h"
+#include <stddef.h>
+
#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
diff --git a/courgette/consecutive_range_visitor.h b/courgette/consecutive_range_visitor.h
index 562409d..f911154 100644
--- a/courgette/consecutive_range_visitor.h
+++ b/courgette/consecutive_range_visitor.h
@@ -5,6 +5,8 @@
#ifndef COURGETTE_CONSECUTIVE_RANGE_VISITOR_H_
#define COURGETTE_CONSECUTIVE_RANGE_VISITOR_H_
+#include <stddef.h>
+
#include <iterator>
#include "base/macros.h"
diff --git a/courgette/consecutive_range_visitor_unittest.cc b/courgette/consecutive_range_visitor_unittest.cc
index 648a6d7..7e38b05 100644
--- a/courgette/consecutive_range_visitor_unittest.cc
+++ b/courgette/consecutive_range_visitor_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/consecutive_range_visitor.h"
+#include <stddef.h>
+
#include <string>
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc
index 962e078..88c346b 100644
--- a/courgette/courgette_tool.cc
+++ b/courgette/courgette_tool.cc
@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stddef.h>
+#include <stdint.h>
+
#include <string>
#include <vector>
#include "base/at_exit.h"
-#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@@ -48,7 +50,7 @@ void Problem(const char* format, ...) {
}
std::string ReadOrFail(const base::FilePath& file_name, const char* kind) {
- int64 file_size = 0;
+ int64_t file_size = 0;
if (!base::GetFileSize(file_name, &file_size))
Problem("Can't read %s file.", kind);
std::string buffer;
diff --git a/courgette/crc.cc b/courgette/crc.cc
index 28a0f9c..2b86b68 100644
--- a/courgette/crc.cc
+++ b/courgette/crc.cc
@@ -4,6 +4,9 @@
#include "courgette/crc.h"
+#include <stdint.h>
+#include <stddef.h>
+
#ifdef COURGETTE_USE_CRC_LIB
# include "zlib.h"
#else
@@ -12,12 +15,11 @@ extern "C" {
}
#endif
-#include "base/basictypes.h"
namespace courgette {
-uint32 CalculateCrc(const uint8* buffer, size_t size) {
- uint32 crc;
+uint32_t CalculateCrc(const uint8_t* buffer, size_t size) {
+ uint32_t crc;
#ifdef COURGETTE_USE_CRC_LIB
// Calculate Crc by calling CRC method in zlib
diff --git a/courgette/crc.h b/courgette/crc.h
index c3662bb..b0c3323 100644
--- a/courgette/crc.h
+++ b/courgette/crc.h
@@ -5,13 +5,14 @@
#ifndef COURGETTE_CRC_H_
#define COURGETTE_CRC_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
namespace courgette {
// Calculates Crc of the given buffer by calling CRC method in LZMA SDK
//
-uint32 CalculateCrc(const uint8* buffer, size_t size);
+uint32_t CalculateCrc(const uint8_t* buffer, size_t size);
} // namespace courgette
#endif // COURGETTE_CRC_H_
diff --git a/courgette/difference_estimator.cc b/courgette/difference_estimator.cc
index 82c23ee..8b7aa29 100644
--- a/courgette/difference_estimator.cc
+++ b/courgette/difference_estimator.cc
@@ -8,7 +8,11 @@
#include "courgette/difference_estimator.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "base/containers/hash_tables.h"
+#include "base/macros.h"
namespace courgette {
@@ -21,9 +25,9 @@ namespace {
static_assert(kTupleSize >= 4 && kTupleSize <= 8,
"kTupleSize should be between 4 and 8");
-size_t HashTuple(const uint8* source) {
- size_t hash1 = *reinterpret_cast<const uint32*>(source);
- size_t hash2 = *reinterpret_cast<const uint32*>(source + kTupleSize - 4);
+size_t HashTuple(const uint8_t* source) {
+ size_t hash1 = *reinterpret_cast<const uint32_t*>(source);
+ size_t hash2 = *reinterpret_cast<const uint32_t*>(source + kTupleSize - 4);
size_t hash = ((hash1 * 17 + hash2 * 37) + (hash1 >> 17)) ^ (hash2 >> 23);
return hash;
}
@@ -43,9 +47,9 @@ class DifferenceEstimator::Base {
void Init() {
if (region_.length() < kTupleSize)
return;
- const uint8* start = region_.start();
- const uint8* end = region_.end() - (kTupleSize - 1);
- for (const uint8* p = start; p < end; ++p) {
+ const uint8_t* start = region_.start();
+ const uint8_t* end = region_.end() - (kTupleSize - 1);
+ for (const uint8_t* p = start; p < end; ++p) {
size_t hash = HashTuple(p);
hashes_.insert(hash);
}
@@ -99,10 +103,10 @@ DifferenceEstimator::Subject* DifferenceEstimator::MakeSubject(
size_t DifferenceEstimator::Measure(Base* base, Subject* subject) {
size_t mismatches = 0;
if (subject->region().length() >= kTupleSize) {
- const uint8* start = subject->region().start();
- const uint8* end = subject->region().end() - (kTupleSize - 1);
+ const uint8_t* start = subject->region().start();
+ const uint8_t* end = subject->region().end() - (kTupleSize - 1);
- const uint8* p = start;
+ const uint8_t* p = start;
while (p < end) {
size_t hash = HashTuple(p);
if (base->hashes_.find(hash) == base->hashes_.end()) {
diff --git a/courgette/difference_estimator.h b/courgette/difference_estimator.h
index 295ff93..690c840 100644
--- a/courgette/difference_estimator.h
+++ b/courgette/difference_estimator.h
@@ -8,8 +8,11 @@
#ifndef COURGETTE_DIFFERENCE_ESTIMATOR_H_
#define COURGETTE_DIFFERENCE_ESTIMATOR_H_
+#include <stddef.h>
+
#include <vector>
+#include "base/macros.h"
#include "courgette/region.h"
namespace courgette {
diff --git a/courgette/disassembler.cc b/courgette/disassembler.cc
index f146b4e..363d6e4 100644
--- a/courgette/disassembler.cc
+++ b/courgette/disassembler.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "courgette/assembly_program.h"
@@ -101,15 +103,14 @@ void DeleteAssemblyProgram(AssemblyProgram* program) {
Disassembler::Disassembler(const void* start, size_t length)
: failure_reason_("uninitialized") {
-
- start_ = reinterpret_cast<const uint8*>(start);
+ start_ = reinterpret_cast<const uint8_t*>(start);
length_ = length;
end_ = start_ + length_;
};
Disassembler::~Disassembler() {};
-const uint8* Disassembler::OffsetToPointer(size_t offset) const {
+const uint8_t* Disassembler::OffsetToPointer(size_t offset) const {
assert(start_ + offset <= end_);
return start_ + offset;
}
diff --git a/courgette/disassembler.h b/courgette/disassembler.h
index abbec3a..e833cfa 100644
--- a/courgette/disassembler.h
+++ b/courgette/disassembler.h
@@ -5,8 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_H_
#define COURGETTE_DISASSEMBLER_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+#include "base/macros.h"
#include "courgette/courgette.h"
#include "courgette/image_utils.h"
@@ -34,12 +36,12 @@ class Disassembler {
// Returns the length of the source executable. May reduce after ParseHeader.
size_t length() const { return length_; }
- const uint8* start() const { return start_; }
- const uint8* end() const { return end_; }
+ const uint8_t* start() const { return start_; }
+ const uint8_t* end() const { return end_; }
// Returns a pointer into the memory copy of the file format.
// FileOffsetToPointer(0) returns a pointer to the start of the file format.
- const uint8* OffsetToPointer(size_t offset) const;
+ const uint8_t* OffsetToPointer(size_t offset) const;
protected:
Disassembler(const void* start, size_t length);
@@ -65,8 +67,8 @@ class Disassembler {
// the total data.
//
size_t length_; // In current memory.
- const uint8* start_; // In current memory, base for 'file offsets'.
- const uint8* end_; // In current memory.
+ const uint8_t* start_; // In current memory, base for 'file offsets'.
+ const uint8_t* end_; // In current memory.
DISALLOW_COPY_AND_ASSIGN(Disassembler);
};
diff --git a/courgette/disassembler_elf_32.cc b/courgette/disassembler_elf_32.cc
index be420d4..c6139a8 100644
--- a/courgette/disassembler_elf_32.cc
+++ b/courgette/disassembler_elf_32.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler_elf_32.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
@@ -182,7 +184,7 @@ CheckBool DisassemblerElf32::RVAToFileOffset(Elf32_Addr addr,
RVA DisassemblerElf32::FileOffsetToRVA(size_t offset) const {
// File offsets can be 64 bit values, but we are dealing with 32
// bit executables and so only need to support 32bit file sizes.
- uint32 offset32 = (uint32)offset;
+ uint32_t offset32 = (uint32_t)offset;
for (int i = 0; i < SectionHeaderCount(); i++) {
@@ -240,7 +242,7 @@ CheckBool DisassemblerElf32::RVAsToOffsets(ScopedVector<TypedRVA>* rvas) {
CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
// Walk all the bytes in the file, whether or not in a section.
- uint32 file_offset = 0;
+ uint32_t file_offset = 0;
std::vector<size_t> abs_offsets;
@@ -370,8 +372,7 @@ CheckBool DisassemblerElf32::ParseProgbitsSection(
if (*current_abs_offset != end_abs_offset &&
file_offset == **current_abs_offset) {
-
- const uint8* p = OffsetToPointer(file_offset);
+ const uint8_t* p = OffsetToPointer(file_offset);
RVA target_rva = Read32LittleEndian(p);
if (!program->EmitAbs32(program->FindOrMakeAbs32Label(target_rva)))
@@ -383,8 +384,7 @@ CheckBool DisassemblerElf32::ParseProgbitsSection(
if (*current_rel != end_rel &&
file_offset == (**current_rel)->get_offset()) {
-
- uint32 relative_target = (**current_rel)->relative_target();
+ uint32_t relative_target = (**current_rel)->relative_target();
// This cast is for 64 bit systems, and is only safe because we
// are working on 32 bit executables.
RVA target_rva = (RVA)(origin + (file_offset - origin_offset) +
diff --git a/courgette/disassembler_elf_32.h b/courgette/disassembler_elf_32.h
index 608c73a..110dd71 100644
--- a/courgette/disassembler_elf_32.h
+++ b/courgette/disassembler_elf_32.h
@@ -5,7 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_ELF_32_H_
#define COURGETTE_DISASSEMBLER_ELF_32_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "courgette/assembly_program.h"
#include "courgette/disassembler.h"
@@ -56,13 +59,13 @@ class DisassemblerElf32 : public Disassembler {
}
// Computes the relative jump's offset from the op in p.
- virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer) = 0;
+ virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0;
// Emits the courgette instruction corresponding to the RVA type.
virtual CheckBool EmitInstruction(AssemblyProgram* program,
RVA target_rva) = 0;
- virtual uint16 op_size() const = 0;
+ virtual uint16_t op_size() const = 0;
static bool IsLessThan(TypedRVA *a, TypedRVA *b) {
return a->rva() < b->rva();
@@ -109,7 +112,7 @@ class DisassemblerElf32 : public Disassembler {
return section_header_table_ + id;
}
- const uint8 *SectionBody(int id) const {
+ const uint8_t* SectionBody(int id) const {
return OffsetToPointer(SectionHeader(id)->sh_offset);
}
diff --git a/courgette/disassembler_elf_32_arm.cc b/courgette/disassembler_elf_32_arm.cc
index 800a64c..f6490d9 100644
--- a/courgette/disassembler_elf_32_arm.cc
+++ b/courgette/disassembler_elf_32_arm.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler_elf_32_arm.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "courgette/assembly_program.h"
@@ -17,8 +19,11 @@
namespace courgette {
-CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
- uint16* c_op, uint32* addr) {
+CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type,
+ uint32_t arm_op,
+ RVA rva,
+ uint16_t* c_op,
+ uint32_t* addr) {
// This method takes an ARM or thumb opcode, extracts the relative
// target address from it (addr), and creates a corresponding
// Courgette opcode (c_op).
@@ -31,32 +36,32 @@ CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
case ARM_OFF8: {
// The offset is given by lower 8 bits of the op. It is a 9-bit
// offset, shifted right one bit and signed extended.
- uint32 temp = (arm_op & 0x00FF) << 1;
+ uint32_t temp = (arm_op & 0x00FF) << 1;
if (temp & 0x0100)
temp |= 0xFFFFFE00;
temp += 4; // Offset from _next_ PC.
fflush(stdout);
(*addr) = temp;
- (*c_op) = static_cast<uint16>(arm_op >> 8) | 0x1000;
+ (*c_op) = static_cast<uint16_t>(arm_op >> 8) | 0x1000;
break;
}
case ARM_OFF11: {
// The offset is given by lower 11 bits of the op, and is a
// 12-bit offset, shifted right one bit and sign extended.
- uint32 temp = (arm_op & 0x07FF) << 1;
+ uint32_t temp = (arm_op & 0x07FF) << 1;
if (temp & 0x00000800)
temp |= 0xFFFFF000;
temp += 4; // Offset from _next_ PC.
(*addr) = temp;
- (*c_op) = static_cast<uint16>(arm_op >> 11) | 0x2000;
+ (*c_op) = static_cast<uint16_t>(arm_op >> 11) | 0x2000;
break;
}
case ARM_OFF24: {
// The offset is given by the lower 24-bits of the op, shifted
// left 2 bits, and sign extended.
- uint32 temp = (arm_op & 0x00FFFFFF) << 2;
+ uint32_t temp = (arm_op & 0x00FFFFFF) << 2;
if (temp & 0x02000000)
temp |= 0xFC000000;
temp += 8;
@@ -66,28 +71,28 @@ CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
break;
}
case ARM_OFF25: {
- uint32 temp = 0;
+ uint32_t temp = 0;
temp |= (arm_op & 0x000007FF) << 1; // imm11
temp |= (arm_op & 0x03FF0000) >> 4; // imm10
- uint32 S = (arm_op & (1 << 26)) >> 26;
- uint32 j2 = (arm_op & (1 << 11)) >> 11;
- uint32 j1 = (arm_op & (1 << 13)) >> 13;
+ uint32_t S = (arm_op & (1 << 26)) >> 26;
+ uint32_t j2 = (arm_op & (1 << 11)) >> 11;
+ uint32_t j1 = (arm_op & (1 << 13)) >> 13;
bool bit12 = ((arm_op & (1 << 12)) >> 12) != 0;
bool bit14 = ((arm_op & (1 << 14)) >> 14) != 0;
- uint32 i2 = ~(j2 ^ S) & 1;
- uint32 i1 = ~(j1 ^ S) & 1;
+ uint32_t i2 = ~(j2 ^ S) & 1;
+ uint32_t i1 = ~(j1 ^ S) & 1;
bool toARM = bit14 && !bit12;
temp |= (S << 24) | (i1 << 23) | (i2 << 22);
if (temp & 0x01000000) // sign extension
temp |= 0xFE000000;
- uint32 prefetch;
+ uint32_t prefetch;
if (toARM) {
// Align PC on 4-byte boundary
- uint32 align4byte = (rva % 4) ? 2 : 4;
+ uint32_t align4byte = (rva % 4) ? 2 : 4;
prefetch = align4byte;
} else {
prefetch = 4;
@@ -95,23 +100,23 @@ CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
temp += prefetch;
(*addr) = temp;
- uint32 temp2 = 0x4000;
+ uint32_t temp2 = 0x4000;
temp2 |= (arm_op & (1 << 12)) >> 12;
temp2 |= (arm_op & (1 << 14)) >> 13;
temp2 |= (arm_op & (1 << 15)) >> 13;
temp2 |= (arm_op & 0xF8000000) >> 24;
temp2 |= (prefetch & 0x0000000F) << 8;
- (*c_op) = static_cast<uint16>(temp2);
+ (*c_op) = static_cast<uint16_t>(temp2);
break;
}
case ARM_OFF21: {
- uint32 temp = 0;
+ uint32_t temp = 0;
temp |= (arm_op & 0x000007FF) << 1; // imm11
temp |= (arm_op & 0x003F0000) >> 4; // imm6
- uint32 S = (arm_op & (1 << 26)) >> 26;
- uint32 j2 = (arm_op & (1 << 11)) >> 11;
- uint32 j1 = (arm_op & (1 << 13)) >> 13;
+ uint32_t S = (arm_op & (1 << 26)) >> 26;
+ uint32_t j2 = (arm_op & (1 << 11)) >> 11;
+ uint32_t j1 = (arm_op & (1 << 13)) >> 13;
temp |= (S << 20) | (j1 << 19) | (j2 << 18);
@@ -120,9 +125,9 @@ CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
temp += 4;
(*addr) = temp;
- uint32 temp2 = 0x5000;
+ uint32_t temp2 = 0x5000;
temp2 |= (arm_op & 0x03C00000) >> 22; // just save the cond
- (*c_op) = static_cast<uint16>(temp2);
+ (*c_op) = static_cast<uint16_t>(temp2);
break;
}
default:
@@ -131,8 +136,10 @@ CheckBool DisassemblerElf32ARM::Compress(ARM_RVA type, uint32 arm_op, RVA rva,
return true;
}
-CheckBool DisassemblerElf32ARM::Decompress(ARM_RVA type, uint16 c_op,
- uint32 addr, uint32* arm_op) {
+CheckBool DisassemblerElf32ARM::Decompress(ARM_RVA type,
+ uint16_t c_op,
+ uint32_t addr,
+ uint32_t* arm_op) {
// Reverses the process in the compress() method. Takes the
// Courgette op and relative address and reconstructs the original
// ARM or thumb op.
@@ -147,23 +154,23 @@ CheckBool DisassemblerElf32ARM::Decompress(ARM_RVA type, uint16 c_op,
(*arm_op) = ((c_op & 0x0FFF) << 24) | (((addr - 8) >> 2) & 0x00FFFFFF);
break;
case ARM_OFF25: {
- uint32 temp = 0;
+ uint32_t temp = 0;
temp |= (c_op & (1 << 0)) << 12;
temp |= (c_op & (1 << 1)) << 13;
temp |= (c_op & (1 << 2)) << 13;
temp |= (c_op & (0xF8000000 >> 24)) << 24;
- uint32 prefetch = (c_op & 0x0F00) >> 8;
+ uint32_t prefetch = (c_op & 0x0F00) >> 8;
addr -= prefetch;
addr &= 0x01FFFFFF;
- uint32 S = (addr & (1 << 24)) >> 24;
- uint32 i1 = (addr & (1 << 23)) >> 23;
- uint32 i2 = (addr & (1 << 22)) >> 22;
+ uint32_t S = (addr & (1 << 24)) >> 24;
+ uint32_t i1 = (addr & (1 << 23)) >> 23;
+ uint32_t i2 = (addr & (1 << 22)) >> 22;
- uint32 j1 = ((~i1) ^ S) & 1;
- uint32 j2 = ((~i2) ^ S) & 1;
+ uint32_t j1 = ((~i1) ^ S) & 1;
+ uint32_t j2 = ((~i2) ^ S) & 1;
temp |= S << 26;
temp |= j2 << 11;
@@ -176,15 +183,15 @@ CheckBool DisassemblerElf32ARM::Decompress(ARM_RVA type, uint16 c_op,
break;
}
case ARM_OFF21: {
- uint32 temp = 0xF0008000;
+ uint32_t temp = 0xF0008000;
temp |= (c_op & (0x03C00000 >> 22)) << 22;
addr -= 4;
addr &= 0x001FFFFF;
- uint32 S = (addr & (1 << 20)) >> 20;
- uint32 j1 = (addr & (1 << 19)) >> 19;
- uint32 j2 = (addr & (1 << 18)) >> 18;
+ uint32_t S = (addr & (1 << 20)) >> 20;
+ uint32_t j1 = (addr & (1 << 19)) >> 19;
+ uint32_t j2 = (addr & (1 << 18)) >> 18;
temp |= S << 26;
temp |= j2 << 11;
@@ -202,7 +209,7 @@ CheckBool DisassemblerElf32ARM::Decompress(ARM_RVA type, uint16 c_op,
return true;
}
-uint16 DisassemblerElf32ARM::TypedRVAARM::op_size() const {
+uint16_t DisassemblerElf32ARM::TypedRVAARM::op_size() const {
switch (type_) {
case ARM_OFF8:
return 2;
@@ -220,7 +227,7 @@ uint16 DisassemblerElf32ARM::TypedRVAARM::op_size() const {
}
CheckBool DisassemblerElf32ARM::TypedRVAARM::ComputeRelativeTarget(
- const uint8* op_pointer) {
+ const uint8_t* op_pointer) {
arm_op_ = op_pointer;
switch (type_) {
case ARM_OFF8:
@@ -243,8 +250,8 @@ CheckBool DisassemblerElf32ARM::TypedRVAARM::ComputeRelativeTarget(
// Fall through
case ARM_OFF21: {
// A thumb-2 op is 32 bits stored as two 16-bit words
- uint32 pval = (Read16LittleEndian(op_pointer) << 16)
- | Read16LittleEndian(op_pointer + 2);
+ uint32_t pval = (Read16LittleEndian(op_pointer) << 16) |
+ Read16LittleEndian(op_pointer + 2);
RVA relative_target;
CheckBool ret = Compress(type_, pval, rva(), &c_op_, &relative_target);
set_relative_target(relative_target);
@@ -276,7 +283,7 @@ CheckBool DisassemblerElf32ARM::RelToRVA(Elf32_Rel rel, RVA* result) const {
(elf32_rel_arm_type_values)(unsigned char)rel.r_info;
// The other 3 bytes of r_info are the symbol
- uint32 symbol = rel.r_info >> 8;
+ uint32_t symbol = rel.r_info >> 8;
switch(type)
{
@@ -321,8 +328,8 @@ CheckBool DisassemblerElf32ARM::ParseRelocationSection(
Elf32_Rel *section_relocs_iter =
(Elf32_Rel *)OffsetToPointer(section_header->sh_offset);
- uint32 section_relocs_count = section_header->sh_size /
- section_header->sh_entsize;
+ uint32_t section_relocs_count =
+ section_header->sh_size / section_header->sh_entsize;
if (abs32_locations_.size() > section_relocs_count)
match = false;
@@ -330,7 +337,7 @@ CheckBool DisassemblerElf32ARM::ParseRelocationSection(
if (!abs32_locations_.empty()) {
std::vector<RVA>::iterator reloc_iter = abs32_locations_.begin();
- for (uint32 i = 0; i < section_relocs_count; i++) {
+ for (uint32_t i = 0; i < section_relocs_count; i++) {
if (section_relocs_iter->r_offset == *reloc_iter)
break;
@@ -364,20 +371,19 @@ CheckBool DisassemblerElf32ARM::ParseRelocationSection(
CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
const Elf32_Shdr* section_header) {
+ uint32_t start_file_offset = section_header->sh_offset;
+ uint32_t end_file_offset = start_file_offset + section_header->sh_size;
- uint32 start_file_offset = section_header->sh_offset;
- uint32 end_file_offset = start_file_offset + section_header->sh_size;
-
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer -
- section_header->sh_addr;
+ const uint8_t* const adjust_pointer_to_rva =
+ start_pointer - section_header->sh_addr;
// Find the rel32 relocations.
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
bool on_32bit = 1; // 32-bit ARM ops appear on 32-bit boundaries, so track it
while (p < end_pointer) {
// Heuristic discovery of rel32 locations in instruction stream: are the
@@ -390,12 +396,12 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
// 16-bit thumb ops
if (!found && (p + 3) <= end_pointer) {
- uint16 pval = Read16LittleEndian(p);
+ uint16_t pval = Read16LittleEndian(p);
if ((pval & 0xF000) == 0xD000) {
RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva);
rel32_rva = new TypedRVAARM(ARM_OFF8, rva);
- if (!rel32_rva->ComputeRelativeTarget((uint8*) p)) {
+ if (!rel32_rva->ComputeRelativeTarget((uint8_t*)p)) {
return false;
}
target_rva = rel32_rva->rva() + rel32_rva->relative_target();
@@ -404,7 +410,7 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva);
rel32_rva = new TypedRVAARM(ARM_OFF11, rva);
- if (!rel32_rva->ComputeRelativeTarget((uint8*) p)) {
+ if (!rel32_rva->ComputeRelativeTarget((uint8_t*)p)) {
return false;
}
target_rva = rel32_rva->rva() + rel32_rva->relative_target();
@@ -415,7 +421,7 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
// thumb-2 ops comprised of two 16-bit words
if (!found && (p + 5) <= end_pointer) {
// This is really two 16-bit words, not one 32-bit word.
- uint32 pval = (Read16LittleEndian(p) << 16) | Read16LittleEndian(p + 2);
+ uint32_t pval = (Read16LittleEndian(p) << 16) | Read16LittleEndian(p + 2);
if ((pval & 0xF8008000) == 0xF0008000) {
// Covers thumb-2's 32-bit conditional/unconditional branches
@@ -424,7 +430,7 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva);
rel32_rva = new TypedRVAARM(ARM_OFF25, rva);
- if (!rel32_rva->ComputeRelativeTarget((uint8*) p)) {
+ if (!rel32_rva->ComputeRelativeTarget((uint8_t*)p)) {
return false;
}
target_rva = rel32_rva->rva() + rel32_rva->relative_target();
@@ -435,7 +441,7 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva);
rel32_rva = new TypedRVAARM(ARM_OFF21, rva);
- if (!rel32_rva->ComputeRelativeTarget((uint8*) p)) {
+ if (!rel32_rva->ComputeRelativeTarget((uint8_t*)p)) {
return false;
}
target_rva = rel32_rva->rva() + rel32_rva->relative_target();
@@ -446,13 +452,13 @@ CheckBool DisassemblerElf32ARM::ParseRel32RelocsFromSection(
// 32-bit ARM ops
if (!found && on_32bit && (p + 5) <= end_pointer) {
- uint32 pval = Read32LittleEndian(p);
+ uint32_t pval = Read32LittleEndian(p);
if ((pval & 0x0E000000) == 0x0A000000) {
// Covers both 0x0A 0x0B ARM relative branches
RVA rva = static_cast<RVA>(p - adjust_pointer_to_rva);
rel32_rva = new TypedRVAARM(ARM_OFF24, rva);
- if (!rel32_rva->ComputeRelativeTarget((uint8*) p)) {
+ if (!rel32_rva->ComputeRelativeTarget((uint8_t*)p)) {
return false;
}
target_rva = rel32_rva->rva() + rel32_rva->relative_target();
diff --git a/courgette/disassembler_elf_32_arm.h b/courgette/disassembler_elf_32_arm.h
index 8a64766..17ebb25 100644
--- a/courgette/disassembler_elf_32_arm.h
+++ b/courgette/disassembler_elf_32_arm.h
@@ -5,7 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
#define COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/macros.h"
#include "courgette/disassembler_elf_32.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_elf.h"
@@ -28,22 +31,20 @@ class DisassemblerElf32ARM : public DisassemblerElf32 {
public:
TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { }
- uint16 c_op() const {
- return c_op_;
- }
+ uint16_t c_op() const { return c_op_; }
- virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer);
+ virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer);
virtual CheckBool EmitInstruction(AssemblyProgram* program,
RVA target_rva);
- virtual uint16 op_size() const;
+ virtual uint16_t op_size() const;
private:
ARM_RVA type_;
- uint16 c_op_; // set by ComputeRelativeTarget()
- const uint8* arm_op_;
+ uint16_t c_op_; // set by ComputeRelativeTarget()
+ const uint8_t* arm_op_;
};
explicit DisassemblerElf32ARM(const void* start, size_t length);
@@ -52,11 +53,16 @@ class DisassemblerElf32ARM : public DisassemblerElf32 {
virtual e_machine_values ElfEM() { return EM_ARM; }
- static CheckBool Compress(ARM_RVA type, uint32 arm_op, RVA rva,
- uint16* c_op /* out */, uint32* addr /* out */);
+ static CheckBool Compress(ARM_RVA type,
+ uint32_t arm_op,
+ RVA rva,
+ uint16_t* c_op /* out */,
+ uint32_t* addr /* out */);
- static CheckBool Decompress(ARM_RVA type, uint16 c_op, uint32 addr,
- uint32* arm_op /* out */);
+ static CheckBool Decompress(ARM_RVA type,
+ uint16_t c_op,
+ uint32_t addr,
+ uint32_t* arm_op /* out */);
protected:
diff --git a/courgette/disassembler_elf_32_x86.cc b/courgette/disassembler_elf_32_x86.cc
index da389a4..98084c1 100644
--- a/courgette/disassembler_elf_32_x86.cc
+++ b/courgette/disassembler_elf_32_x86.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler_elf_32_x86.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "courgette/assembly_program.h"
@@ -29,7 +31,7 @@ CheckBool DisassemblerElf32X86::RelToRVA(Elf32_Rel rel, RVA* result) const {
(elf32_rel_386_type_values)(unsigned char)rel.r_info;
// The other 3 bytes of r_info are the symbol
- uint32 symbol = rel.r_info >> 8;
+ uint32_t symbol = rel.r_info >> 8;
switch(type)
{
@@ -88,8 +90,8 @@ CheckBool DisassemblerElf32X86::ParseRelocationSection(
Elf32_Rel *section_relocs_iter =
(Elf32_Rel *)OffsetToPointer(section_header->sh_offset);
- uint32 section_relocs_count = section_header->sh_size /
- section_header->sh_entsize;
+ uint32_t section_relocs_count =
+ section_header->sh_size / section_header->sh_entsize;
if (abs32_locations_.empty())
match = false;
@@ -119,27 +121,26 @@ CheckBool DisassemblerElf32X86::ParseRelocationSection(
CheckBool DisassemblerElf32X86::ParseRel32RelocsFromSection(
const Elf32_Shdr* section_header) {
+ uint32_t start_file_offset = section_header->sh_offset;
+ uint32_t end_file_offset = start_file_offset + section_header->sh_size;
- uint32 start_file_offset = section_header->sh_offset;
- uint32 end_file_offset = start_file_offset + section_header->sh_size;
-
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer -
- section_header->sh_addr;
+ const uint8_t* const adjust_pointer_to_rva =
+ start_pointer - section_header->sh_addr;
// Find the rel32 relocations.
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
while (p < end_pointer) {
//RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
// Heuristic discovery of rel32 locations in instruction stream: are the
// next few bytes the start of an instruction containing a rel32
// addressing mode?
- const uint8* rel32 = NULL;
+ const uint8_t* rel32 = NULL;
if (p + 5 <= end_pointer) {
if (*p == 0xE8 || *p == 0xE9) { // jmp rel32 and call rel32
diff --git a/courgette/disassembler_elf_32_x86.h b/courgette/disassembler_elf_32_x86.h
index 913e93f..5c87d4c 100644
--- a/courgette/disassembler_elf_32_x86.h
+++ b/courgette/disassembler_elf_32_x86.h
@@ -5,7 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_ELF_32_X86_H_
#define COURGETTE_DISASSEMBLER_ELF_32_X86_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/macros.h"
#include "courgette/disassembler_elf_32.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_elf.h"
@@ -21,7 +24,7 @@ class DisassemblerElf32X86 : public DisassemblerElf32 {
explicit TypedRVAX86(RVA rva) : TypedRVA(rva) {
}
- CheckBool ComputeRelativeTarget(const uint8* op_pointer) override {
+ CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override {
set_relative_target(Read32LittleEndian(op_pointer) + 4);
return true;
}
@@ -31,7 +34,7 @@ class DisassemblerElf32X86 : public DisassemblerElf32 {
return program->EmitRel32(program->FindOrMakeRel32Label(target_rva));
}
- uint16 op_size() const override { return 4; }
+ uint16_t op_size() const override { return 4; }
};
explicit DisassemblerElf32X86(const void* start, size_t length);
diff --git a/courgette/disassembler_elf_32_x86_unittest.cc b/courgette/disassembler_elf_32_x86_unittest.cc
index d48bc4f..3ce6a63 100644
--- a/courgette/disassembler_elf_32_x86_unittest.cc
+++ b/courgette/disassembler_elf_32_x86_unittest.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stddef.h>
+#include <stdint.h>
+
#include "courgette/assembly_program.h"
#include "courgette/base_test_unittest.h"
#include "courgette/disassembler_elf_32_x86.h"
@@ -30,7 +33,7 @@ void DisassemblerElf32X86Test::TestExe(const char* file_name,
// real file, since trailing debug info is not included
EXPECT_EQ(file1.length(), disassembler->length());
- const uint8* offset_p = disassembler->OffsetToPointer(0);
+ const uint8_t* offset_p = disassembler->OffsetToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(offset_p));
EXPECT_EQ(0x7F, offset_p[0]);
diff --git a/courgette/disassembler_win32_x64.cc b/courgette/disassembler_win32_x64.cc
index 58e787b..357930d 100644
--- a/courgette/disassembler_win32_x64.cc
+++ b/courgette/disassembler_win32_x64.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler_win32_x64.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
@@ -55,13 +57,12 @@ bool DisassemblerWin32X64::ParseHeader() {
return Bad("Not MZ");
// offset from DOS header to PE header is stored in DOS header.
- uint32 offset = ReadU32(start(),
- kOffsetOfFileAddressOfNewExeHeader);
+ uint32_t offset = ReadU32(start(), kOffsetOfFileAddressOfNewExeHeader);
if (offset >= length())
return Bad("Bad offset to PE header");
- const uint8* const pe_header = OffsetToPointer(offset);
+ const uint8_t* const pe_header = OffsetToPointer(offset);
const size_t kMinPEHeaderSize = 4 /*signature*/ + kSizeOfCoffHeader;
if (pe_header <= start() ||
pe_header >= end() - kMinPEHeaderSize)
@@ -83,13 +84,13 @@ bool DisassemblerWin32X64::ParseHeader() {
// The second field of the IMAGE_NT_HEADERS is the COFF header.
// The COFF header is also called an IMAGE_FILE_HEADER
// http://msdn.microsoft.com/en-us/library/ms680313(VS.85).aspx
- const uint8* const coff_header = pe_header + 4;
+ const uint8_t* const coff_header = pe_header + 4;
machine_type_ = ReadU16(coff_header, 0);
number_of_sections_ = ReadU16(coff_header, 2);
size_of_optional_header_ = ReadU16(coff_header, 16);
// The rest of the IMAGE_NT_HEADERS is the IMAGE_OPTIONAL_HEADER(32|64)
- const uint8* const optional_header = coff_header + kSizeOfCoffHeader;
+ const uint8_t* const optional_header = coff_header + kSizeOfCoffHeader;
optional_header_ = optional_header;
if (optional_header + size_of_optional_header_ >= end())
@@ -99,7 +100,7 @@ bool DisassemblerWin32X64::ParseHeader() {
if (size_of_optional_header_ < 2)
return Bad("optional header no magic");
- uint16 magic = ReadU16(optional_header, 0);
+ uint16_t magic = ReadU16(optional_header, 0);
if (magic == kImageNtOptionalHdr32Magic) {
is_PE32_plus_ = false;
@@ -176,7 +177,7 @@ bool DisassemblerWin32X64::ParseHeader() {
if (memcmp(section->name, ".text", 6) == 0)
has_text_section_ = true;
- uint32 section_end =
+ uint32_t section_end =
section->file_offset_of_raw_data + section->size_of_raw_data;
if (section_end > detected_length)
detected_length = section_end;
@@ -229,8 +230,8 @@ bool DisassemblerWin32X64::ParseRelocs(std::vector<RVA> *relocs) {
// "The format of the base relocation data is somewhat quirky"
// at http://msdn.microsoft.com/en-us/library/ms809762.aspx
- const uint8* relocs_start = RVAToPointer(base_relocation_table_.address_);
- const uint8* relocs_end = relocs_start + relocs_size;
+ const uint8_t* relocs_start = RVAToPointer(base_relocation_table_.address_);
+ const uint8_t* relocs_end = relocs_start + relocs_size;
// Make sure entire base relocation table is within the buffer.
if (relocs_start < start() ||
@@ -240,17 +241,17 @@ bool DisassemblerWin32X64::ParseRelocs(std::vector<RVA> *relocs) {
return Bad(".relocs outside image");
}
- const uint8* block = relocs_start;
+ const uint8_t* block = relocs_start;
// Walk the variable sized blocks.
while (block + 8 < relocs_end) {
RVA page_rva = ReadU32(block, 0);
- uint32 size = ReadU32(block, 4);
+ uint32_t size = ReadU32(block, 4);
if (size < 8 || // Size includes header ...
size % 4 != 0) // ... and is word aligned.
return Bad("unreasonable relocs block");
- const uint8* end_entries = block + size;
+ const uint8_t* end_entries = block + size;
if (end_entries <= block ||
end_entries <= start() ||
@@ -258,8 +259,8 @@ bool DisassemblerWin32X64::ParseRelocs(std::vector<RVA> *relocs) {
return Bad(".relocs block outside image");
// Walk through the two-byte entries.
- for (const uint8* p = block + 8; p < end_entries; p += 2) {
- uint16 entry = ReadU16(p, 0);
+ for (const uint8_t* p = block + 8; p < end_entries; p += 2) {
+ uint16_t entry = ReadU16(p, 0);
int type = entry >> 12;
int offset = entry & 0xFFF;
@@ -287,7 +288,7 @@ bool DisassemblerWin32X64::ParseRelocs(std::vector<RVA> *relocs) {
const Section* DisassemblerWin32X64::RVAToSection(RVA rva) const {
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
- uint32 offset = rva - section->virtual_address;
+ uint32_t offset = rva - section->virtual_address;
if (offset < section->virtual_size) {
return section;
}
@@ -298,7 +299,7 @@ const Section* DisassemblerWin32X64::RVAToSection(RVA rva) const {
int DisassemblerWin32X64::RVAToFileOffset(RVA rva) const {
const Section* section = RVAToSection(rva);
if (section) {
- uint32 offset = rva - section->virtual_address;
+ uint32_t offset = rva - section->virtual_address;
if (offset < section->size_of_raw_data) {
return section->file_offset_of_raw_data + offset;
} else {
@@ -317,7 +318,7 @@ int DisassemblerWin32X64::RVAToFileOffset(RVA rva) const {
return kNoOffset;
}
-const uint8* DisassemblerWin32X64::RVAToPointer(RVA rva) const {
+const uint8_t* DisassemblerWin32X64::RVAToPointer(RVA rva) const {
int file_offset = RVAToFileOffset(rva);
if (file_offset == kNoOffset)
return NULL;
@@ -336,7 +337,7 @@ std::string DisassemblerWin32X64::SectionName(const Section* section) {
CheckBool DisassemblerWin32X64::ParseFile(AssemblyProgram* program) {
// Walk all the bytes in the file, whether or not in a section.
- uint32 file_offset = 0;
+ uint32_t file_offset = 0;
while (file_offset < length()) {
const Section* section = FindNextSection(file_offset);
if (section == NULL) {
@@ -346,14 +347,14 @@ CheckBool DisassemblerWin32X64::ParseFile(AssemblyProgram* program) {
break;
}
if (file_offset < section->file_offset_of_raw_data) {
- uint32 section_start_offset = section->file_offset_of_raw_data;
+ uint32_t section_start_offset = section->file_offset_of_raw_data;
if(!ParseNonSectionFileRegion(file_offset, section_start_offset,
program))
return false;
file_offset = section_start_offset;
}
- uint32 end = file_offset + section->size_of_raw_data;
+ uint32_t end = file_offset + section->size_of_raw_data;
if (!ParseFileRegion(section, file_offset, end, program))
return false;
file_offset = end;
@@ -376,7 +377,7 @@ bool DisassemblerWin32X64::ParseAbs32Relocs() {
for (size_t i = 0; i < abs32_locations_.size(); ++i) {
RVA rva = abs32_locations_[i];
// The 4 bytes at the relocation are a reference to some address.
- uint32 target_address = Read32LittleEndian(RVAToPointer(rva));
+ uint32_t target_address = Read32LittleEndian(RVAToPointer(rva));
++abs32_target_rvas_[target_address - image_base()];
}
#endif
@@ -384,7 +385,7 @@ bool DisassemblerWin32X64::ParseAbs32Relocs() {
}
void DisassemblerWin32X64::ParseRel32RelocsFromSections() {
- uint32 file_offset = 0;
+ uint32_t file_offset = 0;
while (file_offset < length()) {
const Section* section = FindNextSection(file_offset);
if (section == NULL)
@@ -427,28 +428,28 @@ void DisassemblerWin32X64::ParseRel32RelocsFromSection(const Section* section) {
if (!isCode)
return;
- uint32 start_file_offset = section->file_offset_of_raw_data;
- uint32 end_file_offset = start_file_offset + section->size_of_raw_data;
+ uint32_t start_file_offset = section->file_offset_of_raw_data;
+ uint32_t end_file_offset = start_file_offset + section->size_of_raw_data;
RVA relocs_start_rva = base_relocation_table().address_;
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
RVA start_rva = FileOffsetToRVA(start_file_offset);
RVA end_rva = start_rva + section->virtual_size;
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer - start_rva;
+ const uint8_t* const adjust_pointer_to_rva = start_pointer - start_rva;
std::vector<RVA>::iterator abs32_pos = abs32_locations_.begin();
// Find the rel32 relocations.
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
while (p < end_pointer) {
RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
if (current_rva == relocs_start_rva) {
- uint32 relocs_size = base_relocation_table().size_;
+ uint32_t relocs_size = base_relocation_table().size_;
if (relocs_size) {
p += relocs_size;
continue;
@@ -461,7 +462,7 @@ void DisassemblerWin32X64::ParseRel32RelocsFromSection(const Section* section) {
// Heuristic discovery of rel32 locations in instruction stream: are the
// next few bytes the start of an instruction containing a rel32
// addressing mode?
- const uint8* rel32 = NULL;
+ const uint8_t* rel32 = NULL;
bool is_rip_relative = false;
if (p + 5 <= end_pointer) {
@@ -528,8 +529,8 @@ void DisassemblerWin32X64::ParseRel32RelocsFromSection(const Section* section) {
}
CheckBool DisassemblerWin32X64::ParseNonSectionFileRegion(
- uint32 start_file_offset,
- uint32 end_file_offset,
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
AssemblyProgram* program) {
if (incomplete_disassembly_)
return true;
@@ -544,21 +545,21 @@ CheckBool DisassemblerWin32X64::ParseNonSectionFileRegion(
return true;
}
-CheckBool DisassemblerWin32X64::ParseFileRegion(
- const Section* section,
- uint32 start_file_offset, uint32 end_file_offset,
- AssemblyProgram* program) {
+CheckBool DisassemblerWin32X64::ParseFileRegion(const Section* section,
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program) {
RVA relocs_start_rva = base_relocation_table().address_;
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
RVA start_rva = FileOffsetToRVA(start_file_offset);
RVA end_rva = start_rva + section->virtual_size;
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer - start_rva;
+ const uint8_t* const adjust_pointer_to_rva = start_pointer - start_rva;
std::vector<RVA>::iterator rel32_pos = rel32_locations_.begin();
std::vector<RVA>::iterator abs32_pos = abs32_locations_.begin();
@@ -566,7 +567,7 @@ CheckBool DisassemblerWin32X64::ParseFileRegion(
if (!program->EmitOriginInstruction(start_rva))
return false;
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
while (p < end_pointer) {
RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
@@ -577,7 +578,7 @@ CheckBool DisassemblerWin32X64::ParseFileRegion(
if (current_rva == relocs_start_rva) {
if (!program->EmitPeRelocsInstruction())
return false;
- uint32 relocs_size = base_relocation_table().size_;
+ uint32_t relocs_size = base_relocation_table().size_;
if (relocs_size) {
p += relocs_size;
continue;
@@ -588,7 +589,7 @@ CheckBool DisassemblerWin32X64::ParseFileRegion(
++abs32_pos;
if (abs32_pos != abs32_locations_.end() && *abs32_pos == current_rva) {
- uint64 target_address = Read64LittleEndian(p);
+ uint64_t target_address = Read64LittleEndian(p);
RVA target_rva = base::checked_cast<RVA>(target_address - image_base());
// TODO(sra): target could be Label+offset. It is not clear how to guess
// which it might be. We assume offset==0.
@@ -690,7 +691,8 @@ std::string DisassemblerWin32X64::DescribeRVA(RVA rva) const {
return s.str();
}
-const Section* DisassemblerWin32X64::FindNextSection(uint32 fileOffset) const {
+const Section* DisassemblerWin32X64::FindNextSection(
+ uint32_t fileOffset) const {
const Section* best = 0;
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
@@ -706,10 +708,10 @@ const Section* DisassemblerWin32X64::FindNextSection(uint32 fileOffset) const {
return best;
}
-RVA DisassemblerWin32X64::FileOffsetToRVA(uint32 file_offset) const {
+RVA DisassemblerWin32X64::FileOffsetToRVA(uint32_t file_offset) const {
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
- uint32 offset = file_offset - section->file_offset_of_raw_data;
+ uint32_t offset = file_offset - section->file_offset_of_raw_data;
if (offset < section->size_of_raw_data) {
return section->virtual_address + offset;
}
@@ -725,7 +727,7 @@ bool DisassemblerWin32X64::ReadDataDirectory(
size_t offset = index * 8 + offset_of_data_directories_;
if (offset >= size_of_optional_header_)
return Bad("number of data directories inconsistent");
- const uint8* data_directory = optional_header_ + offset;
+ const uint8_t* data_directory = optional_header_ + offset;
if (data_directory < start() ||
data_directory + 8 >= end())
return Bad("data directory outside image");
@@ -736,7 +738,7 @@ bool DisassemblerWin32X64::ReadDataDirectory(
// TODO(sra): validate RVA.
directory->address_ = rva;
- directory->size_ = static_cast<uint32>(size);
+ directory->size_ = static_cast<uint32_t>(size);
return true;
} else {
directory->address_ = 0;
diff --git a/courgette/disassembler_win32_x64.h b/courgette/disassembler_win32_x64.h
index bce4802..3b0b978 100644
--- a/courgette/disassembler_win32_x64.h
+++ b/courgette/disassembler_win32_x64.h
@@ -5,7 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_WIN32_X64_H_
#define COURGETTE_DISASSEMBLER_WIN32_X64_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/macros.h"
#include "courgette/disassembler.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_win_pe.h"
@@ -36,7 +39,7 @@ class DisassemblerWin32X64 : public Disassembler {
//
bool has_text_section() const { return has_text_section_; }
- uint32 size_of_code() const { return size_of_code_; }
+ uint32_t size_of_code() const { return size_of_code_; }
bool is_32bit() const { return !is_PE32_plus_; }
// Returns 'true' if the base relocation table can be parsed.
@@ -53,7 +56,7 @@ class DisassemblerWin32X64 : public Disassembler {
// Returns same as FileOffsetToPointer(RVAToFileOffset(rva)) except that NULL
// is returned if there is no file offset corresponding to 'rva'.
- const uint8* RVAToPointer(RVA rva) const;
+ const uint8_t* RVAToPointer(RVA rva) const;
static std::string SectionName(const Section* section);
@@ -63,11 +66,14 @@ class DisassemblerWin32X64 : public Disassembler {
void ParseRel32RelocsFromSections();
void ParseRel32RelocsFromSection(const Section* section);
- CheckBool ParseNonSectionFileRegion(uint32 start_file_offset,
- uint32 end_file_offset, AssemblyProgram* program) WARN_UNUSED_RESULT;
+ CheckBool ParseNonSectionFileRegion(uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program)
+ WARN_UNUSED_RESULT;
CheckBool ParseFileRegion(const Section* section,
- uint32 start_file_offset, uint32 end_file_offset,
- AssemblyProgram* program) WARN_UNUSED_RESULT;
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program) WARN_UNUSED_RESULT;
#if COURGETTE_HISTOGRAM_TARGETS
void HistogramTargets(const char* kind, const std::map<RVA, int>& map);
@@ -76,7 +82,7 @@ class DisassemblerWin32X64 : public Disassembler {
// Most addresses are represented as 32-bit RVAs. The one address we can't
// do this with is the image base address. 'image_base' is valid only for
// 32-bit executables. 'image_base_64' is valid for 32- and 64-bit executable.
- uint64 image_base() const { return image_base_; }
+ uint64_t image_base() const { return image_base_; }
const ImageDataDirectory& base_relocation_table() const {
return base_relocation_table_;
@@ -89,15 +95,14 @@ class DisassemblerWin32X64 : public Disassembler {
// Finds the first section at file_offset or above. Does not return sections
// that have no raw bytes in the file.
- const Section* FindNextSection(uint32 file_offset) const;
+ const Section* FindNextSection(uint32_t file_offset) const;
// There are 2 'coordinate systems' for reasoning about executables.
// FileOffset - the the offset within a single .EXE or .DLL *file*.
// RVA - relative virtual address (offset within *loaded image*)
// FileOffsetToRVA and RVAToFileOffset convert between these representations.
- RVA FileOffsetToRVA(uint32 offset) const;
-
+ RVA FileOffsetToRVA(uint32_t offset) const;
private:
@@ -118,23 +123,23 @@ class DisassemblerWin32X64 : public Disassembler {
bool is_PE32_plus_; // PE32_plus is for 64 bit executables.
// Location and size of IMAGE_OPTIONAL_HEADER in the buffer.
- const uint8 *optional_header_;
- uint16 size_of_optional_header_;
- uint16 offset_of_data_directories_;
+ const uint8_t* optional_header_;
+ uint16_t size_of_optional_header_;
+ uint16_t offset_of_data_directories_;
- uint16 machine_type_;
- uint16 number_of_sections_;
+ uint16_t machine_type_;
+ uint16_t number_of_sections_;
const Section *sections_;
bool has_text_section_;
- uint32 size_of_code_;
- uint32 size_of_initialized_data_;
- uint32 size_of_uninitialized_data_;
+ uint32_t size_of_code_;
+ uint32_t size_of_initialized_data_;
+ uint32_t size_of_uninitialized_data_;
RVA base_of_code_;
RVA base_of_data_;
- uint64 image_base_;
- uint32 size_of_image_;
+ uint64_t image_base_;
+ uint32_t size_of_image_;
int number_of_data_directories_;
ImageDataDirectory export_table_;
diff --git a/courgette/disassembler_win32_x64_unittest.cc b/courgette/disassembler_win32_x64_unittest.cc
index f67e800..8f732b3 100644
--- a/courgette/disassembler_win32_x64_unittest.cc
+++ b/courgette/disassembler_win32_x64_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/disassembler_win32_x64.h"
+#include <stdint.h>
+
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "courgette/base_test_unittest.h"
@@ -44,13 +46,13 @@ void DisassemblerWin32X64Test::TestExe() const {
EXPECT_TRUE(can_parse_relocs);
EXPECT_TRUE(base::STLIsSorted(relocs));
- const uint8* offset_p = disassembler->OffsetToPointer(0);
+ const uint8_t* offset_p = disassembler->OffsetToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(offset_p));
EXPECT_EQ('M', offset_p[0]);
EXPECT_EQ('Z', offset_p[1]);
- const uint8* rva_p = disassembler->RVAToPointer(0);
+ const uint8_t* rva_p = disassembler->RVAToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(rva_p));
EXPECT_EQ('M', rva_p[0]);
diff --git a/courgette/disassembler_win32_x86.cc b/courgette/disassembler_win32_x86.cc
index 85d99f4..bc41ff0 100644
--- a/courgette/disassembler_win32_x86.cc
+++ b/courgette/disassembler_win32_x86.cc
@@ -4,11 +4,13 @@
#include "courgette/disassembler_win32_x86.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <string>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "courgette/assembly_program.h"
@@ -55,13 +57,12 @@ bool DisassemblerWin32X86::ParseHeader() {
return Bad("Not MZ");
// offset from DOS header to PE header is stored in DOS header.
- uint32 offset = ReadU32(start(),
- kOffsetOfFileAddressOfNewExeHeader);
+ uint32_t offset = ReadU32(start(), kOffsetOfFileAddressOfNewExeHeader);
if (offset >= length())
return Bad("Bad offset to PE header");
- const uint8* const pe_header = OffsetToPointer(offset);
+ const uint8_t* const pe_header = OffsetToPointer(offset);
const size_t kMinPEHeaderSize = 4 /*signature*/ + kSizeOfCoffHeader;
if (pe_header <= start() ||
pe_header >= end() - kMinPEHeaderSize)
@@ -83,13 +84,13 @@ bool DisassemblerWin32X86::ParseHeader() {
// The second field of the IMAGE_NT_HEADERS is the COFF header.
// The COFF header is also called an IMAGE_FILE_HEADER
// http://msdn.microsoft.com/en-us/library/ms680313(VS.85).aspx
- const uint8* const coff_header = pe_header + 4;
+ const uint8_t* const coff_header = pe_header + 4;
machine_type_ = ReadU16(coff_header, 0);
number_of_sections_ = ReadU16(coff_header, 2);
size_of_optional_header_ = ReadU16(coff_header, 16);
// The rest of the IMAGE_NT_HEADERS is the IMAGE_OPTIONAL_HEADER(32|64)
- const uint8* const optional_header = coff_header + kSizeOfCoffHeader;
+ const uint8_t* const optional_header = coff_header + kSizeOfCoffHeader;
optional_header_ = optional_header;
if (optional_header + size_of_optional_header_ >= end())
@@ -99,7 +100,7 @@ bool DisassemblerWin32X86::ParseHeader() {
if (size_of_optional_header_ < 2)
return Bad("optional header no magic");
- uint16 magic = ReadU16(optional_header, 0);
+ uint16_t magic = ReadU16(optional_header, 0);
if (magic == kImageNtOptionalHdr32Magic) {
is_PE32_plus_ = false;
@@ -176,7 +177,7 @@ bool DisassemblerWin32X86::ParseHeader() {
if (memcmp(section->name, ".text", 6) == 0)
has_text_section_ = true;
- uint32 section_end =
+ uint32_t section_end =
section->file_offset_of_raw_data + section->size_of_raw_data;
if (section_end > detected_length)
detected_length = section_end;
@@ -229,8 +230,8 @@ bool DisassemblerWin32X86::ParseRelocs(std::vector<RVA> *relocs) {
// "The format of the base relocation data is somewhat quirky"
// at http://msdn.microsoft.com/en-us/library/ms809762.aspx
- const uint8* relocs_start = RVAToPointer(base_relocation_table_.address_);
- const uint8* relocs_end = relocs_start + relocs_size;
+ const uint8_t* relocs_start = RVAToPointer(base_relocation_table_.address_);
+ const uint8_t* relocs_end = relocs_start + relocs_size;
// Make sure entire base relocation table is within the buffer.
if (relocs_start < start() ||
@@ -240,17 +241,17 @@ bool DisassemblerWin32X86::ParseRelocs(std::vector<RVA> *relocs) {
return Bad(".relocs outside image");
}
- const uint8* block = relocs_start;
+ const uint8_t* block = relocs_start;
// Walk the variable sized blocks.
while (block + 8 < relocs_end) {
RVA page_rva = ReadU32(block, 0);
- uint32 size = ReadU32(block, 4);
+ uint32_t size = ReadU32(block, 4);
if (size < 8 || // Size includes header ...
size % 4 != 0) // ... and is word aligned.
return Bad("unreasonable relocs block");
- const uint8* end_entries = block + size;
+ const uint8_t* end_entries = block + size;
if (end_entries <= block ||
end_entries <= start() ||
@@ -258,8 +259,8 @@ bool DisassemblerWin32X86::ParseRelocs(std::vector<RVA> *relocs) {
return Bad(".relocs block outside image");
// Walk through the two-byte entries.
- for (const uint8* p = block + 8; p < end_entries; p += 2) {
- uint16 entry = ReadU16(p, 0);
+ for (const uint8_t* p = block + 8; p < end_entries; p += 2) {
+ uint16_t entry = ReadU16(p, 0);
int type = entry >> 12;
int offset = entry & 0xFFF;
@@ -267,7 +268,7 @@ bool DisassemblerWin32X86::ParseRelocs(std::vector<RVA> *relocs) {
// Skip the relocs that live outside of the image. It might be the case
// if a reloc is relative to a register, e.g.:
// mov ecx,dword ptr [eax+044D5888h]
- uint32 target_address = Read32LittleEndian(RVAToPointer(rva));
+ uint32_t target_address = Read32LittleEndian(RVAToPointer(rva));
if (target_address < image_base_ ||
target_address > (image_base_ + size_of_image_)) {
continue;
@@ -293,7 +294,7 @@ bool DisassemblerWin32X86::ParseRelocs(std::vector<RVA> *relocs) {
const Section* DisassemblerWin32X86::RVAToSection(RVA rva) const {
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
- uint32 offset = rva - section->virtual_address;
+ uint32_t offset = rva - section->virtual_address;
if (offset < section->virtual_size) {
return section;
}
@@ -304,7 +305,7 @@ const Section* DisassemblerWin32X86::RVAToSection(RVA rva) const {
int DisassemblerWin32X86::RVAToFileOffset(RVA rva) const {
const Section* section = RVAToSection(rva);
if (section) {
- uint32 offset = rva - section->virtual_address;
+ uint32_t offset = rva - section->virtual_address;
if (offset < section->size_of_raw_data) {
return section->file_offset_of_raw_data + offset;
} else {
@@ -323,7 +324,7 @@ int DisassemblerWin32X86::RVAToFileOffset(RVA rva) const {
return kNoOffset;
}
-const uint8* DisassemblerWin32X86::RVAToPointer(RVA rva) const {
+const uint8_t* DisassemblerWin32X86::RVAToPointer(RVA rva) const {
int file_offset = RVAToFileOffset(rva);
if (file_offset == kNoOffset)
return NULL;
@@ -342,7 +343,7 @@ std::string DisassemblerWin32X86::SectionName(const Section* section) {
CheckBool DisassemblerWin32X86::ParseFile(AssemblyProgram* program) {
// Walk all the bytes in the file, whether or not in a section.
- uint32 file_offset = 0;
+ uint32_t file_offset = 0;
while (file_offset < length()) {
const Section* section = FindNextSection(file_offset);
if (section == NULL) {
@@ -352,14 +353,14 @@ CheckBool DisassemblerWin32X86::ParseFile(AssemblyProgram* program) {
break;
}
if (file_offset < section->file_offset_of_raw_data) {
- uint32 section_start_offset = section->file_offset_of_raw_data;
+ uint32_t section_start_offset = section->file_offset_of_raw_data;
if(!ParseNonSectionFileRegion(file_offset, section_start_offset,
program))
return false;
file_offset = section_start_offset;
}
- uint32 end = file_offset + section->size_of_raw_data;
+ uint32_t end = file_offset + section->size_of_raw_data;
if (!ParseFileRegion(section, file_offset, end, program))
return false;
file_offset = end;
@@ -382,7 +383,7 @@ bool DisassemblerWin32X86::ParseAbs32Relocs() {
for (size_t i = 0; i < abs32_locations_.size(); ++i) {
RVA rva = abs32_locations_[i];
// The 4 bytes at the relocation are a reference to some address.
- uint32 target_address = Read32LittleEndian(RVAToPointer(rva));
+ uint32_t target_address = Read32LittleEndian(RVAToPointer(rva));
++abs32_target_rvas_[target_address - image_base()];
}
#endif
@@ -390,7 +391,7 @@ bool DisassemblerWin32X86::ParseAbs32Relocs() {
}
void DisassemblerWin32X86::ParseRel32RelocsFromSections() {
- uint32 file_offset = 0;
+ uint32_t file_offset = 0;
while (file_offset < length()) {
const Section* section = FindNextSection(file_offset);
if (section == NULL)
@@ -433,11 +434,11 @@ void DisassemblerWin32X86::ParseRel32RelocsFromSection(const Section* section) {
if (!isCode)
return;
- uint32 start_file_offset = section->file_offset_of_raw_data;
- uint32 end_file_offset = start_file_offset + section->size_of_raw_data;
+ uint32_t start_file_offset = section->file_offset_of_raw_data;
+ uint32_t end_file_offset = start_file_offset + section->size_of_raw_data;
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
RVA start_rva = FileOffsetToRVA(start_file_offset);
RVA end_rva = start_rva + section->virtual_size;
@@ -456,8 +457,8 @@ void DisassemblerWin32X86::ParseRel32RelocsFromSection(const Section* section) {
}
CheckBool DisassemblerWin32X86::ParseNonSectionFileRegion(
- uint32 start_file_offset,
- uint32 end_file_offset,
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
AssemblyProgram* program) {
if (incomplete_disassembly_)
return true;
@@ -472,21 +473,21 @@ CheckBool DisassemblerWin32X86::ParseNonSectionFileRegion(
return true;
}
-CheckBool DisassemblerWin32X86::ParseFileRegion(
- const Section* section,
- uint32 start_file_offset, uint32 end_file_offset,
- AssemblyProgram* program) {
+CheckBool DisassemblerWin32X86::ParseFileRegion(const Section* section,
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program) {
RVA relocs_start_rva = base_relocation_table().address_;
- const uint8* start_pointer = OffsetToPointer(start_file_offset);
- const uint8* end_pointer = OffsetToPointer(end_file_offset);
+ const uint8_t* start_pointer = OffsetToPointer(start_file_offset);
+ const uint8_t* end_pointer = OffsetToPointer(end_file_offset);
RVA start_rva = FileOffsetToRVA(start_file_offset);
RVA end_rva = start_rva + section->virtual_size;
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer - start_rva;
+ const uint8_t* const adjust_pointer_to_rva = start_pointer - start_rva;
std::vector<RVA>::iterator rel32_pos = rel32_locations_.begin();
std::vector<RVA>::iterator abs32_pos = abs32_locations_.begin();
@@ -494,7 +495,7 @@ CheckBool DisassemblerWin32X86::ParseFileRegion(
if (!program->EmitOriginInstruction(start_rva))
return false;
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
while (p < end_pointer) {
RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
@@ -505,7 +506,7 @@ CheckBool DisassemblerWin32X86::ParseFileRegion(
if (current_rva == relocs_start_rva) {
if (!program->EmitPeRelocsInstruction())
return false;
- uint32 relocs_size = base_relocation_table().size_;
+ uint32_t relocs_size = base_relocation_table().size_;
if (relocs_size) {
p += relocs_size;
continue;
@@ -516,7 +517,7 @@ CheckBool DisassemblerWin32X86::ParseFileRegion(
++abs32_pos;
if (abs32_pos != abs32_locations_.end() && *abs32_pos == current_rva) {
- uint32 target_address = Read32LittleEndian(p);
+ uint32_t target_address = Read32LittleEndian(p);
RVA target_rva = target_address - image_base();
// TODO(sra): target could be Label+offset. It is not clear how to guess
// which it might be. We assume offset==0.
@@ -618,7 +619,8 @@ std::string DisassemblerWin32X86::DescribeRVA(RVA rva) const {
return s.str();
}
-const Section* DisassemblerWin32X86::FindNextSection(uint32 fileOffset) const {
+const Section* DisassemblerWin32X86::FindNextSection(
+ uint32_t fileOffset) const {
const Section* best = 0;
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
@@ -634,10 +636,10 @@ const Section* DisassemblerWin32X86::FindNextSection(uint32 fileOffset) const {
return best;
}
-RVA DisassemblerWin32X86::FileOffsetToRVA(uint32 file_offset) const {
+RVA DisassemblerWin32X86::FileOffsetToRVA(uint32_t file_offset) const {
for (int i = 0; i < number_of_sections_; i++) {
const Section* section = &sections_[i];
- uint32 offset = file_offset - section->file_offset_of_raw_data;
+ uint32_t offset = file_offset - section->file_offset_of_raw_data;
if (offset < section->size_of_raw_data) {
return section->virtual_address + offset;
}
@@ -653,7 +655,7 @@ bool DisassemblerWin32X86::ReadDataDirectory(
size_t offset = index * 8 + offset_of_data_directories_;
if (offset >= size_of_optional_header_)
return Bad("number of data directories inconsistent");
- const uint8* data_directory = optional_header_ + offset;
+ const uint8_t* data_directory = optional_header_ + offset;
if (data_directory < start() ||
data_directory + 8 >= end())
return Bad("data directory outside image");
@@ -664,7 +666,7 @@ bool DisassemblerWin32X86::ReadDataDirectory(
// TODO(sra): validate RVA.
directory->address_ = rva;
- directory->size_ = static_cast<uint32>(size);
+ directory->size_ = static_cast<uint32_t>(size);
return true;
} else {
directory->address_ = 0;
diff --git a/courgette/disassembler_win32_x86.h b/courgette/disassembler_win32_x86.h
index 52ce520..891636c 100644
--- a/courgette/disassembler_win32_x86.h
+++ b/courgette/disassembler_win32_x86.h
@@ -5,7 +5,10 @@
#ifndef COURGETTE_DISASSEMBLER_WIN32_X86_H_
#define COURGETTE_DISASSEMBLER_WIN32_X86_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/macros.h"
#include "courgette/disassembler.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_win_pe.h"
@@ -36,7 +39,7 @@ class DisassemblerWin32X86 : public Disassembler {
//
bool has_text_section() const { return has_text_section_; }
- uint32 size_of_code() const { return size_of_code_; }
+ uint32_t size_of_code() const { return size_of_code_; }
bool is_32bit() const { return !is_PE32_plus_; }
// Returns 'true' if the base relocation table can be parsed.
@@ -53,7 +56,7 @@ class DisassemblerWin32X86 : public Disassembler {
// Returns same as FileOffsetToPointer(RVAToFileOffset(rva)) except that NULL
// is returned if there is no file offset corresponding to 'rva'.
- const uint8* RVAToPointer(RVA rva) const;
+ const uint8_t* RVAToPointer(RVA rva) const;
static std::string SectionName(const Section* section);
@@ -63,11 +66,14 @@ class DisassemblerWin32X86 : public Disassembler {
void ParseRel32RelocsFromSections();
void ParseRel32RelocsFromSection(const Section* section);
- CheckBool ParseNonSectionFileRegion(uint32 start_file_offset,
- uint32 end_file_offset, AssemblyProgram* program) WARN_UNUSED_RESULT;
+ CheckBool ParseNonSectionFileRegion(uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program)
+ WARN_UNUSED_RESULT;
CheckBool ParseFileRegion(const Section* section,
- uint32 start_file_offset, uint32 end_file_offset,
- AssemblyProgram* program) WARN_UNUSED_RESULT;
+ uint32_t start_file_offset,
+ uint32_t end_file_offset,
+ AssemblyProgram* program) WARN_UNUSED_RESULT;
#if COURGETTE_HISTOGRAM_TARGETS
void HistogramTargets(const char* kind, const std::map<RVA, int>& map);
@@ -76,7 +82,7 @@ class DisassemblerWin32X86 : public Disassembler {
// Most addresses are represented as 32-bit RVAs. The one address we can't
// do this with is the image base address. 'image_base' is valid only for
// 32-bit executables. 'image_base_64' is valid for 32- and 64-bit executable.
- uint32 image_base() const { return static_cast<uint32>(image_base_); }
+ uint32_t image_base() const { return static_cast<uint32_t>(image_base_); }
const ImageDataDirectory& base_relocation_table() const {
return base_relocation_table_;
@@ -87,15 +93,14 @@ class DisassemblerWin32X86 : public Disassembler {
// Finds the first section at file_offset or above. Does not return sections
// that have no raw bytes in the file.
- const Section* FindNextSection(uint32 file_offset) const;
+ const Section* FindNextSection(uint32_t file_offset) const;
// There are 2 'coordinate systems' for reasoning about executables.
// FileOffset - the the offset within a single .EXE or .DLL *file*.
// RVA - relative virtual address (offset within *loaded image*)
// FileOffsetToRVA and RVAToFileOffset convert between these representations.
- RVA FileOffsetToRVA(uint32 offset) const;
-
+ RVA FileOffsetToRVA(uint32_t offset) const;
private:
@@ -116,23 +121,23 @@ class DisassemblerWin32X86 : public Disassembler {
bool is_PE32_plus_; // PE32_plus is for 64 bit executables.
// Location and size of IMAGE_OPTIONAL_HEADER in the buffer.
- const uint8 *optional_header_;
- uint16 size_of_optional_header_;
- uint16 offset_of_data_directories_;
+ const uint8_t* optional_header_;
+ uint16_t size_of_optional_header_;
+ uint16_t offset_of_data_directories_;
- uint16 machine_type_;
- uint16 number_of_sections_;
+ uint16_t machine_type_;
+ uint16_t number_of_sections_;
const Section *sections_;
bool has_text_section_;
- uint32 size_of_code_;
- uint32 size_of_initialized_data_;
- uint32 size_of_uninitialized_data_;
+ uint32_t size_of_code_;
+ uint32_t size_of_initialized_data_;
+ uint32_t size_of_uninitialized_data_;
RVA base_of_code_;
RVA base_of_data_;
- uint64 image_base_; // range limited to 32 bits for 32 bit executable
- uint32 size_of_image_;
+ uint64_t image_base_; // range limited to 32 bits for 32 bit executable
+ uint32_t size_of_image_;
int number_of_data_directories_;
ImageDataDirectory export_table_;
diff --git a/courgette/disassembler_win32_x86_unittest.cc b/courgette/disassembler_win32_x86_unittest.cc
index 40cc412..4e16464 100644
--- a/courgette/disassembler_win32_x86_unittest.cc
+++ b/courgette/disassembler_win32_x86_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/disassembler_win32_x86.h"
+#include <stdint.h>
+
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "courgette/base_test_unittest.h"
@@ -44,13 +46,13 @@ void DisassemblerWin32X86Test::TestExe() const {
EXPECT_TRUE(can_parse_relocs);
EXPECT_TRUE(base::STLIsSorted(relocs));
- const uint8* offset_p = disassembler->OffsetToPointer(0);
+ const uint8_t* offset_p = disassembler->OffsetToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(offset_p));
EXPECT_EQ('M', offset_p[0]);
EXPECT_EQ('Z', offset_p[1]);
- const uint8* rva_p = disassembler->RVAToPointer(0);
+ const uint8_t* rva_p = disassembler->RVAToPointer(0);
EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
reinterpret_cast<const void*>(rva_p));
EXPECT_EQ('M', rva_p[0]);
diff --git a/courgette/encode_decode_unittest.cc b/courgette/encode_decode_unittest.cc
index 2cf5cd4..9e89c20 100644
--- a/courgette/encode_decode_unittest.cc
+++ b/courgette/encode_decode_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stddef.h>
+
#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
diff --git a/courgette/encoded_program.cc b/courgette/encoded_program.cc
index a4c0089..209fe2f 100644
--- a/courgette/encoded_program.cc
+++ b/courgette/encoded_program.cc
@@ -4,6 +4,9 @@
#include "courgette/encoded_program.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <map>
#include <string>
@@ -42,7 +45,7 @@ CheckBool WriteVector(const V& items, SinkStream* buffer) {
template<typename V>
bool ReadVector(V* items, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
@@ -50,7 +53,7 @@ bool ReadVector(V* items, SourceStream* buffer) {
bool ok = items->reserve(count);
for (size_t i = 0; ok && i < count; ++i) {
- uint32 item;
+ uint32_t item;
ok = buffer->ReadVarint32(&item);
if (ok)
ok = items->push_back(static_cast<typename V::value_type>(item));
@@ -64,10 +67,10 @@ template<typename V>
CheckBool WriteSigned32Delta(const V& set, SinkStream* buffer) {
size_t count = set.size();
bool ok = buffer->WriteSizeVarint32(count);
- uint32 prev = 0;
+ uint32_t prev = 0;
for (size_t i = 0; ok && i < count; ++i) {
- uint32 current = set[i];
- int32 delta = current - prev;
+ uint32_t current = set[i];
+ int32_t delta = current - prev;
ok = buffer->WriteVarint32Signed(delta);
prev = current;
}
@@ -76,19 +79,19 @@ CheckBool WriteSigned32Delta(const V& set, SinkStream* buffer) {
template <typename V>
static CheckBool ReadSigned32Delta(V* set, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
set->clear();
bool ok = set->reserve(count);
- uint32 prev = 0;
+ uint32_t prev = 0;
for (size_t i = 0; ok && i < count; ++i) {
- int32 delta;
+ int32_t delta;
ok = buffer->ReadVarint32Signed(&delta);
if (ok) {
- uint32 current = static_cast<uint32>(prev + delta);
+ uint32_t current = static_cast<uint32_t>(prev + delta);
ok = set->push_back(current);
prev = current;
}
@@ -116,7 +119,7 @@ CheckBool WriteVectorU8(const V& items, SinkStream* buffer) {
template<typename V>
bool ReadVectorU8(V* items, SourceStream* buffer) {
- uint32 count;
+ uint32_t count;
if (!buffer->ReadVarint32(&count))
return false;
@@ -190,7 +193,7 @@ CheckBool EncodedProgram::AddOrigin(RVA origin) {
}
CheckBool EncodedProgram::AddCopy(size_t count, const void* bytes) {
- const uint8* source = static_cast<const uint8*>(bytes);
+ const uint8_t* source = static_cast<const uint8_t*>(bytes);
bool ok = true;
@@ -240,7 +243,7 @@ CheckBool EncodedProgram::AddRel32(int label_index) {
return ops_.push_back(REL32) && rel32_ix_.push_back(label_index);
}
-CheckBool EncodedProgram::AddRel32ARM(uint16 op, int label_index) {
+CheckBool EncodedProgram::AddRel32ARM(uint16_t op, int label_index) {
return ops_.push_back(static_cast<OP>(op)) &&
rel32_ix_.push_back(label_index);
}
@@ -295,7 +298,7 @@ static FieldSelect GetFieldSelect() {
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string s;
env->GetVar("A_FIELDS", &s);
- uint64 fields;
+ uint64_t fields;
if (!base::StringToUint64(s, &fields))
return static_cast<FieldSelect>(~0);
return static_cast<FieldSelect>(fields);
@@ -314,8 +317,8 @@ CheckBool EncodedProgram::WriteTo(SinkStreamSet* streams) {
// the rest can be interleaved.
if (select & INCLUDE_MISC) {
- uint32 high = static_cast<uint32>(image_base_ >> 32);
- uint32 low = static_cast<uint32>(image_base_ & 0xffffffffU);
+ uint32_t high = static_cast<uint32_t>(image_base_ >> 32);
+ uint32_t low = static_cast<uint32_t>(image_base_ & 0xffffffffU);
if (!streams->stream(kStreamMisc)->WriteVarint32(high) ||
!streams->stream(kStreamMisc)->WriteVarint32(low)) {
@@ -360,14 +363,14 @@ CheckBool EncodedProgram::WriteTo(SinkStreamSet* streams) {
}
bool EncodedProgram::ReadFrom(SourceStreamSet* streams) {
- uint32 high;
- uint32 low;
+ uint32_t high;
+ uint32_t low;
if (!streams->stream(kStreamMisc)->ReadVarint32(&high) ||
!streams->stream(kStreamMisc)->ReadVarint32(&low)) {
return false;
}
- image_base_ = (static_cast<uint64>(high) << 32) | low;
+ image_base_ = (static_cast<uint64_t>(high) << 32) | low;
if (!ReadSigned32Delta(&abs32_rva_, streams->stream(kStreamAbs32Addresses)))
return false;
@@ -411,58 +414,56 @@ CheckBool EncodedProgram::EvaluateRel32ARM(OP op,
SinkStream* output) {
switch (op & 0x0000F000) {
case REL32ARM8: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF8,
- static_cast<uint16>(op),
- static_cast<uint32>(rva -
- current_rva),
- &decompressed_op)) {
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(
+ ARM_OFF8, static_cast<uint16_t>(op),
+ static_cast<uint32_t>(rva - current_rva), &decompressed_op)) {
return false;
}
- uint16 op16 = static_cast<uint16>(decompressed_op);
+ uint16_t op16 = static_cast<uint16_t>(decompressed_op);
if (!output->Write(&op16, 2))
return false;
current_rva += 2;
break;
}
case REL32ARM11: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF11, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF11, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint16 op16 = static_cast<uint16>(decompressed_op);
+ uint16_t op16 = static_cast<uint16_t>(decompressed_op);
if (!output->Write(&op16, 2))
return false;
current_rva += 2;
break;
}
case REL32ARM24: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF24, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF24, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
@@ -472,40 +473,40 @@ CheckBool EncodedProgram::EvaluateRel32ARM(OP op,
break;
}
case REL32ARM25: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF25, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF25, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint32 words = (decompressed_op << 16) | (decompressed_op >> 16);
+ uint32_t words = (decompressed_op << 16) | (decompressed_op >> 16);
if (!output->Write(&words, 4))
return false;
current_rva += 4;
break;
}
case REL32ARM21: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 decompressed_op;
- if (!DisassemblerElf32ARM::Decompress(ARM_OFF21, (uint16) op,
- (uint32) (rva - current_rva),
+ uint32_t decompressed_op;
+ if (!DisassemblerElf32ARM::Decompress(ARM_OFF21, (uint16_t)op,
+ (uint32_t)(rva - current_rva),
&decompressed_op)) {
return false;
}
- uint32 words = (decompressed_op << 16) | (decompressed_op >> 16);
+ uint32_t words = (decompressed_op << 16) | (decompressed_op >> 16);
if (!output->Write(&words, 4))
return false;
current_rva += 4;
@@ -530,7 +531,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
RVA current_rva = 0;
bool pending_pe_relocation_table = false;
- uint8 pending_pe_relocation_table_type = 0x03; // IMAGE_REL_BASED_HIGHLOW
+ uint8_t pending_pe_relocation_table_type = 0x03; // IMAGE_REL_BASED_HIGHLOW
Elf32_Word pending_elf_relocation_table_type = 0;
SinkStream bytes_following_relocation_table;
@@ -560,7 +561,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
return false;
++ix_copy_counts;
for (size_t i = 0; i < count; ++i) {
- uint8 b;
+ uint8_t b;
if (!VectorAt(copy_bytes_, ix_copy_bytes, &b))
return false;
++ix_copy_bytes;
@@ -572,7 +573,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
}
case COPY1: {
- uint8 b;
+ uint8_t b;
if (!VectorAt(copy_bytes_, ix_copy_bytes, &b))
return false;
++ix_copy_bytes;
@@ -583,14 +584,14 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
}
case REL32: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(rel32_ix_, ix_rel32_ix, &index))
return false;
++ix_rel32_ix;
RVA rva;
if (!VectorAt(rel32_rva_, index, &rva))
return false;
- uint32 offset = (rva - (current_rva + 4));
+ uint32_t offset = (rva - (current_rva + 4));
if (!output->Write(&offset, 4))
return false;
current_rva += 4;
@@ -599,7 +600,7 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
case ABS32:
case ABS64: {
- uint32 index;
+ uint32_t index;
if (!VectorAt(abs32_ix_, ix_abs32_ix, &index))
return false;
++ix_abs32_ix;
@@ -607,18 +608,18 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
if (!VectorAt(abs32_rva_, index, &rva))
return false;
if (op == ABS32) {
- base::CheckedNumeric<uint32> abs32 = image_base_;
+ base::CheckedNumeric<uint32_t> abs32 = image_base_;
abs32 += rva;
- uint32 safe_abs32 = abs32.ValueOrDie();
+ uint32_t safe_abs32 = abs32.ValueOrDie();
if (!abs32_relocs_.push_back(current_rva) ||
!output->Write(&safe_abs32, 4)) {
return false;
}
current_rva += 4;
} else {
- base::CheckedNumeric<uint64> abs64 = image_base_;
+ base::CheckedNumeric<uint64_t> abs64 = image_base_;
abs64 += rva;
- uint64 safe_abs64 = abs64.ValueOrDie();
+ uint64_t safe_abs64 = abs64.ValueOrDie();
if (!abs32_relocs_.push_back(current_rva) ||
!output->Write(&safe_abs64, 8)) {
return false;
@@ -715,9 +716,9 @@ CheckBool EncodedProgram::AssembleTo(SinkStream* final_buffer) {
// table file format.
//
struct RelocBlockPOD {
- uint32 page_rva;
- uint32 block_size;
- uint16 relocs[4096]; // Allow up to one relocation per byte of a 4k page.
+ uint32_t page_rva;
+ uint32_t block_size;
+ uint16_t relocs[4096]; // Allow up to one relocation per byte of a 4k page.
};
static_assert(offsetof(RelocBlockPOD, relocs) == 8, "reloc block header size");
@@ -729,7 +730,7 @@ class RelocBlock {
pod.block_size = 8;
}
- void Add(uint16 item) {
+ void Add(uint16_t item) {
pod.relocs[(pod.block_size-8)/2] = item;
pod.block_size += 2;
}
@@ -749,21 +750,21 @@ class RelocBlock {
};
CheckBool EncodedProgram::GeneratePeRelocations(SinkStream* buffer,
- uint8 type) {
+ uint8_t type) {
std::sort(abs32_relocs_.begin(), abs32_relocs_.end());
RelocBlock block;
bool ok = true;
for (size_t i = 0; ok && i < abs32_relocs_.size(); ++i) {
- uint32 rva = abs32_relocs_[i];
- uint32 page_rva = rva & ~0xFFF;
+ uint32_t rva = abs32_relocs_[i];
+ uint32_t page_rva = rva & ~0xFFF;
if (page_rva != block.pod.page_rva) {
ok &= block.Flush(buffer);
block.pod.page_rva = page_rva;
}
if (ok)
- block.Add(((static_cast<uint16>(type)) << 12) | (rva & 0xFFF));
+ block.Add(((static_cast<uint16_t>(type)) << 12) | (rva & 0xFFF));
}
ok &= block.Flush(buffer);
return ok;
diff --git a/courgette/encoded_program.h b/courgette/encoded_program.h
index 641f523..81e1639 100644
--- a/courgette/encoded_program.h
+++ b/courgette/encoded_program.h
@@ -5,9 +5,12 @@
#ifndef COURGETTE_ENCODED_PROGRAM_H_
#define COURGETTE_ENCODED_PROGRAM_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include <vector>
-#include "base/basictypes.h"
+#include "base/macros.h"
#include "courgette/disassembler.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_elf.h"
@@ -43,7 +46,7 @@ class EncodedProgram {
// Generating an EncodedProgram:
//
// (1) The image base can be specified at any time.
- void set_image_base(uint64 base) { image_base_ = base; }
+ void set_image_base(uint64_t base) { image_base_ = base; }
// (2) Address tables and indexes defined first.
CheckBool DefineRel32Label(int index, RVA address) WARN_UNUSED_RESULT;
@@ -56,7 +59,7 @@ class EncodedProgram {
CheckBool AddOrigin(RVA rva) WARN_UNUSED_RESULT;
CheckBool AddCopy(size_t count, const void* bytes) WARN_UNUSED_RESULT;
CheckBool AddRel32(int label_index) WARN_UNUSED_RESULT;
- CheckBool AddRel32ARM(uint16 op, int label_index) WARN_UNUSED_RESULT;
+ CheckBool AddRel32ARM(uint16_t op, int label_index) WARN_UNUSED_RESULT;
CheckBool AddAbs32(int label_index) WARN_UNUSED_RESULT;
CheckBool AddAbs64(int label_index) WARN_UNUSED_RESULT;
CheckBool AddPeMakeRelocs(ExecutableType kind) WARN_UNUSED_RESULT;
@@ -104,13 +107,13 @@ class EncodedProgram {
typedef NoThrowBuffer<RVA> RvaVector;
typedef NoThrowBuffer<size_t> SizeTVector;
- typedef NoThrowBuffer<uint32> UInt32Vector;
- typedef NoThrowBuffer<uint8> UInt8Vector;
+ typedef NoThrowBuffer<uint32_t> UInt32Vector;
+ typedef NoThrowBuffer<uint8_t> UInt8Vector;
typedef NoThrowBuffer<OP> OPVector;
void DebuggingSummary();
- CheckBool GeneratePeRelocations(SinkStream *buffer,
- uint8 type) WARN_UNUSED_RESULT;
+ CheckBool GeneratePeRelocations(SinkStream* buffer,
+ uint8_t type) WARN_UNUSED_RESULT;
CheckBool GenerateElfRelocations(Elf32_Word pending_elf_relocation_table,
SinkStream *buffer) WARN_UNUSED_RESULT;
CheckBool DefineLabelCommon(RvaVector*, int, RVA) WARN_UNUSED_RESULT;
@@ -121,7 +124,7 @@ class EncodedProgram {
SinkStream* output);
// Binary assembly language tables.
- uint64 image_base_;
+ uint64_t image_base_;
RvaVector rel32_rva_;
RvaVector abs32_rva_;
OPVector ops_;
diff --git a/courgette/encoded_program_fuzz_unittest.cc b/courgette/encoded_program_fuzz_unittest.cc
index 9801fc8..b755f85 100644
--- a/courgette/encoded_program_fuzz_unittest.cc
+++ b/courgette/encoded_program_fuzz_unittest.cc
@@ -13,6 +13,8 @@
#include "base/test/test_suite.h"
+#include <stddef.h>
+
#include "courgette/base_test_unittest.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
diff --git a/courgette/encoded_program_unittest.cc b/courgette/encoded_program_unittest.cc
index a2ce9b6..5d29452 100644
--- a/courgette/encoded_program_unittest.cc
+++ b/courgette/encoded_program_unittest.cc
@@ -4,6 +4,9 @@
#include "courgette/encoded_program.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "courgette/disassembler.h"
@@ -15,7 +18,7 @@ namespace {
using courgette::EncodedProgram;
struct AddressSpec {
- int32 index;
+ int32_t index;
courgette::RVA rva;
};
@@ -27,7 +30,7 @@ scoped_ptr<EncodedProgram> CreateTestProgram(AddressSpec* abs32_specs,
size_t num_rel32_specs) {
scoped_ptr<EncodedProgram> program(new EncodedProgram());
- uint32 base = 0x00900000;
+ uint32_t base = 0x00900000;
program->set_image_base(base);
for (size_t i = 0; i < num_abs32_specs; ++i) {
@@ -48,13 +51,13 @@ scoped_ptr<EncodedProgram> CreateTestProgram(AddressSpec* abs32_specs,
return program;
}
-bool CompareSink(const uint8 expected[],
+bool CompareSink(const uint8_t expected[],
size_t num_expected,
courgette::SinkStream* ss) {
size_t n = ss->Length();
if (num_expected != n)
return false;
- const uint8* buffer = ss->Buffer();
+ const uint8_t* buffer = ss->Buffer();
return memcmp(&expected[0], buffer, n) == 0;
}
@@ -98,9 +101,11 @@ TEST(EncodedProgramTest, Test) {
EXPECT_TRUE(can_assemble);
encoded2.reset();
- const uint8 golden[] = {
- 0x04, 0x00, 0x90, 0x00, // ABS32 to base + 4
- 0xF8, 0xFF, 0xFF, 0xFF // REL32 from next line to base + 2
+ const uint8_t golden[] = {
+ 0x04, 0x00, 0x90,
+ 0x00, // ABS32 to base + 4
+ 0xF8, 0xFF, 0xFF,
+ 0xFF // REL32 from next line to base + 2
};
EXPECT_TRUE(CompareSink(golden, arraysize(golden), &assembled));
}
@@ -121,15 +126,15 @@ TEST(EncodedProgramTest, TestWriteAddress) {
program.reset();
// Check addresses in sinks.
- const uint8 golden_abs32_indexes[] = {
- 0x03, 0x07, 0x03, 0x05 // 3 indexes: [7, 3, 5].
+ const uint8_t golden_abs32_indexes[] = {
+ 0x03, 0x07, 0x03, 0x05 // 3 indexes: [7, 3, 5].
};
EXPECT_TRUE(CompareSink(golden_abs32_indexes,
arraysize(golden_abs32_indexes),
sinks.stream(courgette::kStreamAbs32Indexes)));
- const uint8 golden_rel32_indexes[] = {
- 0x03, 0x00, 0x03, 0x01 // 3 indexes: [0, 3, 1].
+ const uint8_t golden_rel32_indexes[] = {
+ 0x03, 0x00, 0x03, 0x01 // 3 indexes: [0, 3, 1].
};
EXPECT_TRUE(CompareSink(golden_rel32_indexes,
arraysize(golden_rel32_indexes),
@@ -141,9 +146,9 @@ TEST(EncodedProgramTest, TestWriteAddress) {
// Hex: [0, 0, 0, 0x02, 0, 0x15, 0, 0xFFFFFFF4].
// Complement neg: [0, 0, 0, 0x02, 0, 0x15, 0, (0x0B)].
// Varint32 Signed: [0, 0, 0, 0x04, 0, 0x2A, 0, 0x17].
- const uint8 golden_abs32_addresses[] = {
- 0x08, // 8 address deltas.
- 0x00, 0x00, 0x00, 0x04, 0x00, 0x2A, 0x00, 0x17,
+ const uint8_t golden_abs32_addresses[] = {
+ 0x08, // 8 address deltas.
+ 0x00, 0x00, 0x00, 0x04, 0x00, 0x2A, 0x00, 0x17,
};
EXPECT_TRUE(CompareSink(golden_abs32_addresses,
arraysize(golden_abs32_addresses),
@@ -155,9 +160,9 @@ TEST(EncodedProgramTest, TestWriteAddress) {
// Hex: [0x10, 0xFFFFFFF7, 0, 0x19].
// Complement Neg: [0x10, (0x08), 0, 0x19].
// Varint32 Signed: [0x20, 0x11, 0, 0x32].
- const uint8 golden_rel32_addresses[] = {
- 0x04, // 4 address deltas.
- 0x20, 0x11, 0x00, 0x32,
+ const uint8_t golden_rel32_addresses[] = {
+ 0x04, // 4 address deltas.
+ 0x20, 0x11, 0x00, 0x32,
};
EXPECT_TRUE(CompareSink(golden_rel32_addresses,
arraysize(golden_rel32_addresses),
diff --git a/courgette/ensemble.cc b/courgette/ensemble.cc
index 669e264..d5277a4 100644
--- a/courgette/ensemble.cc
+++ b/courgette/ensemble.cc
@@ -4,7 +4,9 @@
#include "courgette/ensemble.h"
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "base/strings/string_number_conversions.h"
#include "courgette/region.h"
@@ -33,7 +35,7 @@ std::string Element::Name() const {
Status Ensemble::FindEmbeddedElements() {
size_t length = region_.length();
- const uint8* start = region_.start();
+ const uint8_t* start = region_.start();
size_t position = 0;
while (position < length) {
diff --git a/courgette/ensemble.h b/courgette/ensemble.h
index e538bd6..adb4b07 100644
--- a/courgette/ensemble.h
+++ b/courgette/ensemble.h
@@ -17,11 +17,13 @@
#ifndef COURGETTE_ENSEMBLE_H_
#define COURGETTE_ENSEMBLE_H_
-#include <vector>
-#include <string>
+#include <stddef.h>
+#include <stdint.h>
-#include "base/basictypes.h"
+#include <string>
+#include <vector>
+#include "base/macros.h"
#include "courgette/courgette.h"
#include "courgette/region.h"
#include "courgette/streams.h"
@@ -130,9 +132,9 @@ struct CourgettePatchFile {
// element-2
// ...
- static const uint32 kMagic = 'C' | ('o' << 8) | ('u' << 16);
+ static const uint32_t kMagic = 'C' | ('o' << 8) | ('u' << 16);
- static const uint32 kVersion = 20110216;
+ static const uint32_t kVersion = 20110216;
};
// For any transform you would implement both a TransformationPatcher and a
diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc
index 121fae8..f740ba9 100644
--- a/courgette/ensemble_apply.cc
+++ b/courgette/ensemble_apply.cc
@@ -6,10 +6,13 @@
#include "courgette/ensemble.h"
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
+#include "base/macros.h"
#include "courgette/crc.h"
#include "courgette/patcher_x86_32.h"
#include "courgette/region.h"
@@ -61,9 +64,9 @@ class EnsemblePatchApplication {
Region base_region_; // Location of in-memory copy of 'old' version.
- uint32 source_checksum_;
- uint32 target_checksum_;
- uint32 final_patch_input_size_prediction_;
+ uint32_t source_checksum_;
+ uint32_t target_checksum_;
+ uint32_t final_patch_input_size_prediction_;
std::vector<TransformationPatcher*> patchers_;
@@ -85,14 +88,14 @@ EnsemblePatchApplication::~EnsemblePatchApplication() {
}
Status EnsemblePatchApplication::ReadHeader(SourceStream* header_stream) {
- uint32 magic;
+ uint32_t magic;
if (!header_stream->ReadVarint32(&magic))
return C_BAD_ENSEMBLE_MAGIC;
if (magic != CourgettePatchFile::kMagic)
return C_BAD_ENSEMBLE_MAGIC;
- uint32 version;
+ uint32_t version;
if (!header_stream->ReadVarint32(&version))
return C_BAD_ENSEMBLE_VERSION;
@@ -117,7 +120,7 @@ Status EnsemblePatchApplication::InitBase(const Region& region) {
}
Status EnsemblePatchApplication::ValidateBase() {
- uint32 checksum = CalculateCrc(base_region_.start(), base_region_.length());
+ uint32_t checksum = CalculateCrc(base_region_.start(), base_region_.length());
if (source_checksum_ != checksum)
return C_BAD_ENSEMBLE_CRC;
@@ -126,12 +129,12 @@ Status EnsemblePatchApplication::ValidateBase() {
Status EnsemblePatchApplication::ReadInitialParameters(
SourceStream* transformation_parameters) {
- uint32 number_of_transformations = 0;
+ uint32_t number_of_transformations = 0;
if (!transformation_parameters->ReadVarint32(&number_of_transformations))
return C_BAD_ENSEMBLE_HEADER;
for (size_t i = 0; i < number_of_transformations; ++i) {
- uint32 kind;
+ uint32_t kind;
if (!transformation_parameters->ReadVarint32(&kind))
return C_BAD_ENSEMBLE_HEADER;
diff --git a/courgette/ensemble_create.cc b/courgette/ensemble_create.cc
index ea5873c..3bc1846 100644
--- a/courgette/ensemble_create.cc
+++ b/courgette/ensemble_create.cc
@@ -14,10 +14,11 @@
#include "courgette/ensemble.h"
+#include <stddef.h>
+
#include <limits>
#include <vector>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "base/time/time.h"
diff --git a/courgette/image_utils.h b/courgette/image_utils.h
index 47ba4f4..9a077fd 100644
--- a/courgette/image_utils.h
+++ b/courgette/image_utils.h
@@ -5,7 +5,8 @@
#ifndef COURGETTE_IMAGE_UTILS_H_
#define COURGETTE_IMAGE_UTILS_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+#include <stdint.h>
// COURGETTE_HISTOGRAM_TARGETS prints out a histogram of how frequently
// different target addresses are referenced. Purely for debugging.
@@ -13,7 +14,7 @@
namespace courgette {
-typedef uint32 RVA;
+typedef uint32_t RVA;
// A Label is a symbolic reference to an address. Unlike a conventional
// assembly language, we always know the address. The address will later be
@@ -32,32 +33,32 @@ class Label {
RVA rva_ = 0; // Address referred to by the label.
int index_ = kNoIndex; // Index of address in address table.
- int32 count_ = 0;
+ int32_t count_ = 0;
};
// These helper functions avoid the need for casts in the main code.
-inline uint16 ReadU16(const uint8* address, size_t offset) {
- return *reinterpret_cast<const uint16*>(address + offset);
+inline uint16_t ReadU16(const uint8_t* address, size_t offset) {
+ return *reinterpret_cast<const uint16_t*>(address + offset);
}
-inline uint32 ReadU32(const uint8* address, size_t offset) {
- return *reinterpret_cast<const uint32*>(address + offset);
+inline uint32_t ReadU32(const uint8_t* address, size_t offset) {
+ return *reinterpret_cast<const uint32_t*>(address + offset);
}
-inline uint64 ReadU64(const uint8* address, size_t offset) {
- return *reinterpret_cast<const uint64*>(address + offset);
+inline uint64_t ReadU64(const uint8_t* address, size_t offset) {
+ return *reinterpret_cast<const uint64_t*>(address + offset);
}
-inline uint16 Read16LittleEndian(const void* address) {
- return *reinterpret_cast<const uint16*>(address);
+inline uint16_t Read16LittleEndian(const void* address) {
+ return *reinterpret_cast<const uint16_t*>(address);
}
-inline uint32 Read32LittleEndian(const void* address) {
- return *reinterpret_cast<const uint32*>(address);
+inline uint32_t Read32LittleEndian(const void* address) {
+ return *reinterpret_cast<const uint32_t*>(address);
}
-inline uint64 Read64LittleEndian(const void* address) {
- return *reinterpret_cast<const uint64*>(address);
+inline uint64_t Read64LittleEndian(const void* address) {
+ return *reinterpret_cast<const uint64_t*>(address);
}
} // namespace courgette
diff --git a/courgette/image_utils_unittest.cc b/courgette/image_utils_unittest.cc
index a90c19b..5b914c5 100644
--- a/courgette/image_utils_unittest.cc
+++ b/courgette/image_utils_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/image_utils.h"
+#include <stdint.h>
+
#include "testing/gtest/include/gtest/gtest.h"
namespace courgette {
@@ -11,7 +13,7 @@ namespace courgette {
namespace {
TEST(ImageUtilsTest, Read) {
- uint8 test_data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 00};
+ uint8_t test_data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 00};
EXPECT_EQ(0x2301U, Read16LittleEndian(test_data));
EXPECT_EQ(0x67452301U, Read32LittleEndian(test_data));
EXPECT_EQ(0xEFCDAB8967452301ULL, Read64LittleEndian(test_data));
diff --git a/courgette/label_manager.cc b/courgette/label_manager.cc
index 14b6b4f..f19975d 100644
--- a/courgette/label_manager.cc
+++ b/courgette/label_manager.cc
@@ -4,6 +4,9 @@
#include "courgette/label_manager.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include "base/logging.h"
@@ -47,12 +50,12 @@ void LabelManager::Read(RvaVisitor* rva_visitor) {
labels_.reserve(num_distinct_rva);
for (CRV it(rvas.begin(), rvas.end()); it.has_more(); it.advance()) {
labels_.push_back(Label(*it.cur()));
- base::CheckedNumeric<uint32> count = it.repeat();
+ base::CheckedNumeric<uint32_t> count = it.repeat();
labels_.back().count_ = count.ValueOrDie();
}
}
-void LabelManager::RemoveUnderusedLabels(int32 count_threshold) {
+void LabelManager::RemoveUnderusedLabels(int32_t count_threshold) {
if (count_threshold <= 0)
return;
labels_.erase(std::remove_if(labels_.begin(), labels_.end(),
diff --git a/courgette/label_manager.h b/courgette/label_manager.h
index 595e2e7..d155561 100644
--- a/courgette/label_manager.h
+++ b/courgette/label_manager.h
@@ -5,6 +5,9 @@
#ifndef COURGETTE_LABEL_MANAGER_H_
#define COURGETTE_LABEL_MANAGER_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include <vector>
#include "base/macros.h"
@@ -43,7 +46,7 @@ class LabelManager {
void Read(RvaVisitor* rva_visitor);
// Removes |labels_| elements whose |count_| is less than |count_threshold|.
- void RemoveUnderusedLabels(int32 count_threshold);
+ void RemoveUnderusedLabels(int32_t count_threshold);
// Efficiently searches for a Label that targets |rva|. Returns the pointer to
// the stored Label instance if found, or null otherwise.
diff --git a/courgette/label_manager_unittest.cc b/courgette/label_manager_unittest.cc
index 2387162..acc6240 100644
--- a/courgette/label_manager_unittest.cc
+++ b/courgette/label_manager_unittest.cc
@@ -4,6 +4,9 @@
#include "courgette/label_manager.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <iterator>
#include <map>
#include <utility>
@@ -42,7 +45,7 @@ class TestLabelManager : public LabelManager {
};
void CheckLabelManagerContent(TestLabelManager* label_manager,
- const std::map<RVA, int32>& expected) {
+ const std::map<RVA, int32_t>& expected) {
EXPECT_EQ(expected.size(), label_manager->LabelCount());
for (const auto& rva_and_count : expected) {
Label* label = label_manager->Find(rva_and_count.first);
@@ -75,16 +78,11 @@ TEST(LabelManagerTest, Basic) {
TestLabelManager label_manager;
label_manager.Read(&visitor);
- static const std::pair<RVA, int32> kExpected1Raw[] = {
- {0x00000110, 1},
- {0x04000010, 3},
- {0x04000020, 1},
- {0x04000030, 2},
- {0xABCD1234, 1},
- {0xFEEDF00D, 2}
- };
- std::map<RVA, int32> expected1(std::begin(kExpected1Raw),
- std::end(kExpected1Raw));
+ static const std::pair<RVA, int32_t> kExpected1Raw[] = {
+ {0x00000110, 1}, {0x04000010, 3}, {0x04000020, 1},
+ {0x04000030, 2}, {0xABCD1234, 1}, {0xFEEDF00D, 2}};
+ std::map<RVA, int32_t> expected1(std::begin(kExpected1Raw),
+ std::end(kExpected1Raw));
CheckLabelManagerContent(&label_manager, expected1);
@@ -98,13 +96,10 @@ TEST(LabelManagerTest, Basic) {
// Remove Labels with |count_| < 2.
label_manager.RemoveUnderusedLabels(2);
- static const std::pair<RVA, int32> kExpected2Raw[] = {
- {0x04000010, 3},
- {0x04000030, 2},
- {0xFEEDF00D, 2}
- };
- std::map<RVA, int32> expected2(std::begin(kExpected2Raw),
- std::end(kExpected2Raw));
+ static const std::pair<RVA, int32_t> kExpected2Raw[] = {
+ {0x04000010, 3}, {0x04000030, 2}, {0xFEEDF00D, 2}};
+ std::map<RVA, int32_t> expected2(std::begin(kExpected2Raw),
+ std::end(kExpected2Raw));
CheckLabelManagerContent(&label_manager, expected2);
}
diff --git a/courgette/memory_allocator.cc b/courgette/memory_allocator.cc
index 5b92c80..e83a293 100644
--- a/courgette/memory_allocator.cc
+++ b/courgette/memory_allocator.cc
@@ -4,6 +4,9 @@
#include "courgette/memory_allocator.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <map>
#include "base/files/file_util.h"
@@ -108,7 +111,7 @@ bool TempMapping::Initialize(size_t size) {
}
void* TempMapping::memory() const {
- uint8* mem = reinterpret_cast<uint8*>(mapping_.view());
+ uint8_t* mem = reinterpret_cast<uint8_t*>(mapping_.view());
// The 'this' pointer is written at the start of mapping_.view(), so
// go past it. (See Initialize()).
if (mem)
diff --git a/courgette/memory_allocator.h b/courgette/memory_allocator.h
index 59d3ec8..6541e91 100644
--- a/courgette/memory_allocator.h
+++ b/courgette/memory_allocator.h
@@ -5,9 +5,10 @@
#ifndef COURGETTE_MEMORY_ALLOCATOR_H_
#define COURGETTE_MEMORY_ALLOCATOR_H_
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
-#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
@@ -194,12 +195,12 @@ class MemoryAllocator {
}
void deallocate(pointer ptr, size_type size) {
- uint8* mem = reinterpret_cast<uint8*>(ptr);
+ uint8_t* mem = reinterpret_cast<uint8_t*>(ptr);
mem -= sizeof(T);
if (mem[0] == HEAP_ALLOCATION) {
free(mem);
} else {
- DCHECK_EQ(static_cast<uint8>(FILE_ALLOCATION), mem[0]);
+ DCHECK_EQ(static_cast<uint8_t>(FILE_ALLOCATION), mem[0]);
UncheckedDelete(TempMapping::GetMappingFromPtr(mem));
}
}
@@ -215,20 +216,20 @@ class MemoryAllocator {
return NULL;
size_type bytes = count * sizeof(T);
- uint8* mem = NULL;
+ uint8_t* mem = NULL;
// First see if we can do this allocation on the heap.
if (count < kMaxHeapAllocationSize &&
base::UncheckedMalloc(bytes, reinterpret_cast<void**>(&mem))) {
- mem[0] = static_cast<uint8>(HEAP_ALLOCATION);
+ mem[0] = static_cast<uint8_t>(HEAP_ALLOCATION);
} else {
// Back the allocation with a temp file if either the request exceeds the
// max heap allocation threshold or the heap allocation failed.
TempMapping* mapping = UncheckedNew<TempMapping>();
if (mapping) {
if (mapping->Initialize(bytes)) {
- mem = reinterpret_cast<uint8*>(mapping->memory());
- mem[0] = static_cast<uint8>(FILE_ALLOCATION);
+ mem = reinterpret_cast<uint8_t*>(mapping->memory());
+ mem[0] = static_cast<uint8_t>(FILE_ALLOCATION);
} else {
UncheckedDelete(mapping);
}
diff --git a/courgette/memory_allocator_unittest.cc b/courgette/memory_allocator_unittest.cc
index 335cdc9..9d2d476 100644
--- a/courgette/memory_allocator_unittest.cc
+++ b/courgette/memory_allocator_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/memory_allocator.h"
+#include <stddef.h>
+
#include <algorithm>
#include "base/macros.h"
diff --git a/courgette/memory_monitor.cc b/courgette/memory_monitor.cc
index 2769cdc..a480531 100644
--- a/courgette/memory_monitor.cc
+++ b/courgette/memory_monitor.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stddef.h>
#include <stdio.h>
#include <map>
diff --git a/courgette/patch_generator_x86_32.h b/courgette/patch_generator_x86_32.h
index 3610eeb..ac558be 100644
--- a/courgette/patch_generator_x86_32.h
+++ b/courgette/patch_generator_x86_32.h
@@ -9,8 +9,8 @@
#define COURGETTE_WIN32_X86_GENERATOR_H_
#include "base/logging.h"
+#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-
#include "courgette/assembly_program.h"
#include "courgette/ensemble.h"
diff --git a/courgette/patcher_x86_32.h b/courgette/patcher_x86_32.h
index e984579..3461d79 100644
--- a/courgette/patcher_x86_32.h
+++ b/courgette/patcher_x86_32.h
@@ -5,6 +5,9 @@
#ifndef COURGETTE_WIN32_X86_PATCHER_H_
#define COURGETTE_WIN32_X86_PATCHER_H_
+#include <stdint.h>
+
+#include "base/macros.h"
#include "courgette/ensemble.h"
namespace courgette {
@@ -90,8 +93,8 @@ class PatcherX86_32 : public TransformationPatcher {
private:
Region ensemble_region_;
- uint32 base_offset_;
- uint32 base_length_;
+ uint32_t base_offset_;
+ uint32_t base_length_;
DISALLOW_COPY_AND_ASSIGN(PatcherX86_32);
};
diff --git a/courgette/region.h b/courgette/region.h
index 4aafbca..b0100cf 100644
--- a/courgette/region.h
+++ b/courgette/region.h
@@ -5,9 +5,11 @@
#ifndef COURGETTE_REGION_H_
#define COURGETTE_REGION_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include <string>
-#include "base/basictypes.h"
namespace courgette {
@@ -21,16 +23,13 @@ class Region {
// Usual constructor for regions given a |start| address and |length|.
Region(const void* start, size_t length)
- : start_(static_cast<const uint8*>(start)),
- length_(length) {
- }
+ : start_(static_cast<const uint8_t*>(start)), length_(length) {}
// String constructor. Region is owned by the string, so the string should
// have a lifetime greater than the region.
explicit Region(const std::string& string)
- : start_(reinterpret_cast<const uint8*>(string.c_str())),
- length_(string.length()) {
- }
+ : start_(reinterpret_cast<const uint8_t*>(string.c_str())),
+ length_(string.length()) {}
// Copy constructor.
Region(const Region& other) : start_(other.start_), length_(other.length_) {}
@@ -43,16 +42,16 @@ class Region {
}
// Returns the starting address of the region.
- const uint8* start() const { return start_; }
+ const uint8_t* start() const { return start_; }
// Returns the length of the region.
size_t length() const { return length_; }
// Returns the address after the last byte of the region.
- const uint8* end() const { return start_ + length_; }
+ const uint8_t* end() const { return start_ + length_; }
private:
- const uint8* start_;
+ const uint8_t* start_;
size_t length_;
void operator=(const Region&); // Disallow assignment operator.
diff --git a/courgette/rel32_finder_win32_x86.cc b/courgette/rel32_finder_win32_x86.cc
index 09419e9..171b781 100644
--- a/courgette/rel32_finder_win32_x86.cc
+++ b/courgette/rel32_finder_win32_x86.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdint.h>
+
#include "courgette/rel32_finder_win32_x86.h"
namespace courgette {
@@ -34,20 +36,19 @@ Rel32FinderWin32X86_Basic::Rel32FinderWin32X86_Basic(
Rel32FinderWin32X86_Basic::~Rel32FinderWin32X86_Basic() {
}
-void Rel32FinderWin32X86_Basic::Find(
- const uint8* start_pointer,
- const uint8* end_pointer,
- RVA start_rva,
- RVA end_rva,
- const std::vector<RVA>& abs32_locations) {
+void Rel32FinderWin32X86_Basic::Find(const uint8_t* start_pointer,
+ const uint8_t* end_pointer,
+ RVA start_rva,
+ RVA end_rva,
+ const std::vector<RVA>& abs32_locations) {
// Quick way to convert from Pointer to RVA within a single Section is to
// subtract 'pointer_to_rva'.
- const uint8* const adjust_pointer_to_rva = start_pointer - start_rva;
+ const uint8_t* const adjust_pointer_to_rva = start_pointer - start_rva;
std::vector<RVA>::const_iterator abs32_pos = abs32_locations.begin();
// Find the rel32 relocations.
- const uint8* p = start_pointer;
+ const uint8_t* p = start_pointer;
while (p < end_pointer) {
RVA current_rva = static_cast<RVA>(p - adjust_pointer_to_rva);
if (current_rva == relocs_start_rva_) {
@@ -63,7 +64,7 @@ void Rel32FinderWin32X86_Basic::Find(
// Heuristic discovery of rel32 locations in instruction stream: are the
// next few bytes the start of an instruction containing a rel32
// addressing mode?
- const uint8* rel32 = NULL;
+ const uint8_t* rel32 = NULL;
if (p + 5 <= end_pointer) {
if (*p == 0xE8 || *p == 0xE9) { // jmp rel32 and call rel32
diff --git a/courgette/rel32_finder_win32_x86.h b/courgette/rel32_finder_win32_x86.h
index 84dfe0b..24523d3 100644
--- a/courgette/rel32_finder_win32_x86.h
+++ b/courgette/rel32_finder_win32_x86.h
@@ -5,12 +5,13 @@
#ifndef COURGETTE_REL32_FINDER_WIN32_X86_H_
#define COURGETTE_REL32_FINDER_WIN32_X86_H_
+#include <stdint.h>
+
#if COURGETTE_HISTOGRAM_TARGETS
#include <map>
#endif
#include <vector>
-#include "base/basictypes.h"
#include "courgette/image_utils.h"
namespace courgette {
@@ -38,8 +39,8 @@ class Rel32FinderWin32X86 {
// - Do not collide with |base_relocation_table|'s RVA range,
// - Whose targets are in [|start_rva|, |end_rva|).
// The sorted results are written to |rel32_locations_|.
- virtual void Find(const uint8* start_pointer,
- const uint8* end_pointer,
+ virtual void Find(const uint8_t* start_pointer,
+ const uint8_t* end_pointer,
RVA start_rva,
RVA end_rva,
const std::vector<RVA>& abs32_locations) = 0;
@@ -65,8 +66,8 @@ class Rel32FinderWin32X86_Basic : public Rel32FinderWin32X86 {
virtual ~Rel32FinderWin32X86_Basic();
// Rel32FinderWin32X86 implementation.
- void Find(const uint8* start_pointer,
- const uint8* end_pointer,
+ void Find(const uint8_t* start_pointer,
+ const uint8_t* end_pointer,
RVA start_rva,
RVA end_rva,
const std::vector<RVA>& abs32_locations) override;
diff --git a/courgette/rel32_finder_win32_x86_unittest.cc b/courgette/rel32_finder_win32_x86_unittest.cc
index 08eb5c2..aed5c13 100644
--- a/courgette/rel32_finder_win32_x86_unittest.cc
+++ b/courgette/rel32_finder_win32_x86_unittest.cc
@@ -4,6 +4,9 @@
#include "courgette/rel32_finder_win32_x86.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <sstream>
#include <string>
@@ -47,7 +50,7 @@ class Rel32FinderWin32X86TestCase {
RVA relocs_start_rva_;
RVA relocs_end_rva_;
RVA image_end_rva_;
- std::vector<uint8> text_data_;
+ std::vector<uint8_t> text_data_;
std::vector<RVA> abs32_locations_;
std::vector<RVA> expected_rel32_locations_;
@@ -71,9 +74,9 @@ class Rel32FinderWin32X86TestCase {
return true;
}
- // Scans |iss| for the next non-empty line, and reads (hex) uint32 into |v|.
+ // Scans |iss| for the next non-empty line, and reads (hex) uint32_t into |v|.
// Returns true iff successful.
- bool ReadHexUInt32(std::istringstream& iss, uint32* v) {
+ bool ReadHexUInt32(std::istringstream& iss, uint32_t* v) {
std::string line;
if (!ReadNonEmptyLine(iss, &line))
return false;
@@ -103,11 +106,11 @@ class Rel32FinderWin32X86TestCase {
ASSERT_EQ("Program:", line);
while (ReadNonEmptyLine(iss, &line) && line != "Abs32:") {
std::string toks = line.substr(kBytesBegin, kBytesEnd);
- uint32 vals[6];
+ uint32_t vals[6];
int num_read = sscanf(toks.c_str(), "%X %X %X %X %X %X", &vals[0],
&vals[1], &vals[2], &vals[3], &vals[4], &vals[5]);
for (int i = 0; i < num_read; ++i)
- text_data_.push_back(static_cast<uint8>(vals[i] & 0xFF));
+ text_data_.push_back(static_cast<uint8_t>(vals[i] & 0xFF));
}
ASSERT_FALSE(text_data_.empty());
diff --git a/courgette/simple_delta.cc b/courgette/simple_delta.cc
index 37b910d..23f8430 100644
--- a/courgette/simple_delta.cc
+++ b/courgette/simple_delta.cc
@@ -7,7 +7,6 @@
#include "courgette/simple_delta.h"
-#include "base/basictypes.h"
#include "base/logging.h"
#include "courgette/third_party/bsdiff.h"
diff --git a/courgette/streams.cc b/courgette/streams.cc
index fcac593..d6bebf9 100644
--- a/courgette/streams.cc
+++ b/courgette/streams.cc
@@ -19,8 +19,9 @@
#include "courgette/streams.h"
#include <memory.h>
+#include <stddef.h>
+#include <stdint.h>
-#include "base/basictypes.h"
#include "base/logging.h"
namespace courgette {
@@ -35,19 +36,20 @@ static const unsigned int kStreamsSerializationFormatVersion = 20090218;
//
class Varint {
public:
- // Maximum lengths of varint encoding of uint32
+ // Maximum lengths of varint encoding of uint32_t
static const int kMax32 = 5;
// Parses a Varint32 encoded value from |source| and stores it in |output|,
// and returns a pointer to the following byte. Returns NULL if a valid
// varint value was not found before |limit|.
- static const uint8* Parse32WithLimit(const uint8* source, const uint8* limit,
- uint32* output);
+ static const uint8_t* Parse32WithLimit(const uint8_t* source,
+ const uint8_t* limit,
+ uint32_t* output);
// Writes the Varint32 encoded representation of |value| to buffer
// |destination|. |destination| must have sufficient length to hold kMax32
// bytes. Returns a pointer to the byte just past the last encoded byte.
- static uint8* Encode32(uint8* destination, uint32 value);
+ static uint8_t* Encode32(uint8_t* destination, uint32_t value);
};
// Parses a Varint32 encoded unsigned number from |source|. The Varint32
@@ -59,10 +61,10 @@ class Varint {
//
// The digit loop is unrolled for performance. It usually exits after the first
// one or two digits.
-const uint8* Varint::Parse32WithLimit(const uint8* source,
- const uint8* limit,
- uint32* output) {
- uint32 digit, result;
+const uint8_t* Varint::Parse32WithLimit(const uint8_t* source,
+ const uint8_t* limit,
+ uint32_t* output) {
+ uint32_t digit, result;
if (source >= limit)
return NULL;
digit = *(source++);
@@ -113,12 +115,12 @@ const uint8* Varint::Parse32WithLimit(const uint8* source,
// Write the base-128 digits in little-endian order. All except the last digit
// have the high bit set to indicate more digits.
-inline uint8* Varint::Encode32(uint8* destination, uint32 value) {
+inline uint8_t* Varint::Encode32(uint8_t* destination, uint32_t value) {
while (value >= 128) {
- *(destination++) = static_cast<uint8>(value) | 128;
+ *(destination++) = static_cast<uint8_t>(value) | 128;
value = value >> 7;
}
- *(destination++) = static_cast<uint8>(value);
+ *(destination++) = static_cast<uint8_t>(value);
return destination;
}
@@ -134,24 +136,24 @@ bool SourceStream::Read(void* destination, size_t count) {
return true;
}
-bool SourceStream::ReadVarint32(uint32* output_value) {
- const uint8* after = Varint::Parse32WithLimit(current_, end_, output_value);
+bool SourceStream::ReadVarint32(uint32_t* output_value) {
+ const uint8_t* after = Varint::Parse32WithLimit(current_, end_, output_value);
if (!after)
return false;
current_ = after;
return true;
}
-bool SourceStream::ReadVarint32Signed(int32* output_value) {
+bool SourceStream::ReadVarint32Signed(int32_t* output_value) {
// Signed numbers are encoded as unsigned numbers so that numbers nearer zero
// have shorter varint encoding.
// 0000xxxx encoded as 000xxxx0.
// 1111xxxx encoded as 000yyyy1 where yyyy is complement of xxxx.
- uint32 unsigned_value;
+ uint32_t unsigned_value;
if (!ReadVarint32(&unsigned_value))
return false;
if (unsigned_value & 1)
- *output_value = ~static_cast<int32>(unsigned_value >> 1);
+ *output_value = ~static_cast<int32_t>(unsigned_value >> 1);
else
*output_value = (unsigned_value >> 1);
return true;
@@ -185,13 +187,13 @@ CheckBool SinkStream::Write(const void* data, size_t byte_count) {
return buffer_.append(static_cast<const char*>(data), byte_count);
}
-CheckBool SinkStream::WriteVarint32(uint32 value) {
- uint8 buffer[Varint::kMax32];
- uint8* end = Varint::Encode32(buffer, value);
+CheckBool SinkStream::WriteVarint32(uint32_t value) {
+ uint8_t buffer[Varint::kMax32];
+ uint8_t* end = Varint::Encode32(buffer, value);
return Write(buffer, end - buffer);
}
-CheckBool SinkStream::WriteVarint32Signed(int32 value) {
+CheckBool SinkStream::WriteVarint32Signed(int32_t value) {
// Encode signed numbers so that numbers nearer zero have shorter
// varint encoding.
// 0000xxxx encoded as 000xxxx0.
@@ -205,7 +207,7 @@ CheckBool SinkStream::WriteVarint32Signed(int32 value) {
}
CheckBool SinkStream::WriteSizeVarint32(size_t value) {
- uint32 narrowed_value = static_cast<uint32>(value);
+ uint32_t narrowed_value = static_cast<uint32_t>(value);
// On 32-bit, the compiler should figure out this test always fails.
LOG_ASSERT(value == narrowed_value);
return WriteVarint32(narrowed_value);
@@ -239,11 +241,11 @@ SourceStreamSet::~SourceStreamSet() {
// <bytes1><bytes2>...<bytesN>
//
bool SourceStreamSet::Init(const void* source, size_t byte_count) {
- const uint8* start = static_cast<const uint8*>(source);
- const uint8* end = start + byte_count;
+ const uint8_t* start = static_cast<const uint8_t*>(source);
+ const uint8_t* end = start + byte_count;
unsigned int version;
- const uint8* finger = Varint::Parse32WithLimit(start, end, &version);
+ const uint8_t* finger = Varint::Parse32WithLimit(start, end, &version);
if (finger == NULL)
return false;
if (version != kStreamsSerializationFormatVersion)
@@ -287,12 +289,12 @@ bool SourceStreamSet::Init(SourceStream* source) {
}
bool SourceStreamSet::ReadSet(SourceStreamSet* set) {
- uint32 stream_count = 0;
+ uint32_t stream_count = 0;
SourceStream* control_stream = this->stream(0);
if (!control_stream->ReadVarint32(&stream_count))
return false;
- uint32 lengths[kMaxStreams] = {}; // i.e. all zero.
+ uint32_t lengths[kMaxStreams] = {}; // i.e. all zero.
for (size_t i = 0; i < stream_count; ++i) {
if (!control_stream->ReadVarint32(&lengths[i]))
@@ -364,13 +366,13 @@ CheckBool SinkStreamSet::CopyTo(SinkStream *combined_stream) {
}
CheckBool SinkStreamSet::WriteSet(SinkStreamSet* set) {
- uint32 lengths[kMaxStreams];
+ uint32_t lengths[kMaxStreams];
// 'stream_count' includes all non-empty streams and all empty stream numbered
// lower than a non-empty stream.
size_t stream_count = 0;
for (size_t i = 0; i < kMaxStreams; ++i) {
SinkStream* stream = set->stream(i);
- lengths[i] = static_cast<uint32>(stream->Length());
+ lengths[i] = static_cast<uint32_t>(stream->Length());
if (lengths[i] > 0)
stream_count = i + 1;
}
diff --git a/courgette/streams.h b/courgette/streams.h
index ff65d13..c23d710 100644
--- a/courgette/streams.h
+++ b/courgette/streams.h
@@ -10,15 +10,17 @@
// writing. Streams are aggregated into Sets which allows several streams to be
// used at once. Example: we can write A1, B1, A2, B2 but achieve the memory
// layout A1 A2 B1 B2 by writing 'A's to one stream and 'B's to another.
+
#ifndef COURGETTE_STREAMS_H_
#define COURGETTE_STREAMS_H_
+#include <stddef.h>
+#include <stdint.h>
#include <stdio.h> // for FILE*
#include <string>
-#include "base/basictypes.h"
#include "base/compiler_specific.h"
-
+#include "base/macros.h"
#include "courgette/memory_allocator.h"
#include "courgette/region.h"
@@ -41,7 +43,7 @@ class SourceStream {
// still owns the memory at |pointer| and should free the memory only after
// the last use of the stream.
void Init(const void* pointer, size_t length) {
- start_ = static_cast<const uint8*>(pointer);
+ start_ = static_cast<const uint8_t*>(pointer);
end_ = start_ + length;
current_ = start_;
}
@@ -67,7 +69,7 @@ class SourceStream {
// Returns initial length of stream before any data consumed by reading.
size_t OriginalLength() const { return end_ - start_; }
- const uint8* Buffer() const { return current_; }
+ const uint8_t* Buffer() const { return current_; }
bool Empty() const { return current_ == end_; }
// Copies bytes from stream to memory at |destination|. Returns 'false' if
@@ -76,11 +78,11 @@ class SourceStream {
// Reads a varint formatted unsigned integer from stream. Returns 'false' if
// the read failed due to insufficient data or malformed Varint32.
- bool ReadVarint32(uint32* output_value);
+ bool ReadVarint32(uint32_t* output_value);
// Reads a varint formatted signed integer from stream. Returns 'false' if
// the read failed due to insufficient data or malformed Varint32.
- bool ReadVarint32Signed(int32* output_value);
+ bool ReadVarint32Signed(int32_t* output_value);
// Initializes |substream| to yield |length| bytes from |this| stream,
// starting at |offset| bytes from the current position. Returns 'false' if
@@ -103,9 +105,9 @@ class SourceStream {
bool Skip(size_t byte_count);
private:
- const uint8* start_; // Points to start of buffer.
- const uint8* end_; // Points to first location after buffer.
- const uint8* current_; // Points into buffer at current read location.
+ const uint8_t* start_; // Points to start of buffer.
+ const uint8_t* end_; // Points to first location after buffer.
+ const uint8_t* current_; // Points into buffer at current read location.
DISALLOW_COPY_AND_ASSIGN(SourceStream);
};
@@ -124,13 +126,13 @@ class SinkStream {
CheckBool Write(const void* data, size_t byte_count) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32(uint32 value) WARN_UNUSED_RESULT;
+ CheckBool WriteVarint32(uint32_t value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- CheckBool WriteVarint32Signed(int32 value) WARN_UNUSED_RESULT;
+ CheckBool WriteVarint32Signed(int32_t value) WARN_UNUSED_RESULT;
// Appends the 'varint32' encoding of |value| to the stream.
- // On platforms where sizeof(size_t) != sizeof(int32), do a safety check.
+ // On platforms where sizeof(size_t) != sizeof(int32_t), do a safety check.
CheckBool WriteSizeVarint32(size_t value) WARN_UNUSED_RESULT;
// Contents of |other| are appended to |this| stream. The |other| stream
@@ -143,8 +145,8 @@ class SinkStream {
// Returns a pointer to contiguously allocated Length() bytes in the stream.
// Writing to the stream invalidates the pointer. The SinkStream continues to
// own the memory.
- const uint8* Buffer() const {
- return reinterpret_cast<const uint8*>(buffer_.data());
+ const uint8_t* Buffer() const {
+ return reinterpret_cast<const uint8_t*>(buffer_.data());
}
// Hints that the stream will grow by an additional |length| bytes.
diff --git a/courgette/streams_unittest.cc b/courgette/streams_unittest.cc
index d0903c9..67fd6b0 100644
--- a/courgette/streams_unittest.cc
+++ b/courgette/streams_unittest.cc
@@ -4,6 +4,9 @@
#include "courgette/streams.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,7 +17,7 @@ TEST(StreamsTest, SimpleWriteRead) {
EXPECT_TRUE(sink.WriteVarint32(kValue1));
- const uint8* sink_buffer = sink.Buffer();
+ const uint8_t* sink_buffer = sink.Buffer();
size_t length = sink.Length();
courgette::SourceStream source;
@@ -32,7 +35,7 @@ TEST(StreamsTest, SimpleWriteRead2) {
EXPECT_TRUE(sink.Write("Hello", 5));
- const uint8* sink_buffer = sink.Buffer();
+ const uint8_t* sink_buffer = sink.Buffer();
size_t sink_length = sink.Length();
courgette::SourceStream source;
@@ -57,14 +60,14 @@ TEST(StreamsTest, StreamSetWriteRead) {
EXPECT_TRUE(out.CopyTo(&collected));
- const uint8* collected_buffer = collected.Buffer();
+ const uint8_t* collected_buffer = collected.Buffer();
size_t collected_length = collected.Length();
courgette::SourceStreamSet in;
bool can_init = in.Init(collected_buffer, collected_length);
EXPECT_TRUE(can_init);
- uint32 value;
+ uint32_t value;
bool can_read = in.stream(3)->ReadVarint32(&value);
EXPECT_TRUE(can_read);
EXPECT_EQ(kValue1, value);
@@ -104,7 +107,7 @@ TEST(StreamsTest, StreamSetWriteRead2) {
for (size_t i = 0; data[i] != kEnd; i += 2) {
size_t id = data[i];
size_t datum = data[i + 1];
- uint32 value = 77;
+ uint32_t value = 77;
bool can_read = in.stream(id)->ReadVarint32(&value);
EXPECT_TRUE(can_read);
EXPECT_EQ(datum, value);
@@ -118,16 +121,13 @@ TEST(StreamsTest, StreamSetWriteRead2) {
TEST(StreamsTest, SignedVarint32) {
courgette::SinkStream out;
- static const int32 data[] = {
- 0, 64, 128, 8192, 16384,
- 1 << 20, 1 << 21, 1 << 22,
- 1 << 27, 1 << 28,
- 0x7fffffff, -0x7fffffff
- };
+ static const int32_t data[] = {0, 64, 128, 8192,
+ 16384, 1 << 20, 1 << 21, 1 << 22,
+ 1 << 27, 1 << 28, 0x7fffffff, -0x7fffffff};
- std::vector<int32> values;
+ std::vector<int32_t> values;
for (size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) {
- int32 basis = data[i];
+ int32_t basis = data[i];
for (int delta = -4; delta <= 4; ++delta) {
EXPECT_TRUE(out.WriteVarint32Signed(basis + delta));
values.push_back(basis + delta);
@@ -141,7 +141,7 @@ TEST(StreamsTest, SignedVarint32) {
for (size_t i = 0; i < values.size(); ++i) {
int written_value = values[i];
- int32 datum;
+ int32_t datum;
bool can_read = in.ReadVarint32Signed(&datum);
EXPECT_TRUE(can_read);
EXPECT_EQ(written_value, datum);
@@ -188,7 +188,7 @@ TEST(StreamsTest, StreamSetReadWrite) {
EXPECT_FALSE(subset1.Empty());
EXPECT_FALSE(subset1.Empty());
- uint32 datum;
+ uint32_t datum;
EXPECT_TRUE(subset1.stream(3)->ReadVarint32(&datum));
EXPECT_EQ(30000U, datum);
EXPECT_TRUE(subset1.stream(5)->ReadVarint32(&datum));
diff --git a/courgette/third_party/bsdiff.h b/courgette/third_party/bsdiff.h
index 7c4888c..1a7e025 100644
--- a/courgette/third_party/bsdiff.h
+++ b/courgette/third_party/bsdiff.h
@@ -37,7 +37,8 @@
#ifndef COURGETTE_BSDIFF_H_
#define COURGETTE_BSDIFF_H_
-#include "base/basictypes.h"
+#include <stdint.h>
+
#include "base/files/file_util.h"
namespace courgette {
@@ -79,9 +80,9 @@ BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_stream,
// The patch stream starts with a MBSPatchHeader.
typedef struct MBSPatchHeader_ {
char tag[8]; // Contains MBS_PATCH_HEADER_TAG
- uint32 slen; // Length of the file to be patched.
- uint32 scrc32; // CRC32 of the file to be patched.
- uint32 dlen; // Length of the result file.
+ uint32_t slen; // Length of the file to be patched.
+ uint32_t scrc32; // CRC32 of the file to be patched.
+ uint32_t dlen; // Length of the result file.
} MBSPatchHeader;
// This is the value for the tag field. Must match length exactly, not counting
diff --git a/courgette/third_party/bsdiff_apply.cc b/courgette/third_party/bsdiff_apply.cc
index 48ee1be..537f194 100644
--- a/courgette/third_party/bsdiff_apply.cc
+++ b/courgette/third_party/bsdiff_apply.cc
@@ -36,6 +36,9 @@
#include "courgette/third_party/bsdiff.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "base/files/memory_mapped_file.h"
#include "courgette/crc.h"
#include "courgette/streams.h"
@@ -57,11 +60,12 @@ BSDiffStatus MBS_ReadHeader(SourceStream* stream, MBSPatchHeader* header) {
return OK;
}
-BSDiffStatus MBS_ApplyPatch(const MBSPatchHeader *header,
+BSDiffStatus MBS_ApplyPatch(const MBSPatchHeader* header,
SourceStream* patch_stream,
- const uint8* old_start, size_t old_size,
+ const uint8_t* old_start,
+ size_t old_size,
SinkStream* new_stream) {
- const uint8* old_end = old_start + old_size;
+ const uint8_t* old_end = old_start + old_size;
SourceStreamSet patch_streams;
if (!patch_streams.Init(patch_stream))
@@ -74,22 +78,22 @@ BSDiffStatus MBS_ApplyPatch(const MBSPatchHeader *header,
SourceStream* diff_bytes = patch_streams.stream(4);
SourceStream* extra_bytes = patch_streams.stream(5);
- const uint8* extra_start = extra_bytes->Buffer();
- const uint8* extra_end = extra_start + extra_bytes->Remaining();
- const uint8* extra_position = extra_start;
+ const uint8_t* extra_start = extra_bytes->Buffer();
+ const uint8_t* extra_end = extra_start + extra_bytes->Remaining();
+ const uint8_t* extra_position = extra_start;
- const uint8* old_position = old_start;
+ const uint8_t* old_position = old_start;
if (header->dlen && !new_stream->Reserve(header->dlen))
return MEM_ERROR;
- uint32 pending_diff_zeros = 0;
+ uint32_t pending_diff_zeros = 0;
if (!diff_skips->ReadVarint32(&pending_diff_zeros))
return UNEXPECTED_ERROR;
while (!control_stream_copy_counts->Empty()) {
- uint32 copy_count, extra_count;
- int32 seek_adjustment;
+ uint32_t copy_count, extra_count;
+ int32_t seek_adjustment;
if (!control_stream_copy_counts->ReadVarint32(&copy_count))
return UNEXPECTED_ERROR;
if (!control_stream_extra_counts->ReadVarint32(&extra_count))
@@ -108,7 +112,7 @@ BSDiffStatus MBS_ApplyPatch(const MBSPatchHeader *header,
// Add together bytes from the 'old' file and the 'diff' stream.
for (size_t i = 0; i < copy_count; ++i) {
- uint8 diff_byte = 0;
+ uint8_t diff_byte = 0;
if (pending_diff_zeros) {
--pending_diff_zeros;
} else {
@@ -117,7 +121,7 @@ BSDiffStatus MBS_ApplyPatch(const MBSPatchHeader *header,
if (!diff_bytes->Read(&diff_byte, 1))
return UNEXPECTED_ERROR;
}
- uint8 byte = old_position[i] + diff_byte;
+ uint8_t byte = old_position[i] + diff_byte;
if (!new_stream->Write(&byte, 1))
return MEM_ERROR;
}
@@ -158,7 +162,7 @@ BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream,
BSDiffStatus ret = MBS_ReadHeader(patch_stream, &header);
if (ret != OK) return ret;
- const uint8* old_start = old_stream->Buffer();
+ const uint8_t* old_start = old_stream->Buffer();
size_t old_size = old_stream->Remaining();
if (old_size != header.slen) return UNEXPECTED_ERROR;
diff --git a/courgette/third_party/bsdiff_create.cc b/courgette/third_party/bsdiff_create.cc
index b883f73..61b36cf 100644
--- a/courgette/third_party/bsdiff_create.cc
+++ b/courgette/third_party/bsdiff_create.cc
@@ -28,6 +28,8 @@
#include "courgette/third_party/bsdiff.h"
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <algorithm>
@@ -67,10 +69,10 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
SinkStream* diff_bytes = patch_streams.stream(4);
SinkStream* extra_bytes = patch_streams.stream(5);
- const uint8* old = old_stream->Buffer();
+ const uint8_t* old = old_stream->Buffer();
const int oldsize = static_cast<int>(old_stream->Remaining());
- uint32 pending_diff_zeros = 0;
+ uint32_t pending_diff_zeros = 0;
PagedArray<int> I;
PagedArray<int> V;
@@ -93,7 +95,7 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
<< (base::Time::Now() - q_start_time).InSecondsF();
V.clear();
- const uint8* newbuf = new_stream->Buffer();
+ const uint8_t* newbuf = new_stream->Buffer();
const int newsize = static_cast<int>(new_stream->Remaining());
int control_length = 0;
@@ -224,7 +226,7 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
};
for (int i = 0; i < lenf; i++) {
- uint8 diff_byte = newbuf[lastscan + i] - old[lastpos + i];
+ uint8_t diff_byte = newbuf[lastscan + i] - old[lastpos + i];
if (diff_byte) {
++diff_bytes_nonzero;
if (!diff_skips->WriteVarint32(pending_diff_zeros))
@@ -245,9 +247,9 @@ BSDiffStatus CreateBinaryPatch(SourceStream* old_stream,
diff_bytes_length += lenf;
extra_bytes_length += gap;
- uint32 copy_count = lenf;
- uint32 extra_count = gap;
- int32 seek_adjustment = ((pos - lenb) - (lastpos + lenf));
+ uint32_t copy_count = lenf;
+ uint32_t extra_count = gap;
+ int32_t seek_adjustment = ((pos - lenb) - (lastpos + lenf));
if (!control_stream_copy_counts->WriteVarint32(copy_count) ||
!control_stream_extra_counts->WriteVarint32(extra_count) ||
diff --git a/courgette/third_party/paged_array.h b/courgette/third_party/paged_array.h
index 76cb879..48a92f1 100644
--- a/courgette/third_party/paged_array.h
+++ b/courgette/third_party/paged_array.h
@@ -11,7 +11,9 @@
#ifndef COURGETTE_BSDIFF_PAGED_ARRAY_H_
#define COURGETTE_BSDIFF_PAGED_ARRAY_H_
-#include "base/basictypes.h"
+#include <stddef.h>
+
+#include "base/macros.h"
#include "base/process/memory.h"
namespace courgette {
diff --git a/courgette/third_party/qsufsort_unittest.cc b/courgette/third_party/qsufsort_unittest.cc
index 675eac4..e0ece01 100644
--- a/courgette/third_party/qsufsort_unittest.cc
+++ b/courgette/third_party/qsufsort_unittest.cc
@@ -4,6 +4,8 @@
#include "courgette/third_party/qsufsort.h"
+#include <stddef.h>
+
#include <algorithm>
#include <cstring>
#include <string>
diff --git a/courgette/typedrva_unittest.cc b/courgette/typedrva_unittest.cc
index dc30fa9..d0ad833 100644
--- a/courgette/typedrva_unittest.cc
+++ b/courgette/typedrva_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdint.h>
+
#include "courgette/base_test_unittest.h"
#include "courgette/disassembler_elf_32_arm.h"
#include "courgette/disassembler_elf_32_x86.h"
@@ -14,12 +16,12 @@ class TypedRVATest : public BaseTest {
void TestRelativeTargetARM(courgette::ARM_RVA arm_rva,
courgette::RVA rva,
- uint32 op,
+ uint32_t op,
courgette::RVA expected) const;
void TestARMOPEncode(courgette::ARM_RVA arm_rva,
courgette::RVA rva,
- uint32 op,
+ uint32_t op,
courgette::RVA expected) const;
};
@@ -27,7 +29,7 @@ void TypedRVATest::TestRelativeTargetX86(courgette::RVA word,
courgette::RVA expected) const {
courgette::DisassemblerElf32X86::TypedRVAX86* typed_rva
= new courgette::DisassemblerElf32X86::TypedRVAX86(0);
- const uint8* op_pointer = reinterpret_cast<const uint8*>(&word);
+ const uint8_t* op_pointer = reinterpret_cast<const uint8_t*>(&word);
EXPECT_TRUE(typed_rva->ComputeRelativeTarget(op_pointer));
EXPECT_EQ(typed_rva->relative_target(), expected);
@@ -35,17 +37,17 @@ void TypedRVATest::TestRelativeTargetX86(courgette::RVA word,
delete typed_rva;
}
-uint32 Read32LittleEndian(const void* address) {
- return *reinterpret_cast<const uint32*>(address);
+uint32_t Read32LittleEndian(const void* address) {
+ return *reinterpret_cast<const uint32_t*>(address);
}
void TypedRVATest::TestRelativeTargetARM(courgette::ARM_RVA arm_rva,
courgette::RVA rva,
- uint32 op,
+ uint32_t op,
courgette::RVA expected) const {
courgette::DisassemblerElf32ARM::TypedRVAARM* typed_rva
= new courgette::DisassemblerElf32ARM::TypedRVAARM(arm_rva, rva);
- uint8* op_pointer = reinterpret_cast<uint8*>(&op);
+ uint8_t* op_pointer = reinterpret_cast<uint8_t*>(&op);
EXPECT_TRUE(typed_rva->ComputeRelativeTarget(op_pointer));
EXPECT_EQ(rva + typed_rva->relative_target(), expected);
@@ -54,16 +56,16 @@ void TypedRVATest::TestRelativeTargetARM(courgette::ARM_RVA arm_rva,
}
void TypedRVATest::TestARMOPEncode(courgette::ARM_RVA arm_rva,
- courgette::RVA rva,
- uint32 op,
- courgette::RVA expected) const {
- uint16 c_op;
- uint32 addr;
+ courgette::RVA rva,
+ uint32_t op,
+ courgette::RVA expected) const {
+ uint16_t c_op;
+ uint32_t addr;
EXPECT_TRUE(courgette::DisassemblerElf32ARM::Compress(arm_rva, op, rva,
&c_op, &addr));
EXPECT_EQ(rva + addr, expected);
- uint32 new_op;
+ uint32_t new_op;
EXPECT_TRUE(courgette::DisassemblerElf32ARM::Decompress(arm_rva, c_op, addr,
&new_op));
EXPECT_EQ(new_op, op);
diff --git a/courgette/types_elf.h b/courgette/types_elf.h
index eb054ee..a98fd8b 100644
--- a/courgette/types_elf.h
+++ b/courgette/types_elf.h
@@ -5,17 +5,18 @@
#ifndef COURGETTE_ELF_TYPES_H_
#define COURGETTE_ELF_TYPES_H_
+#include <stdint.h>
+
//
// This header defines various types from the ELF file spec, but no code
// related to using them.
//
-typedef uint32 Elf32_Addr; // Unsigned program address
-typedef uint16 Elf32_Half; // Unsigned medium integer
-typedef uint32 Elf32_Off; // Unsigned file offset
-typedef int32 Elf32_Sword; // Signed large integer
-typedef uint32 Elf32_Word; // Unsigned large integer
-
+typedef uint32_t Elf32_Addr; // Unsigned program address
+typedef uint16_t Elf32_Half; // Unsigned medium integer
+typedef uint32_t Elf32_Off; // Unsigned file offset
+typedef int32_t Elf32_Sword; // Signed large integer
+typedef uint32_t Elf32_Word; // Unsigned large integer
// The header at the top of the file
struct Elf32_Ehdr {
diff --git a/courgette/types_win_pe.h b/courgette/types_win_pe.h
index eed88af..f926b5f 100644
--- a/courgette/types_win_pe.h
+++ b/courgette/types_win_pe.h
@@ -5,8 +5,8 @@
#ifndef TYPES_WIN_PE_H_
#define TYPES_WIN_PE_H_
-#include "base/basictypes.h"
-
+#include <stddef.h>
+#include <stdint.h>
namespace courgette {
@@ -17,15 +17,15 @@ namespace courgette {
#pragma pack(push, 1) // Supported by MSVC and GCC. Ensures no gaps in packing.
struct Section {
char name[8];
- uint32 virtual_size;
- uint32 virtual_address;
- uint32 size_of_raw_data;
- uint32 file_offset_of_raw_data;
- uint32 pointer_to_relocations; // Always zero in an image.
- uint32 pointer_to_line_numbers; // Always zero in an image.
- uint16 number_of_relocations; // Always zero in an image.
- uint16 number_of_line_numbers; // Always zero in an image.
- uint32 characteristics;
+ uint32_t virtual_size;
+ uint32_t virtual_address;
+ uint32_t size_of_raw_data;
+ uint32_t file_offset_of_raw_data;
+ uint32_t pointer_to_relocations; // Always zero in an image.
+ uint32_t pointer_to_line_numbers; // Always zero in an image.
+ uint16_t number_of_relocations; // Always zero in an image.
+ uint16_t number_of_line_numbers; // Always zero in an image.
+ uint32_t characteristics;
};
#pragma pack(pop)
@@ -39,7 +39,7 @@ class ImageDataDirectory {
public:
ImageDataDirectory() : address_(0), size_(0) {}
RVA address_;
- uint32 size_;
+ uint32_t size_;
};
static_assert(sizeof(ImageDataDirectory) == 8,
@@ -54,8 +54,8 @@ static_assert(sizeof(ImageDataDirectory) == 8,
// This is FIELD_OFFSET(IMAGE_DOS_HEADER, e_lfanew):
const size_t kOffsetOfFileAddressOfNewExeHeader = 0x3c;
-const uint16 kImageNtOptionalHdr32Magic = 0x10b;
-const uint16 kImageNtOptionalHdr64Magic = 0x20b;
+const uint16_t kImageNtOptionalHdr32Magic = 0x10b;
+const uint16_t kImageNtOptionalHdr64Magic = 0x20b;
const size_t kSizeOfCoffHeader = 20;
const size_t kOffsetOfDataDirectoryFromImageOptionalHeader32 = 96;
diff --git a/courgette/versioning_unittest.cc b/courgette/versioning_unittest.cc
index 91154d8..655aa93 100644
--- a/courgette/versioning_unittest.cc
+++ b/courgette/versioning_unittest.cc
@@ -4,9 +4,10 @@
#include "courgette/base_test_unittest.h"
+#include <stddef.h>
+
#include <string>
-#include "base/basictypes.h"
#include "courgette/courgette.h"
#include "courgette/streams.h"
#include "courgette/third_party/bsdiff.h"