├── NikPEViewer ├── NikPEViewer.h ├── res │ ├── 1.bmp │ ├── small.ico │ ├── Dumpfile.dat │ ├── NikPEViewer.ico │ ├── Nik_toolbar.bmp │ └── Copy of Nik_toolbar.bmp ├── small.ico ├── PEViewer.cpp ├── NikPEViewer.ico ├── stdafx.cpp ├── PEViewerTree.h ├── targetver.h ├── MenuWnd.h ├── Resource.h ├── DisAssembly.h ├── ReadMe.txt ├── ResourceWnd.h ├── DialogWnd.h ├── NikDisassembly.h ├── NikDisassemblyWin.h ├── PEBinaryFile.h ├── EditorBitmap.h ├── stdafx.h ├── NikPEViewer.vcproj ├── PEViewerListView.h ├── NikPEViewer.rc ├── CommonStr.h ├── PEViewer.h ├── NikHTMLView.h ├── MenuWnd.cpp ├── EditorBitmap.cpp ├── DialogWnd.cpp └── PEBinaryFile.cpp ├── NikPEViewer.suo ├── .gitattributes ├── .gitignore ├── NikPEViewer.sln └── README.md /NikPEViewer/NikPEViewer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /NikPEViewer.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer.suo -------------------------------------------------------------------------------- /NikPEViewer/res/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/1.bmp -------------------------------------------------------------------------------- /NikPEViewer/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/small.ico -------------------------------------------------------------------------------- /NikPEViewer/PEViewer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/PEViewer.cpp -------------------------------------------------------------------------------- /NikPEViewer/res/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/small.ico -------------------------------------------------------------------------------- /NikPEViewer/NikPEViewer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/NikPEViewer.ico -------------------------------------------------------------------------------- /NikPEViewer/res/Dumpfile.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/Dumpfile.dat -------------------------------------------------------------------------------- /NikPEViewer/res/NikPEViewer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/NikPEViewer.ico -------------------------------------------------------------------------------- /NikPEViewer/res/Nik_toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/Nik_toolbar.bmp -------------------------------------------------------------------------------- /NikPEViewer/res/Copy of Nik_toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SinghRajenM/NikPEViewer/master/NikPEViewer/res/Copy of Nik_toolbar.bmp -------------------------------------------------------------------------------- /NikPEViewer/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // NikPEViewer.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /NikPEViewer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual C++ Express 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NikPEViewer", "NikPEViewer\NikPEViewer.vcproj", "{BA16A701-219B-4BFE-9D7F-CF0B4629C672}" 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 | {BA16A701-219B-4BFE-9D7F-CF0B4629C672}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {BA16A701-219B-4BFE-9D7F-CF0B4629C672}.Debug|Win32.Build.0 = Debug|Win32 14 | {BA16A701-219B-4BFE-9D7F-CF0B4629C672}.Release|Win32.ActiveCfg = Release|Win32 15 | {BA16A701-219B-4BFE-9D7F-CF0B4629C672}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /NikPEViewer/PEViewerTree.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | class CNikPEVTreeViewCtrl 5 | { 6 | HWND m_hWnd; 7 | HINSTANCE m_hInstance; 8 | HIMAGELIST m_hImgList; 9 | 10 | public: 11 | CNikPEVTreeViewCtrl(); 12 | virtual ~CNikPEVTreeViewCtrl(); 13 | 14 | HWND GetWindowHandle() 15 | { 16 | return m_hWnd; 17 | } 18 | 19 | int DispalyBinaryInfo(); 20 | int SetRootItems(void *); 21 | _tstring SetTreeItemStr(void * ); 22 | int GetTreeItemIndex( HTREEITEM ); 23 | int SetBinarySelection(_tstring ); 24 | LRESULT Tree_Notify(HWND , LPARAM ); 25 | LPARAM GetTreeItemlParam( HTREEITEM ); 26 | _tstring GetTreeItemName( HTREEITEM ); 27 | int GetSectionOffsetDiff(void *, int ); 28 | int AddResourceItems( void *, HTREEITEM ); 29 | int AddResourceString( void * , _tstring & ); 30 | HWND CreatePETreeCtrl(HINSTANCE , HWND , RECT ); 31 | HTREEITEM AddChildItems(HTREEITEM , _tstring , void * ); 32 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LICENSE 2 | ------- 3 | 4 | This is free and unencumbered software released into the public domain. 5 | 6 | Anyone is free to copy, modify, publish, use, compile, sell, or 7 | distribute this software, either in source code form or as a compiled 8 | binary, for any purpose, commercial or non-commercial, and by any 9 | means. 10 | 11 | In jurisdictions that recognize copyright laws, the author or authors 12 | of this software dedicate any and all copyright interest in the 13 | software to the public domain. We make this dedication for the benefit 14 | of the public at large and to the detriment of our heirs and 15 | successors. We intend this dedication to be an overt act of 16 | relinquishment in perpetuity of all present and future rights to this 17 | software under copyright law. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | For more information, please refer to 28 | 29 | --------------------------------------------------------------- 30 | 31 | -------------------------------------------------------------------------------- /NikPEViewer/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The following macros define the minimum required platform. The minimum required platform 4 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 5 | // your application. The macros work by enabling all features available on platform versions up to and 6 | // including the version specified. 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista. 11 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 15 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 16 | #endif 17 | 18 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. 19 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 20 | #endif 21 | 22 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. 23 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. 24 | #endif 25 | -------------------------------------------------------------------------------- /NikPEViewer/MenuWnd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | #include 5 | #include "RESOURCE.H" 6 | 7 | using namespace std; 8 | 9 | #pragma comment (lib,"user32.lib") 10 | #pragma comment (lib,"GDI32.lib") 11 | 12 | #ifdef _UNICODE 13 | #define _tstring wstring 14 | #else 15 | #define _tstring string 16 | #endif 17 | 18 | #define CLASS_MENU _T("NIKHIL_MENU") 19 | 20 | class CMenuWnd 21 | { 22 | 23 | HWND m_hWnd; 24 | HWND m_hToolTip; 25 | HWND m_hParentWnd; 26 | HFONT m_hFont; 27 | MENU_INFO m_stMenuInfo; 28 | 29 | CMenuWnd * m_pcMenuWnd; 30 | 31 | public: 32 | 33 | CMenuWnd(); 34 | ~CMenuWnd(); 35 | 36 | void DrawMenuItems(HDC hdc); 37 | void DrawMenuText(HDC hdc, RECT &rc, _tstring &strText, int nHighlightItem); 38 | void InitMenuItems(); 39 | RECT SetMenuSize(); 40 | 41 | void OnLbuttonDown(WPARAM wParam, LPARAM lParam); 42 | void OnLbuttonUP(WPARAM wParam, LPARAM lParam); 43 | void OnMouseMove(WPARAM wParam, LPARAM lParam); 44 | 45 | void SetParentHwnd(HWND hwnd) 46 | { 47 | m_hParentWnd = hwnd; 48 | } 49 | HWND GetParenthWnd() 50 | { 51 | return m_hParentWnd; 52 | } 53 | 54 | void SethWnd(HWND hwnd) 55 | { 56 | m_hWnd = hwnd; 57 | } 58 | HWND GethWnd() 59 | { 60 | return m_hWnd; 61 | } 62 | 63 | HWND CreateMyTooltip(); 64 | 65 | HWND CreateMenuWindow(HWND hParent, HWND hSubling, MENU_INFO &stMenuInfo); 66 | 67 | static int RegisterMenuclass(HINSTANCE hInstance); 68 | static INT_PTR CALLBACK MenuWndProc(HWND hwnd, UINT uMsg, 69 | WPARAM wParam, LPARAM lParam); 70 | }; -------------------------------------------------------------------------------- /NikPEViewer/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by NikPEViewer.rc 4 | // 5 | 6 | #define IDS_APP_TITLE 103 7 | 8 | #define IDR_MAINFRAME 128 9 | #define IDD_NIKPEVIEWER_DIALOG 102 10 | #define IDD_ABOUTBOX 103 11 | #define IDM_ABOUT 104 12 | #define IDM_EXIT 105 13 | #define IDI_NIKPEVIEWER 107 14 | #define IDI_SMALL 108 15 | #define IDC_NIKPEVIEWER 109 16 | #define ID_FILE_NEW 110 17 | #define ID_FILE_OPEN 111 18 | #define IDB_TREEBITMAP 112 19 | #define IDC_TREEVIEW 113 20 | #define ID_LISTVIEW 114 21 | #define IDD_LICENSEBOX 115 22 | #define IDD_EDITLICENSE 116 23 | #define IDM_LICENSE 117 24 | #define IDM_GROUP_ALL_VIEW 118 25 | #define IDM_PE_SAMMARY 119 26 | #define IDM_PE_HEADERS 120 27 | #define IDM_PE_IMPORT_TABLE 121 28 | #define IDM_PE_EXPORT_TABLE 122 29 | #define IDM_MODULES_BINARY 123 30 | #define IDM_PE_DATA_SECTIONS 124 31 | #define ID_FILE_CLOSE 125 32 | #define IDM_SHOW_ALL_VIEW 126 33 | #define IDM_ARRANGE_ICON 127 34 | #define IDM_CASCADE_ICON 128 35 | #define IDM_TILE_VERTICAL 129 36 | #define IDM_TILE_HORIZONTAL 130 37 | #define IDB_TOOLBARBITMAP 131 38 | #define IDB_TOOLBARCTRL 132 39 | #define IDS_FILE_OPEN 133 40 | #define IDS_FILE_CLOSE 134 41 | #define IDS_PE_SAMMARY 135 42 | #define IDS_PE_HEADERS 136 43 | #define IDS_PE_DATA_SECTIONS 137 44 | #define IDS_PE_IMPORT_TABLE 138 45 | #define IDS_PE_EXPORT_TABLE 139 46 | #define IDS_MODULES_BINARY 140 47 | #define IDS_LICENSE 141 48 | #define IDS_ABOUT 142 49 | #define IDB_OPCODE_FILE 143 50 | #define IDM_PE_DISASSEMBLY 144 51 | #define IDS_PE_DISASSEMBLY 145 52 | #define IDM_MODULES_HTML 146 53 | #define IDS_MODULES_HTML 147 54 | 55 | 56 | #define IDC_MYICON 2 57 | #ifndef IDC_STATIC 58 | #define IDC_STATIC -1 59 | #endif 60 | // Next default values for new objects 61 | // 62 | #ifdef APSTUDIO_INVOKED 63 | #ifndef APSTUDIO_READONLY_SYMBOLS 64 | 65 | #define _APS_NO_MFC 130 66 | #define _APS_NEXT_RESOURCE_VALUE 129 67 | #define _APS_NEXT_COMMAND_VALUE 32771 68 | #define _APS_NEXT_CONTROL_VALUE 1000 69 | #define _APS_NEXT_SYMED_VALUE 148 70 | #endif 71 | #endif 72 | -------------------------------------------------------------------------------- /NikPEViewer/DisAssembly.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define R_M_OPCODE 1 5 | #define R_M8_OPCODE 2 6 | #define D8_OPCODE 3 7 | #define D32_OPCODE 4 8 | #define R32_OPCODE 5 9 | #define R8_OPCODE 6 10 | #define IMM8_OPCODE 7 11 | #define IMM32_OPCODE 8 12 | #define REL8_OPCODE 9 13 | #define REL32_OPCODE 10 14 | #define SREG_OPCODE 11 15 | #define EAX_OPCODE 12 16 | #define AX_OPCODE 13 17 | #define AL_OPCODE 14 18 | #define MOFFS32_OPCODE 15 19 | #define D16_OPCODE 16 20 | #define R16_OPCODE 17 21 | #define IMM16_OPCODE 18 22 | #define REL16_OPCODE 19 23 | #define MOFFS8_OPCODE 20 24 | 25 | typedef struct tagTHREEPART 26 | { 27 | BYTE rm : 3; 28 | BYTE reg : 3; 29 | BYTE mod : 2; 30 | }THREEPART; 31 | 32 | typedef struct _INSTRUCTION_OPCODE 33 | { 34 | short int bOpNumber[5]; 35 | TCHAR strNumber[64]; 36 | TCHAR strOpcode[64]; 37 | int nSlashPresent; 38 | BYTE bOpcodeFlag[8]; 39 | vector<_tstring> strList; 40 | //vector vOpcodeFlag; 41 | 42 | public: 43 | _INSTRUCTION_OPCODE() 44 | { 45 | bOpNumber[0] = -1; 46 | bOpNumber[1] = -1; 47 | bOpNumber[2] = -1; 48 | bOpNumber[3] = -1; 49 | bOpNumber[4] = -1; 50 | 51 | bOpcodeFlag[0] = 0; 52 | bOpcodeFlag[1] = 0; 53 | bOpcodeFlag[2] = 0; 54 | bOpcodeFlag[3] = 0; 55 | bOpcodeFlag[4] = 0; 56 | bOpcodeFlag[5] = 0; 57 | bOpcodeFlag[6] = 0; 58 | bOpcodeFlag[7] = 0; 59 | 60 | nSlashPresent= -1; 61 | 62 | strNumber[0] = strNumber[63] = 0; 63 | strOpcode[0] = strOpcode[63] = 0; 64 | } 65 | ~_INSTRUCTION_OPCODE() 66 | { 67 | } 68 | }INSTRUCTION_OPCODE; 69 | 70 | typedef vector INSTRUCTION_LIST; 71 | typedef vector INDEX_INT_LIST; 72 | 73 | class CNikDisassembly 74 | { 75 | INDEX_INT_LIST m_vIndexList[256]; 76 | INSTRUCTION_LIST m_vInstructionList; 77 | 78 | public: 79 | CNikDisassembly(); 80 | virtual ~CNikDisassembly(); 81 | 82 | void CleanUp(); 83 | int ConvertCharToNumber(TCHAR ch); 84 | int DumpTextOpcodeFile(_tstring strFileName); 85 | int DumpSortedOpcodeFile(_tstring strFileName); 86 | int LoadSortedOpcodeFile(_tstring strFileName); 87 | int Fill_OpNumber(INSTRUCTION_OPCODE * pOpcode); 88 | _tstring GetFormattedStr(BYTE * pBuf,int nFlag); 89 | _tstring GetNoString(_tstring strBase, int nNo); 90 | int ExtractString(TCHAR * chBuffer, int nStrLen); 91 | int GetLineOffset(TCHAR * chBuffer, int nStrLen); 92 | int ParserIntructionSetFile(_tstring strFileName); 93 | int ReturnStringNumber(TCHAR * str, int nStringlen); 94 | _tstring DisOpcodeReturns(BYTE * pBuff,int &nOffset); 95 | int RemoveWhiteSpaces(TCHAR * chBuffer, int nStrLen); 96 | int GetPlusValue(INSTRUCTION_OPCODE * pTemp,int nbop); 97 | int LoadOpcodeResource(HINSTANCE hInstance, int nResourceID); 98 | int LoadSortedOpcodeBuffer( BYTE * pBuffer, DWORD dwBufferSize); 99 | INSTRUCTION_OPCODE * SearchNextOpcode(int &nOffset,BYTE * pBuff); 100 | int GetStringSeprator(TCHAR chSep, TCHAR * chBuffer, int nStrLen); 101 | _tstring GetStringWithoutDelimiter(const _tstring &str, int &nOffset); 102 | int FindStringDelimiter(const _tstring &str, TCHAR &ch, int &nStartDelimiter); 103 | _tstring ProcessOpcodeStr(BYTE *pBuf, INSTRUCTION_OPCODE * pInstOpcode, int &nOpcodeBytes); 104 | }; 105 | 106 | -------------------------------------------------------------------------------- /NikPEViewer/ReadMe.txt: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is free and unencumbered software released into the public domain. 3 | 4 | Anyone is free to copy, modify, publish, use, compile, sell, or 5 | distribute this software, either in source code form or as a compiled 6 | binary, for any purpose, commercial or non-commercial, and by any 7 | means. 8 | 9 | In jurisdictions that recognize copyright laws, the author or authors 10 | of this software dedicate any and all copyright interest in the 11 | software to the public domain. We make this dedication for the benefit 12 | of the public at large and to the detriment of our heirs and 13 | successors. We intend this dedication to be an overt act of 14 | relinquishment in perpetuity of all present and future rights to this 15 | software under copyright law. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | For more information, please refer to 26 | *********************************************************************/ 27 | 28 | ======================================================================== 29 | WIN32 APPLICATION : NikPEViewer Project Overview 30 | ======================================================================== 31 | 32 | AppWizard has created this NikPEViewer application for you. 33 | 34 | This file contains a summary of what you will find in each of the files that 35 | make up your NikPEViewer application. 36 | 37 | 38 | NikPEViewer.vcproj 39 | This is the main project file for VC++ projects generated using an Application Wizard. 40 | It contains information about the version of Visual C++ that generated the file, and 41 | information about the platforms, configurations, and project features selected with the 42 | Application Wizard. 43 | 44 | NikPEViewer.cpp 45 | This is the main application source file. 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | AppWizard has created the following resources: 49 | 50 | NikPEViewer.rc 51 | This is a listing of all of the Microsoft Windows resources that the 52 | program uses. It includes the icons, bitmaps, and cursors that are stored 53 | in the RES subdirectory. This file can be directly edited in Microsoft 54 | Visual C++. 55 | 56 | Resource.h 57 | This is the standard header file, which defines new resource IDs. 58 | Microsoft Visual C++ reads and updates this file. 59 | 60 | NikPEViewer.ico 61 | This is an icon file, which is used as the application's icon (32x32). 62 | This icon is included by the main resource file NikPEViewer.rc. 63 | 64 | small.ico 65 | This is an icon file, which contains a smaller version (16x16) 66 | of the application's icon. This icon is included by the main resource 67 | file NikPEViewer.rc. 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | Other standard files: 71 | 72 | StdAfx.h, StdAfx.cpp 73 | These files are used to build a precompiled header (PCH) file 74 | named NikPEViewer.pch and a precompiled types file named StdAfx.obj. 75 | 76 | ///////////////////////////////////////////////////////////////////////////// 77 | Other notes: 78 | 79 | AppWizard uses "TODO:" comments to indicate parts of the source code you 80 | should add to or customize. 81 | 82 | ///////////////////////////////////////////////////////////////////////////// 83 | -------------------------------------------------------------------------------- /NikPEViewer/ResourceWnd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "RESOURCE.H" 11 | 12 | #include "MenuWnd.h" 13 | 14 | using namespace std; 15 | 16 | #pragma comment (lib,"user32.lib") 17 | #pragma comment (lib,"GDI32.lib") 18 | 19 | #ifdef _UNICODE 20 | #define _tstring wstring 21 | #else 22 | #define _tstring string 23 | #endif 24 | 25 | #define CLASS_RESOURCE _T("NIKHIL_RESOURCE") 26 | #define RESOURCE_CAPTION _T("Nik's Resource") 27 | #define MENU_FONT _T("Tahoma") 28 | 29 | typedef struct _ACCELTABLEENTRY 30 | { 31 | WORD fFlags; 32 | WORD wAnsi; 33 | WORD wId; 34 | WORD padding; 35 | }ACCELTABLEENTRY; 36 | 37 | typedef struct _ResourceString { 38 | WORD wLength; 39 | WORD wValueLength; 40 | WORD wType; 41 | }RESOURCESTRING; 42 | 43 | class CNikResource 44 | { 45 | HWND m_hWnd; 46 | HWND m_hListView; 47 | HWND m_hParentWnd; 48 | 49 | BYTE * m_pBuffer; 50 | RESOURCELIST * m_pResource; 51 | 52 | int m_nSize; 53 | int m_nFlag; 54 | 55 | HFONT m_hFont; 56 | 57 | MENU_INFO m_MenuItem; 58 | 59 | CMenuWnd * m_pcMenuWnd; 60 | 61 | vector m_vMenuWndList; 62 | 63 | public: 64 | 65 | void OnSize(WPARAM wParam, LPARAM lParam); 66 | 67 | static void DrawRectArea(HDC hdc, RECT rc,COLORREF col); 68 | 69 | static int CreateMenuList(MENU_INFO * pMenu, int nOffset, int nSize, BYTE *); 70 | 71 | void CreateListViewWindow(); 72 | 73 | int CreateStringWindows(RESOURCELIST * pRes); 74 | 75 | int CreateVersionWindows(RESOURCELIST * pRes); 76 | 77 | int CreateAccelaratorWindows(RESOURCELIST * pRes); 78 | 79 | int CreateMessageWindows(RESOURCELIST * pRes); 80 | 81 | int CreateMenuWindows(RESOURCELIST * pRes); 82 | 83 | void CreateMenuItemsWindow(int nNo); 84 | 85 | void CreateMenuRectSize(); 86 | 87 | void DrawMenuItems(HDC hdc); 88 | 89 | BOOL InitStringListView(HWND hWndListView); 90 | 91 | BOOL InitVersionView(HWND hWndListView); 92 | 93 | BOOL InitMessageView(HWND hWndListView); 94 | 95 | BOOL InitAccelaratorListView(HWND hWndListView); 96 | 97 | void OnLbuttonDown(WPARAM wParam, LPARAM lParam); 98 | void OnLbuttonUP(WPARAM wParam, LPARAM lParam); 99 | void OnMouseMove(WPARAM wParam, LPARAM lParam); 100 | 101 | CNikResource() 102 | { 103 | m_hWnd = NULL; 104 | m_hListView = NULL; 105 | m_hParentWnd = NULL; 106 | m_hFont = NULL; 107 | m_nFlag = 0; 108 | m_pResource = NULL; 109 | m_pcMenuWnd = NULL; 110 | m_pBuffer = NULL; 111 | } 112 | 113 | ~CNikResource() 114 | { 115 | if(m_hFont) 116 | DeleteObject(m_hFont); 117 | 118 | //UnregisterClass(CLASS_RESOURCE 119 | // , GetWindowInstance(m_hParentWnd)); 120 | 121 | CMenuWnd * pTemp; 122 | for(int i=0;i<(int)m_vMenuWndList.size();i++) 123 | { 124 | pTemp = m_vMenuWndList.at(i); 125 | if(pTemp->GethWnd()) 126 | DestroyWindow(pTemp->GethWnd()); 127 | if(pTemp == m_pcMenuWnd) 128 | m_pcMenuWnd = NULL; 129 | delete pTemp; 130 | } 131 | m_vMenuWndList.clear(); 132 | 133 | if(m_pcMenuWnd) 134 | delete m_pcMenuWnd; 135 | 136 | m_MenuItem.m_vMenuList.clear(); 137 | } 138 | 139 | void SetParentHwnd(HWND hwnd) 140 | { 141 | m_hParentWnd = hwnd; 142 | } 143 | HWND GetParenthWnd() 144 | { 145 | return m_hParentWnd; 146 | } 147 | 148 | void SetFlag(int nFlag) 149 | { 150 | m_nFlag = nFlag; 151 | } 152 | 153 | void SethWnd(HWND hwnd) 154 | { 155 | m_hWnd = hwnd; 156 | } 157 | HWND GethWnd() 158 | { 159 | return m_hWnd; 160 | } 161 | 162 | void ShowWindowPosition( int nFlag 163 | , POINT pt ) 164 | { 165 | if(m_hWnd) 166 | { 167 | if(nFlag) 168 | { 169 | RECT rc; 170 | GetClientRect( GetParent( m_hWnd ), &rc ); 171 | int nWidth = rc.right - rc.left; 172 | int nHeight = rc.bottom - rc.top; 173 | SetWindowPos( m_hWnd, HWND_TOP 174 | , pt.x+(nWidth/4) , pt.y, nWidth/2, nHeight/2, SWP_SHOWWINDOW ); 175 | } 176 | else 177 | SetWindowPos( m_hWnd, HWND_TOP, 0 , 0, 0, 0 178 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 179 | } 180 | } 181 | 182 | static int RegisterResourceclass(HINSTANCE hInstance); 183 | 184 | static LRESULT CALLBACK ResourceWndProc(HWND hwnd, UINT uMsg, 185 | WPARAM wParam, LPARAM lParam); 186 | 187 | HWND CreateResourceWindow(HWND hParent); 188 | 189 | HWND SetResourceData(HWND hParent, RESOURCELIST * pTemp 190 | , BYTE * pBuffer, int nFlag); 191 | }; -------------------------------------------------------------------------------- /NikPEViewer/DialogWnd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "RESOURCE.H" 11 | 12 | using namespace std; 13 | 14 | #pragma comment (lib,"user32.lib") 15 | #pragma comment (lib,"GDI32.lib") 16 | 17 | #ifdef _UNICODE 18 | #define _tstring wstring 19 | #else 20 | #define _tstring string 21 | #endif 22 | 23 | #define CLASS_DIALOG _T("NIKHIL_DIALOG") 24 | #define DIALOG_CAPTION _T("Resource dialog viewer") 25 | 26 | typedef struct _DIALOGCONTROL 27 | { 28 | DWORD m_lStyle; 29 | DWORD m_lExStyle; 30 | WORD m_NoOfItems; 31 | WORD m_wX; 32 | WORD m_wY; 33 | WORD m_wCX; 34 | WORD m_wCY; 35 | WORD m_wControlID; 36 | WORD m_wPointSize; 37 | DWORD m_dwHelpID; 38 | WORD m_wWeight; 39 | BYTE m_bItalic; 40 | BYTE m_bCharset; 41 | DWORD m_dwIsExtend; 42 | int m_nFlag; 43 | 44 | RECT m_rRect; 45 | 46 | LOGFONT m_lf; 47 | 48 | HWND m_hWnd; 49 | 50 | WCHAR m_strMenuName[1024]; 51 | WCHAR m_strClassName[1024]; 52 | WCHAR m_strCaption[1024]; 53 | WCHAR m_strFontName[1024]; 54 | 55 | _DIALOGCONTROL() 56 | { 57 | m_lStyle = 0; 58 | m_lExStyle = 0; 59 | m_NoOfItems = 0; 60 | m_wX = 0; 61 | m_wX = 0; 62 | m_wY = 0; 63 | m_wCX = 0; 64 | m_wCY = 0; 65 | m_wControlID = 0; 66 | m_wPointSize = 0; 67 | m_dwHelpID = 0; 68 | m_wWeight = 0; 69 | m_bItalic = 0; 70 | m_bCharset = 0; 71 | m_dwIsExtend = 0; 72 | m_nFlag = 0; 73 | m_hWnd = NULL; 74 | 75 | m_strMenuName[0] = NULL; 76 | m_strClassName[0] = NULL; 77 | m_strCaption[0] = NULL; 78 | m_strFontName[0] = NULL; 79 | m_strMenuName[1023] = NULL; 80 | m_strClassName[1023] = NULL; 81 | m_strCaption[1023] = NULL; 82 | m_strFontName[1023] = NULL; 83 | 84 | memset(&m_rRect,0,sizeof(RECT)); 85 | 86 | memset(&m_lf,0,sizeof(LOGFONT)); 87 | } 88 | 89 | ~_DIALOGCONTROL() 90 | { 91 | } 92 | }DIALOGCONTROL; 93 | 94 | class CNikDialog 95 | { 96 | HWND m_hWnd; 97 | HWND m_hParentWnd; 98 | HWND m_hDlgWnd; 99 | 100 | BYTE * m_pBuffer; 101 | int m_nPos; 102 | 103 | RECT m_rRect; 104 | 105 | HFONT m_hFont; 106 | 107 | POINT m_ptStartPos; 108 | POINT m_ptEndPos; 109 | 110 | vector m_vDialogList; 111 | 112 | public: 113 | 114 | void OnSize(WPARAM wParam, LPARAM lParam); 115 | 116 | int MakeDialogList(RESOURCELIST * pRes); 117 | 118 | void DrawDialogBox(HDC hdc); 119 | 120 | void DrawDialogBorder(HDC hdc); 121 | 122 | int SetCursorShape(POINT pt); 123 | 124 | int DrawRectMarkers(HDC hdc, RECT rc, POINT *pt, int nFlag); 125 | 126 | void OnLbuttonDown(WPARAM wParam, LPARAM lParam); 127 | void OnLbuttonUP(WPARAM wParam, LPARAM lParam); 128 | void OnMouseMove(WPARAM wParam, LPARAM lParam); 129 | 130 | CNikDialog() 131 | { 132 | m_hWnd = NULL; 133 | m_hParentWnd = NULL; 134 | m_hFont = NULL; 135 | m_hDlgWnd = NULL; 136 | 137 | m_nPos = 0; 138 | m_ptEndPos.x = 0; 139 | m_ptEndPos.y = 0; 140 | m_ptStartPos.x = 0; 141 | m_ptStartPos.y = 0; 142 | 143 | memset(&m_rRect,0,sizeof(RECT)); 144 | } 145 | 146 | ~CNikDialog() 147 | { 148 | if(m_hFont) 149 | DeleteObject(m_hFont); 150 | 151 | UnregisterClass(CLASS_DIALOG, GetWindowInstance(m_hParentWnd)); 152 | 153 | m_vDialogList.clear(); 154 | } 155 | 156 | void SetParentHwnd(HWND hwnd) 157 | { 158 | m_hParentWnd = hwnd; 159 | } 160 | HWND GetParenthWnd() 161 | { 162 | return m_hParentWnd; 163 | } 164 | 165 | void SethWnd(HWND hwnd) 166 | { 167 | m_hWnd = hwnd; 168 | } 169 | HWND GethWnd() 170 | { 171 | return m_hWnd; 172 | } 173 | 174 | void DestroyDialogBox() 175 | { 176 | if(m_hDlgWnd 177 | && IsWindow(m_hDlgWnd)) 178 | { 179 | DestroyWindow(m_hDlgWnd); 180 | m_hDlgWnd = NULL; 181 | } 182 | } 183 | 184 | void ShowWindowPosition( int nFlag 185 | , POINT pt ) 186 | { 187 | if(m_hWnd) 188 | { 189 | if(nFlag) 190 | { 191 | RECT rc; 192 | GetClientRect( GetParent( m_hWnd ), &rc ); 193 | int nWidth = rc.right - rc.left; 194 | int nHeight = rc.bottom - rc.top; 195 | SetWindowPos( m_hWnd, HWND_TOP 196 | , pt.x+(nWidth/4) , pt.y, nWidth/2, nHeight/2, SWP_SHOWWINDOW ); 197 | } 198 | else 199 | SetWindowPos( m_hWnd, HWND_TOP, 0 , 0, 0, 0 200 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 201 | } 202 | } 203 | 204 | HWND CreateDialogWindow(HWND hParent); 205 | 206 | HWND SetDialogData( HWND hParent 207 | , RESOURCELIST * pRes 208 | , BYTE * pBuffer 209 | , int nFlag); 210 | 211 | static void DrawLineRect(HDC hdc, RECT rc 212 | , COLORREF cLineCol, int nLineWidth); 213 | static void DrawRectArea(HDC hdc, RECT rc,COLORREF col); 214 | 215 | static int RegisterDialogclass(HINSTANCE hInstance); 216 | 217 | static LRESULT CALLBACK ResourceWndProc(HWND hwnd, UINT uMsg, 218 | WPARAM wParam, LPARAM lParam); 219 | 220 | static INT_PTR CALLBACK DialogWndProc(HWND hwnd, UINT uMsg, 221 | WPARAM wParam, LPARAM lParam); 222 | }; -------------------------------------------------------------------------------- /NikPEViewer/NikDisassembly.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define UM_SETBREAKPOINT WM_USER + 1900 5 | 6 | #define R_M_OPCODE 1 7 | #define R_M8_OPCODE 2 8 | #define D8_OPCODE 3 9 | #define D32_OPCODE 4 10 | #define R32_OPCODE 5 11 | #define R8_OPCODE 6 12 | #define IMM8_OPCODE 7 13 | #define IMM32_OPCODE 8 14 | #define REL8_OPCODE 9 15 | #define REL32_OPCODE 10 16 | #define SREG_OPCODE 11 17 | #define EAX_OPCODE 12 18 | #define AX_OPCODE 13 19 | #define AL_OPCODE 14 20 | #define MOFFS32_OPCODE 15 21 | #define D16_OPCODE 16 22 | #define R16_OPCODE 17 23 | #define IMM16_OPCODE 18 24 | #define REL16_OPCODE 19 25 | #define MOFFS8_OPCODE 20 26 | #define M32FP_OPCODE 21 27 | #define M64FP_OPCODE 22 28 | #define M80FP_OPCODE 23 29 | #define M16INT_OPCODE 24 30 | #define M32INT_OPCODE 25 31 | #define M64INT_OPCODE 26 32 | #define M16_32_OPCODE 27 33 | #define M16_16_OPCODE 28 34 | #define M32_32_OPCODE 29 35 | #define M2BYTE_OPCODE 30 36 | #define M94_108_OPCODE 31 37 | #define XMM2_M32_OPCODE 32 38 | #define XMM2_M128_OPCODE 33 39 | #define XMM2_M64_OPCODE 34 40 | #define MM2_M64_OPCODE 35 41 | #define MM2_M32_OPCODE 36 42 | #define XMM1_OPCODE 37 43 | #define MM1_OPCODE 38 44 | #define XMM_OPCODE 39 45 | #define MM_OPCODE 40 46 | 47 | typedef struct tagTHREEPART 48 | { 49 | BYTE rm : 3; 50 | BYTE reg : 3; 51 | BYTE mod : 2; 52 | }THREEPART; 53 | 54 | typedef struct _INSTRUCTION_OPCODE 55 | { 56 | short int bOpNumber[5]; 57 | TCHAR strNumber[64]; 58 | TCHAR strOpcode[64]; 59 | int nSlashPresent; 60 | int nNoOpcodeBytes; 61 | BYTE bOpcodeFlag[8]; 62 | vector<_tstring> strList; 63 | 64 | public: 65 | _INSTRUCTION_OPCODE() 66 | { 67 | bOpNumber[0] = -1; 68 | bOpNumber[1] = -1; 69 | bOpNumber[2] = -1; 70 | bOpNumber[3] = -1; 71 | bOpNumber[4] = -1; 72 | 73 | bOpcodeFlag[0] = 0; 74 | bOpcodeFlag[1] = 0; 75 | bOpcodeFlag[2] = 0; 76 | bOpcodeFlag[3] = 0; 77 | bOpcodeFlag[4] = 0; 78 | bOpcodeFlag[5] = 0; 79 | bOpcodeFlag[6] = 0; 80 | bOpcodeFlag[7] = 0; 81 | 82 | nSlashPresent = -1; 83 | 84 | nNoOpcodeBytes = 0; 85 | 86 | strNumber[0] = strNumber[63] = 0; 87 | strOpcode[0] = strOpcode[63] = 0; 88 | } 89 | ~_INSTRUCTION_OPCODE() 90 | { 91 | } 92 | 93 | void operator=(_INSTRUCTION_OPCODE &stInstruct) 94 | { 95 | memcpy( bOpcodeFlag, &stInstruct.bOpcodeFlag, sizeof(bOpcodeFlag)); 96 | memcpy( bOpNumber, &stInstruct.bOpNumber, sizeof(bOpNumber)); 97 | memcpy( strNumber, &stInstruct.strNumber, sizeof(strNumber)); 98 | memcpy( strOpcode, &stInstruct.strOpcode, sizeof(strOpcode)); 99 | 100 | nSlashPresent = stInstruct.nSlashPresent; 101 | nNoOpcodeBytes = stInstruct.nNoOpcodeBytes; 102 | 103 | strList = stInstruct.strList; 104 | } 105 | }INSTRUCTION_OPCODE; 106 | 107 | typedef struct _BREAK_POINT_INFO 108 | { 109 | BYTE m_chBreakData; 110 | DWORD m_dwAdress; 111 | }BREAK_POINT_INFO; 112 | 113 | typedef vector INSTRUCTION_LIST; 114 | typedef vector INDEX_INT_LIST; 115 | 116 | class CNikDisassembly 117 | { 118 | INSTRUCTION_OPCODE *m_pOpcodeList_OF[256]; 119 | int m_nOpcodeList_OF[256]; 120 | int m_nOpcodeList[256]; 121 | INSTRUCTION_OPCODE *m_pIntOpcodeList[256]; 122 | INDEX_INT_LIST m_vIndexList[256]; 123 | INSTRUCTION_LIST m_vInstructionList; 124 | 125 | public: 126 | CNikDisassembly(); 127 | virtual ~CNikDisassembly(); 128 | 129 | void CleanUp(); 130 | void Create_RM_Mode(); 131 | void Create_SIB_Mode(); 132 | int ConvertCharToNumber(TCHAR ch); 133 | int Get_RM_Mode_No_Bytes( BYTE * pBuffer ); 134 | int DumpTextOpcodeFile(_tstring strFileName); 135 | int DumpSortedOpcodeFile(_tstring strFileName); 136 | int LoadSortedOpcodeFile(_tstring strFileName); 137 | int Fill_OpNumber(INSTRUCTION_OPCODE * pOpcode); 138 | _tstring GetFormattedStr(BYTE * pBuf,int nFlag); 139 | _tstring GetNoString(_tstring strBase, int nNo); 140 | int ExtractString(TCHAR * chBuffer, int nStrLen); 141 | int GetLineOffset(TCHAR * chBuffer, int nStrLen); 142 | int ParserIntructionSetFile(_tstring strFileName); 143 | int ReturnStringNumber(TCHAR * str, int nStringlen); 144 | _tstring DisOpcodeReturns(BYTE * pBuff,int &nOffset); 145 | int RemoveWhiteSpaces(TCHAR * chBuffer, int nStrLen); 146 | int GetPlusValue(INSTRUCTION_OPCODE * pTemp,int nbop); 147 | int LoadOpcodeResource(HINSTANCE hInstance, int nResourceID); 148 | int LoadSortedOpcodeBuffer( BYTE * pBuffer, DWORD dwBufferSize); 149 | INSTRUCTION_OPCODE * SearchNextOpcode(int &nOffset,BYTE * pBuff); 150 | int GetStringSeprator(TCHAR chSep, TCHAR * chBuffer, int nStrLen); 151 | _tstring GetStringWithoutDelimiter(const _tstring &str, int &nOffset); 152 | int FindStringDelimiter(const _tstring &str, TCHAR &ch, int &nStartDelimiter); 153 | _tstring ProcessOpcodeStr(BYTE *pBuf, INSTRUCTION_OPCODE * pInstOpcode 154 | , int &nOpcodeBytes, _tstring strPix, int nFlag); 155 | }; 156 | 157 | -------------------------------------------------------------------------------- /NikPEViewer/NikDisassemblyWin.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #pragma once 4 | 5 | #include "NikDisAssembly.h" 6 | 7 | #define EDITOR_FONT _T("Courier New") 8 | #define TES_STRING _T("ABCDEFGHIJKLMNOPQRSTWXYZ") 9 | 10 | class CNikDisassemblyWin 11 | { 12 | HBITMAP m_hBitmap; 13 | HFONT m_hFont; 14 | LOGFONT m_lf; 15 | RECT m_rDrawRect; 16 | 17 | int m_nLineHeight; 18 | int m_nMaxCharWidth; 19 | int m_nAveCharWidth; 20 | int m_nOffsetLineNo; 21 | 22 | int m_nListRectNo; 23 | int m_nListRectStart; 24 | RECT m_rListViewRect[5]; 25 | 26 | TCHAR * m_pchDisCodeBuffer; 27 | 28 | DWORD m_dwFocusLine; 29 | DWORD m_dwActiveLine; 30 | 31 | vector m_vBreakPoints; 32 | vector m_vDisNewLineOffset; 33 | 34 | vector m_vDisOpcodeOffset; 35 | 36 | HWND m_hWnd; 37 | HANDLE m_hThread; 38 | 39 | BOOL m_bIsDisplayBinary; 40 | BOOL m_bIsThreadRunning; 41 | 42 | CNikDisassembly * m_pNikDisassembly; 43 | EXECUTABLE_INFO * m_pstExecutableInfo; 44 | 45 | public: 46 | CNikDisassemblyWin(); 47 | virtual ~CNikDisassemblyWin(); 48 | 49 | RECT GetDrawRectangle() 50 | { 51 | return m_rDrawRect; 52 | } 53 | 54 | HWND GetWindowHandle() 55 | { 56 | return m_hWnd; 57 | } 58 | 59 | int GetOffsetLineNo() 60 | { 61 | return m_nOffsetLineNo; 62 | } 63 | 64 | void SetOffsetLineNo( int nDisOffsetLineNo ) 65 | { 66 | m_nOffsetLineNo = nDisOffsetLineNo; 67 | SetScrollBar( m_hWnd ); 68 | } 69 | 70 | void ToggleBinaryData() 71 | { 72 | if(FALSE == m_bIsDisplayBinary) 73 | m_bIsDisplayBinary = TRUE; 74 | else 75 | m_bIsDisplayBinary = FALSE; 76 | 77 | InvalidateRect( m_hWnd, NULL, TRUE ); 78 | UpdateWindow( m_hWnd ); 79 | } 80 | 81 | BOOL IsLineVisible( int nDisOffsetLineNo ) 82 | { 83 | RECT rc; 84 | GetClientRect( m_hWnd, &rc ); 85 | int nLineInPage = rc.bottom / m_nLineHeight; 86 | 87 | if((nDisOffsetLineNo >= m_nOffsetLineNo) 88 | && (nDisOffsetLineNo < (m_nOffsetLineNo+nLineInPage))) 89 | { 90 | return TRUE; 91 | } 92 | 93 | return FALSE; 94 | } 95 | 96 | vector &GetBreakPointList() 97 | { 98 | return m_vBreakPoints; 99 | } 100 | 101 | BOOL IsDisThreadRunning() 102 | { 103 | return m_bIsThreadRunning; 104 | } 105 | 106 | void SetActiveAddress( DWORD dwActiveAddress ) 107 | { 108 | m_dwActiveLine = CovertAddressToLineNo( dwActiveAddress ); 109 | m_dwFocusLine = m_dwActiveLine; 110 | } 111 | 112 | int CovertAddressToLineNo( DWORD dwAddress ) 113 | { 114 | for(int i=0; i<(int)m_vDisOpcodeOffset.size()-1; i++) 115 | { 116 | if(dwAddress == (DWORD)m_vDisOpcodeOffset.at(i)) 117 | return i; 118 | else if((dwAddress >= (DWORD)m_vDisOpcodeOffset.at(i)) 119 | && (dwAddress < (DWORD)m_vDisOpcodeOffset.at(i+1))) 120 | return i; 121 | } 122 | 123 | return -1; 124 | } 125 | 126 | int SetBreakPoint( DWORD dwAddress ) 127 | { 128 | int i = CovertAddressToLineNo( dwAddress ); 129 | 130 | if(i >= 0) 131 | { 132 | m_vBreakPoints.push_back( i ); 133 | return TRUE; 134 | } 135 | 136 | return FALSE; 137 | } 138 | 139 | int UnSetBreakPoint( DWORD dwAddress ) 140 | { 141 | int ii = CovertAddressToLineNo( dwAddress ); 142 | 143 | if(ii >= 0) 144 | { 145 | for(int i=0; i<(int)m_vBreakPoints.size(); i++) 146 | { 147 | if(ii == m_vBreakPoints.at(i)) 148 | { 149 | m_vBreakPoints.erase(m_vBreakPoints.begin() + i); 150 | return TRUE; 151 | } 152 | } 153 | } 154 | 155 | return FALSE; 156 | } 157 | 158 | int StopDisAssemblyThread(); 159 | int ShowPEDisassemblyCode(); 160 | void SetScrollBar(HWND hWnd); 161 | void SetLogFont(LOGFONT &lf); 162 | void DrawListViewTop( HDC hdc ); 163 | DWORD GetLineAddress( POINT pt ); 164 | void CreateEditorFont( HDC hdc ); 165 | void CalculateLineHeight(HDC hdc); 166 | void PaintWindow( HDC hdc, RECT rc ); 167 | int DrawBreakPoints(HDC hdc, RECT rc); 168 | int DrawActivePoint(HDC hdc, RECT rc); 169 | void SetDisasmBuffer( _tstring strBuffer ); 170 | int DumpAssemblyCode( _tstring strFileName ); 171 | void DrawListViewBoders( HDC hdc , RECT rc ); 172 | void OnKeyDown( WPARAM wParam, LPARAM lParam); 173 | void OnMouseMove( WPARAM wParam, LPARAM lParam ); 174 | void OnLButtonUp( WPARAM wParam, LPARAM lParam ); 175 | _tstring GetImportFunctionName( DWORD dwAddress ); 176 | void OnLButtonDown( WPARAM wParam, LPARAM lParam ); 177 | void OnScrollBar(HWND hWnd, int nFlag, WPARAM wParam); 178 | static ATOM NikDissembeRegisterClass(HINSTANCE hInstance); 179 | static DWORD WINAPI DisAssemblyThreadProc( LPVOID lpParam ); 180 | int DrawSelectionRect( HDC hdc, RECT rc, COLORREF cRect, int nItemNo ); 181 | int DrawDisassemblyData( HDC hdc, RECT rc, TCHAR * pBuffer, int nOffset); 182 | 183 | static LRESULT CALLBACK NikDissembeWndProc(HWND hWnd, UINT message 184 | , WPARAM wParam, LPARAM lParam); 185 | HWND NikDissembeInitInstance( HWND hWndParent, RECT rc, _tstring strFileName 186 | , EXECUTABLE_INFO * pstExecutableInfo, CNikDisassembly * pNikDisassembly); 187 | }; 188 | 189 | -------------------------------------------------------------------------------- /NikPEViewer/PEBinaryFile.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define TES_STRING _T("ABCDEFGHIJKLMNOPQRSTWXYZ") 5 | #define EDITOR_FONT _T("Courier New") 6 | #define HEADER_ADD _T("Offset") 7 | #define LEFT_WINDOW_BAR 20 8 | #define EDITOR_TAB_SIZE 4 9 | #define BINARY_CHAR_ROW 0x10 10 | 11 | #define BINARY_HEX 1 12 | #define BINARY_TEXT 2 13 | #define BINARY_OCTAL 3 14 | #define BINARY_DECIMAL 4 15 | #define BINARY_BINARY 5 16 | 17 | #define SIDE_BAR_COLOR RGB(232,232,232) 18 | #define LINE_NUMBER_COLOR RGB(0,208,0) 19 | #define WINDOW_BACKGROUND_COLOR RGB(255,255,255) 20 | #define BIN_SELECTION_COLOR RGB(50, 95, 170) 21 | #define TEXT_SELECTION_COLOR RGB(200, 200, 200) 22 | 23 | typedef struct _TEXT_SELECT_RECT 24 | { 25 | int m_nEnd; 26 | int m_nStart; 27 | RECT m_rSelect; 28 | 29 | _TEXT_SELECT_RECT() 30 | { 31 | ResetSelection(); 32 | } 33 | 34 | void ResetSelection() 35 | { 36 | m_nEnd = -1; 37 | m_nStart = -1; 38 | memset( &m_rSelect, 0, sizeof(RECT)); 39 | } 40 | 41 | }TEXT_SELECT_RECT; 42 | 43 | class CBinaryEditor 44 | { 45 | BYTE * m_pbBinBuffer; 46 | 47 | RECT m_rDrawArea; 48 | RECT m_rACSIIRect[3]; 49 | 50 | LOGFONT m_lf; 51 | HFONT m_hFont; 52 | 53 | HBITMAP m_hBitmap; 54 | 55 | int m_nLineHeight; 56 | int m_nMaxCharLen; 57 | int m_nBinarySize; 58 | int m_nLineNoType; 59 | int m_nASCIIOffset; 60 | int m_nLineNumbers; 61 | int m_nTotalLineNo; 62 | int m_nBufferOffset; 63 | int m_nTabsSizes[2]; 64 | int m_nLeftBoundary; 65 | int m_nAveCharWidth; 66 | int m_nSelectionEnd; 67 | int m_nBinRowNumbers; 68 | int m_nSelectionStart; 69 | int m_nLineNumberWidth; 70 | 71 | BOOL m_bLineNumberEnable; 72 | BOOL m_bBinHeaderEnable; 73 | 74 | TEXT_SELECT_RECT m_stSelectRect[3]; 75 | 76 | public: 77 | 78 | void SetBinBuffer( BYTE * pbBuffer 79 | , int nBufferSize 80 | , int nBufferOffset ) 81 | { 82 | m_pbBinBuffer = pbBuffer; 83 | m_nBinarySize = nBufferSize; 84 | m_nTotalLineNo = m_nBinarySize / m_nBinRowNumbers; 85 | 86 | SetBufferOffset( nBufferOffset ); 87 | } 88 | 89 | void SetBufferOffset( int nBufferOffset ) 90 | { 91 | m_nBufferOffset = (nBufferOffset/m_nBinRowNumbers) * m_nBinRowNumbers; 92 | } 93 | 94 | BYTE * GetBinBuffer() 95 | { 96 | return m_pbBinBuffer; 97 | } 98 | 99 | RECT GetDrawRect() 100 | { 101 | return m_rDrawArea; 102 | } 103 | void SetDrawRect(RECT rc) 104 | { 105 | m_rDrawArea = rc; 106 | } 107 | 108 | BOOL IsLinenumberEnable() 109 | { 110 | return m_bLineNumberEnable; 111 | } 112 | 113 | BOOL IsBinHeaderEnable() 114 | { 115 | return m_bBinHeaderEnable; 116 | } 117 | 118 | int GetBinRowNumbers() 119 | { 120 | return m_nBinRowNumbers; 121 | } 122 | 123 | void SetBinRowNumbers( int nBinRowNumbers ) 124 | { 125 | m_nBinRowNumbers = nBinRowNumbers; 126 | } 127 | 128 | void SetSelection(int nStart=-1, int nEnd=-1); 129 | 130 | BOOL IsBinSelection() 131 | { 132 | if((m_nSelectionEnd == m_nSelectionStart) 133 | || (m_nSelectionEnd < 0) 134 | || (m_nSelectionStart < 0)) 135 | { 136 | //m_nSelectionEnd = -1; 137 | //m_nSelectionStart = -1; 138 | return FALSE; 139 | } 140 | 141 | return TRUE; 142 | } 143 | 144 | void GetEditorWindowSize(int &nWidth,int &nHeight) 145 | { 146 | nWidth = m_rDrawArea.right - m_rDrawArea.left; 147 | nHeight = m_rDrawArea.bottom - m_rDrawArea.top; 148 | } 149 | 150 | HBITMAP GetEditorBitmap() 151 | { 152 | return m_hBitmap; 153 | } 154 | void SetEditorBitmap(HBITMAP hBitmap = NULL) 155 | { 156 | if(m_hBitmap) 157 | DeleteObject(m_hBitmap); 158 | 159 | m_hBitmap = hBitmap; 160 | } 161 | 162 | CBinaryEditor( HWND hWnd ); 163 | virtual ~CBinaryEditor(); 164 | 165 | virtual void CalculateBinRowNumber(); 166 | virtual void CreateEditorFont( HDC hdc ); 167 | virtual void CalculateCharLen( HDC hdc ); 168 | virtual void CalculateLineHeight( HDC hdc ); 169 | 170 | virtual void PaintWindow( HDC hdc ); 171 | virtual void DrawBinEditor( HDC hdc ); 172 | virtual void DrawBinaryHeader( HDC hdc); 173 | virtual void DrawBinForground( HDC hdc ); 174 | virtual void DrawTextSelection( HDC hdc ); 175 | virtual void DrawBinBackground( HDC hdc ); 176 | virtual void DrawBinaryLineNumber(HDC hdc); 177 | virtual void DrawBinaryData( HDC hdc, BYTE * pbBinBuffer, RECT rc); 178 | virtual void DrawLineBinary(HDC hdc,BYTE * pBuffer 179 | , int nOffsetX, int nOffsetY, int nLineOffset); 180 | 181 | virtual int GetBinOffsetfromPt(POINT pt); 182 | 183 | void SetScrollBar( HWND hWnd ); 184 | void OnScrollBar(HWND hWnd, int nFlag, WPARAM wParam); 185 | 186 | virtual POINT GetBinPtfromOffset( int nOffset , int nASCIIOffset ); 187 | 188 | static void DrawRectArea( HDC hdc, RECT rc, COLORREF col ); 189 | }; 190 | 191 | ///---------------------------- 192 | 193 | class CNikPEBinaryViewer 194 | { 195 | HWND m_hWnd; 196 | HINSTANCE m_hInstance; 197 | CBinaryEditor * m_pBinaryEditor; 198 | 199 | public: 200 | CNikPEBinaryViewer(); 201 | virtual ~CNikPEBinaryViewer(); 202 | 203 | HWND GetWindowHandle() 204 | { 205 | return m_hWnd; 206 | } 207 | 208 | CBinaryEditor * GetBinaryEditor() 209 | { 210 | return m_pBinaryEditor; 211 | } 212 | 213 | int SetBinaryData(BYTE *, int ); 214 | HWND CreateBinaryViewer(HINSTANCE , HWND , RECT , _tstring ); 215 | static LRESULT CALLBACK ToolChildWndProc( HWND hWnd 216 | , UINT uMsg 217 | , WPARAM wParam 218 | , LPARAM lParam ); 219 | }; -------------------------------------------------------------------------------- /NikPEViewer/EditorBitmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "RESOURCE.H" 15 | 16 | using namespace std; 17 | using namespace Gdiplus; 18 | 19 | #pragma comment (lib,"user32.lib") 20 | #pragma comment (lib,"GDI32.lib") 21 | #pragma comment (lib,"shell32.lib") 22 | #pragma comment (lib,"Comdlg32.lib") 23 | #pragma comment (lib,"Gdiplus.lib") 24 | 25 | #ifdef _UNICODE 26 | #define _tstring wstring 27 | #else 28 | #define _tstring string 29 | #endif 30 | 31 | #define CLASS_NAME _T("BITMAP_EDITOR") 32 | #define WINDOWS_CAPTION _T("PE Bitmap viewer") 33 | #define NEW_LINE_CHAR _T('\n') 34 | #define NEW_LINE_STR _T("\n") 35 | #define NULL_CHAR _T('\0') 36 | #define BITMAP_FONT _T("Courier New") 37 | 38 | #define MAX_FILESIZE 1024 39 | #define LEFT_MARGIN 20 40 | 41 | #define LINE_NUMBER_COLOR RGB(0,208,0) 42 | #define SIDE_BAR_COLOR RGB(232,232,232) 43 | #define WINDOW_BACK_COLOR RGB(255,255,255) 44 | 45 | #define BITMAP_DATA 1 46 | #define ICON_DATA 2 47 | #define CURSOR_DATA 3 48 | 49 | typedef struct _ICONDIR{ 50 | WORD idReverved; 51 | WORD idType; 52 | WORD idCount; 53 | }ICONDIR; 54 | 55 | typedef struct _ICON{ 56 | BYTE bWidth; 57 | BYTE bHeight; 58 | BYTE bColorCount; 59 | BYTE bReserved; 60 | WORD wPlanes; 61 | WORD wBitCount; 62 | DWORD dwBytesInRes; 63 | DWORD dwImageOffset; 64 | }ICON; 65 | 66 | class CNikBitmapEditor 67 | { 68 | HWND m_hWnd; 69 | HWND m_hParentWnd; 70 | 71 | RECT m_rDrawArea; 72 | RECT m_rRectSelection; 73 | 74 | HFONT m_hFont; 75 | 76 | int m_nSelectionType; 77 | int m_nLeftBoundary; 78 | int m_nOffsetX; 79 | int m_nOffsetY; 80 | 81 | BOOL m_bIsLButtonDown; 82 | BOOL m_bKeyDown[256]; 83 | 84 | POINT m_ptStartSelection; 85 | POINT m_ptEndSelection; 86 | 87 | BITMAPINFOHEADER m_stBitmapHeader; 88 | 89 | HBITMAP m_hBitmap; 90 | HBITMAP m_hImageBitmap; 91 | 92 | LOGFONT m_lf; 93 | 94 | public: 95 | 96 | CNikBitmapEditor() 97 | { 98 | m_hWnd = NULL; 99 | m_hFont = NULL; 100 | 101 | m_nOffsetX = 0; 102 | m_nOffsetY = 0; 103 | m_nSelectionType = 0; 104 | m_nLeftBoundary = LEFT_MARGIN; 105 | 106 | m_hImageBitmap = NULL; 107 | 108 | m_bIsLButtonDown = false; 109 | 110 | m_ptStartSelection.x = -1; 111 | m_ptStartSelection.y = -1; 112 | m_ptEndSelection.x = -1; 113 | m_ptEndSelection.y = -1; 114 | 115 | memset(&m_lf,0,sizeof(LOGFONT)); 116 | 117 | _tcscpy_s(m_lf.lfFaceName,sizeof(m_lf.lfFaceName)/sizeof(TCHAR),BITMAP_FONT); 118 | m_lf.lfClipPrecision = 2; 119 | m_lf.lfHeight = -20; 120 | m_lf.lfQuality = 1; 121 | m_lf.lfWeight = 400; 122 | m_lf.lfOutPrecision = 3; 123 | m_lf.lfPitchAndFamily = 34; 124 | 125 | m_hBitmap = NULL; 126 | 127 | memset(&m_rDrawArea,0,sizeof(RECT)); 128 | memset(m_bKeyDown,0,sizeof(m_bKeyDown)); 129 | } 130 | 131 | ~CNikBitmapEditor() 132 | { 133 | if(m_hFont) 134 | DeleteObject(m_hFont); 135 | 136 | if(m_hBitmap) 137 | DeleteObject(m_hBitmap); 138 | 139 | if(m_hImageBitmap) 140 | DeleteObject(m_hImageBitmap); 141 | } 142 | 143 | void ProcessKeyMessages(DWORD dwKeycode,int nFlag); 144 | 145 | void DrawBitmapEditor(HDC hdc, RECT rPaint); 146 | 147 | void DrawRectArea(HDC hdc, RECT rc, COLORREF col); 148 | void DrawLineRect(HDC hdc, RECT rc); 149 | 150 | BYTE * ReadBinaryFile(_tstring str, DWORD &dwFileSize); 151 | 152 | void SetScrollBar(); 153 | void OnScrollBar(int nFlag, WPARAM wParam); 154 | 155 | int CreateBitmap(IStream * pIStream, DWORD dwSize); 156 | 157 | void DrawSideBar(HDC hdc); 158 | 159 | void OnSize(WPARAM wParam, LPARAM lParam); 160 | 161 | void OnLbuttonDown(WPARAM wParam, LPARAM lParam); 162 | void OnLbuttonUP(WPARAM wParam, LPARAM lParam); 163 | void OnMouseMove(WPARAM wParam, LPARAM lParam); 164 | void OnRbuttonDown(WPARAM wParam, LPARAM lParam); 165 | 166 | int CreateBitmapfromBuffer(BYTE * pBuffer, int nSize, int nFlag); 167 | 168 | void SetWindowHWnd(HWND hwnd) 169 | { 170 | m_hWnd = hwnd; 171 | } 172 | 173 | void SetLogFont(LOGFONT lf) 174 | { 175 | m_lf = lf; 176 | } 177 | 178 | void GetEditorWindowSize(int &nWidth,int &nHeight) 179 | { 180 | nWidth = m_rDrawArea.right - m_rDrawArea.left; 181 | nHeight = m_rDrawArea.bottom - m_rDrawArea.top; 182 | } 183 | 184 | void ShowWindowPosition( int nFlag 185 | , POINT pt ) 186 | { 187 | if(m_hWnd) 188 | { 189 | if(nFlag) 190 | { 191 | RECT rc; 192 | GetClientRect( GetParent( m_hWnd ), &rc ); 193 | int nWidth = rc.right - rc.left; 194 | int nHeight = rc.bottom - rc.top; 195 | SetWindowPos( m_hWnd, HWND_TOP 196 | , pt.x+(nWidth/4) , pt.y, nWidth/2, nHeight/2, SWP_SHOWWINDOW ); 197 | } 198 | else 199 | SetWindowPos( m_hWnd, HWND_TOP, 0 , 0, 0, 0 200 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 201 | } 202 | } 203 | 204 | LOGFONT GetEditorFont() 205 | { 206 | return m_lf; 207 | } 208 | 209 | void SetDrawRect(RECT rc) 210 | { 211 | m_rDrawArea = rc; 212 | } 213 | 214 | 215 | HBITMAP GetEditorBitmap() 216 | { 217 | return m_hBitmap; 218 | } 219 | void SetEditorBitmap(HBITMAP hBitmap) 220 | { 221 | m_hBitmap = hBitmap; 222 | } 223 | 224 | HWND GethWnd() 225 | { 226 | return m_hWnd; 227 | } 228 | 229 | HWND GetEditorhWnd() 230 | { 231 | return m_hParentWnd; 232 | } 233 | 234 | HWND CreateBitmapWindow(HWND hParent); 235 | 236 | HWND CreateBitmapWindowBuf(HWND hParent, BYTE * pBuffer 237 | , _tstring strID 238 | , int nSize, int nFlag); 239 | 240 | void PaintWindow(HWND hwnd, HDC hdc, RECT rPaint); 241 | 242 | static void MenuProcess(HWND hwnd,DWORD dwValue); 243 | 244 | static int RegisterEditorclass(HINSTANCE hInstance); 245 | 246 | static LRESULT CALLBACK EditorWndProc(HWND hwnd, UINT uMsg, 247 | WPARAM wParam, LPARAM lParam); 248 | 249 | static CNikBitmapEditor * GetBitmapEditorPtr(HWND hwnd); 250 | }; 251 | -------------------------------------------------------------------------------- /NikPEViewer/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 11 | // Windows Header Files: 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // C RunTime Header Files 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | // TODO: reference additional headers your program requires here 35 | using namespace std; 36 | 37 | #pragma comment (lib,"user32.lib") 38 | #pragma comment (lib,"GDI32.lib") 39 | #pragma comment (lib,"shell32.lib") 40 | #pragma comment (lib,"Comdlg32.lib") 41 | #pragma comment (lib,"comctl32.lib") 42 | #pragma comment (lib,"Psapi.lib") 43 | 44 | #ifdef _UNICODE 45 | #define _tstring wstring 46 | #else 47 | #define _tstring string 48 | #endif 49 | 50 | #define WM_PE_VIEWER_DISTORY WM_USER + 1977 51 | #define OPEN_RESOURCE_ITEM WM_USER + 1978 52 | #define UM_WHEELDOWN WM_USER + 1979 53 | #define UM_WHEELUP WM_USER + 1980 54 | 55 | #define MENU_FONT _T("Tahoma") 56 | #define DOS_HEADER _T("Dos header") 57 | #define NT_HEADERS _T("NT headers") 58 | #define NT_SIGNATURE _T("NT Signature") 59 | #define FILE_HEADER _T("File header") 60 | #define OPTIONAL_HEADER _T("Optional header") 61 | #define DATA_DIRECTORIES _T("Data Directories") 62 | #define EXPORT_TABLE _T("Export table") 63 | #define IMPORT_TABLE _T("Import table") 64 | #define RESOURCE_TABLE _T("Resource table") 65 | #define EXCEPTION_TABLE _T("Exception table") 66 | #define SECURITY_TABLE _T("Security table") 67 | #define BASERELOC_TABLE _T("Basereloc table") 68 | #define DEBUG_TABLE _T("Debug table") 69 | #define COPYRIGHT_TABLE _T("Copyright table") 70 | #define GLOBALPTR_TABLE _T("Globalptr table") 71 | #define TLS_TABLE _T("Tls table") 72 | #define LOAD_CONFIG_TABLE _T("LOAD_CONFIG TABLE") 73 | #define UNDEFINED_TABLE _T("UNDEFINED TABLE") 74 | #define IMAGE_SECTIONS _T("Sections") 75 | #define UNDEFINED_SECTION _T("") 76 | 77 | //--------------------------- 78 | typedef struct _MENU_INFO 79 | { 80 | WORD m_wFlag; 81 | WORD m_wMenuID; 82 | wstring m_strText; 83 | RECT m_rRect; 84 | vector<_MENU_INFO> m_vMenuList; 85 | 86 | _MENU_INFO() 87 | { 88 | m_wFlag = 0; 89 | m_wMenuID = 0; 90 | memset( &m_rRect, 0, sizeof(RECT)); 91 | } 92 | 93 | ~_MENU_INFO() 94 | { 95 | m_vMenuList.clear(); 96 | } 97 | }MENU_INFO; 98 | //--------------------------- 99 | 100 | //--------------------------- 101 | typedef struct _IMPORTFUNCTIONLIST 102 | { 103 | int m_nOrdinalNo; 104 | _tstring m_strFunctionName; 105 | }IMPORTFUNCTIONLIST; 106 | //--------------------------- 107 | 108 | //--------------------------- 109 | typedef struct _IMPORTDLLLIST 110 | { 111 | _tstring m_strDllName; 112 | IMAGE_IMPORT_DESCRIPTOR m_stImageDescriptor; 113 | vector m_vImportFunctionList; 114 | 115 | _IMPORTDLLLIST() 116 | { 117 | memset(&m_stImageDescriptor,0,sizeof(IMAGE_IMPORT_DESCRIPTOR)); 118 | } 119 | ~_IMPORTDLLLIST() 120 | { 121 | m_vImportFunctionList.clear(); 122 | } 123 | }IMPORTDLLLIST; 124 | //--------------------------- 125 | 126 | //--------------------------- 127 | typedef struct _EXPORTFUNCTIONLIST 128 | { 129 | _tstring m_strFunctionName; 130 | DWORD m_dwOrdianlNo; 131 | DWORD m_dwHint; 132 | DWORD m_dwEntryPoint; 133 | 134 | _EXPORTFUNCTIONLIST() 135 | { 136 | m_dwHint = 0; 137 | m_dwOrdianlNo = 0; 138 | m_dwEntryPoint = 0; 139 | } 140 | }EXPORTFUNCTIONLIST; 141 | //--------------------------- 142 | 143 | //--------------------------- 144 | typedef struct _RESOURCELIST 145 | { 146 | TCHAR m_chName[128]; 147 | BOOL m_bIsDir; 148 | int m_nType; 149 | int m_nFileOffset; 150 | int m_nSize; 151 | int m_nOffsetToData; 152 | vector<_RESOURCELIST *> m_vDirList; 153 | 154 | _RESOURCELIST() 155 | { 156 | memset(m_chName,0,sizeof(m_chName)); 157 | m_nType = -1; 158 | m_nSize = 0; 159 | m_nFileOffset = -1; 160 | m_nOffsetToData = -1; 161 | m_bIsDir = FALSE; 162 | } 163 | ~_RESOURCELIST() 164 | { 165 | _RESOURCELIST * pTemp; 166 | for(int i=0;i<(int)m_vDirList.size();i++) 167 | { 168 | pTemp = m_vDirList.at(i); 169 | if(pTemp) 170 | delete pTemp; 171 | } 172 | m_vDirList.clear(); 173 | } 174 | }RESOURCELIST; 175 | //--------------------------- 176 | 177 | /*/--------------------------- 178 | typedef struct _EXECUTABLE_INFO 179 | { 180 | HWND m_hListWnd; 181 | BYTE * m_pBuffer; 182 | DWORD m_dwBufferSize; 183 | DWORD m_dwEndOffset; 184 | DWORD m_dwStartOffset; 185 | DWORD m_dwEntryPoint; 186 | 187 | _EXECUTABLE_INFO() 188 | { 189 | m_hListWnd = NULL; 190 | 191 | m_pBuffer = NULL; 192 | 193 | m_dwEndOffset = 0; 194 | m_dwEntryPoint = 0; 195 | m_dwBufferSize = 0; 196 | m_dwStartOffset = 0; 197 | } 198 | }EXECUTABLE_INFO; 199 | *///--------------------------- 200 | 201 | //--------------------------- 202 | typedef struct _EXECUTABLE_INFO 203 | { 204 | HWND m_hListWnd; 205 | 206 | BYTE * m_pBuffer; 207 | DWORD m_dwBufferSize; 208 | 209 | DWORD m_dwBaseCode; 210 | DWORD m_dwEndOffset; 211 | DWORD m_dwStartOffset; 212 | DWORD m_dwEntryPoint; 213 | 214 | IMAGE_NT_HEADERS m_stNTHeader; 215 | 216 | vector m_vImportDllList; 217 | vector m_vExportFunctionList; 218 | 219 | void CleanUp() 220 | { 221 | m_hListWnd = NULL; 222 | m_dwBaseCode = 0; 223 | m_dwEndOffset = 0; 224 | m_dwStartOffset = 0; 225 | m_dwEntryPoint = 0; 226 | 227 | m_pBuffer = NULL; 228 | m_dwBufferSize = 0; 229 | 230 | memset(&m_stNTHeader, 0, sizeof(IMAGE_NT_HEADERS)); 231 | 232 | m_vImportDllList.clear(); 233 | m_vExportFunctionList.clear(); 234 | } 235 | 236 | _EXECUTABLE_INFO() 237 | { 238 | CleanUp(); 239 | } 240 | 241 | ~_EXECUTABLE_INFO() 242 | { 243 | if(m_pBuffer) 244 | { 245 | //delete [] m_pBuffer; 246 | m_pBuffer = NULL; 247 | } 248 | 249 | m_dwBufferSize = 0; 250 | } 251 | 252 | }EXECUTABLE_INFO; 253 | //--------------------------- 254 | -------------------------------------------------------------------------------- /NikPEViewer/NikPEViewer.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 53 | 56 | 59 | 62 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 91 | 99 | 102 | 105 | 108 | 111 | 114 | 125 | 128 | 131 | 134 | 143 | 146 | 149 | 152 | 155 | 158 | 161 | 164 | 165 | 166 | 167 | 168 | 169 | 174 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 228 | 232 | 233 | 236 | 240 | 241 | 242 | 243 | 248 | 251 | 252 | 255 | 256 | 259 | 260 | 263 | 264 | 267 | 268 | 271 | 272 | 275 | 276 | 279 | 280 | 283 | 284 | 287 | 288 | 291 | 292 | 295 | 296 | 299 | 300 | 303 | 304 | 307 | 308 | 311 | 312 | 313 | 318 | 321 | 322 | 325 | 326 | 329 | 330 | 331 | 334 | 335 | 336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /NikPEViewer/PEViewerListView.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | extern TCHAR DOS_HEADER_E_LFANEW[] ; 5 | extern TCHAR DOS_HEADER_E_OEMINFO[] ; 6 | extern TCHAR DOS_HEADER_E_OEMID[] ; 7 | extern TCHAR DOS_HEADER_E_OVNO[] ; 8 | extern TCHAR DOS_HEADER_E_LFARLC[] ; 9 | extern TCHAR DOS_HEADER_E_CS[] ; 10 | extern TCHAR DOS_HEADER_E_IP[] ; 11 | extern TCHAR DOS_HEADER_E_CSUM[] ; 12 | extern TCHAR DOS_HEADER_E_SP[] ; 13 | extern TCHAR DOS_HEADER_E_SS[] ; 14 | extern TCHAR DOS_HEADER_E_MAXALLOC[] ; 15 | extern TCHAR DOS_HEADER_E_MINALLOC[] ; 16 | extern TCHAR DOS_HEADER_E_CPARHDR[] ; 17 | extern TCHAR DOS_HEADER_E_CRLC[] ; 18 | extern TCHAR DOS_HEADER_E_CP[] ; 19 | extern TCHAR DOS_HEADER_E_CBLP[] ; 20 | extern TCHAR DOS_HEADER_E_MAGIC[] ; 21 | extern TCHAR DOS_HEADER_1[] ; 22 | extern TCHAR STR_PRINTF_X[] ; 23 | extern TCHAR STR_PRINTF_s[] ; 24 | extern TCHAR STR_HEX_VALUES[] ; 25 | extern TCHAR STR_DESCRIPTION[] ; 26 | extern TCHAR NT_HEADERS_1[] ; 27 | extern TCHAR NT_HEADERS_SIGNATURE[] ; 28 | extern TCHAR NT_HEADERS_FH_1[] ; 29 | extern TCHAR NT_HEADERS_FH_2[] ; 30 | extern TCHAR NT_HEADERS_FH_MACHINE[] ; 31 | extern TCHAR NT_HEADERS_FH_NUOFSECTIONS[] ; 32 | extern TCHAR NT_HEADERS_FH_TIMEDATESTAMP[] ; 33 | extern TCHAR NT_HEADERS_FH_PTSYMBOLTABLE[] ; 34 | extern TCHAR NT_HEADERS_FH_NUMBEROFSYMBOL[] ; 35 | extern TCHAR NT_HEADERS_FH_SIZEOFOPHEADER[] ; 36 | extern TCHAR NT_HEADERS_FH_CHARACTERISTIC[] ; 37 | extern TCHAR NT_HEADERS_OP_NUOFRVAANDSIZES[] ; 38 | extern TCHAR NT_HEADERS_OP_LOADERFLAGS[] ; 39 | extern TCHAR NT_HEADERS_OP_SIZEOFHEAPCOMMIT[] ; 40 | extern TCHAR NT_HEADERS_OP_SIZEOFHEAPRESERVE[] ; 41 | extern TCHAR NT_HEADERS_OP_SIZEOFSTACKCOMMIT[] ; 42 | extern TCHAR NT_HEADERS_OP_SIZEOFSTACKRESERVE[]; 43 | extern TCHAR NT_HEADERS_OP_SUBSYSTEM[] ; 44 | extern TCHAR NT_HEADERS_OP_CHECKSUM[] ; 45 | extern TCHAR NT_HEADERS_OP_DLLCHARACTERISTIC[] ; 46 | extern TCHAR NT_HEADERS_OP_WDMDRIVER[] ; 47 | extern TCHAR NT_HEADERS_OP_SIZEOFHEADERS[] ; 48 | extern TCHAR NT_HEADERS_OP_SIZEOFIMAGE[] ; 49 | extern TCHAR NT_HEADERS_OP_WIN32VERSIONVALUE[] ; 50 | extern TCHAR NT_HEADERS_OP_MINORSUBSYSVERSION[]; 51 | extern TCHAR NT_HEADERS_OP_MAJORSUBSYSVERSION[]; 52 | extern TCHAR NT_HEADERS_OP_MINORIMAGEVERSION[] ; 53 | extern TCHAR NT_HEADERS_OP_MAJORLINKERVERSION[]; 54 | extern TCHAR NT_HEADERS_OP_MINOROSVERSION[] ; 55 | extern TCHAR NT_HEADERS_OP_MAJOROSVERSION[] ; 56 | extern TCHAR NT_HEADERS_OP_FILEALIGNMENT[] ; 57 | extern TCHAR NT_HEADERS_OP_SECTIONALIGNMENT[] ; 58 | extern TCHAR NT_HEADERS_OP_IMAGEBASE[] ; 59 | extern TCHAR NT_HEADERS_OP_BASEOFDATA[] ; 60 | extern TCHAR NT_HEADERS_OP_BASEOFCODE[] ; 61 | extern TCHAR NT_HEADERS_OP_ADDOFENTRYPOINT[] ; 62 | extern TCHAR NT_HEADERS_OP_SIZEOFUNINITDATA[] ; 63 | extern TCHAR NT_HEADERS_OP_SIZEOFINITDATA[] ; 64 | extern TCHAR NT_HEADERS_OP_SIZEOFCODE[] ; 65 | extern TCHAR NT_HEADERS_OP_MINORLINKERVERSION[]; 66 | extern TCHAR NT_HEADERS_OP_MAGIC[] ; 67 | extern TCHAR NT_HEADERS_OP_1[] ; 68 | extern TCHAR NT_HEADERS_OP_2[] ; 69 | extern TCHAR STR_ORDIANL_NO[] ; 70 | extern TCHAR STR_ENTRY_POINT[] ; 71 | extern TCHAR STR_FUNCTION_NAME[] ; 72 | extern TCHAR STR_EXPORT_FUNCTIONS[] ; 73 | extern TCHAR STR_VIRTUAL_ADDRESS[] ; 74 | extern TCHAR STR_DATADIRECTORY_SIZE[] ; 75 | extern TCHAR STR_DATA_DIRECTORY[] ; 76 | extern TCHAR SH_NUMBEROFLINENUMBERS[] ; 77 | extern TCHAR SH_NUMBEROFRELOCATIONS[] ; 78 | extern TCHAR SH_POINTERTOLINENUMBERS[] ; 79 | extern TCHAR SH_POINTERTORELOCATIONS[] ; 80 | extern TCHAR SH_POINTERTORAWDATA[] ; 81 | extern TCHAR SH_SIZEOFRAWDATA[] ; 82 | extern TCHAR SH_VIRTUAL_ADDRESS[] ; 83 | extern TCHAR SH_PHYSICAL_ADDRESS[] ; 84 | extern TCHAR SH_SECTIONS_NAME[] ; 85 | extern TCHAR SH_SECTIONS_LIST[] ; 86 | extern TCHAR STR_RECENT_FILES[] ; 87 | extern TCHAR STR_HTML_START[] ; 88 | extern TCHAR STR_HTML_END[] ; 89 | extern TCHAR STR_HTML_HEAD[] ; 90 | extern TCHAR STR_HTML_BODY_S[] ; 91 | extern TCHAR STR_HTML_BODY_S_1[] ; 92 | extern TCHAR STR_HTML_BODY_E[] ; 93 | extern TCHAR STR_HTML_TABLE_S[] ; 94 | extern TCHAR STR_HTML_TABLE_E[] ; 95 | extern TCHAR STR_HTML_TB_TR_S[] ; 96 | extern TCHAR STR_HTML_TB_TR_E[] ; 97 | extern TCHAR STR_HTML_TB_TD_CENTER[] ; 98 | extern TCHAR STR_HTML_TB_TD_S[] ; 99 | extern TCHAR STR_HTML_TB_TD_E[] ; 100 | 101 | class CNikPEVListViewCtrl 102 | { 103 | 104 | protected: 105 | 106 | HWND m_hWnd; 107 | HINSTANCE m_hInstance; 108 | 109 | void * m_pNikPEViewer; 110 | 111 | public: 112 | CNikPEVListViewCtrl(); 113 | virtual ~CNikPEVListViewCtrl(); 114 | 115 | HWND GetWindowHandle() 116 | { 117 | return m_hWnd; 118 | } 119 | 120 | LRESULT ListView_Notify(HWND , LPARAM ); 121 | 122 | virtual int FillPEVListViewInfo(void * ); 123 | 124 | virtual HWND CreatePEListViewCtrl(HINSTANCE , HWND , RECT , _tstring ); 125 | 126 | virtual BOOL InsertColumnListViewCtl( HWND , TCHAR * , int , int ); 127 | virtual BOOL InsertColumnListViewValues( HWND , TCHAR * , int , int nFlag = 0); 128 | static BOOL InsertColumnListViewValues_1( HWND , TCHAR * , int , int nFlag = 0); 129 | }; 130 | 131 | class CNikPEVHeaderList : public CNikPEVListViewCtrl 132 | { 133 | public: 134 | 135 | CNikPEVHeaderList(); 136 | virtual ~CNikPEVHeaderList(); 137 | 138 | virtual int FillPEVListViewInfo(void * ); 139 | 140 | int List_IMAGE_DOS_HEADER(const IMAGE_DOS_HEADER * ); 141 | int List_IMAGE_NT_HEADERS(const IMAGE_NT_HEADERS * ); 142 | }; 143 | 144 | class CNikDataSectionList : public CNikPEVListViewCtrl 145 | { 146 | public: 147 | 148 | CNikDataSectionList(); 149 | virtual ~CNikDataSectionList(); 150 | 151 | int List_IMAGE_NT_DATA_DIRECTORY(void * ); 152 | int List_IMAGE_NT_SECTION_DETAILS(void * ); 153 | virtual int FillPEVListViewInfo(void * ); 154 | }; 155 | 156 | class CNikImportFunList : public CNikPEVListViewCtrl 157 | { 158 | public: 159 | 160 | CNikImportFunList(); 161 | virtual ~CNikImportFunList(); 162 | 163 | virtual int FillPEVListViewInfo(void * ); 164 | 165 | int List_IMAGE_NT_IMPORT_TABLE(void * ); 166 | }; 167 | 168 | class CNikExportFunList : public CNikPEVListViewCtrl 169 | { 170 | public: 171 | 172 | CNikExportFunList(); 173 | virtual ~CNikExportFunList(); 174 | 175 | virtual int FillPEVListViewInfo(void * ); 176 | int List_IMAGE_NT_EXPORT_TABLE(void * ); 177 | }; 178 | 179 | class CNikResourceItemsList : public CNikPEVListViewCtrl 180 | { 181 | public: 182 | 183 | CNikResourceItemsList(); 184 | virtual ~CNikResourceItemsList(); 185 | 186 | virtual int FillPEVListViewInfo(const void * ); 187 | int List_IMAGE_RESOURCE_ITEMS_TABLE(const void *, int ); 188 | }; 189 | 190 | class CNikDisAssemblyList : public CNikPEVListViewCtrl 191 | { 192 | HANDLE m_hThread; 193 | DWORD m_dwThreadId; 194 | 195 | BOOL m_bIsThreadRunning; 196 | 197 | public: 198 | 199 | CNikDisAssemblyList(); 200 | virtual ~CNikDisAssemblyList(); 201 | 202 | int StopDisAssemblyThread(); 203 | virtual int FillPEVListViewInfo(const void * ); 204 | 205 | static DWORD WINAPI DisAssemblyThreadProc( LPVOID lpParam ); 206 | }; 207 | -------------------------------------------------------------------------------- /NikPEViewer/NikPEViewer.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #ifndef APSTUDIO_INVOKED 11 | #include "targetver.h" 12 | #endif 13 | #define APSTUDIO_HIDDEN_SYMBOLS 14 | #include "windows.h" 15 | #undef APSTUDIO_HIDDEN_SYMBOLS 16 | ///////////////////////////////////////////////////////////////////////////// 17 | #undef APSTUDIO_READONLY_SYMBOLS 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE 9, 1 21 | #pragma code_page(1252) 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // Bitmap 26 | // 27 | 28 | IDB_TREEBITMAP BITMAP DISCARDABLE "res/1.bmp" 29 | IDB_TOOLBARBITMAP BITMAP DISCARDABLE "res/Nik_toolbar.bmp" 30 | 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | // 34 | // OPCODE_FILE 35 | // 36 | IDB_OPCODE_FILE OPCODE_FILE "res/Dumpfile.dat" 37 | 38 | 39 | ///////////////////////////////////////////////////////////////////////////// 40 | // 41 | // Icon 42 | // 43 | 44 | // Icon with lowest ID value placed first to ensure application icon 45 | // remains consistent on all systems. 46 | 47 | IDI_NIKPEVIEWER ICON "res/NikPEViewer.ico" 48 | IDI_SMALL ICON "res/small.ico" 49 | 50 | 51 | ///////////////////////////////////////////////////////////////////////////// 52 | // 53 | // Menu 54 | // 55 | 56 | IDC_NIKPEVIEWER MENU 57 | BEGIN 58 | POPUP "&File" 59 | BEGIN 60 | MENUITEM "&Open...", ID_FILE_OPEN 61 | MENUITEM "&Close", ID_FILE_CLOSE 62 | MENUITEM SEPARATOR 63 | MENUITEM SEPARATOR 64 | MENUITEM "E&xit", IDM_EXIT 65 | END 66 | POPUP "&View" 67 | BEGIN 68 | MENUITEM "&PE Sammary", IDM_PE_SAMMARY 69 | MENUITEM "&PE Headers", IDM_PE_HEADERS 70 | MENUITEM "&PE DataSections", IDM_PE_DATA_SECTIONS 71 | MENUITEM "&PE Import table", IDM_PE_IMPORT_TABLE 72 | MENUITEM "&PE Export table", IDM_PE_EXPORT_TABLE 73 | MENUITEM "&PE Module HTML", IDM_MODULES_HTML 74 | MENUITEM "&PE Module Binary", IDM_MODULES_BINARY 75 | MENUITEM "Code &Dis-assembly", IDM_PE_DISASSEMBLY 76 | MENUITEM SEPARATOR 77 | MENUITEM "&Show All views", IDM_SHOW_ALL_VIEW 78 | MENUITEM "&Group ALL views", IDM_GROUP_ALL_VIEW 79 | END 80 | POPUP "&Window" 81 | BEGIN 82 | MENUITEM "&Cascade", IDM_CASCADE_ICON 83 | MENUITEM "&Arrange Icon", IDM_ARRANGE_ICON 84 | MENUITEM "Tile &Vertical", IDM_TILE_VERTICAL 85 | MENUITEM "Tile &Horizontal", IDM_TILE_HORIZONTAL 86 | END 87 | POPUP "&Help" 88 | BEGIN 89 | MENUITEM "&About ...", IDM_ABOUT 90 | MENUITEM "&License ...", IDM_LICENSE 91 | END 92 | END 93 | 94 | 95 | ///////////////////////////////////////////////////////////////////////////// 96 | // 97 | // Accelerator 98 | // 99 | 100 | IDC_NIKPEVIEWER ACCELERATORS 101 | BEGIN 102 | "?", IDM_ABOUT, ASCII, ALT 103 | "/", IDM_ABOUT, ASCII, ALT 104 | END 105 | 106 | 107 | ///////////////////////////////////////////////////////////////////////////// 108 | // 109 | // Dialog 110 | // 111 | 112 | IDD_ABOUTBOX DIALOGEX 200, 100, 230, 74 113 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 114 | CAPTION "About NikPEResourceViewer" 115 | FONT 8, "MS Shell Dlg" 116 | BEGIN 117 | ICON IDI_NIKPEVIEWER,IDC_STATIC,14,14,21,20 118 | LTEXT "NikPEResourceViewer, Bita Version 0.0.2.1",IDC_STATIC,42,14,144,8,SS_NOPREFIX 119 | LTEXT "Protable Executable (PE) 32-bits Resource Viewer",IDC_STATIC,42,26,150,8 120 | LTEXT "Copyright (C) 2008 CodeDebug ( www.CodeDebug.com )",IDC_STATIC,42,38,200,8 121 | DEFPUSHBUTTON "OK",IDOK,95,53,50,14,WS_GROUP 122 | END 123 | 124 | IDD_LICENSEBOX DIALOGEX 250, 30, 200, 300 125 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION 126 | CAPTION "CodeDebug PE Resource Viewer's EULA" 127 | FONT 8, "MS Shell Dlg" 128 | BEGIN 129 | ICON IDI_NIKPEVIEWER,IDC_STATIC,10,10,21,20 130 | CTEXT "END-USER LICENSE AGREEMENT", IDC_STATIC, 42, 14, 130, 8, SS_NOPREFIX 131 | EDITTEXT IDD_EDITLICENSE, 10, 37, 180, 230, ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL 132 | DEFPUSHBUTTON "I Agree",IDYES,50,280,50,14,WS_GROUP 133 | DEFPUSHBUTTON "Not Agree",IDNO,110,280,50,14,WS_GROUP 134 | END 135 | 136 | ///////////////////////////////////////////////////////////////////////////// 137 | // 138 | // Version 139 | // 140 | 141 | VS_VERSION_INFO VERSIONINFO 142 | FILEVERSION 0,0,2,1 143 | PRODUCTVERSION 0,0,2,1 144 | FILEFLAGSMASK 0x3fL 145 | #ifdef _DEBUG 146 | FILEFLAGS 0x1L 147 | #else 148 | FILEFLAGS 0x0L 149 | #endif 150 | FILEOS 0x4L 151 | FILETYPE 0x1L 152 | FILESUBTYPE 0x0L 153 | BEGIN 154 | BLOCK "StringFileInfo" 155 | BEGIN 156 | BLOCK "040904B0" 157 | BEGIN 158 | VALUE "CompanyName", "CodeDebug\0" 159 | VALUE "FileDescription", "Protable Executable Viewer (Bita v)\0" 160 | VALUE "FileVersion", "0, 0, 2, 1\0" 161 | VALUE "InternalName", "NIKPEResourceViewer\0" 162 | VALUE "LegalCopyright", "Copyright (C) 2008 CodeDebug\0" 163 | VALUE "LegalTrademarks", "\0" 164 | VALUE "OriginalFilename", "NikPEResourceViewer.EXE\0" 165 | VALUE "ProductName", "PE Viewer\0" 166 | VALUE "ProductVersion", "0, 0, 2, 1\0" 167 | END 168 | END 169 | BLOCK "VarFileInfo" 170 | BEGIN 171 | VALUE "Translation", 0x409, 1200 172 | END 173 | END 174 | 175 | 176 | ///////////////////////////////////////////////////////////////////////////// 177 | // 178 | // DESIGNINFO 179 | // 180 | 181 | #ifdef APSTUDIO_INVOKED 182 | GUIDELINES DESIGNINFO 183 | BEGIN 184 | IDD_ABOUTBOX, DIALOG 185 | BEGIN 186 | LEFTMARGIN, 7 187 | RIGHTMARGIN, 163 188 | TOPMARGIN, 7 189 | BOTTOMMARGIN, 55 190 | END 191 | END 192 | #endif // APSTUDIO_INVOKED 193 | 194 | #ifdef APSTUDIO_INVOKED 195 | ///////////////////////////////////////////////////////////////////////////// 196 | // 197 | // TEXTINCLUDE 198 | // 199 | 1 TEXTINCLUDE 200 | BEGIN 201 | "resource.h\0" 202 | END 203 | 204 | 2 TEXTINCLUDE 205 | BEGIN 206 | "#ifndef APSTUDIO_INVOKED\r\n" 207 | "#include ""targetver.h""\r\n" 208 | "#endif\r\n" 209 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 210 | "#include ""windows.h""\r\n" 211 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 212 | "\0" 213 | END 214 | 215 | 3 TEXTINCLUDE 216 | BEGIN 217 | "\r\n" 218 | "\0" 219 | END 220 | 221 | #endif // APSTUDIO_INVOKED 222 | 223 | ///////////////////////////////////////////////////////////////////////////// 224 | // 225 | // String Table 226 | // 227 | 228 | STRINGTABLE 229 | BEGIN 230 | IDC_NIKPEVIEWER "NIKPEVIEWER" 231 | IDS_APP_TITLE "NikPEViewer" 232 | IDS_FILE_OPEN "Open File..." 233 | IDS_FILE_CLOSE "Close File" 234 | IDS_PE_SAMMARY "PE Sammary" 235 | IDS_PE_HEADERS "PE Headers" 236 | IDS_PE_DATA_SECTIONS "PE Directory and Sections" 237 | IDS_PE_IMPORT_TABLE "PE Import table" 238 | IDS_PE_EXPORT_TABLE "PE Export table" 239 | IDS_MODULES_BINARY "Module Binary view" 240 | IDS_LICENSE "Application License" 241 | IDS_ABOUT "About application" 242 | IDS_MODULES_HTML "Nik HTML Viewer" 243 | IDS_PE_DISASSEMBLY "Code Dis-assembly view" 244 | END 245 | 246 | #endif 247 | ///////////////////////////////////////////////////////////////////////////// 248 | 249 | 250 | 251 | #ifndef APSTUDIO_INVOKED 252 | ///////////////////////////////////////////////////////////////////////////// 253 | // 254 | // Generated from the TEXTINCLUDE 3 resource. 255 | // 256 | 257 | ///////////////////////////////////////////////////////////////////////////// 258 | #endif // not APSTUDIO_INVOKED 259 | -------------------------------------------------------------------------------- /NikPEViewer/CommonStr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | TCHAR DOS_HEADER_E_LFANEW[] = _T("File address of new exe header"); 4 | TCHAR DOS_HEADER_E_OEMINFO[] = _T("OEM information (e_oemid specific)"); 5 | TCHAR DOS_HEADER_E_OEMID[] = _T("OEM identifier (for e_oemid)"); 6 | TCHAR DOS_HEADER_E_OVNO[] = _T("Overlay number"); 7 | TCHAR DOS_HEADER_E_LFARLC[] = _T("File address of relocation table"); 8 | TCHAR DOS_HEADER_E_CS[] = _T("Initial (relative) CS value"); 9 | TCHAR DOS_HEADER_E_IP[] = _T("Initial IP value"); 10 | TCHAR DOS_HEADER_E_CSUM[] = _T("Checksum"); 11 | TCHAR DOS_HEADER_E_SP[] = _T("Initial SP value"); 12 | TCHAR DOS_HEADER_E_SS[] = _T("Initial (relative) SS value"); 13 | TCHAR DOS_HEADER_E_MAXALLOC[] = _T("Maximum extra paragraphs needed"); 14 | TCHAR DOS_HEADER_E_MINALLOC[] = _T("Minimum extra paragraphs needed"); 15 | TCHAR DOS_HEADER_E_CPARHDR[] = _T("Size of header in paragraphs"); 16 | TCHAR DOS_HEADER_E_CRLC[] = _T("Relocations"); 17 | TCHAR DOS_HEADER_E_CP[] = _T("Pages in file"); 18 | TCHAR DOS_HEADER_E_CBLP[] = _T("Bytes on last page of file"); 19 | TCHAR DOS_HEADER_E_MAGIC[] = _T("Magic number"); 20 | TCHAR DOS_HEADER_1[] = _T("Dos header"); 21 | TCHAR STR_PRINTF_X[] = _T("0x%X"); 22 | TCHAR STR_PRINTF_s[] = _T("%s"); 23 | TCHAR STR_HEX_VALUES[] = _T("Hex values"); 24 | TCHAR STR_DESCRIPTION[] = _T("Description"); 25 | 26 | TCHAR NT_HEADERS_1[] = _T("NT headers"); 27 | TCHAR NT_HEADERS_SIGNATURE[] = _T("Signature"); 28 | 29 | TCHAR NT_HEADERS_FH_1[] = _T("File headers"); 30 | TCHAR NT_HEADERS_FH_2[] = _T("NT File headers"); 31 | TCHAR NT_HEADERS_FH_MACHINE[] = _T("Machine"); 32 | TCHAR NT_HEADERS_FH_NUOFSECTIONS[] = _T("NumberOfSections"); 33 | TCHAR NT_HEADERS_FH_TIMEDATESTAMP[] = _T("TimeDateStamp"); 34 | TCHAR NT_HEADERS_FH_PTSYMBOLTABLE[] = _T("PointerToSymbolTable"); 35 | TCHAR NT_HEADERS_FH_NUMBEROFSYMBOL[] = _T("NumberOfSymbols"); 36 | TCHAR NT_HEADERS_FH_SIZEOFOPHEADER[] = _T("SizeOfOptionalHeader"); 37 | TCHAR NT_HEADERS_FH_CHARACTERISTIC[] = _T("Characteristics"); 38 | 39 | TCHAR NT_HEADERS_OP_NUOFRVAANDSIZES[] = _T("NumberOfRvaAndSizes"); 40 | TCHAR NT_HEADERS_OP_LOADERFLAGS[] = _T("LoaderFlags"); 41 | TCHAR NT_HEADERS_OP_SIZEOFHEAPCOMMIT[] = _T("SizeOfHeapCommit"); 42 | TCHAR NT_HEADERS_OP_SIZEOFHEAPRESERVE[] = _T("SizeOfHeapReserve"); 43 | TCHAR NT_HEADERS_OP_SIZEOFSTACKCOMMIT[] = _T("SizeOfStackCommit"); 44 | TCHAR NT_HEADERS_OP_SIZEOFSTACKRESERVE[]= _T("SizeOfStackReserve"); 45 | TCHAR NT_HEADERS_OP_SUBSYSTEM[] = _T("Subsystem"); 46 | TCHAR NT_HEADERS_OP_CHECKSUM[] = _T("CheckSum"); 47 | TCHAR NT_HEADERS_OP_DLLCHARACTERISTIC[] = _T("DllCharacteristics"); 48 | TCHAR NT_HEADERS_OP_WDMDRIVER[] = _T("WDM driver"); 49 | TCHAR NT_HEADERS_OP_SIZEOFHEADERS[] = _T("SizeOfHeaders"); 50 | TCHAR NT_HEADERS_OP_SIZEOFIMAGE[] = _T("SizeOfImage"); 51 | TCHAR NT_HEADERS_OP_WIN32VERSIONVALUE[] = _T("Win32VersionValue"); 52 | TCHAR NT_HEADERS_OP_MINORSUBSYSVERSION[]= _T("MinorSubsystemVersion"); 53 | TCHAR NT_HEADERS_OP_MAJORSUBSYSVERSION[]= _T("MajorSubsystemVersion"); 54 | TCHAR NT_HEADERS_OP_MINORIMAGEVERSION[] = _T("MinorImageVersion"); 55 | TCHAR NT_HEADERS_OP_MAJORLINKERVERSION[]= _T("MajorLinkerVersion"); 56 | TCHAR NT_HEADERS_OP_MINOROSVERSION[] = _T("MinorOperatingSystemVersion"); 57 | TCHAR NT_HEADERS_OP_MAJOROSVERSION[] = _T("MajorOperatingSystemVersion"); 58 | TCHAR NT_HEADERS_OP_FILEALIGNMENT[] = _T("FileAlignment"); 59 | TCHAR NT_HEADERS_OP_SECTIONALIGNMENT[] = _T("SectionAlignment"); 60 | TCHAR NT_HEADERS_OP_IMAGEBASE[] = _T("ImageBase"); 61 | TCHAR NT_HEADERS_OP_BASEOFDATA[] = _T("BaseOfData"); 62 | TCHAR NT_HEADERS_OP_BASEOFCODE[] = _T("BaseOfCode"); 63 | TCHAR NT_HEADERS_OP_ADDOFENTRYPOINT[] = _T("AddressOfEntryPoint"); 64 | TCHAR NT_HEADERS_OP_SIZEOFUNINITDATA[] = _T("SizeOfUninitializedData"); 65 | TCHAR NT_HEADERS_OP_SIZEOFINITDATA[] = _T("SizeOfInitializedData"); 66 | TCHAR NT_HEADERS_OP_SIZEOFCODE[] = _T("SizeOfCode"); 67 | TCHAR NT_HEADERS_OP_MINORLINKERVERSION[]= _T("MinorLinkerVersion"); 68 | TCHAR NT_HEADERS_OP_MAGIC[] = _T("Magic"); 69 | TCHAR NT_HEADERS_OP_1[] = _T("Optional headers"); 70 | TCHAR NT_HEADERS_OP_2[] = _T("NT Optional headers"); 71 | 72 | TCHAR STR_ORDIANL_NO[] = _T("Ordianl No"); 73 | TCHAR STR_ENTRY_POINT[] = _T("Entry Point"); 74 | TCHAR STR_FUNCTION_NAME[] = _T("Function name"); 75 | TCHAR STR_EXPORT_FUNCTIONS[] =_T("Export functions"); 76 | 77 | TCHAR STR_VIRTUAL_ADDRESS[] = _T("Virtual Address"); 78 | TCHAR STR_DATADIRECTORY_SIZE[] = _T("DataDirectory[%d].Size"); 79 | TCHAR STR_DATA_DIRECTORY[] = _T("Data Directory"); 80 | 81 | TCHAR SH_NUMBEROFLINENUMBERS[] = _T("NumberOfLinenumbers"); 82 | TCHAR SH_NUMBEROFRELOCATIONS[] = _T("NumberOfRelocations"); 83 | TCHAR SH_POINTERTOLINENUMBERS[] = _T("PointerToLinenumbers"); 84 | TCHAR SH_POINTERTORELOCATIONS[] = _T("PointerToRelocations"); 85 | TCHAR SH_POINTERTORAWDATA[] = _T("PointerToRawData"); 86 | TCHAR SH_SIZEOFRAWDATA[] = _T("SizeOfRawData"); 87 | TCHAR SH_VIRTUAL_ADDRESS[] = _T("Virtual Address"); 88 | TCHAR SH_PHYSICAL_ADDRESS[] = _T("Physical Address"); 89 | TCHAR SH_SECTIONS_NAME[] = _T("Sections name"); 90 | TCHAR SH_SECTIONS_LIST[] = _T("Sections list"); 91 | 92 | TCHAR STR_RECENT_FILES[] = _T("Recent Files"); 93 | 94 | TCHAR STR_HTML_START[] = _T(""); 95 | TCHAR STR_HTML_END[] = _T(""); 96 | 97 | TCHAR STR_HTML_HEAD[] = _T("PORTABLE EXECUTABLE FORMAT"); 99 | 100 | //TCHAR STR_HTML_BODY_S[] = _T(" \r\n

THE
PORTABLE EXECUTABLE FORMAT





"); 101 | 102 | TCHAR STR_HTML_BODY_S[] = _T(" \r\n
"); 103 | 104 | TCHAR STR_HTML_BODY_S_1[] = _T(" \r\n
"); 105 | 106 | TCHAR STR_HTML_BODY_E[] = _T(""); 107 | 108 | TCHAR STR_HTML_TABLE_S[] = _T(""); 109 | TCHAR STR_HTML_TABLE_E[] = _T("
"); 110 | 111 | TCHAR STR_HTML_TB_TR_S[] = _T(""); 112 | TCHAR STR_HTML_TB_TR_E[] = _T(""); 113 | 114 | TCHAR STR_HTML_TB_TD_CENTER[] = _T(""); 115 | TCHAR STR_HTML_TB_TD_S[] = _T(""); 116 | TCHAR STR_HTML_TB_TD_E[] = _T(""); 117 | 118 | TCHAR STR_LICENSE[] = _T("Protable Executable (PE) 32-bits file Viewer, Bita Version 0.0.0.1\r\n\r\n\ 119 | CodeDebug grants you a personal right to install and execute the Product \ 120 | on a Host Computer for Personal Use or Educational Use or for Evaluation.\r\n\r\n\ 121 | Since you have not paid for the use of the Product, there is no warranty for it, to \ 122 | the extent permitted by applicable law. \ 123 | This software is provided \"as is\" and use of \ 124 | the software is at your own risk. \'CodeDebug\' disclaims \ 125 | any and all warranties, whether express, implied or statutory \ 126 | , including, without limitation, any implied warranties of \ 127 | merchantability, fitness for a particular purpose or non-infringement \ 128 | of third-party rights. \'CodeDebug\' does not warrant that the software is free of Defects.\r\n\r\n\ 129 | You are not allowed to modify, decompile, disassemble or reverse engineer \ 130 | the Software except and only to the extent that such activity is expressly \ 131 | permitted by applicable law. You are not allowed to distribute or use any \ 132 | parts of the Software separately.\r\n\r\nYou may not use the Software or any Content \ 133 | for any commercial purpose."); 134 | 135 | /*TCHAR STR_HTML_TEXT[] = _T(" \r\n\ 136 | \r\n\ 137 | PE NikViewer v1.0 \r\n\ 138 | \r\n\ 139 | \r\n\ 140 | \r\n\ 141 | \r\n\ 142 | \r\n\ 143 | \r\n\ 144 | \r\n\ 145 | \r\n\*/ 146 | -------------------------------------------------------------------------------- /NikPEViewer/PEViewer.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "DialogWnd.h" 5 | #include "NikDisAssembly.h" 6 | #include "ResourceWnd.h" 7 | #include "NikHTMLView.h" 8 | #include "EditorBitmap.h" 9 | #include "PEViewerTree.h" 10 | #include "PEBinaryFile.h" 11 | #include "PEViewerListView.h" 12 | #include "NikDisassemblyWin.h" 13 | 14 | extern CNikDisassembly g_cNikDisassembly; 15 | 16 | class CNikPEViewer 17 | { 18 | HWND m_hWnd; 19 | HWND m_hTreeCtrl; 20 | 21 | int m_nChildCount; 22 | int m_nDiffOffset; 23 | 24 | DWORD m_dwPEFileSize; 25 | DWORD m_dwDiffAddress; 26 | DWORD m_dwResourceBaseAdd; 27 | 28 | BYTE * m_pPEBuffer; 29 | 30 | HINSTANCE m_hInstance; 31 | 32 | _tstring m_strFileName; 33 | _tstring m_strShortName; 34 | _tstring m_strSaveFileName; 35 | 36 | CNikPEVTreeViewCtrl m_cPEVTreeCtrl; 37 | CNikPEVHeaderList m_cPEVHeaderList; 38 | CNikImportFunList m_cPEVImportList; 39 | CNikExportFunList m_cPEVExportList; 40 | CNikPEBinaryViewer m_cPEBinaryViewer; 41 | CNikDataSectionList m_cDataSectionList; 42 | //CNikDisAssemblyList m_cDisAssemblyList; 43 | CNikDisassemblyWin m_cDisAssemblyList; 44 | CNikResourceItemsList m_cResourceItemsList; 45 | CNikHTMLWindow m_cNikHTMLWindow; 46 | 47 | RESOURCELIST * m_pstResourceList; 48 | 49 | EXECUTABLE_INFO m_stExecutableInfo; 50 | IMAGE_DOS_HEADER m_stImageDosHeader; 51 | IMAGE_NT_HEADERS32 m_stImageNtHeaders32; 52 | IMAGE_NT_HEADERS64 m_stImageNtHeaders64; 53 | 54 | vector m_vImportDllList; 55 | vector m_vExportFunctionList; 56 | vector m_vImageSectionHeaderList; 57 | 58 | vector m_vNikDialogList; 59 | 60 | vector m_vMenuViewerList; 61 | vector m_vStringViewerList; 62 | vector m_vVersionViewerList; 63 | vector m_vMessageViewerList; 64 | vector m_vResourceViewerList; 65 | vector m_vAccelaratorViewerList; 66 | 67 | vector m_vIconEditorList; 68 | vector m_vCursorEditorList; 69 | vector m_vBitmapEditorList; 70 | 71 | public: 72 | CNikPEViewer(); 73 | virtual ~CNikPEViewer(); 74 | 75 | HWND GetWindowHandle() 76 | { 77 | return m_hWnd; 78 | } 79 | void SetWindowHandle( HWND hWnd ) 80 | { 81 | m_hWnd = hWnd; 82 | } 83 | 84 | BYTE * GetPEBuffer() 85 | { 86 | return m_pPEBuffer; 87 | } 88 | 89 | HINSTANCE GetPEViewerInstance() 90 | { 91 | return m_hInstance; 92 | } 93 | 94 | const IMAGE_DOS_HEADER &GetImageDosHeader() 95 | { 96 | return m_stImageDosHeader; 97 | } 98 | const IMAGE_NT_HEADERS &GetImageNtHeaders() 99 | { 100 | if(m_stImageNtHeaders32.OptionalHeader.Magic == 0x020b) 101 | return (const IMAGE_NT_HEADERS32 &)m_stImageNtHeaders64; 102 | else 103 | return m_stImageNtHeaders32; 104 | } 105 | const vector &GetImportFunctionList() 106 | { 107 | return m_vImportDllList; 108 | } 109 | const vector &GetExportFunctionList() 110 | { 111 | return m_vExportFunctionList; 112 | } 113 | const vector &GetImageSectionHeaderList() 114 | { 115 | return m_vImageSectionHeaderList; 116 | } 117 | const RESOURCELIST * GetResourceItemsList() 118 | { 119 | return m_pstResourceList; 120 | } 121 | const EXECUTABLE_INFO &GetExecutableInfo() 122 | { 123 | return m_stExecutableInfo; 124 | } 125 | 126 | _tstring GetModuleFileName() 127 | { 128 | return m_strFileName; 129 | } 130 | _tstring GetModuleShortName() 131 | { 132 | return m_strShortName; 133 | } 134 | DWORD GetModuleFileSize() 135 | { 136 | return m_dwPEFileSize; 137 | } 138 | 139 | CNikPEBinaryViewer &GetBinaryViewer() 140 | { 141 | return m_cPEBinaryViewer; 142 | } 143 | 144 | int GetDiffAddOffset() 145 | { 146 | return m_nDiffOffset; 147 | } 148 | 149 | //CNikDisAssemblyList &GetDisAssemblyList() 150 | CNikDisassemblyWin &GetDisAssemblyList() 151 | { 152 | return m_cDisAssemblyList; 153 | } 154 | 155 | int ShowPESammaryView(int nShow = FALSE) 156 | { 157 | if(nShow) 158 | return SetWindowPos( m_cPEVTreeCtrl.GetWindowHandle(), HWND_TOP 159 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 160 | else 161 | { 162 | if(TRUE == IsWindowVisible( m_cPEVTreeCtrl.GetWindowHandle() )) 163 | return ShowWindow( m_cPEVTreeCtrl.GetWindowHandle(), SW_HIDE ); 164 | else 165 | return SetWindowPos( m_cPEVTreeCtrl.GetWindowHandle(), HWND_TOP 166 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 167 | } 168 | } 169 | 170 | int ShowPEImportListView(int nShow = FALSE) 171 | { 172 | if(nShow) 173 | return SetWindowPos( m_cPEVImportList.GetWindowHandle(), HWND_TOP 174 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 175 | else 176 | { 177 | if(TRUE == IsWindowVisible( m_cPEVImportList.GetWindowHandle() )) 178 | return ShowWindow( m_cPEVImportList.GetWindowHandle(), SW_HIDE ); 179 | else 180 | return SetWindowPos( m_cPEVImportList.GetWindowHandle(), HWND_TOP 181 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 182 | } 183 | } 184 | 185 | int ShowPEExportListView(int nShow = FALSE) 186 | { 187 | if(nShow) 188 | return SetWindowPos( m_cPEVExportList.GetWindowHandle(), HWND_TOP 189 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 190 | else 191 | { 192 | if(TRUE == IsWindowVisible( m_cPEVExportList.GetWindowHandle() )) 193 | return ShowWindow( m_cPEVExportList.GetWindowHandle(), SW_HIDE ); 194 | else 195 | return SetWindowPos( m_cPEVExportList.GetWindowHandle(), HWND_TOP 196 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 197 | } 198 | } 199 | 200 | int ShowPEHeadersView(int nShow = FALSE) 201 | { 202 | if(nShow) 203 | return SetWindowPos( m_cPEVHeaderList.GetWindowHandle(), HWND_TOP 204 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 205 | else 206 | { 207 | if(TRUE == IsWindowVisible( m_cPEVHeaderList.GetWindowHandle() )) 208 | return ShowWindow( m_cPEVHeaderList.GetWindowHandle(), SW_HIDE ); 209 | else 210 | return SetWindowPos( m_cPEVHeaderList.GetWindowHandle(), HWND_TOP 211 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 212 | } 213 | } 214 | 215 | int ShowPEBinaryView(int nShow = FALSE) 216 | { 217 | if(nShow) 218 | return SetWindowPos( m_cPEBinaryViewer.GetWindowHandle(), HWND_TOP 219 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 220 | else 221 | { 222 | if(TRUE == IsWindowVisible( m_cPEBinaryViewer.GetWindowHandle() )) 223 | return ShowWindow( m_cPEBinaryViewer.GetWindowHandle(), SW_HIDE ); 224 | else 225 | return SetWindowPos( m_cPEBinaryViewer.GetWindowHandle(), HWND_TOP 226 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 227 | } 228 | } 229 | 230 | int ShowPEDataSectionsView(int nShow = FALSE) 231 | { 232 | if(nShow) 233 | return SetWindowPos( m_cDataSectionList.GetWindowHandle(), HWND_TOP 234 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 235 | else 236 | { 237 | if(TRUE == IsWindowVisible( m_cDataSectionList.GetWindowHandle() )) 238 | return ShowWindow( m_cDataSectionList.GetWindowHandle(), SW_HIDE ); 239 | else 240 | return SetWindowPos( m_cDataSectionList.GetWindowHandle(), HWND_TOP 241 | , 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE); 242 | } 243 | } 244 | 245 | int ShowPEAllSectionView() 246 | { 247 | ShowPEImportListView( TRUE ); 248 | ShowPEExportListView( TRUE ); 249 | ShowPEDataSectionsView( TRUE ); 250 | ShowPEHeadersView( TRUE ); 251 | ShowPESammaryView( TRUE ); 252 | ShowPEDataSectionsView( TRUE ); 253 | ShowPEBinaryView( TRUE ); 254 | ShowCodeDisassembly( TRUE ); 255 | ShowPEHtmlView(); 256 | 257 | return 0; 258 | } 259 | int ShowPEHtmlView(); 260 | 261 | virtual int InitPEFrameWindow(); 262 | virtual int SetAllViewsDefaultPos(); 263 | virtual int DecodePEFile(_tstring ); 264 | virtual int SavePEFileRecords(_tstring ); 265 | virtual int RegisterNikWindows( HINSTANCE ); 266 | virtual HWND CreatePEFrameWindow(HINSTANCE , HWND ); 267 | 268 | void CreateExecutableInfo( BYTE * pBuf 269 | , DWORD dwSize 270 | , PIMAGE_NT_HEADERS pNTHeader 271 | , PIMAGE_SECTION_HEADER pNTSection); 272 | 273 | void CreateImportFunctionList( BYTE * , DWORD , DWORD , int 274 | , PIMAGE_NT_HEADERS , PIMAGE_SECTION_HEADER ); 275 | 276 | void CreateExportFunctionList(BYTE * , DWORD , DWORD , int 277 | , PIMAGE_NT_HEADERS , PIMAGE_SECTION_HEADER ); 278 | 279 | void CreateResourceList(BYTE * ,int ); 280 | void GetResourceName(DWORD ,TCHAR * ); 281 | RESOURCELIST * DecodeResourceItems(BYTE * ,int ,int ); 282 | int SavePEHtmlFilePart(_tstring , _tstring , _tstring ); 283 | void DecodeDirResourceEntry(BYTE * , int , int , int , RESOURCELIST * ); 284 | 285 | static _tstring OpenFileDialogBox(HWND hWnd); 286 | static _tstring SaveFileDialogBox(HWND hWnd); 287 | static LRESULT CALLBACK PEViewerWndProc( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam ); 288 | 289 | int ShowCodeDisassembly(int nShow = FALSE); 290 | static DWORD GetHexValues(_tstring str); 291 | static _tstring GetVersionOSName( DWORD dwOScode); 292 | static _tstring GetVerResourceType( DWORD dwType ); 293 | static _tstring GetVerResLanguage( DWORD dwResLang ); 294 | static int GetMachineName(int nCode, int nStrSize, TCHAR *chMachine); 295 | static int GetNTOptionalSubsystem(int nCode, int nStrSize, TCHAR *chBuf); 296 | static int GetNTCharacteristics(WORD wCharacteristics, _tstring &strChar); 297 | static int GetStrDateTimeStamp(DWORD dwDateTime, int nStrSize, TCHAR *chBuf); 298 | static int GetDirectoryEnteries(int i, int nStrSize, TCHAR *chBuf); 299 | static int GetNTSectionCharacteristics(DWORD dwCharacteristics, _tstring &strChar); 300 | }; -------------------------------------------------------------------------------- /NikPEViewer/NikHTMLView.h: -------------------------------------------------------------------------------- 1 | 2 | #define NOTIMPLEMENTED return E_NOTIMPL 3 | 4 | class CNikHTMLWindow; 5 | 6 | class CNullStorage: public IStorage 7 | { 8 | public: 9 | 10 | CNikHTMLWindow * m_pNikHTMLWin; 11 | 12 | // IUnknown 13 | STDMETHODIMP QueryInterface(REFIID //riid 14 | ,void ** //ppvObject 15 | ) 16 | { NOTIMPLEMENTED; } 17 | STDMETHODIMP_(ULONG) AddRef(void) 18 | { return (ULONG)E_NOTIMPL; } 19 | STDMETHODIMP_(ULONG) Release(void) 20 | { return (ULONG)E_NOTIMPL; } 21 | 22 | // IStorage 23 | STDMETHODIMP CreateStream(const WCHAR * //pwcsName 24 | ,DWORD //grfMode 25 | ,DWORD //reserved1 26 | ,DWORD //reserved2 27 | ,IStream ** //ppstm 28 | ) 29 | { NOTIMPLEMENTED; } 30 | STDMETHODIMP OpenStream(const WCHAR * //pwcsName 31 | ,void * //reserved1 32 | ,DWORD //grfMode 33 | ,DWORD //reserved2 34 | ,IStream ** //ppstm 35 | ) 36 | { NOTIMPLEMENTED; } 37 | STDMETHODIMP CreateStorage(const WCHAR * //pwcsName 38 | ,DWORD //grfMode 39 | ,DWORD //reserved1 40 | ,DWORD //reserved2 41 | ,IStorage ** //ppstg 42 | ) 43 | { NOTIMPLEMENTED; } 44 | STDMETHODIMP OpenStorage(const WCHAR * //pwcsName 45 | ,IStorage * //pstgPriority 46 | ,DWORD //grfMode 47 | ,SNB //snbExclude 48 | ,DWORD //reserved 49 | ,IStorage ** //ppstg 50 | ) 51 | { NOTIMPLEMENTED; } 52 | STDMETHODIMP CopyTo(DWORD //ciidExclude 53 | ,IID const * //rgiidExclude 54 | ,SNB //snbExclude 55 | ,IStorage * //pstgDest 56 | ) 57 | { NOTIMPLEMENTED; } 58 | STDMETHODIMP MoveElementTo(const OLECHAR * //pwcsName 59 | ,IStorage * //pstgDest 60 | ,const OLECHAR* //pwcsNewName 61 | ,DWORD //grfFlags 62 | ) 63 | { NOTIMPLEMENTED; } 64 | STDMETHODIMP Commit(DWORD /*grfCommitFlags*/) 65 | { NOTIMPLEMENTED; } 66 | STDMETHODIMP Revert(void) 67 | { NOTIMPLEMENTED; } 68 | STDMETHODIMP EnumElements(DWORD //reserved1 69 | ,void * //reserved2 70 | ,DWORD //reserved3 71 | ,IEnumSTATSTG ** //ppenum 72 | ) 73 | { NOTIMPLEMENTED; } 74 | STDMETHODIMP DestroyElement(const OLECHAR * /*pwcsName*/) 75 | { NOTIMPLEMENTED; } 76 | STDMETHODIMP RenameElement(const WCHAR * //pwcsOldName 77 | ,const WCHAR * //pwcsNewName 78 | ) 79 | { NOTIMPLEMENTED; } 80 | STDMETHODIMP SetElementTimes(const WCHAR * //pwcsName 81 | ,FILETIME const * //pctime 82 | ,FILETIME const * //patime 83 | ,FILETIME const * //pmtime 84 | ) 85 | { NOTIMPLEMENTED; } 86 | STDMETHODIMP SetStateBits(DWORD //grfStateBits 87 | ,DWORD //grfMask 88 | ) 89 | { NOTIMPLEMENTED; } 90 | STDMETHODIMP Stat(STATSTG * //pstatstg 91 | ,DWORD //grfStatFlag 92 | ) 93 | { NOTIMPLEMENTED; } 94 | STDMETHODIMP SetClass(REFCLSID /*clsid*/) 95 | { return S_OK; } 96 | }; 97 | 98 | class CHtmlFrame: public IOleInPlaceFrame 99 | { 100 | public: 101 | 102 | CNikHTMLWindow * m_pNikHTMLWin; 103 | 104 | // IUnknown 105 | STDMETHODIMP QueryInterface(REFIID //riid 106 | ,void ** //ppvObject 107 | ) 108 | { NOTIMPLEMENTED; } 109 | STDMETHODIMP_(ULONG) AddRef(void) 110 | { return 1;} 111 | STDMETHODIMP_(ULONG) Release(void) 112 | { return 1;} 113 | 114 | // IOleWindow 115 | STDMETHODIMP GetWindow(HWND FAR* /*lphwnd*/); 116 | STDMETHODIMP ContextSensitiveHelp(BOOL /*fEnterMode*/) 117 | { NOTIMPLEMENTED; } 118 | 119 | // IOleInPlaceUIWindow 120 | STDMETHODIMP GetBorder(LPRECT /*lprectBorder*/) 121 | { NOTIMPLEMENTED; } 122 | STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS /*pborderwidths*/) 123 | { NOTIMPLEMENTED; } 124 | STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS /*pborderwidths*/) 125 | { NOTIMPLEMENTED; } 126 | STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject * //pActiveObject 127 | ,LPCOLESTR //pszObjName 128 | ) 129 | { return S_OK; } 130 | 131 | // IOleInPlaceFrame 132 | STDMETHODIMP InsertMenus(HMENU //hmenuShared 133 | ,LPOLEMENUGROUPWIDTHS //lpMenuWidths 134 | ) 135 | { NOTIMPLEMENTED; } 136 | STDMETHODIMP SetMenu(HMENU //hmenuShared 137 | ,HOLEMENU //holemenu 138 | ,HWND //hwndActiveObject 139 | ) 140 | { return S_OK; } 141 | STDMETHODIMP RemoveMenus(HMENU /*hmenuShared*/) 142 | { NOTIMPLEMENTED; } 143 | STDMETHODIMP SetStatusText(LPCOLESTR /*pszStatusText*/) 144 | { return S_OK; } 145 | STDMETHODIMP EnableModeless(BOOL /*fEnable*/) 146 | { return S_OK; } 147 | STDMETHODIMP TranslateAccelerator( LPMSG //lpmsg 148 | ,WORD //wID 149 | ) 150 | { NOTIMPLEMENTED; } 151 | }; 152 | 153 | class CHtmlSite: public IOleClientSite, public IOleInPlaceSite 154 | { 155 | public: 156 | 157 | CNikHTMLWindow * m_pNikHTMLWin; 158 | 159 | // IUnknown 160 | STDMETHODIMP QueryInterface(REFIID //riid 161 | , void ** //ppvObject 162 | ); 163 | STDMETHODIMP_(ULONG) AddRef(void) 164 | { return 1;} 165 | STDMETHODIMP_(ULONG) Release(void) 166 | { return 1;} 167 | 168 | // IOleClientSite 169 | STDMETHODIMP SaveObject() 170 | { NOTIMPLEMENTED; } 171 | STDMETHODIMP GetMoniker(DWORD //dwAssign 172 | ,DWORD //dwWhichMoniker 173 | ,IMoniker ** //ppmk 174 | ) 175 | { NOTIMPLEMENTED; } 176 | STDMETHODIMP GetContainer(LPOLECONTAINER FAR* /*ppContainer*/); 177 | STDMETHODIMP ShowObject() 178 | { return S_OK; } 179 | STDMETHODIMP OnShowWindow(BOOL /*fShow*/) 180 | { NOTIMPLEMENTED; } 181 | STDMETHODIMP RequestNewObjectLayout() 182 | { NOTIMPLEMENTED; } 183 | 184 | // IOleWindow 185 | STDMETHODIMP GetWindow(HWND FAR* /*lphwnd*/); 186 | STDMETHODIMP ContextSensitiveHelp(BOOL /*fEnterMode*/) 187 | { NOTIMPLEMENTED; } 188 | 189 | // IOleInPlaceSite methods 190 | STDMETHODIMP CanInPlaceActivate() 191 | { return S_OK; } 192 | STDMETHODIMP OnInPlaceActivate() 193 | { return S_OK; } 194 | STDMETHODIMP OnUIActivate() 195 | { return S_OK; } 196 | STDMETHODIMP GetWindowContext(LPOLEINPLACEFRAME FAR* //lplpFrame 197 | ,LPOLEINPLACEUIWINDOW FAR* //lplpDoc 198 | ,LPRECT //lprcPosRect 199 | ,LPRECT //lprcClipRect 200 | ,LPOLEINPLACEFRAMEINFO //lpFrameInfo 201 | ); 202 | STDMETHODIMP Scroll(SIZE /*scrollExtent*/) 203 | { NOTIMPLEMENTED; } 204 | STDMETHODIMP OnUIDeactivate(BOOL /*fUndoable*/) 205 | { return S_OK; } 206 | STDMETHODIMP OnInPlaceDeactivate() 207 | { return S_OK; } 208 | STDMETHODIMP DiscardUndoState() 209 | { NOTIMPLEMENTED; } 210 | STDMETHODIMP DeactivateAndUndo() 211 | { NOTIMPLEMENTED; } 212 | STDMETHODIMP OnPosRectChange(LPCRECT /*lprcPosRect*/); 213 | }; 214 | 215 | /*class CHtmlUIHandler : public IDocHostUIHandler 216 | { 217 | public: 218 | 219 | CNikHTMLWindow * m_pNikHTMLWin; 220 | 221 | // IUnknown 222 | HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppv) 223 | { NOTIMPLEMENTED; } 224 | STDMETHODIMP_(ULONG) AddRef(void) 225 | { return 1;} 226 | STDMETHODIMP_(ULONG) Release(void) 227 | { return 1;} 228 | 229 | // IDocHostUIHandler 230 | HRESULT STDMETHODCALLTYPE ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved) 231 | {return S_OK;} 232 | HRESULT STDMETHODCALLTYPE GetHostInfo(DOCHOSTUIINFO *pInfo) 233 | { 234 | //pInfo->dwFlags=0; 235 | return S_OK; 236 | //NOTIMPLEMENTED; 237 | } 238 | HRESULT STDMETHODCALLTYPE ShowUI(DWORD dwID, IOleInPlaceActiveObject *pActiveObject, 239 | IOleCommandTarget *pCommandTarget,IOleInPlaceFrame *pFrame,IOleInPlaceUIWindow *pDoc) 240 | {return S_OK;} 241 | HRESULT STDMETHODCALLTYPE HideUI() 242 | {return S_OK;} 243 | HRESULT STDMETHODCALLTYPE UpdateUI() 244 | {return S_OK;} 245 | HRESULT STDMETHODCALLTYPE EnableModeless(BOOL fEnable) 246 | {return S_OK;} 247 | HRESULT STDMETHODCALLTYPE OnDocWindowActivate(BOOL fActivate) 248 | {return S_OK;} 249 | HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(BOOL fActivate) 250 | {return S_OK;} 251 | HRESULT STDMETHODCALLTYPE ResizeBorder(LPCRECT prcBorder,IOleInPlaceUIWindow *pUIWindow,BOOL fRameWindow) 252 | {return S_OK;} 253 | HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpMsg,const GUID *pguidCmdGroup,DWORD nCmdID) 254 | {return S_FALSE;} 255 | HRESULT STDMETHODCALLTYPE GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw) 256 | {return S_FALSE;} 257 | HRESULT STDMETHODCALLTYPE GetDropTarget(IDropTarget *pDropTarget,IDropTarget **ppDropTarget) 258 | {return S_FALSE;} 259 | HRESULT STDMETHODCALLTYPE GetExternal(IDispatch **ppDispatch) 260 | {*ppDispatch=0; return S_FALSE;} 261 | HRESULT STDMETHODCALLTYPE TranslateUrl(DWORD dwTranslate,OLECHAR *pchURLIn,OLECHAR **ppchURLOut) 262 | {*ppchURLOut=0; return S_FALSE;} 263 | HRESULT STDMETHODCALLTYPE FilterDataObject(IDataObject *pDO,IDataObject **ppDORet) 264 | {*ppDORet=0; return S_FALSE;} 265 | };*/ 266 | 267 | class CNikHTMLWindow 268 | { 269 | //protected: 270 | public: 271 | 272 | HWND m_hWnd; 273 | HINSTANCE m_hInstance; 274 | 275 | CHtmlSite m_cSite; 276 | CHtmlFrame m_cFrame; 277 | CNullStorage m_cStorage; 278 | IOleObject* m_pWebObject; 279 | //CHtmlUIHandler m_cUIHandler; 280 | 281 | void * m_pNikPEViewer; 282 | 283 | public: 284 | 285 | CNikHTMLWindow(); 286 | virtual ~CNikHTMLWindow(); 287 | 288 | HWND GetWindowHandle() 289 | { 290 | return m_hWnd; 291 | } 292 | 293 | void SetTable1ColValue(_tstring &strHtmlText, TCHAR* strRow1); 294 | void SetTable2ColValue(_tstring &strHtmlText, TCHAR* strRow1, DWORD nValue); 295 | void SetTable2ColStr(_tstring &strHtmlText, TCHAR* strRow1, TCHAR* strValue); 296 | 297 | _tstring CreatePEDosHrHtmlPageStr(); 298 | _tstring CreatePENTHtmlPageString(); 299 | _tstring CreateDataHtmlPageString(); 300 | _tstring CreateImportHtmlPageString(); 301 | _tstring CreateExportHtmlPageString(); 302 | _tstring CreateSectionHtmlPageString(); 303 | 304 | void Fill_IMAGE_DOS_HEADER(_tstring &); 305 | void Fill_IMAGE_NT_HEADERS(_tstring &); 306 | 307 | int Fill_IMAGE_NT_SECTION_DETAILS(_tstring &); 308 | int Fill_IMAGE_NT_DATA_DIRECTORY(_tstring &); 309 | 310 | int Fill_IMAGE_NT_IMPORT_TABLE(_tstring &); 311 | int Fill_IMAGE_NT_EXPORT_TABLE(_tstring &); 312 | 313 | _tstring SetTreeItemStr(void * ); 314 | _tstring GetHtmlStrVersion(void * ); 315 | _tstring GetHtmlResMenuItems(void * ); 316 | _tstring GetHtmlStrAccelarator(void * ); 317 | _tstring GetHtmlResStringTable(void * ); 318 | _tstring InitHtmlTableResMenu(MENU_INFO * ); 319 | 320 | _tstring GetHtmlResBitmap(void * , TCHAR *, TCHAR *); 321 | 322 | void SetTableColumnVal(TCHAR * , _tstring &, TCHAR *); 323 | 324 | static int GetEncoderClsid(const WCHAR* format, CLSID* pClsid); 325 | int SaveBitmapResBuffer(BYTE * pBuffer, int nSize, int nFlag,_tstring ); 326 | 327 | HRESULT CreateEmbeddedWebControl(void * pNikPEViewer); 328 | void UnCreateEmbeddedWebControl(void); 329 | virtual HWND CreateHTMLWindow(HINSTANCE , HWND , RECT , _tstring ); 330 | HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream); 331 | }; 332 | -------------------------------------------------------------------------------- /NikPEViewer/MenuWnd.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "stdafx.h" 3 | #include "MenuWnd.h" 4 | #include "DialogWnd.h" 5 | #include "ResourceWnd.h" 6 | 7 | HWND CMenuWnd::CreateMyTooltip() 8 | { 9 | /////------------------------------------- 10 | TOOLINFOA ti; 11 | char strTT[2] = ""; 12 | RECT rect; 13 | 14 | HWND hToolTip = CreateWindowEx(WS_EX_TOPMOST, 15 | TOOLTIPS_CLASS, 16 | NULL, 17 | WS_VISIBLE | WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, 18 | CW_USEDEFAULT, 19 | CW_USEDEFAULT, 20 | CW_USEDEFAULT, 21 | CW_USEDEFAULT, 22 | m_hWnd, 23 | NULL, 24 | GetWindowInstance(m_hParentWnd), 25 | NULL 26 | ); 27 | 28 | SetWindowPos( hToolTip, HWND_TOPMOST, 0, 0, 0, 0, 29 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 30 | 31 | GetClientRect (m_hWnd, &rect); 32 | 33 | ti.cbSize = sizeof(TOOLINFO); 34 | ti.uFlags = TTF_SUBCLASS; 35 | ti.hwnd = m_hWnd; 36 | ti.hinst = GetWindowInstance(m_hParentWnd); 37 | ti.uId = 0; 38 | ti.lpszText = strTT; 39 | ti.rect.left = rect.left; 40 | ti.rect.top = rect.top; 41 | ti.rect.right = rect.right; 42 | ti.rect.bottom = rect.bottom; 43 | 44 | SendMessage(hToolTip, TTM_ADDTOOLA, 0, (LPARAM) (LPTOOLINFO) &ti); 45 | /////------------------------------------- 46 | 47 | return hToolTip; 48 | } 49 | 50 | CMenuWnd::CMenuWnd() 51 | { 52 | m_hWnd = NULL; 53 | m_hParentWnd = NULL; 54 | 55 | m_hFont = NULL; 56 | 57 | m_hToolTip = NULL; 58 | m_pcMenuWnd = NULL; 59 | } 60 | 61 | CMenuWnd::~CMenuWnd() 62 | { 63 | if(IsWindow(m_hWnd)) 64 | DestroyWindow(m_hWnd); 65 | 66 | if(m_pcMenuWnd) 67 | { 68 | DestroyWindow(m_pcMenuWnd->GethWnd()); 69 | delete m_pcMenuWnd; 70 | } 71 | } 72 | 73 | int CMenuWnd::RegisterMenuclass(HINSTANCE hInstance) 74 | { 75 | WNDCLASS wc; 76 | memset(&wc,0,sizeof(wc)); 77 | 78 | wc.lpfnWndProc = (WNDPROC)CMenuWnd::MenuWndProc; 79 | wc.cbClsExtra = 0; 80 | wc.cbWndExtra = 0; 81 | wc.hInstance = hInstance; 82 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 83 | wc.hIcon = (HICON)LoadIcon(hInstance,MAKEINTRESOURCE(IDC_NIKPEVIEWER)); 84 | wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 85 | wc.lpszClassName = CLASS_MENU; 86 | wc.lpszMenuName = NULL; 87 | 88 | if (!RegisterClass(&wc)) 89 | return FALSE; 90 | 91 | return TRUE; 92 | } 93 | 94 | void CMenuWnd::OnLbuttonDown(WPARAM //wParam 95 | , LPARAM lParam) 96 | { 97 | POINT pt; 98 | pt.x = GET_X_LPARAM(lParam); 99 | pt.y = GET_Y_LPARAM(lParam); 100 | 101 | RECT rc; 102 | for(int i=0;i<(int)m_stMenuInfo.m_vMenuList.size();i++) 103 | { 104 | rc = m_stMenuInfo.m_vMenuList.at(i).m_rRect; 105 | 106 | if(PtInRect(&rc,pt)) 107 | { 108 | MENU_INFO stMenu = m_stMenuInfo.m_vMenuList.at(i); 109 | if(stMenu.m_wFlag & MF_POPUP) 110 | { 111 | if(m_pcMenuWnd) 112 | { 113 | DestroyWindow(m_pcMenuWnd->GethWnd()); 114 | delete m_pcMenuWnd; 115 | m_pcMenuWnd = NULL; 116 | } 117 | 118 | m_pcMenuWnd = new CMenuWnd; 119 | if(m_pcMenuWnd) 120 | { 121 | m_pcMenuWnd->CreateMenuWindow(m_hParentWnd 122 | , m_hWnd, m_stMenuInfo.m_vMenuList.at(i)); 123 | } 124 | } 125 | break; 126 | } 127 | } 128 | } 129 | 130 | void CMenuWnd::OnLbuttonUP(WPARAM //wParam 131 | , LPARAM //lParam 132 | ) 133 | { 134 | } 135 | 136 | void CMenuWnd::OnMouseMove(WPARAM //wParam 137 | , LPARAM lParam) 138 | { 139 | POINT pt; 140 | pt.x = GET_X_LPARAM(lParam); 141 | pt.y = GET_Y_LPARAM(lParam); 142 | 143 | HDC hdc = GetDC(m_hWnd); 144 | 145 | RECT rcWnd; 146 | GetClientRect(m_hWnd,&rcWnd); 147 | HDC hdcComp = CreateCompatibleDC(hdc); 148 | HBITMAP hbmComp = CreateCompatibleBitmap(hdc, rcWnd.right, rcWnd.bottom); 149 | SelectObject(hdcComp,hbmComp); 150 | 151 | HFONT hOldFont = (HFONT)SelectObject(hdcComp,m_hFont); 152 | 153 | int nBKMode = SetBkMode(hdcComp,TRANSPARENT); 154 | 155 | RECT rc; 156 | for(int i=0;i<(int)m_stMenuInfo.m_vMenuList.size();i++) 157 | { 158 | MENU_INFO stMenu = m_stMenuInfo.m_vMenuList.at(i); 159 | 160 | rc = m_stMenuInfo.m_vMenuList.at(i).m_rRect; 161 | 162 | if(!stMenu.m_strText.empty()) 163 | { 164 | _tstring strText = _T(" "); 165 | strText += stMenu.m_strText; 166 | 167 | if(PtInRect(&rc,pt)) 168 | { 169 | ////---------------------- 170 | char chToolStr[1024]; 171 | chToolStr[0] = chToolStr[255] = 0; 172 | TOOLINFOA ti; 173 | memset(&ti, 0, sizeof(TOOLINFO)); 174 | ti.cbSize = sizeof(TOOLINFO); 175 | ti.hwnd = m_hWnd; 176 | ti.hinst = GetWindowInstance(m_hParentWnd); 177 | if(stMenu.m_wMenuID) 178 | sprintf_s(chToolStr, 1023, "Menu ID = 0x%04X", stMenu.m_wMenuID); 179 | else 180 | sprintf_s(chToolStr, 1023, "Click to POP-UP the Menu"); 181 | ti.lpszText = (char *)chToolStr; 182 | SendMessage(m_hToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM) (LPTOOLINFO)&ti); 183 | ////---------------------- 184 | 185 | DrawMenuText(hdcComp,rc,strText,1); 186 | } 187 | else 188 | DrawMenuText(hdcComp,rc,strText,0); 189 | 190 | if(stMenu.m_wFlag & MF_POPUP) 191 | { 192 | RECT rcTemp = rc; 193 | rcTemp.left = rc.right - 20; 194 | DrawFrameControl(hdcComp,&rcTemp,DFC_MENU,DFCS_MENUARROW); 195 | } 196 | } 197 | else 198 | { 199 | CNikDialog::DrawRectArea(hdcComp 200 | , rc 201 | , RGB(255,255,255)); 202 | MoveToEx(hdcComp,rc.left,rc.top+4,NULL); 203 | LineTo(hdcComp,rc.right,rc.top+4); 204 | MoveToEx(hdcComp,rc.left,rc.top+6,NULL); 205 | LineTo(hdcComp,rc.right,rc.top+6); 206 | } 207 | } 208 | 209 | BitBlt(hdc,0,0,rcWnd.right,rcWnd.bottom,hdcComp,0,0,SRCCOPY); 210 | SetBkMode(hdcComp,nBKMode); 211 | 212 | SelectObject(hdcComp,hOldFont); 213 | 214 | DeleteObject(hbmComp); 215 | DeleteDC(hdcComp); 216 | 217 | ReleaseDC(m_hWnd,hdc); 218 | } 219 | 220 | RECT CMenuWnd::SetMenuSize() 221 | { 222 | RECT rcWnd,rc; 223 | rc.left = rc.right = rc.top = rc.bottom = 0; 224 | rcWnd.left = rcWnd.right = rcWnd.bottom = rcWnd.top = 0; 225 | 226 | HDC hdc = GetDC(m_hWnd); 227 | if(NULL == hdc) 228 | return rcWnd; 229 | 230 | for(int i=0;i<(int)m_stMenuInfo.m_vMenuList.size();i++) 231 | { 232 | MENU_INFO stMenu = m_stMenuInfo.m_vMenuList.at(i); 233 | 234 | if(stMenu.m_strText.length()) 235 | { 236 | _tstring strText = stMenu.m_strText; 237 | 238 | int nPos = strText.find(_T('\t'),0); 239 | while(nPos >= 0) 240 | { 241 | strText.replace(strText.begin()+nPos 242 | , strText.begin() + nPos + 1 243 | , _T(" ")); 244 | nPos = strText.find(_T('\t'),nPos); 245 | } 246 | 247 | int nTabSize = 4; 248 | DWORD dwSize = GetTabbedTextExtent(hdc,strText.data() 249 | , strText.length(),0,&nTabSize); 250 | 251 | rc.right = rc.left + (dwSize & 0xFFFF) + 5; 252 | rc.bottom = rc.top + (dwSize>>16) + 10; 253 | 254 | m_stMenuInfo.m_vMenuList.at(i).m_rRect = rc; 255 | 256 | rcWnd.bottom = rc.bottom; 257 | 258 | OffsetRect(&rc,0,(rc.bottom-rc.top)); 259 | } 260 | else 261 | { 262 | rc.bottom = rc.top + 10; 263 | m_stMenuInfo.m_vMenuList.at(i).m_rRect = rc; 264 | OffsetRect(&rc,0,10); 265 | } 266 | 267 | if(rcWnd.right < rc.right) 268 | rcWnd.right = rc.right; 269 | } 270 | 271 | ReleaseDC(m_hWnd,hdc); 272 | 273 | RECT * pRect; 274 | for(int i=0;i<(int)m_stMenuInfo.m_vMenuList.size();i++) 275 | { 276 | pRect = &m_stMenuInfo.m_vMenuList.at(i).m_rRect; 277 | pRect->left = 0; 278 | pRect->right = rcWnd.right; 279 | } 280 | 281 | return rcWnd; 282 | } 283 | 284 | void CMenuWnd::DrawMenuText(HDC hdc 285 | , RECT &rc 286 | , _tstring &strText 287 | , int nHighlightItem) 288 | { 289 | DRAWTEXTPARAMS stExtParams; 290 | stExtParams.cbSize = sizeof(DRAWTEXTPARAMS); 291 | stExtParams.iLeftMargin = 0; 292 | stExtParams.iRightMargin = 0; 293 | stExtParams.iTabLength = 8; 294 | stExtParams.uiLengthDrawn = 0; 295 | 296 | if(nHighlightItem) 297 | CNikDialog::DrawRectArea(hdc,rc,RGB(216,216,216)); 298 | else 299 | CNikDialog::DrawRectArea(hdc,rc,RGB(255,255,255)); 300 | 301 | DrawTextEx(hdc 302 | , (LPWSTR)strText.data() 303 | , strText.length() 304 | , &rc 305 | , DT_LEFT | DT_EXPANDTABS | DT_VCENTER | DT_SINGLELINE 306 | , &stExtParams); 307 | } 308 | 309 | void CMenuWnd::DrawMenuItems(HDC hdc) 310 | { 311 | if(hdc) 312 | { 313 | int nBKMode = SetBkMode(hdc,TRANSPARENT); 314 | 315 | RECT rc; 316 | rc.left = rc.right = rc.top = rc.bottom = 0; 317 | 318 | RECT rcWnd; 319 | rcWnd.left = rcWnd.right = rcWnd.bottom = rcWnd.top = 0; 320 | 321 | GetClientRect(m_hWnd,&rcWnd); 322 | 323 | HDC hdcComp = CreateCompatibleDC(hdc); 324 | HBITMAP hbmComp = CreateCompatibleBitmap(hdc, rcWnd.right, rcWnd.bottom); 325 | SelectObject(hdcComp,hbmComp); 326 | 327 | HFONT hOldFont = (HFONT)SelectObject(hdcComp,m_hFont); 328 | 329 | CNikDialog::DrawLineRect(hdcComp, rcWnd, RGB(0,0,0), 0); 330 | 331 | int nMode = SetBkMode(hdcComp,TRANSPARENT); 332 | 333 | for(int i=0;i<(int)m_stMenuInfo.m_vMenuList.size();i++) 334 | { 335 | MENU_INFO stMenu = m_stMenuInfo.m_vMenuList.at(i); 336 | 337 | RECT rec = m_stMenuInfo.m_vMenuList.at(i).m_rRect; 338 | 339 | if(stMenu.m_strText.length()) 340 | { 341 | _tstring strText = _T(" "); 342 | strText += stMenu.m_strText; 343 | 344 | DrawMenuText(hdcComp,rec,strText,0); 345 | 346 | if(stMenu.m_wFlag & MF_POPUP) 347 | { 348 | RECT rcTemp = rec; 349 | rcTemp.left = rec.right - 20; 350 | DrawFrameControl(hdcComp,&rcTemp,DFC_MENU,DFCS_MENUARROW); 351 | } 352 | 353 | OffsetRect(&rc,0,(rc.bottom-rc.top)+5); 354 | } 355 | else 356 | { 357 | CNikDialog::DrawRectArea(hdcComp,rec,RGB(255,255,255)); 358 | MoveToEx(hdcComp,rec.left,rec.top+4,NULL); 359 | LineTo(hdcComp,rec.right,rec.top+4); 360 | MoveToEx(hdcComp,rec.left,rec.top+6,NULL); 361 | LineTo(hdcComp,rec.right,rec.top+6); 362 | } 363 | } 364 | 365 | BitBlt(hdc,0,0,rcWnd.right,rcWnd.bottom,hdcComp,0,0,SRCCOPY); 366 | 367 | SetBkMode(hdcComp,nMode); 368 | 369 | SelectObject(hdcComp,hOldFont); 370 | 371 | SetBkMode(hdcComp,nBKMode); 372 | 373 | DeleteObject(hbmComp); 374 | DeleteDC(hdcComp); 375 | } 376 | } 377 | 378 | void CMenuWnd::InitMenuItems() 379 | { 380 | if(NULL == m_hFont) 381 | { 382 | LOGFONT lf; 383 | memset(&lf,0,sizeof(LOGFONT)); 384 | 385 | _tcscpy_s(lf.lfFaceName,sizeof(lf.lfFaceName)/sizeof(TCHAR),MENU_FONT); 386 | lf.lfClipPrecision = 2; 387 | lf.lfHeight = -14; 388 | lf.lfQuality = 1; 389 | lf.lfWeight = 400; 390 | lf.lfOutPrecision = 3; 391 | lf.lfPitchAndFamily = 34; 392 | 393 | m_hFont = CreateFontIndirect(&lf); 394 | } 395 | } 396 | 397 | INT_PTR CALLBACK CMenuWnd::MenuWndProc(HWND hwnd 398 | , UINT uMsg 399 | , WPARAM wParam 400 | , LPARAM lParam) 401 | { 402 | CMenuWnd * pMenuWnd = (CMenuWnd *)GetWindowLong( hwnd, GWL_USERDATA ); 403 | 404 | switch(uMsg) 405 | { 406 | case WM_CREATE: 407 | break; 408 | 409 | case WM_PAINT: 410 | { 411 | PAINTSTRUCT ps; 412 | HDC hdc = BeginPaint(hwnd,&ps); 413 | if(pMenuWnd) 414 | pMenuWnd->DrawMenuItems(hdc); 415 | EndPaint(hwnd,&ps); 416 | } 417 | break; 418 | 419 | case WM_MOUSEMOVE: 420 | if(pMenuWnd) 421 | pMenuWnd->OnMouseMove(wParam,lParam); 422 | break; 423 | 424 | case WM_LBUTTONDOWN: 425 | if(pMenuWnd) 426 | { 427 | SetCapture(hwnd); 428 | pMenuWnd->OnLbuttonDown(wParam,lParam); 429 | } 430 | break; 431 | 432 | case WM_LBUTTONUP: 433 | if(pMenuWnd) 434 | { 435 | ReleaseCapture(); 436 | pMenuWnd->OnLbuttonUP(wParam,lParam); 437 | } 438 | break; 439 | 440 | //case WM_ERASEBKGND: 441 | // break; 442 | 443 | case WM_CLOSE: 444 | break; 445 | 446 | case WM_DESTROY: 447 | return DefWindowProc(hwnd, uMsg, wParam, lParam); 448 | 449 | default: 450 | return DefWindowProc(hwnd, uMsg, wParam, lParam); 451 | } 452 | 453 | return FALSE; 454 | } 455 | 456 | HWND CMenuWnd::CreateMenuWindow( HWND hParent 457 | , HWND hSubling 458 | , MENU_INFO &stMenuInfo) 459 | { 460 | int nWidth = stMenuInfo.m_rRect.right - stMenuInfo.m_rRect.left; 461 | 462 | m_hWnd = CreateWindowEx(0 , CLASS_MENU 463 | , _T("") 464 | , WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN 465 | | WS_CLIPSIBLINGS | WS_BORDER 466 | , nWidth, 30, 0, 0 467 | , hParent 468 | , (HMENU)NULL 469 | , GetWindowInstance(hParent) 470 | , (LPARAM)NULL ); 471 | 472 | ShowWindow( m_hWnd, SW_SHOW ); 473 | 474 | SetWindowLong( m_hWnd, GWL_USERDATA, (LONG)this ); 475 | 476 | m_stMenuInfo = stMenuInfo; 477 | 478 | SetParentHwnd(hParent); 479 | InitMenuItems(); 480 | RECT rRect = SetMenuSize(); 481 | 482 | if(hSubling) 483 | { 484 | RECT rPRect, rSRect; 485 | GetWindowRect( hParent, &rPRect ); 486 | GetWindowRect( hSubling, &rSRect ); 487 | int nDiffX = rSRect.right - rPRect.left; 488 | if(nDiffX > 2) 489 | nDiffX -= 2; 490 | else 491 | nDiffX = 2; 492 | SetWindowPos(m_hWnd, HWND_TOP, nDiffX, 30 493 | , rRect.right, rRect.bottom, SWP_SHOWWINDOW); 494 | } 495 | else 496 | { 497 | SetWindowPos(m_hWnd, HWND_TOP, m_stMenuInfo.m_rRect.left, 30 498 | , rRect.right, rRect.bottom, SWP_SHOWWINDOW); 499 | } 500 | 501 | m_hToolTip = CreateMyTooltip(); 502 | 503 | return m_hWnd; 504 | } 505 | -------------------------------------------------------------------------------- /NikPEViewer/EditorBitmap.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Stdafx.h" 3 | #include "EditorBitmap.h" 4 | 5 | void CNikBitmapEditor::SetScrollBar() 6 | { 7 | // Set the vertical scrolling range and page size 8 | SCROLLINFO si; 9 | 10 | GetScrollInfo(m_hWnd,SB_VERT,&si); 11 | 12 | si.cbSize = sizeof(si); 13 | si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; 14 | si.nMin = 0; 15 | si.nMax = m_stBitmapHeader.biHeight; 16 | 17 | si.nPage = m_rDrawArea.bottom; 18 | 19 | SetScrollInfo(m_hWnd, SB_VERT, &si, TRUE); 20 | 21 | GetScrollInfo(m_hWnd,SB_HORZ,&si); 22 | 23 | si.cbSize = sizeof(si); 24 | si.fMask = SIF_RANGE | SIF_PAGE; 25 | si.nMin = 0; 26 | si.nMax = m_stBitmapHeader.biWidth; 27 | 28 | si.nPage = m_rDrawArea.right; 29 | 30 | SetScrollInfo(m_hWnd, SB_HORZ, &si, TRUE); 31 | } 32 | 33 | void CNikBitmapEditor::OnScrollBar(int nFlag 34 | , WPARAM wParam) 35 | { 36 | SCROLLINFO si; 37 | si.cbSize = sizeof (si); 38 | si.fMask = SIF_ALL; 39 | 40 | int nDiffX; 41 | int nDiffY; 42 | 43 | if(WM_VSCROLL == nFlag) 44 | { 45 | GetScrollInfo (m_hWnd, SB_VERT, &si); 46 | 47 | int nCurPos = si.nPos; 48 | 49 | switch (LOWORD (wParam)) 50 | { 51 | // user clicked the HOME keyboard key 52 | case UM_WHEELUP: 53 | si.nPos -= 60; 54 | break; 55 | 56 | case UM_WHEELDOWN: 57 | si.nPos += 60; 58 | break; 59 | 60 | case SB_TOP: 61 | si.nPos = si.nMin; 62 | break; 63 | 64 | // user clicked the END keyboard key 65 | case SB_BOTTOM: 66 | si.nPos = si.nMax; 67 | break; 68 | 69 | // user clicked the top arrow 70 | case SB_LINEUP: 71 | si.nPos -= 20; 72 | break; 73 | 74 | // user clicked the bottom arrow 75 | case SB_LINEDOWN: 76 | si.nPos += 20; 77 | break; 78 | 79 | // user clicked the scroll bar shaft above the scroll box 80 | case SB_PAGEUP: 81 | si.nPos -= si.nPage; 82 | break; 83 | 84 | // user clicked the scroll bar shaft below the scroll box 85 | case SB_PAGEDOWN: 86 | si.nPos += si.nPage; 87 | break; 88 | 89 | // user dragged the scroll box 90 | case SB_THUMBTRACK: 91 | si.nPos = si.nTrackPos; 92 | break; 93 | 94 | default: 95 | break; 96 | } 97 | // Set the position and then retrieve it. Due to adjustments 98 | // by Windows it may not be the same as the value set. 99 | si.fMask = SIF_POS; 100 | SetScrollInfo (m_hWnd, SB_VERT, &si, TRUE); 101 | GetScrollInfo (m_hWnd, SB_VERT, &si); 102 | // If the position has changed, scroll window and update it 103 | if (si.nPos != nCurPos) 104 | { 105 | nDiffY = m_nOffsetY - si.nPos; 106 | m_nOffsetY = si.nPos; 107 | ScrollWindowEx(m_hWnd, 0,nDiffY 108 | , NULL, NULL, NULL, NULL, SW_INVALIDATE); 109 | UpdateWindow (m_hWnd); 110 | } 111 | } 112 | else if(WM_HSCROLL == nFlag) 113 | { 114 | GetScrollInfo (m_hWnd, SB_HORZ, &si); 115 | 116 | int nCurPos = si.nPos; 117 | 118 | switch (LOWORD (wParam)) 119 | { 120 | case SB_TOP: 121 | si.nPos = si.nMin; 122 | break; 123 | 124 | // user clicked the END keyboard key 125 | case SB_BOTTOM: 126 | si.nPos = si.nMax; 127 | break; 128 | 129 | // user clicked the top arrow 130 | case SB_LINEUP: 131 | si.nPos -= 20; 132 | break; 133 | 134 | // user clicked the bottom arrow 135 | case SB_LINEDOWN: 136 | si.nPos += 20; 137 | break; 138 | 139 | // user clicked the scroll bar shaft above the scroll box 140 | case SB_PAGEUP: 141 | si.nPos -= si.nPage; 142 | break; 143 | 144 | // user clicked the scroll bar shaft below the scroll box 145 | case SB_PAGEDOWN: 146 | si.nPos += si.nPage; 147 | break; 148 | 149 | // user dragged the scroll box 150 | case SB_THUMBTRACK: 151 | si.nPos = si.nTrackPos; 152 | break; 153 | 154 | default: 155 | break; 156 | } 157 | // Set the position and then retrieve it. Due to adjustments 158 | // by Windows it may not be the same as the value set. 159 | si.fMask = SIF_POS; 160 | SetScrollInfo (m_hWnd, SB_HORZ, &si, TRUE); 161 | GetScrollInfo (m_hWnd, SB_HORZ, &si); 162 | // If the position has changed, scroll window and update it 163 | if (si.nPos != nCurPos) 164 | { 165 | nDiffX = m_nOffsetX - si.nPos; 166 | m_nOffsetX = si.nPos; 167 | ScrollWindowEx(m_hWnd, nDiffX,0 168 | , NULL, NULL, NULL, NULL, SW_INVALIDATE); 169 | UpdateWindow (m_hWnd); 170 | } 171 | } 172 | } 173 | 174 | void CNikBitmapEditor::DrawRectArea(HDC hdc 175 | , RECT rc 176 | ,COLORREF col) 177 | { 178 | if(hdc) 179 | { 180 | HBRUSH hBrush = CreateSolidBrush(col); 181 | HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,hBrush); 182 | 183 | FillRect(hdc,&rc,hBrush); 184 | 185 | SelectObject(hdc,hOldBrush); 186 | 187 | DeleteObject(hBrush); 188 | } 189 | } 190 | 191 | void CNikBitmapEditor::DrawLineRect(HDC hdc, RECT rc) 192 | { 193 | if(hdc) 194 | { 195 | HPEN hOldPen,hPen = CreatePen(PS_SOLID,1,LINE_NUMBER_COLOR); 196 | hOldPen = (HPEN)SelectObject(hdc,hPen); 197 | 198 | MoveToEx(hdc,rc.left,rc.top,NULL); 199 | LineTo(hdc,rc.right,rc.top); 200 | LineTo(hdc,rc.right,rc.bottom); 201 | LineTo(hdc,rc.left,rc.bottom); 202 | LineTo(hdc,rc.left,rc.top); 203 | 204 | SelectObject(hdc,hOldPen); 205 | DeleteObject(hOldPen); 206 | } 207 | } 208 | 209 | void CNikBitmapEditor::DrawSideBar(HDC hdc) 210 | { 211 | if(hdc) 212 | { 213 | RECT rc = m_rDrawArea; 214 | 215 | rc.right = m_nLeftBoundary; 216 | 217 | DrawRectArea(hdc,m_rDrawArea,WINDOW_BACK_COLOR); 218 | } 219 | } 220 | 221 | BYTE * CNikBitmapEditor::ReadBinaryFile(_tstring strFile 222 | , DWORD &dwFileSize) 223 | { 224 | BYTE * pBuffer = NULL; 225 | HANDLE hFile = CreateFile(strFile.data(), GENERIC_READ, FILE_SHARE_READ, NULL, 226 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 227 | if ( hFile == INVALID_HANDLE_VALUE ) 228 | { 229 | return 0; 230 | } 231 | 232 | dwFileSize = GetFileSize(hFile,NULL); 233 | if(dwFileSize) 234 | { 235 | pBuffer = new BYTE [dwFileSize + 2]; 236 | if(pBuffer) 237 | { 238 | pBuffer[dwFileSize] = 0; 239 | pBuffer[dwFileSize+1] = 0; 240 | DWORD dwRead = 0; 241 | ReadFile(hFile,pBuffer,dwFileSize,&dwRead,NULL); 242 | if(dwRead == dwFileSize) 243 | { 244 | return pBuffer; 245 | } 246 | } 247 | delete [] pBuffer; 248 | pBuffer = NULL; 249 | } 250 | return NULL; 251 | } 252 | 253 | void CNikBitmapEditor::DrawBitmapEditor(HDC hdc 254 | , RECT rPaint 255 | ) 256 | { 257 | if(hdc && m_hImageBitmap) 258 | { 259 | HDC memDC = CreateCompatibleDC ( hdc ); 260 | HBITMAP hOldBitmap = (HBITMAP)SelectObject(memDC,m_hImageBitmap); 261 | 262 | GetClientRect(m_hWnd,&rPaint); 263 | 264 | if(rPaint.right > m_stBitmapHeader.biWidth) 265 | rPaint.right = m_stBitmapHeader.biWidth; 266 | 267 | if((rPaint.bottom) > m_stBitmapHeader.biHeight) 268 | rPaint.bottom = m_stBitmapHeader.biHeight; 269 | 270 | BitBlt(hdc,-m_nOffsetX,-m_nOffsetY 271 | , rPaint.right+m_nOffsetX 272 | , rPaint.bottom+m_nOffsetY 273 | , memDC,0,0,SRCCOPY); 274 | 275 | SelectObject(memDC,hOldBitmap); 276 | DeleteDC(memDC); 277 | } 278 | } 279 | 280 | int CNikBitmapEditor::CreateBitmap(IStream * pIStream 281 | , DWORD dwSize) 282 | { 283 | if(pIStream 284 | && (dwSize > 0)) 285 | { 286 | Color cColor; 287 | { 288 | if(m_hImageBitmap) 289 | { 290 | DeleteObject(m_hImageBitmap); 291 | m_hImageBitmap = NULL; 292 | } 293 | 294 | { 295 | Bitmap hBitmap(pIStream,FALSE); 296 | hBitmap.GetHBITMAP(cColor,&m_hImageBitmap); 297 | } 298 | 299 | { 300 | memset(&m_stBitmapHeader,0,sizeof(BITMAPINFO)); 301 | m_stBitmapHeader.biSize = sizeof(BITMAPINFOHEADER); 302 | HDC hdc = GetDC(m_hWnd); 303 | GetDIBits(hdc,m_hImageBitmap,0,0,NULL,(BITMAPINFO *)&m_stBitmapHeader,DIB_RGB_COLORS); 304 | ReleaseDC(m_hWnd,hdc); 305 | } 306 | } 307 | } 308 | return 0; 309 | } 310 | 311 | HWND CNikBitmapEditor::CreateBitmapWindowBuf(HWND hParent 312 | , BYTE * pBuffer 313 | , _tstring strID 314 | , int nSize 315 | , int nFlag) 316 | { 317 | if((!pBuffer) 318 | || (nSize<=0)) 319 | return NULL; 320 | 321 | int nCount = 0xFFFF & (nFlag>>16); 322 | if(nCount > 0) 323 | nCount--; 324 | 325 | nFlag = 0xFFFF & nFlag; 326 | 327 | if(hParent 328 | || (!m_hWnd)) 329 | { 330 | m_hParentWnd = hParent; 331 | m_hWnd = CreateBitmapWindow(hParent); 332 | SetWindowLong( m_hWnd, GWL_USERDATA, (LONG)this ); 333 | } 334 | 335 | if(m_hWnd) 336 | { 337 | _tstring strCaption; 338 | if(CURSOR_DATA == nFlag) 339 | strCaption = _T("Resource cursor Viewer"); 340 | else if(BITMAP_DATA == nFlag) 341 | strCaption = _T("Resource bitmap Viewer"); 342 | else if(ICON_DATA == nFlag) 343 | strCaption = _T("Resource icon Viewer"); 344 | 345 | if(!strCaption.empty()) 346 | { 347 | strCaption += _T(" - "); 348 | strCaption += strID; 349 | } 350 | 351 | SetWindowText( m_hWnd, strCaption.c_str()); 352 | 353 | if(CreateBitmapfromBuffer(pBuffer, nSize, nFlag) < 0) 354 | return 0; 355 | 356 | POINT pt; 357 | pt.x = 20 * nCount; 358 | pt.y = 20 * nCount; 359 | ShowWindowPosition((NULL != hParent), pt); 360 | } 361 | 362 | return m_hWnd; 363 | } 364 | 365 | int CNikBitmapEditor::CreateBitmapfromBuffer(BYTE * pBuffer 366 | , int nSize 367 | , int nFlag) 368 | { 369 | if(pBuffer 370 | && (nSize > 0)) 371 | { 372 | if(m_hBitmap) 373 | { 374 | DeleteObject(m_hBitmap); 375 | m_hBitmap = NULL; 376 | } 377 | 378 | if(m_hImageBitmap) 379 | { 380 | DeleteObject(m_hImageBitmap); 381 | m_hImageBitmap = NULL; 382 | } 383 | 384 | if(BITMAP_DATA == nFlag) 385 | { 386 | nSize += 0xE; 387 | } 388 | 389 | HGLOBAL hGobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD 390 | ,nSize+1); 391 | if(hGobal) 392 | { 393 | BYTE * pbuf = (BYTE *)GlobalLock(hGobal); 394 | if(pbuf) 395 | { 396 | IStream * pIStream; 397 | if(BITMAP_DATA == nFlag) 398 | { 399 | for(int i=0;i<0xE;i++) 400 | pbuf[i] = 0; 401 | 402 | pbuf[0] = 'B'; 403 | pbuf[1] = 'M'; 404 | pbuf[2] = nSize & 0XFF; 405 | pbuf[3] = (nSize>>8) & 0XFF; 406 | pbuf[4] = (nSize>>16) & 0XFF; 407 | pbuf[5] = (nSize>>24) & 0XFF; 408 | BITMAPINFOHEADER * pBitInfoHeader = (BITMAPINFOHEADER *)pBuffer; 409 | int nOffset = 0; 410 | if(pBitInfoHeader->biSizeImage) 411 | { 412 | nOffset = nSize - pBitInfoHeader->biSizeImage; 413 | } 414 | else 415 | { 416 | nOffset = 0xE + 0x28; 417 | if(pBitInfoHeader->biBitCount <= 8) 418 | { 419 | if(pBitInfoHeader->biClrUsed) 420 | nOffset += (pBitInfoHeader->biClrUsed << 2); 421 | else 422 | nOffset += ((1 << pBitInfoHeader->biBitCount) << 2); 423 | } 424 | } 425 | pbuf[10] = nOffset & 0XFF; 426 | pbuf[11] = (nOffset>>8) & 0XFF; 427 | pbuf[12] = (nOffset>>16) & 0XFF; 428 | pbuf[13] = (nOffset>>24) & 0XFF; 429 | memcpy(&pbuf[0xE],pBuffer,nSize-0xE); 430 | } 431 | else if((ICON_DATA == nFlag) 432 | || (CURSOR_DATA == nFlag)) 433 | { 434 | for(int i=0;i<0xE;i++) 435 | pbuf[i] = 0; 436 | 437 | if(CURSOR_DATA == nFlag) 438 | { 439 | pBuffer = pBuffer + 4; 440 | nSize -= 4; 441 | } 442 | 443 | BITMAPINFOHEADER * pBitInfoHeader = (BITMAPINFOHEADER *)pBuffer; 444 | 445 | pBitInfoHeader->biHeight = pBitInfoHeader->biHeight>>1; 446 | 447 | int nBitSize = ((pBitInfoHeader->biWidth * pBitInfoHeader->biHeight) + 7)>>3; 448 | 449 | nBitSize = 0xE + pBitInfoHeader->biSizeImage; 450 | 451 | pbuf[0] = 'B'; 452 | pbuf[1] = 'M'; 453 | pbuf[2] = nBitSize & 0XFF; 454 | pbuf[3] = (nBitSize>>8) & 0XFF; 455 | pbuf[4] = (nBitSize>>16) & 0XFF; 456 | pbuf[5] = (nBitSize>>24) & 0XFF; 457 | 458 | int nOffset = 0; 459 | { 460 | nOffset = 0xE + 0x28; 461 | if(pBitInfoHeader->biBitCount <= 8) 462 | nOffset += ((1 << pBitInfoHeader->biBitCount) << 2); 463 | } 464 | pbuf[10] = nOffset & 0XFF; 465 | pbuf[11] = (nOffset>>8) & 0XFF; 466 | pbuf[12] = (nOffset>>16) & 0XFF; 467 | pbuf[13] = (nOffset>>24) & 0XFF; 468 | memcpy(&pbuf[0xE],pBuffer,nSize-0xE); 469 | 470 | pBitInfoHeader->biHeight = pBitInfoHeader->biHeight<<1; 471 | } 472 | else 473 | { 474 | memcpy(pbuf,pBuffer,nSize); 475 | } 476 | 477 | CreateStreamOnHGlobal(hGobal,TRUE,&pIStream); 478 | 479 | if(pIStream) 480 | { 481 | CreateBitmap(pIStream,nSize); 482 | 483 | SetScrollBar(); 484 | 485 | if(pIStream) 486 | pIStream->Release(); 487 | 488 | InvalidateRect(m_hWnd,NULL,0); 489 | UpdateWindow(m_hWnd); 490 | } 491 | 492 | GlobalUnlock(hGobal); 493 | } 494 | GlobalFree(hGobal); 495 | } 496 | 497 | if((m_hBitmap) 498 | && (m_hImageBitmap)) 499 | return 0; 500 | 501 | return -2; 502 | } 503 | 504 | return -1; 505 | } 506 | 507 | void CNikBitmapEditor::ProcessKeyMessages(DWORD dwKeycode 508 | ,int nFlag) 509 | { 510 | m_bKeyDown[(BYTE)(dwKeycode)] = nFlag; 511 | 512 | if(TRUE == nFlag) 513 | { 514 | m_bKeyDown[(BYTE)(dwKeycode)] = TRUE; 515 | 516 | switch(dwKeycode) 517 | { 518 | case VK_INSERT: 519 | break; 520 | case VK_DOWN: 521 | break; 522 | 523 | case VK_UP: 524 | break; 525 | 526 | case VK_RIGHT: 527 | break; 528 | 529 | case VK_LEFT: 530 | break; 531 | 532 | case VK_DELETE: 533 | break; 534 | } 535 | } 536 | } 537 | 538 | void CNikBitmapEditor::OnMouseMove(WPARAM wParam 539 | , LPARAM lParam) 540 | { 541 | if(MK_LBUTTON & wParam) 542 | { 543 | POINT ptDiff; 544 | 545 | ptDiff.x = GET_X_LPARAM(lParam); 546 | ptDiff.y = GET_Y_LPARAM(lParam); 547 | 548 | InvalidateRect(m_hWnd,NULL,FALSE); 549 | } 550 | } 551 | 552 | void CNikBitmapEditor::OnSize(WPARAM //wParam 553 | , LPARAM lParam) 554 | { 555 | RECT rc; 556 | rc.left = 0; 557 | rc.right = LOWORD(lParam); 558 | rc.top = 0; 559 | rc.bottom = HIWORD(lParam); 560 | 561 | if(m_hBitmap) 562 | { 563 | DeleteObject(m_hBitmap); 564 | m_hBitmap = NULL; 565 | } 566 | 567 | SetDrawRect(rc); 568 | 569 | if(m_hImageBitmap) 570 | { 571 | if((rc.right+m_nOffsetX) > m_stBitmapHeader.biWidth) 572 | { 573 | m_nOffsetX = m_stBitmapHeader.biWidth - rc.right; 574 | if(m_nOffsetX < 0) 575 | m_nOffsetX = 0; 576 | InvalidateRect(m_hWnd,NULL,0); 577 | } 578 | 579 | if((rc.bottom+m_nOffsetY) > m_stBitmapHeader.biHeight) 580 | { 581 | m_nOffsetY = m_stBitmapHeader.biHeight - rc.bottom; 582 | if(m_nOffsetY < 0) 583 | m_nOffsetY = 0; 584 | InvalidateRect(m_hWnd,NULL,0); 585 | } 586 | } 587 | 588 | SetScrollBar(); 589 | } 590 | 591 | 592 | void CNikBitmapEditor::OnLbuttonDown(WPARAM //wParam 593 | , LPARAM //lParam 594 | ) 595 | { 596 | if(m_hWnd) 597 | SetWindowPos( m_hWnd, HWND_TOP, 0 , 0, 0, 0 598 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 599 | } 600 | 601 | void CNikBitmapEditor::OnLbuttonUP(WPARAM //wParam 602 | , LPARAM //lParam 603 | ) 604 | { 605 | } 606 | 607 | void CNikBitmapEditor::OnRbuttonDown(WPARAM //wParam 608 | , LPARAM //lParam 609 | ) 610 | { 611 | } 612 | 613 | HWND CNikBitmapEditor::CreateBitmapWindow(HWND hParent) 614 | { 615 | DWORD dwStyle = WS_TABSTOP | 616 | WS_VISIBLE | 617 | WS_SIZEBOX | 618 | WS_CAPTION | 619 | WS_SYSMENU | 620 | WS_VSCROLL | 621 | WS_HSCROLL | 622 | WS_CHILDWINDOW | 623 | WS_CLIPSIBLINGS | 624 | 0; 625 | 626 | HWND hwnd = CreateWindowEx( WS_EX_TOOLWINDOW 627 | , CLASS_NAME 628 | , WINDOWS_CAPTION 629 | , dwStyle 630 | , 0, 0, 0, 0 631 | , hParent 632 | , NULL 633 | , GetWindowInstance(hParent) 634 | , (LPARAM)NULL ); 635 | return hwnd; 636 | } 637 | 638 | void CNikBitmapEditor::PaintWindow(HWND hwnd 639 | , HDC hdc 640 | , RECT rPaint 641 | ) 642 | { 643 | RECT rc; 644 | GetClientRect(hwnd,&rc); 645 | 646 | HDC memDC = CreateCompatibleDC ( hdc ); 647 | 648 | int nWidth,nHeight; 649 | GetEditorWindowSize(nWidth,nHeight); 650 | 651 | if(NULL == GetEditorBitmap()) 652 | { 653 | HBITMAP hBitmap = CreateCompatibleBitmap ( hdc 654 | , nWidth 655 | , nHeight ); 656 | SetEditorBitmap(hBitmap); 657 | } 658 | 659 | HBITMAP OldBM = (HBITMAP)SelectObject ( memDC, GetEditorBitmap() ); 660 | 661 | DrawSideBar(memDC); 662 | 663 | DrawBitmapEditor(memDC,rPaint); 664 | 665 | BitBlt(hdc,0,0,nWidth,nHeight,memDC,0,0,SRCCOPY); 666 | 667 | SelectObject ( hdc, OldBM); 668 | 669 | DeleteDC(memDC); 670 | } 671 | 672 | void CNikBitmapEditor::MenuProcess( HWND //hwnd 673 | , DWORD //dwValue 674 | ) 675 | { 676 | } 677 | 678 | int CNikBitmapEditor::RegisterEditorclass( HINSTANCE hInstance ) 679 | { 680 | WNDCLASS wc; 681 | memset(&wc,0,sizeof(wc)); 682 | 683 | wc.lpfnWndProc = (WNDPROC)CNikBitmapEditor::EditorWndProc; 684 | wc.cbClsExtra = 0; 685 | wc.cbWndExtra = 0; 686 | wc.hInstance = hInstance; 687 | wc.hCursor = LoadCursor(NULL, IDC_IBEAM); 688 | wc.hIcon = (HICON)LoadIcon(hInstance,MAKEINTRESOURCE(IDC_NIKPEVIEWER)); 689 | wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 690 | wc.lpszClassName = CLASS_NAME; 691 | wc.lpszMenuName = NULL; 692 | if (!RegisterClass(&wc)) 693 | return FALSE; 694 | return TRUE; 695 | } 696 | 697 | LRESULT CALLBACK CNikBitmapEditor::EditorWndProc(HWND hwnd 698 | , UINT uMsg 699 | , WPARAM wParam 700 | , LPARAM lParam) 701 | { 702 | CNikBitmapEditor * pBitmapEditor = (CNikBitmapEditor *)GetWindowLong( hwnd, GWL_USERDATA ); 703 | 704 | switch(uMsg) 705 | { 706 | case WM_MOUSEMOVE: 707 | if(pBitmapEditor) 708 | pBitmapEditor->OnMouseMove(wParam,lParam); 709 | break; 710 | 711 | case WM_LBUTTONDOWN: 712 | if(pBitmapEditor) 713 | { 714 | SetCapture(hwnd); 715 | pBitmapEditor->OnLbuttonDown(wParam,lParam); 716 | } 717 | break; 718 | 719 | case WM_LBUTTONUP: 720 | if(pBitmapEditor) 721 | { 722 | ReleaseCapture(); 723 | pBitmapEditor->OnLbuttonUP(wParam,lParam); 724 | SetFocus(hwnd); 725 | } 726 | break; 727 | 728 | case WM_RBUTTONDOWN: 729 | break; 730 | 731 | case WM_MOUSEWHEEL: 732 | if(pBitmapEditor) 733 | { 734 | int zDelta = GET_WHEEL_DELTA_WPARAM(wParam); 735 | if(zDelta > 0) 736 | pBitmapEditor->OnScrollBar(WM_VSCROLL,UM_WHEELUP); 737 | else 738 | pBitmapEditor->OnScrollBar(WM_VSCROLL,UM_WHEELDOWN); 739 | } 740 | break; 741 | 742 | case WM_VSCROLL: 743 | if(pBitmapEditor) 744 | pBitmapEditor->OnScrollBar(WM_VSCROLL,wParam); 745 | break; 746 | 747 | case WM_HSCROLL: 748 | if(pBitmapEditor) 749 | pBitmapEditor->OnScrollBar(WM_HSCROLL,wParam); 750 | break; 751 | 752 | case WM_ERASEBKGND: 753 | return 0; 754 | 755 | case WM_SIZE: 756 | if(pBitmapEditor) 757 | pBitmapEditor->OnSize(wParam,lParam); 758 | break; 759 | 760 | case WM_KEYDOWN: 761 | if(pBitmapEditor) 762 | pBitmapEditor->ProcessKeyMessages(wParam, TRUE); 763 | break; 764 | 765 | case WM_KEYUP: 766 | if(pBitmapEditor) 767 | pBitmapEditor->ProcessKeyMessages(wParam, FALSE); 768 | break; 769 | 770 | case WM_COMMAND: 771 | MenuProcess(hwnd,LOWORD(wParam)); 772 | break; 773 | 774 | case WM_PAINT: 775 | { 776 | PAINTSTRUCT ps; 777 | HDC hdc = BeginPaint(hwnd, &ps); 778 | 779 | ///////////// 780 | if(pBitmapEditor) 781 | pBitmapEditor->PaintWindow(hwnd,hdc,ps.rcPaint); 782 | ///////////// 783 | 784 | EndPaint(hwnd, &ps); 785 | } 786 | break; 787 | 788 | case WM_CLOSE: 789 | ShowWindow( hwnd, SW_HIDE ); 790 | break; 791 | 792 | case WM_DESTROY: 793 | return DefWindowProc( hwnd, uMsg, wParam, lParam ); 794 | 795 | default: 796 | return DefWindowProc( hwnd, uMsg, wParam, lParam ); 797 | } 798 | 799 | return 0; 800 | } 801 | 802 | // end: -------------------------------------------------------------------------------- /NikPEViewer/DialogWnd.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Stdafx.h" 3 | #include "PEViewer.h" 4 | #include "DialogWnd.h" 5 | 6 | int CNikDialog::RegisterDialogclass(HINSTANCE hInstance) 7 | { 8 | WNDCLASS wc; 9 | memset(&wc,0,sizeof(wc)); 10 | 11 | wc.lpfnWndProc = (WNDPROC)CNikDialog::ResourceWndProc; 12 | wc.cbClsExtra = 0; 13 | wc.cbWndExtra = 0; 14 | wc.hInstance = hInstance; 15 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 16 | wc.hIcon = (HICON)LoadIcon(hInstance,MAKEINTRESOURCE(IDC_NIKPEVIEWER)); 17 | wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 18 | wc.lpszClassName = CLASS_DIALOG; 19 | wc.lpszMenuName = NULL; 20 | if (!RegisterClass(&wc)) 21 | return FALSE; 22 | return TRUE; 23 | } 24 | 25 | int CNikDialog::SetCursorShape(POINT pt) 26 | { 27 | int nPos = 0; 28 | if(m_hDlgWnd) 29 | { 30 | HCURSOR hCurs; 31 | switch(DrawRectMarkers(NULL,m_rRect,&pt,1)) 32 | { 33 | case 4: 34 | hCurs = LoadCursor(NULL, IDC_SIZENWSE); 35 | SetCursor(hCurs); 36 | nPos = 4; 37 | break; 38 | case 6: 39 | hCurs = LoadCursor(NULL, IDC_SIZEWE); 40 | SetCursor(hCurs); 41 | nPos = 6; 42 | break; 43 | case 8: 44 | hCurs = LoadCursor(NULL, IDC_SIZENS); 45 | SetCursor(hCurs); 46 | nPos = 8; 47 | break; 48 | } 49 | } 50 | return nPos; 51 | } 52 | 53 | void CNikDialog::OnLbuttonDown(WPARAM //wParam 54 | , LPARAM lParam) 55 | { 56 | if(m_hDlgWnd) 57 | { 58 | SetWindowPos( m_hWnd, HWND_TOP, 0 , 0, 0, 0 59 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 60 | 61 | SetCapture(m_hWnd); 62 | 63 | POINT pt; 64 | pt.x = GET_X_LPARAM(lParam); 65 | pt.y = GET_Y_LPARAM(lParam); 66 | m_nPos = SetCursorShape(pt); 67 | 68 | if(m_nPos) 69 | { 70 | m_ptStartPos = pt; 71 | m_ptEndPos = pt; 72 | } 73 | else 74 | { 75 | m_ptEndPos.x = 0; 76 | m_ptEndPos.y = 0; 77 | m_ptStartPos.x = 0; 78 | m_ptStartPos.y = 0; 79 | } 80 | } 81 | } 82 | 83 | void CNikDialog::OnLbuttonUP(WPARAM //wParam 84 | , LPARAM lParam) 85 | { 86 | if(m_hDlgWnd) 87 | { 88 | POINT pt; 89 | pt.x = GET_X_LPARAM(lParam); 90 | pt.y = GET_Y_LPARAM(lParam); 91 | SetCursorShape(pt); 92 | 93 | m_ptEndPos.x = 0; 94 | m_ptEndPos.y = 0; 95 | m_ptStartPos.x = 0; 96 | m_ptStartPos.y = 0; 97 | 98 | m_nPos = 0; 99 | } 100 | 101 | ReleaseCapture(); 102 | } 103 | 104 | void CNikDialog::OnMouseMove(WPARAM wParam 105 | , LPARAM lParam) 106 | { 107 | if(m_hDlgWnd) 108 | { 109 | POINT pt; 110 | pt.x = GET_X_LPARAM(lParam); 111 | pt.y = GET_Y_LPARAM(lParam); 112 | SetCursorShape(pt); 113 | 114 | if(m_nPos 115 | && (wParam & MK_LBUTTON)) 116 | { 117 | int nDifX = pt.x - m_ptEndPos.x; 118 | int nDifY = pt.y - m_ptEndPos.y; 119 | m_ptEndPos = pt; 120 | 121 | RECT rc; 122 | 123 | switch(m_nPos) 124 | { 125 | case 4: 126 | m_rRect.right += nDifX; 127 | m_rRect.bottom += nDifY; 128 | GetWindowRect(m_hDlgWnd,&rc); 129 | rc.right += nDifX; 130 | rc.bottom += nDifY; 131 | SetWindowPos(m_hDlgWnd, NULL, 0, 0 132 | , rc.right-rc.left, rc.bottom-rc.top 133 | , SWP_NOMOVE|SWP_SHOWWINDOW); 134 | 135 | rc = m_rRect; 136 | InflateRect(&rc,4+abs(nDifX),4+abs(nDifY)); 137 | InvalidateRect(m_hWnd,&rc,TRUE); 138 | UpdateWindow(m_hWnd); 139 | break; 140 | case 6: 141 | m_rRect.right += nDifX; 142 | GetWindowRect(m_hDlgWnd,&rc); 143 | rc.right += nDifX; 144 | SetWindowPos(m_hDlgWnd, NULL, 0, 0 145 | , rc.right-rc.left, rc.bottom-rc.top 146 | , SWP_NOMOVE|SWP_SHOWWINDOW); 147 | 148 | rc = m_rRect; 149 | InflateRect(&rc,4+abs(nDifX),8); 150 | InvalidateRect(m_hWnd,&rc,TRUE); 151 | UpdateWindow(m_hWnd); 152 | break; 153 | case 8: 154 | m_rRect.bottom += nDifY; 155 | 156 | GetWindowRect(m_hDlgWnd,&rc); 157 | rc.bottom += nDifY; 158 | SetWindowPos(m_hDlgWnd, NULL, 0, 0 159 | , rc.right-rc.left, rc.bottom-rc.top 160 | , SWP_NOMOVE|SWP_SHOWWINDOW); 161 | 162 | rc = m_rRect; 163 | InflateRect(&rc,8,4+abs(nDifY)); 164 | InvalidateRect(m_hWnd,&rc,TRUE); 165 | 166 | UpdateWindow(m_hWnd); 167 | break; 168 | } 169 | } 170 | } 171 | } 172 | 173 | void CNikDialog::DrawLineRect( HDC hdc 174 | , RECT rc 175 | , COLORREF cLineCol 176 | , int nLineWidth) 177 | { 178 | if(hdc) 179 | { 180 | HPEN hOldPen,hPen = CreatePen(PS_SOLID,nLineWidth,cLineCol); 181 | hOldPen = (HPEN)SelectObject(hdc,hPen); 182 | 183 | MoveToEx(hdc,rc.left,rc.top,NULL); 184 | LineTo(hdc,rc.right,rc.top); 185 | LineTo(hdc,rc.right,rc.bottom); 186 | LineTo(hdc,rc.left,rc.bottom); 187 | LineTo(hdc,rc.left,rc.top-1); 188 | 189 | SelectObject(hdc,hOldPen); 190 | DeleteObject(hPen); 191 | } 192 | } 193 | 194 | int CNikDialog::DrawRectMarkers(HDC hdc 195 | , RECT rc 196 | , POINT *pt 197 | , int nFlag) 198 | { 199 | int nRect = 0; 200 | 201 | if(nFlag 202 | && (NULL == pt)) 203 | return 0; 204 | else if((0 == nFlag) 205 | && (NULL == hdc)) 206 | return 0; 207 | 208 | RECT rc1; 209 | int nWid = (rc.right - rc.left)>>1; 210 | int nHei = (rc.bottom - rc.top)>>1; 211 | 212 | rc1.left = rc1.right = rc.left; 213 | rc1.bottom = rc1.top = rc.top; 214 | InflateRect(&rc1,2,2); 215 | if(nFlag) 216 | { 217 | nRect++; 218 | if(PtInRect(&rc1,pt[0])) 219 | return nRect; 220 | } 221 | else 222 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 223 | 224 | rc1.left = rc1.right = rc.right; 225 | rc1.bottom = rc1.top = rc.top; 226 | InflateRect(&rc1,2,2); 227 | 228 | if(nFlag) 229 | { 230 | nRect++; 231 | if(PtInRect(&rc1,pt[0])) 232 | return nRect; 233 | } 234 | else 235 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 236 | 237 | rc1.left = rc1.right = rc.left; 238 | rc1.bottom = rc1.top = rc.bottom; 239 | InflateRect(&rc1,2,2); 240 | 241 | if(nFlag) 242 | { 243 | nRect++; 244 | if(PtInRect(&rc1,pt[0])) 245 | return nRect; 246 | } 247 | else 248 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 249 | 250 | rc1.left = rc1.right = rc.right; 251 | rc1.bottom = rc1.top = rc.bottom; 252 | InflateRect(&rc1,2,2); 253 | 254 | if(nFlag) 255 | { 256 | nRect++; 257 | if(PtInRect(&rc1,pt[0])) 258 | return nRect; 259 | } 260 | else 261 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 262 | 263 | /////////////////////////////////////// 264 | 265 | rc1.left = rc1.right = nWid; 266 | rc1.bottom = rc1.top = rc.top; 267 | InflateRect(&rc1,2,2); 268 | 269 | if(nFlag) 270 | { 271 | nRect++; 272 | if(PtInRect(&rc1,pt[0])) 273 | return nRect; 274 | } 275 | else 276 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 277 | 278 | rc1.left = rc1.right = rc.right; 279 | rc1.bottom = rc1.top = nHei; 280 | InflateRect(&rc1,2,2); 281 | 282 | if(nFlag) 283 | { 284 | nRect++; 285 | if(PtInRect(&rc1,pt[0])) 286 | return nRect; 287 | } 288 | else 289 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 290 | 291 | rc1.left = rc1.right = rc.left; 292 | rc1.bottom = rc1.top = nHei; 293 | InflateRect(&rc1,2,2); 294 | 295 | if(nFlag) 296 | { 297 | nRect++; 298 | if(PtInRect(&rc1,pt[0])) 299 | return nRect; 300 | } 301 | else 302 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 303 | 304 | rc1.left = rc1.right = nWid; 305 | rc1.bottom = rc1.top = rc.bottom; 306 | InflateRect(&rc1,2,2); 307 | 308 | if(nFlag) 309 | { 310 | nRect++; 311 | if(PtInRect(&rc1,pt[0])) 312 | return nRect; 313 | } 314 | else 315 | DrawLineRect(hdc,rc1,RGB(0,128,0),1); 316 | 317 | return 0; 318 | } 319 | 320 | void CNikDialog::DrawDialogBorder(HDC hdc) 321 | { 322 | if(hdc && m_hDlgWnd) 323 | { 324 | DrawLineRect(hdc,m_rRect,RGB(0,128,0),2); 325 | DrawRectMarkers(hdc,m_rRect,NULL,0); 326 | } 327 | } 328 | 329 | void CNikDialog::DrawDialogBox(HDC hdc) 330 | { 331 | if(m_hDlgWnd) 332 | { 333 | DrawDialogBorder(hdc); 334 | return; 335 | } 336 | 337 | if(hdc 338 | && m_vDialogList.size()) 339 | { 340 | HRGN hrn = NULL; 341 | DIALOGCONTROL * pDlgTemp = NULL; 342 | HFONT hOldFont = NULL,hFont = NULL; 343 | for(int i=0;i<(int)m_vDialogList.size();i++) 344 | { 345 | pDlgTemp = &m_vDialogList.at(i); 346 | if(pDlgTemp) 347 | { 348 | if(0 == i) 349 | { 350 | hFont = CreateFontIndirect(&pDlgTemp->m_lf); 351 | 352 | hOldFont = (HFONT)SelectObject(hdc,hFont); 353 | 354 | if(1 == pDlgTemp->m_nFlag) 355 | { 356 | RECT rc; 357 | rc.left = pDlgTemp->m_rRect.left; 358 | rc.top = pDlgTemp->m_rRect.top - GetSystemMetrics(SM_CYCAPTION); 359 | rc.right = pDlgTemp->m_rRect.right; 360 | rc.bottom = pDlgTemp->m_rRect.top; 361 | 362 | InflateRect(&rc,1,0); 363 | 364 | DrawRectArea(hdc,rc,GetSysColor(COLOR_ACTIVECAPTION)); 365 | 366 | COLORREF col = SetTextColor(hdc,GetSysColor(COLOR_CAPTIONTEXT)); 367 | 368 | int nMode = SetBkMode(hdc,TRANSPARENT); 369 | 370 | rc.left += 5; 371 | 372 | DrawText(hdc, pDlgTemp->m_strCaption 373 | , wcslen(pDlgTemp->m_strCaption) 374 | , &rc, DT_LEFT|DT_VCENTER|DT_SINGLELINE); 375 | 376 | rc.left -= 5; 377 | 378 | SetTextColor(hdc,col); 379 | 380 | SetBkMode(hdc,nMode); 381 | } 382 | 383 | HRGN hrn = CreateRectRgn(pDlgTemp->m_rRect.left-2 384 | , pDlgTemp->m_rRect.top-2 385 | , pDlgTemp->m_rRect.right+2 386 | , pDlgTemp->m_rRect.bottom+2); 387 | SelectClipRgn(hdc,hrn); 388 | } 389 | 390 | if(0 != i) 391 | { 392 | if(0 == _tcscmp(pDlgTemp->m_strClassName,L"0x82")) 393 | { 394 | 395 | if(pDlgTemp->m_lStyle & (ES_CENTER<<16)) 396 | { 397 | DrawText(hdc,pDlgTemp->m_strCaption 398 | , _tcslen(pDlgTemp->m_strCaption) 399 | , &pDlgTemp->m_rRect 400 | , DT_CENTER); 401 | } 402 | else if(pDlgTemp->m_lStyle & (ES_RIGHT<<16)) 403 | { 404 | DrawText(hdc,pDlgTemp->m_strCaption 405 | , _tcslen(pDlgTemp->m_strCaption) 406 | , &pDlgTemp->m_rRect 407 | , DT_RIGHT); 408 | } 409 | else 410 | { 411 | DrawText(hdc,pDlgTemp->m_strCaption 412 | , _tcslen(pDlgTemp->m_strCaption) 413 | , &pDlgTemp->m_rRect 414 | , DT_LEFT); 415 | } 416 | } 417 | else if(0 == _tcscmp(pDlgTemp->m_strClassName,L"0x80")) 418 | { 419 | DrawText(hdc,pDlgTemp->m_strCaption 420 | , _tcslen(pDlgTemp->m_strCaption) 421 | , &pDlgTemp->m_rRect 422 | , DT_CENTER|DT_VCENTER|DT_SINGLELINE); 423 | } 424 | } 425 | 426 | DrawLineRect(hdc,pDlgTemp->m_rRect,RGB(0,0,0),1); 427 | } 428 | } 429 | 430 | SelectClipRgn(hdc,NULL); 431 | 432 | SelectObject(hdc,hOldFont); 433 | 434 | if(hFont) 435 | DeleteObject(hFont); 436 | 437 | if(hrn) 438 | DeleteObject(hrn); 439 | } 440 | } 441 | 442 | void CNikDialog::DrawRectArea(HDC hdc 443 | , RECT rc 444 | ,COLORREF col) 445 | { 446 | if(hdc) 447 | { 448 | HBRUSH hBrush = CreateSolidBrush(col); 449 | HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,hBrush); 450 | 451 | FillRect(hdc,&rc,hBrush); 452 | 453 | SelectObject(hdc,hOldBrush); 454 | 455 | DeleteObject(hBrush); 456 | } 457 | } 458 | 459 | LRESULT CALLBACK CNikDialog::ResourceWndProc(HWND hwnd, UINT uMsg, 460 | WPARAM wParam, LPARAM lParam) 461 | { 462 | CNikDialog * pDialogEditor = (CNikDialog *)GetWindowLong( hwnd, GWL_USERDATA ); 463 | 464 | switch(uMsg) 465 | { 466 | case WM_SIZE: 467 | if(pDialogEditor) 468 | pDialogEditor->OnSize(wParam,lParam); 469 | break; 470 | 471 | case WM_PAINT: 472 | { 473 | PAINTSTRUCT ps; 474 | HDC hdc = BeginPaint(hwnd,&ps); 475 | 476 | hdc; 477 | //if(pDialogEditor) 478 | // pDialogEditor->DrawDialogBox(hdc); 479 | 480 | EndPaint(hwnd,&ps); 481 | } 482 | break; 483 | 484 | case WM_CHAR: 485 | { 486 | if(0x1B == wParam) 487 | { 488 | if(pDialogEditor) 489 | pDialogEditor->DestroyDialogBox(); 490 | } 491 | } 492 | break; 493 | 494 | case WM_MOUSEMOVE: 495 | //if(pDialogEditor) 496 | // pDialogEditor->OnMouseMove(wParam,lParam); 497 | break; 498 | 499 | case WM_LBUTTONDOWN: 500 | //if(pDialogEditor) 501 | //{ 502 | // SetCapture(hwnd); 503 | // pDialogEditor->OnLbuttonDown(wParam,lParam); 504 | //} 505 | break; 506 | 507 | case WM_LBUTTONUP: 508 | //if(pDialogEditor) 509 | //{ 510 | // ReleaseCapture(); 511 | // pDialogEditor->OnLbuttonUP(wParam,lParam); 512 | //} 513 | break; 514 | 515 | case WM_CLOSE: 516 | ShowWindow( hwnd, SW_HIDE ); 517 | break; 518 | 519 | case WM_DESTROY: 520 | { 521 | if(pDialogEditor) 522 | pDialogEditor->DestroyDialogBox(); 523 | } 524 | return DefWindowProc( hwnd, uMsg, wParam, lParam ); 525 | 526 | default: 527 | return DefWindowProc( hwnd, uMsg, wParam, lParam ); 528 | } 529 | 530 | return 0; 531 | } 532 | 533 | void CNikDialog::OnSize(WPARAM //wParam 534 | , LPARAM //lParam 535 | ) 536 | { 537 | } 538 | 539 | INT_PTR CALLBACK CNikDialog::DialogWndProc( HWND //hwnd 540 | , UINT uMsg 541 | , WPARAM wParam 542 | , LPARAM //lParam 543 | ) 544 | { 545 | switch(uMsg) 546 | { 547 | case WM_INITDIALOG: 548 | return TRUE; 549 | 550 | case WM_COMMAND: 551 | { 552 | switch(wParam & 0xFFFF) 553 | { 554 | case IDCANCEL: 555 | case IDOK: 556 | //if(pDialogEditor) 557 | // pDialogEditor->DestroyDialogBox(); 558 | //else 559 | // EndDialog(hwnd,(wParam & 0xFFFF)); 560 | break; 561 | } 562 | } 563 | break; 564 | 565 | case WM_CLOSE: 566 | //if(pDialogEditor) 567 | // pDialogEditor->DestroyDialogBox(); 568 | //else 569 | // EndDialog(hwnd,IDCANCEL); 570 | break; 571 | 572 | default: 573 | return FALSE; 574 | } 575 | return TRUE; 576 | } 577 | 578 | HWND CNikDialog::CreateDialogWindow(HWND hParent) 579 | { 580 | m_hParentWnd = hParent; 581 | 582 | DWORD dwStyle = WS_TABSTOP | 583 | WS_VISIBLE | 584 | WS_SIZEBOX | 585 | WS_CAPTION | 586 | WS_SYSMENU | 587 | //WS_VSCROLL | 588 | //WS_HSCROLL | 589 | WS_CHILDWINDOW | 590 | WS_CLIPSIBLINGS | 591 | 0; 592 | 593 | m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW 594 | , CLASS_DIALOG 595 | , DIALOG_CAPTION 596 | , dwStyle 597 | , 200, 100, 200, 400 598 | , hParent 599 | , NULL 600 | , GetWindowInstance(hParent) 601 | , (LPARAM)NULL ); 602 | 603 | return m_hWnd; 604 | } 605 | 606 | int CNikDialog::MakeDialogList(RESOURCELIST * pRes) 607 | { 608 | m_vDialogList.clear(); 609 | 610 | if(pRes) 611 | { 612 | BYTE * pBufferTemp = new BYTE [pRes->m_nSize+8]; 613 | if(NULL == pBufferTemp) 614 | return -2; 615 | 616 | memcpy(pBufferTemp,&m_pBuffer[pRes->m_nOffsetToData],pRes->m_nSize+8); 617 | 618 | BYTE * pBuf = &m_pBuffer[pRes->m_nOffsetToData]; 619 | 620 | int bHasMenu = FALSE; 621 | 622 | int nBufSize = pRes->m_nSize; 623 | 624 | int nStructLen = 0; 625 | 626 | DestroyDialogBox(); 627 | 628 | HINSTANCE hInst = (HINSTANCE)GetWindowInstance(m_hParentWnd); 629 | 630 | BYTE * pBackupBuf = pBuf; 631 | 632 | DIALOGCONTROL * pDlgTemp = (DIALOGCONTROL *)pBuf; 633 | DIALOGCONTROL stDialogCtrl; 634 | 635 | if(0xFFFF0001 == pDlgTemp->m_lStyle) 636 | { 637 | pBuf += 8; 638 | stDialogCtrl.m_dwHelpID = pDlgTemp->m_lExStyle; 639 | pDlgTemp = (DIALOGCONTROL *)pBuf; 640 | stDialogCtrl.m_dwIsExtend = 1; 641 | } 642 | 643 | if(FALSE == stDialogCtrl.m_dwIsExtend) 644 | { 645 | stDialogCtrl.m_lStyle = pDlgTemp->m_lStyle; 646 | stDialogCtrl.m_lExStyle = pDlgTemp->m_lExStyle; 647 | stDialogCtrl.m_NoOfItems = pDlgTemp->m_NoOfItems; 648 | stDialogCtrl.m_wX = pDlgTemp->m_wX; 649 | stDialogCtrl.m_wY = pDlgTemp->m_wY; 650 | stDialogCtrl.m_wCX = pDlgTemp->m_wCX; 651 | stDialogCtrl.m_wCY = pDlgTemp->m_wCY; 652 | } 653 | else 654 | { 655 | stDialogCtrl.m_lStyle = pDlgTemp->m_lExStyle; 656 | stDialogCtrl.m_lExStyle = pDlgTemp->m_lStyle; 657 | stDialogCtrl.m_NoOfItems = pDlgTemp->m_NoOfItems; 658 | stDialogCtrl.m_wX = pDlgTemp->m_wX; 659 | stDialogCtrl.m_wY = pDlgTemp->m_wY; 660 | stDialogCtrl.m_wCX = pDlgTemp->m_wCX; 661 | stDialogCtrl.m_wCY = pDlgTemp->m_wCY; 662 | } 663 | 664 | DWORD dwBaseUnit = GetDialogBaseUnits(); 665 | 666 | DWORD * pdwTemp = (DWORD *)&pDlgTemp->m_wControlID; 667 | 668 | if(0xFFFF == (pdwTemp[0]&0xFFFF)) 669 | { 670 | bHasMenu = TRUE; 671 | 672 | pdwTemp[0] = 0; 673 | BYTE * pTemp_1 = (BYTE *)&pdwTemp[0] + 2; 674 | BYTE * pTemp_2 = (BYTE *)&pdwTemp[0] + 4; 675 | int nSize = nBufSize - ((DWORD)pTemp_2-(DWORD)pBuf); 676 | memcpy(pTemp_1,pTemp_2,nSize); 677 | pdwTemp = (DWORD *)pTemp_1; 678 | } 679 | else 680 | { 681 | BYTE * pTemp = (BYTE *)pdwTemp; 682 | int nLen = 2; 683 | if(((WCHAR *)pdwTemp)[0]) 684 | { 685 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 686 | _tcscpy_s(stDialogCtrl.m_strMenuName,1023,(WCHAR *)pdwTemp); 687 | else 688 | { 689 | delete [] pBufferTemp; 690 | return -1; 691 | } 692 | 693 | nLen += (_tcslen(stDialogCtrl.m_strMenuName) * 2); 694 | } 695 | pdwTemp = (DWORD *)(pTemp + nLen); 696 | } 697 | 698 | if(0xFFFF == (pdwTemp[0]&0xFFFF)) 699 | { 700 | _stprintf_s(stDialogCtrl.m_strClassName,1023,_T("0x%X"),(WORD)(pdwTemp[0]>>16)); 701 | pdwTemp++; 702 | } 703 | else 704 | { 705 | int nLen = 2; 706 | BYTE * pTemp = (BYTE *)pdwTemp; 707 | if(((WCHAR *)pdwTemp)[0]) 708 | { 709 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 710 | _tcscpy_s(stDialogCtrl.m_strClassName,1023,(WCHAR *)pdwTemp); 711 | else 712 | { 713 | delete [] pBufferTemp; 714 | return -1; 715 | } 716 | 717 | nLen += (_tcslen(stDialogCtrl.m_strClassName) * 2); 718 | } 719 | pdwTemp = (DWORD *)(pTemp + nLen); 720 | } 721 | 722 | { 723 | int nLen = 2; 724 | BYTE * pTemp = (BYTE *)pdwTemp; 725 | if(((WCHAR *)pdwTemp)[0]) 726 | { 727 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 728 | _tcscpy_s(stDialogCtrl.m_strCaption,1023,(WCHAR *)pdwTemp); 729 | else 730 | { 731 | delete [] pBufferTemp; 732 | return -1; 733 | } 734 | 735 | nLen += (_tcslen(stDialogCtrl.m_strCaption) * 2); 736 | } 737 | pdwTemp = (DWORD *)(pTemp + nLen); 738 | } 739 | 740 | if(stDialogCtrl.m_lStyle & DS_SETFONT) 741 | { 742 | stDialogCtrl.m_wPointSize = (WORD)(pdwTemp[0] & 0xFFFF); 743 | pdwTemp = (DWORD *)(((BYTE *)pdwTemp) + 2); 744 | 745 | if(stDialogCtrl.m_dwIsExtend) 746 | { 747 | stDialogCtrl.m_wWeight = (WORD)(pdwTemp[0] & 0xFFFF); 748 | stDialogCtrl.m_bItalic = (BYTE)((pdwTemp[0] >> 16) & 0xFF); 749 | stDialogCtrl.m_bCharset = (BYTE)(pdwTemp[0] >> 24); 750 | pdwTemp++; 751 | } 752 | 753 | int nLen = 0; 754 | BYTE * pTemp = (BYTE *)pdwTemp; 755 | if(((WCHAR *)pdwTemp)[0]) 756 | { 757 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 758 | _tcscpy_s(stDialogCtrl.m_strFontName,1023,(WCHAR *)pdwTemp); 759 | else 760 | { 761 | delete [] pBufferTemp; 762 | return -1; 763 | } 764 | 765 | nLen += (_tcslen(stDialogCtrl.m_strFontName) * 2); 766 | } 767 | pdwTemp = (DWORD *)(pTemp + nLen); 768 | 769 | if(stDialogCtrl.m_wPointSize) 770 | { 771 | int nPoints = stDialogCtrl.m_wPointSize * 2; 772 | 773 | memset(&stDialogCtrl.m_lf,0,sizeof(stDialogCtrl.m_lf)); 774 | stDialogCtrl.m_lf.lfItalic = stDialogCtrl.m_bItalic; 775 | stDialogCtrl.m_lf.lfWeight = stDialogCtrl.m_wWeight; 776 | stDialogCtrl.m_lf.lfCharSet = stDialogCtrl.m_bCharset; 777 | stDialogCtrl.m_lf.lfHeight = nPoints;//MulDiv(nPoints,nPoints,dwBaseUnit>>16); 778 | if(32 > _tcslen(stDialogCtrl.m_strFontName)) 779 | wcscpy_s(stDialogCtrl.m_lf.lfFaceName,32,stDialogCtrl.m_strFontName); 780 | else 781 | { 782 | delete [] pBufferTemp; 783 | return -1; 784 | } 785 | 786 | HDC hdc = GetDC(m_hWnd); 787 | if(hdc) 788 | { 789 | HFONT hOldFont, hFont = CreateFontIndirect(&stDialogCtrl.m_lf); 790 | 791 | hOldFont = (HFONT)SelectObject(hdc,hFont); 792 | 793 | SIZE sSize; 794 | int nX = wcslen(stDialogCtrl.m_strFontName); 795 | GetTextExtentPoint32(hdc,stDialogCtrl.m_strFontName 796 | , nX, &sSize); 797 | 798 | nX = MulDiv(sSize.cx,1,nX) + 2; 799 | 800 | dwBaseUnit = (nPoints<<16) | nX; 801 | 802 | SelectObject(hdc,hOldFont); 803 | ReleaseDC(m_hWnd,hdc); 804 | } 805 | } 806 | } 807 | 808 | stDialogCtrl.m_rRect.left = MulDiv(pDlgTemp->m_wX, dwBaseUnit&0xFFFF, 4); 809 | stDialogCtrl.m_rRect.top = MulDiv(pDlgTemp->m_wY, dwBaseUnit>>16, 8); 810 | stDialogCtrl.m_rRect.right = stDialogCtrl.m_rRect.left 811 | + MulDiv(pDlgTemp->m_wCX, dwBaseUnit&0xFFFF, 4); 812 | stDialogCtrl.m_rRect.bottom = stDialogCtrl.m_rRect.top 813 | + MulDiv(pDlgTemp->m_wCY, dwBaseUnit>>16, 8); 814 | 815 | OffsetRect(&stDialogCtrl.m_rRect 816 | , -stDialogCtrl.m_rRect.left 817 | , -stDialogCtrl.m_rRect.top); 818 | 819 | if(bHasMenu) 820 | { 821 | int nSize = ((DWORD)pdwTemp-(DWORD)pBuf); 822 | nSize = (nSize % 4)%4; 823 | if(nSize) 824 | { 825 | BYTE * pTemp_1 = (BYTE *)&pdwTemp[0] + (4-nSize); 826 | nSize = nBufSize - ((DWORD)pTemp_1-(DWORD)pBuf); 827 | memcpy(pdwTemp,pTemp_1,nSize); 828 | } 829 | } 830 | 831 | m_hDlgWnd = CreateDialogIndirectParam(hInst 832 | , (LPCDLGTEMPLATE)pBackupBuf, m_hWnd 833 | , (DLGPROC)DialogWndProc, NULL); 834 | 835 | if(m_hDlgWnd) 836 | { 837 | stDialogCtrl.m_hWnd = m_hDlgWnd; 838 | DWORD dwStyle = stDialogCtrl.m_lStyle; 839 | 840 | dwStyle &= (~WS_POPUP); 841 | dwStyle = dwStyle | WS_CHILD | WS_BORDER | WS_SYSMENU; 842 | SetWindowLong(m_hDlgWnd,GWL_STYLE,dwStyle); 843 | 844 | SetParent(m_hDlgWnd,m_hWnd); 845 | SetWindowPos(m_hDlgWnd,NULL,4,4,0,0,SWP_NOSIZE); 846 | EnableWindow(m_hDlgWnd,FALSE); 847 | ShowWindow(m_hDlgWnd,SW_SHOW); 848 | 849 | { 850 | GetWindowRect(m_hDlgWnd,&m_rRect); 851 | int nWid = m_rRect.right - m_rRect.left; 852 | int nHei = m_rRect.bottom - m_rRect.top; 853 | 854 | POINT pt; 855 | pt.x = m_rRect.left; 856 | pt.y = m_rRect.top; 857 | ScreenToClient(m_hWnd,&pt); 858 | 859 | m_rRect.left = pt.x; 860 | m_rRect.right = m_rRect.left + nWid; 861 | m_rRect.top = pt.y; 862 | m_rRect.bottom = m_rRect.top + nHei; 863 | 864 | InflateRect(&m_rRect,2,2); 865 | } 866 | } 867 | 868 | int nCaptionWidth = 0; 869 | 870 | if((WS_CAPTION & stDialogCtrl.m_lStyle) 871 | || (WS_OVERLAPPED & stDialogCtrl.m_lStyle) 872 | || (WS_SYSMENU & stDialogCtrl.m_lStyle) 873 | || (WS_TILED & stDialogCtrl.m_lStyle)) 874 | { 875 | nCaptionWidth = GetSystemMetrics(SM_CYCAPTION); 876 | stDialogCtrl.m_nFlag = TRUE; 877 | OffsetRect(&stDialogCtrl.m_rRect,0,nCaptionWidth); 878 | } 879 | 880 | m_vDialogList.push_back(stDialogCtrl); 881 | 882 | nStructLen = (BYTE *)pdwTemp - (BYTE *)&m_pBuffer[pRes->m_nOffsetToData] + 2; 883 | 884 | if(nStructLen%4) 885 | { 886 | pdwTemp = (DWORD *)(((BYTE *)pdwTemp) + 2); 887 | nStructLen += 2; 888 | } 889 | 890 | for(int i=0;im_lExStyle; 906 | stDlgCtrl.m_lExStyle = pDlgTemp->m_NoOfItems; 907 | stDlgCtrl.m_wX = pDlgTemp->m_wX; 908 | stDlgCtrl.m_wY = pDlgTemp->m_wY; 909 | stDlgCtrl.m_wCX = pDlgTemp->m_wCX; 910 | stDlgCtrl.m_wCY = pDlgTemp->m_wCY; 911 | stDlgCtrl.m_wControlID = pDlgTemp->m_wControlID; 912 | } 913 | else 914 | { 915 | stDlgCtrl.m_lStyle = pDlgTemp->m_lStyle; 916 | stDlgCtrl.m_lExStyle = pDlgTemp->m_lExStyle; 917 | stDlgCtrl.m_wX = pDlgTemp->m_wX; 918 | stDlgCtrl.m_wY = pDlgTemp->m_wY; 919 | stDlgCtrl.m_wCX = pDlgTemp->m_wCX; 920 | stDlgCtrl.m_wCY = pDlgTemp->m_wCY; 921 | stDlgCtrl.m_wControlID = pDlgTemp->m_wControlID; 922 | } 923 | 924 | if(m_hDlgWnd) 925 | { 926 | stDlgCtrl.m_hWnd = GetDlgItem(m_hDlgWnd 927 | , stDlgCtrl.m_wControlID); 928 | } 929 | 930 | stDlgCtrl.m_rRect.left = MulDiv(pDlgTemp->m_wX, dwBaseUnit&0xFFFF, 4); 931 | stDlgCtrl.m_rRect.top = MulDiv(pDlgTemp->m_wY, dwBaseUnit>>16, 8); 932 | stDlgCtrl.m_rRect.right = stDlgCtrl.m_rRect.left 933 | + MulDiv(pDlgTemp->m_wCX, dwBaseUnit&0xFFFF, 4); 934 | stDlgCtrl.m_rRect.bottom = stDlgCtrl.m_rRect.top 935 | + MulDiv(pDlgTemp->m_wCY, dwBaseUnit>>16, 8); 936 | 937 | OffsetRect(&stDlgCtrl.m_rRect 938 | , stDialogCtrl.m_rRect.left 939 | , stDialogCtrl.m_rRect.top); 940 | 941 | nStructLen = ((DWORD)((BYTE *)&pDlgTemp->m_wPointSize) - (DWORD)((BYTE *)pdwTemp)); 942 | 943 | pdwTemp = (DWORD *)&pDlgTemp->m_wPointSize; 944 | 945 | if(stDialogCtrl.m_dwIsExtend) 946 | { 947 | pdwTemp = (DWORD *)((BYTE *)pdwTemp + 2); 948 | nStructLen += 2; 949 | } 950 | 951 | if(0xFFFF == (pdwTemp[0]&0xFFFF)) 952 | { 953 | _stprintf_s(stDlgCtrl.m_strClassName,1023,_T("0x%X"),(WORD)(pdwTemp[0]>>16)); 954 | pdwTemp++; 955 | nStructLen += sizeof(DWORD); 956 | } 957 | else 958 | { 959 | int nLen = 2; 960 | BYTE * pTemp = (BYTE *)pdwTemp; 961 | if(((WCHAR *)pdwTemp)[0]) 962 | { 963 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 964 | _tcscpy_s(stDlgCtrl.m_strClassName,1023,(WCHAR *)pdwTemp); 965 | else 966 | { 967 | delete [] pBufferTemp; 968 | return -1; 969 | } 970 | 971 | nLen += (_tcslen(stDlgCtrl.m_strClassName) * 2); 972 | } 973 | pdwTemp = (DWORD *)(pTemp + nLen); 974 | nStructLen += nLen; 975 | 976 | if(nStructLen%4) 977 | { 978 | pdwTemp = (DWORD *)(((BYTE *)pdwTemp) + 2); 979 | nStructLen += 2; 980 | } 981 | } 982 | 983 | if(0xFFFF == (pdwTemp[0]&0xFFFF)) 984 | { 985 | _stprintf_s(stDlgCtrl.m_strCaption,1023,_T("0x%X"),(WORD)(pdwTemp[0]>>16)); 986 | pdwTemp++; 987 | nStructLen += sizeof(DWORD); 988 | } 989 | else 990 | { 991 | int nLen = 2; 992 | BYTE * pTemp = (BYTE *)pdwTemp; 993 | if(((WCHAR *)pdwTemp)[0]) 994 | { 995 | if(1023 > _tcslen((WCHAR *)pdwTemp)) 996 | _tcscpy_s(stDlgCtrl.m_strCaption,1023,(WCHAR *)pdwTemp); 997 | else 998 | { 999 | delete [] pBufferTemp; 1000 | return -1; 1001 | } 1002 | 1003 | nLen += (_tcslen(stDlgCtrl.m_strCaption) * 2); 1004 | } 1005 | pdwTemp = (DWORD *)(pTemp + nLen); 1006 | nStructLen += nLen; 1007 | 1008 | if(nStructLen%4) 1009 | { 1010 | pdwTemp = (DWORD *)(((BYTE *)pdwTemp) + 2); 1011 | nStructLen += 2; 1012 | } 1013 | } 1014 | 1015 | if(nStructLen%4) 1016 | { 1017 | pdwTemp = (DWORD *)((BYTE *)pdwTemp + 2); 1018 | nStructLen += 2; 1019 | } 1020 | 1021 | m_vDialogList.push_back(stDlgCtrl); 1022 | } 1023 | 1024 | memcpy(&m_pBuffer[pRes->m_nOffsetToData],pBufferTemp,pRes->m_nSize+8); 1025 | 1026 | delete [] pBufferTemp; 1027 | 1028 | InvalidateRect(m_hWnd,NULL,TRUE); 1029 | UpdateWindow(m_hWnd); 1030 | } 1031 | 1032 | return 0; 1033 | } 1034 | 1035 | HWND CNikDialog::SetDialogData( HWND hParent 1036 | , RESOURCELIST * pRes 1037 | , BYTE * pBuffer 1038 | , int nFlag) 1039 | { 1040 | if ((!pRes) 1041 | || (!pBuffer)) 1042 | return NULL; 1043 | 1044 | int nCount = 0xFFFF & (nFlag>>16); 1045 | if(nCount > 0) 1046 | nCount--; 1047 | 1048 | nFlag = 0xFFFF & nFlag; 1049 | 1050 | if(hParent 1051 | || (!m_hWnd)) 1052 | { 1053 | CreateDialogWindow( hParent ); 1054 | SetWindowLong( m_hWnd, GWL_USERDATA, (LONG)this ); 1055 | m_pBuffer = pBuffer; 1056 | } 1057 | 1058 | if(m_hWnd) 1059 | { 1060 | _tstring strCaption = _T("Resource dialog Viewer"); 1061 | 1062 | if(pRes->m_chName[0]) 1063 | { 1064 | strCaption += _T(" - "); 1065 | strCaption += pRes->m_chName; 1066 | } 1067 | 1068 | SetWindowText( m_hWnd, strCaption.c_str()); 1069 | 1070 | if(MakeDialogList( pRes ) < 0) 1071 | return 0; 1072 | 1073 | POINT pt; 1074 | pt.x = 20 * nCount; 1075 | pt.y = 20 * nCount; 1076 | ShowWindowPosition( (NULL != hParent), pt ); 1077 | } 1078 | 1079 | return m_hWnd; 1080 | } -------------------------------------------------------------------------------- /NikPEViewer/PEBinaryFile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "stdafx.h" 3 | #include "Resource.h" 4 | #include "PEBinaryFile.h" 5 | 6 | void CBinaryEditor::DrawRectArea( HDC hdc 7 | , RECT rc 8 | , COLORREF col) 9 | { 10 | if (hdc) 11 | { 12 | HBRUSH hBrush = CreateSolidBrush(col); 13 | HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,hBrush); 14 | 15 | FillRect(hdc,&rc,hBrush); 16 | 17 | SelectObject(hdc,hOldBrush); 18 | 19 | DeleteObject(hBrush); 20 | } 21 | } 22 | 23 | CBinaryEditor::CBinaryEditor( HWND hWnd ): 24 | m_hFont( NULL ) 25 | , m_hBitmap( NULL ) 26 | , m_pbBinBuffer( NULL ) 27 | , m_nMaxCharLen( 0 ) 28 | , m_nLineHeight( 0 ) 29 | , m_nBinarySize( 0 ) 30 | , m_nLineNumbers( 0 ) 31 | , m_nTotalLineNo( 0 ) 32 | , m_nASCIIOffset( 0 ) 33 | , m_nLeftBoundary( 0 ) 34 | , m_nAveCharWidth( 0 ) 35 | , m_nBufferOffset( 0 ) 36 | , m_nSelectionEnd( -1 ) 37 | , m_nSelectionStart( -1 ) 38 | , m_nLineNumberWidth( 0 ) 39 | , m_bBinHeaderEnable( TRUE ) 40 | , m_bLineNumberEnable( TRUE ) 41 | , m_nBinRowNumbers( BINARY_CHAR_ROW ) 42 | { 43 | memset(&m_rDrawArea,0,sizeof(RECT)); 44 | 45 | memset(&m_lf,0,sizeof(LOGFONT)); 46 | 47 | m_nTabsSizes[0] = EDITOR_TAB_SIZE; 48 | m_nTabsSizes[1] = EDITOR_TAB_SIZE; 49 | 50 | _tcscpy_s(m_lf.lfFaceName,sizeof(m_lf.lfFaceName)/sizeof(TCHAR),EDITOR_FONT); 51 | m_lf.lfClipPrecision = 2; 52 | m_lf.lfHeight = -15; 53 | m_lf.lfQuality = 1; 54 | m_lf.lfWeight = 400; 55 | m_lf.lfOutPrecision = 3; 56 | m_lf.lfPitchAndFamily = 34; 57 | 58 | HDC hdc = GetDC( hWnd ); 59 | if(hdc) 60 | { 61 | CreateEditorFont( hdc ); 62 | ReleaseDC(hWnd, hdc); 63 | } 64 | } 65 | 66 | CBinaryEditor::~CBinaryEditor() 67 | { 68 | if(m_hBitmap) 69 | DeleteObject(m_hBitmap); 70 | 71 | if(m_hFont) 72 | DeleteObject(m_hFont); 73 | } 74 | 75 | int CBinaryEditor::GetBinOffsetfromPt( POINT pt ) 76 | { 77 | int nOffsetY, nOffsetX; 78 | int nBinOffset; 79 | 80 | nOffsetY = pt.y - m_nLineHeight; 81 | nOffsetY = nOffsetY / m_nLineHeight; 82 | 83 | int nDiffOffset = pt.x - m_nASCIIOffset + m_nMaxCharLen; 84 | 85 | if(nDiffOffset < 0) 86 | { 87 | int nCharsLen = m_nMaxCharLen * 3; 88 | nOffsetX = pt.x - (m_nLeftBoundary + m_nMaxCharLen); 89 | if( nOffsetX < 0 ) 90 | nOffsetX = 0; 91 | 92 | nDiffOffset = nOffsetX + ((m_nBinRowNumbers>>1) * nCharsLen); 93 | if(pt.x > nDiffOffset) 94 | { 95 | nDiffOffset += m_nMaxCharLen; 96 | nOffsetX -= nDiffOffset; 97 | } 98 | else 99 | nDiffOffset = 0; 100 | 101 | nOffsetX = (nOffsetX + m_nMaxCharLen) / nCharsLen; 102 | } 103 | else 104 | { 105 | nOffsetX = pt.x - m_nASCIIOffset; 106 | nOffsetX = nOffsetX / m_nMaxCharLen; 107 | } 108 | 109 | nBinOffset = (nOffsetY*m_nBinRowNumbers) + nOffsetX; 110 | 111 | nBinOffset += m_nBufferOffset; 112 | 113 | return nBinOffset; 114 | } 115 | 116 | POINT CBinaryEditor::GetBinPtfromOffset( int nOffset 117 | , int nASCIIOffset ) 118 | { 119 | POINT pt; 120 | 121 | int nHeight = m_rDrawArea.bottom - m_rDrawArea.top; 122 | int nPageLines = (nHeight / m_nLineHeight) + 1; 123 | int nEndPage = m_nBufferOffset + (m_nBinRowNumbers * nPageLines); 124 | nEndPage -= 1; 125 | 126 | /// page bound check 127 | if(nOffset < m_nBufferOffset) 128 | nOffset = m_nBufferOffset; 129 | if(nOffset > nEndPage) 130 | nOffset = nEndPage; 131 | 132 | /// Binary buffer bound check 133 | if(nOffset < 0) 134 | nOffset = 0; 135 | if(nOffset > m_nBinarySize) 136 | nOffset = m_nBinarySize; 137 | 138 | int nPageBufOffset = nOffset - m_nBufferOffset; 139 | 140 | pt.y = (nPageBufOffset / m_nBinRowNumbers) * m_nLineHeight; 141 | pt.y += m_nLineHeight; 142 | 143 | int nXLineOffset = nPageBufOffset % m_nBinRowNumbers; 144 | int nBreak = (m_nBinRowNumbers>>1) - 1; 145 | 146 | if(0 == nASCIIOffset) 147 | { 148 | int nXOffset = m_nLeftBoundary + m_nMaxCharLen; 149 | pt.x = ((m_nMaxCharLen * 3) * nXLineOffset) + nXOffset; 150 | if(nXLineOffset > nBreak) 151 | pt.x += m_nMaxCharLen; 152 | } 153 | else 154 | { 155 | pt.x = (m_nMaxCharLen * nXLineOffset) + m_nASCIIOffset; 156 | } 157 | 158 | return pt; 159 | } 160 | 161 | void CBinaryEditor::SetScrollBar( HWND hWnd ) 162 | { 163 | RECT rc; 164 | GetClientRect(hWnd, &rc); 165 | 166 | // Set the vertical scrolling range and page size 167 | SCROLLINFO si; 168 | si.cbSize = sizeof (si); 169 | si.fMask = SIF_ALL; 170 | 171 | si.cbSize = sizeof(si); 172 | si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; 173 | si.nMin = 0; 174 | if(m_nTotalLineNo > 0) 175 | si.nMax = m_nTotalLineNo; 176 | else 177 | si.nMax = 0; 178 | 179 | if(m_nLineHeight) 180 | si.nPage = rc.bottom/m_nLineHeight; 181 | else 182 | si.nPage = 0; 183 | 184 | si.nPos = m_nBufferOffset/m_nBinRowNumbers; 185 | if((int)(si.nPos+si.nPage + 1) > si.nMax) 186 | { 187 | si.nPos = si.nMax - si.nPage + 1; 188 | m_nBufferOffset = si.nPos * m_nBinRowNumbers; 189 | 190 | InvalidateRect( hWnd, NULL, TRUE ); 191 | UpdateWindow( hWnd ); 192 | } 193 | 194 | SetScrollInfo(hWnd, SB_VERT, &si, TRUE); 195 | } 196 | 197 | void CBinaryEditor::OnScrollBar(HWND hWnd 198 | , int nFlag 199 | , WPARAM wParam) 200 | { 201 | SCROLLINFO si; 202 | si.cbSize = sizeof (si); 203 | si.fMask = SIF_ALL; 204 | 205 | if(WM_VSCROLL == nFlag) 206 | { 207 | GetScrollInfo (hWnd, SB_VERT, &si); 208 | 209 | int nCurPos = si.nPos; 210 | 211 | switch (LOWORD (wParam)) 212 | { 213 | // user clicked the HOME keyboard key 214 | case UM_WHEELUP: 215 | si.nPos -= 3; 216 | break; 217 | 218 | case UM_WHEELDOWN: 219 | si.nPos += 3; 220 | break; 221 | 222 | case SB_TOP: 223 | si.nPos = si.nMin; 224 | break; 225 | 226 | // user clicked the END keyboard key 227 | case SB_BOTTOM: 228 | si.nPos = si.nMax; 229 | break; 230 | 231 | // user clicked the top arrow 232 | case SB_LINEUP: 233 | si.nPos -= 1; 234 | break; 235 | 236 | // user clicked the bottom arrow 237 | case SB_LINEDOWN: 238 | si.nPos += 1; 239 | break; 240 | 241 | // user clicked the scroll bar shaft above the scroll box 242 | case SB_PAGEUP: 243 | si.nPos -= si.nPage; 244 | break; 245 | 246 | // user clicked the scroll bar shaft below the scroll box 247 | case SB_PAGEDOWN: 248 | si.nPos += si.nPage; 249 | break; 250 | 251 | // user dragged the scroll box 252 | case SB_THUMBTRACK: 253 | si.nPos = si.nTrackPos; 254 | break; 255 | 256 | default: 257 | break; 258 | } 259 | // Set the position and then retrieve it. Due to adjustments 260 | // by Windows it may not be the same as the value set. 261 | si.fMask = SIF_POS; 262 | SetScrollInfo (hWnd, SB_VERT, &si, TRUE); 263 | GetScrollInfo (hWnd, SB_VERT, &si); 264 | // If the position has changed, scroll window and update it 265 | if (si.nPos != nCurPos) 266 | { 267 | RECT rc; 268 | GetClientRect( hWnd, &rc ); 269 | rc.top += m_nLineHeight + 2; 270 | m_nBufferOffset = si.nPos * m_nBinRowNumbers; 271 | ScrollWindowEx( hWnd, 0, m_nLineHeight * (nCurPos - si.nPos) 272 | , &rc, &rc, NULL, &rc, SW_INVALIDATE ); 273 | } 274 | } 275 | } 276 | 277 | void CBinaryEditor::CalculateBinRowNumber() 278 | { 279 | if(!IsRectEmpty( &m_rDrawArea )) 280 | { 281 | int nWidth = (m_rDrawArea.right - m_rDrawArea.left); 282 | nWidth -= m_nLeftBoundary; 283 | 284 | if(nWidth < m_nMaxCharLen) 285 | m_nBinRowNumbers = 2; 286 | else 287 | { 288 | int nCharLength = m_nMaxCharLen + (m_nMaxCharLen>>1); 289 | int nRows = (nWidth / nCharLength) - 1; 290 | nRows -= EDITOR_TAB_SIZE; 291 | m_nBinRowNumbers = nRows/3; 292 | if(m_nBinRowNumbers < 2) 293 | m_nBinRowNumbers = 2; 294 | } 295 | 296 | m_nTotalLineNo = m_nBinarySize / m_nBinRowNumbers; 297 | } 298 | } 299 | 300 | void CBinaryEditor::CreateEditorFont( HDC hdc ) 301 | { 302 | if(m_hFont) 303 | DeleteObject(m_hFont); 304 | 305 | m_hFont = CreateFontIndirect(&m_lf); 306 | 307 | CalculateLineHeight( hdc ); 308 | } 309 | 310 | void CBinaryEditor::CalculateCharLen( HDC hdc ) 311 | { 312 | if(hdc) 313 | { 314 | HFONT hOldFont = (HFONT)SelectObject(hdc, m_hFont); 315 | 316 | DWORD dwSize; 317 | TCHAR chBuf[2]; 318 | chBuf[1] = 0; 319 | 320 | m_nMaxCharLen = 0; 321 | 322 | for(int i=0; i<256; i++) 323 | { 324 | chBuf[0] = (TCHAR)i; 325 | dwSize = GetTabbedTextExtent( hdc 326 | , chBuf 327 | , 1 328 | , 1 329 | , m_nTabsSizes); 330 | 331 | if(m_nMaxCharLen < LOWORD(dwSize)) 332 | { 333 | if((i >= (char)'A') 334 | && (i <= (char)'Z')) 335 | m_nMaxCharLen = LOWORD(dwSize); 336 | } 337 | } 338 | 339 | SelectObject(hdc,hOldFont); 340 | } 341 | } 342 | 343 | void CBinaryEditor::CalculateLineHeight( HDC hdc ) 344 | { 345 | if(hdc) 346 | { 347 | CalculateCharLen( hdc ); 348 | 349 | HFONT hOldFont = (HFONT)SelectObject(hdc, m_hFont); 350 | 351 | SIZE sSize; 352 | int nChar = sizeof(TES_STRING)/sizeof(TCHAR) - 1; 353 | GetTextExtentPoint32(hdc 354 | ,TES_STRING 355 | ,nChar 356 | ,&sSize); 357 | 358 | m_nLineHeight = sSize.cy; 359 | 360 | m_nAveCharWidth = (sSize.cx+nChar-1)/nChar; 361 | 362 | m_nTabsSizes[0] = m_nAveCharWidth * EDITOR_TAB_SIZE; 363 | m_nTabsSizes[1] = m_nAveCharWidth * EDITOR_TAB_SIZE; 364 | 365 | int nBinLineWidth = m_nMaxCharLen * (3*(m_nBinRowNumbers+1)); 366 | m_nLineNumberWidth = m_nMaxCharLen * 11; 367 | 368 | m_nASCIIOffset = m_nLineNumberWidth + LEFT_WINDOW_BAR + nBinLineWidth + m_nMaxCharLen; 369 | 370 | SelectObject(hdc,hOldFont); 371 | 372 | m_nLeftBoundary = LEFT_WINDOW_BAR; 373 | if(m_bLineNumberEnable) 374 | m_nLeftBoundary += m_nLineNumberWidth; 375 | } 376 | } 377 | 378 | void CBinaryEditor::SetSelection( int nStart 379 | , int nEnd) 380 | { 381 | m_nSelectionEnd = nEnd; 382 | m_nSelectionStart = nStart; 383 | 384 | m_stSelectRect[0].ResetSelection(); 385 | m_stSelectRect[1].ResetSelection(); 386 | m_stSelectRect[2].ResetSelection(); 387 | 388 | memset( &m_rACSIIRect[0], 0, sizeof(RECT)); 389 | memset( &m_rACSIIRect[1], 0, sizeof(RECT)); 390 | memset( &m_rACSIIRect[2], 0, sizeof(RECT)); 391 | 392 | if(m_nSelectionEnd != m_nSelectionStart) 393 | { 394 | if(m_nSelectionEnd < m_nSelectionStart) 395 | { 396 | int nTemp = m_nSelectionEnd; 397 | m_nSelectionEnd = m_nSelectionStart; 398 | m_nSelectionStart = nTemp; 399 | } 400 | 401 | POINT ptStart, ptEnd; 402 | int nStart = m_nBinRowNumbers - (m_nSelectionStart % m_nBinRowNumbers); 403 | nStart = m_nSelectionStart + nStart - 1; 404 | 405 | int nEnd = m_nSelectionEnd % m_nBinRowNumbers; 406 | nEnd = m_nSelectionEnd - nEnd; 407 | 408 | if(nEnd > nStart) 409 | { 410 | if( nStart >= m_nBufferOffset ) 411 | { 412 | ptEnd = GetBinPtfromOffset( nStart, 0 ); 413 | ptStart = GetBinPtfromOffset( m_nSelectionStart, 0 ); 414 | 415 | m_stSelectRect[0].m_nEnd = nStart; 416 | m_stSelectRect[0].m_nStart = m_nSelectionStart; 417 | m_stSelectRect[0].m_rSelect.left = ptStart.x; 418 | m_stSelectRect[0].m_rSelect.right = ptEnd.x + (m_nMaxCharLen<<1); 419 | m_stSelectRect[0].m_rSelect.top = ptStart.y; 420 | m_stSelectRect[0].m_rSelect.bottom = ptEnd.y + m_nLineHeight; 421 | 422 | ptEnd = GetBinPtfromOffset( nStart, 1 ); 423 | ptStart = GetBinPtfromOffset( m_nSelectionStart, 1 ); 424 | m_rACSIIRect[0].left = ptStart.x; 425 | m_rACSIIRect[0].top = ptStart.y; 426 | m_rACSIIRect[0].right = ptEnd.x + m_nMaxCharLen; 427 | m_rACSIIRect[0].bottom = ptEnd.y + m_nLineHeight; 428 | } 429 | 430 | if( m_nSelectionEnd >= m_nBufferOffset ) 431 | { 432 | ptEnd = GetBinPtfromOffset( m_nSelectionEnd, 0 ); 433 | ptStart = GetBinPtfromOffset( nEnd, 0 ); 434 | m_stSelectRect[1].m_nEnd = m_nSelectionEnd; 435 | m_stSelectRect[1].m_nStart = nEnd; 436 | m_stSelectRect[1].m_rSelect.left = ptStart.x; 437 | m_stSelectRect[1].m_rSelect.right = ptEnd.x - m_nMaxCharLen; 438 | m_stSelectRect[1].m_rSelect.top = ptStart.y; 439 | m_stSelectRect[1].m_rSelect.bottom = ptEnd.y + m_nLineHeight; 440 | 441 | ptEnd = GetBinPtfromOffset( m_nSelectionEnd, 1 ); 442 | ptStart = GetBinPtfromOffset( nEnd, 1 ); 443 | m_rACSIIRect[1].left = ptStart.x; 444 | m_rACSIIRect[1].top = ptStart.y; 445 | m_rACSIIRect[1].right = ptEnd.x; 446 | m_rACSIIRect[1].bottom = ptEnd.y + m_nLineHeight; 447 | } 448 | 449 | nEnd--; 450 | nStart++; 451 | if(nEnd > nStart) 452 | { 453 | if( nEnd >= m_nBufferOffset ) 454 | { 455 | ptEnd = GetBinPtfromOffset( nEnd, 0 ); 456 | ptStart = GetBinPtfromOffset( nStart, 0 ); 457 | m_stSelectRect[2].m_nEnd = nEnd; 458 | m_stSelectRect[2].m_nStart = nStart; 459 | m_stSelectRect[2].m_rSelect.left = ptStart.x; 460 | m_stSelectRect[2].m_rSelect.right = ptEnd.x + (m_nMaxCharLen<<1); 461 | m_stSelectRect[2].m_rSelect.top = ptStart.y; 462 | m_stSelectRect[2].m_rSelect.bottom = ptEnd.y + m_nLineHeight; 463 | 464 | ptEnd = GetBinPtfromOffset( nEnd, 1 ); 465 | ptStart = GetBinPtfromOffset( nStart, 1 ); 466 | m_rACSIIRect[2].left = ptStart.x; 467 | m_rACSIIRect[2].top = ptStart.y; 468 | m_rACSIIRect[2].right = ptEnd.x + m_nMaxCharLen; 469 | m_rACSIIRect[2].bottom = ptEnd.y + m_nLineHeight; 470 | } 471 | } 472 | } 473 | else 474 | { 475 | ptEnd = GetBinPtfromOffset( m_nSelectionEnd, 0 ); 476 | ptStart = GetBinPtfromOffset( m_nSelectionStart, 0 ); 477 | m_stSelectRect[0].m_nEnd = m_nSelectionEnd; 478 | m_stSelectRect[0].m_nStart = m_nSelectionStart; 479 | m_stSelectRect[0].m_rSelect.left = ptStart.x; 480 | m_stSelectRect[0].m_rSelect.right = ptEnd.x - m_nMaxCharLen; 481 | m_stSelectRect[0].m_rSelect.top = ptStart.y; 482 | m_stSelectRect[0].m_rSelect.bottom = ptEnd.y + m_nLineHeight; 483 | 484 | ptEnd = GetBinPtfromOffset( m_nSelectionEnd, 1 ); 485 | ptStart = GetBinPtfromOffset( m_nSelectionStart, 1 ); 486 | m_rACSIIRect[0].left = ptStart.x; 487 | m_rACSIIRect[0].top = ptStart.y; 488 | m_rACSIIRect[0].right = ptEnd.x; 489 | m_rACSIIRect[0].bottom = ptEnd.y + m_nLineHeight; 490 | } 491 | } 492 | else 493 | { 494 | m_nSelectionEnd = -1; 495 | m_nSelectionStart = -1; 496 | } 497 | } 498 | 499 | void CBinaryEditor::DrawTextSelection( HDC hdc ) 500 | { 501 | if( hdc && IsBinSelection()) 502 | { 503 | if(!IsRectEmpty(&m_stSelectRect[0].m_rSelect)) 504 | { 505 | DrawRectArea(hdc, m_stSelectRect[0].m_rSelect, BIN_SELECTION_COLOR); 506 | DrawRectArea(hdc, m_rACSIIRect[0], TEXT_SELECTION_COLOR); 507 | } 508 | 509 | if(!IsRectEmpty(&m_stSelectRect[1].m_rSelect)) 510 | { 511 | DrawRectArea(hdc, m_stSelectRect[1].m_rSelect, BIN_SELECTION_COLOR); 512 | DrawRectArea(hdc, m_rACSIIRect[1], TEXT_SELECTION_COLOR); 513 | } 514 | 515 | if(!IsRectEmpty(&m_stSelectRect[2].m_rSelect)) 516 | { 517 | DrawRectArea(hdc, m_stSelectRect[2].m_rSelect, BIN_SELECTION_COLOR); 518 | DrawRectArea(hdc, m_rACSIIRect[2], TEXT_SELECTION_COLOR); 519 | } 520 | } 521 | } 522 | 523 | void CBinaryEditor::DrawBinBackground( HDC hdc ) 524 | { 525 | if (hdc) 526 | { 527 | RECT rc = m_rDrawArea; 528 | rc.left = LEFT_WINDOW_BAR; 529 | DrawRectArea(hdc, rc, WINDOW_BACKGROUND_COLOR); 530 | 531 | rc.left = 0; 532 | rc.right = LEFT_WINDOW_BAR; 533 | DrawRectArea(hdc, rc, SIDE_BAR_COLOR); 534 | SetSelection( m_nSelectionStart, m_nSelectionEnd ); 535 | DrawTextSelection( hdc ); 536 | } 537 | } 538 | 539 | void CBinaryEditor::DrawBinaryLineNumber(HDC hdc) 540 | { 541 | if(hdc 542 | && (TRUE == IsLinenumberEnable())) 543 | { 544 | RECT rc = m_rDrawArea; 545 | 546 | TCHAR chLineNo[64]; 547 | COLORREF col = SetTextColor(hdc, LINE_NUMBER_COLOR); 548 | 549 | HPEN hOldPen,hPen = CreatePen(PS_DOT, 1, LINE_NUMBER_COLOR); 550 | hOldPen = (HPEN)SelectObject(hdc,hPen); 551 | 552 | HFONT hFontOld = (HFONT)SelectObject(hdc,m_hFont); 553 | 554 | rc.left = LEFT_WINDOW_BAR; 555 | rc.right = rc.left + m_nLineNumberWidth; 556 | rc.top = m_rDrawArea.top; 557 | rc.bottom = rc.top + m_nLineHeight; 558 | 559 | if(IsBinHeaderEnable()) 560 | OffsetRect(&rc, 0, m_nLineHeight); 561 | 562 | for(int i=0; i 0) 574 | { 575 | int nYOffset = m_rDrawArea.top + m_nLineHeight; 576 | int nOffset = m_nLineNumberWidth + LEFT_WINDOW_BAR; 577 | MoveToEx(hdc, nOffset, nYOffset, NULL); 578 | LineTo(hdc, nOffset, rc.bottom+1); 579 | 580 | nOffset = m_nASCIIOffset - (m_nMaxCharLen<<1); 581 | MoveToEx(hdc, nOffset, nYOffset, NULL); 582 | LineTo(hdc, nOffset, rc.bottom+1); 583 | } 584 | 585 | SetTextColor(hdc,col); 586 | SelectObject(hdc,hFontOld); 587 | SelectObject(hdc,hOldPen); 588 | 589 | DeleteObject(hPen); 590 | } 591 | } 592 | 593 | void CBinaryEditor::DrawLineBinary( HDC hdc 594 | , BYTE * pBuffer 595 | , int nOffsetX 596 | , int nOffsetY 597 | , int nLineOffset) 598 | { 599 | if(hdc) 600 | { 601 | BYTE * pBuff = pBuffer; 602 | int nSize = m_nBinarySize - nLineOffset; 603 | 604 | TCHAR chBuf[0x10]; 605 | chBuf[0] = 0; 606 | 607 | int i = 0; 608 | int nBreak = (m_nBinRowNumbers>>1) - 1; 609 | 610 | _tstring strBin, strASCII; 611 | while(i < nSize) 612 | { 613 | _stprintf_s(chBuf, sizeof(chBuf)/sizeof(TCHAR), _T("%02X "), pBuff[i]); 614 | strBin += chBuf; 615 | 616 | if((pBuff[i] >= 0x20) 617 | && (pBuff[i] < 0x80)) 618 | _stprintf_s(chBuf, sizeof(chBuf)/sizeof(TCHAR), _T("%c"),pBuff[i]); 619 | else 620 | { 621 | chBuf[0] = _T('.'); 622 | chBuf[1] = 0; 623 | } 624 | 625 | strASCII += chBuf; 626 | 627 | if(i == nBreak) 628 | strBin += _T(" "); 629 | 630 | i++; 631 | if(i >= m_nBinRowNumbers) 632 | break; 633 | } 634 | 635 | TextOut(hdc, nOffsetX+m_nMaxCharLen, nOffsetY, strBin.c_str(), strBin.length()); 636 | TextOut(hdc, m_nASCIIOffset, nOffsetY, strASCII.c_str(), strASCII.length()); 637 | } 638 | } 639 | 640 | void CBinaryEditor::DrawBinaryHeader( HDC hdc ) 641 | { 642 | if(hdc && (IsBinHeaderEnable())) 643 | { 644 | TCHAR chBuf[0x10]; 645 | chBuf[0] = 0; 646 | 647 | COLORREF col = SetTextColor(hdc, LINE_NUMBER_COLOR); 648 | HPEN hOldPen,hPen = CreatePen(PS_DOT, 1, LINE_NUMBER_COLOR); 649 | hOldPen = (HPEN)SelectObject(hdc,hPen); 650 | HFONT hFontOld = (HFONT)SelectObject(hdc, m_hFont); 651 | 652 | RECT rc = m_rDrawArea; 653 | MoveToEx(hdc, rc.left+LEFT_WINDOW_BAR, rc.top+m_nLineHeight, NULL); 654 | LineTo(hdc, rc.right, rc.top+m_nLineHeight); 655 | 656 | rc.left = LEFT_WINDOW_BAR; 657 | rc.right = rc.left + m_nLineNumberWidth; 658 | rc.top = m_rDrawArea.top; 659 | rc.bottom = rc.top + m_nLineHeight; 660 | 661 | DrawText(hdc, HEADER_ADD, _tcslen(HEADER_ADD), &rc, DT_TOP|DT_CENTER|DT_NOCLIP); 662 | 663 | int nOffsetY = m_rDrawArea.top; 664 | int nOffset = m_rDrawArea.left + m_nLeftBoundary + m_nMaxCharLen; 665 | int nBreak = (m_nBinRowNumbers>>1) - 1; 666 | 667 | _tstring strTemp = _T(""); 668 | 669 | for(int i=0; i rc.bottom) 715 | break; 716 | } 717 | } 718 | } 719 | 720 | void CBinaryEditor::DrawBinForground( HDC hdc ) 721 | { 722 | if (hdc && m_pbBinBuffer) 723 | { 724 | RECT rc = m_rDrawArea; 725 | 726 | rc.left += m_nLeftBoundary; 727 | 728 | HRGN hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); 729 | SelectClipRgn(hdc, hrgn); 730 | 731 | int nMode; 732 | 733 | nMode = SetBkMode(hdc,TRANSPARENT); 734 | 735 | HFONT hOldFont = (HFONT)SelectObject(hdc, m_hFont); 736 | 737 | DrawBinaryData(hdc, m_pbBinBuffer, rc); 738 | 739 | SelectObject(hdc, hOldFont); 740 | 741 | SetBkMode(hdc, nMode); 742 | SelectClipRgn(hdc, NULL); 743 | DeleteObject(hrgn); 744 | 745 | DrawBinaryLineNumber(hdc); 746 | DrawBinaryHeader(hdc); 747 | } 748 | } 749 | 750 | void CBinaryEditor::DrawBinEditor( HDC hdc ) 751 | { 752 | if (hdc) 753 | { 754 | DrawBinBackground( hdc ); 755 | DrawBinForground( hdc ); 756 | } 757 | } 758 | 759 | void CBinaryEditor::PaintWindow( HDC hdc ) 760 | { 761 | if(hdc) 762 | { 763 | HDC memDC = CreateCompatibleDC ( hdc ); 764 | 765 | int nWidth, nHeight; 766 | GetEditorWindowSize(nWidth, nHeight); 767 | 768 | if(NULL == GetEditorBitmap()) 769 | { 770 | HBITMAP hBitmap = CreateCompatibleBitmap ( hdc 771 | , nWidth 772 | , nHeight ); 773 | SetEditorBitmap(hBitmap); 774 | } 775 | 776 | HBITMAP OldBM = (HBITMAP)SelectObject ( memDC, GetEditorBitmap() ); 777 | 778 | DrawBinEditor(memDC); 779 | 780 | BitBlt(hdc,0,0,nWidth,nHeight,memDC,0,0,SRCCOPY); 781 | 782 | SelectObject ( hdc, OldBM); 783 | 784 | DeleteDC(memDC); 785 | } 786 | } 787 | 788 | ///------------------------------------ 789 | 790 | TCHAR szToolClassName[] = _T("TOOL_CHILD_WINDOW"); 791 | 792 | CNikPEBinaryViewer::CNikPEBinaryViewer() 793 | { 794 | m_hWnd = NULL; 795 | m_hInstance = NULL; 796 | m_pBinaryEditor = NULL; 797 | } 798 | 799 | CNikPEBinaryViewer::~CNikPEBinaryViewer() 800 | { 801 | if(m_pBinaryEditor) 802 | delete m_pBinaryEditor; 803 | } 804 | 805 | HWND CNikPEBinaryViewer::CreateBinaryViewer(HINSTANCE hInstance 806 | , HWND hParent 807 | , RECT rcWidRect 808 | , _tstring strCaption) 809 | { 810 | if(hParent && hInstance) 811 | { 812 | WNDCLASS wc; 813 | BOOL bResult; 814 | 815 | memset(&wc, 0, sizeof(WNDCLASS)); 816 | wc.lpfnWndProc = (WNDPROC)ToolChildWndProc; 817 | wc.cbClsExtra = 0; 818 | wc.cbWndExtra = 8; 819 | wc.hInstance = hInstance; 820 | wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_NIKPEVIEWER) ); 821 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 822 | wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); 823 | wc.lpszMenuName = NULL; 824 | wc.lpszClassName = szToolClassName; 825 | bResult = RegisterClass( &wc ); 826 | 827 | DWORD dwStyle = WS_TABSTOP | 828 | WS_VISIBLE | 829 | WS_SIZEBOX | 830 | WS_CAPTION | 831 | WS_SYSMENU | 832 | LVS_REPORT | 833 | WS_CHILDWINDOW | 834 | WS_CLIPSIBLINGS | 835 | LVS_NOSORTHEADER | 836 | 0; 837 | 838 | m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW 839 | , szToolClassName 840 | , strCaption.c_str() 841 | , dwStyle 842 | , rcWidRect.left, rcWidRect.top 843 | , rcWidRect.right - rcWidRect.left 844 | , rcWidRect.bottom - rcWidRect.top 845 | , hParent, NULL, hInstance, NULL ); 846 | 847 | if(m_hWnd) 848 | { 849 | m_hInstance = hInstance; 850 | m_pBinaryEditor = new CBinaryEditor( m_hWnd ); 851 | SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)m_pBinaryEditor); 852 | } 853 | } 854 | 855 | return m_hWnd; 856 | } 857 | 858 | int CNikPEBinaryViewer::SetBinaryData(BYTE * pBuffer 859 | , int nSize) 860 | { 861 | if(pBuffer 862 | && m_pBinaryEditor) 863 | { 864 | m_pBinaryEditor->SetBinBuffer( pBuffer, nSize, 0 ); 865 | m_pBinaryEditor->SetScrollBar( m_hWnd ); 866 | } 867 | 868 | return 0; 869 | } 870 | 871 | LRESULT CALLBACK CNikPEBinaryViewer::ToolChildWndProc( HWND hWnd 872 | , UINT uMsg 873 | , WPARAM wParam 874 | , LPARAM lParam ) 875 | { 876 | //static int nStartValue, nCapture = 0; 877 | CBinaryEditor * pBinaryEditor = (CBinaryEditor *)GetWindowLong(hWnd, GWL_USERDATA); 878 | 879 | switch( uMsg ) 880 | { 881 | 882 | case WM_LBUTTONDOWN: 883 | if(pBinaryEditor) 884 | { 885 | /*POINT pt; 886 | pt.x = lParam & 0xFFFF; 887 | pt.y = (lParam >> 16) & 0xFFFF; 888 | nStartValue = pBinaryEditor->GetBinOffsetfromPt( pt ); 889 | SetCapture( hWnd ); 890 | nCapture = 1;*/ 891 | SetWindowPos( hWnd, HWND_TOP, 0 , 0, 0, 0 892 | , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); 893 | } 894 | break; 895 | 896 | case WM_LBUTTONUP: 897 | if(pBinaryEditor 898 | /*&& (1 == nCapture)*/) 899 | { 900 | /*POINT pt; 901 | pt.x = lParam & 0xFFFF; 902 | pt.y = (lParam >> 16) & 0xFFFF; 903 | int nEndValue = pBinaryEditor->GetBinOffsetfromPt( pt ); 904 | pBinaryEditor->SetSelection( nStartValue, nEndValue ); 905 | 906 | ReleaseCapture(); 907 | nCapture = 0; 908 | 909 | InvalidateRect( hWnd, NULL, TRUE ); 910 | UpdateWindow( hWnd );*/ 911 | SetFocus(hWnd); 912 | } 913 | break; 914 | 915 | case WM_MOUSEMOVE: 916 | if(pBinaryEditor 917 | && (MK_LBUTTON & wParam) 918 | /*&& (1 == nCapture)*/) 919 | { 920 | /*POINT pt; 921 | pt.x = lParam & 0xFFFF; 922 | pt.y = (lParam >> 16) & 0xFFFF; 923 | int nEndValue = pBinaryEditor->GetBinOffsetfromPt( pt ); 924 | pBinaryEditor->SetSelection( nStartValue, nEndValue ); 925 | 926 | InvalidateRect( hWnd, NULL, TRUE ); 927 | UpdateWindow( hWnd );*/ 928 | } 929 | break; 930 | 931 | case WM_MOUSEWHEEL: 932 | if(pBinaryEditor) 933 | { 934 | int fwKeys = GET_WHEEL_DELTA_WPARAM(wParam); 935 | if(fwKeys >= 0) 936 | fwKeys = UM_WHEELUP; 937 | else 938 | fwKeys = UM_WHEELDOWN; 939 | pBinaryEditor->OnScrollBar(hWnd, WM_VSCROLL, fwKeys); 940 | } 941 | break; 942 | case WM_KEYDOWN: 943 | if(pBinaryEditor) 944 | { 945 | WPARAM nCode = 0; 946 | switch(wParam) 947 | { 948 | case VK_UP: 949 | nCode = SB_LINEUP; 950 | break; 951 | case VK_DOWN: 952 | nCode = SB_LINEDOWN; 953 | break; 954 | case VK_NEXT: 955 | nCode = SB_PAGEDOWN; 956 | break; 957 | case VK_PRIOR: 958 | nCode = SB_PAGEUP; 959 | break; 960 | } 961 | pBinaryEditor->OnScrollBar(hWnd, WM_VSCROLL, nCode); 962 | } 963 | break; 964 | case WM_VSCROLL: 965 | if(pBinaryEditor) 966 | pBinaryEditor->OnScrollBar(hWnd, WM_VSCROLL, wParam); 967 | break; 968 | 969 | case WM_PAINT: 970 | { 971 | PAINTSTRUCT ps; 972 | HDC hdc = BeginPaint(hWnd, &ps); 973 | // TODO: Add any drawing code here... 974 | if(pBinaryEditor) 975 | { 976 | RECT rc = pBinaryEditor->GetDrawRect(); 977 | if(IsRectEmpty( &rc)) 978 | { 979 | GetClientRect( hWnd, &rc); 980 | pBinaryEditor->SetDrawRect( rc ); 981 | pBinaryEditor->SetEditorBitmap( NULL ); 982 | //pBinaryEditor->CalculateBinRowNumber(); 983 | } 984 | 985 | pBinaryEditor->PaintWindow( hdc ); 986 | } 987 | EndPaint(hWnd, &ps); 988 | } 989 | break; 990 | case WM_SIZE: 991 | 992 | if(pBinaryEditor) 993 | { 994 | RECT rcBin; 995 | rcBin.left = 0; 996 | rcBin.right = LOWORD(lParam); 997 | rcBin.top = 0; 998 | rcBin.bottom = HIWORD(lParam); 999 | 1000 | pBinaryEditor->SetDrawRect( rcBin ); 1001 | pBinaryEditor->SetEditorBitmap( NULL ); 1002 | //pBinaryEditor->CalculateBinRowNumber(); 1003 | 1004 | pBinaryEditor->SetScrollBar( hWnd ); 1005 | } 1006 | 1007 | break; 1008 | case WM_ERASEBKGND: 1009 | return TRUE; 1010 | case WM_CREATE: 1011 | break; 1012 | 1013 | case WM_CLOSE: 1014 | ShowWindow( hWnd, SW_HIDE ); 1015 | break; 1016 | 1017 | case WM_DESTROY: 1018 | return DefWindowProc( hWnd, uMsg, wParam, lParam); 1019 | 1020 | default: 1021 | return DefWindowProc( hWnd, uMsg, wParam, lParam); 1022 | } 1023 | return 0; 1024 | } 1025 | --------------------------------------------------------------------------------