BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
DOSExe.h
Go to the documentation of this file.
1#pragma once
2
3#include "../MappedExe.h"
4#include "DosHdrWrapper.h"
5
6#define DOS_PARAGRAPH 0x10
7
8class DOSExeBuilder: public ExeBuilder {
9public:
11 virtual bool signatureMatches(AbstractByteBuffer *buf);
12 virtual Executable* build(AbstractByteBuffer *buf);
13 QString typeName() { return "MZ"; }
14};
15
16//-------------------------------------------------------------
17
18class DOSExe : public MappedExe
19{
20public:
26
28 virtual ~DOSExe() { }
29
31
32 // inherited from Executable:
33 //
34 virtual void wrap();
35 // FileAddr <-> RVA
36 virtual offset_t rawToRva(offset_t raw) { return (raw < codeOffset()) ? INVALID_ADDR : raw - codeOffset(); }
37 virtual offset_t rvaToRaw(offset_t rva) { return rva + codeOffset(); } //TODO
38
40 {
41 if (aType == Executable::RAW)
42 return getContentSize();
43 return moduleSize() - codeOffset();
44 }
45
46 virtual bufsize_t getAlignment(Executable::addr_type aType) const { return 0; } //TODO
47 virtual offset_t getImageBase(bool recalculate = false) { return m_dosHdr->e_cs; }
49
50 //---
51 // DOS Exe only:
52 virtual offset_t dosHeaderOffset() { return 0; } //wrapper's mount point
54
55protected:
56 offset_t codeOffset() { return static_cast<offset_t> (m_dosHdr->e_cparhdr) * DOS_PARAGRAPH; }
58 {
59 const size_t unit_size = 0x200;
60 WORD size = m_dosHdr->e_cp * unit_size;
61 if (m_dosHdr->e_cblp ) {
62 WORD trimSize = unit_size - m_dosHdr->e_cblp;
63 size -= trimSize;
64 }
65 return static_cast<bufsize_t> (size);
66 }
67
68
70 IMAGE_DOS_HEADER* m_dosHdr;
71};
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
#define DOS_PARAGRAPH
Definition DOSExe.h:6
DOSExeBuilder()
Definition DOSExe.h:10
virtual Executable * build(AbstractByteBuffer *buf)
Definition DOSExe.cpp:18
QString typeName()
Definition DOSExe.h:13
virtual bool signatureMatches(AbstractByteBuffer *buf)
Definition DOSExe.cpp:4
offset_t codeOffset()
Definition DOSExe.h:56
virtual offset_t dosHeaderOffset()
Definition DOSExe.h:52
virtual offset_t rvaToRaw(offset_t rva)
Definition DOSExe.h:37
virtual void wrap()
Definition DOSExe.cpp:40
DOSExe(AbstractByteBuffer *v_buf)
Definition DOSExe.cpp:34
bufsize_t moduleSize()
Definition DOSExe.h:57
IMAGE_DOS_HEADER * m_dosHdr
Definition DOSExe.h:70
offset_t peSignatureOffset()
Definition DOSExe.cpp:60
virtual offset_t getImageBase(bool recalculate=false)
Definition DOSExe.h:47
virtual exe_arch getArch()
Definition DOSExe.h:30
DosHdrWrapper * dosHdrWrapper
Definition DOSExe.h:69
virtual offset_t getEntryPoint(Executable::addr_type aType=Executable::RVA)
Definition DOSExe.h:48
virtual offset_t rawToRva(offset_t raw)
Definition DOSExe.h:36
virtual bufsize_t getMappedSize(Executable::addr_type aType)
Definition DOSExe.h:39
WRAPPERS
Definition DOSExe.h:21
@ WR_NONE
Definition DOSExe.h:22
@ COUNT_WRAPPERS
Definition DOSExe.h:24
@ WR_DOS_HDR
Definition DOSExe.h:23
virtual ~DOSExe()
Definition DOSExe.h:28
virtual bufsize_t getAlignment(Executable::addr_type aType) const
Definition DOSExe.h:46
virtual bufsize_t getContentSize()
Definition Executable.h:59