├── PatternManager.sln ├── PatternManager ├── PatternManager.vcxproj ├── PatternManager.vcxproj.filters ├── icon.ico ├── main.cpp ├── manifest.xml ├── resource.h ├── resource.rc ├── scanner.cpp └── scanner.h └── README.md /PatternManager.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PatternManager", "PatternManager\PatternManager.vcxproj", "{B9CCA944-DBCA-4A3C-87B7-1DC34085E55C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {B9CCA944-DBCA-4A3C-87B7-1DC34085E55C}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {B9CCA944-DBCA-4A3C-87B7-1DC34085E55C}.Debug|Win32.Build.0 = Debug|Win32 14 | {B9CCA944-DBCA-4A3C-87B7-1DC34085E55C}.Release|Win32.ActiveCfg = Release|Win32 15 | {B9CCA944-DBCA-4A3C-87B7-1DC34085E55C}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /PatternManager/PatternManager.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {B9CCA944-DBCA-4A3C-87B7-1DC34085E55C} 15 | Win32Proj 16 | PatternManager 17 | 18 | 19 | 20 | Application 21 | true 22 | Unicode 23 | 24 | 25 | Application 26 | false 27 | true 28 | Unicode 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | true 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | Level3 51 | Disabled 52 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 53 | 54 | 55 | Windows 56 | true 57 | 58 | 59 | 60 | 61 | Level3 62 | 63 | 64 | MaxSpeed 65 | true 66 | true 67 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 68 | MultiThreaded 69 | 70 | 71 | Windows 72 | false 73 | true 74 | true 75 | type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df';%(AdditionalManifestDependencies) 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /PatternManager/PatternManager.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Quelldateien 20 | 21 | 22 | Quelldateien 23 | 24 | 25 | 26 | 27 | Headerdateien 28 | 29 | 30 | Headerdateien 31 | 32 | 33 | 34 | 35 | Ressourcendateien 36 | 37 | 38 | -------------------------------------------------------------------------------- /PatternManager/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NtQuery/PatternManager/949e3635becc01ab6610f8efb68eb044dcd9b881/PatternManager/icon.ico -------------------------------------------------------------------------------- /PatternManager/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "resource.h" 6 | #include "scanner.h" 7 | 8 | #pragma comment(lib,"Comctl32.lib") 9 | 10 | //#define _WIN32_IE 0x0500 11 | //#define _WIN32_WINDOWS 0x0410 12 | #define DEFAULT_RECT_WIDTH 150 13 | #define DEFAULT_RECT_HEIGHT 30 14 | #define IDH_RESTOREHIDE 400 15 | #define IDI_TRAYICON 300 16 | #define TRAY_EXIT 301 17 | #define TRAY_RESTORE 302 18 | #define MSG_MINTRAYICON (WM_USER+0) 19 | 20 | 21 | #ifdef UNICODE 22 | #define TEXT_TITLE "Pattern Manager MOD" 23 | #else 24 | #define TEXT_TITLE "Pattern Manager" 25 | #endif 26 | 27 | void FormatTextHex(TCHAR* text, bool byte_space); 28 | 29 | HINSTANCE hInst = 0; 30 | HWND hwndMain = 0; 31 | NOTIFYICONDATA nid = {0}; 32 | 33 | bool category_edit=false; 34 | bool stuff_changed=false; 35 | bool new_category=false; 36 | bool del_category=false; 37 | bool no_categories=true; 38 | bool startMinimized=false; 39 | bool IsMinimized=false; 40 | bool update_nibbles=false; 41 | 42 | int number_pattern_selected=0; 43 | int main_category_selected=0; 44 | int edit_category_selected=0; 45 | int main_pattern_selected=0; 46 | 47 | TCHAR curdir[MAX_PATH]={0}; 48 | TCHAR datafile[MAX_PATH]={0}; 49 | TCHAR ini_file[MAX_PATH]={0}; 50 | 51 | TCHAR scannerLog[MAX_PATH]={0}; 52 | 53 | TCHAR add_data_text[PATTERN_MAX_SIZE]={0}; 54 | TCHAR add_name_text[255]={0}; 55 | TCHAR category_selected[255]={0}; 56 | TCHAR name_pattern_selected[255]={0}; 57 | 58 | TCHAR pattern_data[PATTERN_MAX_SIZE]={0}; 59 | TCHAR keyname[KEYNAME_MAX_SIZE]={0}; 60 | 61 | void ComparePatterns(TCHAR* old_pattern, TCHAR* new_pattern, TCHAR* updated_buffer, bool nibbles) 62 | { 63 | //Initialize variables and get the pattern lengths 64 | updated_buffer[0]=0; 65 | int old_pattern_len=0, new_pattern_len=0, smallest_len=0; 66 | bool spaced_pattern=false,different_length=true; 67 | 68 | //Determine if a spaced pattern is used. 69 | if(old_pattern[2]==TEXT(' ')) 70 | spaced_pattern=true; 71 | 72 | //Prepare the patterns for comparing. 73 | FormatTextHex(old_pattern, false); 74 | FormatTextHex(new_pattern, false); 75 | 76 | //Get patterns lengths and determine which one is the shortest. 77 | old_pattern_len=_tcslen(old_pattern); 78 | new_pattern_len=_tcslen(new_pattern); 79 | if(old_pattern_len>new_pattern_len) 80 | smallest_len=new_pattern_len; 81 | else if(old_pattern_lentop=appBarData.rc.bottom-100; 197 | lpTrayRect->bottom=appBarData.rc.bottom-16; 198 | lpTrayRect->left=appBarData.rc.left; 199 | lpTrayRect->right=appBarData.rc.right; 200 | break; 201 | 202 | case ABE_TOP: 203 | case ABE_BOTTOM: 204 | lpTrayRect->top=appBarData.rc.top; 205 | lpTrayRect->bottom=appBarData.rc.bottom; 206 | lpTrayRect->left=appBarData.rc.right-100; 207 | lpTrayRect->right=appBarData.rc.right-16; 208 | break; 209 | } 210 | 211 | return; 212 | } 213 | hShellTrayWnd=FindWindowEx(NULL,NULL,TEXT("Shell_TrayWnd"),NULL); 214 | if(hShellTrayWnd) 215 | { 216 | GetWindowRect(hShellTrayWnd,lpTrayRect); 217 | if(lpTrayRect->right-lpTrayRect->left>DEFAULT_RECT_WIDTH) 218 | lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH; 219 | if(lpTrayRect->bottom-lpTrayRect->top>DEFAULT_RECT_HEIGHT) 220 | lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT; 221 | 222 | return; 223 | } 224 | SystemParametersInfo(SPI_GETWORKAREA,0,lpTrayRect,0); 225 | lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH; 226 | lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT; 227 | } 228 | 229 | void MinimizeToTray(HWND hwnd) 230 | { 231 | WritePrivateProfileString(TEXT("Settings"), TEXT("startMinimized"), TEXT("1"), ini_file); 232 | RECT rcFrom,rcTo; 233 | GetWindowRect(hwnd,&rcFrom); 234 | GetTrayWndRect(&rcTo); 235 | DrawAnimatedRects(hwnd,IDANI_CAPTION,&rcFrom,&rcTo); 236 | startMinimized=true; 237 | ShowWindow(hwnd, SW_HIDE); 238 | IsMinimized=true; 239 | } 240 | 241 | void MinimizeToTray_thread(HWND hwnd) 242 | { 243 | WritePrivateProfileString(TEXT("Settings"), TEXT("startMinimized"), TEXT("1"), ini_file); 244 | startMinimized=true; 245 | ShowWindow(hwnd, SW_HIDE); 246 | IsMinimized=true; 247 | } 248 | 249 | void RestoreFromTray(HWND hwnd) 250 | { 251 | WritePrivateProfileString(TEXT("Settings"), TEXT("startMinimized"), TEXT("0"), ini_file); 252 | startMinimized=false; 253 | ShowWindow(hwnd, SW_SHOW); 254 | ShowWindow(hwnd, SW_RESTORE); 255 | SetForegroundWindow(hwnd); 256 | IsMinimized=false; 257 | } 258 | 259 | DWORD WINAPI MinimizeThread(LPVOID lparam) 260 | { 261 | int counter=0; 262 | while(counter<40) 263 | { 264 | MinimizeToTray_thread(hwndMain); 265 | Sleep(25); 266 | counter++; 267 | } 268 | return 0; 269 | } 270 | 271 | BOOL FileExists(LPCTSTR szPath) 272 | { 273 | DWORD dwAttrib = GetFileAttributes(szPath); 274 | 275 | return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); 276 | } 277 | 278 | void CreateDummyUnicodeFile(const TCHAR * file) 279 | { 280 | //http://www.codeproject.com/Articles/9071/Using-Unicode-in-INI-files 281 | 282 | if (!FileExists(file)) 283 | { 284 | // UTF16-LE BOM(FFFE) 285 | WORD wBOM = 0xFEFF; 286 | DWORD NumberOfBytesWritten; 287 | 288 | HANDLE hFile = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); 289 | WriteFile(hFile, &wBOM, sizeof(WORD), &NumberOfBytesWritten, NULL); 290 | //WriteFile(hFile, pszSectionB, (_tcslen(pszSectionB)+1)*(sizeof(TCHAR)), &NumberOfBytesWritten, NULL); 291 | CloseHandle(hFile); 292 | } 293 | } 294 | 295 | bool AddCategory(const TCHAR* name) 296 | { 297 | _tcscpy_s(category_selected,_countof(category_selected), name); 298 | 299 | #ifdef UNICODE 300 | CreateDummyUnicodeFile(datafile); 301 | #endif 302 | 303 | if(!WritePrivateProfileString(name, TEXT("Patterns"), TEXT("0"), datafile)) 304 | return false; 305 | stuff_changed=true; 306 | new_category=true; 307 | return true; 308 | } 309 | 310 | bool RemoveCategory(const TCHAR* name) 311 | { 312 | if(!WritePrivateProfileSection(name, 0, datafile)) 313 | return false; 314 | stuff_changed=true; 315 | return true; 316 | } 317 | 318 | bool EditCategory(const TCHAR* name, const TCHAR* newname) 319 | { 320 | TCHAR category_data[65535]={0}; 321 | if(!GetPrivateProfileSection(name, category_data, _countof(category_data), datafile)) 322 | return false; 323 | if(!RemoveCategory(name)) 324 | return false; 325 | if(!WritePrivateProfileSection(newname, category_data, datafile)) 326 | return false; 327 | return true; 328 | } 329 | 330 | bool FixPatterns(const TCHAR* category) 331 | { 332 | TCHAR newname[10]={0}, category_section[65535]={0}; 333 | int len = GetPrivateProfileSection(category, category_section, _countof(category_section), datafile); 334 | int total_patterns = 0; 335 | if(!len) 336 | return false; 337 | TCHAR* keynamedata=category_section; 338 | for(int i=0,j=1,k=0,l=0; i30) 686 | add_name_text[30]=0; 687 | if(add_data_text[2]==TEXT(' ')) 688 | FormatTextHex(add_data_text, true); 689 | else 690 | FormatTextHex(add_data_text, false); 691 | if(AddPattern(category_selected, add_name_text, add_data_text)) 692 | { 693 | MessageBox(hwndDlg, TEXT("Pattern added!"), TEXT("Success"), MB_ICONINFORMATION); 694 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 695 | } 696 | else 697 | { 698 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 699 | } 700 | } 701 | } 702 | return TRUE; 703 | 704 | case IDC_EDT_NAME: 705 | { 706 | if(GetDlgItemText(hwndDlg, IDC_EDT_NAME, add_name_text, 255) && (GetDlgItemText(hwndDlg, IDC_EDT_DATA, add_data_text, PATTERN_MAX_SIZE) || category_edit==true)) 707 | { 708 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 709 | } 710 | else 711 | { 712 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 713 | } 714 | } 715 | return TRUE; 716 | 717 | case IDC_EDT_DATA: 718 | { 719 | if(GetDlgItemText(hwndDlg, IDC_EDT_NAME, add_name_text, 255) && (GetDlgItemText(hwndDlg, IDC_EDT_DATA, add_data_text, PATTERN_MAX_SIZE) || category_edit==true)) 720 | { 721 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 722 | } 723 | else 724 | { 725 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 726 | } 727 | } 728 | return TRUE; 729 | } 730 | } 731 | return TRUE; 732 | } 733 | return FALSE; 734 | } 735 | 736 | BOOL CALLBACK DlgEdit(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 737 | { 738 | switch(uMsg) 739 | { 740 | case WM_INITDIALOG: 741 | { 742 | memset(add_name_text, 0, 255); 743 | memset(add_data_text, 0, PATTERN_MAX_SIZE); 744 | memset(category_selected, 0, 255); 745 | SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1))); 746 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), false); 747 | if(category_edit) 748 | { 749 | EnableWindow(GetDlgItem(hwndDlg, IDC_EDT_DATA), FALSE); 750 | EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), FALSE); 751 | SetWindowText(hwndDlg, TEXT("Edit Category")); 752 | } 753 | else 754 | { 755 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), false, hwndDlg, false); 756 | } 757 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 758 | } 759 | return TRUE; 760 | 761 | case WM_CLOSE: 762 | { 763 | EndDialog(hwndDlg, 0); 764 | } 765 | return TRUE; 766 | 767 | case WM_COMMAND: 768 | { 769 | switch(LOWORD(wParam)) 770 | { 771 | case IDC_COMBO_CATEGORY: 772 | { 773 | switch(HIWORD(wParam)) 774 | { 775 | case CBN_SELCHANGE: 776 | { 777 | int currentsel=SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETCURSEL, 0, 0); 778 | edit_category_selected=currentsel; 779 | SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETLBTEXT, (WPARAM)currentsel, (LPARAM)category_selected); 780 | if(!category_edit) 781 | { 782 | number_pattern_selected=0; 783 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), false, hwndDlg, true); 784 | } 785 | } 786 | return TRUE; 787 | } 788 | } 789 | return TRUE; 790 | 791 | case IDC_COMBO_PATTERN: 792 | { 793 | switch(HIWORD(wParam)) 794 | { 795 | case CBN_SELCHANGE: 796 | { 797 | //TCHAR keyname[255]={0}, pattern_data[PATTERN_MAX_SIZE]={0}; 798 | number_pattern_selected=SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETCURSEL, 0, 0); 799 | SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETLBTEXT, (WPARAM)number_pattern_selected, (LPARAM)name_pattern_selected); 800 | SetDlgItemText(hwndDlg, IDC_EDT_NAME, name_pattern_selected); 801 | 802 | _stprintf_s(keyname,KEYNAME_MAX_SIZE, TEXT("Pattern%.04dData"), number_pattern_selected+1); 803 | if(GetPrivateProfileString(category_selected, keyname, TEXT(""), pattern_data, PATTERN_MAX_SIZE, datafile)) 804 | { 805 | SetDlgItemText(hwndDlg, IDC_EDT_DATA, pattern_data); 806 | } 807 | else 808 | { 809 | SetDlgItemText(hwndDlg, IDC_EDT_DATA, TEXT("Error!")); 810 | } 811 | } 812 | return TRUE; 813 | } 814 | } 815 | return TRUE; 816 | 817 | case IDC_BTN_CANCEL: 818 | { 819 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 820 | } 821 | return TRUE; 822 | 823 | case IDC_EDT_NAME: 824 | { 825 | if(GetDlgItemText(hwndDlg, IDC_EDT_NAME, add_name_text, 255) && (GetDlgItemText(hwndDlg, IDC_EDT_DATA, add_data_text, PATTERN_MAX_SIZE) || (category_edit==true))) 826 | { 827 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 828 | } 829 | else 830 | { 831 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 832 | } 833 | } 834 | return TRUE; 835 | 836 | case IDC_EDT_DATA: 837 | { 838 | if(GetDlgItemText(hwndDlg, IDC_EDT_NAME, add_name_text, 255) && (GetDlgItemText(hwndDlg, IDC_EDT_DATA, add_data_text, PATTERN_MAX_SIZE) || (category_edit==true))) 839 | { 840 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 841 | } 842 | else 843 | { 844 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 845 | } 846 | } 847 | return TRUE; 848 | 849 | case IDC_BTN_OK: 850 | { 851 | if(category_edit) 852 | { 853 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to change this category?"), category_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 854 | { 855 | if(EditCategory(category_selected, add_name_text)) 856 | { 857 | MessageBox(hwndDlg, TEXT("Category changed!"), TEXT("Success"), MB_ICONINFORMATION); 858 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 859 | } 860 | else 861 | { 862 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 863 | } 864 | } 865 | } 866 | else 867 | { 868 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to change this pattern?"), name_pattern_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 869 | { 870 | if(_tcslen(add_name_text)>30) 871 | add_name_text[30]=0; 872 | if(add_data_text[2]==' ') 873 | FormatTextHex(add_data_text, true); 874 | else 875 | FormatTextHex(add_data_text, false); 876 | if(EditPattern(category_selected, number_pattern_selected+1, add_name_text, add_data_text)) 877 | { 878 | MessageBox(hwndDlg, TEXT("Pattern changed!"), TEXT("Success"), MB_ICONINFORMATION); 879 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 880 | } 881 | else 882 | { 883 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 884 | } 885 | } 886 | } 887 | } 888 | return TRUE; 889 | } 890 | } 891 | return TRUE; 892 | } 893 | return FALSE; 894 | } 895 | 896 | BOOL CALLBACK DlgRemove(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 897 | { 898 | switch(uMsg) 899 | { 900 | case WM_INITDIALOG: 901 | { 902 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), false); 903 | if(category_edit) 904 | { 905 | EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), FALSE); 906 | SetWindowText(hwndDlg, TEXT("Remove Category")); 907 | } 908 | else 909 | { 910 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), false, 0, false); 911 | } 912 | SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1))); 913 | } 914 | return TRUE; 915 | 916 | case WM_CLOSE: 917 | { 918 | EndDialog(hwndDlg, 0); 919 | } 920 | return TRUE; 921 | 922 | case WM_COMMAND: 923 | { 924 | switch(LOWORD(wParam)) 925 | { 926 | case IDC_COMBO_CATEGORY: 927 | { 928 | switch(HIWORD(wParam)) 929 | { 930 | case CBN_SELCHANGE: 931 | { 932 | int currentsel=SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETCURSEL, 0, 0); 933 | SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETLBTEXT, (WPARAM)currentsel, (LPARAM)category_selected); 934 | } 935 | return TRUE; 936 | } 937 | } 938 | return TRUE; 939 | 940 | case IDC_COMBO_PATTERN: 941 | { 942 | switch(HIWORD(wParam)) 943 | { 944 | case CBN_SELCHANGE: 945 | { 946 | number_pattern_selected=SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETCURSEL, 0, 0); 947 | SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETLBTEXT, (WPARAM)number_pattern_selected, (LPARAM)name_pattern_selected); 948 | } 949 | return TRUE; 950 | } 951 | } 952 | return TRUE; 953 | 954 | case IDC_BTN_OK: 955 | { 956 | if(category_edit) 957 | { 958 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to remove this category?"), category_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 959 | { 960 | if(RemoveCategory(category_selected)) 961 | { 962 | MessageBox(hwndDlg, TEXT("Category removed!"), TEXT("Success"), MB_ICONINFORMATION); 963 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 964 | } 965 | else 966 | { 967 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 968 | } 969 | } 970 | } 971 | else 972 | { 973 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to remove this pattern?"), name_pattern_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 974 | { 975 | if(RemovePattern(category_selected, number_pattern_selected+1)) 976 | { 977 | MessageBox(hwndDlg, TEXT("Pattern removed!"), TEXT("Success"), MB_ICONINFORMATION); 978 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 979 | } 980 | else 981 | { 982 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 983 | } 984 | } 985 | } 986 | } 987 | return TRUE; 988 | 989 | case IDC_BTN_CANCEL: 990 | { 991 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 992 | } 993 | return TRUE; 994 | } 995 | } 996 | return TRUE; 997 | } 998 | return FALSE; 999 | } 1000 | 1001 | BOOL CALLBACK DlgUpdate(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 1002 | { 1003 | switch(uMsg) 1004 | { 1005 | case WM_INITDIALOG: 1006 | { 1007 | SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1))); 1008 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), false); 1009 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), false, 0, false); 1010 | SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETLBTEXT, (WPARAM)number_pattern_selected, (LPARAM)add_name_text); 1011 | //TCHAR keyname[255]={0}, pattern_data[PATTERN_MAX_SIZE]={0}; 1012 | 1013 | _stprintf_s(keyname,KEYNAME_MAX_SIZE, TEXT("Pattern%.04dData"), number_pattern_selected+1); 1014 | if(GetPrivateProfileString(category_selected, keyname, TEXT(""), pattern_data, PATTERN_MAX_SIZE, datafile)) 1015 | { 1016 | SetDlgItemText(hwndDlg, IDC_EDT_DATA1, pattern_data); 1017 | } 1018 | else 1019 | { 1020 | SetDlgItemText(hwndDlg, IDC_EDT_DATA, TEXT("Error!")); 1021 | } 1022 | update_nibbles=true; 1023 | CheckDlgButton(hwndDlg, IDC_CHK_NIBBLES, update_nibbles); 1024 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), FALSE); 1025 | } 1026 | return TRUE; 1027 | 1028 | case WM_CLOSE: 1029 | { 1030 | EndDialog(hwndDlg, 0); 1031 | } 1032 | return TRUE; 1033 | 1034 | case WM_COMMAND: 1035 | { 1036 | switch(LOWORD(wParam)) 1037 | { 1038 | case IDC_COMBO_CATEGORY: 1039 | { 1040 | switch(HIWORD(wParam)) 1041 | { 1042 | case CBN_SELCHANGE: 1043 | { 1044 | //TCHAR keyname[255]={0}, pattern_data[PATTERN_MAX_SIZE]={0}; 1045 | int currentsel=SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETCURSEL, 0, 0); 1046 | edit_category_selected=currentsel; 1047 | SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETLBTEXT, (WPARAM)currentsel, (LPARAM)category_selected); 1048 | number_pattern_selected=0; 1049 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_COMBO_PATTERN), false, 0, true); 1050 | SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETLBTEXT, (WPARAM)number_pattern_selected, (LPARAM)add_name_text); 1051 | 1052 | _stprintf_s(keyname,KEYNAME_MAX_SIZE, TEXT("Pattern%.04dData"), number_pattern_selected+1); 1053 | if(GetPrivateProfileString(category_selected, keyname, TEXT(""), pattern_data, PATTERN_MAX_SIZE, datafile)) 1054 | { 1055 | SetDlgItemText(hwndDlg, IDC_EDT_DATA1, pattern_data); 1056 | } 1057 | else 1058 | { 1059 | SetDlgItemText(hwndDlg, IDC_EDT_DATA, TEXT("Error!")); 1060 | } 1061 | } 1062 | return TRUE; 1063 | } 1064 | } 1065 | return TRUE; 1066 | 1067 | case IDC_CHK_NIBBLES: 1068 | { 1069 | update_nibbles= (IsDlgButtonChecked(hwndDlg, IDC_CHK_NIBBLES) == TRUE); 1070 | SetFocus(GetDlgItem(hwndDlg, IDC_EDT_DATA2)); 1071 | } 1072 | return TRUE; 1073 | 1074 | case IDC_COMBO_PATTERN: 1075 | { 1076 | switch(HIWORD(wParam)) 1077 | { 1078 | case CBN_SELCHANGE: 1079 | { 1080 | //TCHAR keyname[255]={0}, pattern_data[PATTERN_MAX_SIZE]={0}; 1081 | number_pattern_selected=SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETCURSEL, 0, 0); 1082 | SendDlgItemMessage(hwndDlg, IDC_COMBO_PATTERN, CB_GETLBTEXT, (WPARAM)number_pattern_selected, (LPARAM)add_name_text); 1083 | _stprintf_s(keyname,KEYNAME_MAX_SIZE, TEXT("Pattern%.04dData"), number_pattern_selected+1); 1084 | if(GetPrivateProfileString(category_selected, keyname, TEXT(""), pattern_data, PATTERN_MAX_SIZE, datafile)) 1085 | { 1086 | SetDlgItemText(hwndDlg, IDC_EDT_DATA1, pattern_data); 1087 | } 1088 | else 1089 | { 1090 | SetDlgItemText(hwndDlg, IDC_EDT_DATA, TEXT("Error!")); 1091 | } 1092 | SetFocus(GetDlgItem(hwndDlg, IDC_EDT_DATA2)); 1093 | } 1094 | return TRUE; 1095 | } 1096 | } 1097 | return TRUE; 1098 | 1099 | case IDC_BTN_CANCEL: 1100 | { 1101 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 1102 | } 1103 | return TRUE; 1104 | 1105 | case IDC_BTN_OK: 1106 | { 1107 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to update this pattern?"), name_pattern_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 1108 | { 1109 | if(EditPattern(category_selected, number_pattern_selected+1, add_name_text, add_data_text)) 1110 | { 1111 | MessageBox(hwndDlg, TEXT("Pattern updated!"), TEXT("Success"), MB_ICONINFORMATION); 1112 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 1113 | } 1114 | else 1115 | { 1116 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 1117 | } 1118 | } 1119 | } 1120 | return TRUE; 1121 | 1122 | case IDC_EDT_DATA2: 1123 | { 1124 | TCHAR new_pattern_data[PATTERN_MAX_SIZE]={0},old_pattern_data[PATTERN_MAX_SIZE]={0}; 1125 | 1126 | if(GetDlgItemText(hwndDlg, IDC_EDT_DATA2, new_pattern_data, PATTERN_MAX_SIZE) && GetDlgItemText(hwndDlg, IDC_EDT_DATA1, old_pattern_data, PATTERN_MAX_SIZE)) 1127 | { 1128 | ComparePatterns(old_pattern_data, new_pattern_data, add_data_text, update_nibbles); 1129 | SetDlgItemText(hwndDlg, IDC_EDT_DATA3, add_data_text); 1130 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 1131 | } 1132 | else 1133 | { 1134 | EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_OK), TRUE); 1135 | SetDlgItemText(hwndDlg, IDC_EDT_DATA3, TEXT("")); 1136 | } 1137 | } 1138 | return TRUE; 1139 | } 1140 | } 1141 | return TRUE; 1142 | } 1143 | return FALSE; 1144 | } 1145 | 1146 | BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 1147 | { 1148 | switch(uMsg) 1149 | { 1150 | case WM_INITDIALOG: 1151 | { 1152 | SetWindowText(hwndDlg,TEXT(TEXT_TITLE)); 1153 | 1154 | TCHAR startmin[10]={0},hotkey[10]={0}; 1155 | hwndMain=hwndDlg; 1156 | 1157 | GetCurrentDirectory(_countof(curdir), curdir); 1158 | _stprintf_s(datafile,_countof(datafile), TEXT("%s\\patterns.ini"), curdir); 1159 | _stprintf_s(ini_file,_countof(ini_file), TEXT("%s\\settings.ini"), curdir); 1160 | _stprintf_s(scannerLog,_countof(scannerLog), TEXT("%s\\scanner.log"), curdir); 1161 | 1162 | HICON hIcon=LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); 1163 | SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); 1164 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), true); 1165 | FixPatterns(category_selected); 1166 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1167 | if(!GetPrivateProfileString(TEXT("Settings"), TEXT("startMinimized"), TEXT(""), startmin, 10, ini_file)) 1168 | { 1169 | WritePrivateProfileString(TEXT("Settings"), TEXT("startMinimized"), TEXT("0"), ini_file); 1170 | _tcscpy_s(startmin,_countof(startmin), TEXT("0")); 1171 | } 1172 | if(!GetPrivateProfileString(TEXT("Settings"), TEXT("HotKey"), TEXT(""), hotkey, 10, ini_file)) 1173 | { 1174 | WritePrivateProfileString(TEXT("Settings"), TEXT("HotKey"), TEXT("U"), ini_file); 1175 | _tcscpy_s(hotkey,_countof(hotkey), TEXT("U")); 1176 | } 1177 | 1178 | if(_tcscmp(startmin, TEXT("1"))==0) 1179 | startMinimized=true; 1180 | 1181 | if(startMinimized) 1182 | CreateThread(0, 0, MinimizeThread, 0, 0, 0); 1183 | 1184 | memset(&nid, 0, sizeof(nid)); 1185 | nid.cbSize=sizeof(NOTIFYICONDATA); 1186 | nid.hWnd=hwndDlg; 1187 | nid.uID=IDI_TRAYICON; 1188 | nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP; 1189 | nid.hIcon=hIcon; 1190 | nid.uCallbackMessage=MSG_MINTRAYICON; 1191 | _tcscpy_s(nid.szTip, TEXT(TEXT_TITLE)); 1192 | Shell_NotifyIcon(NIM_ADD, &nid); 1193 | if(!RegisterHotKey(hwndDlg, IDH_RESTOREHIDE, MOD_ALT|MOD_CONTROL|MOD_WIN, VkKeyScan(_totlower(hotkey[0])))) 1194 | { 1195 | SetWindowText(hwndDlg, TEXT("")); 1196 | HWND oldhwnd = FindWindow(0, TEXT(TEXT_TITLE)); 1197 | 1198 | if (oldhwnd) 1199 | { 1200 | RestoreFromTray(oldhwnd); 1201 | } 1202 | 1203 | ExitProcess(0); 1204 | 1205 | } 1206 | if(no_categories) 1207 | SendMessage(hwndDlg, WM_COMMAND, IDM_CATEGORY_ADD, 0); 1208 | } 1209 | return TRUE; 1210 | 1211 | case WM_CLOSE: 1212 | { 1213 | MinimizeToTray(hwndDlg); 1214 | } 1215 | return TRUE; 1216 | 1217 | case WM_HOTKEY: 1218 | { 1219 | switch(LOWORD(wParam)) 1220 | { 1221 | case IDH_RESTOREHIDE: 1222 | { 1223 | if(IsMinimized) 1224 | RestoreFromTray(hwndDlg); 1225 | else 1226 | MinimizeToTray(hwndDlg); 1227 | } 1228 | return TRUE; 1229 | } 1230 | } 1231 | return TRUE; 1232 | 1233 | case MSG_MINTRAYICON: 1234 | { 1235 | if(wParam!=IDI_TRAYICON) 1236 | { 1237 | break; 1238 | } 1239 | else 1240 | { 1241 | switch(lParam) 1242 | { 1243 | case WM_LBUTTONUP: 1244 | { 1245 | if(IsMinimized) 1246 | RestoreFromTray(hwndDlg); 1247 | else 1248 | MinimizeToTray(hwndDlg); 1249 | } 1250 | return TRUE; 1251 | 1252 | case WM_RBUTTONUP: 1253 | { 1254 | HMENU myMenu=NULL; 1255 | myMenu=CreatePopupMenu(); 1256 | if(IsMinimized) 1257 | AppendMenu(myMenu, MF_STRING, TRAY_RESTORE, TEXT("Restore")); 1258 | AppendMenu(myMenu, MF_STRING, TRAY_EXIT, TEXT("Exit")); 1259 | POINT cursorPos; 1260 | GetCursorPos(&cursorPos); 1261 | SetForegroundWindow(hwndDlg); 1262 | UINT MenuItemClicked=TrackPopupMenu(myMenu, TPM_RETURNCMD | TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwndDlg, NULL); 1263 | SendMessage(hwndDlg, WM_NULL, 0, 0); 1264 | switch(MenuItemClicked) 1265 | { 1266 | case TRAY_RESTORE: 1267 | { 1268 | RestoreFromTray(hwndDlg); 1269 | } 1270 | return TRUE; 1271 | 1272 | case TRAY_EXIT: 1273 | { 1274 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to exit Pattern Manager?"), TEXT("Exit?"), MB_YESNO|MB_DEFBUTTON2|MB_ICONQUESTION)==IDYES) 1275 | { 1276 | memset(&nid, 0, sizeof(nid)); 1277 | nid.cbSize=sizeof(NOTIFYICONDATA); 1278 | nid.hWnd=hwndDlg; 1279 | nid.uID=IDI_TRAYICON; 1280 | Shell_NotifyIcon(NIM_DELETE, &nid); 1281 | IsMinimized=false; 1282 | ExitProcess(0); 1283 | } 1284 | } 1285 | return TRUE; 1286 | } 1287 | return TRUE; 1288 | } 1289 | } 1290 | break; 1291 | } 1292 | } 1293 | return TRUE; 1294 | 1295 | case WM_COMMAND: 1296 | { 1297 | switch(LOWORD(wParam)) 1298 | { 1299 | case IDM_FILE_HIDE: 1300 | { 1301 | if(IsMinimized) 1302 | RestoreFromTray(hwndDlg); 1303 | else 1304 | MinimizeToTray(hwndDlg); 1305 | } 1306 | return TRUE; 1307 | 1308 | case IDM_FILE_EXIT: 1309 | { 1310 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to exit Pattern Manager?"), TEXT("Exit?"), MB_YESNO|MB_DEFBUTTON2|MB_ICONQUESTION)==IDYES) 1311 | { 1312 | memset(&nid, 0, sizeof(nid)); 1313 | nid.cbSize=sizeof(NOTIFYICONDATA); 1314 | nid.hWnd=hwndDlg; 1315 | nid.uID=IDI_TRAYICON; 1316 | Shell_NotifyIcon(NIM_DELETE, &nid); 1317 | IsMinimized=false; 1318 | ExitProcess(0); 1319 | } 1320 | } 1321 | return TRUE; 1322 | 1323 | case IDM_HELP_ABOUT: 1324 | { 1325 | MessageBox(hwndDlg, TEXT("Pattern Manager v0.2 Mod\n\nCoded by Mr. eXoDia // T.P.o.D.T 2012\nmr.exodia.tpodt@gmail.com\nhttp://www.tpodt.com\n\nSpecial thanks fly out to:\nLoki, LCF-AT and Av0id"), TEXT("About"), MB_ICONINFORMATION); 1326 | } 1327 | return TRUE; 1328 | 1329 | case IDC_BTN_COPY: 1330 | { 1331 | CopyPattern(category_selected, main_pattern_selected+1); 1332 | } 1333 | return TRUE; 1334 | 1335 | case IDM_PATTERN_PROCESSSCAN: 1336 | { 1337 | ScanProcessAction(hwndDlg); 1338 | } 1339 | return TRUE; 1340 | case IDM_PATTERN_FILESCAN: 1341 | { 1342 | if (ScanPatternInFileAction(category_selected, main_pattern_selected+1)) 1343 | { 1344 | MessageBox(hwndDlg, TEXT("File successful scanned"), TEXT("Success"), MB_ICONINFORMATION); 1345 | } 1346 | } 1347 | return TRUE; 1348 | 1349 | case IDM_CATEGORY_ADD: 1350 | { 1351 | category_edit=true; 1352 | stuff_changed=false; 1353 | DialogBox(hInst, MAKEINTRESOURCE(DLG_ADD), hwndDlg, (DLGPROC)DlgAdd); 1354 | if(stuff_changed) 1355 | { 1356 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), true); 1357 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1358 | } 1359 | } 1360 | return TRUE; 1361 | 1362 | case IDM_CATEGORY_REMOVE: 1363 | { 1364 | category_edit=true; 1365 | stuff_changed=false; 1366 | DialogBox(hInst, MAKEINTRESOURCE(DLG_REMOVE), hwndDlg, (DLGPROC)DlgRemove); 1367 | if(stuff_changed) 1368 | { 1369 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), true); 1370 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1371 | } 1372 | } 1373 | return TRUE; 1374 | 1375 | case IDM_CATEGORY_EDIT: 1376 | { 1377 | if(!no_categories) 1378 | { 1379 | category_edit=true; 1380 | stuff_changed=false; 1381 | DialogBox(hInst, MAKEINTRESOURCE(DLG_EDIT), hwndDlg, (DLGPROC)DlgEdit); 1382 | if(stuff_changed) 1383 | { 1384 | RefreshCategoryList(GetDlgItem(hwndDlg, IDC_COMBO_CATEGORY), true); 1385 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1386 | } 1387 | } 1388 | else 1389 | MessageBeep(MB_ICONERROR); 1390 | } 1391 | return TRUE; 1392 | 1393 | case IDM_PATTERN_ADD: 1394 | { 1395 | if(!no_categories) 1396 | { 1397 | category_edit=false; 1398 | stuff_changed=false; 1399 | DialogBox(hInst, MAKEINTRESOURCE(DLG_ADD), hwndDlg, (DLGPROC)DlgAdd); 1400 | if(stuff_changed) 1401 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1402 | } 1403 | else 1404 | MessageBeep(MB_ICONERROR); 1405 | } 1406 | return TRUE; 1407 | 1408 | case IDM_PATTERN_REMOVE: 1409 | { 1410 | if(!no_categories) 1411 | { 1412 | category_edit=false; 1413 | stuff_changed=false; 1414 | DialogBox(hInst, MAKEINTRESOURCE(DLG_REMOVE), hwndDlg, (DLGPROC)DlgRemove); 1415 | if(stuff_changed) 1416 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1417 | } 1418 | else 1419 | { 1420 | MessageBeep(MB_ICONERROR); 1421 | } 1422 | } 1423 | return TRUE; 1424 | 1425 | case IDM_PATTERN_EDIT: 1426 | { 1427 | if(!no_categories) 1428 | { 1429 | category_edit=false; 1430 | stuff_changed=false; 1431 | DialogBox(hInst, MAKEINTRESOURCE(DLG_EDIT), hwndDlg, (DLGPROC)DlgEdit); 1432 | if(stuff_changed) 1433 | { 1434 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1435 | } 1436 | } 1437 | else 1438 | { 1439 | MessageBeep(MB_ICONERROR); 1440 | } 1441 | } 1442 | return TRUE; 1443 | 1444 | case IDM_PATTERN_UPDATE: 1445 | { 1446 | if(!no_categories) 1447 | { 1448 | category_edit=false; 1449 | stuff_changed=false; 1450 | DialogBox(hInst, MAKEINTRESOURCE(DLG_UPDATE), hwndDlg, (DLGPROC)DlgUpdate); 1451 | if(stuff_changed) 1452 | { 1453 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1454 | } 1455 | } 1456 | else 1457 | { 1458 | MessageBeep(MB_ICONERROR); 1459 | } 1460 | } 1461 | return TRUE; 1462 | 1463 | case IDM_PATTERN_COPY: 1464 | { 1465 | if(!no_categories) 1466 | SendMessage(hwndDlg, WM_COMMAND, IDC_BTN_COPY, 0); 1467 | else 1468 | MessageBeep(MB_ICONERROR); 1469 | } 1470 | return TRUE; 1471 | 1472 | case IDC_COMBO_CATEGORY: 1473 | { 1474 | switch(HIWORD(wParam)) 1475 | { 1476 | case CBN_SELCHANGE: 1477 | { 1478 | int currentsel=SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETCURSEL, 0, 0); 1479 | SendDlgItemMessage(hwndDlg, IDC_COMBO_CATEGORY, CB_GETLBTEXT, (WPARAM)currentsel, (LPARAM)category_selected); 1480 | main_category_selected=currentsel; 1481 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1482 | } 1483 | return TRUE; 1484 | } 1485 | } 1486 | return TRUE; 1487 | 1488 | case IDC_LIST_PATTERNS: 1489 | { 1490 | switch(HIWORD(wParam)) 1491 | { 1492 | case LBN_DBLCLK: 1493 | { 1494 | HMENU myMenu=NULL; 1495 | myMenu=CreatePopupMenu(); 1496 | AppendMenu(myMenu, MF_STRING, 5, TEXT("&Copy")); 1497 | AppendMenu(myMenu, MF_STRING, 2, TEXT("&Update")); 1498 | AppendMenu(myMenu, MF_STRING, 1, TEXT("&Add")); 1499 | AppendMenu(myMenu, MF_STRING, 3, TEXT("&Remove")); 1500 | AppendMenu(myMenu, MF_STRING, 4, TEXT("&Edit")); 1501 | AppendMenu(myMenu, MF_STRING, 6, TEXT("&Scan File")); 1502 | AppendMenu(myMenu, MF_STRING, 7, TEXT("&Scan Process")); 1503 | POINT cursorPos; 1504 | GetCursorPos(&cursorPos); 1505 | SetForegroundWindow(hwndDlg); 1506 | UINT MenuItemClicked=TrackPopupMenu(myMenu, TPM_RETURNCMD | TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwndDlg, NULL); 1507 | SendMessage(hwndDlg, WM_NULL, 0, 0); 1508 | if(MenuItemClicked==NULL) 1509 | return TRUE; 1510 | 1511 | switch(MenuItemClicked) 1512 | { 1513 | case 1: 1514 | { 1515 | SendMessage(hwndDlg, WM_COMMAND, IDM_PATTERN_ADD, 0); 1516 | } 1517 | return TRUE; 1518 | 1519 | case 2: 1520 | { 1521 | SendMessage(hwndDlg, WM_COMMAND, IDM_PATTERN_UPDATE, 0); 1522 | } 1523 | return TRUE; 1524 | 1525 | case 3: 1526 | { 1527 | TCHAR keyname[30]={0}; 1528 | _stprintf_s(keyname,_countof(keyname), TEXT("Pattern%.04dName"), main_pattern_selected+1); 1529 | GetPrivateProfileString(category_selected, keyname, TEXT(""), name_pattern_selected, 255, datafile); 1530 | if(MessageBox(hwndDlg, TEXT("Are you sure you want to remove this pattern?"), name_pattern_selected, MB_YESNO|MB_ICONQUESTION)==IDYES) 1531 | { 1532 | if(RemovePattern(category_selected, main_pattern_selected+1)) 1533 | { 1534 | MessageBox(hwndDlg, TEXT("Pattern removed!"), TEXT("Success"), MB_ICONINFORMATION); 1535 | RefreshPatternList(category_selected, GetDlgItem(hwndDlg, IDC_LIST_PATTERNS), true, 0, false); 1536 | } 1537 | else 1538 | { 1539 | MessageBox(hwndDlg, TEXT("Something went wrong..."), TEXT("Failure"), MB_ICONERROR); 1540 | } 1541 | } 1542 | } 1543 | return TRUE; 1544 | 1545 | case 4: 1546 | { 1547 | SendMessage(hwndDlg, WM_COMMAND, IDM_PATTERN_EDIT, 0); 1548 | } 1549 | return TRUE; 1550 | 1551 | case 5: 1552 | { 1553 | SendMessage(hwndDlg, WM_COMMAND, IDM_PATTERN_COPY, 0); 1554 | } 1555 | return TRUE; 1556 | 1557 | case 6: 1558 | { 1559 | if (ScanPatternInFileAction(category_selected, main_pattern_selected+1)) 1560 | { 1561 | MessageBox(hwndDlg, TEXT("File successful scanned"), TEXT("Success"), MB_ICONINFORMATION); 1562 | } 1563 | 1564 | } 1565 | return TRUE; 1566 | 1567 | case 7: 1568 | { 1569 | ScanProcessAction(hwndDlg); 1570 | } 1571 | return TRUE; 1572 | } 1573 | } 1574 | return TRUE; 1575 | 1576 | case LBN_SELCHANGE: 1577 | { 1578 | main_pattern_selected=SendDlgItemMessage(hwndDlg, IDC_LIST_PATTERNS, LB_GETCURSEL, 0, 0); 1579 | } 1580 | return TRUE; 1581 | 1582 | 1583 | } 1584 | } 1585 | return TRUE; 1586 | } 1587 | } 1588 | return TRUE; 1589 | 1590 | //case WM_NOTIFY: 1591 | //{ 1592 | // MessageBeep(MB_OK); 1593 | /*switch(((LPNMHDR)lParam)->code) 1594 | { 1595 | case NM_RCLICK: 1596 | { 1597 | MessageBeep(MB_ICONERROR); 1598 | asm("nop"); 1599 | } 1600 | return TRUE; 1601 | } 1602 | return TRUE;*/ 1603 | /*switch(LOWORD(wParam)) 1604 | { 1605 | case IDC_LIST_PATTERNS: 1606 | { 1607 | MessageBeep(MB_OK); 1608 | } 1609 | return TRUE; 1610 | }*/ 1611 | //} 1612 | //return TRUE; 1613 | 1614 | } 1615 | return FALSE; 1616 | } 1617 | 1618 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) 1619 | { 1620 | hInst=hInstance; 1621 | InitCommonControls(); 1622 | return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain); 1623 | } 1624 | -------------------------------------------------------------------------------- /PatternManager/manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /PatternManager/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef IDC_STATIC 2 | #define IDC_STATIC (-1) 3 | #endif 4 | 5 | #define DLG_MAIN 101 6 | #define IDR_MENU_MAIN 102 7 | #define IDI_ICON1 103 8 | #define DLG_REMOVE 110 9 | #define DLG_ADD 111 10 | #define DLG_EDIT 112 11 | #define DLG_UPDATE 114 12 | #define DLG_PROCESSLIST 116 13 | #define IDC_COMBO_PATTERN 1000 14 | #define IDC_COMBO_CATEGORY 1001 15 | #define IDC_COMBO_PROCESS 1002 16 | #define IDC_EDT_DATA1 1002 17 | #define IDC_LIST_PATTERNS 1002 18 | #define IDC_EDT_DATA 1003 19 | #define IDC_EDT_DATA2 1004 20 | #define IDC_EDT_NAME 1004 21 | #define IDC_BTN_OK 1005 22 | #define IDC_BTN_CANCEL 1006 23 | #define IDC_BTN_COPY 1007 24 | #define IDC_EDT_DATA3 1007 25 | #define IDC_CHK_NIBBLES 1008 26 | #define IDM_FILE_HIDE 40000 27 | #define IDM_FILE_EXIT 40001 28 | #define IDM_CATEGORY_ADD 40002 29 | #define IDM_CATEGORY_REMOVE 40003 30 | #define IDM_CATEGORY_EDIT 40004 31 | #define IDM_PATTERN_ADD 40005 32 | #define IDM_PATTERN_REMOVE 40006 33 | #define IDM_PATTERN_EDIT 40007 34 | #define IDM_PATTERN_COPY 40008 35 | #define IDM_HELP_ABOUT 40009 36 | #define IDM_PATTERN_UPDATE 40010 37 | #define IDM_PATTERN_FILESCAN 40011 38 | #define IDM_PATTERN_PROCESSSCAN 40012 39 | -------------------------------------------------------------------------------- /PatternManager/resource.rc: -------------------------------------------------------------------------------- 1 | // Generated by ResEdit 1.5.10 2 | // Copyright (C) 2006-2012 3 | // http://www.resedit.net 4 | 5 | #include 6 | #include 7 | #include 8 | #include "resource.h" 9 | 10 | 11 | 12 | 13 | // 14 | // Menu resources 15 | // 16 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 17 | IDR_MENU_MAIN MENU 18 | { 19 | POPUP "&File" 20 | { 21 | MENUITEM "&Hide", IDM_FILE_HIDE 22 | MENUITEM "E&xit", IDM_FILE_EXIT 23 | } 24 | POPUP "&Category" 25 | { 26 | MENUITEM "&Add", IDM_CATEGORY_ADD 27 | MENUITEM "&Remove", IDM_CATEGORY_REMOVE 28 | MENUITEM "&Edit", IDM_CATEGORY_EDIT 29 | } 30 | POPUP "&Pattern" 31 | { 32 | MENUITEM "&Add", IDM_PATTERN_ADD 33 | MENUITEM "&Update", IDM_PATTERN_UPDATE 34 | MENUITEM "&Remove", IDM_PATTERN_REMOVE 35 | MENUITEM "&Edit", IDM_PATTERN_EDIT 36 | MENUITEM SEPARATOR 37 | MENUITEM "&Copy", IDM_PATTERN_COPY 38 | MENUITEM SEPARATOR 39 | MENUITEM "&Scan File", IDM_PATTERN_FILESCAN 40 | MENUITEM "&Scan Process", IDM_PATTERN_PROCESSSCAN 41 | } 42 | POPUP "&Help" 43 | { 44 | MENUITEM "&About", IDM_HELP_ABOUT 45 | } 46 | } 47 | 48 | 49 | 50 | // 51 | // Dialog resources 52 | // 53 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 54 | DLG_ADD DIALOGEX 0, 0, 182, 69 55 | STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 56 | CAPTION "Add Pattern" 57 | FONT 8, "Courier New", 400, 0, 0 58 | { 59 | EDITTEXT IDC_EDT_NAME, 39, 21, 137, 12, ES_AUTOHSCROLL 60 | EDITTEXT IDC_EDT_DATA, 39, 37, 137, 12, ES_AUTOHSCROLL | ES_UPPERCASE 61 | DEFPUSHBUTTON "OK", IDC_BTN_OK, 72, 52, 50, 14 62 | PUSHBUTTON "Cancel", IDC_BTN_CANCEL, 126, 52, 50, 14 63 | COMBOBOX IDC_COMBO_CATEGORY, 39, 4, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_SORT 64 | RTEXT "Category:", IDC_STATIC, 1, 5, 36, 8, SS_RIGHT 65 | RTEXT "Name:", IDC_STATIC, 1, 22, 36, 8, SS_RIGHT 66 | RTEXT "Data:", IDC_STATIC, 1, 38, 36, 8, SS_RIGHT 67 | } 68 | 69 | 70 | 71 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 72 | DLG_EDIT DIALOGEX 0, 0, 182, 83 73 | STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 74 | CAPTION "Edit Pattern" 75 | FONT 8, "Courier New", 400, 0, 0 76 | { 77 | EDITTEXT IDC_EDT_NAME, 39, 34, 137, 12, ES_AUTOHSCROLL 78 | EDITTEXT IDC_EDT_DATA, 39, 49, 137, 12, ES_AUTOHSCROLL | ES_UPPERCASE 79 | DEFPUSHBUTTON "OK", IDC_BTN_OK, 72, 65, 50, 14 80 | PUSHBUTTON "Cancel", IDC_BTN_CANCEL, 126, 65, 50, 14 81 | COMBOBOX IDC_COMBO_CATEGORY, 39, 4, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_SORT 82 | RTEXT "Category:", IDC_STATIC, 1, 5, 36, 8, SS_RIGHT 83 | RTEXT "Name:", IDC_STATIC, 1, 36, 36, 8, SS_RIGHT 84 | RTEXT "Data:", IDC_STATIC, 1, 50, 36, 8, SS_RIGHT 85 | COMBOBOX IDC_COMBO_PATTERN, 39, 19, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS 86 | RTEXT "Pattern:", IDC_STATIC, 1, 20, 36, 8, SS_RIGHT 87 | } 88 | 89 | 90 | 91 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 92 | DLG_MAIN DIALOGEX 6, 5, 292, 209 93 | STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_POPUP | WS_SYSMENU 94 | CAPTION "Pattern Manager" 95 | MENU IDR_MENU_MAIN 96 | FONT 8, "Courier New", 400, 0, 0 97 | { 98 | LISTBOX IDC_LIST_PATTERNS, 7, 32, 281, 170, WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY 99 | COMBOBOX IDC_COMBO_CATEGORY, 124, 7, 164, 30, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_HASSTRINGS | CBS_SORT 100 | LTEXT "Category:", IDC_STATIC, 87, 8, 36, 8, SS_LEFT 101 | DEFPUSHBUTTON "Copy Pattern", IDC_BTN_COPY, 9, 5, 73, 14 102 | LTEXT " Num - Pattern Description - Len - Pattern Data", IDC_STATIC, 9, 22, 274, 8, SS_LEFT 103 | } 104 | 105 | 106 | 107 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 108 | DLG_PROCESSLIST DIALOG 0, 0, 315, 35 109 | STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 110 | CAPTION "Select a process" 111 | FONT 8, "Courier New" 112 | { 113 | DEFPUSHBUTTON "OK", IDC_BTN_OK, 214, 19, 50, 14 114 | PUSHBUTTON "Cancel", IDC_BTN_CANCEL, 264, 19, 50, 14 115 | COMBOBOX IDC_COMBO_PROCESS, 41, 4, 273, 100, CBS_DROPDOWN | CBS_HASSTRINGS 116 | LTEXT "Process:", IDC_STATIC, 5, 6, 33, 8, SS_LEFT 117 | } 118 | 119 | 120 | 121 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 122 | DLG_REMOVE DIALOGEX 0, 0, 182, 57 123 | STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 124 | CAPTION "Remove Pattern" 125 | FONT 8, "Courier New", 400, 0, 0 126 | { 127 | COMBOBOX IDC_COMBO_PATTERN, 39, 22, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS 128 | DEFPUSHBUTTON "OK", IDC_BTN_OK, 72, 40, 50, 14 129 | PUSHBUTTON "Cancel", IDC_BTN_CANCEL, 126, 40, 50, 14 130 | COMBOBOX IDC_COMBO_CATEGORY, 39, 4, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_SORT 131 | RTEXT "Category:", IDC_STATIC, 1, 5, 36, 8, SS_RIGHT 132 | RTEXT "Pattern:", IDC_STATIC, 1, 24, 36, 8, SS_RIGHT 133 | } 134 | 135 | 136 | 137 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 138 | DLG_UPDATE DIALOGEX 0, 0, 182, 107 139 | STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 140 | CAPTION "Update Pattern" 141 | FONT 8, "Courier New", 400, 0, 0 142 | { 143 | EDITTEXT IDC_EDT_DATA2, 39, 49, 137, 12, ES_AUTOHSCROLL | ES_UPPERCASE 144 | EDITTEXT IDC_EDT_DATA3, 39, 64, 137, 12, ES_AUTOHSCROLL | ES_UPPERCASE | ES_READONLY 145 | AUTOCHECKBOX "&Nibbles?", IDC_CHK_NIBBLES, 136, 79, 40, 8 146 | DEFPUSHBUTTON "OK", IDC_BTN_OK, 73, 89, 50, 14 147 | PUSHBUTTON "Cancel", IDC_BTN_CANCEL, 127, 89, 50, 14 148 | COMBOBOX IDC_COMBO_CATEGORY, 39, 4, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_SORT 149 | COMBOBOX IDC_COMBO_PATTERN, 39, 19, 137, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS 150 | EDITTEXT IDC_EDT_DATA1, 39, 34, 137, 12, ES_AUTOHSCROLL | ES_UPPERCASE | ES_READONLY 151 | RTEXT "Category:", IDC_STATIC, 1, 5, 36, 8, SS_RIGHT 152 | RTEXT "Data 1:", IDC_STATIC, 1, 36, 36, 8, SS_RIGHT 153 | RTEXT "Data 2:", IDC_STATIC, 1, 50, 36, 8, SS_RIGHT 154 | RTEXT "Pattern:", IDC_STATIC, 1, 20, 36, 8, SS_RIGHT 155 | RTEXT "Update:", IDC_STATIC, 1, 65, 36, 8, SS_RIGHT 156 | } 157 | 158 | 159 | 160 | // 161 | // Icon resources 162 | // 163 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 164 | IDI_ICON1 ICON ".\\icon.ico" 165 | 166 | 167 | 168 | // 169 | // Manifest resources 170 | // 171 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 172 | 1 RT_MANIFEST ".\\manifest.xml" 173 | -------------------------------------------------------------------------------- /PatternManager/scanner.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "scanner.h" 5 | #include "resource.h" 6 | #include 7 | #include 8 | 9 | LONGLONG getFileSize(HANDLE hFile); 10 | void ScanPatternInMemory(BYTE * memory, DWORD memorySize,DWORD_PTR startOffset, TCHAR * pattern); 11 | void WriteLog(const TCHAR * format, ...); 12 | bool SelectFile(TCHAR * filePath); 13 | bool SearchPatternInFile(const TCHAR * filePath, TCHAR * pattern); 14 | DWORD findPattern(DWORD_PTR startOffset, DWORD size, const PBYTE pattern, const TCHAR * mask,DWORD_PTR startRelativeOffset); 15 | void TextToByteMask(TCHAR * pattern, BYTE * bytePattern, TCHAR * mask,unsigned int maskLen); 16 | bool SearchPatternInProcess(Process & process, TCHAR * pattern); 17 | 18 | TCHAR logbuf[500] = {0}; 19 | extern TCHAR scannerLog[MAX_PATH]; 20 | extern TCHAR add_data_text[PATTERN_MAX_SIZE]; 21 | extern HINSTANCE hInst; 22 | 23 | std::vector processList; 24 | 25 | bool ScanPatternInFile(TCHAR * pattern) 26 | { 27 | TCHAR targetFile[MAX_PATH] = {0}; 28 | 29 | if (SelectFile(targetFile)) 30 | { 31 | WriteLog(TEXT("\r\n------------------------------------------------------\r\n")); 32 | WriteLog(TEXT("File: %s\r\n"),targetFile); 33 | 34 | 35 | 36 | return SearchPatternInFile(targetFile,pattern); 37 | } 38 | 39 | return false; 40 | } 41 | 42 | bool SelectFile(TCHAR * filePath) 43 | { 44 | OPENFILENAME ofn = {0}; 45 | 46 | ofn.lStructSize = sizeof(ofn); 47 | ofn.lpstrFile = filePath; 48 | ofn.nMaxFile = MAX_PATH; 49 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; 50 | ofn.lpstrFilter = TEXT("Executable (*.exe)\0*.exe\0Dynamic Link Library (*.dll)\0*.dll\0All files\0*.*\0"); 51 | 52 | 53 | return (GetOpenFileName(&ofn) != 0); 54 | } 55 | 56 | bool SearchPatternInFile(const TCHAR * filePath, TCHAR * pattern) 57 | { 58 | LONGLONG fileSize = 0; 59 | BYTE * fileBuffer = 0; 60 | DWORD lpNumberOfBytesRead = 0; 61 | HANDLE hFile = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 62 | 63 | bool retValue = false; 64 | 65 | if (hFile == INVALID_HANDLE_VALUE) 66 | { 67 | MessageBox(0, TEXT("CreateFile GENERIC_READ FILE_SHARE_READ OPEN_EXISTING failed"), TEXT("Error"), MB_ICONERROR); 68 | } 69 | else 70 | { 71 | fileSize = getFileSize(hFile); 72 | 73 | if (fileSize == 0) 74 | { 75 | MessageBox(0, TEXT("getFileSize failed"), TEXT("Error"), MB_ICONERROR); 76 | } 77 | else 78 | { 79 | fileBuffer = (BYTE *)malloc((size_t)fileSize); 80 | 81 | if (!fileBuffer) 82 | { 83 | MessageBox(0, TEXT("malloc failed"), TEXT("Error"), MB_ICONERROR); 84 | } 85 | else 86 | { 87 | if (!ReadFile(hFile, fileBuffer, (DWORD)fileSize, &lpNumberOfBytesRead, 0)) 88 | { 89 | MessageBox(0, TEXT("ReadFile failed"), TEXT("Error"), MB_ICONERROR); 90 | } 91 | else 92 | { 93 | ScanPatternInMemory(fileBuffer,lpNumberOfBytesRead,0,pattern); 94 | retValue = true; 95 | } 96 | 97 | free(fileBuffer); 98 | } 99 | } 100 | 101 | CloseHandle(hFile); 102 | } 103 | 104 | 105 | return retValue; 106 | } 107 | 108 | void ScanPatternInMemory(BYTE * memory, DWORD memorySize,DWORD_PTR startOffset, TCHAR * pattern) 109 | { 110 | BYTE * bytePattern = 0; 111 | TCHAR * mask = 0; 112 | unsigned int len = _tcslen(pattern); 113 | if (len % 2) 114 | len++; 115 | 116 | len = (len/2) + 1; 117 | 118 | bytePattern = (BYTE *)malloc(len); 119 | mask = (TCHAR *)malloc(len * sizeof(TCHAR)); 120 | 121 | ZeroMemory(mask,len * sizeof(TCHAR)); 122 | ZeroMemory(bytePattern,len); 123 | 124 | TextToByteMask(pattern,bytePattern,mask,len); 125 | 126 | 127 | WriteLog(TEXT("Scanning pattern %s memory size 0x%X\r\n"),pattern,memorySize); 128 | WriteLog(TEXT("------------------------------------------------------\r\n")); 129 | 130 | DWORD found = findPattern((DWORD_PTR)memory,memorySize,bytePattern,mask, startOffset); 131 | 132 | WriteLog(TEXT("Found %d times\r\n"),found); 133 | WriteLog(TEXT("------------------------------------------------------\r\n")); 134 | 135 | free(mask); 136 | free(bytePattern); 137 | } 138 | 139 | void TextToByteMask(TCHAR * pattern, BYTE * bytePattern, TCHAR * mask, unsigned int maskLen) 140 | { 141 | TCHAR temp[3] = {0}; 142 | unsigned int len = _tcslen(pattern); 143 | 144 | if (len % 2) 145 | { 146 | _tcscat_s(pattern,PATTERN_MAX_SIZE,TEXT("?")); 147 | len++; 148 | } 149 | 150 | for (unsigned int i = 0, k = 0; i < len; i+=2, k++) 151 | { 152 | if ((pattern[i] == TEXT('?')) || (pattern[i+1] == TEXT('?'))) 153 | { 154 | _tcscat_s(mask,maskLen,TEXT("?")); 155 | bytePattern[k] = 0; 156 | } 157 | else 158 | { 159 | temp[0] = pattern[i]; 160 | temp[1] = pattern[i+1]; 161 | 162 | _tcscat_s(mask,maskLen,TEXT("x")); 163 | 164 | bytePattern[k] = (BYTE)_tcstoul(temp,0,16); 165 | } 166 | } 167 | } 168 | 169 | LONGLONG getFileSize(HANDLE hFile) 170 | { 171 | LARGE_INTEGER lpFileSize = {0}; 172 | 173 | if ((hFile != INVALID_HANDLE_VALUE) && (hFile != 0)) 174 | { 175 | if (!GetFileSizeEx(hFile, &lpFileSize)) 176 | { 177 | MessageBox(0, TEXT("GetFileSizeEx failed"), TEXT("Error"), MB_ICONERROR); 178 | return 0; 179 | } 180 | else 181 | { 182 | return lpFileSize.QuadPart; 183 | } 184 | } 185 | else 186 | { 187 | return 0; 188 | } 189 | } 190 | 191 | DWORD findPattern(DWORD_PTR startOffset, DWORD size, const PBYTE pattern, const TCHAR * mask, DWORD_PTR startRelativeOffset) 192 | { 193 | DWORD pos = 0; 194 | DWORD found = 0; 195 | size_t searchLen = _tcslen(mask) - 1; 196 | 197 | for(DWORD_PTR retAddress = startOffset; retAddress < startOffset + size; retAddress++) 198 | { 199 | if( *(BYTE*)retAddress == pattern[pos] || mask[pos] == TEXT('?') ) 200 | { 201 | pos++; 202 | if(mask[pos] == 0x00) 203 | { 204 | if (startRelativeOffset) 205 | { 206 | WriteLog(TEXT("Found at VA 0x%08X\r\n"),retAddress - searchLen - startOffset + startRelativeOffset); 207 | } 208 | else 209 | { 210 | WriteLog(TEXT("Found at offset 0x%08X\r\n"),retAddress - searchLen - startOffset); 211 | } 212 | pos = 0; 213 | found++; 214 | } 215 | 216 | } 217 | else 218 | { 219 | pos = 0; 220 | } 221 | } 222 | 223 | return found; 224 | } 225 | 226 | void WriteLog(const TCHAR * format, ...) 227 | { 228 | FILE * pFile; 229 | va_list va_alist; 230 | 231 | if (!format) 232 | { 233 | return; 234 | } 235 | 236 | logbuf[0] = 0; 237 | 238 | va_start (va_alist, format); 239 | _vsntprintf_s(logbuf, _countof(logbuf), _countof(logbuf) - 1, format, va_alist); 240 | va_end (va_alist); 241 | 242 | if (_tfopen_s(&pFile,scannerLog,L"a") == NULL) 243 | { 244 | _fputts(logbuf,pFile); 245 | fclose(pFile); 246 | } 247 | } 248 | 249 | SIZE_T getSizeOfImageProcess(HANDLE processHandle, DWORD_PTR moduleBase) 250 | { 251 | SIZE_T sizeOfImage = 0; 252 | MEMORY_BASIC_INFORMATION lpBuffer = {0}; 253 | 254 | do 255 | { 256 | moduleBase = (DWORD_PTR)((SIZE_T)moduleBase + lpBuffer.RegionSize); 257 | sizeOfImage += lpBuffer.RegionSize; 258 | 259 | if (!VirtualQueryEx(processHandle, (LPCVOID)moduleBase, &lpBuffer, sizeof(MEMORY_BASIC_INFORMATION))) 260 | { 261 | MessageBox(0, TEXT("VirtualQueryEx failed"), TEXT("Error"), MB_ICONERROR); 262 | lpBuffer.Type = 0; 263 | sizeOfImage = 0; 264 | } 265 | } while (lpBuffer.Type == MEM_IMAGE); 266 | 267 | 268 | return sizeOfImage; 269 | } 270 | 271 | bool GetProcessList(HWND hwndDlg) 272 | { 273 | HANDLE hProcessSnap = 0; 274 | PROCESSENTRY32 pe32 = {0}; 275 | HANDLE hModuleSnap = INVALID_HANDLE_VALUE; 276 | MODULEENTRY32 me32 = {0}; 277 | Process process; 278 | HANDLE hProcess = 0; 279 | 280 | HWND hCombo = GetDlgItem(hwndDlg, IDC_COMBO_PROCESS); 281 | 282 | if (!hCombo) 283 | return false; 284 | 285 | processList.clear(); 286 | processList.reserve(34); 287 | 288 | hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 289 | if(hProcessSnap == INVALID_HANDLE_VALUE) 290 | { 291 | MessageBox(0, TEXT("CreateToolhelp32Snapshot failed"), TEXT("Error"), MB_ICONERROR); 292 | return false; 293 | } 294 | 295 | pe32.dwSize = sizeof(PROCESSENTRY32); 296 | 297 | if(!Process32First(hProcessSnap, &pe32)) 298 | { 299 | CloseHandle(hProcessSnap); 300 | MessageBox(0, TEXT("Process32First failed"), TEXT("Error"), MB_ICONERROR); 301 | return false; 302 | } 303 | 304 | do 305 | { 306 | //filter process list 307 | if (pe32.th32ProcessID > 4) 308 | { 309 | process.PID = pe32.th32ProcessID; 310 | 311 | hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, process.PID); 312 | if(hModuleSnap != INVALID_HANDLE_VALUE) 313 | { 314 | me32.dwSize = sizeof(MODULEENTRY32); 315 | 316 | Module32First(hModuleSnap, &me32); 317 | process.imageBase = (DWORD_PTR)me32.hModule; 318 | _tcscpy_s(process.fullPath, MAX_PATH, me32.szExePath); 319 | CloseHandle(hModuleSnap); 320 | 321 | hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, NULL, process.PID); 322 | if(hProcess) 323 | { 324 | process.imageSize = getSizeOfImageProcess(hProcess,process.imageBase); 325 | 326 | CloseHandle(hProcess); 327 | 328 | if (process.imageSize != 0) 329 | { 330 | _tcscpy_s(process.filename, MAX_PATH, pe32.szExeFile); 331 | 332 | processList.push_back(process); 333 | } 334 | 335 | } 336 | } 337 | } 338 | } while(Process32Next(hProcessSnap, &pe32)); 339 | 340 | CloseHandle(hProcessSnap); 341 | 342 | for (size_t i = 0; i < processList.size(); i++) 343 | { 344 | _stprintf_s(logbuf, _countof(logbuf),TEXT("0x%04X - %s - %s"),processList[i].PID,processList[i].filename,processList[i].fullPath); 345 | SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)logbuf); 346 | } 347 | 348 | return true; 349 | } 350 | 351 | bool ScanPatternInProcess(Process & process) 352 | { 353 | WriteLog(TEXT("\r\n------------------------------------------------------\r\n")); 354 | WriteLog(TEXT("Process:\r\n- PID: 0x%X\r\n- Filename: %s\r\n- Fullpath: %s\r\n- Imagebase: 0x%X\r\n- ImageSize 0x%X\r\n"),process.PID,process.filename,process.fullPath,process.imageBase,process.imageSize); 355 | 356 | return SearchPatternInProcess(process, add_data_text); 357 | } 358 | 359 | bool SearchPatternInProcess(Process & process, TCHAR * pattern) 360 | { 361 | SIZE_T numberOfBytesRead = 0; 362 | BYTE * buffer = 0; 363 | 364 | bool retValue = false; 365 | 366 | HANDLE hProcess = OpenProcess(PROCESS_VM_READ, NULL, process.PID); 367 | if(!hProcess) 368 | { 369 | MessageBox(0, TEXT("OpenProcess with PROCESS_VM_READ rights failed"), TEXT("Error"), MB_ICONERROR); 370 | } 371 | else 372 | { 373 | buffer = (BYTE *)malloc(process.imageSize); 374 | 375 | if (!buffer) 376 | { 377 | MessageBox(0, TEXT("malloc failed"), TEXT("Error"), MB_ICONERROR); 378 | } 379 | else 380 | { 381 | if (!ReadProcessMemory(hProcess,(LPCVOID)process.imageBase,buffer,process.imageSize,&numberOfBytesRead)) 382 | { 383 | MessageBox(0, TEXT("ReadProcessMemory failed"), TEXT("Error"), MB_ICONERROR); 384 | } 385 | else 386 | { 387 | ScanPatternInMemory(buffer,numberOfBytesRead,process.imageBase,pattern); 388 | retValue = true; 389 | } 390 | 391 | free(buffer); 392 | } 393 | 394 | CloseHandle(hProcess); 395 | } 396 | 397 | return retValue; 398 | } 399 | 400 | BOOL CALLBACK DlgProcesslist(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 401 | { 402 | LRESULT index = 0; 403 | 404 | switch(uMsg) 405 | { 406 | case WM_INITDIALOG: 407 | { 408 | SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1))); 409 | if (!GetProcessList(hwndDlg)) 410 | { 411 | MessageBox(0, TEXT("Getting process list failed"), TEXT("Error"), MB_ICONERROR); 412 | EndDialog(hwndDlg, 0); 413 | } 414 | } 415 | return TRUE; 416 | 417 | case WM_CLOSE: 418 | { 419 | EndDialog(hwndDlg, 0); 420 | } 421 | return TRUE; 422 | 423 | case WM_COMMAND: 424 | { 425 | switch(LOWORD(wParam)) 426 | { 427 | case IDC_BTN_CANCEL: 428 | { 429 | SendMessage(hwndDlg, WM_CLOSE, 0, 0); 430 | } 431 | return TRUE; 432 | 433 | case IDC_BTN_OK: 434 | { 435 | index = SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_PROCESS),CB_GETCURSEL,0,0); 436 | 437 | if (ScanPatternInProcess(processList.at(index))) 438 | { 439 | MessageBox(hwndDlg, TEXT("Process scanning finished"), TEXT("Success"), MB_ICONINFORMATION); 440 | } 441 | 442 | processList.clear(); 443 | 444 | EndDialog(hwndDlg, 0); 445 | } 446 | return TRUE; 447 | } 448 | } 449 | return TRUE; 450 | } 451 | return FALSE; 452 | } -------------------------------------------------------------------------------- /PatternManager/scanner.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #define PATTERN_MAX_SIZE 2048 5 | #define KEYNAME_MAX_SIZE 20 6 | 7 | bool ScanPatternInFile(TCHAR * pattern); 8 | BOOL CALLBACK DlgProcesslist(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 9 | 10 | class Process { 11 | public: 12 | DWORD PID; 13 | DWORD_PTR imageBase; 14 | DWORD entryPoint; //without imagebase 15 | DWORD imageSize; 16 | TCHAR filename[MAX_PATH]; 17 | TCHAR fullPath[MAX_PATH]; 18 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pattern Manager 2 | ======================================= 3 | based on the source code of Mr. eXoDia 4 | 5 | Changelog 6 | --------- 7 | 8 | Version 0.x: 9 | 10 | - small restore fix 11 | - Process scanner 12 | - File scanner 13 | - Unicode support 14 | - code improvements 15 | 16 | Version 0.02: 17 | 18 | - Fixed pattern and category editing. 19 | - Fixed a bug with pattern modding. 20 | - Changed way of listing patterns. 21 | - Bigger data buffers. 22 | - Added pattern Updater 23 | - Added a quick menu (Double click) 24 | 25 | Version 0.01: 26 | 27 | - Initial release. --------------------------------------------------------------------------------