flex_fishhook.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2013, Facebook, Inc.
  2. // All rights reserved.
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are met:
  5. // * Redistributions of source code must retain the above copyright notice,
  6. // this list of conditions and the following disclaimer.
  7. // * Redistributions in binary form must reproduce the above copyright notice,
  8. // this list of conditions and the following disclaimer in the documentation
  9. // and/or other materials provided with the distribution.
  10. // * Neither the name Facebook nor the names of its contributors may be used to
  11. // endorse or promote products derived from this software without specific
  12. // prior written permission.
  13. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  17. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  21. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. #ifndef fishhook_h
  24. #define fishhook_h
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #if !defined(FISHHOOK_EXPORT)
  28. #define FISHHOOK_VISIBILITY __attribute__((visibility("hidden")))
  29. #else
  30. #define FISHHOOK_VISIBILITY __attribute__((visibility("default")))
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif //__cplusplus
  35. /**
  36. * A structure representing a particular intended rebinding from a symbol
  37. * name to its replacement
  38. */
  39. struct rebinding {
  40. const char *name;
  41. void *replacement;
  42. void **replaced;
  43. };
  44. /**
  45. * For each rebinding in rebindings, rebinds references to external, indirect
  46. * symbols with the specified name to instead point at replacement for each
  47. * image in the calling process as well as for all future images that are loaded
  48. * by the process. If rebind_functions is called more than once, the symbols to
  49. * rebind are added to the existing list of rebindings, and if a given symbol
  50. * is rebound more than once, the later rebinding will take precedence.
  51. * @return 0 on success
  52. */
  53. FISHHOOK_VISIBILITY
  54. int flex_rebind_symbols(struct rebinding rebindings[], size_t rebindings_nel);
  55. /**
  56. * Rebinds as above, but only in the specified image. The header should point
  57. * to the mach-o header, the slide should be the slide offset. Others as above.
  58. * @return 0 on success
  59. */
  60. FISHHOOK_VISIBILITY
  61. int flex_rebind_symbols_image(void *header,
  62. intptr_t slide,
  63. struct rebinding rebindings[],
  64. size_t rebindings_nel);
  65. #ifdef __cplusplus
  66. }
  67. #endif //__cplusplus
  68. #endif //fishhook_h