systemMain.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <phpcpp.h>
  2. #include <string.h>
  3. #include <string>
  4. #include <unistd.h>
  5. #include <errno.h>
  6. #include<sys/time.h>
  7. #include <fcntl.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <stdio.h>
  11. #include "MainLogic.h"
  12. using namespace std;
  13. int __ImageBase=0;
  14. void sgx_foo(){};
  15. void sgx_bar(){};
  16. extern "C" const struct {
  17. size_t nr_ecall; // number of ECALLs
  18. struct {
  19. void *ecall_addr;
  20. uint8_t is_priv;
  21. } ecall_table [2];
  22. } g_ecall_table = {2, { { (void*)sgx_foo, 1}, { (void*)sgx_bar, 0} }};
  23. extern "C" const struct {
  24. // number of OCALLs (number of ECALLs can be found in ECALL table)
  25. size_t nr_ocall;
  26. // entry_table[m][n] = 1 iff. ECALL n is allowed in the OCALL m.
  27. uint8_t entry_table[3][2];
  28. } g_dyn_entry_table = {
  29. 3, {{0, 0}, {0, 1}, {1, 0}}
  30. };
  31. extern "C" uint32_t sgx_init_crypto_lib(uint64_t cpu_feature_indicator, uint32_t *cpuid_table)
  32. {
  33. return 0;
  34. }
  35. int sgx_is_within_enclave(const void *addr, size_t size)
  36. {
  37. return 1;
  38. }
  39. // Mitigator-Public-Key:
  40. MainLogic *mainLogic = NULL;
  41. Php::Value totally_normal_get_mitigator_header()
  42. {
  43. return mainLogic->get_mitigator_header();
  44. }
  45. void totally_normal_deployment_stage()
  46. { mainLogic = new MainLogic;
  47. return mainLogic->deployment_stage();
  48. }
  49. Php::Value totally_normal_php_decrypt_wrapper(Php::Parameters & params)
  50. {
  51. return mainLogic->php_decrypt_wrapper(params);
  52. }
  53. extern "C" {
  54. // export the "get_module" function that will be called by the Zend engine
  55. PHPCPP_EXPORT void *get_module()
  56. {
  57. // create extension
  58. static Php::Extension extension("decryptor_la_setup_and_decryption","1.0");
  59. extension.onStartup(totally_normal_deployment_stage);
  60. extension.add<totally_normal_get_mitigator_header>("get_mitigator_header");
  61. extension.add<totally_normal_php_decrypt_wrapper>("php_decrypt_wrapper",
  62. {Php::ByVal("array", Php::Type::Array)}
  63. );
  64. return extension.module();
  65. }
  66. }