特殊検索を実装。
gettid() をちょっとマシにした。
@@ -2228,7 +2228,7 @@ | ||
2228 | 2228 | case 1: |
2229 | 2229 | YY_RULE_SETUP |
2230 | 2230 | #line 35 "expr_scan.lex" |
2231 | - | |
2231 | +comment( yytext ); | |
2232 | 2232 | YY_BREAK |
2233 | 2233 | case 2: |
2234 | 2234 | YY_RULE_SETUP |
@@ -0,0 +1,7 @@ | ||
1 | +#ifndef MAKAI_H__ | |
2 | +#define MAKAI_H__ | |
3 | + | |
4 | +#define MAKAI_TRUE 1 | |
5 | +#define MAKAI_FALSE 0 | |
6 | + | |
7 | +#endif /* MAKAI_H__ */ |
@@ -32,7 +32,7 @@ | ||
32 | 32 | SJIS2 [\x40-\x7E\x80-\xFC] |
33 | 33 | %% |
34 | 34 | |
35 | -"#"[^\r\n]*[\r]* | |
35 | +"#"[^\r\n]*[\r]* comment( yytext ); | |
36 | 36 | |
37 | 37 | ({CHAR}|{CHX}|{CHXE}){11,} expr_error("ターゲット<%s:%d文字くらい>は明らかに長すぎるので無視!", yytext, yyleng); return JUNK; |
38 | 38 |
@@ -304,20 +304,15 @@ | ||
304 | 304 | 優先度設定したりアイドルスレッド起こしても |
305 | 305 | おもしろくないので、そのへんは今後の研究課題。 */ |
306 | 306 | |
307 | -#if 0 | |
308 | 307 | #include <linux/unistd.h> |
309 | -_syscall0(pid_t,gettid) | |
310 | -#define thread_get_tid() gettid() | |
311 | -#endif /* 0 */ | |
308 | +#ifdef _syscall0 | |
309 | + _syscall0(pid_t,gettid) | |
310 | + #define thread_get_tid() gettid() | |
311 | +#else /* _syscall0 */ | |
312 | + #include <sys/syscall.h> | |
313 | + #define thread_get_tid() (pid_t)syscall(SYS_gettid) | |
314 | +#endif /* _syscall0 */ | |
312 | 315 | |
313 | -#if 0 | |
314 | -#include <sys/types.h> | |
315 | -#define thread_get_tid() gettid() | |
316 | -#endif /* 0 */ | |
317 | - | |
318 | -#include <sys/syscall.h> | |
319 | -#define thread_get_tid() (pid_t)syscall(SYS_gettid) | |
320 | - | |
321 | 316 | static |
322 | 317 | int thread_set_affinity(pid_t tid, int i) |
323 | 318 | { |
@@ -597,6 +592,8 @@ | ||
597 | 592 | int sCnt; |
598 | 593 | int tmplCntMax; |
599 | 594 | int maxSrchCnt; |
595 | + int verbose; | |
596 | + DWORD priority; | |
600 | 597 | |
601 | 598 | /* 鍵文字列 */ |
602 | 599 | struct KS_KEY key; |
@@ -632,8 +629,6 @@ | ||
632 | 629 | char *chPtr; |
633 | 630 | uint64_t availMask; |
634 | 631 | uint64_t pmask; |
635 | - DWORD priority; | |
636 | - int verbose; | |
637 | 632 | |
638 | 633 | availMask = thread_avail(); /* 有効なマスク */ |
639 | 634 | availCPU = popcnt64( availMask ); /* 有効な CPU 数 */ |
@@ -752,7 +747,19 @@ | ||
752 | 747 | |
753 | 748 | nThread = popcnt64( proc_mask ); |
754 | 749 | printf( "%d 個の検索スレッドを起動\n", nThread ); |
750 | +} | |
755 | 751 | |
752 | + assert((1 << N_STRIDE) == N_ALU * ALU_BITS); | |
753 | + | |
754 | + mutex_key = CreateMutex(NULL, FALSE, NULL); | |
755 | + | |
756 | +#ifdef SPECIAL | |
757 | + initSpecial(); | |
758 | +#endif /* SPECIAL */ | |
759 | + | |
760 | + /* タゲ読み込み */ | |
761 | + root_expr = expr_parse("target.txt"); | |
762 | + | |
756 | 763 | if ( verbose ) { |
757 | 764 | int i; |
758 | 765 | printf( "優先度を" ); |
@@ -777,9 +784,15 @@ | ||
777 | 784 | if ( fixedSalt[0] != '\0' ) { |
778 | 785 | printf( "全空間モード (salt:%c%c)\n", fixedSalt[0], fixedSalt[1] ); |
779 | 786 | } |
787 | +#ifdef SPECIAL | |
788 | + dispSpecial(); | |
789 | +#else /* SPECIAL */ | |
790 | + printf( "特殊検索は無効化されています\n" ); | |
791 | +#endif /* SPECIAL */ | |
780 | 792 | } |
781 | 793 | |
782 | 794 | #ifdef WIN32 |
795 | + /* 【注意】priority を上書きしている */ | |
783 | 796 | switch ( priority ) { |
784 | 797 | case PRIO_NORM : priority = NORMAL_PRIORITY_CLASS; break; |
785 | 798 | case PRIO_BELO : priority = BELOW_NORMAL_PRIORITY_CLASS; break; |
@@ -787,15 +800,7 @@ | ||
787 | 800 | } |
788 | 801 | SetPriorityClass( GetCurrentProcess(), priority ); |
789 | 802 | #endif |
790 | -} | |
791 | 803 | |
792 | - assert((1 << N_STRIDE) == N_ALU * ALU_BITS); | |
793 | - | |
794 | - mutex_key = CreateMutex(NULL, FALSE, NULL); | |
795 | - | |
796 | - /* タゲ読み込み */ | |
797 | - root_expr = expr_parse("target.txt"); | |
798 | - | |
799 | 804 | /* コードを生成・展開 |
800 | 805 | 起動予定スレッド数に応じて |
801 | 806 | 生成するコードを変える */ |
@@ -0,0 +1,244 @@ | ||
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <string.h> | |
4 | + | |
5 | +#include "special.h" | |
6 | +#include "util.h" | |
7 | + | |
8 | +#define TRIP_LEN 10 | |
9 | + | |
10 | +#define ST_ALLN 1 /* 全数 */ | |
11 | +#define ST_NIKO 1<<0x1 /* 二構 */ | |
12 | +#define ST_BUOO 1<<0x8 /* ぶお */ | |
13 | +#define ST_DOSU 1<<0x9 /* 怒数 */ | |
14 | +#define ST_CHIN 1<<0xb /* ちん */ | |
15 | +#define ST_EROI 1<<0xc /* エロ */ | |
16 | +#define ST_HREN 1<<0xd /* 飛連 */ | |
17 | +#define ST_YAKU 1<<0xe /* 八雲 */ | |
18 | + | |
19 | +int special; | |
20 | + | |
21 | +static FILE *nfp; /* 全数 */ | |
22 | +#define LOGNUM "lognum.txt" | |
23 | +static FILE *cfp; /* ち */ | |
24 | +#define LOGCHI "logchi.txt" | |
25 | +static FILE *tfp; /* ↑以外の特殊検索 */ | |
26 | +#define LOGSPE "logspe.txt" | |
27 | + | |
28 | +void | |
29 | +dispSpecial() | |
30 | +{ | |
31 | + printf( "特殊検索オプション : " ); | |
32 | + if ( special & ST_DOSU ) { | |
33 | + printf( "怒数 " ); | |
34 | + } else { | |
35 | + if ( special & ST_ALLN ) { | |
36 | + printf( "全数 " ); | |
37 | + } | |
38 | + } | |
39 | + if ( special & ST_EROI ) { | |
40 | + printf( "エロ " ); | |
41 | + } | |
42 | + if ( special & ST_NIKO ) { | |
43 | + printf( "二構 " ); | |
44 | + } | |
45 | + if ( special & ST_BUOO ) { | |
46 | + printf( "ぶお " ); | |
47 | + } | |
48 | + if ( special & ST_CHIN ) { | |
49 | + printf( "ちん " ); | |
50 | + } | |
51 | + if ( special & ST_HREN ) { | |
52 | + printf( "飛連 " ); | |
53 | + } | |
54 | + if ( special & ST_YAKU ) { | |
55 | + printf( "八雲 " ); | |
56 | + } | |
57 | + if ( special ) { | |
58 | + printf( "オン!\n" ); | |
59 | + } else { | |
60 | + printf( "オールオフ!\n" ); | |
61 | + } | |
62 | +} | |
63 | + | |
64 | +void | |
65 | +initSpecial() | |
66 | +{ | |
67 | + special = 0; | |
68 | + | |
69 | + if ( (tfp = fopen( LOGSPE, "at" )) == NULL ) { | |
70 | + perror( LOGSPE ); | |
71 | + exit( 1 ); | |
72 | + } | |
73 | + setvbuf( tfp, NULL, _IONBF, BUFSIZ ); | |
74 | + | |
75 | + if ( (nfp = fopen( LOGNUM, "at" )) == NULL ) { | |
76 | + perror( LOGNUM ); | |
77 | + exit( 1 ); | |
78 | + } | |
79 | + setvbuf( nfp, NULL, _IONBF, BUFSIZ ); | |
80 | + | |
81 | + if ( (cfp = fopen( LOGCHI, "at" )) == NULL ) { | |
82 | + perror( LOGCHI ); | |
83 | + exit( 1 ); | |
84 | + } | |
85 | + setvbuf( cfp, NULL, _IONBF, BUFSIZ ); | |
86 | +} | |
87 | + | |
88 | +void | |
89 | +comment( str ) | |
90 | +char *str; | |
91 | +{ | |
92 | + if ( strlen( str ) >= 4 ) { | |
93 | + if ( str[1] == '[' && str[3] == ']' ) { | |
94 | + switch ( str[2] ) { | |
95 | + case '0': special |= ST_ALLN; break; | |
96 | + case '1': special |= ST_NIKO; break; | |
97 | + case '8': special |= ST_BUOO; break; | |
98 | + case '9': special |= (ST_DOSU | ST_ALLN); break; | |
99 | + case 'd': special |= ST_HREN; break; | |
100 | + case 'e': special |= ST_YAKU; break; | |
101 | + case 'Y': special |= ST_CHIN; break; | |
102 | + case 'Z': special |= ST_EROI; break; | |
103 | +#if 0 | |
104 | +#ifdef KEYLOG | |
105 | + case 'K': keyLog = MAKAI_TRUE; break; | |
106 | +#endif /* KEYLOG */ | |
107 | + case 'S': | |
108 | + seedOffset = atoi( str + 4 ); | |
109 | + if ( seedOffset < MIN_SOFF || seedOffset > MAX_SOFF ) { | |
110 | + fprintf( stderr, "乱数の種のオフセットは、%d 以上 %d 以下で指定してね。\n", MIN_SOFF, MAX_SOFF ); | |
111 | + fprintf( stderr, "%d は範囲外なので無視します。\n", seedOffset ); | |
112 | + seedOffset = 0; | |
113 | + } | |
114 | + break; | |
115 | +#endif /* 0 */ | |
116 | + } | |
117 | + } | |
118 | + } | |
119 | +} | |
120 | + | |
121 | +/* ヒット時には出力ファイルへのポインタを返す */ | |
122 | +FILE * | |
123 | +checkSpecial( trip, kind ) | |
124 | +char *trip; | |
125 | +unsigned char *kind; | |
126 | +{ | |
127 | + OLDPRINT( "trip %s\n", trip ); | |
128 | + | |
129 | + if ( special & ST_CHIN ) { | |
130 | + /* ^Chi(r */ | |
131 | + if ( trip[0] == 'C' && trip[1] == 'h' && trip[2] == 'i' && | |
132 | + trip[3] == 'n' && trip[4] == 'k' && trip[5] == 'o' ) { | |
133 | + strcpy( kind, "ち" ); | |
134 | + return( cfp ); | |
135 | + } | |
136 | + } | |
137 | + | |
138 | + if ( special & ST_BUOO ) { | |
139 | + /* ぶお [A-Za-z]aoo[A-Za-z]uoo$ */ | |
140 | + if ( trip[3] == 'a' && trip[4] == 'o' && trip[5] == 'o' && | |
141 | + trip[7] == 'u' && trip[8] == 'o' && trip[9] == 'o' && | |
142 | + isalpha( trip[2] ) && isalpha( trip[6] ) ) { | |
143 | + strcpy( kind, "ぶ" ); | |
144 | + return( tfp ); | |
145 | + } | |
146 | + } | |
147 | + | |
148 | + if ( special & ST_EROI ) { | |
149 | + int i; | |
150 | + /* エロい人型二構 その 1 looooloooo */ | |
151 | + if ( trip[0] == trip[5] && | |
152 | + trip[1] == trip[2] && trip[1] == trip[3] && trip[1] == trip[4] && | |
153 | + trip[1] == trip[6] && trip[1] == trip[7] && trip[1] == trip[8] && | |
154 | + trip[1] == trip[9] ) { | |
155 | + strcpy( kind, "エ" ); | |
156 | + return( tfp ); | |
157 | + } | |
158 | + /* エロい人型二構 その 2 [./] */ | |
159 | + for ( i = 0; i < TRIP_LEN; i++ ) { | |
160 | + if ( trip[i] != '.' && trip[i] != '/' ) { | |
161 | + goto NOEROI; | |
162 | + } | |
163 | + } | |
164 | + strcpy( kind, "エ" ); | |
165 | + return( tfp ); | |
166 | + } | |
167 | + NOEROI: | |
168 | + | |
169 | + if ( special & ST_NIKO ) { | |
170 | + /* 二構 */ | |
171 | + int i; | |
172 | + char ch1, ch2; | |
173 | + ch1 = trip[0]; | |
174 | + for ( i = 1; i < TRIP_LEN; i++ ) { | |
175 | + if ( trip[i] != ch1 ) break; | |
176 | + } | |
177 | + ch2 = trip[i]; | |
178 | + for ( ; i < TRIP_LEN; i++ ) { | |
179 | + if ( trip[i] != ch1 && trip[i] != ch2 ) goto NONIKO; | |
180 | + } | |
181 | + strcpy( kind, "二" ); | |
182 | + return( tfp ); | |
183 | + } | |
184 | + NONIKO: | |
185 | + | |
186 | + if ( special & ST_YAKU ) { | |
187 | + /* 八雲 */ | |
188 | + if ( trip[0] == trip[1] && trip[0] == trip[2] && | |
189 | + trip[3] == trip[4] && trip[3] == trip[5] && | |
190 | + trip[6] == trip[7] && trip[6] == trip[8] && trip[9] == '.' ) { | |
191 | + strcpy( kind, "八" ); | |
192 | + return( tfp ); | |
193 | + } | |
194 | + } | |
195 | + | |
196 | + /* 飛連関連のコードは、セロリン ◆Celeron/rc 作 */ | |
197 | + if ( special & ST_HREN ) { | |
198 | + /* 飛連 */ | |
199 | + int w, x = 0, y = 0; | |
200 | + for ( w = 0; w < TRIP_LEN; w++ ) { | |
201 | + if ( trip[w] == trip[0] ) x += 1; | |
202 | + if ( trip[w] == trip[1] ) y += 1; | |
203 | + if ( x >= 8 || y >= 8 ) { | |
204 | + strcpy( kind, "飛" ); | |
205 | + return( tfp ); | |
206 | + } | |
207 | + } | |
208 | + } | |
209 | + | |
210 | + if ( special & ST_ALLN ) { | |
211 | + /* 全数 か 怒数 */ | |
212 | + if ( isdigit( trip[0] ) && isdigit( trip[1] ) && isdigit( trip[2] ) && | |
213 | + isdigit( trip[3] ) && isdigit( trip[4] ) && isdigit( trip[5] ) && | |
214 | + isdigit( trip[6] ) && isdigit( trip[7] ) && isdigit( trip[8] ) && | |
215 | + isdigit( trip[9] ) ) { | |
216 | + if ( special & ST_DOSU ) { | |
217 | + /* 全数 & 回文 */ | |
218 | + if ( trip[0] == trip[9] && trip[1] == trip[8] && trip[2] == trip[7] && | |
219 | + trip[3] == trip[6] && trip[4] == trip[5] ) { | |
220 | + strcpy( kind, "怒" ); | |
221 | + return( tfp ); | |
222 | + } | |
223 | + /* 全数 & 双連 */ | |
224 | + if ( trip[0] == trip[1] && trip[2] == trip[3] && trip[4] == trip[5] && | |
225 | + trip[6] == trip[7] && trip[8] == trip[9] ) { | |
226 | + strcpy( kind, "怒" ); | |
227 | + return( tfp ); | |
228 | + } | |
229 | + /* 全数 & 山彦 */ | |
230 | + if ( trip[0] == trip[5] && trip[1] == trip[6] && trip[2] == trip[7] && | |
231 | + trip[3] == trip[8] && trip[4] == trip[9] ) { | |
232 | + strcpy( kind, "怒" ); | |
233 | + return( tfp ); | |
234 | + } | |
235 | + /* 最大と最小は、純 8 連で出るので削除 */ | |
236 | + } else { | |
237 | + strcpy( kind, "数" ); | |
238 | + return( nfp ); | |
239 | + } | |
240 | + } | |
241 | + } | |
242 | + | |
243 | + return( NULL ); | |
244 | +} |
@@ -47,13 +47,16 @@ | ||
47 | 47 | |
48 | 48 | static |
49 | 49 | int |
50 | -log_printf(char const *fmt, ...) | |
50 | +log_printf(FILE *fp, char const *fmt, ...) | |
51 | 51 | { |
52 | 52 | int r; |
53 | 53 | va_list ap; |
54 | 54 | va_start(ap, fmt); |
55 | 55 | vfprintf(stdout, fmt, ap); |
56 | - r = vfprintf(ofp, fmt, ap); | |
56 | + if ( fp == NULL ) { | |
57 | + fp = ofp; | |
58 | + } | |
59 | + r = vfprintf(fp, fmt, ap); | |
57 | 60 | va_end(ap); |
58 | 61 | if (r > 0) |
59 | 62 | return r; |
@@ -62,7 +65,7 @@ | ||
62 | 65 | } |
63 | 66 | |
64 | 67 | void |
65 | -log_print(int full, char const *hash, uint8_t const *key) | |
68 | +log_print(FILE *fp, int full, char const *hash, uint8_t const *key) | |
66 | 69 | { |
67 | 70 | struct timeb tb; |
68 | 71 | struct tm *plt; |
@@ -76,7 +79,7 @@ | ||
76 | 79 | |
77 | 80 | if (full && fixedSalt[0] == '\0') |
78 | 81 | { |
79 | - log_printf("◆%s #%s" | |
82 | + log_printf(fp, "◆%s #%s" | |
80 | 83 | "\t%04d/%02d/%02d %02d:%02d:%02d.%03d" |
81 | 84 | "\t(%02X %02X %02X %02X %02X %02X %02X %02X/%02X)\n", |
82 | 85 | hash, |
@@ -94,7 +97,7 @@ | ||
94 | 97 | } |
95 | 98 | else |
96 | 99 | { |
97 | - log_printf("◆%s ##%02x%02x%02x%02x%02x%02x%02x%02x%s" | |
100 | + log_printf(fp, "◆%s ##%02x%02x%02x%02x%02x%02x%02x%02x%s" | |
98 | 101 | "\t%04d/%02d/%02d %02d:%02d:%02d.%03d" |
99 | 102 | "\t \n", /* ……。ま、いっか */ |
100 | 103 | hash, |
@@ -6,6 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | +#include <stdio.h> | |
9 | 10 | #include <string.h> |
10 | 11 | |
11 | 12 | #include "desconst.h" |
@@ -83,6 +84,10 @@ | ||
83 | 84 | int xkey_loaded = 0; |
84 | 85 | uint8_t xkey_buf[8][16][8]; |
85 | 86 | |
87 | +#ifdef SPECIAL | |
88 | + extern int special; | |
89 | +#endif /* SPECIAL */ | |
90 | + | |
86 | 91 | for (kk = 0; kk < N_ALU; kk++) |
87 | 92 | { |
88 | 93 |
@@ -90,6 +95,35 @@ | ||
90 | 95 | if (!(kk & (N_ALU / N_Q - 1))) |
91 | 96 | xhash_loaded = 0; |
92 | 97 | |
98 | +#ifdef SPECIAL | |
99 | + if ( special ) { | |
100 | + char hash[16]; | |
101 | + FILE *lfp; | |
102 | + unsigned char kind[3]; | |
103 | + uint8_t buf[32]; | |
104 | + | |
105 | + CALL_TR64(&pkt_c->param64.lr[0][0].q[kk / (N_ALU / N_Q)], xhash); | |
106 | + xhash_loaded = 1; | |
107 | + for ( k = 0; k < ALU_BITS; k++ ) { | |
108 | + for ( i = 1; i < 11; i++ ) { | |
109 | + unsigned c = 0; | |
110 | + c = (xhash[(ALU_BITS * kk + k) & 63] >> (6 * (i - 1))) & 0x3F; | |
111 | + hash[i - 1] = C64[c]; | |
112 | + } | |
113 | + hash[10] = 0; | |
114 | + if ( (lfp = checkSpecial( hash, kind )) != NULL ) { | |
115 | + trk8(pkt_c, &xkey_buf[0][0][0]); | |
116 | + xkey_loaded = 1; | |
117 | + for ( i = 0; i < 8; i++ ) { | |
118 | + buf[i] = xkey_buf[i][0][((ALU_BITS * kk + k) >> 3) | (((ALU_BITS * kk + k) & 7) << 4)]; | |
119 | + } | |
120 | + buf[8] = buf[9] = 0; | |
121 | + log_print(lfp, translate(buf, 0, 1), hash, buf); | |
122 | + } | |
123 | + } | |
124 | + } | |
125 | +#endif /* SPECIAL */ | |
126 | + | |
93 | 127 | t = hit[HIT_ANY].a[kk]; |
94 | 128 | if (!t) |
95 | 129 | continue; |
@@ -138,7 +172,7 @@ | ||
138 | 172 | } |
139 | 173 | else |
140 | 174 | { |
141 | - log_print(translate(buf, 0, 1), hash, buf); | |
175 | + log_print(NULL, translate(buf, 0, 1), hash, buf); | |
142 | 176 | } |
143 | 177 | } |
144 | 178 | } |
@@ -0,0 +1,9 @@ | ||
1 | +#ifndef SPECIAL_H__ | |
2 | +#define SPECIAL_H__ | |
3 | + | |
4 | +void comment( char *str ); | |
5 | +FILE *checkSpecial( char *trip, unsigned char *kind ); | |
6 | +void initSpecial(); | |
7 | +void dispSpecial(); | |
8 | + | |
9 | +#endif /* SPECIAL_H__ */ |
@@ -4,6 +4,6 @@ | ||
4 | 4 | #include "mtytypes.h" |
5 | 5 | |
6 | 6 | extern int log_open(char const *name); |
7 | -extern void log_print(int full, char const *hash, uint8_t const *key); | |
7 | +extern void log_print(FILE *fp, int full, char const *hash, uint8_t const *key); | |
8 | 8 | |
9 | 9 | #endif /* LOG_H__ */ |