diff options
author | u <u@noreply.codeberg.org> | 2020-11-11 03:32:05 +0100 |
---|---|---|
committer | u <u@noreply.codeberg.org> | 2020-11-11 03:32:05 +0100 |
commit | 359887b8afb8892f01f72a05ff63a88a6ffa9f4f (patch) | |
tree | 3e29683931748021dbcdfcf2d8e88541b221e082 /tool | |
parent | ab384049a1eda8c7676ef93771e0e040f08c880f (diff) | |
parent | b346040be73f9e28998fde6fc27467ff24c0abad (diff) | |
download | cloudflare-tor-359887b8afb8892f01f72a05ff63a88a6ffa9f4f.tar.lz cloudflare-tor-359887b8afb8892f01f72a05ff63a88a6ffa9f4f.tar.xz cloudflare-tor-359887b8afb8892f01f72a05ff63a88a6ffa9f4f.zip |
🙆
Diffstat (limited to 'tool')
22 files changed, 1863 insertions, 0 deletions
diff --git a/tool/PGListUtil/README.md b/tool/PGListUtil/README.md new file mode 100644 index 00000000..1fc882c8 --- /dev/null +++ b/tool/PGListUtil/README.md @@ -0,0 +1,6 @@ +### PGListUtil + +This tool is useful to convert `CIDR list` to `Range format`, or remove unnecessary lines (such as duplicated ranges) automatically. +The software was released in the [year 2010](https://live28.5ch.net/test/read.cgi/download/1268903774/10). + +Original author said: `You are free to modify or redistribute the source code` diff --git a/tool/PGListUtil/releases/PGListUtil.exe b/tool/PGListUtil/releases/PGListUtil.exe Binary files differnew file mode 100644 index 00000000..67fd1928 --- /dev/null +++ b/tool/PGListUtil/releases/PGListUtil.exe diff --git a/tool/PGListUtil/releases/PGListUtil_en.exe b/tool/PGListUtil/releases/PGListUtil_en.exe Binary files differnew file mode 100644 index 00000000..b8fe4508 --- /dev/null +++ b/tool/PGListUtil/releases/PGListUtil_en.exe diff --git a/tool/PGListUtil/releases/README.md b/tool/PGListUtil/releases/README.md new file mode 100644 index 00000000..fce57afb --- /dev/null +++ b/tool/PGListUtil/releases/README.md @@ -0,0 +1,10 @@ +### Original files + +- [PGListUtil.exe](https://codeberg.org/crimeflare/cloudflare-tor/raw/branch/master/tool/PGListUtil/releases/PGListUtil.exe) +- [readme.txt](readme.txt) + + + +### English + +- [PGListUtil_en.exe](https://codeberg.org/crimeflare/cloudflare-tor/raw/branch/master/tool/PGListUtil/releases/PGListUtil_en.exe) diff --git a/tool/PGListUtil/releases/readme.txt b/tool/PGListUtil/releases/readme.txt new file mode 100644 index 00000000..3bd0d70c --- /dev/null +++ b/tool/PGListUtil/releases/readme.txt @@ -0,0 +1,138 @@ +
+
+PeerGuardianŒü‚¯‚Éì‚ç‚ꂽƒeƒLƒXƒgŒ`Ž®‚ÌƒŠƒXƒgƒtƒ@ƒCƒ‹‚ð
+ðŒ‚ɇ‚킹‚ÄV‚µ‚¢ƒtƒ@ƒCƒ‹‚Éo—Í‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·
+
+•¡”‚ÌƒŠƒXƒgƒtƒ@ƒCƒ‹‚ð‚ЂƂ‚ɂ܂Ƃ߂Äo—Í‚·‚邱‚Æ‚à‚Å‚«‚Ü‚·
+
+
+===================================================================================
+
+
+ƒRƒ}ƒ“ƒhƒ‰ƒCƒ“ˆø”‚Ƀtƒ@ƒCƒ‹ƒpƒX‚ðŽw’肵‚Ä‹N“®‚·‚邯AŽ©“®“I‚É“ü—̓tƒ@ƒCƒ‹ƒpƒX‚ɒljÁ‚Å‚«‚Ü‚·
+•¡”‚̃pƒXŽw’è‚ɑΉž‚µ‚Ä‚¢‚Ü‚·
+
+ƒRƒ}ƒ“ƒh‚ÉŠÖ‚µ‚Ä‚Íu‘—‚é(SendTo)v‚ɃVƒ‡[ƒgƒJƒbƒg‚ð쬂µ‚ÄŽg—p‚·‚邱‚Æ‚ð‘z’肵‚Ä‚¢‚Ü‚·
+(‚¨Žè”‚Å‚·‚ªŽè“®‚Å쬂µ‚Ä‚‚¾‚³‚¢)
+
+ƒŠƒXƒgƒtƒ@ƒCƒ‹‚Å1s‚̃TƒCƒY‚ª1024ƒoƒCƒg‚ð’´‚¦‚邯³Šm‚È\•¶‰ðÍ‚ª‚Å‚«‚Ü‚¹‚ñ
+
+
+
+Ý’è‚͂ǂ±‚É‚à•Û‘¶‚µ‚È‚¢‚̂ŃAƒ“ƒCƒ“ƒXƒg[ƒ‹‚·‚éꇂ͂»‚̂܂Ü휂Ŗâ‘è‚ ‚è‚Ü‚¹‚ñ
+
+ƒ\[ƒXƒR[ƒh‚̉ü•Ï‚â“]Ú“™‚ÍŽ©—R‚És‚Á‚Ä‚‚ê‚Ä‚à\‚¢‚Ü‚¹‚ñ
+
+“–ƒ\ƒtƒg‚ÌŽg—p‚Í‚ ‚‚܂Ŏ©ŒÈÓ”C‚Å‚¨Šè‚¢‚µ‚Ü‚·
+
+“®ìŠÂ‹«‚Í(Šm”F‚µ‚Ä‚¢‚Ü‚¹‚ñ‚ª)Windows 2000ˆÈ~‚ÌWindows NTŒnOS
+“®ìŠm”F‚ÍWindodws XP SP3‚ł̂Ýs‚Á‚Ä‚¢‚Ü‚·
+
+
+===================================================================================
+
+
+Žå‚È‹@”\
+
+
+EƒLƒƒƒvƒVƒ‡ƒ“ƒtƒBƒ‹ƒ^[
+
+ ‘å•¶Žš‚Ƭ•¶Žš‚Í‹æ•Ê‚µ‚Ü‚¹‚ñ
+ œŠO‚Ƀ`ƒFƒbƒN‚ð“ü‚ê‚邯Aˆê’v‚µ‚½‚à‚Ì‚ðœŠO‚µ‚Äo—Í‚·‚邿‚¤‚ɂȂè‚Ü‚·
+ Œ¾‚¢•û‚ð•Ï‚¦‚ê‚Έê’v‚µ‚È‚¢‚à‚Ì‚ðo—Í‚·‚邿‚¤‚ɂȂè‚Ü‚·
+
+ ‰½‚à“ü—Í‚µ‚È‚¯‚ê‚΂±‚Ì‹@”\‚Í–³Œø‚ƂȂè‚Ü‚·
+
+
+EIP‚Ìd•¡‚ð‰ðÁ
+
+ ƒfƒtƒHƒ‹ƒg‚ÅŠJŽnIP‚ÆI—¹IP‚ªˆê’v‚·‚é‚à‚Ì‚ðo—Í‚µ‚Ü‚¹‚ñ
+ test1:1.2.3.4-5.6.7.8
+ test2:1.2.3.4-5.6.7.8 ¨ test1‚Ætest2‚̂ǂ¿‚ç‚©‚Ío—Í‚µ‚Ü‚¹‚ñ
+
+ ŠÔ‚Ɋ܂܂ê‚é‚à‚Ì‚Íd•¡‚Ì‘ÎÛŠO‚Æ‚µ‚Ä•’Ê‚Éo—Í‚µ‚Ü‚·
+ test1:1.2.3.4-5.6.7.100
+ test2:1.2.3.4-5.6.7.10 ¨ Ž–ŽÀãd•¡‚Å‚·‚ªtest2‚Ío—Í‚³‚ê‚Ü‚·
+
+
+Eƒ\[ƒg‹@”\
+
+ ƒLƒƒƒvƒVƒ‡ƒ“‚ÆIPƒAƒhƒŒƒX‚ÅƒŠƒXƒg‚ðƒ\[ƒg‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·
+ ‚±‚Ì“ñ‚‚̃\[ƒg‚Í•¹—p‚·‚邯ƒLƒƒƒvƒVƒ‡ƒ“—D¨‚̃\[ƒg‚ɂȂè‚Ü‚·
+ Žd—lãAd•¡IP‚ð‰ðÁ‚·‚éꇂÍIPƒAƒhƒŒƒX‚Ń\[ƒg‚ð—LŒø‚É‚µ‚½‚Ù‚¤‚ªŽg—pƒƒ‚ƒŠ‚ð‚È‚—}‚¦‚ç‚ê‚Ü‚·
+
+
+E•Û‘¶ƒ‚[ƒh
+
+ uã‘‚«vƒtƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡AˆÈ‘O‚̃tƒ@ƒCƒ‹‚Ì“à—e‚Í”jŠü‚³‚ê‚Ü‚·
+ u’Ç‹Lv@ƒtƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡AˆÈ‘O‚̃tƒ@ƒCƒ‹‚ÌI’[‚É’Ç‹L‚³‚ê‚Ü‚·
+ ‚¢‚¸‚ê‚àƒtƒ@ƒCƒ‹‚ª‘¶Ý‚µ‚È‚¢ê‡‚ÍV‚µ‚¢ƒtƒ@ƒCƒ‹‚ªì¬‚³‚ê‚Ü‚·
+
+
+Eƒ`ƒFƒbƒN‹@”\
+
+ ˆÈ‰º‚̂悤‚È‚ ‚肪‚¿‚ȃ~ƒX‚ðƒ`ƒFƒbƒN‚µ‚Ü‚·
+
+ \•¶ƒGƒ‰[
+ ƒLƒƒƒvƒVƒ‡ƒ“‚ÌÅŒã‚É : ‚ª–³‚¢
+ IPƒAƒhƒŒƒX‚É4Œ…ˆÈã‚Ì”Žš
+ . ‚Æ , ‚̊ԈႢ
+ IPƒAƒhƒŒƒXŠÔ‚Ì - ‚ª–³‚¢
+ ƒ}ƒXƒN•\‹L‚³‚ꂽIP(—á:0.0.0.0/24)
+ s––‚Ì•¶Žš
+
+ •s³‚ÈIPƒAƒhƒŒƒX
+ IPƒAƒhƒŒƒX‚É256ˆÈã‚Ì”Žš
+ ŠJŽnIP‚ªI—¹IP‚æ‚è‘å‚«‚¢
+
+
+EŽ©“®C•œ
+
+ ƒ`ƒFƒbƒNŽž‚Éu\•¶ƒGƒ‰[ (Ž©“®C•œ‰Â)v‚Æo‚½‚à‚Ì‚ÍAƒtƒ@ƒCƒ‹o—ÍŽž‚ÉŽ©“®“I‚ÉC•œA“WŠJ‚³‚ê‚Ü‚·
+ :”²‚¯A.‚Æ,‚̊ԈႢAƒ}ƒXƒN•\‹L‚³‚ꂽIP‚È‚Ç
+ ‚±‚ê‚ç‚É“–‚Ă͂܂Á‚Ä‚à”’l‚ª•s³‚Å‚ ‚ê‚΃Gƒ‰[‚ɂȂè‚Ü‚·
+
+
+‘¼‚ÍŠT‚˃EƒBƒ“ƒhƒE‚É‘‚©‚ê‚Ä‚¢‚é’Ê‚è‚Å‚·
+
+
+===================================================================================
+
+
+XV—š—ð
+
+
+ver0.7.0
+Ž©“®C•œ‹@”\‚ð’ljÁ
+ŽÀsƒƒjƒ…[‚Éuƒ`ƒFƒbƒNŒãAƒtƒ@ƒCƒ‹o—Ív‚ð’ljÁ (ƒGƒ‰[‚ªŒ©‚‚©‚Á‚½‚çƒtƒ@ƒCƒ‹o—Í‚ðs‚í‚È‚¢)
+ƒtƒ@ƒCƒ‹o—ÍŽž‚ÌIPƒAƒhƒŒƒX‚̃`ƒFƒbƒN‚ðÈ—ª (–ⓚ–³—p‚Åo—Í‚·‚邽‚ßuƒ`ƒFƒbƒNŒãAƒtƒ@ƒCƒ‹o—Ív‚ð„§)
+‚»‚Ì‘¼×‚©‚¢’²®
+
+
+ver0.6.1
+Ž‹ŠoƒXƒ^ƒCƒ‹‚ð“K—p
+“ü—̓tƒ@ƒCƒ‹’ljÁƒ_ƒCƒAƒƒO‚ÅAƒhƒ‰ƒCƒu’¼‰º‚æ‚è[‚¢ƒfƒBƒŒƒNƒgƒŠ‚Ńtƒ@ƒCƒ‹‚ð•¡”‘I‘ð‚µ‚½ê‡AƒŠƒXƒg‚ɳ‚µ‚’ljÁ‚Å‚«‚È‚©‚Á‚½•s‹ï‡‚ðC³
+
+
+ver0.6.0
+GUI‚ÌŒ©’¼‚µ
+ƒŠƒ\[ƒXƒGƒfƒBƒ^‚ðResEdit‚É•ÏX (ƒRƒ“ƒpƒCƒ‰‚ÍWindows SDK 6ˆÈ~‚Å•ÏX‚È‚µ)
+(0.5.0‚Ɋ܂܂ê‚éresƒtƒ@ƒCƒ‹‚ÍVC2002‚Å‘g‚ñ‚¾‚à‚Ì‚ðWindows SDK 6‚ŃRƒ“ƒpƒCƒ‹‚µ‚½‚à‚Ì)
+DLL‰»‚µ‚Ä‚¢‚½‹@”\‚ƃ`ƒFƒbƒN‹@”\‚ðUtil‚É“‡‚µACUI”Ń`ƒFƒbƒJ[‚Ì”z•z‚ð’âŽ~
+d•¡IP‰ðÁ‚̉”ۂðÝ’è‚Å‚«‚邿‚¤‚É‚µ‚½
+“ü—̓tƒ@ƒCƒ‹ƒŠƒXƒg‚Ì‘I‘ðƒAƒCƒeƒ€‚ðDeleteƒL[‚Å휂ł«‚邿‚¤‚É‚µ‚½
+‚»‚Ì‘¼×‚©‚¢’²®
+
+
+ver0.5.0
+–¼‘O‚ðPG2ListUtil‚©‚çPGListUtil‚É•ÏX
+WindowsƒlƒCƒeƒBƒu‚ɈÚs (.NET Framework‚Í•s—v‚ɂȂè‚Ü‚µ‚½)
+‹@”\‚̈ꕔ‚ðDLL‚ɈÚs
+•Û‘¶ƒ‚[ƒhu•Û‘¶‚µ‚È‚¢v‚ðíœ
+\•¶ƒGƒ‰[‚ð“f‚©‚È‚¢‚悤‚É‚µ‚½ (ƒ`ƒFƒbƒN‚ÍCUI”ł̃`ƒFƒbƒJ[‚ðŽg—p‚µ‚Ä‚‚¾‚³‚¢)
+ƒLƒƒƒvƒVƒ‡ƒ“ƒtƒBƒ‹ƒ^[‚ðAND‚ÆOR‚É•ª‚¯‚½ (¡Œã“¯Žž‚ÉŽg—p‚Å‚«‚邿‚¤‚É‚·‚é‰Â”\«‚à‚ ‚è‚Ü‚·)
+ƒLƒƒƒvƒVƒ‡ƒ“ƒtƒBƒ‹ƒ^[‚̳‹K•\Œ»‚ðíœ (¡ŒãŽÀ‘•‚·‚é‰Â”\«‚à‚ ‚è‚Ü‚·)
+ANDðŒ‚ÌŽd—l‚ð•ÏX (•¶Žš—ñ‚ªd‚Ȃ镔•ª‚àˆê’v‚·‚邿‚¤‚É‚µ‚½)
+ƒtƒ@ƒCƒ‹‚̃hƒ‰ƒbƒO•ƒhƒƒbƒv‚ð“ü—̓tƒ@ƒCƒ‹‚Æo—̓tƒ@ƒCƒ‹‚É•ª‚¯‚½
+
+
diff --git a/tool/PGListUtil/src/PGListUtil/PGListUtil.cpp b/tool/PGListUtil/src/PGListUtil/PGListUtil.cpp new file mode 100644 index 00000000..6ff52c40 --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/PGListUtil.cpp @@ -0,0 +1,9 @@ +#include <windows.h>
+#include "WindowMain.h"
+#include "resource.h"
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
+ WindowMain::Init(hInstance);
+ DialogBox(hInstance, (LPTSTR)IDD_MAIN, NULL, (DLGPROC)(WindowMain::DlgProcMain));
+ return 0;
+}
diff --git a/tool/PGListUtil/src/PGListUtil/PGListUtil.exe.manifest b/tool/PGListUtil/src/PGListUtil/PGListUtil.exe.manifest new file mode 100644 index 00000000..278d30f4 --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/PGListUtil.exe.manifest @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity
+ version="1.0.0.0"
+ processorArchitecture="X86"
+ name="*.*.PGListUtil"
+ type="win32"
+ />
+ <description>Description</description>
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.Windows.Common-Controls"
+ version="6.0.0.0"
+ processorArchitecture="X86"
+ publicKeyToken="6595b64144ccf1df"
+ language="*"
+ />
+ </dependentAssembly>
+ </dependency>
+</assembly>
diff --git a/tool/PGListUtil/src/PGListUtil/PGListUtil.h b/tool/PGListUtil/src/PGListUtil/PGListUtil.h new file mode 100644 index 00000000..cbe04418 --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/PGListUtil.h @@ -0,0 +1,6 @@ +#ifndef PGLISTUTIL_H
+#define PGLISTUTIL_H
+
+extern HINSTANCE hInst;
+
+#endif // PGLISTUTIL_H
diff --git a/tool/PGListUtil/src/PGListUtil/ThreadExecute.cpp b/tool/PGListUtil/src/PGListUtil/ThreadExecute.cpp new file mode 100644 index 00000000..277ec42f --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/ThreadExecute.cpp @@ -0,0 +1,191 @@ +#include "WindowMain.h"
+#include "resource.h"
+#include "../common/CErrorList.h"
+#include "../common/CIpList.h"
+
+namespace ThreadExecute {
+
+namespace {
+
+TCHAR g_tsTemp[STRLEN_TEMP];
+TCHAR g_tsPath[STRLEN_PATH];
+
+TCHAR g_tsFailedFileRead[STRLEN_RESULT];
+TCHAR g_tsFailedFileWrite[STRLEN_RESULT];
+TCHAR g_tsOutputComplete[STRLEN_RESULT];
+TCHAR g_tsCheckComplete[STRLEN_RESULT];
+TCHAR g_tsFoundError[STRLEN_RESULT];
+TCHAR g_tsNotFoundError[STRLEN_RESULT];
+TCHAR g_tsErrorSyntax[STRLEN_RESULT];
+TCHAR g_tsErrorIp[STRLEN_RESULT];
+TCHAR g_tsErrorSyntaxRestorable[STRLEN_RESULT];
+
+CHAR *GetMBSfromWS(WCHAR *ws) {
+ int i = WideCharToMultiByte(CP_THREAD_ACP, 0, ws, -1, NULL, 0, NULL, NULL) + 1;
+ if(0 < i) {
+ CHAR *mbs = new CHAR[i];
+ if(!WideCharToMultiByte(CP_THREAD_ACP, 0, ws, -1, mbs, i, NULL, NULL)) {
+ delete[] mbs;
+ mbs = NULL;
+ }
+ return mbs;
+ } else {
+ return NULL;
+ }
+}
+
+char *ReleaseMBS(char *mbs) {
+ if(mbs) {
+ delete[] mbs;
+ mbs = NULL;
+ }
+ return mbs;
+}
+
+bool ExecCheckInfile(HWND hDlg) {
+ char *mbsPath;
+ int incomp = 0;
+ pglu::error::CErrorList errlist;
+
+ WindowMain::Edit_Result_SetText(hDlg, NULL);
+ int iInfileCount = WindowMain::ListView_Infile_GetItemCount(hDlg);
+ for(int iCountInfile = 0; iCountInfile < iInfileCount; ++iCountInfile) {
+ WindowMain::ListView_Infile_GetItemText(hDlg, iCountInfile, g_tsPath);
+ WindowMain::Edit_Result_AppendText(hDlg, g_tsPath);
+ mbsPath = GetMBSfromWS(g_tsPath);
+ if(mbsPath && errlist.LoadListFile(mbsPath)) {
+ int iErrCount = errlist.Count();
+ if(0 < iErrCount) {
+ WindowMain::Edit_Result_AppendText(hDlg, g_tsFoundError);
+ lstrcpy(g_tsTemp, TEXT("\r\n"));
+ for(pglu::error::CError * err = errlist.GetNext(); err; err = errlist.GetNext()) {
+ switch(err->kind) {
+ case pglu::error::SYNTAX:
+ wsprintf(g_tsTemp + 2, g_tsErrorSyntax, err->line);
+ ++incomp;
+ break;
+ case pglu::error::IP:
+ wsprintf(g_tsTemp + 2, g_tsErrorIp, err->line);
+ ++incomp;
+ break;
+ case pglu::error::SYNTAX_RESTORABLE:
+ wsprintf(g_tsTemp + 2, g_tsErrorSyntaxRestorable, err->line);
+ break;
+ }
+ WindowMain::Edit_Result_AppendText(hDlg, g_tsTemp);
+ }
+ } else {
+ WindowMain::Edit_Result_AppendText(hDlg, g_tsNotFoundError);
+ }
+ mbsPath = ReleaseMBS(mbsPath);
+ } else {
+ WindowMain::Edit_Result_AppendText(hDlg, g_tsFailedFileRead);
+ ++incomp;
+ }
+ WindowMain::Edit_Result_AppendText(hDlg, TEXT("\r\n\r\n"));
+ errlist.Clear();
+ }
+ return (incomp == 0);
+}
+
+bool ExecOutput(HWND hDlg) {
+ bool succ = false;
+ char *mbsPath;
+ WindowMain::COption option;
+ pglu::ip::CIpList iplist;
+
+ // Ý’èŽæ“¾
+ WindowMain::GetOption(hDlg, &option);
+
+ // ƒtƒBƒ‹ƒ^Ý’è
+ WindowMain::Edit_Filter_GetText(hDlg, g_tsTemp);
+ if(0 < lstrlen(g_tsTemp)) {
+ char *mbsFilter = GetMBSfromWS(g_tsTemp);
+ if(mbsFilter) {
+ pglu::filter::EFilterMode filtMode = (option.filtAnd ? pglu::filter::AND : pglu::filter::OR);
+ iplist.SetFilter(mbsFilter, filtMode, option.filtDel);
+ mbsFilter = ReleaseMBS(mbsFilter);
+ }
+ }
+
+ // “ǂݞ‚Ý
+ int iInfileCount = WindowMain::ListView_Infile_GetItemCount(hDlg);
+ for(int iCountInfile = 0; iCountInfile < iInfileCount; ++iCountInfile) {
+ WindowMain::ListView_Infile_GetItemText(hDlg, iCountInfile, g_tsPath);
+ mbsPath = GetMBSfromWS(g_tsPath);
+ if(mbsPath) {
+ succ = iplist.LoadListFile(mbsPath);
+ mbsPath = ReleaseMBS(mbsPath);
+ if(!succ) {
+ // “ǂݞ‚ÝŽ¸”s
+ WindowMain::Edit_Result_SetText(hDlg, g_tsPath);
+ WindowMain::Edit_Result_SetText(hDlg, g_tsFailedFileRead);
+ return false;
+ }
+ }
+ }
+
+ // ƒ`ƒFƒbƒN@ƒ\[ƒg
+ iplist.CheckAndSort(option.sortCap, option.sortIp, option.delDupIp);
+
+ // ‘‚«o‚µ
+ WindowMain::Edit_Outfile_GetText(hDlg, g_tsPath);
+ mbsPath = GetMBSfromWS(g_tsPath);
+ if(mbsPath) {
+ succ = iplist.SaveListFile(mbsPath, option.saveAppend);
+ mbsPath = ReleaseMBS(mbsPath);
+ if(!succ) {
+ // ‘‚«ž‚ÝŽ¸”s
+ WindowMain::Edit_Result_SetText(hDlg, g_tsPath);
+ WindowMain::Edit_Result_SetText(hDlg, g_tsFailedFileWrite);
+ return false;
+ }
+ }
+
+ // ŽÀsŒ‹‰Ê
+ int iIpCount = iplist.Count();
+ int iIpCountDisabled = iplist.CountDisabled();
+ wsprintf(g_tsTemp, g_tsOutputComplete, iIpCount, iIpCountDisabled, iIpCount - iIpCountDisabled);
+ WindowMain::Edit_Result_SetText(hDlg, g_tsTemp);
+
+ return true;
+}
+
+} // namespace
+
+BOOL Init(HINSTANCE hInstance) {
+ LoadString(hInstance, IDS_FAILED_FILE_READ, g_tsFailedFileRead, STRLEN_RESULT);
+ LoadString(hInstance, IDS_FAILED_FILE_WRITE, g_tsFailedFileWrite, STRLEN_RESULT);
+ LoadString(hInstance, IDS_OUTPUT_COMPLETE, g_tsOutputComplete, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_COMPLETE, g_tsCheckComplete, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_FOUND_ERROR, g_tsFoundError, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_NOTFOUND_ERROR, g_tsNotFoundError, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_ERROR_SYNTAX, g_tsErrorSyntax, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_ERROR_IP, g_tsErrorIp, STRLEN_RESULT);
+ LoadString(hInstance, IDS_CHECK_ERROR_SYNTAX_RESTORABLE, g_tsErrorSyntaxRestorable, STRLEN_RESULT);
+ return TRUE;
+}
+
+DWORD WINAPI ThreadExecCheckInfile(LPVOID lpParam) {
+ HWND hDlg = (HWND)lpParam;
+ ExecCheckInfile(hDlg);
+ WindowMain::Dlg_Executing(hDlg, FALSE);
+ ExitThread(TRUE);
+}
+
+DWORD WINAPI ThreadExecOutput(LPVOID lpParam) {
+ HWND hDlg = (HWND)lpParam;
+ ExecOutput(hDlg);
+ WindowMain::Dlg_Executing(hDlg, FALSE);
+ ExitThread(TRUE);
+}
+
+DWORD WINAPI ThreadExecCheckAndOutput(LPVOID lpParam) {
+ HWND hDlg = (HWND)lpParam;
+ if(ExecCheckInfile(hDlg))
+ ExecOutput(hDlg);
+ WindowMain::Dlg_Executing(hDlg, FALSE);
+ ExitThread(TRUE);
+}
+
+} // namespace ThreadExecute
diff --git a/tool/PGListUtil/src/PGListUtil/ThreadExecute.h b/tool/PGListUtil/src/PGListUtil/ThreadExecute.h new file mode 100644 index 00000000..b34b6253 --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/ThreadExecute.h @@ -0,0 +1,16 @@ +#ifndef THREADEXECUTE_H
+#define THREADEXECUTE_H
+
+#include <windows.h>
+
+namespace ThreadExecute {
+
+BOOL Init(HINSTANCE hInstance);
+
+DWORD WINAPI ThreadExecCheckInfile(LPVOID);
+DWORD WINAPI ThreadExecOutput(LPVOID);
+DWORD WINAPI ThreadExecCheckAndOutput(LPVOID);
+
+}
+
+#endif // THREADEXECUTE_H
diff --git a/tool/PGListUtil/src/PGListUtil/WindowMain.cpp b/tool/PGListUtil/src/PGListUtil/WindowMain.cpp new file mode 100644 index 00000000..67918d8c --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/WindowMain.cpp @@ -0,0 +1,440 @@ +#include "stdafx.h"
+#include "WindowMain.h"
+#include "resource.h"
+#include "ThreadExecute.h"
+
+#define WM_USER_EXECUTING WM_USER
+
+namespace WindowMain {
+
+namespace {
+
+TCHAR g_tsTempA[STRLEN_TEMP];
+TCHAR g_tsTempB[STRLEN_TEMP];
+
+HINSTANCE g_hInst;
+
+OPENFILENAME g_ofn = { 0 };
+TCHAR g_tsExpFilt[STRLEN_EXPFILT];
+TCHAR g_tsPath[STRLEN_PATH];
+
+MENUITEMINFO g_mii = { 0 };
+
+TCHAR g_tsSetInfile[STRLEN_RESULT];
+TCHAR g_tsSetOutfile[STRLEN_RESULT];
+TCHAR g_tsExecuting[STRLEN_RESULT];
+
+WNDPROC WndProcListInfileDef;
+WNDPROC WndProcEditOutfileDef;
+
+//--------------------------------------
+// Function
+//--------------------------------------
+
+void Menu_SwapIfChecked(HMENU hMenuMain, int nItemSrc, int nItemCmp) {
+ GetMenuItemInfo(hMenuMain, nItemCmp, FALSE, &g_mii);
+ if(g_mii.fState & MFS_CHECKED) {
+ g_mii.fState = MFS_CHECKED;
+ SetMenuItemInfo(hMenuMain, nItemSrc, FALSE, &g_mii);
+ g_mii.fState = MFS_UNCHECKED;
+ SetMenuItemInfo(hMenuMain, nItemCmp, FALSE, &g_mii);
+ }
+}
+
+void ListView_Infile_AddItem(HWND hListInfile, LPTSTR tsPath, LPTSTR tsFile) {
+ LVITEM lvItem = { 0 };
+ lvItem.mask = LVIF_TEXT;
+
+ lvItem.iSubItem = 0;
+ lvItem.pszText = tsPath;
+ lvItem.iItem = ListView_InsertItem(hListInfile, &lvItem);
+
+ lvItem.iSubItem = 1;
+ lvItem.pszText = tsFile;
+ ListView_SetItem(hListInfile, &lvItem);
+}
+
+void ListView_Infile_AddItem(HWND hListInfile, LPTSTR tsPath) {
+ LPTSTR tsFile = tsPath;
+ for(LPTSTR tsP = tsFile; *tsP != TEXT('\0'); ++tsP)
+ if(*tsP == TEXT('\\'))
+ tsFile = tsP;
+ ListView_Infile_AddItem(hListInfile, tsPath, tsFile + 1);
+}
+
+void ListView_Infile_DelSelItem(HWND hListInfile) {
+ int i = -1;
+ int j = -1;
+
+ while((i = ListView_GetNextItem(hListInfile, i, LVNI_SELECTED)) != -1) {
+ j = i;
+ ListView_DeleteItem(hListInfile, i--);
+ }
+ if(j != -1) {
+ if(0 < (i = ListView_GetItemCount(hListInfile))) {
+ if(j < i) {
+ ListView_SetItemState(hListInfile, j, LVIS_SELECTED, LVIS_SELECTED);
+ } else {
+ ListView_SetItemState(hListInfile, i - 1, LVIS_SELECTED, LVIS_SELECTED);
+ }
+ }
+ }
+}
+
+void ListView_Infile_DelDup(HWND hListInfile) {
+ int i = ListView_GetItemCount(hListInfile);
+ if(1 < i) {
+ for(--i; 0 < i; --i) {
+ ListView_GetItemText(hListInfile, i, 0, g_tsTempA, STRLEN_TEMP);
+ ListView_GetItemText(hListInfile, i - 1, 0, g_tsTempB, STRLEN_TEMP);
+ if(lstrcmpi(g_tsTempA, g_tsTempB) == 0)
+ ListView_DeleteItem(hListInfile, i);
+ }
+ }
+}
+
+BOOL IsEmptyInfile(HWND hListInfile, HWND hEditResult) {
+ if(ListView_GetItemCount(hListInfile) < 1) {
+ SetWindowText(hEditResult, g_tsSetInfile);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+BOOL IsEmptyOutfile(HWND hEditOutfile, HWND hEditResult) {
+ if(GetWindowTextLength(hEditOutfile) < 1) {
+ SetWindowText(hEditResult, g_tsSetOutfile);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//--------------------------------------
+// Sub Window Procedure
+//--------------------------------------
+
+LRESULT WndProcListInfileSub(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
+ int i, j;
+
+ switch(msg) {
+
+ case WM_KEYDOWN: {
+ if(wp == VK_DELETE)
+ ListView_Infile_DelSelItem(hWnd);
+ } break;
+
+ case WM_DROPFILES: {
+ j = DragQueryFile((HDROP)wp, -1, NULL, 0);
+ for(i = 0; i < j; ++i) {
+ DragQueryFile((HDROP)wp, i, g_tsTempA, STRLEN_TEMP);
+ ListView_Infile_AddItem(hWnd, g_tsTempA);
+ }
+ ListView_Infile_DelDup(hWnd);
+ } break;
+
+ default:
+ return CallWindowProc(WndProcListInfileDef, hWnd, msg, wp, lp);
+ }
+ return 0;
+}
+
+LRESULT WndProcEditOutfileSub(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
+ switch(msg) {
+
+ case WM_DROPFILES: {
+ DragQueryFile((HDROP)wp, 0, g_tsTempA, STRLEN_TEMP);
+ SetWindowText(hWnd, g_tsTempA);
+ } break;
+
+ default:
+ return CallWindowProc(WndProcEditOutfileDef, hWnd, msg, wp, lp);
+ }
+ return 0;
+}
+
+} // namespace
+
+//--------------------------------------
+// WindowMain
+//--------------------------------------
+
+BOOL Init(HINSTANCE hInstance) {
+ InitCommonControls();
+
+ g_hInst = hInstance;
+
+ // •¶Žš—ñ“ǂݞ‚Ý
+ LoadString(hInstance, IDS_SET_INFILE, g_tsSetInfile, STRLEN_RESULT);
+ LoadString(hInstance, IDS_SET_OUTFILE, g_tsSetOutfile, STRLEN_RESULT);
+ LoadString(hInstance, IDS_EXECUTING, g_tsExecuting, STRLEN_RESULT);
+ LoadString(hInstance, IDS_EXPFILT_PGLIST, g_tsExpFilt, STRLEN_EXPFILT);
+ // g_tsExpFilt‚Í@‚ðnull•¶Žš‚ɕϊ·
+ for(TCHAR *p = g_tsExpFilt; *p != TEXT('\0'); ++p)
+ if(*p == TEXT('@'))
+ *p = TEXT('\0');
+
+ // MENUITEMINFOÝ’è
+ g_mii.cbSize = sizeof(g_mii);
+ g_mii.fMask = MIIM_STATE;
+
+ // OPENFILENAMEÝ’è
+ g_ofn.lStructSize = sizeof(g_ofn);
+ g_ofn.lpstrFilter = g_tsExpFilt;
+ g_ofn.nFilterIndex = 0;
+ g_ofn.lpstrFile = g_tsPath;
+ g_ofn.nMaxFile = STRLEN_PATH;
+
+ // ŽÀsƒXƒŒƒbƒh‰Šú‰»
+ ThreadExecute::Init(hInstance);
+ return TRUE;
+}
+
+void Dlg_Executing(HWND hDlg, BOOL bExec) {
+ SendMessage(hDlg, WM_USER_EXECUTING, (WPARAM)bExec, 0);
+}
+
+int ListView_Infile_GetItemCount(HWND hDlg) {
+ return ListView_GetItemCount(GetDlgItem(hDlg, IDC_LISTVIEW_INFILE));
+}
+
+BOOL ListView_Infile_GetItemText(HWND hDlg, int nItem, LPTSTR tsPath) {
+ ListView_GetItemText(GetDlgItem(hDlg, IDC_LISTVIEW_INFILE), nItem, 0, tsPath, STRLEN_PATH);
+ return TRUE;
+}
+
+BOOL Edit_Outfile_GetText(HWND hDlg, LPTSTR tsPath) {
+ return GetDlgItemText(hDlg, IDC_EDIT_OUTFILE, tsPath, STRLEN_PATH);
+}
+
+BOOL Edit_Filter_GetText(HWND hDlg, LPTSTR tsText) {
+ return GetDlgItemText(hDlg, IDC_EDIT_FILTER, tsText, STRLEN_PATH);
+}
+
+void Edit_Result_SetText(HWND hDlg, LPCTSTR tsText) {
+ SetDlgItemText(hDlg, IDC_EDIT_RESULT, tsText);
+}
+
+BOOL GetOption(HWND hDlg, COption *option) {
+ HMENU hMenuMain = GetMenu(hDlg);
+
+ GetMenuItemInfo(hMenuMain, IDM_SORT_CAPTION, FALSE, &g_mii);
+ option->sortCap = ((g_mii.fState & MFS_CHECKED) != 0);
+
+ GetMenuItemInfo(hMenuMain, IDM_SORT_IP, FALSE, &g_mii);
+ option->sortIp = ((g_mii.fState & MFS_CHECKED) != 0);
+
+ GetMenuItemInfo(hMenuMain, IDM_CHECK_DUP_IP, FALSE, &g_mii);
+ option->delDupIp = ((g_mii.fState & MFS_CHECKED) != 0);
+
+ GetMenuItemInfo(hMenuMain, IDM_SAVE_APPEND, FALSE, &g_mii);
+ option->saveAppend = ((g_mii.fState & MFS_CHECKED) != 0);
+
+ option->filtAnd = (SendDlgItemMessage(hDlg, IDC_RADIO_FILTER_AND, BM_GETCHECK, 0, 0) == BST_CHECKED);
+ option->filtDel = (SendDlgItemMessage(hDlg, IDC_CHECK_FILTER_DEL, BM_GETCHECK, 0, 0) == BST_CHECKED);
+
+ return TRUE;
+}
+
+void Edit_Result_AppendText(HWND hDlg, LPCTSTR tsText) {
+ HWND hEditResult = GetDlgItem(hDlg, IDC_EDIT_RESULT);
+ int len = GetWindowTextLength(hEditResult);
+ SendMessage(hEditResult, EM_SETSEL, (WPARAM)len, (LPARAM)len);
+ SendMessage(hEditResult, EM_REPLACESEL, 0, (LPARAM)tsText);
+}
+
+BOOL CALLBACK DlgProcMain(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
+ static HMENU hMenuMain;
+ static HWND hListInfile;
+ static HWND hEditOutfile;
+ static HWND hEditFilter;
+ static HWND hEditResult;
+ static DWORD dwThreadId;
+
+ int i, j;
+
+ switch(msg) {
+
+ case WM_CLOSE: {
+ EndDialog(hWnd, 0);
+ } break;
+
+ case WM_INITDIALOG: {
+ HDC hDC;
+ RECT rect;
+ LVCOLUMN lvCol;
+
+ // Šeƒnƒ“ƒhƒ‹Ši”[
+ hMenuMain = GetMenu(hWnd);
+ hListInfile = GetDlgItem(hWnd, IDC_LISTVIEW_INFILE);
+ hEditOutfile = GetDlgItem(hWnd, IDC_EDIT_OUTFILE);
+ hEditFilter = GetDlgItem(hWnd, IDC_EDIT_FILTER);
+ hEditResult = GetDlgItem(hWnd, IDC_EDIT_RESULT);
+
+ // ƒEƒBƒ“ƒhƒEˆÊ’uÝ’è
+ hDC = GetDC(hWnd);
+ GetWindowRect(hWnd, &rect);
+ SetWindowPos(hWnd, HWND_TOP,
+ (GetDeviceCaps(hDC, HORZRES) - (rect.right - rect.left)) / 2,
+ (GetDeviceCaps(hDC, VERTRES) - (rect.bottom - rect.top)) / 2,
+ 0, 0, SWP_NOSIZE);
+ ReleaseDC(hWnd, hDC);
+
+ // ƒŠƒXƒgƒrƒ…[Ý’è
+ ListView_SetExtendedListViewStyle(hListInfile,
+ LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP);//LVS_EX_INFOTIP);
+
+ int nWidthScroll = GetSystemMetrics(SM_CXVSCROLL);
+ int nWidth3DEdge = GetSystemMetrics(SM_CXEDGE);
+ GetWindowRect(hListInfile, &rect);
+
+ lvCol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
+ lvCol.fmt = LVCFMT_LEFT;
+
+ lvCol.cx = 72;
+ lvCol.iSubItem = 0;
+ LoadString(g_hInst, IDS_FILE_PATH, g_tsTempA, STRLEN_TEMP);
+ lvCol.pszText = g_tsTempA;
+ ListView_InsertColumn(hListInfile, 0, &lvCol);
+
+ lvCol.cx = (rect.right - rect.left) - 72 - nWidthScroll - nWidth3DEdge * 2;
+ lvCol.iSubItem = 1;
+ LoadString(g_hInst, IDS_FILE_NAME, g_tsTempA, STRLEN_TEMP);
+ lvCol.pszText = g_tsTempA;
+ ListView_InsertColumn(hListInfile, 1, &lvCol);
+
+ // ƒ`ƒFƒbƒNó‘Ô
+ SendDlgItemMessage(hWnd, IDC_RADIO_FILTER_AND, BM_SETCHECK, BST_CHECKED, 0);
+
+ #ifdef UNICODE
+ // ƒRƒ}ƒ“ƒhƒ‰ƒCƒ“ˆø”‚©‚烊ƒXƒg‚֒ljÁ
+ LPWSTR *wsCmds = CommandLineToArgvW(GetCommandLineW(), &j);
+ for(i = 1; i < j; ++i)
+ ListView_Infile_AddItem(hListInfile, wsCmds[i]);
+ LocalFree((HLOCAL)wsCmds);
+ ListView_Infile_DelDup(hListInfile);
+ #endif
+
+ // ƒTƒuƒNƒ‰ƒX
+ WndProcListInfileDef = (WNDPROC)GetWindowLong(hListInfile, GWL_WNDPROC);
+ SetWindowLong(hListInfile, GWL_WNDPROC, (LONG)WndProcListInfileSub);
+
+ WndProcEditOutfileDef = (WNDPROC)GetWindowLong(hEditOutfile, GWL_WNDPROC);
+ SetWindowLong(hEditOutfile, GWL_WNDPROC, (LONG)WndProcEditOutfileSub);
+ } break;
+
+ case WM_COMMAND: {
+ switch(LOWORD(wp)) {
+
+ case IDM_EXIT: {
+ EndDialog(hWnd, IDOK);
+ //PostMessage(hWnd, WM_CLOSE, 0, 0);
+ } break;
+
+ case IDM_SORT_CAPTION:
+ case IDM_SORT_IP:
+ case IDM_CHECK_DUP_IP: {
+ GetMenuItemInfo(hMenuMain, LOWORD(wp), FALSE, &g_mii);
+ g_mii.fState = ((g_mii.fState & MFS_CHECKED) ? MFS_UNCHECKED : MFS_CHECKED);
+ SetMenuItemInfo(hMenuMain, LOWORD(wp), FALSE, &g_mii);
+ } break;
+
+ case IDM_SAVE_REPLACE: {
+ Menu_SwapIfChecked(hMenuMain, IDM_SAVE_REPLACE, IDM_SAVE_APPEND);
+ } break;
+
+ case IDM_SAVE_APPEND: {
+ Menu_SwapIfChecked(hMenuMain, IDM_SAVE_APPEND, IDM_SAVE_REPLACE);
+ } break;
+
+ case IDM_CHECK_INFILE: {
+ if(IsEmptyInfile(hListInfile, hEditResult))
+ break;
+ SendMessage(hWnd, WM_USER_EXECUTING, (WPARAM)TRUE, 0);
+ CreateThread(NULL, 0, ThreadExecute::ThreadExecCheckInfile, (LPVOID)hWnd, 0, &dwThreadId);
+ } break;
+
+ case IDM_OUTPUT: {
+ if(IsEmptyInfile(hListInfile, hEditResult) || IsEmptyOutfile(hEditOutfile, hEditResult))
+ break;
+ SendMessage(hWnd, WM_USER_EXECUTING, (WPARAM)TRUE, 0);
+ CreateThread(NULL, 0, ThreadExecute::ThreadExecOutput, (LPVOID)hWnd, 0, &dwThreadId);
+ } break;
+
+ case IDM_CHECK_AND_OUTPUT: {
+ if(IsEmptyInfile(hListInfile, hEditResult) || IsEmptyOutfile(hEditOutfile, hEditResult))
+ break;
+ SendMessage(hWnd, WM_USER_EXECUTING, (WPARAM)TRUE, 0);
+ CreateThread(NULL, 0, ThreadExecute::ThreadExecCheckAndOutput, (LPVOID)hWnd, 0, &dwThreadId);
+ } break;
+
+ case IDC_BUTTON_INFILE_ADD: {
+ // C:\a.txt0
+ // C:\0a.txt0b.txt00
+ // C:\dir0a.txt0b.txt00
+ memset(g_tsPath, 0, STRLEN_PATH);
+ g_ofn.hwndOwner = hWnd;
+ g_ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY;
+ if(GetOpenFileName(&g_ofn)) {
+ if(g_tsPath[g_ofn.nFileOffset - 1] != TEXT('\0'))
+ ListView_Infile_AddItem(hListInfile, g_tsPath, g_tsPath + g_ofn.nFileOffset);
+ else {
+ lstrcpy(g_tsTempA, g_tsPath);
+ LPTSTR tsFile = g_tsTempA + g_ofn.nFileOffset - 1;
+ if(*(tsFile - 1) != TEXT('\\')) {
+ *tsFile = TEXT('\\');
+ ++tsFile;
+ }
+ for(LPTSTR tsP = g_tsPath + g_ofn.nFileOffset; *tsP != TEXT('\0'); ++tsP) {
+ lstrcpy(tsFile, tsP);
+ ListView_Infile_AddItem(hListInfile, g_tsTempA, tsFile);
+ while(*tsP != TEXT('\0'))
+ ++tsP;
+ }
+ }
+ ListView_Infile_DelDup(hListInfile);
+ }
+ } break;
+
+ case IDC_BUTTON_INFILE_DEL: {
+ ListView_Infile_DelSelItem(hListInfile);
+ } break;
+
+ case IDC_BUTTON_INFILE_CLEAR: {
+ ListView_DeleteAllItems(hListInfile);
+ } break;
+
+ case IDC_BUTTON_OUTFILE_REF: {
+ memset(g_tsPath, 0, STRLEN_PATH);
+ g_ofn.hwndOwner = hWnd;
+ g_ofn.Flags = OFN_EXPLORER;
+ if(GetSaveFileName(&g_ofn))
+ SetWindowText(hEditOutfile, g_tsPath);
+ } break;
+
+ case IDC_BUTTON_FILTER_CLEAR: {
+ SetWindowText(hEditFilter, NULL);
+ } break;
+
+ default:
+ return FALSE;
+ }
+ } break;
+
+ case WM_USER_EXECUTING: {
+ if((BOOL)wp) {
+ g_mii.fState = MFS_GRAYED;
+ SetWindowText(hEditResult, g_tsExecuting);
+ } else {
+ g_mii.fState = MFS_ENABLED;
+ }
+ SetMenuItemInfo(hMenuMain, 2, TRUE, &g_mii);
+ DrawMenuBar(hWnd);
+ } break;
+
+ default:
+ return FALSE;
+ }
+ return TRUE;
+}
+
+} // namespace WindowMain
diff --git a/tool/PGListUtil/src/PGListUtil/WindowMain.h b/tool/PGListUtil/src/PGListUtil/WindowMain.h new file mode 100644 index 00000000..d02c3b7f --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/WindowMain.h @@ -0,0 +1,39 @@ +#ifndef WINDOWMAIN_H
+#define WINDOWMAIN_H
+
+#include <windows.h>
+
+#define STRLEN_TEMP 1024
+#define STRLEN_PATH 1024
+#define STRLEN_EXPFILT 128
+#define STRLEN_RESULT 64
+
+namespace WindowMain {
+
+struct COption {
+ bool sortCap;
+ bool sortIp;
+ bool delDupIp;
+ bool saveAppend;
+ bool filtAnd;
+ bool filtDel;
+};
+
+BOOL Init(HINSTANCE hInstance);
+
+BOOL CALLBACK DlgProcMain(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
+
+void Dlg_Executing(HWND hDlg, BOOL bExec);
+int ListView_Infile_GetItemCount(HWND hDlg);
+BOOL ListView_Infile_GetItemText(HWND hDlg, int nItem, LPTSTR tsPath);
+BOOL Edit_Outfile_GetText(HWND hDlg, LPTSTR tsPath);
+BOOL Edit_Filter_GetText(HWND hDlg, LPTSTR tsText);
+
+BOOL GetOption(HWND hDlg, COption *option);
+
+void Edit_Result_SetText(HWND hDlg, LPCTSTR tsText);
+void Edit_Result_AppendText(HWND hDlg, LPCTSTR tsText);
+
+}
+
+#endif // WINDOWMAIN_H
diff --git a/tool/PGListUtil/src/PGListUtil/resource.h b/tool/PGListUtil/src/PGListUtil/resource.h new file mode 100644 index 00000000..ca510e78 --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/resource.h @@ -0,0 +1,42 @@ +#ifndef IDC_STATIC
+#define IDC_STATIC (-1)
+#endif
+
+#define IDC_EDIT_FILTER 1001
+#define IDC_LISTVIEW_INFILE 1002
+#define IDC_BUTTON_INFILE_ADD 1004
+#define IDD_MAIN 1041
+#define IDR_MENU_MAIN 1041
+#define IDM_EXIT 40000
+#define IDS_SET_INFILE 40000
+#define IDM_SORT_CAPTION 40001
+#define IDS_SET_OUTFILE 40001
+#define IDM_SORT_IP 40002
+#define IDS_FAILED_FILE_READ 40002
+#define IDM_CHECK_DUP_IP 40003
+#define IDS_FAILED_FILE_WRITE 40003
+#define IDM_SAVE_REPLACE 40004
+#define IDS_FILE_PATH 40004
+#define IDM_SAVE_APPEND 40005
+#define IDS_FILE_NAME 40005
+#define IDM_CHECK_INFILE 40006
+#define IDS_EXPFILT_PGLIST 40006
+#define IDM_OUTPUT 40007
+#define IDS_OUTPUT_COMPLETE 40007
+#define IDM_CHECK_AND_OUTPUT 40008
+#define IDS_EXECUTING 40008
+#define IDS_CHECK_FOUND_ERROR 40009
+#define IDS_CHECK_NOTFOUND_ERROR 40010
+#define IDS_CHECK_COMPLETE 40011
+#define IDS_CHECK_ERROR_SYNTAX 40012
+#define IDS_CHECK_ERROR_IP 40013
+#define IDS_CHECK_ERROR_SYNTAX_RESTORABLE 40014
+#define IDC_EDIT_OUTFILE 40022
+#define IDC_EDIT_RESULT 40026
+#define IDC_BUTTON_INFILE_DEL 40027
+#define IDC_BUTTON_INFILE_CLEAR 40028
+#define IDC_BUTTON_OUTFILE_REF 40029
+#define IDC_BUTTON_FILTER_CLEAR 40030
+#define IDC_RADIO_FILTER_AND 40031
+#define IDC_RADIO_FILTER_OR 40032
+#define IDC_CHECK_FILTER_DEL 40033
diff --git a/tool/PGListUtil/src/PGListUtil/resource.rc b/tool/PGListUtil/src/PGListUtil/resource.rc new file mode 100644 index 00000000..b8b5a25c --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/resource.rc @@ -0,0 +1,100 @@ +// Generated by ResEdit 1.4.4.18
+// Copyright (C) 2006-2008
+// http://www.resedit.net
+
+#include "resource.h"
+#include <windows.h>
+#include <commctrl.h>
+#include <richedit.h>
+
+
+//
+// Menu resources
+//
+IDR_MENU_MAIN MENU
+{
+ POPUP "ƒtƒ@ƒCƒ‹(&F)"
+ {
+ MENUITEM "I—¹(&X)", IDM_EXIT
+ }
+ POPUP "Ý’è(&O)"
+ {
+ MENUITEM "ƒLƒƒƒvƒVƒ‡ƒ“‚Ń\[ƒg(&C)", IDM_SORT_CAPTION, CHECKED
+ MENUITEM "IPƒAƒhƒŒƒX‚Ń\[ƒg(&I)", IDM_SORT_IP, CHECKED
+ MENUITEM SEPARATOR
+ MENUITEM "IPƒAƒhƒŒƒX‚Ìd•¡‚ð‰ðÁ(&D)", IDM_CHECK_DUP_IP, CHECKED
+ MENUITEM SEPARATOR
+ MENUITEM "ã‘‚«•Û‘¶(&R)", IDM_SAVE_REPLACE, CHECKED
+ MENUITEM "’Ç‹L•Û‘¶(&A)", IDM_SAVE_APPEND
+ }
+ POPUP "ŽÀs(&E)"
+ {
+ MENUITEM "“ü—̓tƒ@ƒCƒ‹‚ðƒ`ƒFƒbƒN(&C)", IDM_CHECK_INFILE
+ MENUITEM SEPARATOR
+ MENUITEM "ƒtƒ@ƒCƒ‹o—Í(&O)", IDM_OUTPUT
+ MENUITEM SEPARATOR
+ MENUITEM "ƒ`ƒFƒbƒNŒãAƒtƒ@ƒCƒ‹o—Í(&S)", IDM_CHECK_AND_OUTPUT
+ }
+}
+
+
+
+//
+// Dialog resources
+//
+IDD_MAIN DIALOGEX 0, 0, 334, 228
+STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_GROUP | WS_POPUP | WS_SYSMENU
+EXSTYLE WS_EX_OVERLAPPEDWINDOW
+CAPTION "PGListUtil ver0.7.0"
+MENU IDR_MENU_MAIN
+FONT 9, "MS UI Gothic", 400, 0, 128
+{
+ CONTROL "", IDC_LISTVIEW_INFILE, WC_LISTVIEW, WS_TABSTOP | WS_BORDER | LVS_ALIGNLEFT | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_REPORT | LVS_SORTASCENDING, 6, 16, 158, 118, WS_EX_ACCEPTFILES
+ PUSHBUTTON "’ljÁ", IDC_BUTTON_INFILE_ADD, 62, 138, 30, 16, BS_PUSHBUTTON
+ PUSHBUTTON "íœ", IDC_BUTTON_INFILE_DEL, 98, 138, 30, 16, BS_PUSHBUTTON
+ PUSHBUTTON "ƒNƒŠƒA", IDC_BUTTON_INFILE_CLEAR, 134, 138, 30, 16, BS_PUSHBUTTON
+ EDITTEXT IDC_EDIT_OUTFILE, 6, 168, 122, 14, ES_AUTOHSCROLL, WS_EX_ACCEPTFILES
+ PUSHBUTTON "ŽQÆ", IDC_BUTTON_OUTFILE_REF, 134, 167, 30, 16, BS_PUSHBUTTON
+ EDITTEXT IDC_EDIT_FILTER, 6, 196, 122, 14, ES_AUTOHSCROLL
+ PUSHBUTTON "ƒNƒŠƒA", IDC_BUTTON_FILTER_CLEAR, 134, 195, 30, 16, BS_PUSHBUTTON
+ AUTORADIOBUTTON "AND", IDC_RADIO_FILTER_AND, 6, 212, 26, 10, WS_GROUP | WS_TABSTOP | BS_AUTORADIOBUTTON
+ AUTORADIOBUTTON "OR", IDC_RADIO_FILTER_OR, 34, 212, 26, 10, WS_TABSTOP | BS_AUTORADIOBUTTON
+ AUTOCHECKBOX "œŠO", IDC_CHECK_FILTER_DEL, 102, 212, 26, 10, BS_AUTOCHECKBOX
+ EDITTEXT IDC_EDIT_RESULT, 170, 16, 158, 206, WS_VSCROLL | ES_MULTILINE | ES_READONLY
+ LTEXT "“ü—̓tƒ@ƒCƒ‹ƒŠƒXƒg", IDC_STATIC, 6, 6, 48, 8, SS_LEFT
+ LTEXT "o—̓tƒ@ƒCƒ‹", IDC_STATIC, 6, 158, 34, 8, SS_LEFT
+ LTEXT "ƒLƒƒƒvƒVƒ‡ƒ“ƒtƒBƒ‹ƒ^[", IDC_STATIC, 6, 186, 55, 8, SS_LEFT
+ LTEXT "ŽÀsŒ‹‰Ê", IDC_STATIC, 170, 6, 28, 8, SS_LEFT
+}
+
+
+
+//
+// String Table resources
+//
+STRINGTABLE
+
+{
+ IDS_SET_INFILE "“ü—̓tƒ@ƒCƒ‹‚ðݒ肵‚Ä‚‚¾‚³‚¢"
+ IDS_SET_OUTFILE "o—̓tƒ@ƒCƒ‹‚ðݒ肵‚Ä‚‚¾‚³‚¢"
+ IDS_FAILED_FILE_READ " ‚̓ǂݞ‚݂Ɏ¸”s‚µ‚Ü‚µ‚½"
+ IDS_FAILED_FILE_WRITE " ‚Ì‘‚«ž‚݂Ɏ¸”s‚µ‚Ü‚µ‚½"
+ IDS_FILE_PATH "ƒtƒ@ƒCƒ‹ƒpƒX"
+ IDS_FILE_NAME "ƒtƒ@ƒCƒ‹–¼"
+ IDS_EXPFILT_PGLIST "ƒeƒLƒXƒgƒtƒ@ƒCƒ‹ (*.txt)@*.txt@‚·‚ׂẴtƒ@ƒCƒ‹ (*.*)@*.*@@"
+ IDS_OUTPUT_COMPLETE "ƒtƒ@ƒCƒ‹o—Í‚ªŠ®—¹‚µ‚Ü‚µ‚½\r\n\r\n“ü—Í” = %d\r\n–³Œø” = %d\r\no—Í” = %d\r\n"
+ IDS_EXECUTING "ŽÀs’†..."
+ IDS_CHECK_FOUND_ERROR " ‚Ɉȉº‚̃Gƒ‰[‚ªŒ©‚‚©‚è‚Ü‚µ‚½"
+ IDS_CHECK_NOTFOUND_ERROR " ‚É‘z’è“à‚̃Gƒ‰[‚ÍŒ©‚‚©‚è‚Ü‚¹‚ñ‚Å‚µ‚½"
+ IDS_CHECK_COMPLETE "ƒ`ƒFƒbƒN‚ªŠ®—¹‚µ‚Ü‚µ‚½"
+ IDS_CHECK_ERROR_SYNTAX "[ %d s–Ú ] \•¶ƒGƒ‰["
+ IDS_CHECK_ERROR_IP "[ %d s–Ú ] •s³‚ÈIPƒAƒhƒŒƒX"
+ IDS_CHECK_ERROR_SYNTAX_RESTORABLE "[ %d s–Ú ] \•¶ƒGƒ‰[ (Ž©“®C•œ‰Â)"
+}
+
+
+
+//
+// Manifest resources
+//
+1 RT_MANIFEST ".\\PGListUtil.exe.manifest"
diff --git a/tool/PGListUtil/src/PGListUtil/stdafx.h b/tool/PGListUtil/src/PGListUtil/stdafx.h new file mode 100644 index 00000000..41aaf82a --- /dev/null +++ b/tool/PGListUtil/src/PGListUtil/stdafx.h @@ -0,0 +1,12 @@ +#ifndef PGLU_STDAFX_H
+#define PGLU_STDAFX_H
+
+#include <windows.h>
+
+#ifdef __MINGW32__
+#define _WIN32_IE 0x0600
+#endif
+
+#include <commctrl.h>
+
+#endif // PGLU_STDAFX_H
diff --git a/tool/PGListUtil/src/common/CErrorList.cpp b/tool/PGListUtil/src/common/CErrorList.cpp new file mode 100644 index 00000000..4dce97bc --- /dev/null +++ b/tool/PGListUtil/src/common/CErrorList.cpp @@ -0,0 +1,171 @@ +#include <stdio.h>
+#include <boost/xpressive/xpressive.hpp>
+#include "CErrorList.h"
+
+namespace pglu {
+namespace error {
+
+CErrorList::CErrorList() :
+ m_pool(sizeof(CError)),
+ m_errFoot(&m_errHead),
+ m_errNext(&m_errHead),
+ m_count(0)
+{
+ m_errHead.line = 0;
+ m_errHead.kind = SYNTAX;
+ m_errHead.next = NULL;
+}
+
+CErrorList::~CErrorList() {
+ Clear();
+}
+
+void CErrorList::Clear() {
+ m_pool.purge_memory();
+ m_errHead.next = NULL;
+ m_errFoot = &m_errHead;
+ m_errNext = &m_errHead;
+ m_count = 0;
+}
+
+bool CErrorList::LoadListFile(const char *path) {
+ char buf[PGLU_LENGTH_FILELINE];
+ uint ip_begin1, ip_begin2, ip_begin3, ip_begin4;
+ uint ip_end1, ip_end2, ip_end3, ip_end4;
+ FILE *fp;
+ CError *err = m_errFoot;
+
+ using namespace boost::xpressive;
+
+ static cmatch match;
+ static mark_tag tagIp1(1), tagIp2(2), tagIp3(3), tagIp4(4), tagIp5(5), tagIp6(6), tagIp7(7), tagIp8(8);
+ static mark_tag tagSep(9), tagMask(10);
+
+ static cregex reSyntax =
+ as_xpr(':') >> *_s >>
+ (tagIp1 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp2 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp3 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp4 = repeat<1, 3>(_d)) >>
+ *_s >> as_xpr('-') >> *_s >>
+ (tagIp5 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp6 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp7 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp8 = repeat<1, 3>(_d)) >>
+ *_s >> (_ln | eos);
+
+ static cregex reSyntaxRestorable =
+ (tagIp1 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp2 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp3 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp4 = repeat<1, 3>(_d)) >> *_s >> (
+ (tagSep = +as_xpr('-')) >> *_s >>
+ (tagIp5 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp6 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp7 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp8 = repeat<1, 3>(_d))
+ |
+ (tagSep = +(set = '/', '\\')) >> *_s >>
+ (tagMask = repeat<1, 2>(_d))
+ ) >> *_s >> (_ln | eos);
+
+#define reIpError repeat<3>(+_d >> *_s >> (set = '.', ',') >> *_s) >> +_d
+
+ static cregex reSyntaxError =
+ reIpError >> *_s >> (
+ *as_xpr('-') >> *_s >> reIpError |
+ +(set = '/', '\\') >> *_s >> +_d
+ );
+
+ fp = fopen(path, "r");
+ if(fp == NULL)
+ return false;
+
+ for(int line = 1; fgets(buf, PGLU_LENGTH_FILELINE, fp); ++line) {
+
+ if(regex_search(buf, match, reSyntax)) {
+ if(!(
+ (ip_begin1 = ParseDigit3(match[1].first, match[1].second)) < 256 &&
+ (ip_begin2 = ParseDigit3(match[2].first, match[2].second)) < 256 &&
+ (ip_begin3 = ParseDigit3(match[3].first, match[3].second)) < 256 &&
+ (ip_begin4 = ParseDigit3(match[4].first, match[4].second)) < 256 &&
+ (ip_end1 = ParseDigit3(match[5].first, match[5].second)) < 256 &&
+ (ip_end2 = ParseDigit3(match[6].first, match[6].second)) < 256 &&
+ (ip_end3 = ParseDigit3(match[7].first, match[7].second)) < 256 &&
+ (ip_end4 = ParseDigit3(match[8].first, match[8].second)) < 256 &&
+ (uint)((ip_begin1 << 24) | (ip_begin2 << 16) | (ip_begin3 << 8) | ip_begin4) <=
+ (uint)((ip_end1 << 24) | (ip_end2 << 16) | (ip_end3 << 8) | ip_end4)
+ )) {
+ ++m_count;
+ err->next = (CError*)m_pool.malloc();
+ err = err->next;
+ err->line = line;
+ err->kind = IP;
+ }
+
+ } else if(regex_search(buf, match, reSyntaxRestorable)) {
+ ++m_count;
+ err->next = (CError*)m_pool.malloc();
+ err = err->next;
+ err->line = line;
+ if(*(match[9].first) == '-') {
+ if(
+ (ip_begin1 = ParseDigit3(match[1].first, match[1].second)) < 256 &&
+ (ip_begin2 = ParseDigit3(match[2].first, match[2].second)) < 256 &&
+ (ip_begin3 = ParseDigit3(match[3].first, match[3].second)) < 256 &&
+ (ip_begin4 = ParseDigit3(match[4].first, match[4].second)) < 256 &&
+ (ip_end1 = ParseDigit3(match[5].first, match[5].second)) < 256 &&
+ (ip_end2 = ParseDigit3(match[6].first, match[6].second)) < 256 &&
+ (ip_end3 = ParseDigit3(match[7].first, match[7].second)) < 256 &&
+ (ip_end4 = ParseDigit3(match[8].first, match[8].second)) < 256 &&
+ (uint)((ip_begin1 << 24) | (ip_begin2 << 16) | (ip_begin3 << 8) | ip_begin4) <=
+ (uint)((ip_end1 << 24) | (ip_end2 << 16) | (ip_end3 << 8) | ip_end4)
+ ) {
+ err->kind = SYNTAX_RESTORABLE;
+ } else {
+ err->kind = SYNTAX;
+ }
+ } else {
+ uint mask = ParseDigit3(match[10].first, match[10].second);
+ if(
+ ParseDigit3(match[1].first, match[1].second) < 256 &&
+ ParseDigit3(match[2].first, match[2].second) < 256 &&
+ ParseDigit3(match[3].first, match[3].second) < 256 &&
+ ParseDigit3(match[4].first, match[4].second) < 256 &&
+ mask < 33
+ ) {
+ err->kind = SYNTAX_RESTORABLE;
+ } else {
+ err->kind = SYNTAX;
+ }
+ }
+ } else if(regex_search(buf, reSyntaxError)) {
+ ++m_count;
+ err->next = (CError*)m_pool.malloc();
+ err = err->next;
+ err->line = line;
+ err->kind = SYNTAX;
+ }
+#ifdef __MINGW32__
+ ZeroString(buf);
+#endif
+ }
+
+ fclose(fp);
+ err->next = NULL;
+ m_errFoot = err;
+ return true;
+}
+
+int CErrorList::Count() {
+ return m_count;
+}
+
+CError * CErrorList::GetNext() {
+ if(m_errNext)
+ m_errNext = m_errNext->next;
+ return m_errNext;
+}
+
+} // namespace error
+} // namespace pglu
diff --git a/tool/PGListUtil/src/common/CErrorList.h b/tool/PGListUtil/src/common/CErrorList.h new file mode 100644 index 00000000..5583bb8d --- /dev/null +++ b/tool/PGListUtil/src/common/CErrorList.h @@ -0,0 +1,43 @@ +#ifndef CERRLIST_H
+#define CERRLIST_H
+
+#include <boost/pool/pool.hpp>
+#include "common.h"
+
+namespace pglu {
+namespace error {
+
+typedef enum _EErrKind {
+ SYNTAX,
+ IP,
+ SYNTAX_RESTORABLE
+} EErrKind;
+
+typedef struct _CError {
+ int line;
+ EErrKind kind;
+ _CError * next;
+} CError;
+
+class CErrorList {
+private:
+ boost::pool<> m_pool;
+ CError m_errHead;
+ CError * m_errFoot;
+ CError * m_errNext;
+ int m_count;
+
+public:
+ CErrorList();
+ ~CErrorList();
+
+ void Clear();
+ bool LoadListFile(const char *path);
+ int Count();
+ CError * GetNext();
+};
+
+} // namespace error
+} // namespace pglu
+
+#endif // CERRLIST_H
diff --git a/tool/PGListUtil/src/common/CFilter.cpp b/tool/PGListUtil/src/common/CFilter.cpp new file mode 100644 index 00000000..a6235547 --- /dev/null +++ b/tool/PGListUtil/src/common/CFilter.cpp @@ -0,0 +1,125 @@ +#include <ctype.h>
+#include <string.h>
+#include "CFilter.h"
+
+namespace pglu {
+namespace filter {
+
+namespace {
+
+char *strichr(const char *str, int chr) {
+ const char *p = str;
+ chr = tolower((unsigned char)chr);
+ for(; tolower((unsigned char)(*p)) != chr; ++p)
+ if(*p == '\0')
+ return NULL;
+ return (char*)p;
+}
+
+char *stristr(const char *str, const char *pattern) {
+ if(*pattern == '\0')
+ return (char*)str;
+
+ const char *p = str;
+ size_t len = strlen(pattern);
+ for(; (p = strichr(p, pattern[0])) != NULL; ++p)
+ if(!strnicmp(p, pattern, len))
+ return (char*)p;
+ return NULL;
+}
+
+bool search_and(const char *str, const char *terms, const bool del) {
+ do {
+ if(!stristr(str, terms))
+ return del; // not found
+ while(*terms != '\0')
+ ++terms;
+ ++terms;
+ } while(*terms != '\0');
+ return !del; // found all
+}
+
+bool search_or(const char *str, const char *terms, const bool del) {
+ do {
+ if(stristr(str, terms))
+ return !del; // found
+ while(*terms != '\0')
+ ++terms;
+ ++terms;
+ } while(*terms != '\0');
+ return del; // not found
+}
+
+} // namespace
+
+//--------------------------------------
+// CFilter class
+//--------------------------------------
+
+CFilter::CFilter() :
+ m_terms(NULL)
+{
+}
+
+CFilter::CFilter(const char *strFilter, const EFilterMode mode, const bool del) :
+ m_terms(NULL)
+{
+ Assign(strFilter, mode, del);
+}
+
+CFilter::~CFilter() {
+ Clear();
+}
+
+void CFilter::Assign(const char *strFilter, const EFilterMode mode, const bool del) {
+ Clear();
+
+ if(mode == AND)
+ m_search = search_and;
+ else if(mode == OR)
+ m_search = search_or;
+ else
+ return;
+
+ m_mode = mode;
+ m_del = del;
+
+ m_terms = new char[strlen(strFilter) + 2];
+
+ while(*strFilter == ' ' || *strFilter == '\t')
+ ++strFilter;
+
+ char *strTerms = m_terms;
+ while(*strFilter != '\0') {
+ *(strTerms++) = *(strFilter++);
+ if(*strFilter == ' ' || *strFilter == '\t') {
+ *(strTerms++) = '\0';
+ do {
+ ++strFilter;
+ } while(*strFilter == ' ' || *strFilter == '\t');
+ }
+ }
+ *strTerms = '\0';
+ *(strTerms + 1) = '\0';
+}
+
+void CFilter::Clear() {
+ if(m_terms) {
+ delete[] m_terms;
+ m_terms = NULL;
+ }
+}
+
+bool CFilter::IsEmpty() {
+ if(m_terms)
+ return *m_terms == '\0';
+ else
+ return true;
+}
+
+bool CFilter::IsMatch(const char *str) {
+ return m_search(str, m_terms, m_del);
+}
+
+} // namespace filter
+} // namespace pglu
diff --git a/tool/PGListUtil/src/common/CFilter.h b/tool/PGListUtil/src/common/CFilter.h new file mode 100644 index 00000000..5f52db28 --- /dev/null +++ b/tool/PGListUtil/src/common/CFilter.h @@ -0,0 +1,34 @@ +#ifndef CFILTER_H
+#define CFILTER_H
+
+namespace pglu {
+namespace filter {
+
+typedef enum _EFilterMode {
+ AND,
+ OR
+} EFilterMode;
+
+class CFilter {
+private:
+ char * m_terms;
+ EFilterMode m_mode;
+ bool m_del;
+
+ bool (* m_search)(const char *, const char *, const bool);
+
+public:
+ CFilter();
+ CFilter(const char *strFilter, const EFilterMode mode, const bool del);
+ ~CFilter();
+
+ void Assign(const char *strFilter, const EFilterMode mode, const bool del);
+ void Clear();
+ bool IsEmpty();
+ bool IsMatch(const char *str);
+};
+
+} // namespace filter
+} // namespace pglu
+
+#endif // CFILTER_H
diff --git a/tool/PGListUtil/src/common/CIpList.cpp b/tool/PGListUtil/src/common/CIpList.cpp new file mode 100644 index 00000000..b9eaf800 --- /dev/null +++ b/tool/PGListUtil/src/common/CIpList.cpp @@ -0,0 +1,355 @@ +#include <stdio.h>
+#include <string.h>
+#include "CIpList.h"
+
+namespace pglu {
+namespace ip {
+
+namespace {
+
+inline void Ip_Swap(CIp **ipA, CIp **ipB) {
+ CIp *ip = *ipA;
+ *ipA = *ipB;
+ *ipB = ip;
+}
+
+void Ip_SortByIpQuick(CIp **ipBegin, CIp **ipEnd) {
+ CIp **ipA;
+ CIp **ipB;
+ int nGap = ipEnd - ipBegin;
+
+ if(nGap < 64)
+ return;
+
+ ipA = ipBegin + ((int)(nGap / 2));
+ if((*ipBegin)->ip64 > (*ipA)->ip64)
+ Ip_Swap(ipBegin, ipA);
+ if((*ipBegin)->ip64 > (*ipEnd)->ip64)
+ Ip_Swap(ipBegin, ipEnd);
+ if((*ipA)->ip64 > (*ipEnd)->ip64)
+ Ip_Swap(ipA, ipEnd);
+ ulong ip64 = (*ipA)->ip64;
+
+ ipB = ipEnd - 1;
+ Ip_Swap(ipA, ipB);
+ ipA = ipBegin;
+
+ for(; ; ) {
+ while((*(++ipA))->ip64 < ip64);
+ while((*(--ipB))->ip64 > ip64);
+ if(ipA > ipB)
+ break;
+ Ip_Swap(ipA, ipB);
+ }
+ Ip_Swap(ipA, ipEnd - 1);
+
+ Ip_SortByIpQuick(ipBegin, ipB);
+ Ip_SortByIpQuick(ipA + 1, ipEnd);
+}
+
+void Ip_SortByIpInsert(CIp **ipBegin, CIp **ipEnd) {
+ CIp **ipA = ipBegin + 1;
+ CIp **ipB;
+ CIp **ipAEnd = ipEnd + 1;
+ CIp **ipBEnd = ipBegin - 1;
+ ulong ip64;
+ for(; ipA != ipAEnd; ++ipA) {
+ ip64 = (*ipA)->ip64;
+ for(ipB = ipA - 1; ipB != ipBEnd && (*ipB)->ip64 > ip64; --ipB)
+ Ip_Swap(ipB, ipB + 1);
+ }
+}
+
+void Ip_SortByIp(CIp **ipBegin, CIp **ipEnd) {
+ Ip_SortByIpQuick(ipBegin, ipEnd);
+ Ip_SortByIpInsert(ipBegin, ipEnd);
+}
+
+CIp * Ip_SortByCaption(CIp *ipHeadA) {
+ if(!ipHeadA || !(ipHeadA->next))
+ return ipHeadA;
+
+ // split ipB‚ð2”{‚Åi‚߂邱‚Æ‚ÅipA‚𒆊Ԉʒu‚ÉŽ‚Á‚Ä‚¢‚
+ CIp *ipA = ipHeadA;
+ CIp *ipB = ipHeadA->next->next;
+ while(ipB) {
+ ipA = ipA->next;
+ ipB = ipB->next;
+ if(ipB)
+ ipB = ipB->next;
+ }
+ CIp *ipHeadB = ipA->next;
+ ipA->next = NULL;
+
+ ipHeadA = Ip_SortByCaption(ipHeadA);
+ ipHeadB = Ip_SortByCaption(ipHeadB);
+
+ // merge
+ CIp ipMerged;
+ ipA = &ipMerged;
+ while(ipHeadA || ipHeadB) {
+ if(((ipHeadA && ipHeadB) && stricmp(ipHeadA->caption, ipHeadB->caption) <= 0) || !ipHeadB) {
+ ipA->next = ipHeadA;
+ ipHeadA = ipHeadA->next;
+ } else {
+ ipA->next = ipHeadB;
+ ipHeadB = ipHeadB->next;
+ }
+ ipA = ipA->next;
+ }
+ ipA->next = NULL;
+
+ return ipMerged.next;
+}
+
+} // namespace
+
+//--------------------------------------
+// CIpList class
+//--------------------------------------
+
+CIpList::CIpList() :
+ m_poolIp(sizeof(CIp)),
+ m_ipFoot(&m_ipHead),
+ m_count(0),
+ m_countDisabled(0)
+{
+ m_ipHead.caption = NULL;
+ m_ipHead.ip64 = 0L;
+ m_ipHead.next = NULL;
+}
+
+CIpList::~CIpList() {
+ Clear();
+}
+
+void CIpList::Clear() {
+ for(CIp *ip = m_ipHead.next; ip; ip = ip->next)
+ delete[] ip->caption;
+ m_poolIp.purge_memory();
+ m_ipHead.next = NULL;
+ m_ipFoot = &m_ipHead;
+ m_count = 0;
+ m_countDisabled = 0;
+ UnSetFilter();
+}
+
+void CIpList::SetFilter(const char *filter, const filter::EFilterMode mode, const bool del) {
+ m_filter.Assign(filter, mode, del);
+}
+
+void CIpList::UnSetFilter() {
+ m_filter.Clear();
+}
+
+CIp * CIpList::CreateIp(boost::xpressive::cmatch & match) {
+ CIp *ip = (CIp*)m_poolIp.malloc();
+
+ const char *capBegin = match.prefix().first;
+ const char *capEnd = match[9].first;
+ size_t lenCap = capEnd - capBegin;
+ char *chunk = new char[lenCap + 1];
+ memcpy(chunk, capBegin, lenCap);
+ *(chunk + lenCap) = '\0';
+ ip->caption = chunk;
+
+ uchar *ip8 = ip->ip8;
+ ip8[4] = ParseDigit3(match[4].first, match[4].second);
+ ip8[5] = ParseDigit3(match[3].first, match[3].second);
+ ip8[6] = ParseDigit3(match[2].first, match[2].second);
+ ip8[7] = ParseDigit3(match[1].first, match[1].second);
+
+ if(*(match[10].first) == '-') {
+ ip8[0] = ParseDigit3(match[8].first, match[8].second);
+ ip8[1] = ParseDigit3(match[7].first, match[7].second);
+ ip8[2] = ParseDigit3(match[6].first, match[6].second);
+ ip8[3] = ParseDigit3(match[5].first, match[5].second);
+ } else {
+ ip->ip32[0] = ip->ip32[1] | (0xFFFFFFFF >> ParseDigit3(match[11].first, match[11].second));
+ }
+
+ return ip;
+}
+
+bool CIpList::LoadListFile(const char *path) {
+ char buf[PGLU_LENGTH_FILELINE];
+ char colon;
+ char *colon_p;
+
+ using namespace boost::xpressive;
+
+ static cmatch match;
+ static mark_tag tagIp1(1), tagIp2(2), tagIp3(3), tagIp4(4), tagIp5(5), tagIp6(6), tagIp7(7), tagIp8(8);
+ static mark_tag tagColon(9), tagSep(10), tagMask(11);
+
+ static cregex reSyntax = // bos >> (tag = *_) >> // slower
+ (tagColon = as_xpr(':')) >> *_s >>
+ (tagIp1 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp2 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp3 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp4 = repeat<1, 3>(_d)) >>
+ *_s >> (tagSep = as_xpr('-')) >> *_s >>
+ (tagIp5 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp6 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp7 = repeat<1, 3>(_d)) >> as_xpr('.') >>
+ (tagIp8 = repeat<1, 3>(_d)) >>
+ *_s >> (_ln | eos);
+
+ static cregex reSyntaxRestorable =
+ (tagColon = !as_xpr(':')) >> *_s >>
+ (tagIp1 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp2 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp3 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp4 = repeat<1, 3>(_d)) >> *_s >> (
+ (tagSep = +as_xpr('-')) >> *_s >>
+ (tagIp5 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp6 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp7 = repeat<1, 3>(_d)) >> (set = '.', ',') >>
+ (tagIp8 = repeat<1, 3>(_d))
+ |
+ (tagSep = +(set = '/', '\\')) >> *_s >>
+ (tagMask = repeat<1, 2>(_d))
+ ) >> *_s >> (_ln | eos);
+
+ FILE *fp = fopen(path, "r");
+ if(fp == NULL)
+ return false;
+
+ CIp *ip = m_ipFoot;
+
+ if(m_filter.IsEmpty()) {
+ while(fgets(buf, PGLU_LENGTH_FILELINE, fp)) {
+
+ if(regex_search(buf, match, reSyntax) || regex_search(buf, match, reSyntaxRestorable)) {
+ ++m_count;
+ ip->next = CreateIp(match);
+ ip = ip->next;
+ }
+#ifdef __MINGW32__
+ ZeroString(buf);
+#endif
+ }
+ } else {
+ while(fgets(buf, PGLU_LENGTH_FILELINE, fp)) {
+
+ if(regex_search(buf, match, reSyntax) || regex_search(buf, match, reSyntaxRestorable)) {
+ colon_p = (char*)(match[9].first);
+ colon = *colon_p;
+ *colon_p = '\0';
+
+ if(m_filter.IsMatch(buf)) {
+ ++m_count;
+ ip->next = CreateIp(match);
+ ip = ip->next;
+ }
+ *colon_p = colon;
+ }
+#ifdef __MINGW32__
+ ZeroString(buf);
+#endif
+ }
+ }
+ fclose(fp);
+ ip->next = NULL;
+ m_ipFoot = ip;
+ return true;
+}
+
+bool CIpList::SaveListFile(const char *path, const bool append) {
+ uchar *ip8;
+
+ FILE *fp = fopen(path, (append ? "a" : "w"));
+ if(fp == NULL)
+ return false;
+
+ for(CIp *ip = m_ipHead.next; ip; ip = ip->next) {
+ // IP‚ª0L‚Ȃ瑂«o‚³‚È‚¢
+ if(ip->ip64 != 0L) {
+ ip8 = ip->ip8;
+ fprintf(fp,
+ "%s:%u.%u.%u.%u-%u.%u.%u.%u\n",
+ ip->caption,
+ ip8[7], ip8[6], ip8[5], ip8[4],
+ ip8[3], ip8[2], ip8[1], ip8[0]
+ );
+ }
+ }
+ fclose(fp);
+ return true;
+}
+
+void CIpList::CheckAndSort(const bool sortCap, const bool sortIp, const bool delDupIp) {
+ CIp **ipBegin;
+ CIp **ipEnd;
+ CIp *ip;
+
+ if(m_count < 2)
+ return;
+
+ if(sortIp || delDupIp) {
+ // ƒŠƒXƒg‚©‚ç”z—ñ‚ð•¡»
+ CIp **ipSort = new CIp*[m_count];
+ ipBegin = ipSort;
+ for(ip = m_ipHead.next; ip; ip = ip->next)
+ *(ipBegin++) = ip;
+
+ // ”z—ñ‚ðƒ\[ƒg
+ Ip_SortByIp(ipSort, ipSort + m_count - 1);
+
+ if(delDupIp) {
+ // ‚·‚Å‚ÉIP‚ª0L‚È‚à‚̂𖳌ø‚Æ‚µ‚ăJƒEƒ“ƒg
+ ipBegin = ipSort;
+ ipEnd = ipBegin + m_count;
+
+ for(; ipBegin != ipEnd && (*ipBegin)->ip64 == 0L; ++ipBegin)
+ ++m_countDisabled;
+ if(ipBegin == ipEnd)
+ goto END_SORT; // ‘S‚Ä‚ÌIP‚ª0L
+
+ // d•¡‚µ‚½IP‚Í0L‚É‚µ‚Ä–³Œø‚Æ‚µ‚ăJƒEƒ“ƒg
+ for(--ipEnd; ipBegin != ipEnd; ++ipBegin)
+ if((*ipBegin)->ip64 == (*(ipBegin + 1))->ip64) {
+ (*ipBegin)->ip64 = 0L;
+ ++m_countDisabled;
+ }
+ }
+ if(sortIp) {
+ // ”z—ñ‚Ì’†g‚ð˜AŒ‹
+ ipBegin = ipSort;
+ ipEnd = ipSort + m_count;
+ ip = &m_ipHead;
+ while(ipBegin != ipEnd) {
+ ip->next = *(ipBegin++);
+ ip = ip->next;
+ }
+ ip->next = NULL;
+ }
+ END_SORT:
+ delete[] ipSort;
+ }
+
+ if(sortCap)
+ m_ipHead.next = Ip_SortByCaption(m_ipHead.next);
+
+ if(sortIp || sortCap) {
+ // m_ipFoot‚ðÄÝ’è
+ ip = m_ipHead.next;
+ if(ip) {
+ for(; ip->next; ip = ip->next);
+ m_ipFoot = ip;
+ } else {
+ m_ipFoot = &m_ipHead;
+ }
+ }
+}
+
+int CIpList::Count() {
+ return m_count;
+}
+
+int CIpList::CountDisabled() {
+ return m_countDisabled;
+}
+
+} // namespace ip
+} // namespace pglu
diff --git a/tool/PGListUtil/src/common/CIpList.h b/tool/PGListUtil/src/common/CIpList.h new file mode 100644 index 00000000..591c3877 --- /dev/null +++ b/tool/PGListUtil/src/common/CIpList.h @@ -0,0 +1,56 @@ +#ifndef CIPLIST_H
+#define CIPLIST_H
+
+#include <boost/pool/pool.hpp>
+#include <boost/xpressive/xpressive.hpp>
+#include "common.h"
+#include "CFilter.h"
+
+namespace pglu {
+namespace ip {
+
+struct CIp {
+ char * caption;
+ union {
+ ulong ip64;
+ uint ip32[2];
+ uchar ip8[8];
+ };
+ CIp * next;
+};
+
+class CIpList {
+private:
+ boost::pool<> m_poolIp;
+ CIp m_ipHead;
+ CIp * m_ipFoot;
+
+ filter::CFilter m_filter;
+
+ int m_count;
+ int m_countDisabled;
+
+ CIp * CreateIp(boost::xpressive::cmatch & match);
+
+public:
+ CIpList();
+ ~CIpList();
+
+ void Clear();
+
+ void SetFilter(const char *filter, const filter::EFilterMode mode, const bool del);
+ void UnSetFilter();
+
+ bool LoadListFile(const char *path);
+ bool SaveListFile(const char *path, const bool append);
+
+ void CheckAndSort(const bool sortCap, const bool sortIp, const bool delDupIp);
+
+ int Count();
+ int CountDisabled();
+};
+
+} // namespace ip
+} // namespace pglu
+
+#endif // CIPLIST_H
diff --git a/tool/PGListUtil/src/common/common.h b/tool/PGListUtil/src/common/common.h new file mode 100644 index 00000000..60530d5b --- /dev/null +++ b/tool/PGListUtil/src/common/common.h @@ -0,0 +1,48 @@ +#ifndef COMMON_H
+#define COMMON_H
+
+#ifdef _MSC_VER
+
+typedef unsigned __int8 uchar;
+typedef unsigned __int32 uint;
+typedef unsigned __int64 ulong;
+
+# else
+
+#include <boost/cstdint.hpp>
+
+typedef uint8_t uchar;
+typedef uint32_t uint;
+typedef uint64_t ulong;
+
+#endif
+
+namespace pglu {
+
+#define PGLU_LENGTH_FILELINE 1024
+
+inline uint ParseDigit3(const char *begin, const char *end) {
+ switch(end - begin) {
+ case 3:
+ return ((*begin & 0xF) * 100) + ((*(begin + 1) & 0xF) * 10) + (*(begin + 2) & 0xF);
+ case 2:
+ return ((*begin & 0xF) * 10) + (*(begin + 1) & 0xF);
+ case 1:
+ return (*begin & 0xF);
+ default:
+ return 256;
+ }
+}
+
+#ifdef __MINGW32__
+
+inline void ZeroString(char *str) {
+ while(*str != '\0')
+ *(str++) = '\0';
+}
+
+#endif
+
+} // namespace pglu
+
+#endif // COMMON_H
|