├── LICENSE ├── README.md ├── README_CN.md ├── fricc2 ├── Makefile └── fricc2.c └── fricc2load ├── .gitignore ├── CREDITS ├── config.m4 ├── fricc2_lib.c ├── fricc2_lib.h ├── fricc2load.c ├── init_key └── php_fricc2load.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What's FRICC2? 2 | 3 | FRICC2 is a PHP Script encryption tool. When you are developing a commercial software using PHP, the script can be distributed as encrypted up until just before execution. Thanks for PHP-Screw. 4 | 5 | [**中文版说明**](./README_CN.md) 6 | 7 | 8 | 9 | ## Features 10 | 11 | 1. Less file handle open or read. 12 | 2. Compress supported, small size of target files. 13 | 3. Fix serval memory Leak. 14 | 4. More performance when php open files. 15 | 5. Supported Bundle in PHP with static. 16 | 6. Tested on Ubuntu / CentOS / Openwrt. 17 | 7. Tested in x86_64 / MIPS / ARM Processors. 18 | 8. Supported PHP 8(include JIT), Tested Memory Leak. 19 | 9. Supported Sandbox Mode(uncomment in fricc2_lib.h to enable it), only encrypted source can be run. 20 | 21 | 22 | 23 | 24 | 25 | ## Requirement 26 | 27 | ### PHP Version 28 | 29 | | PHP Version | Status | Notice | 30 | | ----------------- | --------------- | ---------------------------------------------------- | 31 | | PHP 8.1.X | Static / Shared | Recommend, Tested on 8.1.10, FRICC2 2.0.1 | 32 | | PHP 8.0.X | Static / Shared | Recommend, Tested on 8.0.23, FRICC2 2.0.1 | 33 | | PHP 7.4.X | Static / Shared | Recommend | 34 | | PHP 7.0.X / 7.3.X | Static / Shared | Runtime Little Memory Leak (auto free when php exit) | 35 | | Other Version | NO TEST | NO TEST | 36 | 37 | ### ZLIB Support in PHP 38 | 39 | PHP must be compiled with the "--with-zlib" option. 40 | 41 | 42 | 43 | 44 | 45 | ## Installation 46 | 47 | ### Get Source 48 | 49 | ```bash 50 | # git clone source 51 | cd ~/ 52 | git clone https://github.com/hoowa/FRICC2.git 53 | 54 | # optional init key (Set Better Secure different) 55 | chmod +x ~/FRICC2/fricc2load/init_key 56 | ~/FRICC2/fricc2load/init_key 57 | 58 | # optional enable sandbox mode to edit fricc2_lib.h 59 | # uncomment FRICCSANDBOX_ENABLE 60 | 61 | # Requirement Example CentOS 7.9 62 | yum groupinstall "Development Tools" 63 | yum install zlib-static zlib-devel 64 | 65 | # Requirement Example Ubuntu 20.04 66 | sudo apt install build-essential pkg-config autoconf zlib1g-dev 67 | ``` 68 | 69 | ### Build PHP Extension (Shared) 70 | 71 | ```bash 72 | # Compile fricc2load 73 | cd ~/FRICC2/fricc2load/ 74 | phpize 75 | ./configure 76 | make 77 | make install 78 | 79 | # Append this line to php.ini 80 | extension=fricc2load.so 81 | 82 | # Test in CLI 83 | php -m|grep fricc2load 84 | 85 | # Restart the web server / your php daemon as you need 86 | ``` 87 | 88 | ### Build Encode Program 89 | 90 | ```bash 91 | # Compile Encode Program 92 | cd ~/FRICC2/fricc2/ 93 | make 94 | cp fricc2 /usr/bin/ 95 | 96 | # Test Create test.php 97 | 100 | fricc2 -o test_new.php test.php 101 | php ./test_new.php 102 | # Screen output: 103 | hello fricc2 104 | ``` 105 | 106 | 107 | 108 | ## Others 109 | 110 | ### Optional Build PHP Extension (Static) 111 | 112 | ```bash 113 | # example of your php source in ~/php-7.4.22/ 114 | cd ~/php-7.4.22 115 | cp -avf ~/FRICC2/fricc2load/ ./ext/ 116 | ./buildconf --force 117 | 118 | # append --enable-fricc2load=static --with-zlib to configure (example): 119 | ./configure --enable-fricc2load=static --with-zlib 120 | make 121 | make install 122 | 123 | # check modules 124 | php -m|grep fricc2load 125 | ``` 126 | 127 | ### Author 128 | 129 | Sun Bing 130 | 131 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # FRICC2介绍 2 | 3 | FRICC2是PHP源码加密工具。当你使用PHP开发商业软件时可以使用FRICC2对发布的代码进行加密,加密后只有具备解密权限的PHP解析器才能执行程序。感谢PHP-Screw项目的贡献。 4 | 5 | 6 | 7 | 8 | 9 | ## 功能 10 | 11 | 1. 更少的文件句柄打开或读取(相比其他项目)。 12 | 2. 压缩支持,加密后文件更小(ZLIB低CPU占用率压缩,对嵌入式环境磁盘占用率更小)。 13 | 3. 解决数个内存泄漏问题(相比其他项目)。 14 | 4. 打开文件速度更快。 15 | 5. 支持以静态绑定方式编译到PHP解析器中(增加跟踪破解难度)。 16 | 6. 在Ubuntu / CentOS / OpenWRT等数个操作系统下测试完毕。 17 | 7. 在x86_64 / MIPS / ARM等数个不同架构CPU测试完毕。 18 | 8. 首个支持PHP 8(及JIT模式),并经过内存泄漏检测的开源加密算法。 19 | 9. 支持沙箱模式(修改fricc2_lib.h头文件开启),只支持加密后的.php文件。 20 | 21 | 22 | 23 | 24 | 25 | ## 基本需求 26 | 27 | ### PHP版本 28 | 29 | | PHP 版本 | 状态 | 备注 | 30 | | ----------------- | ------------------- | --------------------------------------------- | 31 | | PHP 8.1.X | 静态扩展 / 动态扩展 | 推荐, 测试在8.1.10版, 使用FRICC2 2.0.1 | 32 | | PHP 8.0.X | 静态扩展 / 动态扩展 | 推荐, 测试在8.0.23版, 使用FRICC2 2.0.1 | 33 | | PHP 7.4.X | 静态扩展 / 动态扩展 | 推荐 | 34 | | PHP 7.0.X / 7.3.X | 静态扩展 / 动态扩展 | 运行时存在少量固定内存泄漏(PHP退出后自动清理) | 35 | | 其他版本 | 未测试 | 未测试 | 36 | 37 | ### PHP的ZLIB支持 38 | 39 | PHP需要编译时支持"--with-zlib"选项。 40 | 41 | 42 | 43 | 44 | 45 | ## 安装 46 | 47 | ### 获得源代码 48 | 49 | ```bash 50 | # 从GIT获得源代码 51 | cd ~/ 52 | git clone https://github.com/hoowa/FRICC2.git 53 | 54 | # 可选的初始化KEY (使用不同的KEY更难破解) 55 | chmod +x ~/FRICC2/fricc2load/init_key 56 | ~/FRICC2/fricc2load/init_key 57 | 58 | # 可选修改fricc2_lib.h取消FRICCSANDBOX_ENABLE的注释 59 | # 开启沙箱模式,支持加密后的PHP文件不再支持加密前PHP文件 60 | 61 | # 基本依赖安装示例 CentOS 7.9 62 | yum groupinstall "Development Tools" 63 | yum install zlib-static zlib-devel 64 | 65 | # 基本依赖安装示例 20.04 66 | sudo apt install build-essential pkg-config autoconf zlib1g-dev 67 | ``` 68 | 69 | ### 编译PHP扩展支持 (动态扩展) 70 | 71 | ```bash 72 | # 编译 fricc2load 73 | cd ~/FRICC2/fricc2load/ 74 | phpize 75 | ./configure 76 | make 77 | make install 78 | 79 | # 在php.ini中增加如下 80 | extension=fricc2load.so 81 | 82 | # CLI命令下测试 83 | php -m|grep fricc2load 84 | 85 | # 重启web服务器或php服务即可生效 86 | ``` 87 | 88 | ### 编译生成加密工具 89 | 90 | ```bash 91 | # 编译生成加密工具 92 | cd ~/FRICC2/fricc2/ 93 | make 94 | cp fricc2 /usr/bin/ 95 | 96 | # 进行测试test.php 97 | 100 | fricc2 -o test_new.php test.php 101 | php ./test_new.php 102 | # Screen output: 103 | hello fricc2 104 | ``` 105 | 106 | 107 | 108 | ## 其他 109 | 110 | ### 可选编译PHP扩展支持 (静态扩展) 111 | 112 | ```bash 113 | # 假如你的PHP在如下地址 ~/php-7.4.22/ 114 | cd ~/php-7.4.22 115 | cp -avf ~/FRICC2/fricc2load/ ./ext/ 116 | ./buildconf --force 117 | 118 | # 在configure的时候增加此选项 --enable-fricc2load=static --with-zlib 119 | ./configure --enable-fricc2load=static --with-zlib 120 | make 121 | make install 122 | 123 | # 检测扩展 124 | php -m|grep fricc2load 125 | ``` 126 | 127 | ### 作者 128 | 129 | Sun Bing 130 | 131 | -------------------------------------------------------------------------------- /fricc2/Makefile: -------------------------------------------------------------------------------- 1 | all: fricc2 2 | 3 | fricc2: fricc2.c 4 | gcc -Wall -O2 -o fricc2 fricc2.c ../fricc2load/fricc2_lib.c -I../fricc2load/ -lz 5 | 6 | static: 7 | gcc -Wall -O2 -o fricc2 fricc2.c ../fricc2load/fricc2_lib.c -I../fricc2load/ -lz -static 8 | 9 | debug: 10 | gcc -Wall -g -O0 -o fricc2 fricc2.c ../fricc2load/fricc2_lib.c -I../fricc2load/ -lz 11 | 12 | clean: 13 | /bin/rm -vf *.o *.so fricc2 test.t 14 | 15 | #valgrind --tool=memcheck --leak-check=full --track-origins=yes ./fricc2 -o t /usr/bin/xz 16 | -------------------------------------------------------------------------------- /fricc2/fricc2.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | FRICC2 | 4 | +----------------------------------------------------------------------+ 5 | | Author: sun bing | 6 | +----------------------------------------------------------------------+ 7 | */ 8 | #include 9 | #include 10 | #include 11 | // #include 12 | #include 13 | #include 14 | // #include 15 | #include "fricc2_lib.h" 16 | 17 | int main(int argc, char**argv) 18 | { 19 | int option = -1; 20 | FILE *fp = NULL; 21 | struct stat fp_stat; 22 | size_t src_data_len = 0, dst_data_len = 0; 23 | char *src_data_buf = NULL, *dst_data_buf = NULL; 24 | 25 | // checking args input 26 | if (argc != 4) { 27 | fprintf(stderr, "Usage: %s -o [target] [source]\n",argv[0]); 28 | goto CLEAN_DONE; 29 | } 30 | option = strcmp(argv[1],"-o"); 31 | if (option != 0) { 32 | fprintf(stderr, "Usage: %s -o [target] [source]\n",argv[0]); 33 | goto CLEAN_DONE; 34 | } 35 | 36 | // load source 37 | fp = fopen(argv[3], "r"); 38 | if (fp == NULL) { 39 | fprintf(stderr, "File not found: %s\n", argv[3]); 40 | goto CLEAN_DONE; 41 | } 42 | fstat(fileno(fp), &fp_stat); 43 | src_data_len = fp_stat.st_size; 44 | src_data_buf = (char*)malloc(src_data_len + FRICCTAG_LEN); 45 | if (fread(src_data_buf, src_data_len, 1, fp)) { 46 | fclose(fp); 47 | } 48 | fp = NULL; 49 | 50 | //check source file 51 | if (memcmp(src_data_buf, FRICCTAG_STR, FRICCTAG_LEN) == 0) { 52 | fprintf(stderr, "Error Source was Encrypted: %s\n", argv[3]); 53 | goto CLEAN_DONE; 54 | } 55 | 56 | // target compress and encode 57 | dst_data_buf = fricc2_lib_zcodecom(ZENCOMPRESS, src_data_buf, src_data_len, &dst_data_len); 58 | fricc2_lib_decrypt(dst_data_buf,&dst_data_len); 59 | 60 | // save target 61 | fp = fopen(argv[2], "w"); 62 | if (fp == NULL) { 63 | fprintf(stderr, "Error Target File Create: %s\n", argv[2]); 64 | goto CLEAN_DONE; 65 | } 66 | fwrite(FRICCTAG_STR, FRICCTAG_LEN, 1, fp); 67 | fwrite(dst_data_buf, dst_data_len, 1, fp); 68 | fclose(fp); 69 | fp = NULL; 70 | fprintf(stderr, "Encrypted: %s\n", argv[2]); 71 | goto CLEAN_DONE; 72 | 73 | CLEAN_DONE: 74 | if (fp != NULL) { 75 | //printf("fclose fp\n"); 76 | fclose(fp); 77 | } 78 | if (src_data_buf != NULL) { 79 | //printf("free src_data_p\n"); 80 | free(src_data_buf); 81 | } 82 | if (dst_data_buf != NULL) { 83 | //printf("free dst_data_p\n"); 84 | free(dst_data_buf); 85 | } 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /fricc2load/.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.la 3 | .libs 4 | acinclude.m4 5 | aclocal.m4 6 | autom4te.cache 7 | build 8 | config.guess 9 | config.h 10 | config.h.in 11 | config.log 12 | config.nice 13 | config.status 14 | config.sub 15 | configure 16 | configure.ac 17 | configure.in 18 | include 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | Makefile 23 | Makefile.fragments 24 | Makefile.global 25 | Makefile.objects 26 | missing 27 | mkinstalldirs 28 | modules 29 | run-tests.php 30 | tests/*/*.diff 31 | tests/*/*.out 32 | tests/*/*.php 33 | tests/*/*.exp 34 | tests/*/*.log 35 | tests/*/*.sh 36 | -------------------------------------------------------------------------------- /fricc2load/CREDITS: -------------------------------------------------------------------------------- 1 | fricc2load 2 | hoowa.sun -------------------------------------------------------------------------------- /fricc2load/config.m4: -------------------------------------------------------------------------------- 1 | PHP_ARG_ENABLE([fricc2load], 2 | [whether to enable fricc2load support], 3 | [AS_HELP_STRING([--enable-fricc2load], 4 | [Enable fricc2load support])], 5 | [no]) 6 | 7 | if test -z "$PHP_ZLIB_DIR"; then 8 | PHP_ARG_WITH([zlib-dir], 9 | [for the location of libz], 10 | [AS_HELP_STRING([[--with-zlib-dir[=DIR]]], 11 | [fricc2load: Set the path to libz install prefix])], 12 | [no], 13 | [no]) 14 | fi 15 | 16 | if test "$PHP_FRICC2LOAD" != "no"; then 17 | 18 | dnl PKG_CHECK_MODULES([ZLIB], [zlib >= 1.0.0.0]) 19 | dnl AC_DEFINE(HAVE_FRICC2LOAD, 1, [ Have fricc2load support ]) 20 | 21 | PHP_CHECK_LIBRARY(z, gzgets, [ 22 | AC_DEFINE(HAVE_FRICC2LOAD,1,[ Have fricc2load support ]) 23 | ],[ 24 | AC_MSG_ERROR(HAVE_FRICC2LOAD extension requires gzgets in zlib) 25 | ]) 26 | 27 | PHP_EVAL_INCLINE($ZLIB_CFLAGS) 28 | PHP_EVAL_LIBLINE($ZLIB_LIBS, FRICC2LOAD_SHARED_LIBADD) 29 | 30 | PHP_NEW_EXTENSION(fricc2load, fricc2load.c fricc2_lib.c, $ext_shared,, -DFRICC2_INPHP_COMPILE=1) 31 | fi 32 | -------------------------------------------------------------------------------- /fricc2load/fricc2_lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | FRICC2 | 4 | +----------------------------------------------------------------------+ 5 | | Author: sun bing | 6 | +----------------------------------------------------------------------+ 7 | */ 8 | #ifdef FRICC2_INPHP_COMPILE 9 | #include "php.h" 10 | #else 11 | #include 12 | #include 13 | #include 14 | #endif 15 | #include 16 | #include "fricc2_lib.h" 17 | 18 | void fricc2_lib_decrypt(char *file_buf, size_t *file_buf_len) 19 | { 20 | int i; 21 | short friccload_key[] = { 22 | FRICCKEY 23 | }; 24 | int cryptokey_len = sizeof friccload_key / 2; 25 | 26 | // start_rre 27 | i = friccload_key[13]; 28 | friccload_key[13] = friccload_key[12]; 29 | friccload_key[12] = i; 30 | i = friccload_key[9]; 31 | friccload_key[9] = friccload_key[6]; 32 | friccload_key[6] = i; 33 | i = friccload_key[7]; 34 | friccload_key[7] = friccload_key[8]; 35 | friccload_key[8] = i; 36 | i = friccload_key[1]; 37 | friccload_key[1] = friccload_key[11]; 38 | friccload_key[11] = i; 39 | // end_rre 40 | 41 | for (i=0; i<*file_buf_len; i++) 42 | file_buf[i] = (char)friccload_key[(*file_buf_len - i) % cryptokey_len] ^ (~(file_buf[i])); 43 | 44 | return; 45 | } 46 | 47 | char *fricc2_lib_zcodecom(int mode, char *inbuf, size_t inbuf_len, size_t *resultbuf_len) 48 | { 49 | z_stream z; 50 | 51 | // 每次压缩/解压缩的缓冲 52 | char outbuf[OUTBUFSIZ]; // 数据缓冲 53 | int count, status; // 数据缓冲量, 缓冲器状态 54 | 55 | // 总数据 56 | char *resultbuf = NULL, *resultbuf2 = NULL; // 已读取数据指针, 临时已读取数据指针 57 | size_t total_count = 0; // 已读取数据总量 58 | 59 | // 初始化zlib 60 | z.zalloc = Z_NULL; 61 | z.zfree = Z_NULL; 62 | z.opaque = Z_NULL; 63 | z.next_in = Z_NULL; 64 | z.avail_in = 0; 65 | if (mode == 0) { 66 | deflateInit(&z, 1); 67 | } else { 68 | inflateInit(&z); 69 | } 70 | 71 | // 首次读取初始化 72 | z.next_out = (Bytef *)outbuf; // 目标缓冲器 73 | z.avail_out = OUTBUFSIZ; // 目标缓冲器大小 74 | z.next_in = (Bytef *)inbuf; // 原始数据 75 | z.avail_in = inbuf_len; // 原始数据总长度 76 | 77 | #ifdef FRICC2_INPHP_COMPILE 78 | resultbuf = safe_emalloc(OUTBUFSIZ+1, sizeof(char), 0); 79 | #else 80 | resultbuf = malloc(OUTBUFSIZ+1); 81 | #endif 82 | if (resultbuf == NULL) { // 内存申请失败 83 | *resultbuf_len = 0; 84 | return(NULL); 85 | } 86 | 87 | // 每次读取 88 | while (1) { 89 | // 数据缓冲读取 90 | if (mode == 0) { 91 | status = deflate(&z, Z_FINISH); 92 | } else { 93 | status = inflate(&z, Z_NO_FLUSH); 94 | } 95 | // 如果读取完成, 则结束循环进入后半段处理 96 | if (status == Z_STREAM_END) break; 97 | // 如果读取出错, 直接结束程序 98 | if (status != Z_OK) { 99 | if (mode == 0) { 100 | deflateEnd(&z); 101 | } else { 102 | inflateEnd(&z); 103 | } 104 | #ifdef FRICC2_INPHP_COMPILE 105 | efree(resultbuf); 106 | #else 107 | free(resultbuf); 108 | #endif 109 | *resultbuf_len = 0; 110 | return(NULL); 111 | } 112 | // 如果Z_OK并且目标缓冲器读满了,则保存一次 113 | // 备注:如果目标缓冲器没满很有可能会进入Z_STREAM_END 114 | if (z.avail_out == 0) { 115 | #ifdef FRICC2_INPHP_COMPILE 116 | resultbuf2 = safe_erealloc(resultbuf, total_count+OUTBUFSIZ+1, sizeof(char), 0); 117 | #else 118 | resultbuf2 = realloc(resultbuf, total_count+OUTBUFSIZ+1); 119 | #endif 120 | if (resultbuf2 == NULL) { // 内存申请失败 121 | if (mode == 0) { 122 | deflateEnd(&z); 123 | } else { 124 | inflateEnd(&z); 125 | } 126 | #ifdef FRICC2_INPHP_COMPILE 127 | efree(resultbuf); 128 | #else 129 | free(resultbuf); 130 | #endif 131 | *resultbuf_len = 0; 132 | return(NULL); 133 | } 134 | resultbuf = resultbuf2; // 内存申请成功 135 | 136 | // 保存 137 | memcpy(resultbuf+total_count, outbuf, OUTBUFSIZ); 138 | total_count += OUTBUFSIZ; 139 | z.next_out = (Bytef *)outbuf; 140 | z.avail_out = OUTBUFSIZ; 141 | } 142 | } 143 | 144 | // 后半段处理 145 | // 如果最后一次还有数据要读, 比如Z_STREAM_END过来就还有一些数据 146 | if ((count = OUTBUFSIZ - z.avail_out) != 0) { 147 | #ifdef FRICC2_INPHP_COMPILE 148 | resultbuf2 = safe_erealloc(resultbuf, total_count+OUTBUFSIZ+1, sizeof(char), 0); 149 | #else 150 | resultbuf2 = realloc(resultbuf, total_count+OUTBUFSIZ+1); 151 | #endif 152 | if (resultbuf2 == NULL) { // 内存申请失败 153 | if (mode == 0) { 154 | deflateEnd(&z); 155 | } else { 156 | inflateEnd(&z); 157 | } 158 | #ifdef FRICC2_INPHP_COMPILE 159 | efree(resultbuf); 160 | #else 161 | free(resultbuf); 162 | #endif 163 | *resultbuf_len = 0; 164 | return(NULL); 165 | } 166 | resultbuf = resultbuf2; // 内存申请成功 167 | 168 | // 保存 169 | memcpy(resultbuf+total_count, outbuf, count); 170 | total_count += count; 171 | } 172 | 173 | // 正常结束 174 | if (mode == 0) { 175 | deflateEnd(&z); 176 | } else { 177 | inflateEnd(&z); 178 | } 179 | 180 | *resultbuf_len = total_count; 181 | resultbuf[total_count] = '\0'; 182 | return(resultbuf); 183 | } 184 | -------------------------------------------------------------------------------- /fricc2load/fricc2_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | FRICC2 | 4 | +----------------------------------------------------------------------+ 5 | | Author: sun bing | 6 | +----------------------------------------------------------------------+ 7 | */ 8 | #ifndef FRICC2_LIB_H 9 | #define FRICC2_LIB_H 10 | 11 | #define FRICCTAG_STR "hellokitty" 12 | #define FRICCTAG_LEN 10 13 | // uncomment to enable sanbox mode 14 | // #define FRICCSANDBOX_ENABLE 15 | 16 | // Notice FRICCKEY must more than 16 numbers 17 | #define FRICCKEY 18447,763,892,7347,26797,24482,978,62,464,18,600,061,138,1321,1,1342 18 | 19 | #define ZENCOMPRESS 0 20 | #define ZDECOMPRESS 1 21 | #define OUTBUFSIZ 100000 22 | 23 | void fricc2_lib_decrypt(char *file_buf, size_t *file_buf_len); 24 | char *fricc2_lib_zcodecom(int mode, char *inbuf, size_t inbuf_len, size_t *resultbuf_len); 25 | 26 | #endif -------------------------------------------------------------------------------- /fricc2load/fricc2load.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | FRICC2 | 4 | +----------------------------------------------------------------------+ 5 | | Author: sun bing | 6 | +----------------------------------------------------------------------+ 7 | */ 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include "config.h" 11 | #endif 12 | 13 | #include "php.h" 14 | #include "ext/standard/info.h" 15 | #include "php_fricc2load.h" 16 | #include "fricc2_lib.h" 17 | 18 | /* For compatibility with older PHP versions */ 19 | #ifndef ZEND_PARSE_PARAMETERS_NONE 20 | #define ZEND_PARSE_PARAMETERS_NONE() \ 21 | ZEND_PARSE_PARAMETERS_START(0, 0) \ 22 | ZEND_PARSE_PARAMETERS_END() 23 | #endif 24 | 25 | /* For compatibility with PHP 8.X versions */ 26 | #ifndef TSRMLS_D 27 | #define TSRMLS_D void 28 | #define TSRMLS_DC 29 | #define TSRMLS_C 30 | #define TSRMLS_CC 31 | #define TSRMLS_FETCH() 32 | #endif 33 | 34 | /* 35 | ======================================================================= 36 | FRICC2LOAD Functions 37 | ======================================================================= 38 | */ 39 | int fricc2load_fd_checkheader(FILE *fp) 40 | { 41 | char ftag[FRICCTAG_LEN + 1]; 42 | 43 | memset(ftag, 0, sizeof(ftag)); 44 | if (fread(ftag, sizeof(char), FRICCTAG_LEN, fp)) { 45 | return memcmp(ftag, FRICCTAG_STR, FRICCTAG_LEN); 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | char *fricc2load_fd_decrypt(FILE *fp, size_t *real_data_len) 52 | { 53 | // file data 54 | struct stat fp_stat; 55 | size_t file_buf_len = 0; 56 | char *file_buf = NULL; 57 | // real 58 | char *real_data_buf = NULL; 59 | 60 | // from handle to file_data 61 | fstat(fileno(fp), &fp_stat); 62 | file_buf_len = fp_stat.st_size - FRICCTAG_LEN; 63 | file_buf = safe_emalloc(file_buf_len, sizeof(char), 0); 64 | if (fread(file_buf, sizeof(char), file_buf_len, fp)) { 65 | // decrypt and uncompress 66 | fricc2_lib_decrypt(file_buf,&file_buf_len); 67 | real_data_buf = fricc2_lib_zcodecom(ZDECOMPRESS, file_buf, file_buf_len, real_data_len); 68 | } 69 | // clean done 70 | efree(file_buf); 71 | 72 | return(real_data_buf); 73 | } 74 | 75 | ZEND_API zend_op_array *(*org_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC); 76 | ZEND_API zend_op_array *fricc2load_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) 77 | { 78 | // file handle 79 | FILE *fp; 80 | char fname[32]; 81 | // real data 82 | char *real_data_buf = NULL; 83 | size_t real_data_len = 0; 84 | // stream fixup used 85 | char *tmp_buf = NULL; 86 | size_t tmp_size = 0; 87 | 88 | #if PHP_VERSION_ID >= 80100 89 | if (!file_handle || !file_handle->filename || strstr(ZSTR_VAL(file_handle->filename), ".phar") || strstr(ZSTR_VAL(file_handle->filename), "phar://")) { 90 | return org_compile_file(file_handle, type TSRMLS_CC); 91 | } 92 | #else 93 | if (!file_handle || !file_handle->filename || strstr(file_handle->filename, ".phar") || strstr(file_handle->filename, "phar://")) { 94 | return org_compile_file(file_handle, type TSRMLS_CC); 95 | } 96 | #endif 97 | 98 | // checking file name 99 | memset(fname, 0, sizeof fname); 100 | if (zend_is_executing(TSRMLS_C) && get_active_function_name(TSRMLS_C)) { 101 | strncpy(fname, get_active_function_name(TSRMLS_C), sizeof fname - 2); 102 | } 103 | if (fname[0]) { 104 | if (strcasecmp(fname, "show_source") == 0 105 | || strcasecmp(fname, "highlight_file") == 0) { 106 | return NULL; 107 | } 108 | } 109 | 110 | // open file and decrypt and uncompress 111 | // when file is opened directly (type is ZEND_HANDLE_FP), check here. 112 | #if PHP_VERSION_ID >= 80100 113 | fp = fopen(ZSTR_VAL(file_handle->filename), "rb"); 114 | #else 115 | fp = fopen(file_handle->filename, "rb"); 116 | #endif 117 | if (!fp) { 118 | return org_compile_file(file_handle, type TSRMLS_CC); 119 | } 120 | 121 | // check header tag to ignore decrypt and uncompress 122 | if (fricc2load_fd_checkheader(fp) != 0) { 123 | fclose(fp); 124 | #ifdef FRICCSANDBOX_ENABLE 125 | goto DONEWORK; 126 | #else 127 | return org_compile_file(file_handle, type TSRMLS_CC); 128 | #endif 129 | } 130 | 131 | // decode real data 132 | real_data_buf = fricc2load_fd_decrypt(fp, &real_data_len); 133 | fclose(fp); 134 | // if buf = null or len = 0 means failed 135 | if (real_data_buf == NULL || real_data_len == 0) { 136 | if (real_data_buf != NULL) { 137 | efree(real_data_buf); 138 | } 139 | real_data_len = 0; 140 | real_data_buf = NULL; 141 | #ifdef FRICCSANDBOX_ENABLE 142 | goto DONEWORK; 143 | #else 144 | return org_compile_file(file_handle, type TSRMLS_CC); 145 | #endif 146 | } 147 | 148 | // replace with new buf 149 | DONEWORK: 150 | if (zend_stream_fixup(file_handle, (char **) &tmp_buf, &tmp_size TSRMLS_CC) == FAILURE) { 151 | return NULL; 152 | } 153 | #if PHP_VERSION_ID < 70400 154 | // version < 7.4.0 can not use efree, but its come to memory leak. 155 | // if (file_handle->handle.stream.mmap.buf != NULL) 156 | // efree(file_handle->handle.stream.mmap.buf); 157 | file_handle->handle.stream.mmap.buf = real_data_buf; 158 | file_handle->handle.stream.mmap.len = real_data_len; 159 | #else 160 | if (file_handle->buf != NULL) { 161 | efree(file_handle->buf); 162 | } 163 | file_handle->buf = real_data_buf; 164 | file_handle->len = real_data_len; 165 | #endif 166 | file_handle->handle.stream.closer = NULL; 167 | 168 | return org_compile_file(file_handle, type TSRMLS_CC); 169 | } 170 | 171 | /* 172 | ======================================================================= 173 | PHP Extension API Define 174 | ======================================================================= 175 | */ 176 | PHP_MINIT_FUNCTION(fricc2load) 177 | { 178 | // CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; 179 | org_compile_file = zend_compile_file; 180 | zend_compile_file = fricc2load_compile_file; 181 | return SUCCESS; 182 | } 183 | 184 | PHP_MSHUTDOWN_FUNCTION(fricc2load) 185 | { 186 | // CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; 187 | zend_compile_file = org_compile_file; 188 | return SUCCESS; 189 | } 190 | 191 | /* {{{ PHP_MINFO_FUNCTION 192 | */ 193 | PHP_MINFO_FUNCTION(fricc2load) 194 | { 195 | php_info_print_table_start(); 196 | php_info_print_table_header(2, "fricc2load support", "enabled"); 197 | php_info_print_table_header(2, "fricc2load version", "2"); 198 | php_info_print_table_row(2, "URL", "http://github.com/hoowa/FRICC2"); 199 | php_info_print_table_end(); 200 | } 201 | /* }}} */ 202 | 203 | /* {{{ fricc2load_module_entry 204 | */ 205 | zend_module_entry fricc2load_module_entry = { 206 | STANDARD_MODULE_HEADER, 207 | "fricc2load", /* Extension name */ 208 | NULL, /* zend_function_entry */ 209 | PHP_MINIT(fricc2load), /* PHP_MINIT - Module initialization */ 210 | PHP_MSHUTDOWN(fricc2load), /* PHP_MSHUTDOWN - Module shutdown */ 211 | NULL, /* PHP_RINIT - Request initialization */ 212 | NULL, /* PHP_RSHUTDOWN - Request shutdown */ 213 | PHP_MINFO(fricc2load), /* PHP_MINFO - Module info */ 214 | PHP_FRICC2LOAD_VERSION, /* Version */ 215 | STANDARD_MODULE_PROPERTIES 216 | }; 217 | /* }}} */ 218 | 219 | #ifdef COMPILE_DL_FRICC2LOAD 220 | # ifdef ZTS 221 | ZEND_TSRMLS_CACHE_DEFINE() 222 | # endif 223 | ZEND_GET_MODULE(fricc2load) 224 | #endif 225 | -------------------------------------------------------------------------------- /fricc2load/init_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use FindBin qw($Bin); 3 | use Data::Dumper; 4 | use Time::HiRes qw(gettimeofday); 5 | use List::Util qw(shuffle); 6 | use strict; 7 | 8 | my ($seconds, $microseconds) = gettimeofday; 9 | my $sm = $seconds+$microseconds; 10 | srand($sm); 11 | 12 | # ============================================ 13 | # generate key string and save to fricc2_lib.h 14 | # ============================================ 15 | my $key_str = ''; 16 | my $key_limit = 32767; #-32768~+32767 17 | for (my $i=0;$i<16;$i++) { 18 | $key_str .= int(rand($key_limit)).','; 19 | } 20 | chop($key_str); 21 | 22 | print "New Key is: $key_str\n"; 23 | my @source_body; 24 | open(DATA, "<$Bin/fricc2_lib.h") or die "Error To Read file!\n"; 25 | @source_body = ; 26 | close(DATA); 27 | 28 | open(DATA, ">$Bin/fricc2_lib.h") or die "Error To Write file!\n"; 29 | foreach my $line (@source_body) { 30 | if ($line =~ /^#define FRICCKEY /) { 31 | print DATA '#define FRICCKEY '.$key_str."\n"; 32 | } else { 33 | print DATA $line; 34 | } 35 | } 36 | close(DATA); 37 | 38 | # ============================================ 39 | # generate key order and save to fricc2_lib.c 40 | # ============================================ 41 | my (%keys_used, %keys_selected); 42 | my $keys_count=0; 43 | my $keys_buf=''; 44 | while(1) 45 | { 46 | my $key1 = int(rand(15)); 47 | my $key2 = int(rand(15)); 48 | if (exists $keys_used{$key1} || exists $keys_used{$key2} || $key1 == $key2) { 49 | next; 50 | } 51 | $keys_used{$key1} = 1; 52 | $keys_used{$key2} = 1; 53 | 54 | $keys_selected{$key1} = $key2; 55 | $keys_count++; 56 | if ($keys_count >= 4) { 57 | last; 58 | } 59 | } 60 | foreach my $old_idx (keys %keys_selected) 61 | { 62 | $keys_buf .= "\ti = friccload_key[".$old_idx."];\n". 63 | "\tfriccload_key[".$old_idx."] = friccload_key[".$keys_selected{$old_idx}."];\n". 64 | "\t".'friccload_key['.$keys_selected{$old_idx}."] = i;\n"; 65 | } 66 | print "New Key order: "; 67 | print Dumper \%keys_selected; 68 | my @source_body; 69 | open(DATA, "<$Bin/fricc2_lib.c") or die "Error To Read file!\n"; 70 | @source_body = ; 71 | close(DATA); 72 | open(DATA, ">$Bin/fricc2_lib.c") or die "Error To Write file!\n"; 73 | my $start_pos = 0; 74 | foreach my $line (@source_body) { 75 | if ($line =~ /\/\/ start_rre/) { 76 | print DATA $line; 77 | $start_pos = 1; 78 | } elsif ($line =~ /\/\/ end_rre/) { 79 | print DATA $keys_buf; 80 | print DATA $line; 81 | $start_pos = 0; 82 | } elsif ($start_pos == 1) { 83 | next; 84 | } else { 85 | print DATA $line; 86 | } 87 | } 88 | close(DATA); 89 | -------------------------------------------------------------------------------- /fricc2load/php_fricc2load.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | FRICC2 | 4 | +----------------------------------------------------------------------+ 5 | | Author: sun bing | 6 | +----------------------------------------------------------------------+ 7 | */ 8 | 9 | #ifndef PHP_FRICC2LOAD_H 10 | # define PHP_FRICC2LOAD_H 11 | 12 | extern zend_module_entry fricc2load_module_entry; 13 | # define phpext_fricc2load_ptr &fricc2load_module_entry 14 | 15 | # define PHP_FRICC2LOAD_VERSION "2.0.1" 16 | 17 | # if defined(ZTS) && defined(COMPILE_DL_FRICC2LOAD) 18 | ZEND_TSRMLS_CACHE_EXTERN() 19 | # endif 20 | 21 | #endif /* PHP_FRICC2LOAD_H */ 22 | --------------------------------------------------------------------------------