1fd98b2af3773437487af0df22c428f3db630949awaylonis// Copyright (c) 2006, Google Inc. 2fd98b2af3773437487af0df22c428f3db630949awaylonis// All rights reserved. 3fd98b2af3773437487af0df22c428f3db630949awaylonis// 4fd98b2af3773437487af0df22c428f3db630949awaylonis// Redistribution and use in source and binary forms, with or without 5fd98b2af3773437487af0df22c428f3db630949awaylonis// modification, are permitted provided that the following conditions are 6fd98b2af3773437487af0df22c428f3db630949awaylonis// met: 7fd98b2af3773437487af0df22c428f3db630949awaylonis// 8fd98b2af3773437487af0df22c428f3db630949awaylonis// * Redistributions of source code must retain the above copyright 9fd98b2af3773437487af0df22c428f3db630949awaylonis// notice, this list of conditions and the following disclaimer. 10fd98b2af3773437487af0df22c428f3db630949awaylonis// * Redistributions in binary form must reproduce the above 11fd98b2af3773437487af0df22c428f3db630949awaylonis// copyright notice, this list of conditions and the following disclaimer 12fd98b2af3773437487af0df22c428f3db630949awaylonis// in the documentation and/or other materials provided with the 13fd98b2af3773437487af0df22c428f3db630949awaylonis// distribution. 14fd98b2af3773437487af0df22c428f3db630949awaylonis// * Neither the name of Google Inc. nor the names of its 15fd98b2af3773437487af0df22c428f3db630949awaylonis// contributors may be used to endorse or promote products derived from 16fd98b2af3773437487af0df22c428f3db630949awaylonis// this software without specific prior written permission. 17fd98b2af3773437487af0df22c428f3db630949awaylonis// 18fd98b2af3773437487af0df22c428f3db630949awaylonis// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19fd98b2af3773437487af0df22c428f3db630949awaylonis// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20fd98b2af3773437487af0df22c428f3db630949awaylonis// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21fd98b2af3773437487af0df22c428f3db630949awaylonis// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22fd98b2af3773437487af0df22c428f3db630949awaylonis// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23fd98b2af3773437487af0df22c428f3db630949awaylonis// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24fd98b2af3773437487af0df22c428f3db630949awaylonis// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25fd98b2af3773437487af0df22c428f3db630949awaylonis// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26fd98b2af3773437487af0df22c428f3db630949awaylonis// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27fd98b2af3773437487af0df22c428f3db630949awaylonis// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28fd98b2af3773437487af0df22c428f3db630949awaylonis// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29e5dc60822e5938fea2ae892ccddb906641ba174emmentovai 30fd98b2af3773437487af0df22c428f3db630949awaylonis// file_id.h: Return a unique identifier for a file 31fd98b2af3773437487af0df22c428f3db630949awaylonis// 32fd98b2af3773437487af0df22c428f3db630949awaylonis// Author: Dan Waylonis 33fd98b2af3773437487af0df22c428f3db630949awaylonis 34fd98b2af3773437487af0df22c428f3db630949awaylonis#ifndef COMMON_MAC_FILE_ID_H__ 35fd98b2af3773437487af0df22c428f3db630949awaylonis#define COMMON_MAC_FILE_ID_H__ 36fd98b2af3773437487af0df22c428f3db630949awaylonis 37fd98b2af3773437487af0df22c428f3db630949awaylonis#include <limits.h> 38b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org#include <mach/machine.h> 39fd98b2af3773437487af0df22c428f3db630949awaylonis 40e5dc60822e5938fea2ae892ccddb906641ba174emmentovainamespace google_breakpad { 41fd98b2af3773437487af0df22c428f3db630949awaylonis 42fd98b2af3773437487af0df22c428f3db630949awaylonisclass FileID { 43fd98b2af3773437487af0df22c428f3db630949awaylonis public: 44fd98b2af3773437487af0df22c428f3db630949awaylonis FileID(const char *path); 45fd98b2af3773437487af0df22c428f3db630949awaylonis ~FileID() {}; 46fd98b2af3773437487af0df22c428f3db630949awaylonis 47fd98b2af3773437487af0df22c428f3db630949awaylonis // Load the identifier for the file path specified in the constructor into 48fd98b2af3773437487af0df22c428f3db630949awaylonis // |identifier|. Return false if the identifier could not be created for the 49fd98b2af3773437487af0df22c428f3db630949awaylonis // file. 50fd98b2af3773437487af0df22c428f3db630949awaylonis // The current implementation will return the MD5 hash of the file's bytes. 51fd98b2af3773437487af0df22c428f3db630949awaylonis bool FileIdentifier(unsigned char identifier[16]); 52fd98b2af3773437487af0df22c428f3db630949awaylonis 53fd98b2af3773437487af0df22c428f3db630949awaylonis // Treat the file as a mach-o file that will contain one or more archicture. 54b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // Accepted values for |cpu_type| and |cpu_subtype| (e.g., CPU_TYPE_X86 or 55b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // CPU_TYPE_POWERPC) are listed in /usr/include/mach/machine.h. 56b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // If |cpu_type| is 0, then the native cpu type is used. If |cpu_subtype| is 57b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // CPU_SUBTYPE_MULTIPLE, the match is only done on |cpu_type|. 58b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // Returns false if opening the file failed or if the |cpu_type|/|cpu_subtype| 59b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org // is not present in the file. 60fd98b2af3773437487af0df22c428f3db630949awaylonis // Return the unique identifier in |identifier|. 61fd98b2af3773437487af0df22c428f3db630949awaylonis // The current implementation will look for the (in order of priority): 62fd98b2af3773437487af0df22c428f3db630949awaylonis // LC_UUID, LC_ID_DYLIB, or MD5 hash of the given |cpu_type|. 63b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org bool MachoIdentifier(cpu_type_t cpu_type, 64b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org cpu_subtype_t cpu_subtype, 65b2cb7ad7bc83205d23f77b660438bf8e8d16fcb5qsr@chromium.org unsigned char identifier[16]); 66fd98b2af3773437487af0df22c428f3db630949awaylonis 67fd98b2af3773437487af0df22c428f3db630949awaylonis // Convert the |identifier| data to a NULL terminated string. The string will 68fd98b2af3773437487af0df22c428f3db630949awaylonis // be formatted as a UUID (e.g., 22F065BB-FC9C-49F7-80FE-26A7CEBD7BCE). 69fd98b2af3773437487af0df22c428f3db630949awaylonis // The |buffer| should be at least 37 bytes long to receive all of the data 70fd98b2af3773437487af0df22c428f3db630949awaylonis // and termination. Shorter buffers will contain truncated data. 71fd98b2af3773437487af0df22c428f3db630949awaylonis static void ConvertIdentifierToString(const unsigned char identifier[16], 72fd98b2af3773437487af0df22c428f3db630949awaylonis char *buffer, int buffer_length); 73fd98b2af3773437487af0df22c428f3db630949awaylonis 74fd98b2af3773437487af0df22c428f3db630949awaylonis private: 75fd98b2af3773437487af0df22c428f3db630949awaylonis // Storage for the path specified 76fd98b2af3773437487af0df22c428f3db630949awaylonis char path_[PATH_MAX]; 77fd98b2af3773437487af0df22c428f3db630949awaylonis}; 78fd98b2af3773437487af0df22c428f3db630949awaylonis 79e5dc60822e5938fea2ae892ccddb906641ba174emmentovai} // namespace google_breakpad 80fd98b2af3773437487af0df22c428f3db630949awaylonis 81fd98b2af3773437487af0df22c428f3db630949awaylonis#endif // COMMON_MAC_FILE_ID_H__ 82