| @ -1,28 +1,28 @@ | ||||
| # How to Contribute | ||||
| 
 | ||||
| We'd love to accept your patches and contributions to this project. There are | ||||
| just a few small guidelines you need to follow. | ||||
| 
 | ||||
| ## Contributor License Agreement | ||||
| 
 | ||||
| Contributions to this project must be accompanied by a Contributor License | ||||
| Agreement. You (or your employer) retain the copyright to your contribution; | ||||
| this simply gives us permission to use and redistribute your contributions as | ||||
| part of the project. Head over to <https://cla.developers.google.com/> to see | ||||
| your current agreements on file or to sign a new one. | ||||
| 
 | ||||
| You generally only need to submit a CLA once, so if you've already submitted one | ||||
| (even if it was for a different project), you probably don't need to do it | ||||
| again. | ||||
| 
 | ||||
| ## Code reviews | ||||
| 
 | ||||
| All submissions, including submissions by project members, require review. We | ||||
| use GitHub pull requests for this purpose. Consult | ||||
| [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||||
| information on using pull requests. | ||||
| 
 | ||||
| ## Community Guidelines | ||||
| 
 | ||||
| This project follows [Google's Open Source Community | ||||
| Guidelines](https://opensource.google.com/conduct/). | ||||
| # How to Contribute | ||||
| 
 | ||||
| We'd love to accept your patches and contributions to this project. There are | ||||
| just a few small guidelines you need to follow. | ||||
| 
 | ||||
| ## Contributor License Agreement | ||||
| 
 | ||||
| Contributions to this project must be accompanied by a Contributor License | ||||
| Agreement. You (or your employer) retain the copyright to your contribution; | ||||
| this simply gives us permission to use and redistribute your contributions as | ||||
| part of the project. Head over to <https://cla.developers.google.com/> to see | ||||
| your current agreements on file or to sign a new one. | ||||
| 
 | ||||
| You generally only need to submit a CLA once, so if you've already submitted one | ||||
| (even if it was for a different project), you probably don't need to do it | ||||
| again. | ||||
| 
 | ||||
| ## Code reviews | ||||
| 
 | ||||
| All submissions, including submissions by project members, require review. We | ||||
| use GitHub pull requests for this purpose. Consult | ||||
| [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||||
| information on using pull requests. | ||||
| 
 | ||||
| ## Community Guidelines | ||||
| 
 | ||||
| This project follows [Google's Open Source Community | ||||
| Guidelines](https://opensource.google.com/conduct/). | ||||
|  | ||||
| @ -1,202 +1,202 @@ | ||||
| 
 | ||||
|                                  Apache License | ||||
|                            Version 2.0, January 2004 | ||||
|                         http://www.apache.org/licenses/ | ||||
| 
 | ||||
|    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||||
| 
 | ||||
|    1. Definitions. | ||||
| 
 | ||||
|       "License" shall mean the terms and conditions for use, reproduction, | ||||
|       and distribution as defined by Sections 1 through 9 of this document. | ||||
| 
 | ||||
|       "Licensor" shall mean the copyright owner or entity authorized by | ||||
|       the copyright owner that is granting the License. | ||||
| 
 | ||||
|       "Legal Entity" shall mean the union of the acting entity and all | ||||
|       other entities that control, are controlled by, or are under common | ||||
|       control with that entity. For the purposes of this definition, | ||||
|       "control" means (i) the power, direct or indirect, to cause the | ||||
|       direction or management of such entity, whether by contract or | ||||
|       otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||||
|       outstanding shares, or (iii) beneficial ownership of such entity. | ||||
| 
 | ||||
|       "You" (or "Your") shall mean an individual or Legal Entity | ||||
|       exercising permissions granted by this License. | ||||
| 
 | ||||
|       "Source" form shall mean the preferred form for making modifications, | ||||
|       including but not limited to software source code, documentation | ||||
|       source, and configuration files. | ||||
| 
 | ||||
|       "Object" form shall mean any form resulting from mechanical | ||||
|       transformation or translation of a Source form, including but | ||||
|       not limited to compiled object code, generated documentation, | ||||
|       and conversions to other media types. | ||||
| 
 | ||||
|       "Work" shall mean the work of authorship, whether in Source or | ||||
|       Object form, made available under the License, as indicated by a | ||||
|       copyright notice that is included in or attached to the work | ||||
|       (an example is provided in the Appendix below). | ||||
| 
 | ||||
|       "Derivative Works" shall mean any work, whether in Source or Object | ||||
|       form, that is based on (or derived from) the Work and for which the | ||||
|       editorial revisions, annotations, elaborations, or other modifications | ||||
|       represent, as a whole, an original work of authorship. For the purposes | ||||
|       of this License, Derivative Works shall not include works that remain | ||||
|       separable from, or merely link (or bind by name) to the interfaces of, | ||||
|       the Work and Derivative Works thereof. | ||||
| 
 | ||||
|       "Contribution" shall mean any work of authorship, including | ||||
|       the original version of the Work and any modifications or additions | ||||
|       to that Work or Derivative Works thereof, that is intentionally | ||||
|       submitted to Licensor for inclusion in the Work by the copyright owner | ||||
|       or by an individual or Legal Entity authorized to submit on behalf of | ||||
|       the copyright owner. For the purposes of this definition, "submitted" | ||||
|       means any form of electronic, verbal, or written communication sent | ||||
|       to the Licensor or its representatives, including but not limited to | ||||
|       communication on electronic mailing lists, source code control systems, | ||||
|       and issue tracking systems that are managed by, or on behalf of, the | ||||
|       Licensor for the purpose of discussing and improving the Work, but | ||||
|       excluding communication that is conspicuously marked or otherwise | ||||
|       designated in writing by the copyright owner as "Not a Contribution." | ||||
| 
 | ||||
|       "Contributor" shall mean Licensor and any individual or Legal Entity | ||||
|       on behalf of whom a Contribution has been received by Licensor and | ||||
|       subsequently incorporated within the Work. | ||||
| 
 | ||||
|    2. Grant of Copyright License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       copyright license to reproduce, prepare Derivative Works of, | ||||
|       publicly display, publicly perform, sublicense, and distribute the | ||||
|       Work and such Derivative Works in Source or Object form. | ||||
| 
 | ||||
|    3. Grant of Patent License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       (except as stated in this section) patent license to make, have made, | ||||
|       use, offer to sell, sell, import, and otherwise transfer the Work, | ||||
|       where such license applies only to those patent claims licensable | ||||
|       by such Contributor that are necessarily infringed by their | ||||
|       Contribution(s) alone or by combination of their Contribution(s) | ||||
|       with the Work to which such Contribution(s) was submitted. If You | ||||
|       institute patent litigation against any entity (including a | ||||
|       cross-claim or counterclaim in a lawsuit) alleging that the Work | ||||
|       or a Contribution incorporated within the Work constitutes direct | ||||
|       or contributory patent infringement, then any patent licenses | ||||
|       granted to You under this License for that Work shall terminate | ||||
|       as of the date such litigation is filed. | ||||
| 
 | ||||
|    4. Redistribution. You may reproduce and distribute copies of the | ||||
|       Work or Derivative Works thereof in any medium, with or without | ||||
|       modifications, and in Source or Object form, provided that You | ||||
|       meet the following conditions: | ||||
| 
 | ||||
|       (a) You must give any other recipients of the Work or | ||||
|           Derivative Works a copy of this License; and | ||||
| 
 | ||||
|       (b) You must cause any modified files to carry prominent notices | ||||
|           stating that You changed the files; and | ||||
| 
 | ||||
|       (c) You must retain, in the Source form of any Derivative Works | ||||
|           that You distribute, all copyright, patent, trademark, and | ||||
|           attribution notices from the Source form of the Work, | ||||
|           excluding those notices that do not pertain to any part of | ||||
|           the Derivative Works; and | ||||
| 
 | ||||
|       (d) If the Work includes a "NOTICE" text file as part of its | ||||
|           distribution, then any Derivative Works that You distribute must | ||||
|           include a readable copy of the attribution notices contained | ||||
|           within such NOTICE file, excluding those notices that do not | ||||
|           pertain to any part of the Derivative Works, in at least one | ||||
|           of the following places: within a NOTICE text file distributed | ||||
|           as part of the Derivative Works; within the Source form or | ||||
|           documentation, if provided along with the Derivative Works; or, | ||||
|           within a display generated by the Derivative Works, if and | ||||
|           wherever such third-party notices normally appear. The contents | ||||
|           of the NOTICE file are for informational purposes only and | ||||
|           do not modify the License. You may add Your own attribution | ||||
|           notices within Derivative Works that You distribute, alongside | ||||
|           or as an addendum to the NOTICE text from the Work, provided | ||||
|           that such additional attribution notices cannot be construed | ||||
|           as modifying the License. | ||||
| 
 | ||||
|       You may add Your own copyright statement to Your modifications and | ||||
|       may provide additional or different license terms and conditions | ||||
|       for use, reproduction, or distribution of Your modifications, or | ||||
|       for any such Derivative Works as a whole, provided Your use, | ||||
|       reproduction, and distribution of the Work otherwise complies with | ||||
|       the conditions stated in this License. | ||||
| 
 | ||||
|    5. Submission of Contributions. Unless You explicitly state otherwise, | ||||
|       any Contribution intentionally submitted for inclusion in the Work | ||||
|       by You to the Licensor shall be under the terms and conditions of | ||||
|       this License, without any additional terms or conditions. | ||||
|       Notwithstanding the above, nothing herein shall supersede or modify | ||||
|       the terms of any separate license agreement you may have executed | ||||
|       with Licensor regarding such Contributions. | ||||
| 
 | ||||
|    6. Trademarks. This License does not grant permission to use the trade | ||||
|       names, trademarks, service marks, or product names of the Licensor, | ||||
|       except as required for reasonable and customary use in describing the | ||||
|       origin of the Work and reproducing the content of the NOTICE file. | ||||
| 
 | ||||
|    7. Disclaimer of Warranty. Unless required by applicable law or | ||||
|       agreed to in writing, Licensor provides the Work (and each | ||||
|       Contributor provides its Contributions) on an "AS IS" BASIS, | ||||
|       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||
|       implied, including, without limitation, any warranties or conditions | ||||
|       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||||
|       PARTICULAR PURPOSE. You are solely responsible for determining the | ||||
|       appropriateness of using or redistributing the Work and assume any | ||||
|       risks associated with Your exercise of permissions under this License. | ||||
| 
 | ||||
|    8. Limitation of Liability. In no event and under no legal theory, | ||||
|       whether in tort (including negligence), contract, or otherwise, | ||||
|       unless required by applicable law (such as deliberate and grossly | ||||
|       negligent acts) or agreed to in writing, shall any Contributor be | ||||
|       liable to You for damages, including any direct, indirect, special, | ||||
|       incidental, or consequential damages of any character arising as a | ||||
|       result of this License or out of the use or inability to use the | ||||
|       Work (including but not limited to damages for loss of goodwill, | ||||
|       work stoppage, computer failure or malfunction, or any and all | ||||
|       other commercial damages or losses), even if such Contributor | ||||
|       has been advised of the possibility of such damages. | ||||
| 
 | ||||
|    9. Accepting Warranty or Additional Liability. While redistributing | ||||
|       the Work or Derivative Works thereof, You may choose to offer, | ||||
|       and charge a fee for, acceptance of support, warranty, indemnity, | ||||
|       or other liability obligations and/or rights consistent with this | ||||
|       License. However, in accepting such obligations, You may act only | ||||
|       on Your own behalf and on Your sole responsibility, not on behalf | ||||
|       of any other Contributor, and only if You agree to indemnify, | ||||
|       defend, and hold each Contributor harmless for any liability | ||||
|       incurred by, or claims asserted against, such Contributor by reason | ||||
|       of your accepting any such warranty or additional liability. | ||||
| 
 | ||||
|    END OF TERMS AND CONDITIONS | ||||
| 
 | ||||
|    APPENDIX: How to apply the Apache License to your work. | ||||
| 
 | ||||
|       To apply the Apache License to your work, attach the following | ||||
|       boilerplate notice, with the fields enclosed by brackets "[]" | ||||
|       replaced with your own identifying information. (Don't include | ||||
|       the brackets!)  The text should be enclosed in the appropriate | ||||
|       comment syntax for the file format. We also recommend that a | ||||
|       file or class name and description of purpose be included on the | ||||
|       same "printed page" as the copyright notice for easier | ||||
|       identification within third-party archives. | ||||
| 
 | ||||
|    Copyright [yyyy] [name of copyright owner] | ||||
| 
 | ||||
|    Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|    you may not use this file except in compliance with the License. | ||||
|    You may obtain a copy of the License at | ||||
| 
 | ||||
|        http://www.apache.org/licenses/LICENSE-2.0 | ||||
| 
 | ||||
|    Unless required by applicable law or agreed to in writing, software | ||||
|    distributed under the License is distributed on an "AS IS" BASIS, | ||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|    See the License for the specific language governing permissions and | ||||
|    limitations under the License. | ||||
| 
 | ||||
|                                  Apache License | ||||
|                            Version 2.0, January 2004 | ||||
|                         http://www.apache.org/licenses/ | ||||
| 
 | ||||
|    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||||
| 
 | ||||
|    1. Definitions. | ||||
| 
 | ||||
|       "License" shall mean the terms and conditions for use, reproduction, | ||||
|       and distribution as defined by Sections 1 through 9 of this document. | ||||
| 
 | ||||
|       "Licensor" shall mean the copyright owner or entity authorized by | ||||
|       the copyright owner that is granting the License. | ||||
| 
 | ||||
|       "Legal Entity" shall mean the union of the acting entity and all | ||||
|       other entities that control, are controlled by, or are under common | ||||
|       control with that entity. For the purposes of this definition, | ||||
|       "control" means (i) the power, direct or indirect, to cause the | ||||
|       direction or management of such entity, whether by contract or | ||||
|       otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||||
|       outstanding shares, or (iii) beneficial ownership of such entity. | ||||
| 
 | ||||
|       "You" (or "Your") shall mean an individual or Legal Entity | ||||
|       exercising permissions granted by this License. | ||||
| 
 | ||||
|       "Source" form shall mean the preferred form for making modifications, | ||||
|       including but not limited to software source code, documentation | ||||
|       source, and configuration files. | ||||
| 
 | ||||
|       "Object" form shall mean any form resulting from mechanical | ||||
|       transformation or translation of a Source form, including but | ||||
|       not limited to compiled object code, generated documentation, | ||||
|       and conversions to other media types. | ||||
| 
 | ||||
|       "Work" shall mean the work of authorship, whether in Source or | ||||
|       Object form, made available under the License, as indicated by a | ||||
|       copyright notice that is included in or attached to the work | ||||
|       (an example is provided in the Appendix below). | ||||
| 
 | ||||
|       "Derivative Works" shall mean any work, whether in Source or Object | ||||
|       form, that is based on (or derived from) the Work and for which the | ||||
|       editorial revisions, annotations, elaborations, or other modifications | ||||
|       represent, as a whole, an original work of authorship. For the purposes | ||||
|       of this License, Derivative Works shall not include works that remain | ||||
|       separable from, or merely link (or bind by name) to the interfaces of, | ||||
|       the Work and Derivative Works thereof. | ||||
| 
 | ||||
|       "Contribution" shall mean any work of authorship, including | ||||
|       the original version of the Work and any modifications or additions | ||||
|       to that Work or Derivative Works thereof, that is intentionally | ||||
|       submitted to Licensor for inclusion in the Work by the copyright owner | ||||
|       or by an individual or Legal Entity authorized to submit on behalf of | ||||
|       the copyright owner. For the purposes of this definition, "submitted" | ||||
|       means any form of electronic, verbal, or written communication sent | ||||
|       to the Licensor or its representatives, including but not limited to | ||||
|       communication on electronic mailing lists, source code control systems, | ||||
|       and issue tracking systems that are managed by, or on behalf of, the | ||||
|       Licensor for the purpose of discussing and improving the Work, but | ||||
|       excluding communication that is conspicuously marked or otherwise | ||||
|       designated in writing by the copyright owner as "Not a Contribution." | ||||
| 
 | ||||
|       "Contributor" shall mean Licensor and any individual or Legal Entity | ||||
|       on behalf of whom a Contribution has been received by Licensor and | ||||
|       subsequently incorporated within the Work. | ||||
| 
 | ||||
|    2. Grant of Copyright License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       copyright license to reproduce, prepare Derivative Works of, | ||||
|       publicly display, publicly perform, sublicense, and distribute the | ||||
|       Work and such Derivative Works in Source or Object form. | ||||
| 
 | ||||
|    3. Grant of Patent License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       (except as stated in this section) patent license to make, have made, | ||||
|       use, offer to sell, sell, import, and otherwise transfer the Work, | ||||
|       where such license applies only to those patent claims licensable | ||||
|       by such Contributor that are necessarily infringed by their | ||||
|       Contribution(s) alone or by combination of their Contribution(s) | ||||
|       with the Work to which such Contribution(s) was submitted. If You | ||||
|       institute patent litigation against any entity (including a | ||||
|       cross-claim or counterclaim in a lawsuit) alleging that the Work | ||||
|       or a Contribution incorporated within the Work constitutes direct | ||||
|       or contributory patent infringement, then any patent licenses | ||||
|       granted to You under this License for that Work shall terminate | ||||
|       as of the date such litigation is filed. | ||||
| 
 | ||||
|    4. Redistribution. You may reproduce and distribute copies of the | ||||
|       Work or Derivative Works thereof in any medium, with or without | ||||
|       modifications, and in Source or Object form, provided that You | ||||
|       meet the following conditions: | ||||
| 
 | ||||
|       (a) You must give any other recipients of the Work or | ||||
|           Derivative Works a copy of this License; and | ||||
| 
 | ||||
|       (b) You must cause any modified files to carry prominent notices | ||||
|           stating that You changed the files; and | ||||
| 
 | ||||
|       (c) You must retain, in the Source form of any Derivative Works | ||||
|           that You distribute, all copyright, patent, trademark, and | ||||
|           attribution notices from the Source form of the Work, | ||||
|           excluding those notices that do not pertain to any part of | ||||
|           the Derivative Works; and | ||||
| 
 | ||||
|       (d) If the Work includes a "NOTICE" text file as part of its | ||||
|           distribution, then any Derivative Works that You distribute must | ||||
|           include a readable copy of the attribution notices contained | ||||
|           within such NOTICE file, excluding those notices that do not | ||||
|           pertain to any part of the Derivative Works, in at least one | ||||
|           of the following places: within a NOTICE text file distributed | ||||
|           as part of the Derivative Works; within the Source form or | ||||
|           documentation, if provided along with the Derivative Works; or, | ||||
|           within a display generated by the Derivative Works, if and | ||||
|           wherever such third-party notices normally appear. The contents | ||||
|           of the NOTICE file are for informational purposes only and | ||||
|           do not modify the License. You may add Your own attribution | ||||
|           notices within Derivative Works that You distribute, alongside | ||||
|           or as an addendum to the NOTICE text from the Work, provided | ||||
|           that such additional attribution notices cannot be construed | ||||
|           as modifying the License. | ||||
| 
 | ||||
|       You may add Your own copyright statement to Your modifications and | ||||
|       may provide additional or different license terms and conditions | ||||
|       for use, reproduction, or distribution of Your modifications, or | ||||
|       for any such Derivative Works as a whole, provided Your use, | ||||
|       reproduction, and distribution of the Work otherwise complies with | ||||
|       the conditions stated in this License. | ||||
| 
 | ||||
|    5. Submission of Contributions. Unless You explicitly state otherwise, | ||||
|       any Contribution intentionally submitted for inclusion in the Work | ||||
|       by You to the Licensor shall be under the terms and conditions of | ||||
|       this License, without any additional terms or conditions. | ||||
|       Notwithstanding the above, nothing herein shall supersede or modify | ||||
|       the terms of any separate license agreement you may have executed | ||||
|       with Licensor regarding such Contributions. | ||||
| 
 | ||||
|    6. Trademarks. This License does not grant permission to use the trade | ||||
|       names, trademarks, service marks, or product names of the Licensor, | ||||
|       except as required for reasonable and customary use in describing the | ||||
|       origin of the Work and reproducing the content of the NOTICE file. | ||||
| 
 | ||||
|    7. Disclaimer of Warranty. Unless required by applicable law or | ||||
|       agreed to in writing, Licensor provides the Work (and each | ||||
|       Contributor provides its Contributions) on an "AS IS" BASIS, | ||||
|       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||
|       implied, including, without limitation, any warranties or conditions | ||||
|       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||||
|       PARTICULAR PURPOSE. You are solely responsible for determining the | ||||
|       appropriateness of using or redistributing the Work and assume any | ||||
|       risks associated with Your exercise of permissions under this License. | ||||
| 
 | ||||
|    8. Limitation of Liability. In no event and under no legal theory, | ||||
|       whether in tort (including negligence), contract, or otherwise, | ||||
|       unless required by applicable law (such as deliberate and grossly | ||||
|       negligent acts) or agreed to in writing, shall any Contributor be | ||||
|       liable to You for damages, including any direct, indirect, special, | ||||
|       incidental, or consequential damages of any character arising as a | ||||
|       result of this License or out of the use or inability to use the | ||||
|       Work (including but not limited to damages for loss of goodwill, | ||||
|       work stoppage, computer failure or malfunction, or any and all | ||||
|       other commercial damages or losses), even if such Contributor | ||||
|       has been advised of the possibility of such damages. | ||||
| 
 | ||||
|    9. Accepting Warranty or Additional Liability. While redistributing | ||||
|       the Work or Derivative Works thereof, You may choose to offer, | ||||
|       and charge a fee for, acceptance of support, warranty, indemnity, | ||||
|       or other liability obligations and/or rights consistent with this | ||||
|       License. However, in accepting such obligations, You may act only | ||||
|       on Your own behalf and on Your sole responsibility, not on behalf | ||||
|       of any other Contributor, and only if You agree to indemnify, | ||||
|       defend, and hold each Contributor harmless for any liability | ||||
|       incurred by, or claims asserted against, such Contributor by reason | ||||
|       of your accepting any such warranty or additional liability. | ||||
| 
 | ||||
|    END OF TERMS AND CONDITIONS | ||||
| 
 | ||||
|    APPENDIX: How to apply the Apache License to your work. | ||||
| 
 | ||||
|       To apply the Apache License to your work, attach the following | ||||
|       boilerplate notice, with the fields enclosed by brackets "[]" | ||||
|       replaced with your own identifying information. (Don't include | ||||
|       the brackets!)  The text should be enclosed in the appropriate | ||||
|       comment syntax for the file format. We also recommend that a | ||||
|       file or class name and description of purpose be included on the | ||||
|       same "printed page" as the copyright notice for easier | ||||
|       identification within third-party archives. | ||||
| 
 | ||||
|    Copyright [yyyy] [name of copyright owner] | ||||
| 
 | ||||
|    Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|    you may not use this file except in compliance with the License. | ||||
|    You may obtain a copy of the License at | ||||
| 
 | ||||
|        http://www.apache.org/licenses/LICENSE-2.0 | ||||
| 
 | ||||
|    Unless required by applicable law or agreed to in writing, software | ||||
|    distributed under the License is distributed on an "AS IS" BASIS, | ||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|    See the License for the specific language governing permissions and | ||||
|    limitations under the License. | ||||
|  | ||||
| @ -1,153 +1,153 @@ | ||||
| #
 | ||||
| # american fuzzy lop - makefile
 | ||||
| # -----------------------------
 | ||||
| #
 | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com>
 | ||||
| # 
 | ||||
| # Copyright 2013, 2014, 2015, 2016, 2017 Google LLC All rights reserved.
 | ||||
| # 
 | ||||
| # Licensed under the Apache License, Version 2.0 (the "License");
 | ||||
| # you may not use this file except in compliance with the License.
 | ||||
| # You may obtain a copy of the License at:
 | ||||
| # 
 | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| #
 | ||||
| 
 | ||||
| PROGNAME    = afl | ||||
| VERSION     = $(shell grep '^\#define VERSION ' config.h | cut -d '"' -f2) | ||||
| 
 | ||||
| PREFIX     ?= /usr/local | ||||
| BIN_PATH    = $(PREFIX)/bin | ||||
| HELPER_PATH = $(PREFIX)/lib/afl | ||||
| DOC_PATH    = $(PREFIX)/share/doc/afl | ||||
| MISC_PATH   = $(PREFIX)/share/afl | ||||
| 
 | ||||
| # PROGS intentionally omit afl-as, which gets installed elsewhere.
 | ||||
| 
 | ||||
| PROGS       = afl-gcc afl-fuzz afl-showmap afl-tmin afl-gotcpu afl-analyze | ||||
| SH_PROGS    = afl-plot afl-cmin afl-whatsup | ||||
| 
 | ||||
| CFLAGS     ?= -O3 -funroll-loops | ||||
| CFLAGS     += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \
 | ||||
| 	      -DAFL_PATH=\"$(HELPER_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\" \
 | ||||
| 	      -DBIN_PATH=\"$(BIN_PATH)\" | ||||
| 
 | ||||
| ifneq "$(filter Linux GNU%,$(shell uname))" "" | ||||
|   LDFLAGS  += -ldl | ||||
| endif | ||||
| 
 | ||||
| ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" "" | ||||
|   TEST_CC   = afl-gcc | ||||
| else | ||||
|   TEST_CC   = afl-clang | ||||
| endif | ||||
| 
 | ||||
| COMM_HDR    = alloc-inl.h config.h debug.h types.h | ||||
| 
 | ||||
| all: test_x86 $(PROGS) afl-as test_build all_done | ||||
| 
 | ||||
| ifndef AFL_NO_X86 | ||||
| 
 | ||||
| test_x86: | ||||
| 	@echo "[*] Checking for the ability to compile x86 code..." | ||||
| 	@echo 'main() { __asm__("xorb %al, %al"); }' | $(CC) -w -x c - -o .test || ( echo; echo "Oops, looks like your compiler can't generate x86 code."; echo; echo "Don't panic! You can use the LLVM or QEMU mode, but see docs/INSTALL first."; echo "(To ignore this error, set AFL_NO_X86=1 and try again.)"; echo; exit 1 ) | ||||
| 	@rm -f .test | ||||
| 	@echo "[+] Everything seems to be working, ready to compile." | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
| test_x86: | ||||
| 	@echo "[!] Note: skipping x86 compilation checks (AFL_NO_X86 set)." | ||||
| 
 | ||||
| endif | ||||
| 
 | ||||
| afl-gcc: afl-gcc.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 	set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $$i; done | ||||
| 
 | ||||
| afl-as: afl-as.c afl-as.h $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 	ln -sf afl-as as | ||||
| 
 | ||||
| afl-fuzz: afl-fuzz.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-showmap: afl-showmap.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-tmin: afl-tmin.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-analyze: afl-analyze.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-gotcpu: afl-gotcpu.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| ifndef AFL_NO_X86 | ||||
| 
 | ||||
| test_build: afl-gcc afl-as afl-showmap | ||||
| 	@echo "[*] Testing the CC wrapper and instrumentation output..." | ||||
| 	unset AFL_USE_ASAN AFL_USE_MSAN; AFL_QUIET=1 AFL_INST_RATIO=100 AFL_PATH=. ./$(TEST_CC) $(CFLAGS) test-instr.c -o test-instr $(LDFLAGS) | ||||
| 	./afl-showmap -m none -q -o .test-instr0 ./test-instr < /dev/null | ||||
| 	echo 1 | ./afl-showmap -m none -q -o .test-instr1 ./test-instr | ||||
| 	@rm -f test-instr | ||||
| 	@cmp -s .test-instr0 .test-instr1; DR="$$?"; rm -f .test-instr0 .test-instr1; if [ "$$DR" = "0" ]; then echo; echo "Oops, the instrumentation does not seem to be behaving correctly!"; echo; echo "Please ping <lcamtuf@google.com> to troubleshoot the issue."; echo; exit 1; fi | ||||
| 	@echo "[+] All right, the instrumentation seems to be working!" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
| test_build: afl-gcc afl-as afl-showmap | ||||
| 	@echo "[!] Note: skipping build tests (you may need to use LLVM or QEMU mode)." | ||||
| 
 | ||||
| endif | ||||
| 
 | ||||
| all_done: test_build | ||||
| 	@if [ ! "`which clang 2>/dev/null`" = "" ]; then echo "[+] LLVM users: see llvm_mode/README.llvm for a faster alternative to afl-gcc."; fi | ||||
| 	@echo "[+] All done! Be sure to review README - it's pretty short and useful." | ||||
| 	@if [ "`uname`" = "Darwin" ]; then printf "\nWARNING: Fuzzing on MacOS X is slow because of the unusually high overhead of\nfork() on this OS. Consider using Linux or *BSD. You can also use VirtualBox\n(virtualbox.org) to put AFL inside a Linux or *BSD VM.\n\n"; fi | ||||
| 	@! tty <&1 >/dev/null || printf "\033[0;30mNOTE: If you can read this, your terminal probably uses white background.\nThis will make the UI hard to read. See docs/status_screen.txt for advice.\033[0m\n" 2>/dev/null | ||||
| 
 | ||||
| .NOTPARALLEL: clean | ||||
| 
 | ||||
| clean: | ||||
| 	rm -f $(PROGS) afl-as as afl-g++ afl-clang afl-clang++ *.o *~ a.out core core.[1-9][0-9]* *.stackdump test .test test-instr .test-instr0 .test-instr1 qemu_mode/qemu-2.10.0.tar.bz2 afl-qemu-trace | ||||
| 	rm -rf out_dir qemu_mode/qemu-2.10.0 | ||||
| 	$(MAKE) -C llvm_mode clean | ||||
| 	$(MAKE) -C libdislocator clean | ||||
| 	$(MAKE) -C libtokencap clean | ||||
| 
 | ||||
| install: all | ||||
| 	mkdir -p -m 755 $${DESTDIR}$(BIN_PATH) $${DESTDIR}$(HELPER_PATH) $${DESTDIR}$(DOC_PATH) $${DESTDIR}$(MISC_PATH) | ||||
| 	rm -f $${DESTDIR}$(BIN_PATH)/afl-plot.sh | ||||
| 	install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH) | ||||
| 	rm -f $${DESTDIR}$(BIN_PATH)/afl-as | ||||
| 	if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi | ||||
| ifndef AFL_TRACE_PC | ||||
| 	if [ -f afl-clang-fast -a -f afl-llvm-pass.so -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-pass.so afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| else | ||||
| 	if [ -f afl-clang-fast -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| endif | ||||
| 	if [ -f afl-llvm-rt-32.o ]; then set -e; install -m 755 afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| 	if [ -f afl-llvm-rt-64.o ]; then set -e; install -m 755 afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| 	set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $${DESTDIR}$(BIN_PATH)/$$i; done | ||||
| 	install -m 755 afl-as $${DESTDIR}$(HELPER_PATH) | ||||
| 	ln -sf afl-as $${DESTDIR}$(HELPER_PATH)/as | ||||
| 	install -m 644 README.md docs/ChangeLog docs/*.txt $${DESTDIR}$(DOC_PATH) | ||||
| 	cp -r testcases/ $${DESTDIR}$(MISC_PATH) | ||||
| 	cp -r dictionaries/ $${DESTDIR}$(MISC_PATH) | ||||
| 
 | ||||
| publish: clean | ||||
| 	test "`basename $$PWD`" = "AFL" || exit 1 | ||||
| 	test -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz; if [ "$$?" = "0" ]; then echo; echo "Change program version in config.h, mmkay?"; echo; exit 1; fi | ||||
| 	cd ..; rm -rf $(PROGNAME)-$(VERSION); cp -pr $(PROGNAME) $(PROGNAME)-$(VERSION); \
 | ||||
| 	  tar -cvz -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz $(PROGNAME)-$(VERSION) | ||||
| 	chmod 644 ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz | ||||
| 	( cd ~/www/afl/releases/; ln -s -f $(PROGNAME)-$(VERSION).tgz $(PROGNAME)-latest.tgz ) | ||||
| 	cat docs/README >~/www/afl/README.txt | ||||
| 	cat docs/status_screen.txt >~/www/afl/status_screen.txt | ||||
| 	cat docs/historical_notes.txt >~/www/afl/historical_notes.txt | ||||
| 	cat docs/technical_details.txt >~/www/afl/technical_details.txt | ||||
| 	cat docs/ChangeLog >~/www/afl/ChangeLog.txt | ||||
| 	cat docs/QuickStartGuide.txt >~/www/afl/QuickStartGuide.txt | ||||
| 	echo -n "$(VERSION)" >~/www/afl/version.txt | ||||
| #
 | ||||
| # american fuzzy lop - makefile
 | ||||
| # -----------------------------
 | ||||
| #
 | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com>
 | ||||
| # 
 | ||||
| # Copyright 2013, 2014, 2015, 2016, 2017 Google LLC All rights reserved.
 | ||||
| # 
 | ||||
| # Licensed under the Apache License, Version 2.0 (the "License");
 | ||||
| # you may not use this file except in compliance with the License.
 | ||||
| # You may obtain a copy of the License at:
 | ||||
| # 
 | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| #
 | ||||
| 
 | ||||
| PROGNAME    = afl | ||||
| VERSION     = $(shell grep '^\#define VERSION ' config.h | cut -d '"' -f2) | ||||
| 
 | ||||
| PREFIX     ?= /usr/local | ||||
| BIN_PATH    = $(PREFIX)/bin | ||||
| HELPER_PATH = $(PREFIX)/lib/afl | ||||
| DOC_PATH    = $(PREFIX)/share/doc/afl | ||||
| MISC_PATH   = $(PREFIX)/share/afl | ||||
| 
 | ||||
| # PROGS intentionally omit afl-as, which gets installed elsewhere.
 | ||||
| 
 | ||||
| PROGS       = afl-gcc afl-fuzz afl-showmap afl-tmin afl-gotcpu afl-analyze | ||||
| SH_PROGS    = afl-plot afl-cmin afl-whatsup | ||||
| 
 | ||||
| CFLAGS     ?= -O3 -funroll-loops | ||||
| CFLAGS     += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \
 | ||||
| 	      -DAFL_PATH=\"$(HELPER_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\" \
 | ||||
| 	      -DBIN_PATH=\"$(BIN_PATH)\" | ||||
| 
 | ||||
| ifneq "$(filter Linux GNU%,$(shell uname))" "" | ||||
|   LDFLAGS  += -ldl | ||||
| endif | ||||
| 
 | ||||
| ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" "" | ||||
|   TEST_CC   = afl-gcc | ||||
| else | ||||
|   TEST_CC   = afl-clang | ||||
| endif | ||||
| 
 | ||||
| COMM_HDR    = alloc-inl.h config.h debug.h types.h | ||||
| 
 | ||||
| all: test_x86 $(PROGS) afl-as test_build all_done | ||||
| 
 | ||||
| ifndef AFL_NO_X86 | ||||
| 
 | ||||
| test_x86: | ||||
| 	@echo "[*] Checking for the ability to compile x86 code..." | ||||
| 	@echo 'main() { __asm__("xorb %al, %al"); }' | $(CC) -w -x c - -o .test || ( echo; echo "Oops, looks like your compiler can't generate x86 code."; echo; echo "Don't panic! You can use the LLVM or QEMU mode, but see docs/INSTALL first."; echo "(To ignore this error, set AFL_NO_X86=1 and try again.)"; echo; exit 1 ) | ||||
| 	@rm -f .test | ||||
| 	@echo "[+] Everything seems to be working, ready to compile." | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
| test_x86: | ||||
| 	@echo "[!] Note: skipping x86 compilation checks (AFL_NO_X86 set)." | ||||
| 
 | ||||
| endif | ||||
| 
 | ||||
| afl-gcc: afl-gcc.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 	set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $$i; done | ||||
| 
 | ||||
| afl-as: afl-as.c afl-as.h $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 	ln -sf afl-as as | ||||
| 
 | ||||
| afl-fuzz: afl-fuzz.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-showmap: afl-showmap.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-tmin: afl-tmin.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-analyze: afl-analyze.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| afl-gotcpu: afl-gotcpu.c $(COMM_HDR) | test_x86 | ||||
| 	$(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) | ||||
| 
 | ||||
| ifndef AFL_NO_X86 | ||||
| 
 | ||||
| test_build: afl-gcc afl-as afl-showmap | ||||
| 	@echo "[*] Testing the CC wrapper and instrumentation output..." | ||||
| 	unset AFL_USE_ASAN AFL_USE_MSAN; AFL_QUIET=1 AFL_INST_RATIO=100 AFL_PATH=. ./$(TEST_CC) $(CFLAGS) test-instr.c -o test-instr $(LDFLAGS) | ||||
| 	./afl-showmap -m none -q -o .test-instr0 ./test-instr < /dev/null | ||||
| 	echo 1 | ./afl-showmap -m none -q -o .test-instr1 ./test-instr | ||||
| 	@rm -f test-instr | ||||
| 	@cmp -s .test-instr0 .test-instr1; DR="$$?"; rm -f .test-instr0 .test-instr1; if [ "$$DR" = "0" ]; then echo; echo "Oops, the instrumentation does not seem to be behaving correctly!"; echo; echo "Please ping <lcamtuf@google.com> to troubleshoot the issue."; echo; exit 1; fi | ||||
| 	@echo "[+] All right, the instrumentation seems to be working!" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
| test_build: afl-gcc afl-as afl-showmap | ||||
| 	@echo "[!] Note: skipping build tests (you may need to use LLVM or QEMU mode)." | ||||
| 
 | ||||
| endif | ||||
| 
 | ||||
| all_done: test_build | ||||
| 	@if [ ! "`which clang 2>/dev/null`" = "" ]; then echo "[+] LLVM users: see llvm_mode/README.llvm for a faster alternative to afl-gcc."; fi | ||||
| 	@echo "[+] All done! Be sure to review README - it's pretty short and useful." | ||||
| 	@if [ "`uname`" = "Darwin" ]; then printf "\nWARNING: Fuzzing on MacOS X is slow because of the unusually high overhead of\nfork() on this OS. Consider using Linux or *BSD. You can also use VirtualBox\n(virtualbox.org) to put AFL inside a Linux or *BSD VM.\n\n"; fi | ||||
| 	@! tty <&1 >/dev/null || printf "\033[0;30mNOTE: If you can read this, your terminal probably uses white background.\nThis will make the UI hard to read. See docs/status_screen.txt for advice.\033[0m\n" 2>/dev/null | ||||
| 
 | ||||
| .NOTPARALLEL: clean | ||||
| 
 | ||||
| clean: | ||||
| 	rm -f $(PROGS) afl-as as afl-g++ afl-clang afl-clang++ *.o *~ a.out core core.[1-9][0-9]* *.stackdump test .test test-instr .test-instr0 .test-instr1 qemu_mode/qemu-2.10.0.tar.bz2 afl-qemu-trace | ||||
| 	rm -rf out_dir qemu_mode/qemu-2.10.0 | ||||
| 	$(MAKE) -C llvm_mode clean | ||||
| 	$(MAKE) -C libdislocator clean | ||||
| 	$(MAKE) -C libtokencap clean | ||||
| 
 | ||||
| install: all | ||||
| 	mkdir -p -m 755 $${DESTDIR}$(BIN_PATH) $${DESTDIR}$(HELPER_PATH) $${DESTDIR}$(DOC_PATH) $${DESTDIR}$(MISC_PATH) | ||||
| 	rm -f $${DESTDIR}$(BIN_PATH)/afl-plot.sh | ||||
| 	install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH) | ||||
| 	rm -f $${DESTDIR}$(BIN_PATH)/afl-as | ||||
| 	if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi | ||||
| ifndef AFL_TRACE_PC | ||||
| 	if [ -f afl-clang-fast -a -f afl-llvm-pass.so -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-pass.so afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| else | ||||
| 	if [ -f afl-clang-fast -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| endif | ||||
| 	if [ -f afl-llvm-rt-32.o ]; then set -e; install -m 755 afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| 	if [ -f afl-llvm-rt-64.o ]; then set -e; install -m 755 afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH); fi | ||||
| 	set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $${DESTDIR}$(BIN_PATH)/$$i; done | ||||
| 	install -m 755 afl-as $${DESTDIR}$(HELPER_PATH) | ||||
| 	ln -sf afl-as $${DESTDIR}$(HELPER_PATH)/as | ||||
| 	install -m 644 README.md docs/ChangeLog docs/*.txt $${DESTDIR}$(DOC_PATH) | ||||
| 	cp -r testcases/ $${DESTDIR}$(MISC_PATH) | ||||
| 	cp -r dictionaries/ $${DESTDIR}$(MISC_PATH) | ||||
| 
 | ||||
| publish: clean | ||||
| 	test "`basename $$PWD`" = "AFL" || exit 1 | ||||
| 	test -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz; if [ "$$?" = "0" ]; then echo; echo "Change program version in config.h, mmkay?"; echo; exit 1; fi | ||||
| 	cd ..; rm -rf $(PROGNAME)-$(VERSION); cp -pr $(PROGNAME) $(PROGNAME)-$(VERSION); \
 | ||||
| 	  tar -cvz -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz $(PROGNAME)-$(VERSION) | ||||
| 	chmod 644 ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz | ||||
| 	( cd ~/www/afl/releases/; ln -s -f $(PROGNAME)-$(VERSION).tgz $(PROGNAME)-latest.tgz ) | ||||
| 	cat docs/README >~/www/afl/README.txt | ||||
| 	cat docs/status_screen.txt >~/www/afl/status_screen.txt | ||||
| 	cat docs/historical_notes.txt >~/www/afl/historical_notes.txt | ||||
| 	cat docs/technical_details.txt >~/www/afl/technical_details.txt | ||||
| 	cat docs/ChangeLog >~/www/afl/ChangeLog.txt | ||||
| 	cat docs/QuickStartGuide.txt >~/www/afl/QuickStartGuide.txt | ||||
| 	echo -n "$(VERSION)" >~/www/afl/version.txt | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,461 +1,461 @@ | ||||
| #!/usr/bin/env bash | ||||
| # | ||||
| # american fuzzy lop - corpus minimization tool | ||||
| # --------------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # | ||||
| # Copyright 2014, 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # This tool tries to find the smallest subset of files in the input directory | ||||
| # that still trigger the full range of instrumentation data points seen in | ||||
| # the starting corpus. This has two uses: | ||||
| # | ||||
| #   - Screening large corpora of input files before using them as a seed for | ||||
| #     afl-fuzz. The tool will remove functionally redundant files and likely | ||||
| #     leave you with a much smaller set. | ||||
| # | ||||
| #     (In this case, you probably also want to consider running afl-tmin on | ||||
| #     the individual files later on to reduce their size.) | ||||
| # | ||||
| #   - Minimizing the corpus generated organically by afl-fuzz, perhaps when | ||||
| #     planning to feed it to more resource-intensive tools. The tool achieves | ||||
| #     this by removing all entries that used to trigger unique behaviors in the | ||||
| #     past, but have been made obsolete by later finds. | ||||
| # | ||||
| # Note that the tool doesn't modify the files themselves. For that, you want | ||||
| # afl-tmin. | ||||
| # | ||||
| # This script must use bash because other shells may have hardcoded limits on | ||||
| # array sizes. | ||||
| # | ||||
| 
 | ||||
| echo "corpus minimization tool for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| ######### | ||||
| # SETUP # | ||||
| ######### | ||||
| 
 | ||||
| # Process command-line options... | ||||
| 
 | ||||
| MEM_LIMIT=100 | ||||
| TIMEOUT=none | ||||
| 
 | ||||
| unset IN_DIR OUT_DIR STDIN_FILE EXTRA_PAR MEM_LIMIT_GIVEN \ | ||||
|   AFL_CMIN_CRASHES_ONLY AFL_CMIN_ALLOW_ANY QEMU_MODE | ||||
| 
 | ||||
| while getopts "+i:o:f:m:t:eQC" opt; do | ||||
| 
 | ||||
|   case "$opt" in  | ||||
| 
 | ||||
|     "i") | ||||
|          IN_DIR="$OPTARG" | ||||
|          ;; | ||||
| 
 | ||||
|     "o") | ||||
|          OUT_DIR="$OPTARG" | ||||
|          ;; | ||||
|     "f") | ||||
|          STDIN_FILE="$OPTARG" | ||||
|          ;; | ||||
|     "m") | ||||
|          MEM_LIMIT="$OPTARG" | ||||
|          MEM_LIMIT_GIVEN=1 | ||||
|          ;; | ||||
|     "t") | ||||
|          TIMEOUT="$OPTARG" | ||||
|          ;; | ||||
|     "e") | ||||
|          EXTRA_PAR="$EXTRA_PAR -e" | ||||
|          ;; | ||||
|     "C") | ||||
|          export AFL_CMIN_CRASHES_ONLY=1 | ||||
|          ;; | ||||
|     "Q") | ||||
|          EXTRA_PAR="$EXTRA_PAR -Q" | ||||
|          test "$MEM_LIMIT_GIVEN" = "" && MEM_LIMIT=250 | ||||
|          QEMU_MODE=1 | ||||
|          ;; | ||||
|     "?") | ||||
|          exit 1 | ||||
|          ;; | ||||
| 
 | ||||
|    esac | ||||
| 
 | ||||
| done | ||||
| 
 | ||||
| shift $((OPTIND-1)) | ||||
| 
 | ||||
| TARGET_BIN="$1" | ||||
| 
 | ||||
| if [ "$TARGET_BIN" = "" -o "$IN_DIR" = "" -o "$OUT_DIR" = "" ]; then | ||||
| 
 | ||||
|   cat 1>&2 <<_EOF_ | ||||
| Usage: $0 [ options ] -- /path/to/target_app [ ... ] | ||||
| 
 | ||||
| Required parameters: | ||||
| 
 | ||||
|   -i dir        - input directory with the starting corpus | ||||
|   -o dir        - output directory for minimized files | ||||
| 
 | ||||
| Execution control settings: | ||||
| 
 | ||||
|   -f file       - location read by the fuzzed program (stdin) | ||||
|   -m megs       - memory limit for child process ($MEM_LIMIT MB) | ||||
|   -t msec       - run time limit for child process (none) | ||||
|   -Q            - use binary-only instrumentation (QEMU mode) | ||||
| 
 | ||||
| Minimization settings: | ||||
| 
 | ||||
|   -C            - keep crashing inputs, reject everything else | ||||
|   -e            - solve for edge coverage only, ignore hit counts | ||||
| 
 | ||||
| For additional tips, please consult docs/README. | ||||
| 
 | ||||
| _EOF_ | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Do a sanity check to discourage the use of /tmp, since we can't really | ||||
| # handle this safely from a shell script. | ||||
| 
 | ||||
| if [ "$AFL_ALLOW_TMP" = "" ]; then | ||||
| 
 | ||||
|   echo "$IN_DIR" | grep -qE '^(/var)?/tmp/' | ||||
|   T1="$?" | ||||
| 
 | ||||
|   echo "$TARGET_BIN" | grep -qE '^(/var)?/tmp/' | ||||
|   T2="$?" | ||||
| 
 | ||||
|   echo "$OUT_DIR" | grep -qE '^(/var)?/tmp/' | ||||
|   T3="$?" | ||||
| 
 | ||||
|   echo "$STDIN_FILE" | grep -qE '^(/var)?/tmp/' | ||||
|   T4="$?" | ||||
| 
 | ||||
|   echo "$PWD" | grep -qE '^(/var)?/tmp/' | ||||
|   T5="$?" | ||||
| 
 | ||||
|   if [ "$T1" = "0" -o "$T2" = "0" -o "$T3" = "0" -o "$T4" = "0" -o "$T5" = "0" ]; then | ||||
|     echo "[-] Error: do not use this script in /tmp or /var/tmp." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # If @@ is specified, but there's no -f, let's come up with a temporary input | ||||
| # file name. | ||||
| 
 | ||||
| TRACE_DIR="$OUT_DIR/.traces" | ||||
| 
 | ||||
| if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|   if echo "$*" | grep -qF '@@'; then | ||||
|     STDIN_FILE="$TRACE_DIR/.cur_input" | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # Check for obvious errors. | ||||
| 
 | ||||
| if [ ! "$MEM_LIMIT" = "none" ]; then | ||||
| 
 | ||||
|   if [ "$MEM_LIMIT" -lt "5" ]; then | ||||
|     echo "[-] Error: dangerously low memory limit." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! "$TIMEOUT" = "none" ]; then | ||||
| 
 | ||||
|   if [ "$TIMEOUT" -lt "10" ]; then | ||||
|     echo "[-] Error: dangerously low timeout." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -f "$TARGET_BIN" -o ! -x "$TARGET_BIN" ]; then | ||||
| 
 | ||||
|   TNEW="`which "$TARGET_BIN" 2>/dev/null`" | ||||
| 
 | ||||
|   if [ ! -f "$TNEW" -o ! -x "$TNEW" ]; then | ||||
|     echo "[-] Error: binary '$TARGET_BIN' not found or not executable." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
|   TARGET_BIN="$TNEW" | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_SKIP_BIN_CHECK" = "" -a "$QEMU_MODE" = "" ]; then | ||||
| 
 | ||||
|   if ! grep -qF "__AFL_SHM_ID" "$TARGET_BIN"; then | ||||
|     echo "[-] Error: binary '$TARGET_BIN' doesn't appear to be instrumented." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -d "$IN_DIR" ]; then | ||||
|   echo "[-] Error: directory '$IN_DIR' not found." 1>&2 | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| test -d "$IN_DIR/queue" && IN_DIR="$IN_DIR/queue" | ||||
| 
 | ||||
| find "$OUT_DIR" -name 'id[:_]*' -maxdepth 1 -exec rm -- {} \; 2>/dev/null | ||||
| rm -rf "$TRACE_DIR" 2>/dev/null | ||||
| 
 | ||||
| rmdir "$OUT_DIR" 2>/dev/null | ||||
| 
 | ||||
| if [ -d "$OUT_DIR" ]; then | ||||
|   echo "[-] Error: directory '$OUT_DIR' exists and is not empty - delete it first." 1>&2 | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| mkdir -m 700 -p "$TRACE_DIR" || exit 1 | ||||
| 
 | ||||
| if [ ! "$STDIN_FILE" = "" ]; then | ||||
|   rm -f "$STDIN_FILE" || exit 1 | ||||
|   touch "$STDIN_FILE" || exit 1 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_PATH" = "" ]; then | ||||
|   SHOWMAP="${0%/afl-cmin}/afl-showmap" | ||||
| else | ||||
|   SHOWMAP="$AFL_PATH/afl-showmap" | ||||
| fi | ||||
| 
 | ||||
| if [ ! -x "$SHOWMAP" ]; then | ||||
|   echo "[-] Error: can't find 'afl-showmap' - please set AFL_PATH." 1>&2 | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| IN_COUNT=$((`ls -- "$IN_DIR" 2>/dev/null | wc -l`)) | ||||
| 
 | ||||
| if [ "$IN_COUNT" = "0" ]; then | ||||
|   echo "[+] Hmm, no inputs in the target directory. Nothing to be done." | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| FIRST_FILE=`ls "$IN_DIR" | head -1` | ||||
| 
 | ||||
| # Make sure that we're not dealing with a directory. | ||||
| 
 | ||||
| if [ -d "$IN_DIR/$FIRST_FILE" ]; then | ||||
|   echo "[-] Error: The target directory contains subdirectories - please fix." 1>&2 | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Check for the more efficient way to copy files... | ||||
| 
 | ||||
| if ln "$IN_DIR/$FIRST_FILE" "$TRACE_DIR/.link_test" 2>/dev/null; then | ||||
|   CP_TOOL=ln | ||||
| else | ||||
|   CP_TOOL=cp | ||||
| fi | ||||
| 
 | ||||
| # Make sure that we can actually get anything out of afl-showmap before we | ||||
| # waste too much time. | ||||
| 
 | ||||
| echo "[*] Testing the target binary..." | ||||
| 
 | ||||
| if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|   AFL_CMIN_ALLOW_ANY=1 "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/.run_test" -Z $EXTRA_PAR -- "$@" <"$IN_DIR/$FIRST_FILE" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   cp "$IN_DIR/$FIRST_FILE" "$STDIN_FILE" | ||||
|   AFL_CMIN_ALLOW_ANY=1 "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/.run_test" -Z $EXTRA_PAR -A "$STDIN_FILE" -- "$@" </dev/null | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| FIRST_COUNT=$((`grep -c . "$TRACE_DIR/.run_test"`)) | ||||
| 
 | ||||
| if [ "$FIRST_COUNT" -gt "0" ]; then | ||||
| 
 | ||||
|   echo "[+] OK, $FIRST_COUNT tuples recorded." | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   echo "[-] Error: no instrumentation output detected (perhaps crash or timeout)." 1>&2 | ||||
|   test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # Let's roll! | ||||
| 
 | ||||
| ############################# | ||||
| # STEP 1: COLLECTING TRACES # | ||||
| ############################# | ||||
| 
 | ||||
| echo "[*] Obtaining traces for input files in '$IN_DIR'..." | ||||
| 
 | ||||
| ( | ||||
| 
 | ||||
|   CUR=0 | ||||
| 
 | ||||
|   if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|     while read -r fn; do | ||||
| 
 | ||||
|       CUR=$((CUR+1)) | ||||
|       printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|       "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/$fn" -Z $EXTRA_PAR -- "$@" <"$IN_DIR/$fn" | ||||
| 
 | ||||
|     done < <(ls "$IN_DIR") | ||||
| 
 | ||||
|   else | ||||
| 
 | ||||
|     while read -r fn; do | ||||
| 
 | ||||
|       CUR=$((CUR+1)) | ||||
|       printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|       cp "$IN_DIR/$fn" "$STDIN_FILE" | ||||
| 
 | ||||
|       "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/$fn" -Z $EXTRA_PAR -A "$STDIN_FILE" -- "$@" </dev/null | ||||
| 
 | ||||
|     done < <(ls "$IN_DIR") | ||||
| 
 | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| ) | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| ########################## | ||||
| # STEP 2: SORTING TUPLES # | ||||
| ########################## | ||||
| 
 | ||||
| # With this out of the way, we sort all tuples by popularity across all | ||||
| # datasets. The reasoning here is that we won't be able to avoid the files | ||||
| # that trigger unique tuples anyway, so we will want to start with them and | ||||
| # see what's left. | ||||
| 
 | ||||
| echo "[*] Sorting trace sets (this may take a while)..." | ||||
| 
 | ||||
| ls "$IN_DIR" | sed "s#^#$TRACE_DIR/#" | tr '\n' '\0' | xargs -0 -n 1 cat | \ | ||||
|   sort | uniq -c | sort -n >"$TRACE_DIR/.all_uniq" | ||||
| 
 | ||||
| TUPLE_COUNT=$((`grep -c . "$TRACE_DIR/.all_uniq"`)) | ||||
| 
 | ||||
| echo "[+] Found $TUPLE_COUNT unique tuples across $IN_COUNT files." | ||||
| 
 | ||||
| ##################################### | ||||
| # STEP 3: SELECTING CANDIDATE FILES # | ||||
| ##################################### | ||||
| 
 | ||||
| # The next step is to find the best candidate for each tuple. The "best" | ||||
| # part is understood simply as the smallest input that includes a particular | ||||
| # tuple in its trace. Empirical evidence suggests that this produces smaller | ||||
| # datasets than more involved algorithms that could be still pulled off in | ||||
| # a shell script. | ||||
| 
 | ||||
| echo "[*] Finding best candidates for each tuple..." | ||||
| 
 | ||||
| CUR=0 | ||||
| 
 | ||||
| while read -r fn; do | ||||
| 
 | ||||
|   CUR=$((CUR+1)) | ||||
|   printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|   sed "s#\$# $fn#" "$TRACE_DIR/$fn" >>"$TRACE_DIR/.candidate_list" | ||||
| 
 | ||||
| done < <(ls -rS "$IN_DIR") | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| ############################## | ||||
| # STEP 4: LOADING CANDIDATES # | ||||
| ############################## | ||||
| 
 | ||||
| # At this point, we have a file of tuple-file pairs, sorted by file size | ||||
| # in ascending order (as a consequence of ls -rS). By doing sort keyed | ||||
| # only by tuple (-k 1,1) and configured to output only the first line for | ||||
| # every key (-s -u), we end up with the smallest file for each tuple. | ||||
| 
 | ||||
| echo "[*] Sorting candidate list (be patient)..." | ||||
| 
 | ||||
| sort -k1,1 -s -u "$TRACE_DIR/.candidate_list" | \ | ||||
|   sed 's/^/BEST_FILE[/;s/ /]="/;s/$/"/' >"$TRACE_DIR/.candidate_script" | ||||
| 
 | ||||
| if [ ! -s "$TRACE_DIR/.candidate_script" ]; then | ||||
|   echo "[-] Error: no traces obtained from test cases, check syntax!" 1>&2 | ||||
|   test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # The sed command converted the sorted list to a shell script that populates | ||||
| # BEST_FILE[tuple]="fname". Let's load that! | ||||
| 
 | ||||
| . "$TRACE_DIR/.candidate_script" | ||||
| 
 | ||||
| ########################## | ||||
| # STEP 5: WRITING OUTPUT # | ||||
| ########################## | ||||
| 
 | ||||
| # The final trick is to grab the top pick for each tuple, unless said tuple is | ||||
| # already set due to the inclusion of an earlier candidate; and then put all | ||||
| # tuples associated with the newly-added file to the "already have" list. The | ||||
| # loop works from least popular tuples and toward the most common ones. | ||||
| 
 | ||||
| echo "[*] Processing candidates and writing output files..." | ||||
| 
 | ||||
| CUR=0 | ||||
| 
 | ||||
| touch "$TRACE_DIR/.already_have" | ||||
| 
 | ||||
| while read -r cnt tuple; do | ||||
| 
 | ||||
|   CUR=$((CUR+1)) | ||||
|   printf "\\r    Processing tuple $CUR/$TUPLE_COUNT... " | ||||
| 
 | ||||
|   # If we already have this tuple, skip it. | ||||
| 
 | ||||
|   grep -q "^$tuple\$" "$TRACE_DIR/.already_have" && continue | ||||
| 
 | ||||
|   FN=${BEST_FILE[tuple]} | ||||
| 
 | ||||
|   $CP_TOOL "$IN_DIR/$FN" "$OUT_DIR/$FN" | ||||
| 
 | ||||
|   if [ "$((CUR % 5))" = "0" ]; then | ||||
|     sort -u "$TRACE_DIR/$FN" "$TRACE_DIR/.already_have" >"$TRACE_DIR/.tmp" | ||||
|     mv -f "$TRACE_DIR/.tmp" "$TRACE_DIR/.already_have" | ||||
|   else | ||||
|     cat "$TRACE_DIR/$FN" >>"$TRACE_DIR/.already_have" | ||||
|   fi | ||||
| 
 | ||||
| done <"$TRACE_DIR/.all_uniq" | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| OUT_COUNT=`ls -- "$OUT_DIR" | wc -l` | ||||
| 
 | ||||
| if [ "$OUT_COUNT" = "1" ]; then | ||||
|   echo "[!] WARNING: All test cases had the same traces, check syntax!" | ||||
| fi | ||||
| 
 | ||||
| echo "[+] Narrowed down to $OUT_COUNT files, saved in '$OUT_DIR'." | ||||
| echo | ||||
| 
 | ||||
| test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
| 
 | ||||
| exit 0 | ||||
| #!/usr/bin/env bash | ||||
| # | ||||
| # american fuzzy lop - corpus minimization tool | ||||
| # --------------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # | ||||
| # Copyright 2014, 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # This tool tries to find the smallest subset of files in the input directory | ||||
| # that still trigger the full range of instrumentation data points seen in | ||||
| # the starting corpus. This has two uses: | ||||
| # | ||||
| #   - Screening large corpora of input files before using them as a seed for | ||||
| #     afl-fuzz. The tool will remove functionally redundant files and likely | ||||
| #     leave you with a much smaller set. | ||||
| # | ||||
| #     (In this case, you probably also want to consider running afl-tmin on | ||||
| #     the individual files later on to reduce their size.) | ||||
| # | ||||
| #   - Minimizing the corpus generated organically by afl-fuzz, perhaps when | ||||
| #     planning to feed it to more resource-intensive tools. The tool achieves | ||||
| #     this by removing all entries that used to trigger unique behaviors in the | ||||
| #     past, but have been made obsolete by later finds. | ||||
| # | ||||
| # Note that the tool doesn't modify the files themselves. For that, you want | ||||
| # afl-tmin. | ||||
| # | ||||
| # This script must use bash because other shells may have hardcoded limits on | ||||
| # array sizes. | ||||
| # | ||||
| 
 | ||||
| echo "corpus minimization tool for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| ######### | ||||
| # SETUP # | ||||
| ######### | ||||
| 
 | ||||
| # Process command-line options... | ||||
| 
 | ||||
| MEM_LIMIT=100 | ||||
| TIMEOUT=none | ||||
| 
 | ||||
| unset IN_DIR OUT_DIR STDIN_FILE EXTRA_PAR MEM_LIMIT_GIVEN \ | ||||
|   AFL_CMIN_CRASHES_ONLY AFL_CMIN_ALLOW_ANY QEMU_MODE | ||||
| 
 | ||||
| while getopts "+i:o:f:m:t:eQC" opt; do | ||||
| 
 | ||||
|   case "$opt" in  | ||||
| 
 | ||||
|     "i") | ||||
|          IN_DIR="$OPTARG" | ||||
|          ;; | ||||
| 
 | ||||
|     "o") | ||||
|          OUT_DIR="$OPTARG" | ||||
|          ;; | ||||
|     "f") | ||||
|          STDIN_FILE="$OPTARG" | ||||
|          ;; | ||||
|     "m") | ||||
|          MEM_LIMIT="$OPTARG" | ||||
|          MEM_LIMIT_GIVEN=1 | ||||
|          ;; | ||||
|     "t") | ||||
|          TIMEOUT="$OPTARG" | ||||
|          ;; | ||||
|     "e") | ||||
|          EXTRA_PAR="$EXTRA_PAR -e" | ||||
|          ;; | ||||
|     "C") | ||||
|          export AFL_CMIN_CRASHES_ONLY=1 | ||||
|          ;; | ||||
|     "Q") | ||||
|          EXTRA_PAR="$EXTRA_PAR -Q" | ||||
|          test "$MEM_LIMIT_GIVEN" = "" && MEM_LIMIT=250 | ||||
|          QEMU_MODE=1 | ||||
|          ;; | ||||
|     "?") | ||||
|          exit 1 | ||||
|          ;; | ||||
| 
 | ||||
|    esac | ||||
| 
 | ||||
| done | ||||
| 
 | ||||
| shift $((OPTIND-1)) | ||||
| 
 | ||||
| TARGET_BIN="$1" | ||||
| 
 | ||||
| if [ "$TARGET_BIN" = "" -o "$IN_DIR" = "" -o "$OUT_DIR" = "" ]; then | ||||
| 
 | ||||
|   cat 1>&2 <<_EOF_ | ||||
| Usage: $0 [ options ] -- /path/to/target_app [ ... ] | ||||
| 
 | ||||
| Required parameters: | ||||
| 
 | ||||
|   -i dir        - input directory with the starting corpus | ||||
|   -o dir        - output directory for minimized files | ||||
| 
 | ||||
| Execution control settings: | ||||
| 
 | ||||
|   -f file       - location read by the fuzzed program (stdin) | ||||
|   -m megs       - memory limit for child process ($MEM_LIMIT MB) | ||||
|   -t msec       - run time limit for child process (none) | ||||
|   -Q            - use binary-only instrumentation (QEMU mode) | ||||
| 
 | ||||
| Minimization settings: | ||||
| 
 | ||||
|   -C            - keep crashing inputs, reject everything else | ||||
|   -e            - solve for edge coverage only, ignore hit counts | ||||
| 
 | ||||
| For additional tips, please consult docs/README. | ||||
| 
 | ||||
| _EOF_ | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Do a sanity check to discourage the use of /tmp, since we can't really | ||||
| # handle this safely from a shell script. | ||||
| 
 | ||||
| if [ "$AFL_ALLOW_TMP" = "" ]; then | ||||
| 
 | ||||
|   echo "$IN_DIR" | grep -qE '^(/var)?/tmp/' | ||||
|   T1="$?" | ||||
| 
 | ||||
|   echo "$TARGET_BIN" | grep -qE '^(/var)?/tmp/' | ||||
|   T2="$?" | ||||
| 
 | ||||
|   echo "$OUT_DIR" | grep -qE '^(/var)?/tmp/' | ||||
|   T3="$?" | ||||
| 
 | ||||
|   echo "$STDIN_FILE" | grep -qE '^(/var)?/tmp/' | ||||
|   T4="$?" | ||||
| 
 | ||||
|   echo "$PWD" | grep -qE '^(/var)?/tmp/' | ||||
|   T5="$?" | ||||
| 
 | ||||
|   if [ "$T1" = "0" -o "$T2" = "0" -o "$T3" = "0" -o "$T4" = "0" -o "$T5" = "0" ]; then | ||||
|     echo "[-] Error: do not use this script in /tmp or /var/tmp." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # If @@ is specified, but there's no -f, let's come up with a temporary input | ||||
| # file name. | ||||
| 
 | ||||
| TRACE_DIR="$OUT_DIR/.traces" | ||||
| 
 | ||||
| if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|   if echo "$*" | grep -qF '@@'; then | ||||
|     STDIN_FILE="$TRACE_DIR/.cur_input" | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # Check for obvious errors. | ||||
| 
 | ||||
| if [ ! "$MEM_LIMIT" = "none" ]; then | ||||
| 
 | ||||
|   if [ "$MEM_LIMIT" -lt "5" ]; then | ||||
|     echo "[-] Error: dangerously low memory limit." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! "$TIMEOUT" = "none" ]; then | ||||
| 
 | ||||
|   if [ "$TIMEOUT" -lt "10" ]; then | ||||
|     echo "[-] Error: dangerously low timeout." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -f "$TARGET_BIN" -o ! -x "$TARGET_BIN" ]; then | ||||
| 
 | ||||
|   TNEW="`which "$TARGET_BIN" 2>/dev/null`" | ||||
| 
 | ||||
|   if [ ! -f "$TNEW" -o ! -x "$TNEW" ]; then | ||||
|     echo "[-] Error: binary '$TARGET_BIN' not found or not executable." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
|   TARGET_BIN="$TNEW" | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_SKIP_BIN_CHECK" = "" -a "$QEMU_MODE" = "" ]; then | ||||
| 
 | ||||
|   if ! grep -qF "__AFL_SHM_ID" "$TARGET_BIN"; then | ||||
|     echo "[-] Error: binary '$TARGET_BIN' doesn't appear to be instrumented." 1>&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -d "$IN_DIR" ]; then | ||||
|   echo "[-] Error: directory '$IN_DIR' not found." 1>&2 | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| test -d "$IN_DIR/queue" && IN_DIR="$IN_DIR/queue" | ||||
| 
 | ||||
| find "$OUT_DIR" -name 'id[:_]*' -maxdepth 1 -exec rm -- {} \; 2>/dev/null | ||||
| rm -rf "$TRACE_DIR" 2>/dev/null | ||||
| 
 | ||||
| rmdir "$OUT_DIR" 2>/dev/null | ||||
| 
 | ||||
| if [ -d "$OUT_DIR" ]; then | ||||
|   echo "[-] Error: directory '$OUT_DIR' exists and is not empty - delete it first." 1>&2 | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| mkdir -m 700 -p "$TRACE_DIR" || exit 1 | ||||
| 
 | ||||
| if [ ! "$STDIN_FILE" = "" ]; then | ||||
|   rm -f "$STDIN_FILE" || exit 1 | ||||
|   touch "$STDIN_FILE" || exit 1 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_PATH" = "" ]; then | ||||
|   SHOWMAP="${0%/afl-cmin}/afl-showmap" | ||||
| else | ||||
|   SHOWMAP="$AFL_PATH/afl-showmap" | ||||
| fi | ||||
| 
 | ||||
| if [ ! -x "$SHOWMAP" ]; then | ||||
|   echo "[-] Error: can't find 'afl-showmap' - please set AFL_PATH." 1>&2 | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| IN_COUNT=$((`ls -- "$IN_DIR" 2>/dev/null | wc -l`)) | ||||
| 
 | ||||
| if [ "$IN_COUNT" = "0" ]; then | ||||
|   echo "[+] Hmm, no inputs in the target directory. Nothing to be done." | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| FIRST_FILE=`ls "$IN_DIR" | head -1` | ||||
| 
 | ||||
| # Make sure that we're not dealing with a directory. | ||||
| 
 | ||||
| if [ -d "$IN_DIR/$FIRST_FILE" ]; then | ||||
|   echo "[-] Error: The target directory contains subdirectories - please fix." 1>&2 | ||||
|   rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Check for the more efficient way to copy files... | ||||
| 
 | ||||
| if ln "$IN_DIR/$FIRST_FILE" "$TRACE_DIR/.link_test" 2>/dev/null; then | ||||
|   CP_TOOL=ln | ||||
| else | ||||
|   CP_TOOL=cp | ||||
| fi | ||||
| 
 | ||||
| # Make sure that we can actually get anything out of afl-showmap before we | ||||
| # waste too much time. | ||||
| 
 | ||||
| echo "[*] Testing the target binary..." | ||||
| 
 | ||||
| if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|   AFL_CMIN_ALLOW_ANY=1 "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/.run_test" -Z $EXTRA_PAR -- "$@" <"$IN_DIR/$FIRST_FILE" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   cp "$IN_DIR/$FIRST_FILE" "$STDIN_FILE" | ||||
|   AFL_CMIN_ALLOW_ANY=1 "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/.run_test" -Z $EXTRA_PAR -A "$STDIN_FILE" -- "$@" </dev/null | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| FIRST_COUNT=$((`grep -c . "$TRACE_DIR/.run_test"`)) | ||||
| 
 | ||||
| if [ "$FIRST_COUNT" -gt "0" ]; then | ||||
| 
 | ||||
|   echo "[+] OK, $FIRST_COUNT tuples recorded." | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   echo "[-] Error: no instrumentation output detected (perhaps crash or timeout)." 1>&2 | ||||
|   test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| # Let's roll! | ||||
| 
 | ||||
| ############################# | ||||
| # STEP 1: COLLECTING TRACES # | ||||
| ############################# | ||||
| 
 | ||||
| echo "[*] Obtaining traces for input files in '$IN_DIR'..." | ||||
| 
 | ||||
| ( | ||||
| 
 | ||||
|   CUR=0 | ||||
| 
 | ||||
|   if [ "$STDIN_FILE" = "" ]; then | ||||
| 
 | ||||
|     while read -r fn; do | ||||
| 
 | ||||
|       CUR=$((CUR+1)) | ||||
|       printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|       "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/$fn" -Z $EXTRA_PAR -- "$@" <"$IN_DIR/$fn" | ||||
| 
 | ||||
|     done < <(ls "$IN_DIR") | ||||
| 
 | ||||
|   else | ||||
| 
 | ||||
|     while read -r fn; do | ||||
| 
 | ||||
|       CUR=$((CUR+1)) | ||||
|       printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|       cp "$IN_DIR/$fn" "$STDIN_FILE" | ||||
| 
 | ||||
|       "$SHOWMAP" -m "$MEM_LIMIT" -t "$TIMEOUT" -o "$TRACE_DIR/$fn" -Z $EXTRA_PAR -A "$STDIN_FILE" -- "$@" </dev/null | ||||
| 
 | ||||
|     done < <(ls "$IN_DIR") | ||||
| 
 | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| ) | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| ########################## | ||||
| # STEP 2: SORTING TUPLES # | ||||
| ########################## | ||||
| 
 | ||||
| # With this out of the way, we sort all tuples by popularity across all | ||||
| # datasets. The reasoning here is that we won't be able to avoid the files | ||||
| # that trigger unique tuples anyway, so we will want to start with them and | ||||
| # see what's left. | ||||
| 
 | ||||
| echo "[*] Sorting trace sets (this may take a while)..." | ||||
| 
 | ||||
| ls "$IN_DIR" | sed "s#^#$TRACE_DIR/#" | tr '\n' '\0' | xargs -0 -n 1 cat | \ | ||||
|   sort | uniq -c | sort -n >"$TRACE_DIR/.all_uniq" | ||||
| 
 | ||||
| TUPLE_COUNT=$((`grep -c . "$TRACE_DIR/.all_uniq"`)) | ||||
| 
 | ||||
| echo "[+] Found $TUPLE_COUNT unique tuples across $IN_COUNT files." | ||||
| 
 | ||||
| ##################################### | ||||
| # STEP 3: SELECTING CANDIDATE FILES # | ||||
| ##################################### | ||||
| 
 | ||||
| # The next step is to find the best candidate for each tuple. The "best" | ||||
| # part is understood simply as the smallest input that includes a particular | ||||
| # tuple in its trace. Empirical evidence suggests that this produces smaller | ||||
| # datasets than more involved algorithms that could be still pulled off in | ||||
| # a shell script. | ||||
| 
 | ||||
| echo "[*] Finding best candidates for each tuple..." | ||||
| 
 | ||||
| CUR=0 | ||||
| 
 | ||||
| while read -r fn; do | ||||
| 
 | ||||
|   CUR=$((CUR+1)) | ||||
|   printf "\\r    Processing file $CUR/$IN_COUNT... " | ||||
| 
 | ||||
|   sed "s#\$# $fn#" "$TRACE_DIR/$fn" >>"$TRACE_DIR/.candidate_list" | ||||
| 
 | ||||
| done < <(ls -rS "$IN_DIR") | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| ############################## | ||||
| # STEP 4: LOADING CANDIDATES # | ||||
| ############################## | ||||
| 
 | ||||
| # At this point, we have a file of tuple-file pairs, sorted by file size | ||||
| # in ascending order (as a consequence of ls -rS). By doing sort keyed | ||||
| # only by tuple (-k 1,1) and configured to output only the first line for | ||||
| # every key (-s -u), we end up with the smallest file for each tuple. | ||||
| 
 | ||||
| echo "[*] Sorting candidate list (be patient)..." | ||||
| 
 | ||||
| sort -k1,1 -s -u "$TRACE_DIR/.candidate_list" | \ | ||||
|   sed 's/^/BEST_FILE[/;s/ /]="/;s/$/"/' >"$TRACE_DIR/.candidate_script" | ||||
| 
 | ||||
| if [ ! -s "$TRACE_DIR/.candidate_script" ]; then | ||||
|   echo "[-] Error: no traces obtained from test cases, check syntax!" 1>&2 | ||||
|   test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
|   exit 1 | ||||
| fi | ||||
| 
 | ||||
| # The sed command converted the sorted list to a shell script that populates | ||||
| # BEST_FILE[tuple]="fname". Let's load that! | ||||
| 
 | ||||
| . "$TRACE_DIR/.candidate_script" | ||||
| 
 | ||||
| ########################## | ||||
| # STEP 5: WRITING OUTPUT # | ||||
| ########################## | ||||
| 
 | ||||
| # The final trick is to grab the top pick for each tuple, unless said tuple is | ||||
| # already set due to the inclusion of an earlier candidate; and then put all | ||||
| # tuples associated with the newly-added file to the "already have" list. The | ||||
| # loop works from least popular tuples and toward the most common ones. | ||||
| 
 | ||||
| echo "[*] Processing candidates and writing output files..." | ||||
| 
 | ||||
| CUR=0 | ||||
| 
 | ||||
| touch "$TRACE_DIR/.already_have" | ||||
| 
 | ||||
| while read -r cnt tuple; do | ||||
| 
 | ||||
|   CUR=$((CUR+1)) | ||||
|   printf "\\r    Processing tuple $CUR/$TUPLE_COUNT... " | ||||
| 
 | ||||
|   # If we already have this tuple, skip it. | ||||
| 
 | ||||
|   grep -q "^$tuple\$" "$TRACE_DIR/.already_have" && continue | ||||
| 
 | ||||
|   FN=${BEST_FILE[tuple]} | ||||
| 
 | ||||
|   $CP_TOOL "$IN_DIR/$FN" "$OUT_DIR/$FN" | ||||
| 
 | ||||
|   if [ "$((CUR % 5))" = "0" ]; then | ||||
|     sort -u "$TRACE_DIR/$FN" "$TRACE_DIR/.already_have" >"$TRACE_DIR/.tmp" | ||||
|     mv -f "$TRACE_DIR/.tmp" "$TRACE_DIR/.already_have" | ||||
|   else | ||||
|     cat "$TRACE_DIR/$FN" >>"$TRACE_DIR/.already_have" | ||||
|   fi | ||||
| 
 | ||||
| done <"$TRACE_DIR/.all_uniq" | ||||
| 
 | ||||
| echo | ||||
| 
 | ||||
| OUT_COUNT=`ls -- "$OUT_DIR" | wc -l` | ||||
| 
 | ||||
| if [ "$OUT_COUNT" = "1" ]; then | ||||
|   echo "[!] WARNING: All test cases had the same traces, check syntax!" | ||||
| fi | ||||
| 
 | ||||
| echo "[+] Narrowed down to $OUT_COUNT files, saved in '$OUT_DIR'." | ||||
| echo | ||||
| 
 | ||||
| test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR" | ||||
| 
 | ||||
| exit 0 | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,170 +1,170 @@ | ||||
| #!/bin/sh | ||||
| # | ||||
| # american fuzzy lop - Advanced Persistent Graphing | ||||
| # ------------------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # Based on a design & prototype by Michael Rash. | ||||
| # | ||||
| # Copyright 2014, 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| 
 | ||||
| echo "progress plotting utility for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| if [ ! "$#" = "2" ]; then | ||||
| 
 | ||||
|   cat 1>&2 <<_EOF_ | ||||
| This program generates gnuplot images from afl-fuzz output data. Usage: | ||||
| 
 | ||||
| $0 afl_state_dir graph_output_dir | ||||
| 
 | ||||
| The afl_state_dir parameter should point to an existing state directory for any | ||||
| active or stopped instance of afl-fuzz; while graph_output_dir should point to | ||||
| an empty directory where this tool can write the resulting plots to. | ||||
| 
 | ||||
| The program will put index.html and three PNG images in the output directory; | ||||
| you should be able to view it with any web browser of your choice. | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_ALLOW_TMP" = "" ]; then | ||||
| 
 | ||||
|   echo "$1" | grep -qE '^(/var)?/tmp/' | ||||
|   T1="$?" | ||||
| 
 | ||||
|   echo "$2" | grep -qE '^(/var)?/tmp/' | ||||
|   T2="$?" | ||||
| 
 | ||||
|   if [ "$T1" = "0" -o "$T2" = "0" ]; then | ||||
| 
 | ||||
|     echo "[-] Error: this script shouldn't be used with shared /tmp directories." 1>&2 | ||||
|     exit 1 | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -f "$1/plot_data" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: input directory is not valid (missing 'plot_data')." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| BANNER="`cat "$1/fuzzer_stats" | grep '^afl_banner ' | cut -d: -f2- | cut -b2-`" | ||||
| 
 | ||||
| test "$BANNER" = "" && BANNER="(none)" | ||||
| 
 | ||||
| GNUPLOT=`which gnuplot 2>/dev/null` | ||||
| 
 | ||||
| if [ "$GNUPLOT" = "" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: can't find 'gnuplot' in your \$PATH." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| mkdir "$2" 2>/dev/null | ||||
| 
 | ||||
| if [ ! -d "$2" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: unable to create the output directory - pick another location." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| rm -f "$2/high_freq.png" "$2/low_freq.png" "$2/exec_speed.png" | ||||
| mv -f "$2/index.html" "$2/index.html.orig" 2>/dev/null | ||||
| 
 | ||||
| echo "[*] Generating plots..." | ||||
| 
 | ||||
| ( | ||||
| 
 | ||||
| cat <<_EOF_ | ||||
| set terminal png truecolor enhanced size 1000,300 butt | ||||
| 
 | ||||
| set output '$2/high_freq.png' | ||||
| 
 | ||||
| set xdata time | ||||
| set timefmt '%s' | ||||
| set format x "%b %d\n%H:%M" | ||||
| set tics font 'small' | ||||
| unset mxtics | ||||
| unset mytics | ||||
| 
 | ||||
| set grid xtics linetype 0 linecolor rgb '#e0e0e0' | ||||
| set grid ytics linetype 0 linecolor rgb '#e0e0e0' | ||||
| set border linecolor rgb '#50c0f0' | ||||
| set tics textcolor rgb '#000000' | ||||
| set key outside | ||||
| 
 | ||||
| set autoscale xfixmin | ||||
| set autoscale xfixmax | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:4 with filledcurve x1 title 'total paths' linecolor rgb '#000000' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '' using 1:3 with filledcurve x1 title 'current path' linecolor rgb '#f0f0f0' fillstyle transparent solid 0.5 noborder, \\ | ||||
|      '' using 1:5 with lines title 'pending paths' linecolor rgb '#0090ff' linewidth 3, \\ | ||||
|      '' using 1:6 with lines title 'pending favs' linecolor rgb '#c00080' linewidth 3, \\ | ||||
|      '' using 1:2 with lines title 'cycles done' linecolor rgb '#c000f0' linewidth 3 | ||||
| 
 | ||||
| set terminal png truecolor enhanced size 1000,200 butt | ||||
| set output '$2/low_freq.png' | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:8 with filledcurve x1 title '' linecolor rgb '#c00080' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '' using 1:8 with lines title ' uniq crashes' linecolor rgb '#c00080' linewidth 3, \\ | ||||
|      '' using 1:9 with lines title 'uniq hangs' linecolor rgb '#c000f0' linewidth 3, \\ | ||||
|      '' using 1:10 with lines title 'levels' linecolor rgb '#0090ff' linewidth 3 | ||||
| 
 | ||||
| set terminal png truecolor enhanced size 1000,200 butt | ||||
| set output '$2/exec_speed.png' | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:11 with filledcurve x1 title '' linecolor rgb '#0090ff' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '$1/plot_data' using 1:11 with lines title '    execs/sec' linecolor rgb '#0090ff' linewidth 3 smooth bezier; | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
| ) | gnuplot  | ||||
| 
 | ||||
| if [ ! -s "$2/exec_speed.png" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: something went wrong! Perhaps you have an ancient version of gnuplot?" 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| echo "[*] Generating index.html..." | ||||
| 
 | ||||
| cat >"$2/index.html" <<_EOF_ | ||||
| <table style="font-family: 'Trebuchet MS', 'Tahoma', 'Arial', 'Helvetica'"> | ||||
| <tr><td style="width: 18ex"><b>Banner:</b></td><td>$BANNER</td></tr> | ||||
| <tr><td><b>Directory:</b></td><td>$1</td></tr> | ||||
| <tr><td><b>Generated on:</b></td><td>`date`</td></tr> | ||||
| </table> | ||||
| <p> | ||||
| <img src="high_freq.png" width=1000 height=300><p> | ||||
| <img src="low_freq.png" width=1000 height=200><p> | ||||
| <img src="exec_speed.png" width=1000 height=200> | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
| # Make it easy to remotely view results when outputting directly to a directory | ||||
| # served by Apache or other HTTP daemon. Since the plots aren't horribly | ||||
| # sensitive, this seems like a reasonable trade-off. | ||||
| 
 | ||||
| chmod 755 "$2" | ||||
| chmod 644 "$2/high_freq.png" "$2/low_freq.png" "$2/exec_speed.png" "$2/index.html" | ||||
| 
 | ||||
| echo "[+] All done - enjoy your charts!" | ||||
| 
 | ||||
| exit 0 | ||||
| #!/bin/sh | ||||
| # | ||||
| # american fuzzy lop - Advanced Persistent Graphing | ||||
| # ------------------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # Based on a design & prototype by Michael Rash. | ||||
| # | ||||
| # Copyright 2014, 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| 
 | ||||
| echo "progress plotting utility for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| if [ ! "$#" = "2" ]; then | ||||
| 
 | ||||
|   cat 1>&2 <<_EOF_ | ||||
| This program generates gnuplot images from afl-fuzz output data. Usage: | ||||
| 
 | ||||
| $0 afl_state_dir graph_output_dir | ||||
| 
 | ||||
| The afl_state_dir parameter should point to an existing state directory for any | ||||
| active or stopped instance of afl-fuzz; while graph_output_dir should point to | ||||
| an empty directory where this tool can write the resulting plots to. | ||||
| 
 | ||||
| The program will put index.html and three PNG images in the output directory; | ||||
| you should be able to view it with any web browser of your choice. | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$AFL_ALLOW_TMP" = "" ]; then | ||||
| 
 | ||||
|   echo "$1" | grep -qE '^(/var)?/tmp/' | ||||
|   T1="$?" | ||||
| 
 | ||||
|   echo "$2" | grep -qE '^(/var)?/tmp/' | ||||
|   T2="$?" | ||||
| 
 | ||||
|   if [ "$T1" = "0" -o "$T2" = "0" ]; then | ||||
| 
 | ||||
|     echo "[-] Error: this script shouldn't be used with shared /tmp directories." 1>&2 | ||||
|     exit 1 | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ ! -f "$1/plot_data" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: input directory is not valid (missing 'plot_data')." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| BANNER="`cat "$1/fuzzer_stats" | grep '^afl_banner ' | cut -d: -f2- | cut -b2-`" | ||||
| 
 | ||||
| test "$BANNER" = "" && BANNER="(none)" | ||||
| 
 | ||||
| GNUPLOT=`which gnuplot 2>/dev/null` | ||||
| 
 | ||||
| if [ "$GNUPLOT" = "" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: can't find 'gnuplot' in your \$PATH." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| mkdir "$2" 2>/dev/null | ||||
| 
 | ||||
| if [ ! -d "$2" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: unable to create the output directory - pick another location." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| rm -f "$2/high_freq.png" "$2/low_freq.png" "$2/exec_speed.png" | ||||
| mv -f "$2/index.html" "$2/index.html.orig" 2>/dev/null | ||||
| 
 | ||||
| echo "[*] Generating plots..." | ||||
| 
 | ||||
| ( | ||||
| 
 | ||||
| cat <<_EOF_ | ||||
| set terminal png truecolor enhanced size 1000,300 butt | ||||
| 
 | ||||
| set output '$2/high_freq.png' | ||||
| 
 | ||||
| set xdata time | ||||
| set timefmt '%s' | ||||
| set format x "%b %d\n%H:%M" | ||||
| set tics font 'small' | ||||
| unset mxtics | ||||
| unset mytics | ||||
| 
 | ||||
| set grid xtics linetype 0 linecolor rgb '#e0e0e0' | ||||
| set grid ytics linetype 0 linecolor rgb '#e0e0e0' | ||||
| set border linecolor rgb '#50c0f0' | ||||
| set tics textcolor rgb '#000000' | ||||
| set key outside | ||||
| 
 | ||||
| set autoscale xfixmin | ||||
| set autoscale xfixmax | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:4 with filledcurve x1 title 'total paths' linecolor rgb '#000000' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '' using 1:3 with filledcurve x1 title 'current path' linecolor rgb '#f0f0f0' fillstyle transparent solid 0.5 noborder, \\ | ||||
|      '' using 1:5 with lines title 'pending paths' linecolor rgb '#0090ff' linewidth 3, \\ | ||||
|      '' using 1:6 with lines title 'pending favs' linecolor rgb '#c00080' linewidth 3, \\ | ||||
|      '' using 1:2 with lines title 'cycles done' linecolor rgb '#c000f0' linewidth 3 | ||||
| 
 | ||||
| set terminal png truecolor enhanced size 1000,200 butt | ||||
| set output '$2/low_freq.png' | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:8 with filledcurve x1 title '' linecolor rgb '#c00080' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '' using 1:8 with lines title ' uniq crashes' linecolor rgb '#c00080' linewidth 3, \\ | ||||
|      '' using 1:9 with lines title 'uniq hangs' linecolor rgb '#c000f0' linewidth 3, \\ | ||||
|      '' using 1:10 with lines title 'levels' linecolor rgb '#0090ff' linewidth 3 | ||||
| 
 | ||||
| set terminal png truecolor enhanced size 1000,200 butt | ||||
| set output '$2/exec_speed.png' | ||||
| 
 | ||||
| plot '$1/plot_data' using 1:11 with filledcurve x1 title '' linecolor rgb '#0090ff' fillstyle transparent solid 0.2 noborder, \\ | ||||
|      '$1/plot_data' using 1:11 with lines title '    execs/sec' linecolor rgb '#0090ff' linewidth 3 smooth bezier; | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
| ) | gnuplot  | ||||
| 
 | ||||
| if [ ! -s "$2/exec_speed.png" ]; then | ||||
| 
 | ||||
|   echo "[-] Error: something went wrong! Perhaps you have an ancient version of gnuplot?" 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| echo "[*] Generating index.html..." | ||||
| 
 | ||||
| cat >"$2/index.html" <<_EOF_ | ||||
| <table style="font-family: 'Trebuchet MS', 'Tahoma', 'Arial', 'Helvetica'"> | ||||
| <tr><td style="width: 18ex"><b>Banner:</b></td><td>$BANNER</td></tr> | ||||
| <tr><td><b>Directory:</b></td><td>$1</td></tr> | ||||
| <tr><td><b>Generated on:</b></td><td>`date`</td></tr> | ||||
| </table> | ||||
| <p> | ||||
| <img src="high_freq.png" width=1000 height=300><p> | ||||
| <img src="low_freq.png" width=1000 height=200><p> | ||||
| <img src="exec_speed.png" width=1000 height=200> | ||||
| 
 | ||||
| _EOF_ | ||||
| 
 | ||||
| # Make it easy to remotely view results when outputting directly to a directory | ||||
| # served by Apache or other HTTP daemon. Since the plots aren't horribly | ||||
| # sensitive, this seems like a reasonable trade-off. | ||||
| 
 | ||||
| chmod 755 "$2" | ||||
| chmod 644 "$2/high_freq.png" "$2/low_freq.png" "$2/exec_speed.png" "$2/index.html" | ||||
| 
 | ||||
| echo "[+] All done - enjoy your charts!" | ||||
| 
 | ||||
| exit 0 | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,163 +1,163 @@ | ||||
| #!/bin/sh | ||||
| # | ||||
| # american fuzzy lop - status check tool | ||||
| # -------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # | ||||
| # Copyright 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # This tool summarizes the status of any locally-running synchronized | ||||
| # instances of afl-fuzz. | ||||
| # | ||||
| 
 | ||||
| echo "status check tool for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| if [ "$1" = "-s" ]; then | ||||
| 
 | ||||
|   SUMMARY_ONLY=1 | ||||
|   DIR="$2" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   unset SUMMARY_ONLY | ||||
|   DIR="$1" | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$DIR" = "" ]; then | ||||
| 
 | ||||
|   echo "Usage: $0 [ -s ] afl_sync_dir" 1>&2 | ||||
|   echo 1>&2 | ||||
|   echo "The -s option causes the tool to skip all the per-fuzzer trivia and show" 1>&2 | ||||
|   echo "just the summary results. See docs/parallel_fuzzing.txt for additional tips." 1>&2 | ||||
|   echo 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| cd "$DIR" || exit 1 | ||||
| 
 | ||||
| if [ -d queue ]; then | ||||
| 
 | ||||
|   echo "[-] Error: parameter is an individual output directory, not a sync dir." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| CUR_TIME=`date +%s` | ||||
| 
 | ||||
| TMP=`mktemp -t .afl-whatsup-XXXXXXXX` || TMP=`mktemp -p /data/local/tmp .afl-whatsup-XXXXXXXX` || exit 1 | ||||
| 
 | ||||
| ALIVE_CNT=0 | ||||
| DEAD_CNT=0 | ||||
| 
 | ||||
| TOTAL_TIME=0 | ||||
| TOTAL_EXECS=0 | ||||
| TOTAL_EPS=0 | ||||
| TOTAL_CRASHES=0 | ||||
| TOTAL_PFAV=0 | ||||
| TOTAL_PENDING=0 | ||||
| 
 | ||||
| if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|   echo "Individual fuzzers" | ||||
|   echo "==================" | ||||
|   echo | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| for i in `find . -maxdepth 2 -iname fuzzer_stats | sort`; do | ||||
| 
 | ||||
|   sed 's/^command_line.*$/_skip:1/;s/[ ]*:[ ]*/="/;s/$/"/' "$i" >"$TMP" | ||||
|   . "$TMP" | ||||
| 
 | ||||
|   RUN_UNIX=$((CUR_TIME - start_time)) | ||||
|   RUN_DAYS=$((RUN_UNIX / 60 / 60 / 24)) | ||||
|   RUN_HRS=$(((RUN_UNIX / 60 / 60) % 24)) | ||||
| 
 | ||||
|   if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|     echo ">>> $afl_banner ($RUN_DAYS days, $RUN_HRS hrs) <<<" | ||||
|     echo | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
|   if ! kill -0 "$fuzzer_pid" 2>/dev/null; then | ||||
| 
 | ||||
|     if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|       echo "  Instance is dead or running remotely, skipping." | ||||
|       echo | ||||
| 
 | ||||
|     fi | ||||
| 
 | ||||
|     DEAD_CNT=$((DEAD_CNT + 1)) | ||||
|     continue | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
|   ALIVE_CNT=$((ALIVE_CNT + 1)) | ||||
| 
 | ||||
|   EXEC_SEC=$((execs_done / RUN_UNIX)) | ||||
|   PATH_PERC=$((cur_path * 100 / paths_total)) | ||||
| 
 | ||||
|   TOTAL_TIME=$((TOTAL_TIME + RUN_UNIX)) | ||||
|   TOTAL_EPS=$((TOTAL_EPS + EXEC_SEC)) | ||||
|   TOTAL_EXECS=$((TOTAL_EXECS + execs_done)) | ||||
|   TOTAL_CRASHES=$((TOTAL_CRASHES + unique_crashes)) | ||||
|   TOTAL_PENDING=$((TOTAL_PENDING + pending_total)) | ||||
|   TOTAL_PFAV=$((TOTAL_PFAV + pending_favs)) | ||||
| 
 | ||||
|   if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|     echo "  cycle $((cycles_done + 1)), lifetime speed $EXEC_SEC execs/sec, path $cur_path/$paths_total (${PATH_PERC}%)" | ||||
| 
 | ||||
|     if [ "$unique_crashes" = "0" ]; then | ||||
|       echo "  pending $pending_favs/$pending_total, coverage $bitmap_cvg, no crashes yet" | ||||
|     else | ||||
|       echo "  pending $pending_favs/$pending_total, coverage $bitmap_cvg, crash count $unique_crashes (!)" | ||||
|     fi | ||||
| 
 | ||||
|     echo | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| done | ||||
| 
 | ||||
| rm -f "$TMP" | ||||
| 
 | ||||
| TOTAL_DAYS=$((TOTAL_TIME / 60 / 60 / 24)) | ||||
| TOTAL_HRS=$(((TOTAL_TIME / 60 / 60) % 24)) | ||||
| 
 | ||||
| test "$TOTAL_TIME" = "0" && TOTAL_TIME=1 | ||||
| 
 | ||||
| echo "Summary stats" | ||||
| echo "=============" | ||||
| echo | ||||
| echo "       Fuzzers alive : $ALIVE_CNT" | ||||
| 
 | ||||
| if [ ! "$DEAD_CNT" = "0" ]; then | ||||
|   echo "      Dead or remote : $DEAD_CNT (excluded from stats)" | ||||
| fi | ||||
| 
 | ||||
| echo "      Total run time : $TOTAL_DAYS days, $TOTAL_HRS hours" | ||||
| echo "         Total execs : $((TOTAL_EXECS / 1000 / 1000)) million" | ||||
| echo "    Cumulative speed : $TOTAL_EPS execs/sec" | ||||
| echo "       Pending paths : $TOTAL_PFAV faves, $TOTAL_PENDING total" | ||||
| 
 | ||||
| if [ "$ALIVE_CNT" -gt "1" ]; then | ||||
|   echo "  Pending per fuzzer : $((TOTAL_PFAV/ALIVE_CNT)) faves, $((TOTAL_PENDING/ALIVE_CNT)) total (on average)" | ||||
| fi | ||||
| 
 | ||||
| echo "       Crashes found : $TOTAL_CRASHES locally unique" | ||||
| echo | ||||
| 
 | ||||
| exit 0 | ||||
| #!/bin/sh | ||||
| # | ||||
| # american fuzzy lop - status check tool | ||||
| # -------------------------------------- | ||||
| # | ||||
| # Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| # | ||||
| # Copyright 2015 Google LLC All rights reserved. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at: | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # This tool summarizes the status of any locally-running synchronized | ||||
| # instances of afl-fuzz. | ||||
| # | ||||
| 
 | ||||
| echo "status check tool for afl-fuzz by <lcamtuf@google.com>" | ||||
| echo | ||||
| 
 | ||||
| if [ "$1" = "-s" ]; then | ||||
| 
 | ||||
|   SUMMARY_ONLY=1 | ||||
|   DIR="$2" | ||||
| 
 | ||||
| else | ||||
| 
 | ||||
|   unset SUMMARY_ONLY | ||||
|   DIR="$1" | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| if [ "$DIR" = "" ]; then | ||||
| 
 | ||||
|   echo "Usage: $0 [ -s ] afl_sync_dir" 1>&2 | ||||
|   echo 1>&2 | ||||
|   echo "The -s option causes the tool to skip all the per-fuzzer trivia and show" 1>&2 | ||||
|   echo "just the summary results. See docs/parallel_fuzzing.txt for additional tips." 1>&2 | ||||
|   echo 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| cd "$DIR" || exit 1 | ||||
| 
 | ||||
| if [ -d queue ]; then | ||||
| 
 | ||||
|   echo "[-] Error: parameter is an individual output directory, not a sync dir." 1>&2 | ||||
|   exit 1 | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| CUR_TIME=`date +%s` | ||||
| 
 | ||||
| TMP=`mktemp -t .afl-whatsup-XXXXXXXX` || TMP=`mktemp -p /data/local/tmp .afl-whatsup-XXXXXXXX` || exit 1 | ||||
| 
 | ||||
| ALIVE_CNT=0 | ||||
| DEAD_CNT=0 | ||||
| 
 | ||||
| TOTAL_TIME=0 | ||||
| TOTAL_EXECS=0 | ||||
| TOTAL_EPS=0 | ||||
| TOTAL_CRASHES=0 | ||||
| TOTAL_PFAV=0 | ||||
| TOTAL_PENDING=0 | ||||
| 
 | ||||
| if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|   echo "Individual fuzzers" | ||||
|   echo "==================" | ||||
|   echo | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| for i in `find . -maxdepth 2 -iname fuzzer_stats | sort`; do | ||||
| 
 | ||||
|   sed 's/^command_line.*$/_skip:1/;s/[ ]*:[ ]*/="/;s/$/"/' "$i" >"$TMP" | ||||
|   . "$TMP" | ||||
| 
 | ||||
|   RUN_UNIX=$((CUR_TIME - start_time)) | ||||
|   RUN_DAYS=$((RUN_UNIX / 60 / 60 / 24)) | ||||
|   RUN_HRS=$(((RUN_UNIX / 60 / 60) % 24)) | ||||
| 
 | ||||
|   if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|     echo ">>> $afl_banner ($RUN_DAYS days, $RUN_HRS hrs) <<<" | ||||
|     echo | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
|   if ! kill -0 "$fuzzer_pid" 2>/dev/null; then | ||||
| 
 | ||||
|     if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|       echo "  Instance is dead or running remotely, skipping." | ||||
|       echo | ||||
| 
 | ||||
|     fi | ||||
| 
 | ||||
|     DEAD_CNT=$((DEAD_CNT + 1)) | ||||
|     continue | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
|   ALIVE_CNT=$((ALIVE_CNT + 1)) | ||||
| 
 | ||||
|   EXEC_SEC=$((execs_done / RUN_UNIX)) | ||||
|   PATH_PERC=$((cur_path * 100 / paths_total)) | ||||
| 
 | ||||
|   TOTAL_TIME=$((TOTAL_TIME + RUN_UNIX)) | ||||
|   TOTAL_EPS=$((TOTAL_EPS + EXEC_SEC)) | ||||
|   TOTAL_EXECS=$((TOTAL_EXECS + execs_done)) | ||||
|   TOTAL_CRASHES=$((TOTAL_CRASHES + unique_crashes)) | ||||
|   TOTAL_PENDING=$((TOTAL_PENDING + pending_total)) | ||||
|   TOTAL_PFAV=$((TOTAL_PFAV + pending_favs)) | ||||
| 
 | ||||
|   if [ "$SUMMARY_ONLY" = "" ]; then | ||||
| 
 | ||||
|     echo "  cycle $((cycles_done + 1)), lifetime speed $EXEC_SEC execs/sec, path $cur_path/$paths_total (${PATH_PERC}%)" | ||||
| 
 | ||||
|     if [ "$unique_crashes" = "0" ]; then | ||||
|       echo "  pending $pending_favs/$pending_total, coverage $bitmap_cvg, no crashes yet" | ||||
|     else | ||||
|       echo "  pending $pending_favs/$pending_total, coverage $bitmap_cvg, crash count $unique_crashes (!)" | ||||
|     fi | ||||
| 
 | ||||
|     echo | ||||
| 
 | ||||
|   fi | ||||
| 
 | ||||
| done | ||||
| 
 | ||||
| rm -f "$TMP" | ||||
| 
 | ||||
| TOTAL_DAYS=$((TOTAL_TIME / 60 / 60 / 24)) | ||||
| TOTAL_HRS=$(((TOTAL_TIME / 60 / 60) % 24)) | ||||
| 
 | ||||
| test "$TOTAL_TIME" = "0" && TOTAL_TIME=1 | ||||
| 
 | ||||
| echo "Summary stats" | ||||
| echo "=============" | ||||
| echo | ||||
| echo "       Fuzzers alive : $ALIVE_CNT" | ||||
| 
 | ||||
| if [ ! "$DEAD_CNT" = "0" ]; then | ||||
|   echo "      Dead or remote : $DEAD_CNT (excluded from stats)" | ||||
| fi | ||||
| 
 | ||||
| echo "      Total run time : $TOTAL_DAYS days, $TOTAL_HRS hours" | ||||
| echo "         Total execs : $((TOTAL_EXECS / 1000 / 1000)) million" | ||||
| echo "    Cumulative speed : $TOTAL_EPS execs/sec" | ||||
| echo "       Pending paths : $TOTAL_PFAV faves, $TOTAL_PENDING total" | ||||
| 
 | ||||
| if [ "$ALIVE_CNT" -gt "1" ]; then | ||||
|   echo "  Pending per fuzzer : $((TOTAL_PFAV/ALIVE_CNT)) faves, $((TOTAL_PENDING/ALIVE_CNT)) total (on average)" | ||||
| fi | ||||
| 
 | ||||
| echo "       Crashes found : $TOTAL_CRASHES locally unique" | ||||
| echo | ||||
| 
 | ||||
| exit 0 | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,82 +1,82 @@ | ||||
| #ifdef __ANDROID__ | ||||
| #ifndef _ANDROID_ASHMEM_H | ||||
| #define _ANDROID_ASHMEM_H | ||||
| 
 | ||||
| #include <fcntl.h> | ||||
| #include <linux/ashmem.h> | ||||
| #include <linux/shm.h> | ||||
| #include <sys/ioctl.h> | ||||
| #include <sys/mman.h> | ||||
| 
 | ||||
| #if __ANDROID_API__ >= 26 | ||||
| #define shmat bionic_shmat | ||||
| #define shmctl bionic_shmctl | ||||
| #define shmdt bionic_shmdt | ||||
| #define shmget bionic_shmget | ||||
| #endif | ||||
| #include <sys/shm.h> | ||||
| #undef shmat | ||||
| #undef shmctl | ||||
| #undef shmdt | ||||
| #undef shmget | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| #define ASHMEM_DEVICE "/dev/ashmem" | ||||
| 
 | ||||
| static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) { | ||||
|   int ret = 0; | ||||
|   if (__cmd == IPC_RMID) { | ||||
|     int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); | ||||
|     struct ashmem_pin pin = {0, length}; | ||||
|     ret = ioctl(__shmid, ASHMEM_UNPIN, &pin); | ||||
|     close(__shmid); | ||||
|   } | ||||
| 
 | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| static inline int shmget(key_t __key, size_t __size, int __shmflg) { | ||||
|   (void) __shmflg; | ||||
|   int fd, ret; | ||||
|   char ourkey[11]; | ||||
| 
 | ||||
|   fd = open(ASHMEM_DEVICE, O_RDWR); | ||||
|   if (fd < 0) | ||||
|     return fd; | ||||
| 
 | ||||
|   sprintf(ourkey, "%d", __key); | ||||
|   ret = ioctl(fd, ASHMEM_SET_NAME, ourkey); | ||||
|   if (ret < 0) | ||||
|     goto error; | ||||
| 
 | ||||
|   ret = ioctl(fd, ASHMEM_SET_SIZE, __size); | ||||
|   if (ret < 0) | ||||
|     goto error; | ||||
| 
 | ||||
|   return fd; | ||||
| 
 | ||||
| error: | ||||
|   close(fd); | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| static inline void *shmat(int __shmid, const void *__shmaddr, int __shmflg) { | ||||
|   (void) __shmflg; | ||||
|   int size; | ||||
|   void *ptr; | ||||
| 
 | ||||
|   size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); | ||||
|   if (size < 0) { | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|   ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); | ||||
|   if (ptr == MAP_FAILED) { | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|   return ptr; | ||||
| } | ||||
| 
 | ||||
| #endif /* !_ANDROID_ASHMEM_H */ | ||||
| #endif /* !__ANDROID__ */ | ||||
| #ifdef __ANDROID__ | ||||
| #ifndef _ANDROID_ASHMEM_H | ||||
| #define _ANDROID_ASHMEM_H | ||||
| 
 | ||||
| #include <fcntl.h> | ||||
| #include <linux/ashmem.h> | ||||
| #include <linux/shm.h> | ||||
| #include <sys/ioctl.h> | ||||
| #include <sys/mman.h> | ||||
| 
 | ||||
| #if __ANDROID_API__ >= 26 | ||||
| #define shmat bionic_shmat | ||||
| #define shmctl bionic_shmctl | ||||
| #define shmdt bionic_shmdt | ||||
| #define shmget bionic_shmget | ||||
| #endif | ||||
| #include <sys/shm.h> | ||||
| #undef shmat | ||||
| #undef shmctl | ||||
| #undef shmdt | ||||
| #undef shmget | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| #define ASHMEM_DEVICE "/dev/ashmem" | ||||
| 
 | ||||
| static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) { | ||||
|   int ret = 0; | ||||
|   if (__cmd == IPC_RMID) { | ||||
|     int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); | ||||
|     struct ashmem_pin pin = {0, length}; | ||||
|     ret = ioctl(__shmid, ASHMEM_UNPIN, &pin); | ||||
|     close(__shmid); | ||||
|   } | ||||
| 
 | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| static inline int shmget(key_t __key, size_t __size, int __shmflg) { | ||||
|   (void) __shmflg; | ||||
|   int fd, ret; | ||||
|   char ourkey[11]; | ||||
| 
 | ||||
|   fd = open(ASHMEM_DEVICE, O_RDWR); | ||||
|   if (fd < 0) | ||||
|     return fd; | ||||
| 
 | ||||
|   sprintf(ourkey, "%d", __key); | ||||
|   ret = ioctl(fd, ASHMEM_SET_NAME, ourkey); | ||||
|   if (ret < 0) | ||||
|     goto error; | ||||
| 
 | ||||
|   ret = ioctl(fd, ASHMEM_SET_SIZE, __size); | ||||
|   if (ret < 0) | ||||
|     goto error; | ||||
| 
 | ||||
|   return fd; | ||||
| 
 | ||||
| error: | ||||
|   close(fd); | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
| static inline void *shmat(int __shmid, const void *__shmaddr, int __shmflg) { | ||||
|   (void) __shmflg; | ||||
|   int size; | ||||
|   void *ptr; | ||||
| 
 | ||||
|   size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); | ||||
|   if (size < 0) { | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|   ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); | ||||
|   if (ptr == MAP_FAILED) { | ||||
|     return NULL; | ||||
|   } | ||||
| 
 | ||||
|   return ptr; | ||||
| } | ||||
| 
 | ||||
| #endif /* !_ANDROID_ASHMEM_H */ | ||||
| #endif /* !__ANDROID__ */ | ||||
|  | ||||
| @ -1,362 +1,362 @@ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - vaguely configurable bits | ||||
|    ---------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_CONFIG_H | ||||
| #define _HAVE_CONFIG_H | ||||
| 
 | ||||
| #include "types.h" | ||||
| 
 | ||||
| /* Version string: */ | ||||
| 
 | ||||
| #define VERSION             "2.57b" | ||||
| 
 | ||||
| /******************************************************
 | ||||
|  *                                                    * | ||||
|  *  Settings that may be of interest to power users:  * | ||||
|  *                                                    * | ||||
|  ******************************************************/ | ||||
| 
 | ||||
| /* Comment out to disable terminal colors (note that this makes afl-analyze
 | ||||
|    a lot less nice): */ | ||||
| 
 | ||||
| #define USE_COLOR | ||||
| 
 | ||||
| /* Comment out to disable fancy ANSI boxes and use poor man's 7-bit UI: */ | ||||
| 
 | ||||
| #define FANCY_BOXES | ||||
| 
 | ||||
| /* Default timeout for fuzzed code (milliseconds). This is the upper bound,
 | ||||
|    also used for detecting hangs; the actual value is auto-scaled: */ | ||||
| 
 | ||||
| #define EXEC_TIMEOUT        1000 | ||||
| 
 | ||||
| /* Timeout rounding factor when auto-scaling (milliseconds): */ | ||||
| 
 | ||||
| #define EXEC_TM_ROUND       20 | ||||
| 
 | ||||
| /* 64bit arch MACRO */ | ||||
| #if (defined (__x86_64__) || defined (__arm64__) || defined (__aarch64__)) | ||||
| #define WORD_SIZE_64 1 | ||||
| #endif | ||||
| 
 | ||||
| /* Default memory limit for child process (MB): */ | ||||
| 
 | ||||
| #ifndef WORD_SIZE_64 | ||||
| #  define MEM_LIMIT         25 | ||||
| #else | ||||
| #  define MEM_LIMIT         50 | ||||
| #endif /* ^!WORD_SIZE_64 */ | ||||
| 
 | ||||
| /* Default memory limit when running in QEMU mode (MB): */ | ||||
| 
 | ||||
| #define MEM_LIMIT_QEMU      200 | ||||
| 
 | ||||
| /* Number of calibration cycles per every new test case (and for test
 | ||||
|    cases that show variable behavior): */ | ||||
| 
 | ||||
| #define CAL_CYCLES          8 | ||||
| #define CAL_CYCLES_LONG     40 | ||||
| 
 | ||||
| /* Number of subsequent timeouts before abandoning an input file: */ | ||||
| 
 | ||||
| #define TMOUT_LIMIT         250 | ||||
| 
 | ||||
| /* Maximum number of unique hangs or crashes to record: */ | ||||
| 
 | ||||
| #define KEEP_UNIQUE_HANG    500 | ||||
| #define KEEP_UNIQUE_CRASH   5000 | ||||
| 
 | ||||
| /* Baseline number of random tweaks during a single 'havoc' stage: */ | ||||
| 
 | ||||
| #define HAVOC_CYCLES        256 | ||||
| #define HAVOC_CYCLES_INIT   1024 | ||||
| 
 | ||||
| /* Maximum multiplier for the above (should be a power of two, beware
 | ||||
|    of 32-bit int overflows): */ | ||||
| 
 | ||||
| #define HAVOC_MAX_MULT      16 | ||||
| 
 | ||||
| /* Absolute minimum number of havoc cycles (after all adjustments): */ | ||||
| 
 | ||||
| #define HAVOC_MIN           16 | ||||
| 
 | ||||
| /* Maximum stacking for havoc-stage tweaks. The actual value is calculated
 | ||||
|    like this:  | ||||
| 
 | ||||
|    n = random between 1 and HAVOC_STACK_POW2 | ||||
|    stacking = 2^n | ||||
| 
 | ||||
|    In other words, the default (n = 7) produces 2, 4, 8, 16, 32, 64, or | ||||
|    128 stacked tweaks: */ | ||||
| 
 | ||||
| #define HAVOC_STACK_POW2    7 | ||||
| 
 | ||||
| /* Caps on block sizes for cloning and deletion operations. Each of these
 | ||||
|    ranges has a 33% probability of getting picked, except for the first | ||||
|    two cycles where smaller blocks are favored: */ | ||||
| 
 | ||||
| #define HAVOC_BLK_SMALL     32 | ||||
| #define HAVOC_BLK_MEDIUM    128 | ||||
| #define HAVOC_BLK_LARGE     1500 | ||||
| 
 | ||||
| /* Extra-large blocks, selected very rarely (<5% of the time): */ | ||||
| 
 | ||||
| #define HAVOC_BLK_XL        32768 | ||||
| 
 | ||||
| /* Probabilities of skipping non-favored entries in the queue, expressed as
 | ||||
|    percentages: */ | ||||
| 
 | ||||
| #define SKIP_TO_NEW_PROB    99 /* ...when there are new, pending favorites */ | ||||
| #define SKIP_NFAV_OLD_PROB  95 /* ...no new favs, cur entry already fuzzed */ | ||||
| #define SKIP_NFAV_NEW_PROB  75 /* ...no new favs, cur entry not fuzzed yet */ | ||||
| 
 | ||||
| /* Splicing cycle count: */ | ||||
| 
 | ||||
| #define SPLICE_CYCLES       15 | ||||
| 
 | ||||
| /* Nominal per-splice havoc cycle length: */ | ||||
| 
 | ||||
| #define SPLICE_HAVOC        32 | ||||
| 
 | ||||
| /* Maximum offset for integer addition / subtraction stages: */ | ||||
| 
 | ||||
| #define ARITH_MAX           35 | ||||
| 
 | ||||
| /* Limits for the test case trimmer. The absolute minimum chunk size; and
 | ||||
|    the starting and ending divisors for chopping up the input file: */ | ||||
| 
 | ||||
| #define TRIM_MIN_BYTES      4 | ||||
| #define TRIM_START_STEPS    16 | ||||
| #define TRIM_END_STEPS      1024 | ||||
| 
 | ||||
| /* Maximum size of input file, in bytes (keep under 100MB): */ | ||||
| 
 | ||||
| #define MAX_FILE            (1 * 1024 * 1024) | ||||
| 
 | ||||
| /* The same, for the test case minimizer: */ | ||||
| 
 | ||||
| #define TMIN_MAX_FILE       (10 * 1024 * 1024) | ||||
| 
 | ||||
| /* Block normalization steps for afl-tmin: */ | ||||
| 
 | ||||
| #define TMIN_SET_MIN_SIZE   4 | ||||
| #define TMIN_SET_STEPS      128 | ||||
| 
 | ||||
| /* Maximum dictionary token size (-x), in bytes: */ | ||||
| 
 | ||||
| #define MAX_DICT_FILE       128 | ||||
| 
 | ||||
| /* Length limits for auto-detected dictionary tokens: */ | ||||
| 
 | ||||
| #define MIN_AUTO_EXTRA      3 | ||||
| #define MAX_AUTO_EXTRA      32 | ||||
| 
 | ||||
| /* Maximum number of user-specified dictionary tokens to use in deterministic
 | ||||
|    steps; past this point, the "extras/user" step will be still carried out, | ||||
|    but with proportionally lower odds: */ | ||||
| 
 | ||||
| #define MAX_DET_EXTRAS      200 | ||||
| 
 | ||||
| /* Maximum number of auto-extracted dictionary tokens to actually use in fuzzing
 | ||||
|    (first value), and to keep in memory as candidates. The latter should be much | ||||
|    higher than the former. */ | ||||
| 
 | ||||
| #define USE_AUTO_EXTRAS     50 | ||||
| #define MAX_AUTO_EXTRAS     (USE_AUTO_EXTRAS * 10) | ||||
| 
 | ||||
| /* Scaling factor for the effector map used to skip some of the more
 | ||||
|    expensive deterministic steps. The actual divisor is set to | ||||
|    2^EFF_MAP_SCALE2 bytes: */ | ||||
| 
 | ||||
| #define EFF_MAP_SCALE2      3 | ||||
| 
 | ||||
| /* Minimum input file length at which the effector logic kicks in: */ | ||||
| 
 | ||||
| #define EFF_MIN_LEN         128 | ||||
| 
 | ||||
| /* Maximum effector density past which everything is just fuzzed
 | ||||
|    unconditionally (%): */ | ||||
| 
 | ||||
| #define EFF_MAX_PERC        90 | ||||
| 
 | ||||
| /* UI refresh frequency (Hz): */ | ||||
| 
 | ||||
| #define UI_TARGET_HZ        5 | ||||
| 
 | ||||
| /* Fuzzer stats file and plot update intervals (sec): */ | ||||
| 
 | ||||
| #define STATS_UPDATE_SEC    60 | ||||
| #define PLOT_UPDATE_SEC     5 | ||||
| 
 | ||||
| /* Smoothing divisor for CPU load and exec speed stats (1 - no smoothing). */ | ||||
| 
 | ||||
| #define AVG_SMOOTHING       16 | ||||
| 
 | ||||
| /* Sync interval (every n havoc cycles): */ | ||||
| 
 | ||||
| #define SYNC_INTERVAL       5 | ||||
| 
 | ||||
| /* Output directory reuse grace period (minutes): */ | ||||
| 
 | ||||
| #define OUTPUT_GRACE        25 | ||||
| 
 | ||||
| /* Uncomment to use simple file names (id_NNNNNN): */ | ||||
| 
 | ||||
| // #define SIMPLE_FILES
 | ||||
| 
 | ||||
| /* List of interesting values to use in fuzzing. */ | ||||
| 
 | ||||
| #define INTERESTING_8 \ | ||||
|   -128,          /* Overflow signed 8-bit when decremented  */ \ | ||||
|   -1,            /*                                         */ \ | ||||
|    0,            /*                                         */ \ | ||||
|    1,            /*                                         */ \ | ||||
|    16,           /* One-off with common buffer size         */ \ | ||||
|    32,           /* One-off with common buffer size         */ \ | ||||
|    64,           /* One-off with common buffer size         */ \ | ||||
|    100,          /* One-off with common buffer size         */ \ | ||||
|    127           /* Overflow signed 8-bit when incremented  */ | ||||
| 
 | ||||
| #define INTERESTING_16 \ | ||||
|   -32768,        /* Overflow signed 16-bit when decremented */ \ | ||||
|   -129,          /* Overflow signed 8-bit                   */ \ | ||||
|    128,          /* Overflow signed 8-bit                   */ \ | ||||
|    255,          /* Overflow unsig 8-bit when incremented   */ \ | ||||
|    256,          /* Overflow unsig 8-bit                    */ \ | ||||
|    512,          /* One-off with common buffer size         */ \ | ||||
|    1000,         /* One-off with common buffer size         */ \ | ||||
|    1024,         /* One-off with common buffer size         */ \ | ||||
|    4096,         /* One-off with common buffer size         */ \ | ||||
|    32767         /* Overflow signed 16-bit when incremented */ | ||||
| 
 | ||||
| #define INTERESTING_32 \ | ||||
|   -2147483648LL, /* Overflow signed 32-bit when decremented */ \ | ||||
|   -100663046,    /* Large negative number (endian-agnostic) */ \ | ||||
|   -32769,        /* Overflow signed 16-bit                  */ \ | ||||
|    32768,        /* Overflow signed 16-bit                  */ \ | ||||
|    65535,        /* Overflow unsig 16-bit when incremented  */ \ | ||||
|    65536,        /* Overflow unsig 16 bit                   */ \ | ||||
|    100663045,    /* Large positive number (endian-agnostic) */ \ | ||||
|    2147483647    /* Overflow signed 32-bit when incremented */ | ||||
| 
 | ||||
| /***********************************************************
 | ||||
|  *                                                         * | ||||
|  *  Really exotic stuff you probably don't want to touch:  * | ||||
|  *                                                         * | ||||
|  ***********************************************************/ | ||||
| 
 | ||||
| /* Call count interval between reseeding the libc PRNG from /dev/urandom: */ | ||||
| 
 | ||||
| #define RESEED_RNG          10000 | ||||
| 
 | ||||
| /* Maximum line length passed from GCC to 'as' and used for parsing
 | ||||
|    configuration files: */ | ||||
| 
 | ||||
| #define MAX_LINE            8192 | ||||
| 
 | ||||
| /* Environment variable used to pass SHM ID to the called program. */ | ||||
| 
 | ||||
| #define SHM_ENV_VAR         "__AFL_SHM_ID" | ||||
| 
 | ||||
| /* Other less interesting, internal-only variables. */ | ||||
| 
 | ||||
| #define CLANG_ENV_VAR       "__AFL_CLANG_MODE" | ||||
| #define AS_LOOP_ENV_VAR     "__AFL_AS_LOOPCHECK" | ||||
| #define PERSIST_ENV_VAR     "__AFL_PERSISTENT" | ||||
| #define DEFER_ENV_VAR       "__AFL_DEFER_FORKSRV" | ||||
| 
 | ||||
| /* In-code signatures for deferred and persistent mode. */ | ||||
| 
 | ||||
| #define PERSIST_SIG         "##SIG_AFL_PERSISTENT##" | ||||
| #define DEFER_SIG           "##SIG_AFL_DEFER_FORKSRV##" | ||||
| 
 | ||||
| /* Distinctive bitmap signature used to indicate failed execution: */ | ||||
| 
 | ||||
| #define EXEC_FAIL_SIG       0xfee1dead | ||||
| 
 | ||||
| /* Distinctive exit code used to indicate MSAN trip condition: */ | ||||
| 
 | ||||
| #define MSAN_ERROR          86 | ||||
| 
 | ||||
| /* Designated file descriptors for forkserver commands (the application will
 | ||||
|    use FORKSRV_FD and FORKSRV_FD + 1): */ | ||||
| 
 | ||||
| #define FORKSRV_FD          198 | ||||
| 
 | ||||
| /* Fork server init timeout multiplier: we'll wait the user-selected
 | ||||
|    timeout plus this much for the fork server to spin up. */ | ||||
| 
 | ||||
| #define FORK_WAIT_MULT      10 | ||||
| 
 | ||||
| /* Calibration timeout adjustments, to be a bit more generous when resuming
 | ||||
|    fuzzing sessions or trying to calibrate already-added internal finds. | ||||
|    The first value is a percentage, the other is in milliseconds: */ | ||||
| 
 | ||||
| #define CAL_TMOUT_PERC      125 | ||||
| #define CAL_TMOUT_ADD       50 | ||||
| 
 | ||||
| /* Number of chances to calibrate a case before giving up: */ | ||||
| 
 | ||||
| #define CAL_CHANCES         3 | ||||
| 
 | ||||
| /* Map size for the traced binary (2^MAP_SIZE_POW2). Must be greater than
 | ||||
|    2; you probably want to keep it under 18 or so for performance reasons | ||||
|    (adjusting AFL_INST_RATIO when compiling is probably a better way to solve | ||||
|    problems with complex programs). You need to recompile the target binary | ||||
|    after changing this - otherwise, SEGVs may ensue. */ | ||||
| 
 | ||||
| #define MAP_SIZE_POW2       16 | ||||
| #define MAP_SIZE            (1 << MAP_SIZE_POW2) | ||||
| 
 | ||||
| /* Maximum allocator request size (keep well under INT_MAX): */ | ||||
| 
 | ||||
| #define MAX_ALLOC           0x40000000 | ||||
| 
 | ||||
| /* A made-up hashing seed: */ | ||||
| 
 | ||||
| #define HASH_CONST          0xa5b35705 | ||||
| 
 | ||||
| /* Constants for afl-gotcpu to control busy loop timing: */ | ||||
| 
 | ||||
| #define  CTEST_TARGET_MS    5000 | ||||
| #define  CTEST_CORE_TRG_MS  1000 | ||||
| #define  CTEST_BUSY_CYCLES  (10 * 1000 * 1000) | ||||
| 
 | ||||
| /* Uncomment this to use inferior block-coverage-based instrumentation. Note
 | ||||
|    that you need to recompile the target binary for this to have any effect: */ | ||||
| 
 | ||||
| // #define COVERAGE_ONLY
 | ||||
| 
 | ||||
| /* Uncomment this to ignore hit counts and output just one bit per tuple.
 | ||||
|    As with the previous setting, you will need to recompile the target | ||||
|    binary: */ | ||||
| 
 | ||||
| // #define SKIP_COUNTS
 | ||||
| 
 | ||||
| /* Uncomment this to use instrumentation data to record newly discovered paths,
 | ||||
|    but do not use them as seeds for fuzzing. This is useful for conveniently | ||||
|    measuring coverage that could be attained by a "dumb" fuzzing algorithm: */ | ||||
| 
 | ||||
| // #define IGNORE_FINDS
 | ||||
| 
 | ||||
| #endif /* ! _HAVE_CONFIG_H */ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - vaguely configurable bits | ||||
|    ---------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_CONFIG_H | ||||
| #define _HAVE_CONFIG_H | ||||
| 
 | ||||
| #include "types.h" | ||||
| 
 | ||||
| /* Version string: */ | ||||
| 
 | ||||
| #define VERSION             "2.57b" | ||||
| 
 | ||||
| /******************************************************
 | ||||
|  *                                                    * | ||||
|  *  Settings that may be of interest to power users:  * | ||||
|  *                                                    * | ||||
|  ******************************************************/ | ||||
| 
 | ||||
| /* Comment out to disable terminal colors (note that this makes afl-analyze
 | ||||
|    a lot less nice): */ | ||||
| 
 | ||||
| #define USE_COLOR | ||||
| 
 | ||||
| /* Comment out to disable fancy ANSI boxes and use poor man's 7-bit UI: */ | ||||
| 
 | ||||
| #define FANCY_BOXES | ||||
| 
 | ||||
| /* Default timeout for fuzzed code (milliseconds). This is the upper bound,
 | ||||
|    also used for detecting hangs; the actual value is auto-scaled: */ | ||||
| 
 | ||||
| #define EXEC_TIMEOUT        1000 | ||||
| 
 | ||||
| /* Timeout rounding factor when auto-scaling (milliseconds): */ | ||||
| 
 | ||||
| #define EXEC_TM_ROUND       20 | ||||
| 
 | ||||
| /* 64bit arch MACRO */ | ||||
| #if (defined (__x86_64__) || defined (__arm64__) || defined (__aarch64__)) | ||||
| #define WORD_SIZE_64 1 | ||||
| #endif | ||||
| 
 | ||||
| /* Default memory limit for child process (MB): */ | ||||
| 
 | ||||
| #ifndef WORD_SIZE_64 | ||||
| #  define MEM_LIMIT         25 | ||||
| #else | ||||
| #  define MEM_LIMIT         50 | ||||
| #endif /* ^!WORD_SIZE_64 */ | ||||
| 
 | ||||
| /* Default memory limit when running in QEMU mode (MB): */ | ||||
| 
 | ||||
| #define MEM_LIMIT_QEMU      200 | ||||
| 
 | ||||
| /* Number of calibration cycles per every new test case (and for test
 | ||||
|    cases that show variable behavior): */ | ||||
| 
 | ||||
| #define CAL_CYCLES          8 | ||||
| #define CAL_CYCLES_LONG     40 | ||||
| 
 | ||||
| /* Number of subsequent timeouts before abandoning an input file: */ | ||||
| 
 | ||||
| #define TMOUT_LIMIT         250 | ||||
| 
 | ||||
| /* Maximum number of unique hangs or crashes to record: */ | ||||
| 
 | ||||
| #define KEEP_UNIQUE_HANG    500 | ||||
| #define KEEP_UNIQUE_CRASH   5000 | ||||
| 
 | ||||
| /* Baseline number of random tweaks during a single 'havoc' stage: */ | ||||
| 
 | ||||
| #define HAVOC_CYCLES        256 | ||||
| #define HAVOC_CYCLES_INIT   1024 | ||||
| 
 | ||||
| /* Maximum multiplier for the above (should be a power of two, beware
 | ||||
|    of 32-bit int overflows): */ | ||||
| 
 | ||||
| #define HAVOC_MAX_MULT      16 | ||||
| 
 | ||||
| /* Absolute minimum number of havoc cycles (after all adjustments): */ | ||||
| 
 | ||||
| #define HAVOC_MIN           16 | ||||
| 
 | ||||
| /* Maximum stacking for havoc-stage tweaks. The actual value is calculated
 | ||||
|    like this:  | ||||
| 
 | ||||
|    n = random between 1 and HAVOC_STACK_POW2 | ||||
|    stacking = 2^n | ||||
| 
 | ||||
|    In other words, the default (n = 7) produces 2, 4, 8, 16, 32, 64, or | ||||
|    128 stacked tweaks: */ | ||||
| 
 | ||||
| #define HAVOC_STACK_POW2    7 | ||||
| 
 | ||||
| /* Caps on block sizes for cloning and deletion operations. Each of these
 | ||||
|    ranges has a 33% probability of getting picked, except for the first | ||||
|    two cycles where smaller blocks are favored: */ | ||||
| 
 | ||||
| #define HAVOC_BLK_SMALL     32 | ||||
| #define HAVOC_BLK_MEDIUM    128 | ||||
| #define HAVOC_BLK_LARGE     1500 | ||||
| 
 | ||||
| /* Extra-large blocks, selected very rarely (<5% of the time): */ | ||||
| 
 | ||||
| #define HAVOC_BLK_XL        32768 | ||||
| 
 | ||||
| /* Probabilities of skipping non-favored entries in the queue, expressed as
 | ||||
|    percentages: */ | ||||
| 
 | ||||
| #define SKIP_TO_NEW_PROB    99 /* ...when there are new, pending favorites */ | ||||
| #define SKIP_NFAV_OLD_PROB  95 /* ...no new favs, cur entry already fuzzed */ | ||||
| #define SKIP_NFAV_NEW_PROB  75 /* ...no new favs, cur entry not fuzzed yet */ | ||||
| 
 | ||||
| /* Splicing cycle count: */ | ||||
| 
 | ||||
| #define SPLICE_CYCLES       15 | ||||
| 
 | ||||
| /* Nominal per-splice havoc cycle length: */ | ||||
| 
 | ||||
| #define SPLICE_HAVOC        32 | ||||
| 
 | ||||
| /* Maximum offset for integer addition / subtraction stages: */ | ||||
| 
 | ||||
| #define ARITH_MAX           35 | ||||
| 
 | ||||
| /* Limits for the test case trimmer. The absolute minimum chunk size; and
 | ||||
|    the starting and ending divisors for chopping up the input file: */ | ||||
| 
 | ||||
| #define TRIM_MIN_BYTES      4 | ||||
| #define TRIM_START_STEPS    16 | ||||
| #define TRIM_END_STEPS      1024 | ||||
| 
 | ||||
| /* Maximum size of input file, in bytes (keep under 100MB): */ | ||||
| 
 | ||||
| #define MAX_FILE            (1 * 1024 * 1024) | ||||
| 
 | ||||
| /* The same, for the test case minimizer: */ | ||||
| 
 | ||||
| #define TMIN_MAX_FILE       (10 * 1024 * 1024) | ||||
| 
 | ||||
| /* Block normalization steps for afl-tmin: */ | ||||
| 
 | ||||
| #define TMIN_SET_MIN_SIZE   4 | ||||
| #define TMIN_SET_STEPS      128 | ||||
| 
 | ||||
| /* Maximum dictionary token size (-x), in bytes: */ | ||||
| 
 | ||||
| #define MAX_DICT_FILE       128 | ||||
| 
 | ||||
| /* Length limits for auto-detected dictionary tokens: */ | ||||
| 
 | ||||
| #define MIN_AUTO_EXTRA      3 | ||||
| #define MAX_AUTO_EXTRA      32 | ||||
| 
 | ||||
| /* Maximum number of user-specified dictionary tokens to use in deterministic
 | ||||
|    steps; past this point, the "extras/user" step will be still carried out, | ||||
|    but with proportionally lower odds: */ | ||||
| 
 | ||||
| #define MAX_DET_EXTRAS      200 | ||||
| 
 | ||||
| /* Maximum number of auto-extracted dictionary tokens to actually use in fuzzing
 | ||||
|    (first value), and to keep in memory as candidates. The latter should be much | ||||
|    higher than the former. */ | ||||
| 
 | ||||
| #define USE_AUTO_EXTRAS     50 | ||||
| #define MAX_AUTO_EXTRAS     (USE_AUTO_EXTRAS * 10) | ||||
| 
 | ||||
| /* Scaling factor for the effector map used to skip some of the more
 | ||||
|    expensive deterministic steps. The actual divisor is set to | ||||
|    2^EFF_MAP_SCALE2 bytes: */ | ||||
| 
 | ||||
| #define EFF_MAP_SCALE2      3 | ||||
| 
 | ||||
| /* Minimum input file length at which the effector logic kicks in: */ | ||||
| 
 | ||||
| #define EFF_MIN_LEN         128 | ||||
| 
 | ||||
| /* Maximum effector density past which everything is just fuzzed
 | ||||
|    unconditionally (%): */ | ||||
| 
 | ||||
| #define EFF_MAX_PERC        90 | ||||
| 
 | ||||
| /* UI refresh frequency (Hz): */ | ||||
| 
 | ||||
| #define UI_TARGET_HZ        5 | ||||
| 
 | ||||
| /* Fuzzer stats file and plot update intervals (sec): */ | ||||
| 
 | ||||
| #define STATS_UPDATE_SEC    60 | ||||
| #define PLOT_UPDATE_SEC     5 | ||||
| 
 | ||||
| /* Smoothing divisor for CPU load and exec speed stats (1 - no smoothing). */ | ||||
| 
 | ||||
| #define AVG_SMOOTHING       16 | ||||
| 
 | ||||
| /* Sync interval (every n havoc cycles): */ | ||||
| 
 | ||||
| #define SYNC_INTERVAL       5 | ||||
| 
 | ||||
| /* Output directory reuse grace period (minutes): */ | ||||
| 
 | ||||
| #define OUTPUT_GRACE        25 | ||||
| 
 | ||||
| /* Uncomment to use simple file names (id_NNNNNN): */ | ||||
| 
 | ||||
| // #define SIMPLE_FILES
 | ||||
| 
 | ||||
| /* List of interesting values to use in fuzzing. */ | ||||
| 
 | ||||
| #define INTERESTING_8 \ | ||||
|   -128,          /* Overflow signed 8-bit when decremented  */ \ | ||||
|   -1,            /*                                         */ \ | ||||
|    0,            /*                                         */ \ | ||||
|    1,            /*                                         */ \ | ||||
|    16,           /* One-off with common buffer size         */ \ | ||||
|    32,           /* One-off with common buffer size         */ \ | ||||
|    64,           /* One-off with common buffer size         */ \ | ||||
|    100,          /* One-off with common buffer size         */ \ | ||||
|    127           /* Overflow signed 8-bit when incremented  */ | ||||
| 
 | ||||
| #define INTERESTING_16 \ | ||||
|   -32768,        /* Overflow signed 16-bit when decremented */ \ | ||||
|   -129,          /* Overflow signed 8-bit                   */ \ | ||||
|    128,          /* Overflow signed 8-bit                   */ \ | ||||
|    255,          /* Overflow unsig 8-bit when incremented   */ \ | ||||
|    256,          /* Overflow unsig 8-bit                    */ \ | ||||
|    512,          /* One-off with common buffer size         */ \ | ||||
|    1000,         /* One-off with common buffer size         */ \ | ||||
|    1024,         /* One-off with common buffer size         */ \ | ||||
|    4096,         /* One-off with common buffer size         */ \ | ||||
|    32767         /* Overflow signed 16-bit when incremented */ | ||||
| 
 | ||||
| #define INTERESTING_32 \ | ||||
|   -2147483648LL, /* Overflow signed 32-bit when decremented */ \ | ||||
|   -100663046,    /* Large negative number (endian-agnostic) */ \ | ||||
|   -32769,        /* Overflow signed 16-bit                  */ \ | ||||
|    32768,        /* Overflow signed 16-bit                  */ \ | ||||
|    65535,        /* Overflow unsig 16-bit when incremented  */ \ | ||||
|    65536,        /* Overflow unsig 16 bit                   */ \ | ||||
|    100663045,    /* Large positive number (endian-agnostic) */ \ | ||||
|    2147483647    /* Overflow signed 32-bit when incremented */ | ||||
| 
 | ||||
| /***********************************************************
 | ||||
|  *                                                         * | ||||
|  *  Really exotic stuff you probably don't want to touch:  * | ||||
|  *                                                         * | ||||
|  ***********************************************************/ | ||||
| 
 | ||||
| /* Call count interval between reseeding the libc PRNG from /dev/urandom: */ | ||||
| 
 | ||||
| #define RESEED_RNG          10000 | ||||
| 
 | ||||
| /* Maximum line length passed from GCC to 'as' and used for parsing
 | ||||
|    configuration files: */ | ||||
| 
 | ||||
| #define MAX_LINE            8192 | ||||
| 
 | ||||
| /* Environment variable used to pass SHM ID to the called program. */ | ||||
| 
 | ||||
| #define SHM_ENV_VAR         "__AFL_SHM_ID" | ||||
| 
 | ||||
| /* Other less interesting, internal-only variables. */ | ||||
| 
 | ||||
| #define CLANG_ENV_VAR       "__AFL_CLANG_MODE" | ||||
| #define AS_LOOP_ENV_VAR     "__AFL_AS_LOOPCHECK" | ||||
| #define PERSIST_ENV_VAR     "__AFL_PERSISTENT" | ||||
| #define DEFER_ENV_VAR       "__AFL_DEFER_FORKSRV" | ||||
| 
 | ||||
| /* In-code signatures for deferred and persistent mode. */ | ||||
| 
 | ||||
| #define PERSIST_SIG         "##SIG_AFL_PERSISTENT##" | ||||
| #define DEFER_SIG           "##SIG_AFL_DEFER_FORKSRV##" | ||||
| 
 | ||||
| /* Distinctive bitmap signature used to indicate failed execution: */ | ||||
| 
 | ||||
| #define EXEC_FAIL_SIG       0xfee1dead | ||||
| 
 | ||||
| /* Distinctive exit code used to indicate MSAN trip condition: */ | ||||
| 
 | ||||
| #define MSAN_ERROR          86 | ||||
| 
 | ||||
| /* Designated file descriptors for forkserver commands (the application will
 | ||||
|    use FORKSRV_FD and FORKSRV_FD + 1): */ | ||||
| 
 | ||||
| #define FORKSRV_FD          198 | ||||
| 
 | ||||
| /* Fork server init timeout multiplier: we'll wait the user-selected
 | ||||
|    timeout plus this much for the fork server to spin up. */ | ||||
| 
 | ||||
| #define FORK_WAIT_MULT      10 | ||||
| 
 | ||||
| /* Calibration timeout adjustments, to be a bit more generous when resuming
 | ||||
|    fuzzing sessions or trying to calibrate already-added internal finds. | ||||
|    The first value is a percentage, the other is in milliseconds: */ | ||||
| 
 | ||||
| #define CAL_TMOUT_PERC      125 | ||||
| #define CAL_TMOUT_ADD       50 | ||||
| 
 | ||||
| /* Number of chances to calibrate a case before giving up: */ | ||||
| 
 | ||||
| #define CAL_CHANCES         3 | ||||
| 
 | ||||
| /* Map size for the traced binary (2^MAP_SIZE_POW2). Must be greater than
 | ||||
|    2; you probably want to keep it under 18 or so for performance reasons | ||||
|    (adjusting AFL_INST_RATIO when compiling is probably a better way to solve | ||||
|    problems with complex programs). You need to recompile the target binary | ||||
|    after changing this - otherwise, SEGVs may ensue. */ | ||||
| 
 | ||||
| #define MAP_SIZE_POW2       16 | ||||
| #define MAP_SIZE            (1 << MAP_SIZE_POW2) | ||||
| 
 | ||||
| /* Maximum allocator request size (keep well under INT_MAX): */ | ||||
| 
 | ||||
| #define MAX_ALLOC           0x40000000 | ||||
| 
 | ||||
| /* A made-up hashing seed: */ | ||||
| 
 | ||||
| #define HASH_CONST          0xa5b35705 | ||||
| 
 | ||||
| /* Constants for afl-gotcpu to control busy loop timing: */ | ||||
| 
 | ||||
| #define  CTEST_TARGET_MS    5000 | ||||
| #define  CTEST_CORE_TRG_MS  1000 | ||||
| #define  CTEST_BUSY_CYCLES  (10 * 1000 * 1000) | ||||
| 
 | ||||
| /* Uncomment this to use inferior block-coverage-based instrumentation. Note
 | ||||
|    that you need to recompile the target binary for this to have any effect: */ | ||||
| 
 | ||||
| // #define COVERAGE_ONLY
 | ||||
| 
 | ||||
| /* Uncomment this to ignore hit counts and output just one bit per tuple.
 | ||||
|    As with the previous setting, you will need to recompile the target | ||||
|    binary: */ | ||||
| 
 | ||||
| // #define SKIP_COUNTS
 | ||||
| 
 | ||||
| /* Uncomment this to use instrumentation data to record newly discovered paths,
 | ||||
|    but do not use them as seeds for fuzzing. This is useful for conveniently | ||||
|    measuring coverage that could be attained by a "dumb" fuzzing algorithm: */ | ||||
| 
 | ||||
| // #define IGNORE_FINDS
 | ||||
| 
 | ||||
| #endif /* ! _HAVE_CONFIG_H */ | ||||
|  | ||||
| @ -1,258 +1,258 @@ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - debug / error handling macros | ||||
|    -------------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_DEBUG_H | ||||
| #define _HAVE_DEBUG_H | ||||
| 
 | ||||
| #include <errno.h> | ||||
| 
 | ||||
| #include "types.h" | ||||
| #include "config.h" | ||||
| 
 | ||||
| /*******************
 | ||||
|  * Terminal colors * | ||||
|  *******************/ | ||||
| 
 | ||||
| #ifdef USE_COLOR | ||||
| 
 | ||||
| #  define cBLK "\x1b[0;30m" | ||||
| #  define cRED "\x1b[0;31m" | ||||
| #  define cGRN "\x1b[0;32m" | ||||
| #  define cBRN "\x1b[0;33m" | ||||
| #  define cBLU "\x1b[0;34m" | ||||
| #  define cMGN "\x1b[0;35m" | ||||
| #  define cCYA "\x1b[0;36m" | ||||
| #  define cLGR "\x1b[0;37m" | ||||
| #  define cGRA "\x1b[1;90m" | ||||
| #  define cLRD "\x1b[1;91m" | ||||
| #  define cLGN "\x1b[1;92m" | ||||
| #  define cYEL "\x1b[1;93m" | ||||
| #  define cLBL "\x1b[1;94m" | ||||
| #  define cPIN "\x1b[1;95m" | ||||
| #  define cLCY "\x1b[1;96m" | ||||
| #  define cBRI "\x1b[1;97m" | ||||
| #  define cRST "\x1b[0m" | ||||
| 
 | ||||
| #  define bgBLK "\x1b[40m" | ||||
| #  define bgRED "\x1b[41m" | ||||
| #  define bgGRN "\x1b[42m" | ||||
| #  define bgBRN "\x1b[43m" | ||||
| #  define bgBLU "\x1b[44m" | ||||
| #  define bgMGN "\x1b[45m" | ||||
| #  define bgCYA "\x1b[46m" | ||||
| #  define bgLGR "\x1b[47m" | ||||
| #  define bgGRA "\x1b[100m" | ||||
| #  define bgLRD "\x1b[101m" | ||||
| #  define bgLGN "\x1b[102m" | ||||
| #  define bgYEL "\x1b[103m" | ||||
| #  define bgLBL "\x1b[104m" | ||||
| #  define bgPIN "\x1b[105m" | ||||
| #  define bgLCY "\x1b[106m" | ||||
| #  define bgBRI "\x1b[107m" | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| #  define cBLK "" | ||||
| #  define cRED "" | ||||
| #  define cGRN "" | ||||
| #  define cBRN "" | ||||
| #  define cBLU "" | ||||
| #  define cMGN "" | ||||
| #  define cCYA "" | ||||
| #  define cLGR "" | ||||
| #  define cGRA "" | ||||
| #  define cLRD "" | ||||
| #  define cLGN "" | ||||
| #  define cYEL "" | ||||
| #  define cLBL "" | ||||
| #  define cPIN "" | ||||
| #  define cLCY "" | ||||
| #  define cBRI "" | ||||
| #  define cRST "" | ||||
| 
 | ||||
| #  define bgBLK "" | ||||
| #  define bgRED "" | ||||
| #  define bgGRN "" | ||||
| #  define bgBRN "" | ||||
| #  define bgBLU "" | ||||
| #  define bgMGN "" | ||||
| #  define bgCYA "" | ||||
| #  define bgLGR "" | ||||
| #  define bgGRA "" | ||||
| #  define bgLRD "" | ||||
| #  define bgLGN "" | ||||
| #  define bgYEL "" | ||||
| #  define bgLBL "" | ||||
| #  define bgPIN "" | ||||
| #  define bgLCY "" | ||||
| #  define bgBRI "" | ||||
| 
 | ||||
| #endif /* ^USE_COLOR */ | ||||
| 
 | ||||
| /*************************
 | ||||
|  * Box drawing sequences * | ||||
|  *************************/ | ||||
| 
 | ||||
| #ifdef FANCY_BOXES | ||||
| 
 | ||||
| #  define SET_G1   "\x1b)0"       /* Set G1 for box drawing    */ | ||||
| #  define RESET_G1 "\x1b)B"       /* Reset G1 to ASCII         */ | ||||
| #  define bSTART   "\x0e"         /* Enter G1 drawing mode     */ | ||||
| #  define bSTOP    "\x0f"         /* Leave G1 drawing mode     */ | ||||
| #  define bH       "q"            /* Horizontal line           */ | ||||
| #  define bV       "x"            /* Vertical line             */ | ||||
| #  define bLT      "l"            /* Left top corner           */ | ||||
| #  define bRT      "k"            /* Right top corner          */ | ||||
| #  define bLB      "m"            /* Left bottom corner        */ | ||||
| #  define bRB      "j"            /* Right bottom corner       */ | ||||
| #  define bX       "n"            /* Cross                     */ | ||||
| #  define bVR      "t"            /* Vertical, branch right    */ | ||||
| #  define bVL      "u"            /* Vertical, branch left     */ | ||||
| #  define bHT      "v"            /* Horizontal, branch top    */ | ||||
| #  define bHB      "w"            /* Horizontal, branch bottom */ | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| #  define SET_G1   "" | ||||
| #  define RESET_G1 "" | ||||
| #  define bSTART   "" | ||||
| #  define bSTOP    "" | ||||
| #  define bH       "-" | ||||
| #  define bV       "|" | ||||
| #  define bLT      "+" | ||||
| #  define bRT      "+" | ||||
| #  define bLB      "+" | ||||
| #  define bRB      "+" | ||||
| #  define bX       "+" | ||||
| #  define bVR      "+" | ||||
| #  define bVL      "+" | ||||
| #  define bHT      "+" | ||||
| #  define bHB      "+" | ||||
| 
 | ||||
| #endif /* ^FANCY_BOXES */ | ||||
| 
 | ||||
| /***********************
 | ||||
|  * Misc terminal codes * | ||||
|  ***********************/ | ||||
| 
 | ||||
| #define TERM_HOME     "\x1b[H" | ||||
| #define TERM_CLEAR    TERM_HOME "\x1b[2J" | ||||
| #define cEOL          "\x1b[0K" | ||||
| #define CURSOR_HIDE   "\x1b[?25l" | ||||
| #define CURSOR_SHOW   "\x1b[?25h" | ||||
| 
 | ||||
| /************************
 | ||||
|  * Debug & error macros * | ||||
|  ************************/ | ||||
| 
 | ||||
| /* Just print stuff to the appropriate stream. */ | ||||
| 
 | ||||
| #ifdef MESSAGES_TO_STDOUT | ||||
| #  define SAYF(x...)    printf(x) | ||||
| #else  | ||||
| #  define SAYF(x...)    fprintf(stderr, x) | ||||
| #endif /* ^MESSAGES_TO_STDOUT */ | ||||
| 
 | ||||
| /* Show a prefixed warning. */ | ||||
| 
 | ||||
| #define WARNF(x...) do { \ | ||||
|     SAYF(cYEL "[!] " cBRI "WARNING: " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed "doing something" message. */ | ||||
| 
 | ||||
| #define ACTF(x...) do { \ | ||||
|     SAYF(cLBL "[*] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed "success" message. */ | ||||
| 
 | ||||
| #define OKF(x...) do { \ | ||||
|     SAYF(cLGN "[+] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed fatal error message (not used in afl). */ | ||||
| 
 | ||||
| #define BADF(x...) do { \ | ||||
|     SAYF(cLRD "\n[-] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die with a verbose non-OS fatal error message. */ | ||||
| 
 | ||||
| #define FATAL(x...) do { \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n         Location : " cRST "%s(), %s:%u\n\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     exit(1); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die by calling abort() to provide a core dump. */ | ||||
| 
 | ||||
| #define ABORT(x...) do { \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n    Stop location : " cRST "%s(), %s:%u\n\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     abort(); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die while also including the output of perror(). */ | ||||
| 
 | ||||
| #define PFATAL(x...) do { \ | ||||
|     fflush(stdout); \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-]  SYSTEM ERROR : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n    Stop location : " cRST "%s(), %s:%u\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     SAYF(cLRD "       OS message : " cRST "%s\n", strerror(errno)); \ | ||||
|     exit(1); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die with FAULT() or PFAULT() depending on the value of res (used to
 | ||||
|    interpret different failure modes for read(), write(), etc). */ | ||||
| 
 | ||||
| #define RPFATAL(res, x...) do { \ | ||||
|     if (res < 0) PFATAL(x); else FATAL(x); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Error-checking versions of read() and write() that call RPFATAL() as
 | ||||
|    appropriate. */ | ||||
| 
 | ||||
| #define ck_write(fd, buf, len, fn) do { \ | ||||
|     u32 _len = (len); \ | ||||
|     s32 _res = write(fd, buf, _len); \ | ||||
|     if (_res != _len) RPFATAL(_res, "Short write to %s", fn); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| #define ck_read(fd, buf, len, fn) do { \ | ||||
|     u32 _len = (len); \ | ||||
|     s32 _res = read(fd, buf, _len); \ | ||||
|     if (_res != _len) RPFATAL(_res, "Short read from %s", fn); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| #endif /* ! _HAVE_DEBUG_H */ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - debug / error handling macros | ||||
|    -------------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_DEBUG_H | ||||
| #define _HAVE_DEBUG_H | ||||
| 
 | ||||
| #include <errno.h> | ||||
| 
 | ||||
| #include "types.h" | ||||
| #include "config.h" | ||||
| 
 | ||||
| /*******************
 | ||||
|  * Terminal colors * | ||||
|  *******************/ | ||||
| 
 | ||||
| #ifdef USE_COLOR | ||||
| 
 | ||||
| #  define cBLK "\x1b[0;30m" | ||||
| #  define cRED "\x1b[0;31m" | ||||
| #  define cGRN "\x1b[0;32m" | ||||
| #  define cBRN "\x1b[0;33m" | ||||
| #  define cBLU "\x1b[0;34m" | ||||
| #  define cMGN "\x1b[0;35m" | ||||
| #  define cCYA "\x1b[0;36m" | ||||
| #  define cLGR "\x1b[0;37m" | ||||
| #  define cGRA "\x1b[1;90m" | ||||
| #  define cLRD "\x1b[1;91m" | ||||
| #  define cLGN "\x1b[1;92m" | ||||
| #  define cYEL "\x1b[1;93m" | ||||
| #  define cLBL "\x1b[1;94m" | ||||
| #  define cPIN "\x1b[1;95m" | ||||
| #  define cLCY "\x1b[1;96m" | ||||
| #  define cBRI "\x1b[1;97m" | ||||
| #  define cRST "\x1b[0m" | ||||
| 
 | ||||
| #  define bgBLK "\x1b[40m" | ||||
| #  define bgRED "\x1b[41m" | ||||
| #  define bgGRN "\x1b[42m" | ||||
| #  define bgBRN "\x1b[43m" | ||||
| #  define bgBLU "\x1b[44m" | ||||
| #  define bgMGN "\x1b[45m" | ||||
| #  define bgCYA "\x1b[46m" | ||||
| #  define bgLGR "\x1b[47m" | ||||
| #  define bgGRA "\x1b[100m" | ||||
| #  define bgLRD "\x1b[101m" | ||||
| #  define bgLGN "\x1b[102m" | ||||
| #  define bgYEL "\x1b[103m" | ||||
| #  define bgLBL "\x1b[104m" | ||||
| #  define bgPIN "\x1b[105m" | ||||
| #  define bgLCY "\x1b[106m" | ||||
| #  define bgBRI "\x1b[107m" | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| #  define cBLK "" | ||||
| #  define cRED "" | ||||
| #  define cGRN "" | ||||
| #  define cBRN "" | ||||
| #  define cBLU "" | ||||
| #  define cMGN "" | ||||
| #  define cCYA "" | ||||
| #  define cLGR "" | ||||
| #  define cGRA "" | ||||
| #  define cLRD "" | ||||
| #  define cLGN "" | ||||
| #  define cYEL "" | ||||
| #  define cLBL "" | ||||
| #  define cPIN "" | ||||
| #  define cLCY "" | ||||
| #  define cBRI "" | ||||
| #  define cRST "" | ||||
| 
 | ||||
| #  define bgBLK "" | ||||
| #  define bgRED "" | ||||
| #  define bgGRN "" | ||||
| #  define bgBRN "" | ||||
| #  define bgBLU "" | ||||
| #  define bgMGN "" | ||||
| #  define bgCYA "" | ||||
| #  define bgLGR "" | ||||
| #  define bgGRA "" | ||||
| #  define bgLRD "" | ||||
| #  define bgLGN "" | ||||
| #  define bgYEL "" | ||||
| #  define bgLBL "" | ||||
| #  define bgPIN "" | ||||
| #  define bgLCY "" | ||||
| #  define bgBRI "" | ||||
| 
 | ||||
| #endif /* ^USE_COLOR */ | ||||
| 
 | ||||
| /*************************
 | ||||
|  * Box drawing sequences * | ||||
|  *************************/ | ||||
| 
 | ||||
| #ifdef FANCY_BOXES | ||||
| 
 | ||||
| #  define SET_G1   "\x1b)0"       /* Set G1 for box drawing    */ | ||||
| #  define RESET_G1 "\x1b)B"       /* Reset G1 to ASCII         */ | ||||
| #  define bSTART   "\x0e"         /* Enter G1 drawing mode     */ | ||||
| #  define bSTOP    "\x0f"         /* Leave G1 drawing mode     */ | ||||
| #  define bH       "q"            /* Horizontal line           */ | ||||
| #  define bV       "x"            /* Vertical line             */ | ||||
| #  define bLT      "l"            /* Left top corner           */ | ||||
| #  define bRT      "k"            /* Right top corner          */ | ||||
| #  define bLB      "m"            /* Left bottom corner        */ | ||||
| #  define bRB      "j"            /* Right bottom corner       */ | ||||
| #  define bX       "n"            /* Cross                     */ | ||||
| #  define bVR      "t"            /* Vertical, branch right    */ | ||||
| #  define bVL      "u"            /* Vertical, branch left     */ | ||||
| #  define bHT      "v"            /* Horizontal, branch top    */ | ||||
| #  define bHB      "w"            /* Horizontal, branch bottom */ | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| #  define SET_G1   "" | ||||
| #  define RESET_G1 "" | ||||
| #  define bSTART   "" | ||||
| #  define bSTOP    "" | ||||
| #  define bH       "-" | ||||
| #  define bV       "|" | ||||
| #  define bLT      "+" | ||||
| #  define bRT      "+" | ||||
| #  define bLB      "+" | ||||
| #  define bRB      "+" | ||||
| #  define bX       "+" | ||||
| #  define bVR      "+" | ||||
| #  define bVL      "+" | ||||
| #  define bHT      "+" | ||||
| #  define bHB      "+" | ||||
| 
 | ||||
| #endif /* ^FANCY_BOXES */ | ||||
| 
 | ||||
| /***********************
 | ||||
|  * Misc terminal codes * | ||||
|  ***********************/ | ||||
| 
 | ||||
| #define TERM_HOME     "\x1b[H" | ||||
| #define TERM_CLEAR    TERM_HOME "\x1b[2J" | ||||
| #define cEOL          "\x1b[0K" | ||||
| #define CURSOR_HIDE   "\x1b[?25l" | ||||
| #define CURSOR_SHOW   "\x1b[?25h" | ||||
| 
 | ||||
| /************************
 | ||||
|  * Debug & error macros * | ||||
|  ************************/ | ||||
| 
 | ||||
| /* Just print stuff to the appropriate stream. */ | ||||
| 
 | ||||
| #ifdef MESSAGES_TO_STDOUT | ||||
| #  define SAYF(x...)    printf(x) | ||||
| #else  | ||||
| #  define SAYF(x...)    fprintf(stderr, x) | ||||
| #endif /* ^MESSAGES_TO_STDOUT */ | ||||
| 
 | ||||
| /* Show a prefixed warning. */ | ||||
| 
 | ||||
| #define WARNF(x...) do { \ | ||||
|     SAYF(cYEL "[!] " cBRI "WARNING: " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed "doing something" message. */ | ||||
| 
 | ||||
| #define ACTF(x...) do { \ | ||||
|     SAYF(cLBL "[*] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed "success" message. */ | ||||
| 
 | ||||
| #define OKF(x...) do { \ | ||||
|     SAYF(cLGN "[+] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Show a prefixed fatal error message (not used in afl). */ | ||||
| 
 | ||||
| #define BADF(x...) do { \ | ||||
|     SAYF(cLRD "\n[-] " cRST x); \ | ||||
|     SAYF(cRST "\n"); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die with a verbose non-OS fatal error message. */ | ||||
| 
 | ||||
| #define FATAL(x...) do { \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n         Location : " cRST "%s(), %s:%u\n\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     exit(1); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die by calling abort() to provide a core dump. */ | ||||
| 
 | ||||
| #define ABORT(x...) do { \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n    Stop location : " cRST "%s(), %s:%u\n\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     abort(); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die while also including the output of perror(). */ | ||||
| 
 | ||||
| #define PFATAL(x...) do { \ | ||||
|     fflush(stdout); \ | ||||
|     SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-]  SYSTEM ERROR : " \ | ||||
|          cBRI x); \ | ||||
|     SAYF(cLRD "\n    Stop location : " cRST "%s(), %s:%u\n", \ | ||||
|          __FUNCTION__, __FILE__, __LINE__); \ | ||||
|     SAYF(cLRD "       OS message : " cRST "%s\n", strerror(errno)); \ | ||||
|     exit(1); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Die with FAULT() or PFAULT() depending on the value of res (used to
 | ||||
|    interpret different failure modes for read(), write(), etc). */ | ||||
| 
 | ||||
| #define RPFATAL(res, x...) do { \ | ||||
|     if (res < 0) PFATAL(x); else FATAL(x); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| /* Error-checking versions of read() and write() that call RPFATAL() as
 | ||||
|    appropriate. */ | ||||
| 
 | ||||
| #define ck_write(fd, buf, len, fn) do { \ | ||||
|     u32 _len = (len); \ | ||||
|     s32 _res = write(fd, buf, _len); \ | ||||
|     if (_res != _len) RPFATAL(_res, "Short write to %s", fn); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| #define ck_read(fd, buf, len, fn) do { \ | ||||
|     u32 _len = (len); \ | ||||
|     s32 _res = read(fd, buf, _len); \ | ||||
|     if (_res != _len) RPFATAL(_res, "Short read from %s", fn); \ | ||||
|   } while (0) | ||||
| 
 | ||||
| #endif /* ! _HAVE_DEBUG_H */ | ||||
|  | ||||
| @ -1,111 +1,111 @@ | ||||
| /*
 | ||||
|   Copyright 2016 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - hashing function | ||||
|    ------------------------------------- | ||||
| 
 | ||||
|    The hash32() function is a variant of MurmurHash3, a good | ||||
|    non-cryptosafe hashing function developed by Austin Appleby. | ||||
| 
 | ||||
|    For simplicity, this variant does *NOT* accept buffer lengths | ||||
|    that are not divisible by 8 bytes. The 32-bit version is otherwise | ||||
|    similar to the original; the 64-bit one is a custom hack with | ||||
|    mostly-unproven properties. | ||||
| 
 | ||||
|    Austin's original code is public domain. | ||||
| 
 | ||||
|    Other code written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_HASH_H | ||||
| #define _HAVE_HASH_H | ||||
| 
 | ||||
| #include "types.h" | ||||
| 
 | ||||
| #ifdef __x86_64__ | ||||
| 
 | ||||
| #define ROL64(_x, _r)  ((((u64)(_x)) << (_r)) | (((u64)(_x)) >> (64 - (_r)))) | ||||
| 
 | ||||
| static inline u32 hash32(const void* key, u32 len, u32 seed) { | ||||
| 
 | ||||
|   const u64* data = (u64*)key; | ||||
|   u64 h1 = seed ^ len; | ||||
| 
 | ||||
|   len >>= 3; | ||||
| 
 | ||||
|   while (len--) { | ||||
| 
 | ||||
|     u64 k1 = *data++; | ||||
| 
 | ||||
|     k1 *= 0x87c37b91114253d5ULL; | ||||
|     k1  = ROL64(k1, 31); | ||||
|     k1 *= 0x4cf5ad432745937fULL; | ||||
| 
 | ||||
|     h1 ^= k1; | ||||
|     h1  = ROL64(h1, 27); | ||||
|     h1  = h1 * 5 + 0x52dce729; | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   h1 ^= h1 >> 33; | ||||
|   h1 *= 0xff51afd7ed558ccdULL; | ||||
|   h1 ^= h1 >> 33; | ||||
|   h1 *= 0xc4ceb9fe1a85ec53ULL; | ||||
|   h1 ^= h1 >> 33; | ||||
| 
 | ||||
|   return h1; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| #else  | ||||
| 
 | ||||
| #define ROL32(_x, _r)  ((((u32)(_x)) << (_r)) | (((u32)(_x)) >> (32 - (_r)))) | ||||
| 
 | ||||
| static inline u32 hash32(const void* key, u32 len, u32 seed) { | ||||
| 
 | ||||
|   const u32* data  = (u32*)key; | ||||
|   u32 h1 = seed ^ len; | ||||
| 
 | ||||
|   len >>= 2; | ||||
| 
 | ||||
|   while (len--) { | ||||
| 
 | ||||
|     u32 k1 = *data++; | ||||
| 
 | ||||
|     k1 *= 0xcc9e2d51; | ||||
|     k1  = ROL32(k1, 15); | ||||
|     k1 *= 0x1b873593; | ||||
| 
 | ||||
|     h1 ^= k1; | ||||
|     h1  = ROL32(h1, 13); | ||||
|     h1  = h1 * 5 + 0xe6546b64; | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   h1 ^= h1 >> 16; | ||||
|   h1 *= 0x85ebca6b; | ||||
|   h1 ^= h1 >> 13; | ||||
|   h1 *= 0xc2b2ae35; | ||||
|   h1 ^= h1 >> 16; | ||||
| 
 | ||||
|   return h1; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| #endif /* ^__x86_64__ */ | ||||
| 
 | ||||
| #endif /* !_HAVE_HASH_H */ | ||||
| /*
 | ||||
|   Copyright 2016 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - hashing function | ||||
|    ------------------------------------- | ||||
| 
 | ||||
|    The hash32() function is a variant of MurmurHash3, a good | ||||
|    non-cryptosafe hashing function developed by Austin Appleby. | ||||
| 
 | ||||
|    For simplicity, this variant does *NOT* accept buffer lengths | ||||
|    that are not divisible by 8 bytes. The 32-bit version is otherwise | ||||
|    similar to the original; the 64-bit one is a custom hack with | ||||
|    mostly-unproven properties. | ||||
| 
 | ||||
|    Austin's original code is public domain. | ||||
| 
 | ||||
|    Other code written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_HASH_H | ||||
| #define _HAVE_HASH_H | ||||
| 
 | ||||
| #include "types.h" | ||||
| 
 | ||||
| #ifdef __x86_64__ | ||||
| 
 | ||||
| #define ROL64(_x, _r)  ((((u64)(_x)) << (_r)) | (((u64)(_x)) >> (64 - (_r)))) | ||||
| 
 | ||||
| static inline u32 hash32(const void* key, u32 len, u32 seed) { | ||||
| 
 | ||||
|   const u64* data = (u64*)key; | ||||
|   u64 h1 = seed ^ len; | ||||
| 
 | ||||
|   len >>= 3; | ||||
| 
 | ||||
|   while (len--) { | ||||
| 
 | ||||
|     u64 k1 = *data++; | ||||
| 
 | ||||
|     k1 *= 0x87c37b91114253d5ULL; | ||||
|     k1  = ROL64(k1, 31); | ||||
|     k1 *= 0x4cf5ad432745937fULL; | ||||
| 
 | ||||
|     h1 ^= k1; | ||||
|     h1  = ROL64(h1, 27); | ||||
|     h1  = h1 * 5 + 0x52dce729; | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   h1 ^= h1 >> 33; | ||||
|   h1 *= 0xff51afd7ed558ccdULL; | ||||
|   h1 ^= h1 >> 33; | ||||
|   h1 *= 0xc4ceb9fe1a85ec53ULL; | ||||
|   h1 ^= h1 >> 33; | ||||
| 
 | ||||
|   return h1; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| #else  | ||||
| 
 | ||||
| #define ROL32(_x, _r)  ((((u32)(_x)) << (_r)) | (((u32)(_x)) >> (32 - (_r)))) | ||||
| 
 | ||||
| static inline u32 hash32(const void* key, u32 len, u32 seed) { | ||||
| 
 | ||||
|   const u32* data  = (u32*)key; | ||||
|   u32 h1 = seed ^ len; | ||||
| 
 | ||||
|   len >>= 2; | ||||
| 
 | ||||
|   while (len--) { | ||||
| 
 | ||||
|     u32 k1 = *data++; | ||||
| 
 | ||||
|     k1 *= 0xcc9e2d51; | ||||
|     k1  = ROL32(k1, 15); | ||||
|     k1 *= 0x1b873593; | ||||
| 
 | ||||
|     h1 ^= k1; | ||||
|     h1  = ROL32(h1, 13); | ||||
|     h1  = h1 * 5 + 0xe6546b64; | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   h1 ^= h1 >> 16; | ||||
|   h1 *= 0x85ebca6b; | ||||
|   h1 ^= h1 >> 13; | ||||
|   h1 *= 0xc2b2ae35; | ||||
|   h1 ^= h1 >> 16; | ||||
| 
 | ||||
|   return h1; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| #endif /* ^__x86_64__ */ | ||||
| 
 | ||||
| #endif /* !_HAVE_HASH_H */ | ||||
|  | ||||
| @ -1,45 +1,45 @@ | ||||
| /*
 | ||||
|   Copyright 2014 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - a trivial program to test the build | ||||
|    -------------------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| int main(int argc, char** argv) { | ||||
| 
 | ||||
|   char buf[8]; | ||||
| 
 | ||||
|   if (read(0, buf, 8) < 1) { | ||||
|     printf("Hum?\n"); | ||||
|     exit(1); | ||||
|   } | ||||
| 
 | ||||
|   if (buf[0] == '0') | ||||
|     printf("Looks like a zero to me!\n"); | ||||
|   else | ||||
|     printf("A non-zero value? How quaint!\n"); | ||||
| 
 | ||||
|   exit(0); | ||||
| 
 | ||||
| } | ||||
| /*
 | ||||
|   Copyright 2014 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - a trivial program to test the build | ||||
|    -------------------------------------------------------- | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| int main(int argc, char** argv) { | ||||
| 
 | ||||
|   char buf[8]; | ||||
| 
 | ||||
|   if (read(0, buf, 8) < 1) { | ||||
|     printf("Hum?\n"); | ||||
|     exit(1); | ||||
|   } | ||||
| 
 | ||||
|   if (buf[0] == '0') | ||||
|     printf("Looks like a zero to me!\n"); | ||||
|   else | ||||
|     printf("A non-zero value? How quaint!\n"); | ||||
| 
 | ||||
|   exit(0); | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -1,41 +1,41 @@ | ||||
| /*
 | ||||
|   Copyright 2019 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - a trivial program to test libFuzzer target fuzzing. | ||||
|    ------------------------------------------------------------------------ | ||||
| 
 | ||||
|    Initially written and maintained by Michal Zalewski. | ||||
| */ | ||||
| 
 | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| // TODO(metzman): Create a test/ directory to store this and other similar
 | ||||
| // files.
 | ||||
| int LLVMFuzzerTestOneInput(uint8_t* buf, size_t size) { | ||||
|   if (size < 2) | ||||
|     return 0; | ||||
| 
 | ||||
|   if (buf[0] == '0') | ||||
|     printf("Looks like a zero to me!\n"); | ||||
|   else | ||||
|     printf("A non-zero value? How quaint!\n"); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
| /*
 | ||||
|   Copyright 2019 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - a trivial program to test libFuzzer target fuzzing. | ||||
|    ------------------------------------------------------------------------ | ||||
| 
 | ||||
|    Initially written and maintained by Michal Zalewski. | ||||
| */ | ||||
| 
 | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| // TODO(metzman): Create a test/ directory to store this and other similar
 | ||||
| // files.
 | ||||
| int LLVMFuzzerTestOneInput(uint8_t* buf, size_t size) { | ||||
|   if (size < 2) | ||||
|     return 0; | ||||
| 
 | ||||
|   if (buf[0] == '0') | ||||
|     printf("Looks like a zero to me!\n"); | ||||
|   else | ||||
|     printf("A non-zero value? How quaint!\n"); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| @ -1,94 +1,94 @@ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - type definitions and minor macros | ||||
|    ------------------------------------------------------ | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_TYPES_H | ||||
| #define _HAVE_TYPES_H | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| typedef uint8_t  u8; | ||||
| typedef uint16_t u16; | ||||
| typedef uint32_t u32; | ||||
| 
 | ||||
| /*
 | ||||
| 
 | ||||
|    Ugh. There is an unintended compiler / glibc #include glitch caused by | ||||
|    combining the u64 type an %llu in format strings, necessitating a workaround. | ||||
| 
 | ||||
|    In essence, the compiler is always looking for 'unsigned long long' for %llu. | ||||
|    On 32-bit systems, the u64 type (aliased to uint64_t) is expanded to | ||||
|    'unsigned long long' in <bits/types.h>, so everything checks out. | ||||
| 
 | ||||
|    But on 64-bit systems, it is #ifdef'ed in the same file as 'unsigned long'. | ||||
|    Now, it only happens in circumstances where the type happens to have the | ||||
|    expected bit width, *but* the compiler does not know that... and complains | ||||
|    about 'unsigned long' being unsafe to pass to %llu. | ||||
| 
 | ||||
|  */ | ||||
| 
 | ||||
| #ifdef __x86_64__ | ||||
| typedef unsigned long long u64; | ||||
| #else | ||||
| typedef uint64_t u64; | ||||
| #endif /* ^__x86_64__ */ | ||||
| 
 | ||||
| typedef int8_t   s8; | ||||
| typedef int16_t  s16; | ||||
| typedef int32_t  s32; | ||||
| typedef int64_t  s64; | ||||
| 
 | ||||
| #ifndef MIN | ||||
| #  define MIN(_a,_b) ((_a) > (_b) ? (_b) : (_a)) | ||||
| #  define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b)) | ||||
| #endif /* !MIN */ | ||||
| 
 | ||||
| #define SWAP16(_x) ({ \ | ||||
|     u16 _ret = (_x); \ | ||||
|     (u16)((_ret << 8) | (_ret >> 8)); \ | ||||
|   }) | ||||
| 
 | ||||
| #define SWAP32(_x) ({ \ | ||||
|     u32 _ret = (_x); \ | ||||
|     (u32)((_ret << 24) | (_ret >> 24) | \ | ||||
|           ((_ret << 8) & 0x00FF0000) | \ | ||||
|           ((_ret >> 8) & 0x0000FF00)); \ | ||||
|   }) | ||||
| 
 | ||||
| #ifdef AFL_LLVM_PASS | ||||
| #  define AFL_R(x) (random() % (x)) | ||||
| #else | ||||
| #  define R(x) (random() % (x)) | ||||
| #endif /* ^AFL_LLVM_PASS */ | ||||
| 
 | ||||
| #define STRINGIFY_INTERNAL(x) #x | ||||
| #define STRINGIFY(x) STRINGIFY_INTERNAL(x) | ||||
| 
 | ||||
| #define MEM_BARRIER() \ | ||||
|   __asm__ volatile("" ::: "memory") | ||||
| 
 | ||||
| #define likely(_x)   __builtin_expect(!!(_x), 1) | ||||
| #define unlikely(_x)  __builtin_expect(!!(_x), 0) | ||||
| 
 | ||||
| #endif /* ! _HAVE_TYPES_H */ | ||||
| /*
 | ||||
|   Copyright 2013 Google LLC All rights reserved. | ||||
| 
 | ||||
|   Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|   you may not use this file except in compliance with the License. | ||||
|   You may obtain a copy of the License at: | ||||
| 
 | ||||
|     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| 
 | ||||
|   Unless required by applicable law or agreed to in writing, software | ||||
|   distributed under the License is distributed on an "AS IS" BASIS, | ||||
|   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|   See the License for the specific language governing permissions and | ||||
|   limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| /*
 | ||||
|    american fuzzy lop - type definitions and minor macros | ||||
|    ------------------------------------------------------ | ||||
| 
 | ||||
|    Written and maintained by Michal Zalewski <lcamtuf@google.com> | ||||
| */ | ||||
| 
 | ||||
| #ifndef _HAVE_TYPES_H | ||||
| #define _HAVE_TYPES_H | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| typedef uint8_t  u8; | ||||
| typedef uint16_t u16; | ||||
| typedef uint32_t u32; | ||||
| 
 | ||||
| /*
 | ||||
| 
 | ||||
|    Ugh. There is an unintended compiler / glibc #include glitch caused by | ||||
|    combining the u64 type an %llu in format strings, necessitating a workaround. | ||||
| 
 | ||||
|    In essence, the compiler is always looking for 'unsigned long long' for %llu. | ||||
|    On 32-bit systems, the u64 type (aliased to uint64_t) is expanded to | ||||
|    'unsigned long long' in <bits/types.h>, so everything checks out. | ||||
| 
 | ||||
|    But on 64-bit systems, it is #ifdef'ed in the same file as 'unsigned long'. | ||||
|    Now, it only happens in circumstances where the type happens to have the | ||||
|    expected bit width, *but* the compiler does not know that... and complains | ||||
|    about 'unsigned long' being unsafe to pass to %llu. | ||||
| 
 | ||||
|  */ | ||||
| 
 | ||||
| #ifdef __x86_64__ | ||||
| typedef unsigned long long u64; | ||||
| #else | ||||
| typedef uint64_t u64; | ||||
| #endif /* ^__x86_64__ */ | ||||
| 
 | ||||
| typedef int8_t   s8; | ||||
| typedef int16_t  s16; | ||||
| typedef int32_t  s32; | ||||
| typedef int64_t  s64; | ||||
| 
 | ||||
| #ifndef MIN | ||||
| #  define MIN(_a,_b) ((_a) > (_b) ? (_b) : (_a)) | ||||
| #  define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b)) | ||||
| #endif /* !MIN */ | ||||
| 
 | ||||
| #define SWAP16(_x) ({ \ | ||||
|     u16 _ret = (_x); \ | ||||
|     (u16)((_ret << 8) | (_ret >> 8)); \ | ||||
|   }) | ||||
| 
 | ||||
| #define SWAP32(_x) ({ \ | ||||
|     u32 _ret = (_x); \ | ||||
|     (u32)((_ret << 24) | (_ret >> 24) | \ | ||||
|           ((_ret << 8) & 0x00FF0000) | \ | ||||
|           ((_ret >> 8) & 0x0000FF00)); \ | ||||
|   }) | ||||
| 
 | ||||
| #ifdef AFL_LLVM_PASS | ||||
| #  define AFL_R(x) (random() % (x)) | ||||
| #else | ||||
| #  define R(x) (random() % (x)) | ||||
| #endif /* ^AFL_LLVM_PASS */ | ||||
| 
 | ||||
| #define STRINGIFY_INTERNAL(x) #x | ||||
| #define STRINGIFY(x) STRINGIFY_INTERNAL(x) | ||||
| 
 | ||||
| #define MEM_BARRIER() \ | ||||
|   __asm__ volatile("" ::: "memory") | ||||
| 
 | ||||
| #define likely(_x)   __builtin_expect(!!(_x), 1) | ||||
| #define unlikely(_x)  __builtin_expect(!!(_x), 0) | ||||
| 
 | ||||
| #endif /* ! _HAVE_TYPES_H */ | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								
					Loading…
					
					
				
		Reference in new issue