~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to thirdparty/breakpad/common/mac/macho_id.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2006, Google Inc.
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are
 
6
// met:
 
7
//
 
8
//     * Redistributions of source code must retain the above copyright
 
9
// notice, this list of conditions and the following disclaimer.
 
10
//     * Redistributions in binary form must reproduce the above
 
11
// copyright notice, this list of conditions and the following disclaimer
 
12
// in the documentation and/or other materials provided with the
 
13
// distribution.
 
14
//     * Neither the name of Google Inc. nor the names of its
 
15
// contributors may be used to endorse or promote products derived from
 
16
// this software without specific prior written permission.
 
17
//
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
 
 
30
// macho_id.h: Functions to gather identifying information from a macho file
 
31
//
 
32
// Author: Dan Waylonis
 
33
 
 
34
#ifndef COMMON_MAC_MACHO_ID_H__
 
35
#define COMMON_MAC_MACHO_ID_H__
 
36
 
 
37
#include <limits.h>
 
38
#include <mach-o/loader.h>
 
39
 
 
40
#include "common/mac/macho_walker.h"
 
41
#include "common/md5.h"
 
42
 
 
43
namespace MacFileUtilities {
 
44
 
 
45
class MachoID {
 
46
 public:
 
47
  MachoID(const char *path);
 
48
  MachoID(const char *path, void *memory, size_t size);
 
49
  ~MachoID();
 
50
 
 
51
  // For the given |cpu_type|, return a UUID from the LC_UUID command.
 
52
  // Return false if there isn't a LC_UUID command.
 
53
  bool UUIDCommand(int cpu_type, unsigned char identifier[16]);
 
54
 
 
55
  // For the given |cpu_type|, return a UUID from the LC_ID_DYLIB command.
 
56
  // Return false if there isn't a LC_ID_DYLIB command.
 
57
  bool IDCommand(int cpu_type, unsigned char identifier[16]);
 
58
 
 
59
  // For the given |cpu_type|, return the Adler32 CRC for the mach-o data
 
60
  // segment(s).
 
61
  // Return 0 on error (e.g., if the file is not a mach-o file)
 
62
  uint32_t Adler32(int cpu_type);
 
63
 
 
64
  // For the given |cpu_type|, return the MD5 for the mach-o data segment(s).
 
65
  // Return true on success, false otherwise
 
66
  bool MD5(int cpu_type, unsigned char identifier[16]);
 
67
 
 
68
 private:
 
69
  // Signature of class member function to be called with data read from file
 
70
  typedef void (MachoID::*UpdateFunction)(unsigned char *bytes, size_t size);
 
71
 
 
72
  // Update the CRC value by examining |size| |bytes| and applying the algorithm
 
73
  // to each byte.
 
74
  void UpdateCRC(unsigned char *bytes, size_t size);
 
75
 
 
76
  // Update the MD5 value by examining |size| |bytes| and applying the algorithm
 
77
  // to each byte.
 
78
  void UpdateMD5(unsigned char *bytes, size_t size);
 
79
 
 
80
  // Bottleneck for update routines
 
81
  void Update(MachoWalker *walker, off_t offset, size_t size);
 
82
 
 
83
  // Factory for the MachoWalker
 
84
  bool WalkHeader(int cpu_type, MachoWalker::LoadCommandCallback callback,
 
85
                  void *context);
 
86
 
 
87
  // The callback from the MachoWalker for CRC and MD5
 
88
  static bool WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
 
89
                       bool swap, void *context);
 
90
 
 
91
  // The callback from the MachoWalker for LC_UUID
 
92
  static bool UUIDWalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
 
93
                           bool swap, void *context);
 
94
 
 
95
  // The callback from the MachoWalker for LC_ID_DYLIB
 
96
  static bool IDWalkerCB(MachoWalker *walker, load_command *cmd, off_t offset,
 
97
                         bool swap, void *context);
 
98
 
 
99
  // File path
 
100
  char path_[PATH_MAX];
 
101
 
 
102
  // Memory region to read from
 
103
  void *memory_;
 
104
 
 
105
  // Size of the memory region
 
106
  size_t memory_size_;
 
107
 
 
108
  // The current crc value
 
109
  uint32_t crc_;
 
110
 
 
111
  // The MD5 context
 
112
  google_breakpad::MD5Context md5_context_;
 
113
 
 
114
  // The current update to call from the Update callback
 
115
  UpdateFunction update_function_;
 
116
};
 
117
 
 
118
}  // namespace MacFileUtilities
 
119
 
 
120
#endif  // COMMON_MAC_MACHO_ID_H__