summaryrefslogtreecommitdiffhomepage
path: root/Kernel/KernelKit/MSDOS.hxx
blob: a7da9e861873677d8255b512560fc59178941a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* -------------------------------------------

	Copyright ZKA Technologies

	File: MSDOS.hpp
	Purpose: MS-DOS header for Kernel.

	Revision History:

	30/01/24: Added file (amlel)

------------------------------------------- */

#ifndef __MSDOS_EXEC__
#define __MSDOS_EXEC__

#include <KernelKit/PE.hxx>
#include <NewKit/Defines.hpp>

// Last Rev
// Sat Feb 24 CET 2024

#define kMagMz0 'M'
#define kMagMz1 'Z'

typedef Kernel::UInt32 DosWord;
typedef Kernel::Long   DosLong;

typedef struct _DosHeader
{
	Kernel::UInt8 eMagic[2];
	DosWord		  eMagLen;
	DosWord		  ePagesCount;
	DosWord		  eCrlc;
	DosWord		  eCParHdr;
	DosWord		  eMinAlloc;
	DosWord		  eMaxAlloc;
	DosWord		  eStackSeg;
	DosWord		  eStackPtr;
	DosWord		  eChksum;
	DosWord		  eIp;
	DosWord		  eCs;
	DosWord		  eLfarlc;
	DosWord		  eOvno;
	DosWord		  eRes[4];
	DosWord		  eOemid;
	DosWord		  eOeminfo;
	DosWord		  eRes2[10];
	DosLong		  eLfanew;
} DosHeader, *DosHeaderPtr;

namespace Kernel
{
	/// @brief Find the PE header inside the the blob.
	inline auto rt_find_exec_header(DosHeaderPtr ptrDos) -> VoidPtr
	{
		if (!ptrDos)
			return nullptr;

		if (ptrDos->eMagic[0] != kMagMz0)
			return nullptr;

		if (ptrDos->eMagic[1] != kMagMz1)
			return nullptr;

		return (VoidPtr)(&ptrDos->eLfanew + 1);
	}
} // namespace Kernel

#endif /* ifndef __MSDOS_EXEC__ */