• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: determining binary files from text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: determining binary files from text


  • Subject: Re: determining binary files from text
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 28 Feb 2002 15:36:01 -0800

On Thursday, February 28, 2002, at 12:12 PM, Ed Silva wrote:

Here's the problem that I ran into: I am working on a Cocoa application to manage the /Library/StartupItems folders; you can edit the scripts and plists and enable/disable items (changing the /etc/hostconfig entry to '-NO-' or '-YES-', if there is one), create new startup items, etc. It's pretty nifty, IMHO. :-) Unfortunately it is possible that someone could put binaries in a startup item folder, which causes my app to barf and die when it tires to parse it. So, how do I tell if a file is a binary or text?

Mach-o executables have as their first four bytes either MH_MAGIC, MH_CIGAM, FAT_MAGIC, or FAT_CIGAM, as defined in mach-o/loader.h and mach-o/fat.h. Executable shell scripts have #! for their first two bytes.

However, better for your app not to barf and die when it encounters something it can't parse. Someday somebody is going to put something in there that isn't either one...

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >determining binary files from text (From: Ed Silva <email@hidden>)

  • Prev by Date: Re: determining binary files from text
  • Next by Date: Re: timers and background memory management
  • Previous by thread: Re: determining binary files from text
  • Next by thread: Problems converting NSString path to FSSpec
  • Index(es):
    • Date
    • Thread