static void y_zap_hashtmp(void *ht) { y_hashtmp *h = ht; HashClear(&h->table); p_free(h); }
/* Insert a row into the full-text index; set *piRowid to be the ID of the * new row. */ static int index_insert(fulltext_vtab *v, sqlite3_value *pRequestRowid, const char *zText, sqlite_int64 *piRowid){ Hash terms; /* maps term string -> PosList */ HashElem *e; int rc = content_insert(v, pRequestRowid, zText, -1); if( rc!=SQLITE_OK ) return rc; *piRowid = sqlite3_last_insert_rowid(v->db); if( !zText ) return SQLITE_OK; /* nothing to index */ rc = build_terms(&terms, v->pTokenizer, zText, *piRowid); if( rc!=SQLITE_OK ) return rc; for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); rc = index_insert_term(v, HashKey(e), HashKeysize(e), *piRowid, p); if( rc!=SQLITE_OK ) break; } for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); docListDelete(p); } HashClear(&terms); return rc; }
TAction* HashCreateXdbKeys(Transaction *t, const char *hash_name, const char *db_name) { size_t existvar = t->MakeVariable(); size_t keylistvar = t->MakeVariable(); size_t keyvar = t->MakeVariable(); TOperand *existarg = new TOperandVariable(t, existvar); TOperand *keylistarg = new TOperandVariable(t, keylistvar); TOperand *keyarg = new TOperandVariable(t, keyvar); TActionIterate *key_iter = new TActionIterate(t, keyvar, keylistarg); key_iter->PushAction(HashInsertKey(t, hash_name, keyarg)); TActionTest *nex_test = new TActionTest(t, existarg, false); nex_test->PushAction(HashClear(t, hash_name)); nex_test->PushAction(XdbAllKeys(t, db_name, keylistvar)); nex_test->PushAction(key_iter); TActionSequence *sequence = new TActionSequence(t); sequence->PushAction(HashExists(t, hash_name, existvar)); sequence->PushAction(nex_test); return sequence; }
/* Remove a single entry from the hash table given a pointer to that ** element and a hash on the element's key. */ static void removeElementGivenHash( Hash *pH, /* The pH containing "elem" */ HashElem* elem, /* The element to be removed from the pH */ int h /* Hash value for the element */ ){ struct _ht *pEntry; if( elem->prev ){ elem->prev->next = elem->next; }else{ pH->first = elem->next; } if( elem->next ){ elem->next->prev = elem->prev; } pEntry = &pH->ht[h]; if( pEntry->chain==elem ){ pEntry->chain = elem->next; } pEntry->count--; if( pEntry->count<=0 ){ pEntry->chain = 0; } if( pH->copyKey && elem->pKey ){ pH->xFree(elem->pKey); } pH->xFree( elem ); pH->count--; if( pH->count<=0 ){ assert( pH->first==0 ); assert( pH->count==0 ); HashClear(pH); } }
Hash* HashAlloc(int n) { Hash *hash; hash = calloc(1, sizeof(Hash)); hash->size = n; hash->table = calloc(n, sizeof(HashRecord)); if(hash->table == NULL) { return(NULL); } HashClear(hash); }
static void ClearParser(void *func) { long i; extern int yp_continue; yp_continue = 0; HashClear(&literalTable); /* sets literalTable.maxItems==0 */ p_free(literalTypes); literalTypes= 0; reparsing= func; nYpReList= 0; p_free(ypReList); ypReList= 0; for (i=0 ; i<nConstants ; i++) if (constantTable[i].ops==&dataBlockSym) Unref(constantTable[i].value.db); nConstants= maxConstants= 0; p_free(constantTable); constantTable= 0; nextPC= 0; if (vmCodeSize > 1024L) vmCodeSize= 0; /* force realloc */ else memset(vmCode, 0, sizeof(Instruction)*vmCodeSize); previousOp= 0; wasUndecided= 0; nVariableRefs= nConstantRefs= nGotoTargets= 0; if (maxVariableRefs > 256L) maxVariableRefs= 0; /* force realloc */ if (maxConstantRefs > 256L) maxConstantRefs= 0; /* force realloc */ if (maxGotoTargets > 256L) maxGotoTargets= 0; /* force realloc */ nPos= nKey= nLocal= nTarget= 0; hasPosList= 0; stackDepth= maxStackDepth= didMaxDepth= 0; nextInc= 0; if (incCodeSize > 64L) incCodeSize= 0; /* force realloc */ loopDepth= 0; nextBSP= 0; if (breakStackSize > 16L) breakStackSize= 0; /* force realloc */ nMatrixMarkers= 0; if (maxMatrixMarkers > 16L) maxMatrixMarkers= 0; /* force realloc */ insideFunc= 0; }
int main(int argc, char **argv) { int i; long long diff; int *res = NULL; int times = 10; int clean_avc = 0; struct timespec start, end; if (argc > 1) times = atoi(argv[1]); if (argc > 2) clean_avc = atoi(argv[2]); Hash hmap; HashInit(&hmap, HASH_STRING, 0); char *scon = "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023"; char *tcon = "unconfined_u:object_r:sesqlite_public:s0"; char *clas = "db_column"; char *perm = "select"; char *key = "unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 unconfined_u:object_r:sesqlite_public:s0 db_column select"; res = malloc(sizeof(int)); *res = selinux_check_access(scon, tcon, clas, perm, NULL); HashInsert(&hmap, strdup(key), strlen(key), res); for (i = 0; i < times; ++i) { if ( clean_avc != 0 ){ cleanavc(); HashClear(&hmap); } GETTIME(start) res = HashFind(&hmap, key, strlen(key)); if (res == NULL) { res = malloc(sizeof(int)); *res = selinux_check_access(scon, tcon, clas, perm, NULL); HashInsert(&hmap, strdup(key), strlen(key), res); } GETTIME(end) diff = TIMESPEC_DIFF(start, end); printf("%lld\n", diff); } return 0; }
/* Delete a row from the full-text index. */ static int index_delete(fulltext_vtab *v, sqlite_int64 iRow){ char *zText; Hash terms; HashElem *e; int rc = content_select(v, iRow, &zText); if( rc!=SQLITE_OK ) return rc; rc = build_terms(&terms, v->pTokenizer, zText, iRow); free(zText); if( rc!=SQLITE_OK ) return rc; for(e=HashFirst(&terms); e; e=HashNext(e)){ rc = index_delete_term(v, HashKey(e), HashKeysize(e), iRow); if( rc!=SQLITE_OK ) break; } for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); docListDelete(p); } HashClear(&terms); return content_delete(v, iRow); }
void HashFree(AssocHashTable *hashtable) { HashClear(hashtable); free(hashtable); }
void YpFunc(int isMain, int eol) { long codeSize, i, pc; Function *parsedFunc= 0; DataBlock *oldDB; Symbol *cTable; if (!eol || ypErrors) { if (!eol) YpError("garbage after func or struct definition"); ClearParser((void *)0); return; } if (isMain && nextPC==0) return; /* NOTE- if stackDepth!=0 here, there is a bug in the parser... (unless a previous error involving matrix multiplication?) */ if (previousOp!=&Return) YpReturn(NONE); if (isMain) nLocal= 0; /* end of function marked by code.Action==&Return followed by code.Action==0, followed by code.index==codeSize to enable error recovery to find beginning of function */ if (CheckCodeSpace(2)) { ClearParser((void *)0); return; } vmCode[nextPC++].Action= previousOp= 0; vmCode[nextPC].index= codeSize= 1+nPos+(hasPosList&1)+nKey+nLocal+ nextPC; nextPC++; /* fill in all forward-referenced goto targets */ if (nTarget) { YpError("missing goto label at end of func"); ClearParser((void *)0); return; } for (i=0 ; i<nGotoTargets ; i++) { pc= gotoTargets[i]; SetBranchTarget(pc, (literalTypes[vmCode[pc].index]>>3)); } nGotoTargets= 0; /* shorten constant table to its final size */ if (nConstants) { constantTable= p_realloc(constantTable, nConstants*sizeof(Symbol)); maxConstants= nConstants; } /* fill in all references to constants */ if (!reparsing) cTable= constantTable; else cTable= reparsing->constantTable; for (i=0 ; i<nConstantRefs ; i++) { pc= constantRefs[i]; vmCode[pc].constant= cTable+vmCode[pc].index; } nConstantRefs= 0; /* locate or create all referenced variable names in globTab -- reuse literalTypes array to hold globTab index */ if (CheckCodeSpace(1+nPos+(hasPosList&1)+nKey+nLocal)) { ClearParser((void *)0); return; } if (isMain) { for (i=0 ; i<literalTable.nItems ; i++) if (literalTypes[i]&(L_REFERENCE|L_LOCAL)) literalTypes[i]= Globalize(literalTable.names[i], 0L); vmCode[nextPC++].index= Globalize(isMain==1? "*main*" : literalTable.names[0], 0L); } else { for (i=0 ; i<literalTable.nItems ; i++) { /* Note that function name is first, then positional parameters, then optional *va* parameter, then keyword parameters. */ if (literalTypes[i]&(L_REFERENCE|L_LOCAL)) { if ((literalTypes[i]&(L_REFERENCE|L_LOCAL)) == (L_REFERENCE|L_LOCAL)) vmCode[nextPC++].index= literalTypes[i]= Globalize(literalTable.names[i], 0L); else literalTypes[i]= Globalize(literalTable.names[i], 0L); } } } /* fill in all references to variables */ for (i=0 ; i<nVariableRefs ; i++) { pc= variableRefs[i]; vmCode[pc].index= literalTypes[vmCode[pc].index]; } nVariableRefs= 0; /* done with literal table */ HashClear(&literalTable); /* sets literalTable.maxItems==0 */ p_free(literalTypes); literalTypes= 0; if (!reparsing) parsedFunc= NewFunction(constantTable, nConstants, nPos, nKey, nLocal, hasPosList, maxStackDepth, vmCode, codeSize); else ypReMatch= YpReCompare(reparsing, constantTable, nConstants, nPos, nKey, nLocal, hasPosList, maxStackDepth, vmCode, codeSize); nConstants= maxConstants= 0; constantTable= 0; if (reparsing) return; i= parsedFunc->code[0].index; oldDB= globTab[i].value.db; globTab[i].value.db= (DataBlock *)parsedFunc; if (globTab[i].ops==&dataBlockSym) { Unref(oldDB); } else globTab[i].ops= &dataBlockSym; /* A main function must be pushed onto the stack here; anything else (func or struct definitions) is recorded in the sourceList for the current include file (see also YpExtern). */ if (isMain) PushTask(parsedFunc); else parsedFunc->isrc = RecordSource(i); }
int main(void) { int size = 0, h; char cmd, key[1024], value[1024], buf[1024]; Hash *hash; // ハッシュテーブルの生成 printf("ハッシュテーブルの大きさを入力して下さい: "); scanf("%d", &size); if (size < 1) return -1;// 入力数エラー hash = HashAlloc(size); if (hash == NULL) return -1; // メモリ確保失敗 puts("* ハッシュテーブルを操作するコマンドを入力して下さい."); puts("* データを格納:a"); puts("* キーを削除:x"); puts("* キーに対応するデータの取得:g"); puts("* ハッシュテーブルを表示:d"); puts("* ハッシュ値の表示:h"); puts("* ハッシュテーブルをクリア:c"); puts("* 終了:q"); do { printf(": "); scanf("%s", buf); cmd = buf[0]; switch (cmd) { case 'a': /* データを格納 */ printf("名前を入力して下さい:"); scanf("%s", key); printf("血液型を入力して下さい:"); scanf("%s", value); if (HashAdd(hash, key, value) == TRUE) { // hash, name, blood-type printf("%s=%sを格納しました.\n", key, value); } else { /* 衝突 */ printf("既に同じキーを持つデータが存在します.\n"); } break; case 'd': /* データを表示 */ HashDump(hash); break; case 'c': /* ハッシュテーブルをクリア */ HashClear(hash); break; case 'x': /* キーを削除 */ printf("誰を削除しますか?:"); scanf("%s", key); if(HashDelete(hash, key) == TRUE) { printf("%sを削除しました.\n", key); } else { printf("%sは登録されていません.\n", key); } break; case 'g': /* キーに対応するデータを取得 */ printf("名前を入力して下さい:"); scanf("%s", key); if (HashGet(hash, key, value) == TRUE) { printf("%sの血液型は%sです.\n", key, value); } else { printf("%sは登録されていません.\n", key); } break; case 'h': /* キーに対応するデータを取得 */ printf("名前を入力して下さい:"); scanf("%s", key); h = HashCode(hash, key); printf("%sのハッシュ値は%dです.", key, h); break; case 'q': /* 終了 */ puts("プログラムを終了します."); break; case '\n': /* 改行 */ case '\r': /* 復帰 */ break; default: /* 入力エラー */ puts("コマンドが正しくありません."); break; } } while (cmd != 'q'); HashDump(hash); // 解放前の出力 HashFree(hash); // メモリ解放 return 0; }
// // 関数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: メイン ウィンドウのメッセージを処理します。 // // WM_COMMAND - アプリケーション メニューの処理 // WM_PAINT - メイン ウィンドウの描画 // WM_DESTROY - 中止メッセージを表示して戻る // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HWND boardWnd, hBut[2]; // レバーコントロールのハンドル INITCOMMONCONTROLSEX ic; // INITCOMMONCONTROLSEX構造体 REBARBANDINFO rbBand; // REBARBANDINFO構造体 switch (message) { case WM_CREATE: /* ボード表示ウィンドウの作成 */ //boardWnd = MakeBoardWindow(hWnd); /* レバーコントロールの作成 */ ic.dwSize = sizeof(INITCOMMONCONTROLSEX); ic.dwICC = ICC_COOL_CLASSES; InitCommonControlsEx(&ic); hRebar = MakeMyRebar(hWnd); hListBox = CreateListBox(hWnd); ZeroMemory(&rbBand, sizeof(REBARBANDINFO)); rbBand.cbSize = sizeof(REBARBANDINFO); rbBand.fMask = RBBIM_TEXT | RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE; rbBand.fStyle = RBBS_CHILDEDGE | RBBS_NOGRIPPER; rbBand.cxMinChild = 90; rbBand.cyMinChild = 25; rbBand.hwndChild = CreateWindow("BUTTON", "新規対局", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)NEWGAME_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", "継続対局", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)CONTINUE_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", "中断", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)INTERRUPT_BT, hInst ,NULL); rbBand.cxMinChild = 60; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", "手番変更", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)CHANGE_BT, hInst ,NULL); rbBand.cxMinChild = 90; SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.cxMinChild = 30; rbBand.hwndChild = CreateWindow("BUTTON", "<<", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)FIRST_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", "←", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)UNDO_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", "→", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)REDO_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); rbBand.hwndChild = CreateWindow("BUTTON", ">>", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hRebar, (HMENU)FINAL_BT, hInst ,NULL); SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); //hToolBar = CreateToolbarEx( // hWnd, //親ウィンドウ // WS_CHILD | WS_VISIBLE, //ウィンドウスタイル // ID_TOOLBAR, //コントロールID // 8, //イメージの数 // hInst, // ID_MYBMP, // tbb, // 8, // ボタンの数 // 0, //ボタンの幅 // 0, //ボタンの高さ // 18, //イメージの幅 // 18, //イメージの高さ // sizeof(TBBUTTON)); //SendMessage(hToolBar, TB_INSERTBUTTON, 2, (LPARAM)&tb); hComBox1 = CreateComBox1(hWnd, BOARD_SIZE + 10, 90, 0); SendMessage(hComBox1, CB_SETCURSEL, 0, 0); hComBox2 = CreateComBox1(hWnd, BOARD_SIZE + 10, 120, 1); SendMessage(hComBox2, CB_SETCURSEL, 1, 0); hComBox3 = CreateComBox2(hWnd, BOARD_SIZE + 100, 90, 2); ShowWindow(hComBox3, SW_HIDE); hComBox4 = CreateComBox2(hWnd, BOARD_SIZE + 100, 120, 3); player[0] = HUMAN; player[1] = CPU; /* 初期難易度 */ Onnormal(hWnd, BLACK); Onnormal(hWnd, WHITE); ShowWindow(hListBox, SW_SHOW); //リストボックスを表示 UpdateWindow(hWnd); UpdateWindow(hRebar); //srand((unsigned int)time(NULL)); /* ステータスバー作成 */ hStatus = CreateStatusBar(hWnd); /* 定石データオープン */ open_book_thread(hInst); break; case WM_LBUTTONDOWN: /* 左クリックイベント 打てるマスをクリックすればスレッドが起動 */ if(!AI_THINKING && chk_range_board(lParam)) { Flag_Abort = TRUE; WaitForSingleObject(SIG_HINT_FINISHED, INFINITE); Flag_Abort = FALSE; GameThread(lParam, LBUTTON); } SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]); return 0; case WM_RBUTTONDOWN: RButtonClick(hWnd, hStatus, lParam); return 0; case WM_SET_TEXT_BAR: SendMessage(hStatus, SB_SETTEXT, (WPARAM)0 | 3, (LPARAM)lParam); return 0; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 選択されたメニューの解析: switch (wmId) { /* コンボボックス */ case IDC_COM1: /* 変更された */ if(HIWORD(wParam) == CBN_SELCHANGE) { int index = SendMessage(hComBox1, CB_GETCURSEL, 0, 0); /* 人間を選択 */ if(index == 0) { player[0] = HUMAN; CpuColor = WHITE; ShowWindow(hComBox3, SW_HIDE); } /* CPUを選択 */ else { player[0] = CPU; CpuColor = BLACK; ShowWindow(hComBox3, SW_SHOW); } } break; case IDC_COM2: /* 変更された */ if(HIWORD(wParam) == CBN_SELCHANGE) { int index = SendMessage(hComBox2, CB_GETCURSEL, 0, 0); /* 人間を選択 */ if(index == 0) { player[1] = HUMAN; CpuColor = BLACK; ShowWindow(hComBox4, SW_HIDE); } /* CPUを選択 */ else { player[1] = CPU; CpuColor = WHITE; ShowWindow(hComBox4, SW_SHOW); } } break; case IDC_COM3: /* 変更された */ if(HIWORD(wParam) == CBN_SELCHANGE) { int index = SendMessage(hComBox3, CB_GETCURSEL, 0, 0); /* 難易度 */ switch(index) { case 0: OnVeasy(hWnd, BLACK); break; case 1: Oneasy(hWnd, BLACK); break; case 2: Onnormal(hWnd, BLACK); break; case 3: Onhard(hWnd, BLACK); break; case 4: OnVhard(hWnd, BLACK); break; case 5: OnUhard(hWnd, BLACK); break; case 6: OnSUhard(hWnd, BLACK); break; case 7: OnSSUhard(hWnd, BLACK); break; case 8: OnHUhard(hWnd, BLACK); break; case 9: OnUltra(hWnd, BLACK); break; case 10: OnSUltra(hWnd, BLACK); break; case 11: OnSSUltra(hWnd, BLACK); break; case 12: OnAllSearchWin(hWnd, BLACK); break; case 13: OnAllSearchSD(hWnd, BLACK); break; } } break; case IDC_COM4: /* 変更された */ if(HIWORD(wParam) == CBN_SELCHANGE) { int index = SendMessage(hComBox4, CB_GETCURSEL, 0, 0); /* 難易度 */ switch(index) { case 0: OnVeasy(hWnd, WHITE); break; case 1: Oneasy(hWnd, WHITE); break; case 2: Onnormal(hWnd, WHITE); break; case 3: Onhard(hWnd, WHITE); break; case 4: OnVhard(hWnd, WHITE); break; case 5: OnUhard(hWnd, WHITE); break; case 6: OnSUhard(hWnd, WHITE); break; case 7: OnSSUhard(hWnd, WHITE); break; case 8: OnHUhard(hWnd, WHITE); break; case 9: OnUltra(hWnd, WHITE); break; case 10: OnSUltra(hWnd, WHITE); break; case 11: OnSSUltra(hWnd, WHITE); break; case 12: OnAllSearchWin(hWnd, WHITE); break; case 13: OnAllSearchSD(hWnd, WHITE); break; } } break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case NEWGAME_BT: case StartNew: InitBoard(); /* 置換表の取得 */ HashDelete(ghash); ghash = HashNew(21); HashClear(ghash); /* 再描写 */ hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); GameThread(lParam, STARTGAME); return DefWindowProc(hWnd, message, wParam, lParam); case CONTINUE_BT: /* 置換表の取得 */ if(ghash == NULL){ HashDelete(ghash); ghash = HashNew(21); HashClear(ghash); } if(NowTurn == BLACK) { /* 再描写 */ hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); NowTurn = BLACK; GameThread(lParam, STARTGAME); return DefWindowProc(hWnd, message, wParam, lParam); } else { hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); NowTurn = WHITE; GameThread(lParam, STARTGAME); return DefWindowProc(hWnd, message, wParam, lParam); } case StartContinue_B: /* 再描写 */ hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); NowTurn = BLACK; GameThread(lParam, STARTGAME); return DefWindowProc(hWnd, message, wParam, lParam); case StartContinue_W: hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); NowTurn = WHITE; GameThread(lParam, STARTGAME); return DefWindowProc(hWnd, message, wParam, lParam); /*case Veasy: Force_SearchWin = FALSE; Force_SearchSD = FALSE; OnVeasy(hWnd); break; case easy: Force_SearchWin = FALSE; Force_SearchSD = FALSE; Oneasy(hWnd); break; case normal: Force_SearchWin = FALSE; Force_SearchSD = FALSE; Onnormal(hWnd); break; case hard: Force_SearchWin = FALSE; Force_SearchSD = FALSE; Onhard(hWnd); break; case Vhard: Force_SearchWin = FALSE; Force_SearchSD = FALSE; OnVhard(hWnd); break; case Uhard: Force_SearchWin = FALSE; Force_SearchSD = FALSE; OnUhard(hWnd); break; case AllWinLoss: Force_SearchWin = TRUE; OnAllSearchWin(hWnd); break; case AllStoneDiff: Force_SearchSD = TRUE; Force_SearchWin = FALSE; OnAllSearchSD(hWnd); break;*/ case book_switch: if(!UseBook) { UseBook = TRUE; m_FlagBook = TRUE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, book_switch, MFS_CHECKED); } else { UseBook = FALSE; m_FlagBook = FALSE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, book_switch, MFS_UNCHECKED); } break; case book_best: if(!b_Flag_not_change) { HMENU hMenu = GetMenu(hWnd); UncheckedAll_BookMenu(hMenu); b_Flag_not_change = TRUE; CheckMenuItem(hMenu, book_best, MFS_CHECKED); } break; case book_little_change: if(!b_Flag_little_change) { HMENU hMenu = GetMenu(hWnd); UncheckedAll_BookMenu(hMenu); b_Flag_little_change = TRUE; CheckMenuItem(hMenu, book_little_change, MFS_CHECKED); } break; case book_change: if(!b_Flag_change) { HMENU hMenu = GetMenu(hWnd); UncheckedAll_BookMenu(hMenu); b_Flag_change = TRUE; CheckMenuItem(hMenu, book_change, MFS_CHECKED); } break; case book_random: { HMENU hMenu = GetMenu(hWnd); UncheckedAll_BookMenu(hMenu); CheckMenuItem(hMenu, book_random, MFS_CHECKED); } break; /*case CorrectSt: PrintCorrectSt(hWnd); return DefWindowProc(hWnd, message, wParam, lParam);*/ case rotate90: m_FlagInGame = FALSE; black = rotate_90(black); white = rotate_90(white); { BitBoard move = one << (move_x * 8 + move_y); move = rotate_90(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case rotate180: m_FlagInGame = FALSE; black = rotate_180(black); white = rotate_180(white); { BitBoard move = one << (move_x * 8 + move_y); move = rotate_180(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case rotate270: m_FlagInGame = FALSE; black = rotate_270(black); white = rotate_270(white); { BitBoard move = one << (move_x * 8 + move_y); move = rotate_270(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case symX: m_FlagInGame = FALSE; black = symmetry_x(black); white = symmetry_x(white); { BitBoard move = one << (move_x * 8 + move_y); move = symmetry_x(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case symY: m_FlagInGame = FALSE; black = symmetry_y(black); white = symmetry_y(white); { BitBoard move = one << (move_x * 8 + move_y); move = symmetry_y(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case symBL: m_FlagInGame = FALSE; black = symmetry_b(black); white = symmetry_b(white); { BitBoard move = one << (move_x * 8 + move_y); move = symmetry_b(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case symWL: m_FlagInGame = FALSE; black = symmetry_w(black); white = symmetry_w(white); { BitBoard move = one << (move_x * 8 + move_y); move = symmetry_w(move); int pos = CountBit((move & (-(signed long long int)move)) - 1); move_x = pos / 8; move_y = pos % 8; } break; case BoardInit: InitBoard(); { /* メニューバーの各項目の有効無効化 */ HMENU hMenu = GetMenu(hWnd); EnableMenuItem(hMenu, interrupt, MFS_GRAYED); EnableMenuItem(hMenu, EditBoard, MFS_ENABLED); EnableMenuItem(hMenu, ChangeColor, MFS_ENABLED); } break; case EditBoard: Flag_Edit = TRUE; break; case INTERRUPT_BT: case interrupt: if(AI_THINKING /*|| m_FlagHint */) { Flag_Abort = TRUE; } else { Interrupt_flag = TRUE; m_FlagInterrupt = TRUE; m_FlagInGame = FALSE; } { HMENU hMenu = GetMenu(hWnd); EnableMenuItem(hMenu, interrupt, MFS_GRAYED); hMenu = GetMenu(hWnd); EnableMenuItem(hMenu, EditBoard, MFS_ENABLED); EnableMenuItem(hMenu, ChangeColor, MFS_ENABLED); } break; case CHANGE_BT: case ChangeColor: CpuColor ^= 1; break; case print_result: if(!AI_result) { AI_result = TRUE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_result, MFS_CHECKED); } else { AI_result = FALSE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_result, MFS_UNCHECKED); } break; case print_AI_moves: /*if(!AI_thinking) { AI_thinking = TRUE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_AI_moves, MFS_CHECKED); } else { AI_thinking = FALSE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_AI_moves, MFS_UNCHECKED); }*/ break; case print_thinking: /* if(!OnTheWay) { OnTheWay = TRUE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_thinking, MFS_CHECKED); } else { OnTheWay = FALSE; HMENU hMenu = GetMenu(hWnd); CheckMenuItem(hMenu, print_thinking, MFS_UNCHECKED); }*/ break; case Auto_Learn: //InitBoard(); //{ // int i = 0; // while(i < 1) // { // Learn_Thread(); // //Start_Auto_Learn(4, 13, 100000, -1); // i++; // } //} break; case 32849: /*{ Learn_Thread(); }*/ break; case auto_g: m_FlagInterrupt = FALSE; Interrupt_flag = FALSE; auto_game_thread(); break; case UNDO_BT: case Undo: if(turn == 0 || (UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0)) { break; } m_FlagInGame = FALSE; if(AI_THINKING /* || m_FlagHint */) { Flag_Abort = TRUE; } /* ヒント用の評価データ破棄 */ /*{ for(int i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;} }*/ black = UndoBoard_B[turn - 1]; white = UndoBoard_W[turn - 1]; move_x = Undo_x[turn - 1]; move_y = Undo_y[turn - 1]; NowTurn = Undo_color[turn - 1]; turn--; SendMessage(hListBox, LB_SETCURSEL, turn - 1, 0); if(turn - 1 < 0 || (UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0)) { EnableMenuItem(GetMenu(hWnd), Undo, MFS_GRAYED); EnableWindow(GetDlgItem(hRebar, UNDO_BT), FALSE); } if(!(UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0) || turn + 1 <= 60) { EnableMenuItem(GetMenu(hWnd), Redo, MFS_ENABLED); EnableWindow(GetDlgItem(hRebar, REDO_BT), TRUE); } break; case REDO_BT: case Redo: if(turn == 60 || UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0) { break; } m_FlagInGame = FALSE; /* ヒント用の評価データ破棄 */ /*{ for(int i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;} }*/ SendMessage(hListBox, LB_SETCURSEL, turn, 0); black = UndoBoard_B[turn + 1]; white = UndoBoard_W[turn + 1]; move_x = Undo_x[turn + 1]; move_y = Undo_y[turn + 1]; NowTurn = Undo_color[turn + 1]; turn++; if((UndoBoard_B[turn + 1] == 0 && UndoBoard_W[turn + 1] == 0) || turn + 1 > 60) { EnableMenuItem(GetMenu(hWnd), Redo, MFS_GRAYED); EnableWindow(GetDlgItem(hRebar, REDO_BT), FALSE); } if(turn - 1 >= 0 || !(UndoBoard_B[turn - 1] == 0 && UndoBoard_W[turn - 1] == 0)) { EnableMenuItem(GetMenu(hWnd), Undo, MFS_ENABLED); EnableWindow(GetDlgItem(hRebar, UNDO_BT), TRUE); } break; case FIRST_BT: { int i; for(i = 0; i < 60; i++) { if(UndoBoard_B[i] != 0 || UndoBoard_W[i] != 0) { black = UndoBoard_B[i]; white = UndoBoard_W[i]; move_x = Undo_x[i]; move_y = Undo_y[i]; NowTurn = Undo_color[i]; turn = i; /* ヒント用の評価データ破棄 */ //for(i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;} m_FlagInGame = FALSE; break; } } } break; case FINAL_BT: { int i; for(i = 60; i >= 0; i--) { if(UndoBoard_B[i] != 0 || UndoBoard_W[i] != 0) { black = UndoBoard_B[i]; white = UndoBoard_W[i]; move_x = Undo_x[i]; move_y = Undo_y[i]; NowTurn = Undo_color[i]; turn = i; /* ヒント用の評価データ破棄 */ //for(i = 0; i < 32; i++){ EvalData[i] = NEGAMAX;} m_FlagInGame = FALSE; break; } } } break; case Hint_0: OnHint_0(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_1: OnHint_1(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_2: OnHint_2(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_3: OnHint_3(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_4: OnHint_4(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_5: OnHint_5(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case Hint_6: OnHint_6(hWnd); HINT_DISPED = FALSE; GameThread(0, HINTONLY); break; case print_eval: //read_eval_table(CountBit(black | white) - 4); if(turn == 0){ break; } //read_eval_table(turn - 1); if(NowTurn == BLACK){ init_index_board(black, white); GetEvalFromPattern(black, white, NowTurn, turn - 1); } else{ init_index_board(white, black); GetEvalFromPattern(white, black, NowTurn, turn - 1); } { char eval_msg[PATTERN_NUM + 1][64]; sprintf_s(eval_msg[0], "hori_ver1_1 = %f, ", key_hori_ver1[0]); sprintf_s(eval_msg[1], "hori_ver1_2 = %f\n", key_hori_ver1[1]); sprintf_s(eval_msg[2], "hori_ver1_3 = %f,", key_hori_ver1[2]); sprintf_s(eval_msg[3], "hori_ver1_4 = %f\n", key_hori_ver1[3]); sprintf_s(eval_msg[4], "hori_ver2_1 = %f,", key_hori_ver2[0]); sprintf_s(eval_msg[5], "hori_ver2_2 = %f\n", key_hori_ver2[1]); sprintf_s(eval_msg[6], "hori_ver2_3 = %f,", key_hori_ver2[2]); sprintf_s(eval_msg[7], "hori_ver2_4 = %f\n", key_hori_ver2[3]); sprintf_s(eval_msg[8], "hori_ver3_1 = %f,", key_hori_ver3[0]); sprintf_s(eval_msg[9], "hori_ver3_2 = %f\n", key_hori_ver3[1]); sprintf_s(eval_msg[10], "hori_ver3_3 = %f,", key_hori_ver3[2]); sprintf_s(eval_msg[11], "hori_ver3_4 = %f\n", key_hori_ver3[3]); sprintf_s(eval_msg[12], "dia_ver1_1 = %f,", key_dia_ver1[0]); sprintf_s(eval_msg[13], "dia_ver1_2 = %f\n", key_dia_ver1[1]); sprintf_s(eval_msg[14], "dia_ver2_1 = %f,", key_dia_ver2[0]); sprintf_s(eval_msg[15], "dia_ver2_2 = %f\n", key_dia_ver2[1]); sprintf_s(eval_msg[16], "dia_ver2_3 = %f,", key_dia_ver2[2]); sprintf_s(eval_msg[17], "dia_ver2_4 = %f\n", key_dia_ver2[3]); sprintf_s(eval_msg[18], "dia_ver3_1 = %f,", key_dia_ver3[0]); sprintf_s(eval_msg[19], "dia_ver3_2 = %f\n", key_dia_ver3[1]); sprintf_s(eval_msg[20], "dia_ver3_3 = %f,", key_dia_ver3[2]); sprintf_s(eval_msg[21], "dia_ver3_4 = %f\n", key_dia_ver3[3]); sprintf_s(eval_msg[22], "dia_ver4_1 = %f,", key_dia_ver4[0]); sprintf_s(eval_msg[23], "dia_ver4_2 = %f\n", key_dia_ver4[1]); sprintf_s(eval_msg[24], "dia_ver4_3 = %f,", key_dia_ver4[2]); sprintf_s(eval_msg[25], "dia_ver4_4 = %f\n", key_dia_ver4[3]); sprintf_s(eval_msg[26], "edge_1 = %f,", key_edge[0]); sprintf_s(eval_msg[27], "edge_2 = %f\n", key_edge[1]); sprintf_s(eval_msg[28], "edge_3 = %f,", key_edge[2]); sprintf_s(eval_msg[29], "edge_4 = %f\n", key_edge[3]); sprintf_s(eval_msg[26], "edge_cor_1 = %f,", key_edge_cor[0]); sprintf_s(eval_msg[27], "edge_cor_2 = %f\n", key_edge_cor[1]); sprintf_s(eval_msg[28], "edge_cor_3 = %f,", key_edge_cor[2]); sprintf_s(eval_msg[29], "edge_cor_4 = %f\n", key_edge_cor[3]); sprintf_s(eval_msg[34], "corner4_2_1 = %f,", key_corner4_2[0]); sprintf_s(eval_msg[35], "corner4_2_2 = %f\n", key_corner4_2[1]); sprintf_s(eval_msg[36], "corner4_2_3 = %f,", key_corner4_2[2]); sprintf_s(eval_msg[37], "corner4_2_4 = %f\n", key_corner4_2[3]); sprintf_s(eval_msg[38], "corner3_3_1 = %f,", key_corner3_3[0]); sprintf_s(eval_msg[39], "corner3_3_2 = %f\n", key_corner3_3[1]); sprintf_s(eval_msg[40], "corner3_3_3 = %f,", key_corner3_3[2]); sprintf_s(eval_msg[41], "corner3_3_4 = %f\n", key_corner3_3[3]); /*sprintf_s(eval_msg[38], "triangle_1 = %f,", key_triangle[0]); sprintf_s(eval_msg[39], "triangle_2 = %f\n", key_triangle[1]); sprintf_s(eval_msg[40], "triangle_3 = %f,", key_triangle[2]); sprintf_s(eval_msg[41], "triangle_4 = %f\n", key_triangle[3]); sprintf_s(eval_msg[42], "mobility = %f\n", key_mobility); sprintf_s(eval_msg[43], "potential_mobility = %f\n", key_pot_mobility); sprintf_s(eval_msg[44], "paility = %f\n", key_pality);*/ sprintf_s(eval_msg[42], "mobility = %f\n", key_mobility); sprintf_s(eval_msg[43], "constant = %f\n", key_constant); sprintf_s(eval_msg[44], "\n評価値 = %f,", eval_sum); sprintf_s(eval_msg[45], "\nblack = 0x%llx\nwhite = 0x%llx\n", black, white); int i; char print_msg[8192]; strcpy_s(print_msg, eval_msg[0]); for(i = 1; i < 46; i++) { strcat_s(print_msg, eval_msg[i]); } MessageBox(hWnd, print_msg, "評価値詳細一覧", MB_OK); //memset(msg, 0, sizeof(print_msg)); } break; /* FFOメニュ− */ case FFO40: black = 9158069842325798912; white = 11047339776155165; configCPU(BLACK); break; case FFO41: black = 616174399789064; white = 39493460025648416; configCPU(BLACK); break; case FFO42: white = 9091853944868375556; black = 22586176447709200; configCPU(BLACK); break; case FFO43: black = 38808086923902976; white = 13546258740034592; configCPU(WHITE); break; case FFO44: black = 2494790880993312; white = 1010251075753548824; configCPU(WHITE); break; case FFO45: black = 282828816915486; white = 9287318235258944; configCPU(BLACK); break; case FFO46: black = 4052165999611379712; white = 36117299622447104; configCPU(BLACK); break; case FFO47: black = 277938752194568; white = 3536224466208; configCPU(WHITE); break; case FFO48: black = 38519958422848574; white = 4725679339520; configCPU(WHITE); break; case FFO49: black = 5765976742297600; white = 4253833575484; configCPU(BLACK); break; case FFO50: black = 4504145659822080; white = 4336117619740130304; configCPU(BLACK); break; case FFO51: black = 349834415978528; white = 8664011788383158280; configCPU(WHITE); break; case FFO52: black = 9096176176681728056; white = 35409824317440; configCPU(WHITE); break; case FFO53: black = 2515768979493888; white = 8949795312300457984; configCPU(BLACK); break; case FFO54: black = 277938752194568; white = 3536224466208; configCPU(BLACK); break; case FFO55: black = 4635799596172290; white = 289361502099486840; configCPU(BLACK); break; case FFO56: black = 4925086697193472; white = 9007372734053408; configCPU(WHITE); break; case FFO57: black = 9060166336512000; white = 8943248156475301888; configCPU(BLACK); break; case FFO58: black = 4636039783186432; white = 3383245044333600; configCPU(BLACK); break; case FFO59: black = 17320879491911778304; white = 295223649004691488; configCPU(BLACK); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } InvalidateRect(hWnd, NULL, FALSE); /* 再描写 */ hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, -1, -1); ReleaseDC(hWnd, hdc); UpdateWindow(hRebar); SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 描画コードをここに追加してください... hdc = GetDC(hWnd); DrawBoard( hdc, hStatus, move_x, move_y); ReleaseDC(hWnd, hdc); SendMessage(hStatus, SB_SETTEXT, (WPARAM)1 | 0, (LPARAM)turn_str[NowTurn]); //char str[64]; //sprintf_s(str, "black = %llu", black); //SendMessage(hStatus, SB_SETTEXT, (WPARAM)3 | 0, (LPARAM)str); EndPaint(hWnd, &ps); break; case WM_DESTROY: /* 置換表の解放 */ //HashDelete(hashTable); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void cSystemViaccess::ProcessEMM(int pid, int caid, const unsigned char *data) { for(cViaccessCardInfo *mkey=Vcards.First(); mkey; mkey=Vcards.Next(mkey)) { int updtype; cAssembleData ad(data); if(mkey->cCardViaccess::MatchEMM(data)) { updtype=3; HashClear(); memcpy(hbuff+3,mkey->ua,sizeof(mkey->ua)); } else if(mkey->cProviderViaccess::MatchEMM(data)) { if(mkey->cProviderViaccess::Assemble(&ad)<0) continue; updtype=2; HashClear(); memcpy(hbuff+5,mkey->sa,sizeof(mkey->sa)-1); } else continue; const unsigned char *buff; if((buff=ad.Assembled())) { const unsigned char *scan=cParseViaccess::NanoStart(buff); unsigned int scanlen=SCT_LEN(buff)-(scan-buff); if(scanlen>=5 && mkey->cProviderViaccess::MatchID(buff) && cParseViaccess::KeyNrFromNano(scan)==mkey->keyno) { scan+=5; scanlen-=5; SetHashKey(mkey->key); Hash(); unsigned int n; if(scan[0]==0x9e && scanlen>=(n=scan[1]+2)) { for(unsigned int i=0; i<n; i++) HashByte(scan[i]); Hash(); pH=0; scan+=n; scanlen-=5; } if(scanlen>0) { unsigned char newKey[MAX_NEW_KEYS][8]; int numKeys=0, updPrv[MAX_NEW_KEYS]={}, updKey[MAX_NEW_KEYS]={}; for(unsigned int cnt=0; cnt<scanlen && numKeys<MAX_NEW_KEYS;) { const unsigned int parm=scan[cnt++]; unsigned int plen=scan[cnt++]; switch(parm) { case 0x90: case 0x9E: cnt+=plen; break; case 0xA1: // keyupdate updPrv[numKeys]=(scan[cnt]<<16)+(scan[cnt+1]<<8)+(scan[cnt+2]&0xF0); updKey[numKeys]=scan[cnt+2]&0x0F; // fall through default: HashByte(parm); HashByte(plen); while(plen--) HashByte(scan[cnt++]); break; case 0xEF: // crypted key(s) HashByte(parm); HashByte(plen); if(plen==sizeof(newKey[0])) { const unsigned char k7=mkey->key[7]; for(unsigned int kc=0 ; kc<sizeof(newKey[0]) ; kc++) { const unsigned char b=scan[cnt++]; if(k7&1) newKey[numKeys][kc]=b^(hbuff[pH]&(k7<0x10 ? 0x5a : 0xa5)); else newKey[numKeys][kc]=b; HashByte(b); } numKeys++; } else { PRINTF(L_SYS_EMM,"key length mismatch %d!=%d",plen,(int)sizeof(newKey[0])); cnt=scanlen; } break; case 0xF0: // signature { char str[20], str2[20]; static const char *ptext[] = { 0,0,"SHARED","UNIQUE" }; const char *addr = (updtype==2) ? HexStr(str,mkey->sa,sizeof(mkey->sa)) : HexStr(str,mkey->ua,sizeof(mkey->ua)); Hash(); if(!memcmp(&scan[cnt],hbuff,sizeof(hbuff))) { unsigned char key[8]; memcpy(key,mkey->key,sizeof(key)); if(key[7]) { // Rotate key const unsigned char t1=key[0], t2=key[1]; key[0]=key[2]; key[1]=key[3]; key[2]=key[4]; key[3]=key[5]; key[4]=key[6]; key[5]=t1; key[6]=t2; } while(numKeys--) { Decode(newKey[numKeys],key); PRINTF(L_SYS_EMM,"%02X%02X %02X %s %s - KEY %06X.%02X -> %s", mkey->ident[0],mkey->ident[1],mkey->keyno,addr, ptext[updtype],updPrv[numKeys],updKey[numKeys], HexStr(str2,newKey[numKeys],sizeof(newKey[numKeys]))); FoundKey(); if(keys.NewKey('V',updPrv[numKeys],updKey[numKeys],newKey[numKeys],8)) NewKey(); } } else PRINTF(L_SYS_EMM,"%02X%02X %02X %s %s - FAIL",mkey->ident[0],mkey->ident[1],mkey->keyno,addr,ptext[updtype]); cnt=scanlen; break; } } } } } } } }
bool cViaccess::Decrypt(const unsigned char *work_key, const unsigned char *data, int len, unsigned char *des_data1, unsigned char *des_data2) { int pos=0, encStart=0; unsigned char signatur[8]; while(pos<len) { switch(data[pos]) { case 0xea: // encrypted bytes encStart = pos + 2; memcpy(des_data1,&data[pos+2],8); memcpy(des_data2,&data[pos+2+8],8); break; case 0xf0: // signature memcpy(signatur,&data[pos+2],8); break; } pos += data[pos+1]+2; } HashClear(); SetHashKey(work_key); // key preparation unsigned char prepared_key[8]; if(work_key[7]==0) { // 8th key-byte = 0 then like Eurocrypt-M but with viaccess mods HashNanos(data,encStart+16); memcpy(prepared_key,work_key,sizeof(prepared_key)); } else { // key8 not zero // rotate the key 2x left prepared_key[0]=work_key[2]; prepared_key[1]=work_key[3]; prepared_key[2]=work_key[4]; prepared_key[3]=work_key[5]; prepared_key[4]=work_key[6]; prepared_key[5]=work_key[0]; prepared_key[6]=work_key[1]; prepared_key[7]=work_key[7]; // test if key8 odd if(work_key[7]&1) { HashNanos(data,encStart); // test if low nibble zero unsigned char k = ((work_key[7] & 0xf0) == 0) ? 0x5a : 0xa5; for(int i=0; i<8; i++) { unsigned char tmp=des_data1[i]; des_data1[i]=(k & hbuff[pH]) ^ tmp; HashByte(tmp); } for(int i=0; i<8; i++) { unsigned char tmp=des_data2[i]; des_data2[i]=(k & hbuff[pH]) ^ tmp; HashByte(tmp); } } else { HashNanos(data,encStart+16); } } Decode(des_data1,prepared_key); Decode(des_data2,prepared_key); Hash(); return (memcmp(signatur,hbuff,8)==0); }
static void DeleteAllVariables(char *scope) { struct Scope *ptr; ptr = GetScope(scope); HashClear(ptr->hashtable); }