Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't support elf file? #425

Closed
fbs2016 opened this issue Dec 29, 2020 · 7 comments
Closed

Don't support elf file? #425

fbs2016 opened this issue Dec 29, 2020 · 7 comments

Comments

@fbs2016
Copy link

fbs2016 commented Dec 29, 2020

I try to parse an elf file but it return undefined and can't find elf file from "Supported file types".

@sindresorhus
Copy link
Owner

What is an elf file?

@fbs2016
Copy link
Author

fbs2016 commented Dec 29, 2020

Like .out/.o file:
sh-5.0$ file hello.out
hello.out: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped

@SpraxDev
Copy link

SpraxDev commented Mar 13, 2021

According to Wikipedia

In computing, the Executable and Linkable Format (ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, object code, shared libraries, and core dumps.

There's sadly no issue template where I can see what info is needed for a new type to be added but I'll try my best:

Magic numbers (hex): 7f 45 4c 46
Mime type: application/x-elf (Apperantly application/x-coredump, application/x-executable, application/x-object and application/x-sharedlib are valid too but less common as they require parsing the file header)
File extensions (hard to say as it is used with a lot of variety): .so, .o, .elf, .bin

You can find some additional information on https://manpages.debian.org/buster/manpages/elf.5.en.html

@somebody1234
Copy link
Contributor

  if (check([0x7F, 0x45, 0x4c, 0x46])) {
    return ['', 'application/x-elf'];
  }

should work. not sure what to do about file extensions; generally when you're checking the filetype of a binary it probably won't have an extension

@Marinell0
Copy link

Was this fixed with #514 ?

@Borewit
Copy link
Collaborator

Borewit commented Jul 29, 2022

I think ELF has been implemented:

file-type/core.js

Lines 789 to 794 in 4110073

if (this.check([0x7F, 0x45, 0x4C, 0x46])) {
return {
ext: 'elf',
mime: 'application/x-elf',
};
}

@Borewit Borewit closed this as completed Jul 29, 2022
@regamboa
Copy link

Hi, folks:

I had posted a comment to Sindre via Twitter, who suggested that I repeat it here. The ELF file format is the standard executable format for Linux/Unix, the same way that the Portable Executable format is for Windows. Typically in Unix land, one doesn't use file extensions for executables. Instead, you need to check headers and magic numbers as you have been doing. You managed to spot the magic number, but what you might not realize is that it spells out Unicode character 0x7f followed by 'ELF'.

There's a C library called BFD (binary file descriptors), which is part of the binutils project (https://www.gnu.org/software/binutils/) that makes file checking quite a bit easier.Binutils is also the home for the GNU assembler (gas) and is considered a core part of all Linux distributions. It's also available for Windows via Cygwin and Mac, as well as other OS platforms.

If you want more details on the ELF file format specifically, note that the specification doesn't exist on its own. It's part of the Unix ABI (Application Binary Interface) specification at http://www.sco.com/developers/devspecs/gabi41.pdf. Chapters 4 and 5 provide relevant details on the ELF format.

I've been programming on Linux for...eeek, a couple of decades now, so if you need more information, please feel free to contact me at robygamboa@gmail.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants