stabs.cpp
来自「一个完全使用MFC框架开发的C++编译器的代码。功能十分强大可以编译大型程序。」· C++ 代码 · 共 54 行
CPP
54 行
// ------- 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*)§hdr, 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 + =
减小字号Ctrl + -
显示快捷键?