This document is shared with “Compiling and Installing The Python Component Hyperscan in Windows” written by huawei Cloud community security expert.

What is Hyperscan?

Hyperscan is a high-performance regular expression engine from Intel that can match multiple rules and objects in a single interface call. It supports multiple matching patterns, block patterns and stream patterns. Hyperscan is based on PCRE and is open source under BSD license.

Use time division 2 steps to achieve:

  • Step 1: Precompile the rule set by specifying the parameters of the rule set type: regular expression or text mode.

  • Step 2: Use the compiled rule set for matching, which can be specified as block or stream mode.

    Also note that the source code for the X86 and ARM versions is different. Download the x86 version from the official website (github.com/intel/hyper…). Cannot compile in ARM platform, arm version download address (github.com/tqltech/hyp…) .

The following uses the Windows X86 platform as an example to explain how to compile and install Hyperscan Python components:

Download and unzip Hyperscan-5.4.0.

2. Create build directory in Powershell and run CD build.

3. Run the cmake -g command to view the list of types supported by -g.

Cmake -g “Visual Studio 15 2017 Win64” -dbuild_shared_libs =on / orders.

  • The BOOST_ROOT parameter needs to be specified

5. Download the Boost source code and unzip it into the Hyperscan directory.

6, enter cmake -g “Visual Studio 15 2017 Win64” -d BOOST_ROOT=% CD %/… / boost_1_78_0 / – DBUILD_SHARED_LIBS = on… / orders.

  • The PCRE and SQlite3 are missing

7. Download the PCRE and SQLite source code and unzip it to the Hyperscan directory.

Cmake -g “Visual Studio 15 2017 Win64” -d BOOST_ROOT=% CD %/… / boost_1_78_0 / – PCRE_SOURCE DBUILD_SHARED_LIBS = on – D = % % / CD… / pcre – 8.45 /… / command, and a series of VS2017 project files are generated in the build directory.

9. Run the cmake -build. Command to compile the file, and then generate a series of files in the bin and lib directories.

  • Bin Directory List

  • List of lib directories

Download the Source code for Hyperscan Python (pypi.org/project/hyp…) The original setup.py file cannot be successfully installed on Windows. You need to modify the setup.py file as follows:

# -*- coding: utf-8 -*- from distutils.core import * module1 = Extension("hyperscan.hyperscan", include_dirs = ['src/hyperscan'], Libraries = ['hs', 'HS_runtime '], library_dirs = [r'../hyperscan-5.4.0/build/lib'], extra_compile_args = ['/Zi', '/Od'], extra_link_args = ['/DEBUG'], sources = ["src/hyperscan/hyperscanmodule.c"]) setup( name="hyperscan", Version ="0.2.0", package_dir = {" : 'SRC '}, packages = ['hyperscan'], package_data = {" : ['*']}, ext_modules=[module1] )Copy the code

11. Run the python setup.py install command to install python components. The hs_compile_lit_multi cannot be found.

12. Add the export function HS_compile_lit_multi in hs.def. Recompile the Hyperscan project and run the Python component installation script.

13. Run the Python test successfully. The following script indicates that the installation is successful:

import hyperscan
db = hyperscan.Database()
print(db)
Copy the code

  • Execute successfully

You can try the following leak-scanning services to see if the system has security risks: >>> Vulnerability scanning services

Click to follow, the first time to learn about Huawei cloud fresh technology ~