fishhook.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifdef __cplusplus
  28. extern "C" {
  29. #endif //__cplusplus
  30. /*
  31. * A structure representing a particular intended rebinding from a symbol
  32. * name to its replacement
  33. */
  34. struct rcd_rebinding {
  35. const char *name;
  36. void *replacement;
  37. void **replaced;
  38. };
  39. /*
  40. * For each rebinding in rebindings, rebinds references to external, indirect
  41. * symbols with the specified name to instead point at replacement for each
  42. * image in the calling process as well as for all future images that are loaded
  43. * by the process. If rebind_functions is called more than once, the symbols to
  44. * rebind are added to the existing list of rebindings, and if a given symbol
  45. * is rebound more than once, the later rebinding will take precedence.
  46. */
  47. int rcd_rebind_symbols(struct rcd_rebinding rebindings[], size_t rebindings_nel);
  48. /*
  49. * Rebinds as above, but only in the specified image. The header should point
  50. * to the mach-o header, the slide should be the slide offset. Others as above.
  51. */
  52. int rcd_rebind_symbols_image(void *header,
  53. intptr_t slide,
  54. struct rcd_rebinding rebindings[],
  55. size_t rebindings_nel);
  56. #ifdef __cplusplus
  57. }
  58. #endif //__cplusplus
  59. #endif //fishhook_h