toolkit/crashreporter/google-breakpad/src/common/mac/macho_id.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/mac/macho_id.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +// Copyright (c) 2006, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// macho_id.h: Functions to gather identifying information from a macho file
    1.34 +//
    1.35 +// Author: Dan Waylonis
    1.36 +
    1.37 +#ifndef COMMON_MAC_MACHO_ID_H__
    1.38 +#define COMMON_MAC_MACHO_ID_H__
    1.39 +
    1.40 +#include <limits.h>
    1.41 +#include <mach/machine.h>
    1.42 +#include <mach-o/loader.h>
    1.43 +
    1.44 +#include "common/mac/macho_walker.h"
    1.45 +#include "common/md5.h"
    1.46 +
    1.47 +namespace MacFileUtilities {
    1.48 +
    1.49 +class MachoID {
    1.50 + public:
    1.51 +  MachoID(const char *path);
    1.52 +  MachoID(const char *path, void *memory, size_t size);
    1.53 +  ~MachoID();
    1.54 +
    1.55 +  // For the given |cpu_type| and |cpu_subtype|, return a UUID from the LC_UUID
    1.56 +  // command.
    1.57 +  // Return false if there isn't a LC_UUID command.
    1.58 +  bool UUIDCommand(cpu_type_t cpu_type,
    1.59 +                   cpu_subtype_t cpu_subtype,
    1.60 +                   unsigned char identifier[16]);
    1.61 +
    1.62 +  // For the given |cpu_type| and |cpu_subtype|, return a UUID from the
    1.63 +  // LC_ID_DYLIB command.
    1.64 +  // Return false if there isn't a LC_ID_DYLIB command.
    1.65 +  bool IDCommand(cpu_type_t cpu_type,
    1.66 +                 cpu_subtype_t cpu_subtype,
    1.67 +                 unsigned char identifier[16]);
    1.68 +
    1.69 +  // For the given |cpu_type| and |cpu_subtype|, return the Adler32 CRC for the
    1.70 +  // mach-o data segment(s).
    1.71 +  // Return 0 on error (e.g., if the file is not a mach-o file)
    1.72 +  uint32_t Adler32(cpu_type_t cpu_type,
    1.73 +                   cpu_subtype_t cpu_subtype);
    1.74 +
    1.75 +  // For the given |cpu_type|, and |cpu_subtype| return the MD5 for the mach-o
    1.76 +  // data segment(s).
    1.77 +  // Return true on success, false otherwise
    1.78 +  bool MD5(cpu_type_t cpu_type,
    1.79 +           cpu_subtype_t cpu_subtype,
    1.80 +           unsigned char identifier[16]);
    1.81 +
    1.82 + private:
    1.83 +  // Signature of class member function to be called with data read from file
    1.84 +  typedef void (MachoID::*UpdateFunction)(unsigned char *bytes, size_t size);
    1.85 +
    1.86 +  // Update the CRC value by examining |size| |bytes| and applying the algorithm
    1.87 +  // to each byte.
    1.88 +  void UpdateCRC(unsigned char *bytes, size_t size);
    1.89 +
    1.90 +  // Update the MD5 value by examining |size| |bytes| and applying the algorithm
    1.91 +  // to each byte.
    1.92 +  void UpdateMD5(unsigned char *bytes, size_t size);
    1.93 +
    1.94 +  // Bottleneck for update routines
    1.95 +  void Update(MachoWalker *walker, off_t offset, size_t size);
    1.96 +
    1.97 +  // Factory for the MachoWalker
    1.98 +  bool WalkHeader(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype,
    1.99 +                  MachoWalker::LoadCommandCallback callback, void *context);
   1.100 +
   1.101 +  // The callback from the MachoWalker for CRC and MD5
   1.102 +  static bool WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
   1.103 +                       bool swap, void *context);
   1.104 +
   1.105 +  // The callback from the MachoWalker for LC_UUID
   1.106 +  static bool UUIDWalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
   1.107 +                           bool swap, void *context);
   1.108 +
   1.109 +  // The callback from the MachoWalker for LC_ID_DYLIB
   1.110 +  static bool IDWalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
   1.111 +                         bool swap, void *context);
   1.112 +
   1.113 +  // File path
   1.114 +  char path_[PATH_MAX];
   1.115 +
   1.116 +  // Memory region to read from
   1.117 +  void *memory_;
   1.118 +
   1.119 +  // Size of the memory region
   1.120 +  size_t memory_size_;
   1.121 +
   1.122 +  // The current crc value
   1.123 +  uint32_t crc_;
   1.124 +
   1.125 +  // The MD5 context
   1.126 +  google_breakpad::MD5Context md5_context_;
   1.127 +
   1.128 +  // The current update to call from the Update callback
   1.129 +  UpdateFunction update_function_;
   1.130 +};
   1.131 +
   1.132 +}  // namespace MacFileUtilities
   1.133 +
   1.134 +#endif  // COMMON_MAC_MACHO_ID_H__

mercurial