file signature - Linux

This is a discussion on file signature - Linux ; I can't use stdc to write a file signature for a file format can I? Wouldn't I have to get into the sys calls and maybe even kernel internals to do this with lynx. I am going to write a ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: file signature

  1. file signature

    I can't use stdc to write a file signature for a file format can I?
    Wouldn't I have to get into the sys calls and maybe even kernel internals to
    do this with lynx. I am going to write a parser soon. But I want to parser
    to have a unique signature in it's header somewhere. 0x7f is I believe the
    signature for linux. I will write a 128 unique number generator in C with
    linux to get the number so it will not conflict with other file types like
    adobe's .pdf and so on. Can anyone suggest any source code to create a file
    signature and what else I might need to do?

    Bill



  2. Re: file signature


    "Bill Cunningham" wrote in message
    news:48dac89f$0$5476$bbae4d71@news.suddenlink.net. ..
    > I can't use stdc to write a file signature for a file format can I?
    > Wouldn't I have to get into the sys calls and maybe even kernel internals
    > to do this with lynx. I am going to write a parser soon. But I want to
    > parser to have a unique signature in it's header somewhere. 0x7f is I
    > believe the signature for linux. I will write a 128 unique number
    > generator in C with linux to get the number so it will not conflict with
    > other file types like adobe's .pdf and so on. Can anyone suggest any
    > source code to create a file signature and what else I might need to do?
    >
    > Bill


    I have a feeling elf.h is going to be needed here.

    B



  3. Re: file signature


    "Bill Cunningham" writes:

    > I can't use stdc to write a file signature for a file format can I?
    > Wouldn't I have to get into the sys calls and maybe even kernel internals to
    > do this with lynx. I am going to write a parser soon. But I want to parser
    > to have a unique signature in it's header somewhere. 0x7f is I believe the
    > signature for linux. I will write a 128 unique number generator in C with
    > linux to get the number so it will not conflict with other file types like
    > adobe's .pdf and so on. Can anyone suggest any source code to create a file
    > signature and what else I might need to do?
    >
    > Bill


    By stdc do you mean "standard c" Bill?

    I think you should ask in c.l.c : they are always willing to help people
    with their parsers and 128 unique number generators there!

    Enjoy!

    9/10

    Crosspost & Followup-To: comp.lang.c

    (ps not bad - almost as good as the one where you were telling the lads
    in linux development how you were about to write a device driver!)

  4. Re: file signature

    "Bill Cunningham" writes:

    > I can't use stdc to write a file signature for a file format can I?
    > Wouldn't I have to get into the sys calls and maybe even kernel internals to
    > do this with lynx. I am going to write a parser soon. But I want to parser
    > to have a unique signature in it's header somewhere. 0x7f is I believe the
    > signature for linux. I will write a 128 unique number generator in C with
    > linux to get the number so it will not conflict with other file types like
    > adobe's .pdf and so on. Can anyone suggest any source code to create a file
    > signature and what else I might need to do?


    I'm sorry -- what are you talking about? You can write anything you
    want to any file you want. If you want to start your file with the
    string "Bill Cunningham's File Format" you're more than welcome to do
    that. I've got no idea what this has to do with lynx, and less what
    you mean you say 7f is the signature for linux.

  5. Re: file signature


    "Joe Pfeiffer" wrote in message
    news:1bprmtt36z.fsf@snowball.wb.pfeifferfamily.net ...

    > I'm sorry -- what are you talking about? You can write anything you
    > want to any file you want. If you want to start your file with the
    > string "Bill Cunningham's File Format" you're more than welcome to do
    > that. I've got no idea what this has to do with lynx, and less what
    > you mean you say 7f is the signature for linux.


    Yes yes sorry. I said lynx and not linux. Lynx is a web browser. I mean
    in the OS's internals. STDC is higher level than what I want and this is
    what this group is supposed to be about.

    Bill



  6. Re: file signature

    "Bill Cunningham" writes:

    > "Joe Pfeiffer" wrote in message
    > news:1bprmtt36z.fsf@snowball.wb.pfeifferfamily.net ...
    >
    >> I'm sorry -- what are you talking about? You can write anything you
    >> want to any file you want. If you want to start your file with the
    >> string "Bill Cunningham's File Format" you're more than welcome to do
    >> that. I've got no idea what this has to do with lynx, and less what
    >> you mean you say 7f is the signature for linux.

    >
    > Yes yes sorry. I said lynx and not linux. Lynx is a web browser. I mean
    > in the OS's internals. STDC is higher level than what I want and this is
    > what this group is supposed to be about.


    I'm still confused -- when you say "stdc", do you mean the standard C
    library, aka libc? It doesn't get much lower level than the write()
    system call. And I still don't know what "7C is the signature for
    linux" would mean.


  7. Re: file signature

    Bill Cunningham wrote:
    > "Joe Pfeiffer" wrote in message
    > news:1bprmtt36z.fsf@snowball.wb.pfeifferfamily.net ...
    >
    >> I'm sorry -- what are you talking about? You can write anything you
    >> want to any file you want. If you want to start your file with the
    >> string "Bill Cunningham's File Format" you're more than welcome to do
    >> that. I've got no idea what this has to do with lynx, and less what
    >> you mean you say 7f is the signature for linux.

    >
    > Yes yes sorry. I said lynx and not linux. Lynx is a web browser. I mean
    > in the OS's internals. STDC is higher level than what I want and this is
    > what this group is supposed to be about.


    IIUC you want your file to have a specific signature that lets you
    identify *your* files?
    I don't know anything about the details, but ELF has .note sections that
    you might be able to use for your purpose. Then there is also the
    ..comment section that looks promising, too.

    Oh, and BTW the magic for ELF is four bytes: { 0x7f, 'E', 'L', 'F' }!

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html

  8. Re: file signature


    "Josef Moellers" wrote in message
    news:gbi141$ble$1@nntp.fujitsu-siemens.com...

    > IIUC you want your file to have a specific signature that lets you
    > identify *your* files?
    > I don't know anything about the details, but ELF has .note sections that
    > you might be able to use for your purpose. Then there is also the .comment
    > section that looks promising, too.
    >
    > Oh, and BTW the magic for ELF is four bytes: { 0x7f, 'E', 'L', 'F' }!
    >

    Where can I put meta-data for my own format? Would that come after the
    elf header?

    Bill



  9. Re: file signature

    Bill Cunningham wrote:
    > "Josef Moellers" wrote in message
    > news:gbi141$ble$1@nntp.fujitsu-siemens.com...
    >
    >> IIUC you want your file to have a specific signature that lets you
    >> identify *your* files?
    >> I don't know anything about the details, but ELF has .note sections that
    >> you might be able to use for your purpose. Then there is also the .comment
    >> section that looks promising, too.
    >>
    >> Oh, and BTW the magic for ELF is four bytes: { 0x7f, 'E', 'L', 'F' }!
    >>

    > Where can I put meta-data for my own format? Would that come after the
    > elf header?


    You need to consult the ELF spec. The ELF header contains file offsets
    to various tables (e.g. section header table):

    typedef struct {
    unsigned char e_ident[EI_NIDENT];
    uint16_t e_type;
    uint16_t e_machine;
    uint32_t e_version;
    ElfN_Addr e_entry;
    ElfN_Off e_phoff;
    ElfN_Off e_shoff; <<< section header offset
    uint32_t e_flags;
    uint16_t e_ehsize;
    uint16_t e_phentsize;
    uint16_t e_phnum;
    uint16_t e_shentsize;
    uint16_t e_shnum;
    uint16_t e_shstrndx;
    } ElfN_Ehdr;

    e_shoff This member holds the section header table’s file offset in
    bytes. If the file has no section header table this
    member
    holds zero.
    (from "man elf")

    You would need to read an ELF file without a .note section and write one
    with a .note section.

    There are at least two libraries that will assist you in doing this:
    libelf and libbfd.

    There are also two programs that help you understand the file format:
    readelf and objdump.

    Josef
    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html

  10. Re: file signature


    "Josef Moellers" wrote in message
    news:gbpvtp$253$1@nntp.fujitsu-siemens.com...
    > You need to consult the ELF spec. The ELF header contains file offsets to
    > various tables (e.g. section header table):
    >
    > typedef struct {
    > unsigned char e_ident[EI_NIDENT];
    > uint16_t e_type;
    > uint16_t e_machine;
    > uint32_t e_version;
    > ElfN_Addr e_entry;
    > ElfN_Off e_phoff;
    > ElfN_Off e_shoff; <<< section header offset
    > uint32_t e_flags;
    > uint16_t e_ehsize;
    > uint16_t e_phentsize;
    > uint16_t e_phnum;
    > uint16_t e_shentsize;
    > uint16_t e_shnum;
    > uint16_t e_shstrndx;
    > } ElfN_Ehdr;
    >
    > e_shoff This member holds the section header table’s file offset in
    > bytes. If the file has no section header table this
    > member
    > holds zero.
    > (from "man elf")
    >
    > You would need to read an ELF file without a .note section and write one
    > with a .note section.
    >
    > There are at least two libraries that will assist you in doing this:
    > libelf and libbfd.
    >
    > There are also two programs that help you understand the file format:
    > readelf and objdump.
    >
    > Josef


    Thanks much Josef.



+ Reply to Thread