1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COURGETTE_DISASSEMBLER_WIN32_X86_H_
6 #define COURGETTE_DISASSEMBLER_WIN32_X86_H_
11 #include "courgette/disassembler_win32.h"
12 #include "courgette/image_utils.h"
13 #include "courgette/types_win_pe.h"
17 class InstructionReceptor;
19 class DisassemblerWin32X86 : public DisassemblerWin32 {
21 // Returns true if a valid executable is detected using only quick checks.
22 static bool QuickDetect(const uint8_t* start, size_t length) {
23 return DisassemblerWin32::QuickDetect(start, length,
24 kImageNtOptionalHdr32Magic);
27 DisassemblerWin32X86(const uint8_t* start, size_t length);
29 DisassemblerWin32X86(const DisassemblerWin32X86&) = delete;
30 DisassemblerWin32X86& operator=(const DisassemblerWin32X86&) = delete;
32 ~DisassemblerWin32X86() override = default;
34 // Disassembler interfaces.
35 RVA PointerToTargetRVA(const uint8_t* p) const override;
36 ExecutableType kind() const override { return EXE_WIN_32_X86; }
38 // (4) -> (5) (see AddressTranslator comment): Returns the RVA of the VA
39 // specified by |address|, or kNoRVA if |address| lies outside of the image.
40 RVA Address32ToRVA(uint32_t address) const;
43 // DisassemblerWin32 interfaces.
44 void ParseRel32RelocsFromSection(const Section* section) override;
45 int AbsVAWidth() const override { return 4; }
46 CheckBool EmitAbs(Label* label, InstructionReceptor* receptor) const override;
47 bool SupportsRelTableType(int type) const override {
48 return type == 3; // IMAGE_REL_BASED_HIGHLOW
50 uint16_t RelativeOffsetOfDataDirectories() const override {
51 return kOffsetOfDataDirectoryFromImageOptionalHeader32;
55 } // namespace courgette
57 #endif // COURGETTE_DISASSEMBLER_WIN32_X86_H_