MCPcopy Create free account
hub / github.com/catboost/catboost / IsElf

Function IsElf

tools/fix_elf/patch.cpp:13–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace NElf {
12
13bool IsElf(const TString& path) {
14 TUnbufferedFileInput in(path);
15 char buffer[EI_NIDENT];
16 size_t nread = in.Load(buffer, sizeof(buffer));
17
18 if (nread != sizeof(buffer) || TStringBuf(buffer, SELFMAG) != ELFMAG) {
19 Cerr << "fix_elf skip " << path << " (not an ELF file)";
20 return false;
21 }
22
23 if (buffer[EI_CLASS] != ELFCLASS64) {
24 Cerr << "fix_elf skip " << path << " (ELF class is not ELF64)";
25 return false;
26 }
27
28#ifdef _little_endian_
29 if (buffer[EI_DATA] != ELFDATA2LSB) {
30 Cerr << "fix_elf skip " << path << " (ELF byte order is not native LSB)";
31 return false;
32 }
33#else
34 if (buffer[EI_DATA] != ELFDATA2MSB) {
35 Cerr << "fix_elf skip " << path << " (ELF byte order is not native MSB)";
36 return false;
37 }
38#endif
39
40 if (buffer[EI_VERSION] != 1) {
41 Cerr << "fix_elf skip " << path << " (ELF version is not 1)";
42 return false;
43 }
44
45 return true;
46}
47
48} // namespace NElf
49

Callers 1

mainFunction · 0.85

Calls 1

LoadMethod · 0.45

Tested by

no test coverage detected