makestub.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php'));
  3. $s .= "\nExtract_Phar::go();\n__HALT_COMPILER();";
  4. $news = '';
  5. foreach (token_get_all($s) as $token) {
  6. if (is_array($token)) {
  7. if ($token[0] == T_COMMENT) {
  8. $token[1] = '';
  9. }
  10. if ($token[0] == T_WHITESPACE) {
  11. $n = str_repeat("\n", substr_count($token[1], "\n"));
  12. $token[1] = strlen($n) ? $n : ' ';
  13. }
  14. $news .= $token[1];
  15. } else {
  16. $news .= $token;
  17. }
  18. }
  19. $s = $news . ' ?>';
  20. $slen = strlen($s) - strlen('index.php') - strlen("000");
  21. $s = str_replace('\\', '\\\\', $s);
  22. $s = str_replace('"', '\\"', $s);
  23. $s = str_replace("\n", '\n', $s);
  24. // now we need to find the location of web index file
  25. $webs = substr($s, 0, strpos($s, "000"));
  26. $s = substr($s, strlen($webs) + strlen("000"));
  27. $s1 = substr($s, 0, strpos($s, 'index.php'));
  28. $s2 = substr($s, strlen($s1) + strlen('index.php'));
  29. $s2 = substr($s2, 0, strpos($s2, 'XXXX'));
  30. $s3 = substr($s, strlen($s2) + 4 + strlen($s1) + strlen('index.php'));
  31. $stub = '/*
  32. +----------------------------------------------------------------------+
  33. | phar php single-file executable PHP extension generated stub |
  34. +----------------------------------------------------------------------+
  35. | Copyright (c) The PHP Group |
  36. +----------------------------------------------------------------------+
  37. | This source file is subject to version 3.01 of the PHP license, |
  38. | that is bundled with this package in the file LICENSE, and is |
  39. | available through the world-wide-web at the following url: |
  40. | https://www.php.net/license/3_01.txt |
  41. | If you did not receive a copy of the PHP license and are unable to |
  42. | obtain it through the world-wide-web, please send a note to |
  43. | license@php.net so we can mail you a copy immediately. |
  44. +----------------------------------------------------------------------+
  45. | Authors: Gregory Beaver <cellog@php.net> |
  46. +----------------------------------------------------------------------+
  47. */
  48. static inline void phar_get_stub(const char *index_php, const char *web, size_t *len, char **stub, const int name_len, const int web_len)
  49. {
  50. ';
  51. $s1split = str_split($s1, 2046);
  52. $s3split = str_split($s3, 2046);
  53. $took = false;
  54. foreach ($s1split as $i => $chunk) {
  55. if ($took) {
  56. $s1split[$i] = substr($chunk, 1);
  57. $took = false;
  58. }
  59. if ($chunk[strlen($chunk) - 1] == '\\') {
  60. $s1split[$i] .= $s1split[$i + 1][0];
  61. $took = true;
  62. }
  63. }
  64. foreach ($s3split as $i => $chunk) {
  65. if ($took) {
  66. $s3split[$i] = substr($chunk, 1);
  67. $took = false;
  68. }
  69. if ($chunk[strlen($chunk) - 1] == '\\') {
  70. $s3split[$i] .= $s3split[$i + 1][0];
  71. $took = true;
  72. }
  73. }
  74. $stub .= "\tstatic const char newstub0[] = \"" . $webs . '";
  75. ';
  76. foreach ($s1split as $i => $chunk) {
  77. $s1count = $i + 1;
  78. $stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
  79. ';
  80. }
  81. $stub .= "\tstatic const char newstub2[] = \"" . $s2 . "\";
  82. ";
  83. foreach ($s3split as $i => $chunk) {
  84. $s3count = $i + 1;
  85. $stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
  86. ';
  87. }
  88. $stub .= "\n\tstatic const int newstub_len = " . $slen . ";
  89. \t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d'
  90. . str_repeat('%s', $s3count) . '", newstub0, web';
  91. foreach ($s1split as $i => $unused) {
  92. $stub .= ', newstub1_' . $i;
  93. }
  94. $stub .= ', index_php, newstub2';
  95. $stub .= ", name_len + web_len + newstub_len";
  96. foreach ($s3split as $i => $unused) {
  97. $stub .= ', newstub3_' . $i;
  98. }
  99. $stub .= ");
  100. }";
  101. file_put_contents(dirname(__FILE__) . '/stub.h', $stub."\n");
  102. ?>