⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stabs.cpp

📁 一个完全使用MFC框架开发的C++编译器的代码。功能十分强大可以编译大型程序。
💻 CPP
字号:
// ------- stabs.cpp

#include "stdafx.h"
#include "stabs.h"

CStab::CStab(const std::string& filename)
{
	hasstabs = false;
	// ---- open the executable file
    std::ifstream ifile(filename.c_str(), std::ios::binary);
	if (!ifile.fail())	{

		// ----- read the DOS header
		IMAGE_DOS_HEADER dosheader;
		ifile.read((char*)&dosheader, sizeof dosheader);

		// ----- test .exe file signature
		if (dosheader.e_magic == IMAGE_DOS_SIGNATURE)	{
			// --- is an executable

			// ----- read offset to portable executable header
			ifile.seekg(dosheader.e_lfanew);
			// ---- read the pertable executable header
			struct {
				long signature;
				IMAGE_FILE_HEADER fhdr;
				IMAGE_OPTIONAL_HEADER ohdr;
			} header;

			ifile.read((char*)&header, sizeof header);
			// ----  check the signature
			if (header.signature == IMAGE_NT_SIGNATURE)	{
				// --- is a portable exe file

				// ----- iterate through the segments looking for .stab
				for (int i = 0; i < header.fhdr.NumberOfSections; i++)	{
					IMAGE_SECTION_HEADER secthdr;
					ifile.read((char*)&secthdr, sizeof(secthdr));
					char name[9];
					strncpy(name, (char*)secthdr.Name, 8);
					name[8] = '\0';

					if (strcmp(name, ".stab") == 0)	{
						hasstabs = true;
						break;
					}
				}
			}
		}
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -