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

Unified Diff: courgette/image_utils.h

Issue 1676683002: [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrap #include <iostream> under #if COURGETTE_HISTOGRAM_TARGETS. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/disassembler_win32_x86_unittest.cc ('k') | courgette/rel32_finder_win32_x86.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/image_utils.h
diff --git a/courgette/image_utils.h b/courgette/image_utils.h
index f958cc12f8f3b01db9bb1d2005b2ec64d2f289fa..cfbfcfe2406dc7f6a9de84fb47e3185dad57aa68 100644
--- a/courgette/image_utils.h
+++ b/courgette/image_utils.h
@@ -14,8 +14,44 @@
namespace courgette {
-typedef uint32_t RVA;
+// There are several ways to reason about addresses in an image:
+// - File Offset: Position relative to start of image.
+// - VA (Virtual Address): Virtual memory address of a loaded image. This is
+// subject to relocation by the OS.
+// - RVA (Relative Virtual Address): VA relative to some base address. This is
+// the preferred way to specify pointers in an image. Two ways to encode RVA
+// are:
+// - abs32: RVA value is encoded directly.
+// - rel32: RVA is encoded as offset from an instruction address. This is
+// commonly used for relative branch/call opcodes.
+// Courgette operates on File Offsets and RVAs only.
+
+using RVA = uint32_t;
const RVA kUnassignedRVA = 0xFFFFFFFFU;
+const RVA kNoRVA = 0xFFFFFFFFU;
+
+using FileOffset = size_t;
+const FileOffset kNoFileOffset = UINTPTR_MAX;
+
+// An interface for {File Offset, RVA, pointer to image data} translation.
+class AddressTranslator {
+ public:
+ // Returns the RVA corresponding to |file_offset|, or kNoRVA if nonexistent.
+ virtual RVA FileOffsetToRVA(FileOffset file_offset) const = 0;
+
+ // Returns the file offset corresponding to |rva|, or kNoFileOffset if
+ // nonexistent.
+ virtual FileOffset RVAToFileOffset(RVA rva) const = 0;
+
+ // Returns the pointer to the image data for |file_offset|. Assumes that
+ // 0 <= |file_offset| <= image size. If |file_offset| == image, the resulting
+ // pointer is an end bound for iteration that should never be dereferenced.
+ virtual const uint8_t* FileOffsetToPointer(FileOffset file_offset) const = 0;
+
+ // Returns the pointer to the image data for |rva|, or null if |rva| is
+ // invalid.
+ virtual const uint8_t* RVAToPointer(RVA rva) const = 0;
+};
// A Label is a symbolic reference to an address. Unlike a conventional
// assembly language, we always know the address. The address will later be
« no previous file with comments | « courgette/disassembler_win32_x86_unittest.cc ('k') | courgette/rel32_finder_win32_x86.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698