/thirdparty/breakpad/common/mac/macho_utilities.cc

http://github.com/tomahawk-player/tomahawk · C++ · 90 lines · 50 code · 9 blank · 31 comment · 1 complexity · f66ad0e4db6f3c12584cf0d65c84cce3 MD5 · raw file

  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. // macho_utilties.cc: Utilities for dealing with mach-o files
  30. //
  31. // Author: Dave Camp
  32. #include "common/mac/byteswap.h"
  33. #include "common/mac/macho_utilities.h"
  34. void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc,
  35. enum NXByteOrder target_byte_order)
  36. {
  37. uc->cmd = ByteSwap(uc->cmd);
  38. uc->cmdsize = ByteSwap(uc->cmdsize);
  39. }
  40. void breakpad_swap_segment_command_64(struct segment_command_64 *sg,
  41. enum NXByteOrder target_byte_order)
  42. {
  43. sg->cmd = ByteSwap(sg->cmd);
  44. sg->cmdsize = ByteSwap(sg->cmdsize);
  45. sg->vmaddr = ByteSwap(sg->vmaddr);
  46. sg->vmsize = ByteSwap(sg->vmsize);
  47. sg->fileoff = ByteSwap(sg->fileoff);
  48. sg->filesize = ByteSwap(sg->filesize);
  49. sg->maxprot = ByteSwap(sg->maxprot);
  50. sg->initprot = ByteSwap(sg->initprot);
  51. sg->nsects = ByteSwap(sg->nsects);
  52. sg->flags = ByteSwap(sg->flags);
  53. }
  54. void breakpad_swap_mach_header_64(struct mach_header_64 *mh,
  55. enum NXByteOrder target_byte_order)
  56. {
  57. mh->magic = ByteSwap(mh->magic);
  58. mh->cputype = ByteSwap(mh->cputype);
  59. mh->cpusubtype = ByteSwap(mh->cpusubtype);
  60. mh->filetype = ByteSwap(mh->filetype);
  61. mh->ncmds = ByteSwap(mh->ncmds);
  62. mh->sizeofcmds = ByteSwap(mh->sizeofcmds);
  63. mh->flags = ByteSwap(mh->flags);
  64. mh->reserved = ByteSwap(mh->reserved);
  65. }
  66. void breakpad_swap_section_64(struct section_64 *s,
  67. uint32_t nsects,
  68. enum NXByteOrder target_byte_order)
  69. {
  70. for (uint32_t i = 0; i < nsects; i++) {
  71. s[i].addr = ByteSwap(s[i].addr);
  72. s[i].size = ByteSwap(s[i].size);
  73. s[i].offset = ByteSwap(s[i].offset);
  74. s[i].align = ByteSwap(s[i].align);
  75. s[i].reloff = ByteSwap(s[i].reloff);
  76. s[i].nreloc = ByteSwap(s[i].nreloc);
  77. s[i].flags = ByteSwap(s[i].flags);
  78. s[i].reserved1 = ByteSwap(s[i].reserved1);
  79. s[i].reserved2 = ByteSwap(s[i].reserved2);
  80. }
  81. }