mirror of
https://github.com/reactos/CMake.git
synced 2024-11-25 12:40:06 +00:00
bindexplib: clang-format
This commit is contained in:
parent
9a733c7bd6
commit
7a8860afbc
1
Source/.gitattributes
vendored
1
Source/.gitattributes
vendored
@ -17,5 +17,4 @@
|
||||
/cmListFileLexer.c generated
|
||||
|
||||
# Do not format third-party sources.
|
||||
/bindexplib.* -format.clang-format
|
||||
/kwsys/** -format.clang-format
|
||||
|
@ -68,7 +68,8 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
typedef struct cmANON_OBJECT_HEADER_BIGOBJ {
|
||||
typedef struct cmANON_OBJECT_HEADER_BIGOBJ
|
||||
{
|
||||
/* same as ANON_OBJECT_HEADER_V2 */
|
||||
WORD Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
|
||||
WORD Sig2; // Must be 0xffff
|
||||
@ -87,10 +88,13 @@ typedef struct cmANON_OBJECT_HEADER_BIGOBJ {
|
||||
DWORD NumberOfSymbols;
|
||||
} cmANON_OBJECT_HEADER_BIGOBJ;
|
||||
|
||||
typedef struct _cmIMAGE_SYMBOL_EX {
|
||||
union {
|
||||
typedef struct _cmIMAGE_SYMBOL_EX
|
||||
{
|
||||
union
|
||||
{
|
||||
BYTE ShortName[8];
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
DWORD Short; // if 0, use LongName
|
||||
DWORD Long; // offset into string table
|
||||
} Name;
|
||||
@ -104,27 +108,26 @@ typedef struct _cmIMAGE_SYMBOL_EX {
|
||||
} cmIMAGE_SYMBOL_EX;
|
||||
typedef cmIMAGE_SYMBOL_EX UNALIGNED* cmPIMAGE_SYMBOL_EX;
|
||||
|
||||
PIMAGE_SECTION_HEADER GetSectionHeaderOffset(PIMAGE_FILE_HEADER
|
||||
pImageFileHeader)
|
||||
PIMAGE_SECTION_HEADER GetSectionHeaderOffset(
|
||||
PIMAGE_FILE_HEADER pImageFileHeader)
|
||||
{
|
||||
return (PIMAGE_SECTION_HEADER)
|
||||
((DWORD_PTR)pImageFileHeader +
|
||||
return (PIMAGE_SECTION_HEADER)((DWORD_PTR)pImageFileHeader +
|
||||
IMAGE_SIZEOF_FILE_HEADER +
|
||||
pImageFileHeader->SizeOfOptionalHeader);
|
||||
}
|
||||
|
||||
PIMAGE_SECTION_HEADER GetSectionHeaderOffset(cmANON_OBJECT_HEADER_BIGOBJ*
|
||||
pImageFileHeader)
|
||||
PIMAGE_SECTION_HEADER GetSectionHeaderOffset(
|
||||
cmANON_OBJECT_HEADER_BIGOBJ* pImageFileHeader)
|
||||
{
|
||||
return (PIMAGE_SECTION_HEADER)
|
||||
((DWORD_PTR)pImageFileHeader +
|
||||
return (PIMAGE_SECTION_HEADER)((DWORD_PTR)pImageFileHeader +
|
||||
sizeof(cmANON_OBJECT_HEADER_BIGOBJ));
|
||||
}
|
||||
|
||||
/*
|
||||
+ * Utility func, strstr with size
|
||||
+ */
|
||||
const char* StrNStr(const char* start, const char* find, size_t &size) {
|
||||
const char* StrNStr(const char* start, const char* find, size_t& size)
|
||||
{
|
||||
size_t len;
|
||||
const char* hint;
|
||||
|
||||
@ -162,18 +165,16 @@ public:
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
DumpSymbols(ObjectHeaderType* ih,
|
||||
std::set<std::string>& symbols,
|
||||
std::set<std::string>& dataSymbols,
|
||||
bool is64)
|
||||
:Symbols(symbols), DataSymbols(dataSymbols)
|
||||
DumpSymbols(ObjectHeaderType* ih, std::set<std::string>& symbols,
|
||||
std::set<std::string>& dataSymbols, bool is64)
|
||||
: Symbols(symbols)
|
||||
, DataSymbols(dataSymbols)
|
||||
{
|
||||
this->ObjectImageHeader = ih;
|
||||
this->SymbolTable = (SymbolTableType*)
|
||||
((DWORD_PTR)this->ObjectImageHeader
|
||||
+ this->ObjectImageHeader->PointerToSymbolTable);
|
||||
this->SectionHeaders =
|
||||
GetSectionHeaderOffset(this->ObjectImageHeader);
|
||||
this->SymbolTable =
|
||||
(SymbolTableType*)((DWORD_PTR) this->ObjectImageHeader +
|
||||
this->ObjectImageHeader->PointerToSymbolTable);
|
||||
this->SectionHeaders = GetSectionHeaderOffset(this->ObjectImageHeader);
|
||||
this->SymbolCount = this->ObjectImageHeader->NumberOfSymbols;
|
||||
this->Is64Bit = is64;
|
||||
}
|
||||
@ -187,21 +188,25 @@ public:
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
bool HaveExportedObjects() {
|
||||
bool HaveExportedObjects()
|
||||
{
|
||||
WORD i = 0;
|
||||
size_t size = 0;
|
||||
const char* rawdata = 0;
|
||||
PIMAGE_SECTION_HEADER pDirectivesSectionHeader = 0;
|
||||
PIMAGE_SECTION_HEADER pSectionHeaders = this->SectionHeaders;
|
||||
for (i = 0; (i < this->ObjectImageHeader->NumberOfSections &&
|
||||
!pDirectivesSectionHeader); i++)
|
||||
!pDirectivesSectionHeader);
|
||||
i++)
|
||||
if (!strncmp((const char*)&pSectionHeaders[i].Name[0], ".drectve", 8))
|
||||
pDirectivesSectionHeader = &pSectionHeaders[i];
|
||||
if (!pDirectivesSectionHeader) return 0;
|
||||
if (!pDirectivesSectionHeader)
|
||||
return 0;
|
||||
|
||||
rawdata=(const char*)
|
||||
this->ObjectImageHeader+pDirectivesSectionHeader->PointerToRawData;
|
||||
if (!pDirectivesSectionHeader->PointerToRawData || !rawdata) return 0;
|
||||
rawdata = (const char*)this->ObjectImageHeader +
|
||||
pDirectivesSectionHeader->PointerToRawData;
|
||||
if (!pDirectivesSectionHeader->PointerToRawData || !rawdata)
|
||||
return 0;
|
||||
|
||||
size = pDirectivesSectionHeader->SizeOfRawData;
|
||||
const char* posImportFlag = rawdata;
|
||||
@ -214,10 +219,12 @@ public:
|
||||
}
|
||||
|
||||
const char* lookingForDATA = posImportFlag + 9;
|
||||
while (*(++lookingForDATA) && *lookingForDATA != ' ');
|
||||
while (*(++lookingForDATA) && *lookingForDATA != ' ')
|
||||
;
|
||||
lookingForDATA -= 5;
|
||||
// ignore DATA exports
|
||||
if (strncmp(lookingForDATA, ",DATA", 5)) break;
|
||||
if (strncmp(lookingForDATA, ",DATA", 5))
|
||||
break;
|
||||
posImportFlag = lookingForDATA + 5;
|
||||
}
|
||||
if (posImportFlag) {
|
||||
@ -233,9 +240,7 @@ public:
|
||||
* Dump an object file's exported symbols.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
void DumpObjFile() {
|
||||
this->DumpExternalsObjects();
|
||||
}
|
||||
void DumpObjFile() { this->DumpExternalsObjects(); }
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
@ -244,7 +249,8 @@ public:
|
||||
* Dumps a COFF symbol table from an OBJ.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
void DumpExternalsObjects() {
|
||||
void DumpExternalsObjects()
|
||||
{
|
||||
unsigned i;
|
||||
PSTR stringTable;
|
||||
std::string symbol;
|
||||
@ -269,7 +275,8 @@ public:
|
||||
}
|
||||
|
||||
// clear out any leading spaces
|
||||
while (isspace(symbol[0])) symbol.erase(0,1);
|
||||
while (isspace(symbol[0]))
|
||||
symbol.erase(0, 1);
|
||||
// if it starts with _ and has an @ then it is a __cdecl
|
||||
// so remove the @ stuff for the export
|
||||
if (symbol[0] == '_') {
|
||||
@ -279,10 +286,8 @@ public:
|
||||
}
|
||||
}
|
||||
// For 64 bit builds we don't need to remove _
|
||||
if(!this->Is64Bit)
|
||||
{
|
||||
if (symbol[0] == '_')
|
||||
{
|
||||
if (!this->Is64Bit) {
|
||||
if (symbol[0] == '_') {
|
||||
symbol.erase(0, 1);
|
||||
}
|
||||
}
|
||||
@ -298,17 +303,14 @@ public:
|
||||
// if scalarPrefix and vectorPrefix are not found then print
|
||||
// the symbol
|
||||
if (symbol.compare(0, 4, scalarPrefix) &&
|
||||
symbol.compare(0, 4, vectorPrefix) )
|
||||
{
|
||||
SectChar =
|
||||
this->
|
||||
SectionHeaders[pSymbolTable->SectionNumber-1].Characteristics;
|
||||
symbol.compare(0, 4, vectorPrefix)) {
|
||||
SectChar = this->SectionHeaders[pSymbolTable->SectionNumber - 1]
|
||||
.Characteristics;
|
||||
if (!pSymbolTable->Type && (SectChar & IMAGE_SCN_MEM_WRITE)) {
|
||||
// Read only (i.e. constants) must be excluded
|
||||
this->DataSymbols.insert(symbol);
|
||||
} else {
|
||||
if ( pSymbolTable->Type ||
|
||||
!(SectChar & IMAGE_SCN_MEM_READ) ||
|
||||
if (pSymbolTable->Type || !(SectChar & IMAGE_SCN_MEM_READ) ||
|
||||
(SectChar & IMAGE_SCN_MEM_EXECUTE)) {
|
||||
this->Symbols.insert(symbol);
|
||||
} else {
|
||||
@ -317,16 +319,17 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (pSymbolTable->SectionNumber == IMAGE_SYM_UNDEFINED &&
|
||||
} else if (pSymbolTable->SectionNumber == IMAGE_SYM_UNDEFINED &&
|
||||
!pSymbolTable->Type && 0) {
|
||||
/*
|
||||
* The IMPORT global variable entry points
|
||||
*/
|
||||
if (pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) {
|
||||
symbol = stringTable + pSymbolTable->N.Name.Long;
|
||||
while (isspace(symbol[0])) symbol.erase(0,1);
|
||||
if (symbol[0] == '_') symbol.erase(0,1);
|
||||
while (isspace(symbol[0]))
|
||||
symbol.erase(0, 1);
|
||||
if (symbol[0] == '_')
|
||||
symbol.erase(0, 1);
|
||||
this->DataSymbols.insert(symbol);
|
||||
}
|
||||
}
|
||||
@ -339,6 +342,7 @@ public:
|
||||
pSymbolTable++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<std::string>& Symbols;
|
||||
std::set<std::string>& DataSymbols;
|
||||
@ -349,9 +353,7 @@ private:
|
||||
bool Is64Bit;
|
||||
};
|
||||
|
||||
bool
|
||||
DumpFile(const char* filename,
|
||||
std::set<std::string>& symbols,
|
||||
bool DumpFile(const char* filename, std::set<std::string>& symbols,
|
||||
std::set<std::string>& dataSymbols)
|
||||
{
|
||||
HANDLE hFile;
|
||||
@ -359,9 +361,9 @@ DumpFile(const char* filename,
|
||||
LPVOID lpFileBase;
|
||||
PIMAGE_DOS_HEADER dosHeader;
|
||||
|
||||
hFile = CreateFileW(cmsys::Encoding::ToWide(filename).c_str(),
|
||||
GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
hFile = CreateFileW(cmsys::Encoding::ToWide(filename).c_str(), GENERIC_READ,
|
||||
FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
fprintf(stderr, "Couldn't open file '%s' with CreateFile()\n", filename);
|
||||
@ -389,28 +391,24 @@ DumpFile(const char* filename,
|
||||
return false;
|
||||
}
|
||||
/* Does it look like a i386 COFF OBJ file??? */
|
||||
else if (
|
||||
((dosHeader->e_magic == IMAGE_FILE_MACHINE_I386) ||
|
||||
(dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64))
|
||||
&& (dosHeader->e_sp == 0)
|
||||
) {
|
||||
else if (((dosHeader->e_magic == IMAGE_FILE_MACHINE_I386) ||
|
||||
(dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64)) &&
|
||||
(dosHeader->e_sp == 0)) {
|
||||
/*
|
||||
* The two tests above aren't what they look like. They're
|
||||
* really checking for IMAGE_FILE_HEADER.Machine == i386 (0x14C)
|
||||
* and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
|
||||
*/
|
||||
DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL>
|
||||
symbolDumper((PIMAGE_FILE_HEADER) lpFileBase, symbols, dataSymbols,
|
||||
DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
|
||||
(PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
|
||||
(dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64));
|
||||
symbolDumper.DumpObjFile();
|
||||
} else {
|
||||
// check for /bigobj format
|
||||
cmANON_OBJECT_HEADER_BIGOBJ* h =
|
||||
(cmANON_OBJECT_HEADER_BIGOBJ*) lpFileBase;
|
||||
cmANON_OBJECT_HEADER_BIGOBJ* h = (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase;
|
||||
if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
|
||||
DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX>
|
||||
symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*) lpFileBase, symbols,
|
||||
dataSymbols,
|
||||
DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX> symbolDumper(
|
||||
(cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols, dataSymbols,
|
||||
(h->Machine == IMAGE_FILE_MACHINE_AMD64));
|
||||
symbolDumper.DumpObjFile();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user