呼叫pcre庫實現掃瞄檔案敏感資訊實現多次匹配

2021-07-05 16:49:00 字數 1867 閱讀 4473



本文主要實現多次匹配,來掃瞄檔案內的敏感資訊(正則匹配),並算出掃瞄所需要的時間。新手,可能有些地方有錯誤。

#define pcre_static // 靜態庫編譯選項 

#include

#include

#include "pcre.h"

#include

#include

using namespace std;

#define oveccount 30 /* should be a multiple of 3 */ 

#define ebuflen 128 

#define buflen 1024 

int main()

char* data = null;

int filesize;

int result;

fseek(fp, 0, seek_end);

filesize = ftell(fp);

fseek(fp, 0, seek_set);

data = new char[filesize+1];

memset(data,0,filesize+1);

if (data == null)

result = fread(data, 1, filesize, fp);

if (result != filesize)

fclose(fp);

systemtime time;

getlocaltime(&time);//獲得當前本地時間

cout << time.wyear << ".";

cout << time.wmonth << ".";

cout << time.wday << " ";

cout << time.whour << ":";

cout << time.wminute << ":";

cout << time.wsecond << ":";

cout << time.wmilliseconds << endl;

re = pcre_compile(pattern,       // pattern, 輸入引數,將要被編譯的字串形式的正規表示式 

0,            // options, 輸入引數,用來指定編譯時的一些選項 

&error,       // errptr, 輸出引數,用來輸出錯誤資訊 

&erroffset,   // erroffset, 輸出引數,pattern中出錯位置的偏移量 

null);        // tableptr, 輸入引數,用來指定字元表,一般情況用null 

// 返回值:被編譯好的正規表示式的pcre內部表示結構 

if (re == null) do}

while (rc>0);

systemtime stime;

getlocaltime(&stime);//獲得當前本地時間

cout << stime.wyear << ".";

cout << stime.wmonth << ".";

cout << stime.wday << " ";

cout << stime.whour << ":";

cout << stime.wminute << ":";

cout << stime.wsecond << ":";

cout << stime.wmilliseconds << endl;

cout << "找到" << i-1 << "次敏感資訊";

pcre_free(re);// 編譯正規表示式re 釋放記憶體 

delete data;

system("pause");

}

C 呼叫C 庫檔案

winform下呼叫dll檔案,將dll銬入bin目錄下,using system.runtime.interopservices dllimport securitymaker.dll entrypoint security make public static extern void makes...

Nginx lua 實現呼叫 so檔案

本文給大家分享的是nginx結合lua 實現呼叫.so動態鏈結庫檔案的方法和示例,有需要的小夥伴可以參考下 最近在和智慧型硬體部門一起,做乙個室內定位的服務,該服務根據手機端傳過來的beacon裝置列表,根據一定的演算法計算出具體的商場,並將商場id和beason裝置列表作為引數,呼叫.so檔案中的...

c 如何呼叫lib檔案 靜態庫檔案

include includeusing namespace std int main 新建乙個能產生lib的工程檔案 includeclass mylib 產生好lib後,新建另外乙個工程引用lib 在vc 目錄中,包含目錄與庫目錄分別填寫上lib標頭檔案所在的位置以及lib檔案所在的位置,鏈結器...