├── .gitattributes ├── .gitignore ├── HWFW_GUI.sln ├── HWFW_GUI ├── Common.cpp ├── DlgAbout.cpp ├── DlgAdvDatFmt.cpp ├── DlgEditProduct.cpp ├── DlgItemInfo.cpp ├── DlgMain.cpp ├── DlgMain.h ├── FastCRC32.cpp ├── HWFW_GUI.cpp ├── HWFW_GUI.hpp ├── HWFW_GUI.ico ├── HWFW_GUI.rc ├── HWFW_GUI.vcxproj ├── HWFW_GUI.vcxproj.filters ├── HWNP.cpp ├── HWNP.h ├── HWPDB.ini ├── Licenses │ ├── gpl-3.0-chs.txt │ ├── gpl-3.0-cht.txt │ └── gpl-3.0.txt ├── ListView_Events.cpp ├── ReadMe.txt ├── TreeView_Events.cpp ├── app.manifest ├── resource.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── uboot_image.h ├── LICENSE ├── README.md └── Screenshots ├── SS_1.0.3_1.png ├── SS_1.0.3_2.png ├── SS_1.0.3_3.png ├── SS_1.0.8_1.png └── SS_1.0.8_2.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | /HWFW_GUI/Release_LLVM 244 | /HWFW_GUI/HWNP - 副本.cpp 245 | Release_LLVM 246 | My Amplifier XE Results - HWFW_GUI 247 | -------------------------------------------------------------------------------- /HWFW_GUI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HWFW_GUI", "HWFW_GUI\HWFW_GUI.vcxproj", "{6DA1C07F-D2B9-4834-88E1-6F493A5D589E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release_LLVM|x86 = Release_LLVM|x86 12 | Release|x86 = Release|x86 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Debug|x86.ActiveCfg = Debug|Win32 16 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Debug|x86.Build.0 = Debug|Win32 17 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Release_LLVM|x86.ActiveCfg = Release_LLVM|Win32 18 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Release_LLVM|x86.Build.0 = Release_LLVM|Win32 19 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Release|x86.ActiveCfg = Release|Win32 20 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E}.Release|x86.Build.0 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | GlobalSection(ExtensibilityGlobals) = postSolution 26 | SolutionGuid = {86812C9C-EE35-446F-9B81-3E514036759F} 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /HWFW_GUI/Common.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWFW_GUI.hpp" 3 | 4 | uint32_t MemAlignCpy(LPVOID const dest, size_t const destSize, LPCVOID const src, size_t const srcSize, int fill) { 5 | size_t alignSize, fillSize; 6 | 7 | alignSize = alignPage(srcSize); 8 | fillSize = alignSize - srcSize; 9 | 10 | memcpy_s(dest, destSize, src, srcSize); 11 | 12 | if (fillSize != 0) { 13 | memset(MakePointer32(dest, srcSize), fill, fillSize); 14 | } 15 | 16 | return alignSize; 17 | } -------------------------------------------------------------------------------- /HWFW_GUI/DlgAbout.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWFW_GUI.hpp" 3 | 4 | INT_PTR CALLBACK DlgProc_About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 5 | { 6 | switch (message) 7 | { 8 | case WM_INITDIALOG: 9 | return TRUE; 10 | 11 | case WM_COMMAND: 12 | { 13 | WORD wId = LOWORD(wParam), wNc = HIWORD(wParam); 14 | 15 | switch (wNc) { 16 | case STN_CLICKED: 17 | if (wId == IDC_STATIC_BLOG) { 18 | ShellExecute(0, 0, L"https://blog.csersoft.net", 0, 0, SW_SHOW); 19 | } 20 | break; 21 | } 22 | } 23 | break; 24 | 25 | case WM_CTLCOLORSTATIC: 26 | if ((HWND)lParam == GetDlgItem(hDlg, IDC_STATIC_BLOG)) 27 | { 28 | SetBkMode((HDC)wParam, TRANSPARENT); 29 | SetTextColor((HDC)wParam, RGB(0, 0, 255)); 30 | return (BOOL)GetSysColorBrush(COLOR_MENU); 31 | } 32 | break; 33 | 34 | case WM_CLOSE: 35 | EndDialog(hDlg, IDCLOSE); 36 | break; 37 | } 38 | 39 | return (INT_PTR)FALSE; 40 | } 41 | -------------------------------------------------------------------------------- /HWFW_GUI/DlgEditProduct.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWFW_GUI.hpp" 3 | 4 | #define MAX_LIST 4096 5 | 6 | static HWND hEdit = NULL; 7 | static CHAR chProdList[MAX_LIST]; 8 | 9 | static inline uint32_t alignList(uint32_t size) { 10 | if (size % 0x0100 == 0) return size; 11 | return (size / 0x0100 + 1) * 0x0100; 12 | } 13 | 14 | INT_PTR CALLBACK DlgProc_EditProduct(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { 15 | switch (message) 16 | { 17 | case WM_INITDIALOG: 18 | chProdList[0] = 0; 19 | HWNP_GetProductList(chProdList, MAX_LIST); 20 | 21 | hEdit = GetDlgItem(hDlg, IDC_EDIT_PROD); 22 | SendMessageA(hEdit, EM_SETLIMITTEXT, MAX_LIST - 2, 0); 23 | SetWindowTextA(hEdit, chProdList); 24 | return TRUE; 25 | case WM_COMMAND: 26 | { 27 | WORD wId = LOWORD(wParam), wNc = HIWORD(wParam); 28 | 29 | switch (wId) { 30 | case IDOK: 31 | memset(chProdList, MAX_LIST, 0); 32 | 33 | GetWindowTextA(hEdit, chProdList, MAX_LIST); 34 | 35 | HWNP_SetProductList(chProdList, (uint16_t)alignList(strlen(chProdList))); 36 | EndDialog(hDlg, IDOK); 37 | break; 38 | case IDCANCEL: 39 | EndDialog(hDlg, IDCANCEL); 40 | break; 41 | } 42 | } 43 | break; 44 | case WM_CLOSE: 45 | EndDialog(hDlg, IDCLOSE); 46 | break; 47 | } 48 | 49 | 50 | return (INT_PTR)FALSE; 51 | } -------------------------------------------------------------------------------- /HWFW_GUI/DlgItemInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWFW_GUI.hpp" 3 | 4 | static PDLGIIS lpDlgParam = NULL; 5 | static HWNP_ITEMINFO hwItemInfo; 6 | 7 | static void SaveItemInfo(HWND hDlg) 8 | { 9 | CHAR chTmp[MAX_PATH] = { 0 }; 10 | 11 | GetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_ID), chTmp, MAX_PATH); 12 | if (strlen(chTmp) != 0) hwItemInfo.u32Id = ScanfDec(chTmp); 13 | 14 | GetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_PATH), chTmp, MAX_PATH); 15 | memset(hwItemInfo.chItemPath, 0, sizeof(HWNP_ITEMINFO::chItemPath)); 16 | if (strlen(chTmp) != 0) strcpy_s(hwItemInfo.chItemPath, chTmp); 17 | 18 | GetWindowTextA(GetDlgItem(hDlg, IDC_CB_TYPE), chTmp, MAX_PATH); 19 | memset(hwItemInfo.chItemType, 0, sizeof(HWNP_ITEMINFO::chItemType)); 20 | if (strlen(chTmp) != 0) strcpy_s(hwItemInfo.chItemType, chTmp); 21 | 22 | GetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_VER), chTmp, MAX_PATH); 23 | memset(hwItemInfo.chItemVersion, 0, sizeof(HWNP_ITEMINFO::chItemVersion)); 24 | if (strlen(chTmp) != 0) strcpy_s(hwItemInfo.chItemVersion, chTmp); 25 | 26 | GetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_POLICY), chTmp, MAX_PATH); 27 | if (strlen(chTmp) != 0) hwItemInfo.u32Policy = ScanfHex(chTmp); 28 | 29 | GetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_UNKDAT), chTmp, MAX_PATH); 30 | if (strlen(chTmp) != 0) hwItemInfo.u32Reserved = ScanfHex(chTmp); 31 | } 32 | 33 | static void UpdateView(HWND hDlg) 34 | { 35 | DWORD dwType; 36 | size_t stOut; 37 | WCHAR wsTemp[260]; 38 | 39 | if (lpDlgParam == NULL) return; 40 | 41 | if (lpDlgParam->dtType == DT_EDIT) 42 | { 43 | if ((HWNP_GetItemDataTypeByIndex(lpDlgParam->u32Index, &dwType) == 0) && (CHK_FLAGS(dwType, IDT_WHWH))) 44 | EnableWindow(GetDlgItem(hDlg, IDC_BTN_ADF), TRUE); 45 | else 46 | EnableWindow(GetDlgItem(hDlg, IDC_BTN_ADF), FALSE); 47 | 48 | } 49 | else if (lpDlgParam->dtType == DT_ADD) 50 | { 51 | EnableWindow(GetDlgItem(hDlg, IDC_BTN_ADF), FALSE); 52 | EnableWindow(GetDlgItem(hDlg, IDC_BTN_EXP), FALSE); 53 | EnableWindow(GetDlgItem(hDlg, IDC_BTN_IMP), FALSE); 54 | } 55 | 56 | swprintf_s(wsTemp, SF_DEC, hwItemInfo.u32Id); 57 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_ID), wsTemp); 58 | 59 | if (lpDlgParam->dtType == DT_EDIT) 60 | { 61 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32ItemCRC32); 62 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_CRC), wsTemp); 63 | 64 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Offset); 65 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_OFFSET), wsTemp); 66 | 67 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Size); 68 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_SIZE), wsTemp); 69 | } 70 | else if (lpDlgParam->dtType == DT_ADD) 71 | { 72 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_CRC), L"N/A"); 73 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_OFFSET), L"N/A"); 74 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_SIZE), L"N/A"); 75 | } 76 | 77 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemPath, sizeof(HWNP_ITEMINFO::chItemPath)); 78 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_PATH), wsTemp); 79 | 80 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType)); 81 | SetWindowTextW(GetDlgItem(hDlg, IDC_CB_TYPE), wsTemp); 82 | 83 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion)); 84 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_VER), wsTemp); 85 | 86 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Policy); 87 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_POLICY), wsTemp); 88 | 89 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 90 | SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT_UNKDAT), wsTemp); 91 | 92 | } 93 | 94 | INT_PTR CALLBACK DlgProc_ItemInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 95 | { 96 | switch (message) 97 | { 98 | case WM_INITDIALOG: 99 | { 100 | if (lpDlgParam != NULL) return (INT_PTR)FALSE; 101 | if (lParam == NULL) return (INT_PTR)FALSE; 102 | 103 | int nResult; 104 | WCHAR wsTemp[260]; 105 | 106 | lpDlgParam = (PDLGIIS)lParam; 107 | 108 | SNDMSG(GetDlgItem(hDlg, IDC_EDIT_PATH), EM_SETLIMITTEXT, sizeof(HWNP_ITEMINFO::chItemPath), 0); 109 | ComboBox_LimitText(GetDlgItem(hDlg, IDC_CB_TYPE), sizeof(HWNP_ITEMINFO::chItemType)); 110 | SNDMSG(GetDlgItem(hDlg, IDC_EDIT_VER), EM_SETLIMITTEXT, sizeof(HWNP_ITEMINFO::chItemVersion), 0); 111 | 112 | for (int i = 0; true; i++) { 113 | if (HW_ItemType_Text[i] == NULL) break; 114 | 115 | ComboBox_AddStringW(GetDlgItem(hDlg, IDC_CB_TYPE), HW_ItemType_Text[i]); 116 | } 117 | 118 | if (lpDlgParam->dtType == DT_EDIT) 119 | { 120 | nResult = HWNP_GetItemInfoByIndex(lpDlgParam->u32Index, &hwItemInfo); 121 | 122 | if (nResult != 0) 123 | { 124 | swprintf_s(wsTemp, L"获取项目信息失败!错误码:[%d]", nResult); 125 | SetWindowTextW(GetDlgItem(hDlg, IDC_LBL_II_STATUS), wsTemp); 126 | return (INT_PTR)TRUE; 127 | } 128 | 129 | UpdateView(hDlg); 130 | } 131 | else if (lpDlgParam->dtType == DT_ADD) 132 | { 133 | hwItemInfo.u32Id = HWNP_GetLastItemId(); 134 | 135 | strcpy_s(hwItemInfo.chItemPath, ""); 136 | strcpy_s(hwItemInfo.chItemType, "UNKNOWN"); 137 | strcpy_s(hwItemInfo.chItemVersion, ""); 138 | hwItemInfo.u32Policy = 0; 139 | hwItemInfo.u32Reserved = 0; 140 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 141 | 142 | UpdateView(hDlg); 143 | } 144 | 145 | return (INT_PTR)TRUE; 146 | } 147 | break; 148 | 149 | case WM_SHOWWINDOW: 150 | { 151 | if ((wParam) && (lParam == SW_PARENTOPENING)) UpdateView(hDlg); 152 | } 153 | break; 154 | 155 | case WM_COMMAND: 156 | { 157 | WORD wId = LOWORD(wParam), wNc = HIWORD(wParam); 158 | 159 | if (lParam != 0) 160 | { 161 | switch (wId) 162 | { 163 | case IDC_BTN_EXP: 164 | if (lpDlgParam->dtType == DT_EDIT) 165 | { 166 | int nResult; 167 | uint32_t u32DataSize; 168 | LPCVOID lpData; 169 | WCHAR wsTmp[MAX_PATH] = { 0 }; 170 | 171 | if (GetSaveFilePath(hDlg, wsTmp, MAX_PATH)) 172 | { 173 | nResult = HWNP_GetItemDataSizeByIndex(lpDlgParam->u32Index, &u32DataSize); 174 | if (nResult != 0) 175 | { 176 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"获取项目数据大小失败,错误码:[%d]!", nResult); 177 | break; 178 | } 179 | 180 | nResult = HWNP_GetItemDataPointerByIndex(lpDlgParam->u32Index, &lpData); 181 | if (nResult != 0) 182 | { 183 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"获取项目数据失败,错误码:[%d]!", nResult); 184 | break; 185 | } 186 | 187 | if (ExportToFile(wsTmp, lpData, u32DataSize)) 188 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"导出项目数据完成."); 189 | else 190 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"导出项目数据失败,错误码:[%d]!", GetLastError()); 191 | } 192 | } 193 | break; 194 | 195 | case IDC_BTN_IMP: 196 | if (lpDlgParam->dtType == DT_EDIT) 197 | { 198 | int nResult; 199 | DWORD dwDataSize; 200 | LPVOID lpData; 201 | WCHAR wsTmp[MAX_PATH] = { 0 }; 202 | 203 | if (GetOpenFilePath(hDlg, wsTmp, MAX_PATH)) 204 | { 205 | if (ImportFromFile(wsTmp, &lpData, &dwDataSize) == FALSE) 206 | { 207 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"打开文件失败,错误码:[%d]!", GetLastError()); 208 | break; 209 | } 210 | 211 | nResult = HWNP_SetItemData(lpDlgParam->u32Index, lpData, (uint32_t)dwDataSize); 212 | free(lpData); 213 | 214 | if (nResult != 0) 215 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"导入数据失败,错误码:[%d]!", nResult); 216 | else 217 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"导入数据完成."); 218 | 219 | } 220 | } 221 | break; 222 | 223 | case IDC_BTN_ADF: 224 | if (lpDlgParam->dtType == DT_EDIT) 225 | { 226 | SaveItemInfo(hDlg); 227 | DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ADVFMTDLG), hDlg, &DlgProc_AdvDatFmt, (LPARAM)lpDlgParam->u32Index); 228 | UpdateView(hDlg); 229 | } 230 | break; 231 | 232 | case IDOK: 233 | { 234 | int nResult = 0; 235 | 236 | SaveItemInfo(hDlg); 237 | 238 | if (lpDlgParam->dtType == DT_EDIT) 239 | { 240 | nResult = HWNP_SetItemInfo(lpDlgParam->u32Index, IIFLAG_ALL, hwItemInfo.u32Id, hwItemInfo.chItemPath, hwItemInfo.chItemType, 241 | hwItemInfo.chItemVersion, hwItemInfo.u32Policy, hwItemInfo.u32Reserved); 242 | } 243 | else if (lpDlgParam->dtType == DT_ADD) 244 | { 245 | DWORD dwSize; 246 | LPVOID lpData; 247 | 248 | if (ImportFromFile(lpDlgParam->lpFile, &lpData, &dwSize) == FALSE) 249 | { 250 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"导入文件失败!"); 251 | break; 252 | } 253 | 254 | nResult = HWNP_AddItem(hwItemInfo.u32Id, lpData, dwSize, hwItemInfo.chItemPath, hwItemInfo.chItemType, 255 | hwItemInfo.chItemVersion, hwItemInfo.u32Policy, hwItemInfo.u32Reserved); 256 | 257 | free(lpData); 258 | } 259 | 260 | if (nResult == 0) 261 | { 262 | HWNP_Update(); 263 | //lpDlgIIS = NULL; 264 | EndDialog(hDlg, IDOK); 265 | } 266 | else 267 | { 268 | SetTooltip(GetDlgItem(hDlg, IDC_LBL_II_STATUS), L"保存项目信息失败,错误码:[%d]!", nResult); 269 | } 270 | } 271 | break; 272 | 273 | case IDCANCEL: 274 | //lpDlgIIS = NULL; 275 | EndDialog(hDlg, IDCANCEL); 276 | break; 277 | } 278 | 279 | } 280 | 281 | return TRUE; 282 | } 283 | break; 284 | 285 | case WM_CLOSE: 286 | //lpDlgIIS = NULL; 287 | EndDialog(hDlg, IDCLOSE); 288 | break; 289 | 290 | case WM_DESTROY: 291 | lpDlgParam = NULL; 292 | break; 293 | } 294 | 295 | return (INT_PTR)FALSE; 296 | } 297 | -------------------------------------------------------------------------------- /HWFW_GUI/DlgMain.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DlgMain.h" 3 | 4 | CHAR chIniPath[MAX_PATH] = { 0 }; 5 | 6 | // 主窗口的消息处理程序。 7 | INT_PTR CALLBACK DlgProc_Main(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 8 | { 9 | static LONG lngTv_w, lngTv_h_diff, 10 | lngLv_w_diff, lngLv_h_diff, 11 | lngLbl_l, lngLbl_t_diff, lngLbl_w_diff, lngLbl_h; 12 | 13 | static WCHAR wsPath[MAX_PATH]; 14 | 15 | switch (message) 16 | { 17 | case WM_INITDIALOG: 18 | { 19 | typedef BOOL(WINAPI * lpfnChangeWindowMessageFilter)(__in UINT message, __in DWORD dwFlag); 20 | 21 | RECT rcDlg, rcTmp, rcTmp2; 22 | HMODULE hModUser32 = GetModuleHandleA("user32.dll"); 23 | LPCH lpStr; 24 | 25 | if (hModUser32) 26 | { 27 | lpfnChangeWindowMessageFilter fnChangeWindowMessageFilter = (lpfnChangeWindowMessageFilter)GetProcAddress(hModUser32, "ChangeWindowMessageFilter"); 28 | 29 | if (fnChangeWindowMessageFilter) 30 | { 31 | fnChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); 32 | fnChangeWindowMessageFilter(0x0049, MSGFLT_ADD); 33 | } 34 | } 35 | 36 | hMainDlg = hDlg; 37 | 38 | hmPop = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU_ITEMINFO)); 39 | 40 | if (hmPop) 41 | { 42 | hmItemInfo = GetSubMenu(hmPop, 0); 43 | } 44 | 45 | 46 | GetClientRect(hDlg, &rcDlg); 47 | GetWindowRect(GetDlgItem(hDlg, IDC_TV), &rcTmp); 48 | 49 | lngTv_w = rcTmp.right - rcTmp.left; 50 | lngTv_h_diff = rcDlg.bottom - (rcTmp.bottom - rcTmp.top); 51 | 52 | 53 | GetWindowRect(GetDlgItem(hDlg, IDC_LV), &rcTmp); 54 | 55 | lngLv_w_diff = rcDlg.right - (rcTmp.right - rcTmp.left); 56 | lngLv_h_diff = rcDlg.bottom - (rcTmp.bottom - rcTmp.top); 57 | 58 | 59 | GetWindowRect(GetDlgItem(hDlg, IDC_LBL_STATUS), &rcTmp); 60 | 61 | rcTmp2 = rcTmp; 62 | ScreenToClient(hDlg, &rcTmp2); 63 | 64 | lngLbl_l = rcTmp2.left; 65 | lngLbl_t_diff = rcDlg.bottom - rcTmp2.top; 66 | lngLbl_w_diff = rcDlg.right - (rcTmp.right - rcTmp.left); 67 | lngLbl_h = rcTmp.bottom - rcTmp.top; 68 | 69 | swprintf_s(wsPath, L"%s %s %s Build:%s", APP_NAME, APP_VER1, APP_VER2, APP_BUILD_VER); 70 | SetWindowTextW(hDlg, wsPath); 71 | 72 | wcscpy_s(wsPath, L"firmware.bin"); 73 | 74 | SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_HWFW_GUI))); 75 | SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_HWFW_GUI))); 76 | 77 | GetModuleFileNameA(NULL, chIniPath, MAX_PATH); 78 | lpStr = strrchr(chIniPath, '\\'); 79 | 80 | if (lpStr) 81 | { 82 | lpStr++; 83 | strcpy_s(lpStr, MAX_PATH - (lpStr - chIniPath), "HWPDB.ini"); 84 | } 85 | 86 | TreeView_SetProc(GetDlgItem(hDlg, IDC_TV)); 87 | } 88 | return (INT_PTR)TRUE; 89 | 90 | case WM_COMMAND: 91 | { 92 | WORD wId = LOWORD(wParam), wNc = HIWORD(wParam); 93 | 94 | switch (wNc) 95 | { 96 | case 0: 97 | { 98 | switch (wId) 99 | { 100 | case IDM_OPEN: 101 | { 102 | CleanView(); 103 | 104 | if (GetOpenFilePath(hDlg, wsPath, MAX_PATH)) 105 | { 106 | OpenFirmware(wsPath); 107 | 108 | LPWSTR lpFileName = wcsrchr(wsPath, '\\'); 109 | WCHAR wsTemp[MAX_PATH]; 110 | 111 | if (lpFileName) 112 | { 113 | lpFileName++; 114 | 115 | swprintf_s(wsTemp, L"%s %s %s Build:%s [%s]", APP_NAME, APP_VER1, APP_VER2, APP_BUILD_VER, lpFileName); 116 | SetWindowTextW(hDlg, wsTemp); 117 | } 118 | } 119 | else 120 | SetStatus(L"获取文件路径失败!"); 121 | } 122 | break; 123 | 124 | case IDM_SAVE: 125 | { 126 | int nResult = HWNP_Save(); 127 | 128 | if (nResult == 0) 129 | SetStatus(L"文件保存完成."); 130 | else 131 | { 132 | WCHAR wsTmp[128]; 133 | 134 | swprintf_s(wsTmp, L"文件保存失败,错误码:[%d]!", nResult); 135 | SetStatus(wsTmp); 136 | } 137 | } 138 | break; 139 | 140 | case IDM_SAVEAS: 141 | { 142 | WCHAR wsTmp[MAX_PATH] = { 0 }; 143 | 144 | if (GetSaveFilePath(hDlg, wsTmp, MAX_PATH)) 145 | { 146 | int nResult = HWNP_SaveAs(wsTmp); 147 | 148 | if (nResult == 0) 149 | SetStatus(L"文件保存完成."); 150 | else 151 | { 152 | swprintf_s(wsTmp, L"文件保存失败,错误码:[%d]!", nResult); 153 | SetStatus(wsTmp); 154 | } 155 | } 156 | else 157 | SetStatus(L"获取文件路径失败!"); 158 | } 159 | break; 160 | 161 | case IDM_EXIT: 162 | HWNP_Release(); 163 | EndDialog(hDlg, 0); 164 | break; 165 | 166 | case IDM_ABOUT: 167 | DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hDlg, &DlgProc_About); 168 | break; 169 | 170 | case IDM_CHKCRC: 171 | { 172 | uint32_t u32Result = HWNP_CheckCRC32(); 173 | 174 | if (u32Result == CHKCRC_OK) 175 | SetStatus(L"CRC32校验通过."); 176 | else if (u32Result == CHKCRC_HEADERCRCERR) 177 | SetStatus(L"头部CRC32校验失败!"); 178 | else if (u32Result == CHKCRC_FILECRCERR) 179 | SetStatus(L"文件CRC32校验失败!"); 180 | else if (u32Result >= CHKCRC_ITEMCRCERR) 181 | { 182 | WCHAR wsTmp[128]; 183 | 184 | swprintf_s(wsTmp, L"项目校验失败,Index:[%u]!", u32Result - CHKCRC_ITEMCRCERR); 185 | SetStatus(wsTmp); 186 | } 187 | else 188 | SetStatus(L"未知的CRC32校验结果!"); 189 | } 190 | break; 191 | 192 | case IDM_EDIT_PL: 193 | if (HWNP_GetState() == -1) { 194 | DialogBox(hInst, MAKEINTRESOURCE(IDD_PROD), hDlg, &DlgProc_EditProduct); 195 | } 196 | break; 197 | 198 | case IDM_PII_ADD: 199 | { 200 | WCHAR wsTmp[MAX_PATH] = { 0 }; 201 | 202 | if (GetOpenFilePath(hDlg, wsTmp, MAX_PATH)) 203 | { 204 | DLGIIS dlgiis; 205 | 206 | dlgiis.dtType = DT_ADD; 207 | dlgiis.lpFile = wsTmp; 208 | dlgiis.u32Index = 0; 209 | 210 | DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ITEMINFO), hDlg, &DlgProc_ItemInfo, (LPARAM)&dlgiis); 211 | 212 | CleanListView(); 213 | ListItemInfo(GetDlgItem(hDlg, IDC_LV)); 214 | } 215 | } 216 | break; 217 | 218 | case IDM_PII_EDIT: 219 | { 220 | int nItem = ListView_CurHotItem(); 221 | 222 | if (nItem != -1) 223 | { 224 | DLGIIS dlgiis; 225 | 226 | dlgiis.dtType = DT_EDIT; 227 | dlgiis.lpFile = NULL; 228 | 229 | { 230 | LVITEMW lvi; 231 | 232 | lvi.mask = LVIF_PARAM; 233 | lvi.iItem = nItem; 234 | lvi.iSubItem = 0; 235 | 236 | ListView_GetItemW(GetDlgItem(hDlg, IDC_LV), &lvi); 237 | if (lvi.lParam) dlgiis.u32Index = (uint32_t)((PLVS)lvi.lParam)->dwUserData; 238 | else dlgiis.u32Index = 0; 239 | } 240 | 241 | DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ITEMINFO), hDlg, &DlgProc_ItemInfo, (LPARAM)&dlgiis); 242 | 243 | UpdateItemInfo(GetDlgItem(hDlg, IDC_LV)); 244 | ListView_SetItemState(GetDlgItem(hDlg, IDC_LV), nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); 245 | } 246 | } 247 | break; 248 | 249 | case IDM_PII_DELETE: 250 | { 251 | int nItem = ListView_CurHotItem(); 252 | 253 | if (nItem != -1) 254 | { 255 | HWNP_DeleteItem((uint32_t)nItem); 256 | 257 | CleanListView(); 258 | ListItemInfo(GetDlgItem(hDlg, IDC_LV)); 259 | } 260 | } 261 | break; 262 | } 263 | 264 | return TRUE; 265 | } 266 | break; 267 | 268 | case 1: 269 | break; 270 | 271 | default: 272 | 273 | break; 274 | } 275 | 276 | } 277 | break; 278 | 279 | case WM_NOTIFY: 280 | { 281 | if (lParam == 0) break; 282 | 283 | LPNMHDR lpNm = (LPNMHDR)lParam; 284 | 285 | switch (lpNm->code) 286 | { 287 | case TVN_SELCHANGED: 288 | { 289 | TreeView_SelChanged((LPNMTREEVIEW)lParam); 290 | } 291 | break; 292 | 293 | case LVN_DELETEITEM: 294 | { 295 | LPNMLISTVIEW lpnmLV = (LPNMLISTVIEW)lParam; 296 | 297 | free((void *)lpnmLV->lParam); 298 | } 299 | break; 300 | 301 | case LVN_DELETEALLITEMS: 302 | { 303 | SetWindowLongPtr(hDlg, DWL_MSGRESULT, FALSE); 304 | return TRUE; 305 | } 306 | break; 307 | 308 | case NM_RCLICK: 309 | { 310 | if (lpNm->idFrom == IDC_LV) 311 | { 312 | ListView_RightClick((LPNMITEMACTIVATE)lParam); 313 | } 314 | } 315 | break; 316 | 317 | case NM_CUSTOMDRAW: 318 | { 319 | if (wParam == IDC_TV) 320 | { 321 | LPNMTVCUSTOMDRAW lpCustomDraw = (LPNMTVCUSTOMDRAW)lParam; 322 | 323 | switch (lpCustomDraw->nmcd.dwDrawStage) 324 | { 325 | case CDDS_PREPAINT: 326 | SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW); 327 | return TRUE; 328 | case CDDS_ITEMPREPAINT: 329 | if (CHK_FLAGS(lpCustomDraw->nmcd.uItemState, CDIS_SELECTED)) { 330 | lpCustomDraw->clrText = RGB(255, 40, 40); 331 | lpCustomDraw->clrTextBk = RGB(192, 192, 192); 332 | } 333 | else { 334 | lpCustomDraw->clrText = RGB(20, 20, 20); 335 | lpCustomDraw->clrTextBk = RGB(242, 242, 242); 336 | } 337 | 338 | //SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); 339 | return TRUE; 340 | } 341 | } 342 | } 343 | break; 344 | } 345 | } 346 | break; 347 | 348 | case WM_CLOSE: 349 | HWNP_Release(); 350 | EndDialog(hDlg, IDCLOSE); 351 | break; 352 | 353 | case WM_SIZING: 354 | { 355 | LPRECT lpRect = (LPRECT)lParam; 356 | 357 | if (!lpRect) return FALSE; 358 | 359 | if ((lpRect->right - lpRect->left) < 1024) lpRect->right = lpRect->left + 1024; 360 | if ((lpRect->bottom - lpRect->top) < 480) lpRect->bottom = lpRect->top + 480; 361 | } 362 | return (INT_PTR)TRUE; 363 | 364 | case WM_SIZE: 365 | 366 | if (wParam != SIZE_MINIMIZED) 367 | { 368 | int intWidth = LOWORD(lParam), intHeight = HIWORD(lParam); 369 | 370 | SetWindowPos(GetDlgItem(hDlg, IDC_TV), NULL, 0, 0, lngTv_w, intHeight - lngTv_h_diff, SWP_NOMOVE | SWP_NOZORDER); 371 | 372 | SetWindowPos(GetDlgItem(hDlg, IDC_LV), NULL, 373 | 0, 0, 374 | intWidth - lngLv_w_diff, intHeight - lngLv_h_diff, SWP_NOMOVE | SWP_NOZORDER); 375 | 376 | SetWindowPos(GetDlgItem(hDlg, IDC_LBL_STATUS), NULL, 377 | lngLbl_l, intHeight - lngLbl_t_diff, 378 | intWidth - lngLbl_w_diff, lngLbl_h, SWP_NOZORDER); 379 | } 380 | 381 | break; 382 | } 383 | 384 | return (INT_PTR)FALSE; 385 | } -------------------------------------------------------------------------------- /HWFW_GUI/DlgMain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _WINDOWS_ 4 | #include 5 | #endif 6 | 7 | #ifndef _INC_WINDOWSX 8 | #include 9 | #endif 10 | 11 | #ifndef _INC_COMMCTRL 12 | #include 13 | #endif 14 | 15 | #include "resource.h" 16 | #include "HWNP.h" 17 | #include "HWFW_GUI.hpp" 18 | 19 | void ListItemInfo(HWND hListView); 20 | void UpdateItemInfo(HWND hListView); 21 | 22 | void TreeView_SetProc(HWND hCtrl); 23 | void TreeView_SelChanged(LPNMTREEVIEW lpnmTV); 24 | 25 | void ListView_SetProc(HWND hCtrl); 26 | void ListView_RightClick(LPNMITEMACTIVATE lpnmItemActivate); 27 | int ListView_AddColumn(HWND hCtrl, int nWidth, int nIndex, LPWSTR lpText); 28 | int ListView_AddItemA(HWND hCtrl, int iItem, int iSubItem, LPSTR lpText, LVI_TYPE ltType, DWORD dwFlags, DWORD dwUserData, LPARAM lParam); 29 | int ListView_AddItemW(HWND hCtrl, int iItem, int iSubItem, LPWSTR lpText, LVI_TYPE ltType, DWORD dwFlags, DWORD dwUserData, LPARAM lParam); 30 | int ListView_CurHotItem(); 31 | -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWFW_GUI.hpp" 3 | 4 | // 全局变量: 5 | HINSTANCE hInst = NULL; // 当前实例 6 | HWND hMainDlg = NULL; 7 | HMENU hmPop = NULL; 8 | HMENU hmItemInfo = NULL; 9 | HMENU hmSubItem = NULL; 10 | 11 | // 12 | // 函数: InitInstance(HINSTANCE, int) 13 | // 14 | // 目的: 保存实例句柄并创建主窗口 15 | // 16 | // 注释: 17 | // 18 | // 在此函数中,我们在全局变量中保存实例句柄并 19 | // 创建和显示主程序窗口。 20 | // 21 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 22 | { 23 | hInst = hInstance; // 将实例句柄存储在全局变量中 24 | 25 | DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINDLG), NULL, &DlgProc_Main); 26 | 27 | return TRUE; 28 | } 29 | 30 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 31 | _In_opt_ HINSTANCE hPrevInstance, 32 | _In_ LPWSTR lpCmdLine, 33 | _In_ int nCmdShow) 34 | { 35 | UNREFERENCED_PARAMETER(hPrevInstance); 36 | UNREFERENCED_PARAMETER(lpCmdLine); 37 | 38 | _CrtSetDebugFillThreshold(0); 39 | InitCommonControls(); 40 | 41 | // 执行应用程序初始化: 42 | if (!InitInstance(hInstance, nCmdShow)) 43 | { 44 | return FALSE; 45 | } 46 | 47 | return 1; 48 | } 49 | 50 | 51 | void SetStatus(LPCWSTR lpText, ...) 52 | { 53 | va_list argptr; 54 | WCHAR wsTmp[512]; 55 | 56 | va_start(argptr, lpText); 57 | _vstprintf_s(wsTmp, 512, lpText, argptr); 58 | va_end(argptr); 59 | 60 | SetWindowTextW(GetDlgItem(hMainDlg, IDC_LBL_STATUS), wsTmp); 61 | } 62 | 63 | void SetTooltip(HWND hCtrl, LPCWSTR lpText, ...) 64 | { 65 | va_list argptr; 66 | WCHAR wsTmp[512]; 67 | 68 | va_start(argptr, lpText); 69 | _vstprintf_s(wsTmp, 512, lpText, argptr); 70 | va_end(argptr); 71 | 72 | SetWindowTextW(hCtrl, wsTmp); 73 | } 74 | 75 | BOOL QueryMsg(HWND hOwner, LPCWSTR szText, LPCWSTR szTitle) 76 | { 77 | if (MessageBoxW(hOwner, szText, szTitle, MB_ICONQUESTION | MB_YESNO) == IDYES) 78 | return TRUE; 79 | else 80 | return FALSE; 81 | } 82 | 83 | BOOL GetOpenFilePath(HWND hOwner, LPWSTR lpFilePath, DWORD dwMax) 84 | { 85 | OPENFILENAMEW ofn; 86 | 87 | if (!lpFilePath || !dwMax) return FALSE; 88 | ZeroMemory(&ofn, sizeof(OPENFILENAMEW)); 89 | 90 | ofn.lStructSize = sizeof(OPENFILENAMEW); 91 | ofn.hwndOwner = hOwner; 92 | ofn.lpstrFilter = STR_FILE_TYPE; 93 | ofn.lpstrFile = lpFilePath; 94 | ofn.nMaxFile = dwMax; 95 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER; 96 | return GetOpenFileNameW(&ofn); 97 | } 98 | 99 | BOOL GetSaveFilePath(HWND hOwner, LPWSTR lpFilePath, DWORD dwMax) 100 | { 101 | OPENFILENAMEW ofn; 102 | 103 | if (!lpFilePath || !dwMax) return FALSE; 104 | ZeroMemory(&ofn, sizeof(OPENFILENAMEW)); 105 | 106 | ofn.lStructSize = sizeof(OPENFILENAMEW); 107 | ofn.hwndOwner = hOwner; 108 | ofn.lpstrFilter = STR_FILE_TYPE; 109 | ofn.lpstrFile = lpFilePath; 110 | ofn.nMaxFile = dwMax; 111 | ofn.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER; 112 | return GetSaveFileNameW(&ofn); 113 | } 114 | 115 | BOOL ExportToFile(LPCWSTR lpFile, LPCVOID lpData, DWORD dwSize) 116 | { 117 | HANDLE hFile = CreateFileW(lpFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 118 | DWORD dwTmp; 119 | 120 | if (hFile == INVALID_HANDLE_VALUE) return FALSE; 121 | 122 | SetFilePointer(hFile, dwSize, NULL, FILE_BEGIN); 123 | SetEndOfFile(hFile); 124 | 125 | SetFilePointer(hFile, 0, NULL, FILE_BEGIN); 126 | WriteFile(hFile, lpData, dwSize, &dwTmp, NULL); 127 | 128 | CloseHandle(hFile); 129 | return TRUE; 130 | } 131 | 132 | BOOL ImportFromFile(LPCWSTR lpFile, LPVOID *lppData, DWORD *lpdwSize) 133 | { 134 | HANDLE hFile = CreateFileW(lpFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 135 | LPVOID lpData; 136 | DWORD dwSize, dwSizeHigh; 137 | 138 | if (hFile == INVALID_HANDLE_VALUE) return FALSE; 139 | 140 | dwSize = GetFileSize(hFile, &dwSizeHigh); 141 | if (dwSizeHigh != 0) 142 | { 143 | CloseHandle(hFile); 144 | return FALSE; 145 | } 146 | 147 | lpData = malloc(dwSize); 148 | if (lpData == NULL) 149 | { 150 | CloseHandle(hFile); 151 | return FALSE; 152 | } 153 | 154 | SetFilePointer(hFile, 0, NULL, FILE_BEGIN); 155 | ReadFile(hFile, lpData, dwSize, lpdwSize, NULL); 156 | 157 | *lppData = lpData; 158 | 159 | //free(lpData) 160 | CloseHandle(hFile); 161 | return TRUE; 162 | } 163 | 164 | void CleanListView() 165 | { 166 | ListView_DeleteAllItems(GetDlgItem(hMainDlg, IDC_LV)); 167 | while (ListView_DeleteColumn(GetDlgItem(hMainDlg, IDC_LV), 0)); 168 | } 169 | 170 | void CleanView() 171 | { 172 | TreeView_DeleteAllItems(GetDlgItem(hMainDlg, IDC_TV)); 173 | CleanListView(); 174 | } 175 | 176 | int UpdateView() 177 | { 178 | HTREEITEM htiDefault, htiLastItem; 179 | TVINSERTSTRUCTW tvis; 180 | 181 | if (HWNP_GetState() != -1) return -1; 182 | CleanView(); 183 | 184 | ZeroMemory(&tvis, sizeof(TVINSERTSTRUCTW)); 185 | tvis.hParent = TVI_ROOT; 186 | tvis.hInsertAfter = TVI_LAST; 187 | tvis.item.mask = TVIF_TEXT | TVIF_PARAM; 188 | 189 | tvis.item.pszText = L"<固件文件头部>"; 190 | tvis.item.lParam = (LPARAM)TT_FILEHDR; 191 | htiDefault = htiLastItem = TreeView_DlgInsertItemW(hMainDlg, IDC_TV, &tvis); 192 | 193 | tvis.item.pszText = L"<产品支持信息>"; 194 | tvis.item.lParam = (LPARAM)TT_MODELINFO; 195 | htiLastItem = TreeView_DlgInsertItemW(hMainDlg, IDC_TV, &tvis); 196 | 197 | tvis.item.pszText = L"<包含项目信息>"; 198 | tvis.item.lParam = (LPARAM)TT_ITEMINFO; 199 | htiLastItem = TreeView_DlgInsertItemW(hMainDlg, IDC_TV, &tvis); 200 | 201 | TreeView_DlgSelectItem(hMainDlg, IDC_TV, htiDefault); 202 | return 0; 203 | } 204 | 205 | void OpenFirmware(LPCWSTR lpPath) 206 | { 207 | int nResult; 208 | 209 | if ((nResult = HWNP_OpenFirmware(lpPath)) != 0) 210 | { 211 | SetStatus(L"打开文件失败!错误码:[%d]", nResult); 212 | return; 213 | } 214 | 215 | if ((nResult = UpdateView()) != 0) 216 | { 217 | SetStatus(L"更新视图失败!错误码:[%d]", nResult); 218 | return ; 219 | } 220 | 221 | } 222 | 223 | -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _WINDOWS_ 4 | #include 5 | #endif 6 | 7 | #ifndef _INC_WINDOWSX 8 | #include 9 | #endif 10 | 11 | #include "resource.h" 12 | #include "HWNP.h" 13 | 14 | extern HINSTANCE hInst; 15 | extern HWND hMainDlg; 16 | extern HMENU hmPop; 17 | extern HMENU hmItemInfo; 18 | 19 | INT_PTR CALLBACK DlgProc_Main(HWND, UINT, WPARAM, LPARAM); 20 | INT_PTR CALLBACK DlgProc_ItemInfo(HWND, UINT, WPARAM, LPARAM); 21 | INT_PTR CALLBACK DlgProc_AdvDatFmt(HWND, UINT, WPARAM, LPARAM); 22 | INT_PTR CALLBACK DlgProc_EditProduct(HWND, UINT, WPARAM, LPARAM); 23 | INT_PTR CALLBACK DlgProc_About(HWND, UINT, WPARAM, LPARAM); 24 | 25 | #define STR_FILE_TYPE _T("所有文件(*.*)\0*.*\0\0") 26 | 27 | enum TVI_TYPE : unsigned int 28 | { 29 | TT_NONE, 30 | TT_FILEHDR, //file header 31 | TT_MODELINFO, //Model info (product list) 32 | TT_ITEMINFO, //item info 33 | TT_RAWDATA 34 | }; 35 | 36 | enum LVI_TYPE : unsigned int 37 | { 38 | LT_NONE, 39 | LT_MODELINFO, 40 | LT_ITEMINFO 41 | }; 42 | 43 | enum DLGII_TYPE : unsigned int 44 | { 45 | DT_NONE, 46 | DT_ADD, 47 | DT_EDIT 48 | }; 49 | 50 | typedef struct _LISTVIEW_STRUCT 51 | { 52 | LVI_TYPE ltType; 53 | DWORD dwFlags; 54 | DWORD dwUserData; 55 | LPARAM lParam; 56 | } LVS, *PLVS; 57 | 58 | typedef struct _DIALOG_ITEMINFO_STRUCT 59 | { 60 | DLGII_TYPE dtType; 61 | uint32_t u32Index; 62 | PWCHAR lpFile; 63 | } DLGIIS, *PDLGIIS; 64 | 65 | void SetStatus(LPCWSTR lpText, ...); 66 | void SetTooltip(HWND hCtrl, LPCWSTR lpText, ...); 67 | 68 | BOOL QueryMsg(HWND hOwner, LPCWSTR szText, LPCWSTR szTitle); 69 | 70 | BOOL GetOpenFilePath(HWND hOwner, LPWSTR lpFilePath, DWORD dwMax); 71 | BOOL GetSaveFilePath(HWND hOwner, LPWSTR lpFilePath, DWORD dwMax); 72 | 73 | BOOL ExportToFile(LPCWSTR lpFile, LPCVOID lpData, DWORD dwSize); 74 | BOOL ImportFromFile(LPCWSTR lpFile, LPVOID *lppData, DWORD *lpdwSize); 75 | 76 | void CleanListView(); 77 | void CleanView(); 78 | void OpenFirmware(LPCWSTR lpPath); 79 | 80 | uint32_t MemAlignCpy(LPVOID const dest, size_t const destSize, LPCVOID const src, size_t const srcSize, int fill); 81 | 82 | static inline BOOL ScreenToClient(__in HWND hWnd, __inout LPRECT lpRect) 83 | { 84 | ScreenToClient(hWnd, (LPPOINT)&(lpRect->left)); 85 | return ScreenToClient(hWnd, (LPPOINT)&(lpRect->right)); 86 | } 87 | 88 | static inline DWORD ScanfDec(LPCCH lpString) 89 | { 90 | if (lpString == NULL) return 0; 91 | 92 | DWORD dwDec; 93 | 94 | sscanf_s(lpString, "%u", &dwDec); 95 | 96 | return dwDec; 97 | } 98 | 99 | static inline DWORD ScanfHex(LPCCH lpString) 100 | { 101 | if (lpString == NULL) return 0; 102 | 103 | DWORD dwHex; 104 | 105 | if (_strnicmp(lpString, "0x", 2) == 0) 106 | { 107 | sscanf_s(lpString, "0x%X", &dwHex); 108 | } 109 | else 110 | { 111 | sscanf_s(lpString, "%X", &dwHex); 112 | } 113 | 114 | return dwHex; 115 | } 116 | 117 | /************************************************************************/ 118 | /* 页对齐 */ 119 | /************************************************************************/ 120 | static inline uint32_t alignPage(uint32_t val) { 121 | if (val % 0x1000 == 0) return val; 122 | return (val / 0x1000 + 1) * 0x1000; 123 | } 124 | 125 | static inline int alignPage(int val) { 126 | if (val % 0x1000 == 0) return val; 127 | return (val / 0x1000 + 1) * 0x1000; 128 | } 129 | -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/HWFW_GUI.ico -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/HWFW_GUI.rc -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release_LLVM 10 | Win32 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | 18 | {6DA1C07F-D2B9-4834-88E1-6F493A5D589E} 19 | Win32Proj 20 | HWFW_GUI 21 | 7.0 22 | 23 | 24 | 25 | Application 26 | true 27 | v141_xp 28 | Unicode 29 | Static 30 | 31 | 32 | Application 33 | false 34 | v141_xp 35 | true 36 | Unicode 37 | Static 38 | 39 | 40 | Application 41 | false 42 | v141_xp 43 | false 44 | Unicode 45 | Static 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | false 63 | 64 | 65 | true 66 | 67 | 68 | false 69 | 70 | 71 | false 72 | 73 | 74 | 75 | Use 76 | Level3 77 | Disabled 78 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Windows 83 | true 84 | User32.lib;Gdi32.lib;ComDlg32.lib;Shell32.lib;Comctl32.lib;%(AdditionalDependencies) 85 | 67108864 86 | 2097152 87 | 88 | 89 | copy HWPDB.ini "$(OutDir)HWPDB.ini" 90 | 91 | 92 | $(ProjectDir)app.manifest %(AdditionalManifestFiles) 93 | 94 | 95 | 96 | 97 | Level3 98 | Use 99 | MaxSpeed 100 | true 101 | true 102 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 103 | true 104 | 105 | 106 | Windows 107 | true 108 | true 109 | true 110 | User32.lib;Gdi32.lib;ComDlg32.lib;Shell32.lib;Comctl32.lib;%(AdditionalDependencies) 111 | 67108864 112 | 2097152 113 | 114 | 115 | copy HWPDB.ini "$(OutDir)HWPDB.ini" 116 | 117 | 118 | $(ProjectDir)app.manifest %(AdditionalManifestFiles) 119 | 120 | 121 | 122 | 123 | Level3 124 | Use 125 | MaxSpeed 126 | true 127 | true 128 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 129 | true 130 | 131 | 132 | Windows 133 | true 134 | true 135 | true 136 | User32.lib;Gdi32.lib;ComDlg32.lib;Shell32.lib;Comctl32.lib;%(AdditionalDependencies) 137 | 67108864 138 | 2097152 139 | 140 | 141 | copy HWPDB.ini "$(OutDir)HWPDB.ini" 142 | 143 | 144 | $(ProjectDir)app.manifest %(AdditionalManifestFiles) 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | Speed 171 | Speed 172 | 173 | 174 | 175 | Use 176 | Use 177 | Use 178 | 179 | 180 | 181 | Create 182 | Create 183 | Create 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /HWFW_GUI/HWFW_GUI.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {965257a6-d86a-41cd-9627-7370962de6aa} 18 | 19 | 20 | 21 | 22 | 23 | Licenses 24 | 25 | 26 | Licenses 27 | 28 | 29 | Licenses 30 | 31 | 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 头文件 41 | 42 | 43 | 头文件 44 | 45 | 46 | 头文件 47 | 48 | 49 | 头文件 50 | 51 | 52 | 头文件 53 | 54 | 55 | 56 | 57 | 源文件 58 | 59 | 60 | 源文件 61 | 62 | 63 | 源文件 64 | 65 | 66 | 源文件 67 | 68 | 69 | 源文件 70 | 71 | 72 | 源文件 73 | 74 | 75 | 源文件 76 | 77 | 78 | 源文件 79 | 80 | 81 | 源文件 82 | 83 | 84 | 源文件 85 | 86 | 87 | 源文件 88 | 89 | 90 | 源文件 91 | 92 | 93 | 94 | 95 | 资源文件 96 | 97 | 98 | 99 | 100 | 资源文件 101 | 102 | 103 | 资源文件 104 | 105 | 106 | 资源文件 107 | 108 | 109 | 110 | 111 | 资源文件 112 | 113 | 114 | 115 | 116 | 资源文件 117 | 118 | 119 | -------------------------------------------------------------------------------- /HWFW_GUI/HWNP.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HWNP.h" 3 | 4 | 5 | //内部项目副本 6 | typedef struct _Internal_ItemCopy 7 | { 8 | LPVOID lpItemData; 9 | uint32_t u32DataSize; 10 | HWNP_ITEMINFO ItemInfo; 11 | } INT_ITEMCOPY, *PINT_ITEMCOPY; 12 | 13 | 14 | static HANDLE hFile = INVALID_HANDLE_VALUE; 15 | static int nLastError = 0; 16 | static int nState = 0; 17 | static int nHeaderSizeType = 0; 18 | static BOOL blChanged = FALSE; 19 | static HWNP_HEADER hwHeader; 20 | static LPCH lpProductList = NULL; 21 | static uint32_t u32ItemCount = 0; 22 | static PINT_ITEMCOPY lpItemCopy = NULL; 23 | 24 | 25 | static inline void HWNP_SwapItemCopy(PINT_ITEMCOPY lpItemCopyA, PINT_ITEMCOPY lpItemCopyB) 26 | { 27 | INT_ITEMCOPY ItemCopyTmp = *lpItemCopyB; 28 | 29 | *lpItemCopyB = *lpItemCopyA; 30 | *lpItemCopyA = ItemCopyTmp; 31 | } 32 | 33 | static inline void HWNP_UpdateItemInfo() 34 | { 35 | if (nState != -1) return; 36 | 37 | uint32_t u32DataOffset = sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO); 38 | 39 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 40 | { 41 | lpItemCopy[u32Index].ItemInfo.u32Offset = u32DataOffset; 42 | lpItemCopy[u32Index].ItemInfo.u32Size = lpItemCopy[u32Index].u32DataSize; 43 | lpItemCopy[u32Index].ItemInfo.u32ItemCRC32 = crc32_fast(lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize); 44 | 45 | u32DataOffset += lpItemCopy[u32Index].u32DataSize; 46 | } 47 | } 48 | 49 | static inline void HWNP_UpdateHeader() 50 | { 51 | if (nState != -1) return; 52 | 53 | uint32_t u32DataSize = 0; 54 | uint32_t u32CRC, u32Tmp; 55 | 56 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 57 | u32DataSize += lpItemCopy[u32Index].u32DataSize; 58 | 59 | hwHeader.PacketHeader.u32ItemCount = u32ItemCount; 60 | hwHeader.PacketHeader.u16ItemInfoSize = sizeof(HWNP_ITEMINFO); 61 | 62 | //计算头部大小 63 | if (nHeaderSizeType == 1) 64 | hwHeader.FileHeader2.u32HeaderSize = hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO); 65 | else 66 | hwHeader.FileHeader2.u32HeaderSize = sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO); 67 | 68 | //计算头部CRC 69 | u32CRC = crc32_fast(&hwHeader.PacketHeader, sizeof(HWNP_PAKHDR)); 70 | u32CRC = crc32_fast(lpProductList, hwHeader.PacketHeader.u16ProductListSize, u32CRC); 71 | 72 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 73 | u32CRC = crc32_fast(&lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), u32CRC); 74 | 75 | hwHeader.FileHeader2.u32HeaderCRC32 = u32CRC; 76 | 77 | //计算文件大小 78 | u32Tmp = (sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO) + u32DataSize) - 76; 79 | hwHeader.BasicFileHeader.beu32FileSize = EndianSwap32(u32Tmp); 80 | 81 | //计算文件CRC 82 | u32CRC = crc32_fast(&hwHeader.FileHeader2, sizeof(HWNP_FILEHDR2)); 83 | u32CRC = crc32_fast(&hwHeader.PacketHeader, sizeof(HWNP_PAKHDR), u32CRC); 84 | u32CRC = crc32_fast(lpProductList, hwHeader.PacketHeader.u16ProductListSize, u32CRC); 85 | 86 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 87 | u32CRC = crc32_fast(&lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), u32CRC); 88 | 89 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 90 | u32CRC = crc32_fast(lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize, u32CRC); 91 | 92 | hwHeader.BasicFileHeader.u32FileCRC32 = u32CRC; 93 | } 94 | 95 | BOOL HWNP_IsChanged() 96 | { 97 | return blChanged; 98 | } 99 | 100 | int HWNP_GetLastError() 101 | { 102 | return nLastError; 103 | } 104 | 105 | int HWNP_GetState() 106 | { 107 | return nState; 108 | } 109 | 110 | int HWNP_GetHeaderSizeType() 111 | { 112 | return nHeaderSizeType; 113 | } 114 | 115 | int HWNP_SetHeaderSizeType(__in int nNewType) 116 | { 117 | int nRet = nHeaderSizeType; 118 | 119 | nHeaderSizeType = nNewType; 120 | return nRet; 121 | } 122 | 123 | void HWNP_Update() 124 | { 125 | if (nState != -1) return; 126 | 127 | HWNP_UpdateItemInfo(); 128 | HWNP_UpdateHeader(); 129 | blChanged = TRUE; 130 | } 131 | 132 | void HWNP_Release() 133 | { 134 | if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); 135 | if (lpProductList) free(lpProductList); 136 | 137 | hFile = INVALID_HANDLE_VALUE; 138 | nLastError = 0; 139 | nState = 0; 140 | blChanged = FALSE; 141 | lpProductList = NULL; 142 | 143 | if (lpItemCopy) 144 | { 145 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 146 | { 147 | if (lpItemCopy[u32Index].lpItemData) 148 | { 149 | free(lpItemCopy[u32Index].lpItemData); 150 | lpItemCopy[u32Index].lpItemData = NULL; 151 | } 152 | } 153 | 154 | free(lpItemCopy); 155 | lpItemCopy = NULL; 156 | } 157 | 158 | u32ItemCount = 0; 159 | } 160 | 161 | int HWNP_OpenFirmware(__in LPCWSTR lpFilePath) 162 | { 163 | LPBYTE lpFile; 164 | PHWNP_ITEMINFO lpItemInfo; 165 | DWORD dwFileSize, dwTmp; 166 | 167 | HWNP_Release(); 168 | 169 | hFile = CreateFileW(lpFilePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 170 | if (hFile == INVALID_HANDLE_VALUE) return (nLastError = -1); 171 | 172 | nState = 1; 173 | 174 | dwFileSize = GetFileSize(hFile, &dwTmp); 175 | //不处理大于 1GB 的文件 176 | if (dwTmp != 0 || dwFileSize > 0x40000000U) return (nLastError = -2); 177 | if (dwFileSize < sizeof(HWNP_HEADER)) return (nLastError = -3); 178 | 179 | lpFile = (LPBYTE)malloc(dwFileSize); 180 | if (lpFile == NULL) return (nLastError = -4); 181 | 182 | SetFilePointer(hFile, 0, NULL, FILE_BEGIN); 183 | 184 | if (ReadFile(hFile, lpFile, dwFileSize, &dwTmp, NULL) == FALSE) return (nLastError = -3); 185 | if (dwTmp != dwFileSize) return (nLastError = -5); 186 | 187 | nState = 2; 188 | 189 | //获取文件头 190 | memcpy_s(&hwHeader, sizeof(HWNP_HEADER), lpFile, sizeof(HWNP_HEADER)); 191 | if (hwHeader.BasicFileHeader.u32Magic != HWNP_HEADER_MAGIC) return (nLastError = -6); 192 | 193 | //获取产品支持列表 194 | if (CHK_OUT_OF_UBOUND2(lpFile + sizeof(HWNP_HEADER), hwHeader.PacketHeader.u16ProductListSize, lpFile, dwFileSize)) return (nLastError = -7); 195 | lpProductList = (LPCH)malloc(hwHeader.PacketHeader.u16ProductListSize); 196 | if (lpProductList == NULL) return (nLastError = -8); 197 | 198 | memcpy_s(lpProductList, hwHeader.PacketHeader.u16ProductListSize, lpFile + sizeof(HWNP_HEADER), hwHeader.PacketHeader.u16ProductListSize); 199 | 200 | //获取项目 201 | lpItemInfo = (PHWNP_ITEMINFO)(lpFile + sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize); 202 | u32ItemCount = hwHeader.PacketHeader.u32ItemCount; 203 | lpItemCopy = (PINT_ITEMCOPY)calloc(u32ItemCount, sizeof(INT_ITEMCOPY)); 204 | if (lpItemCopy == NULL) return (nLastError = -9); 205 | 206 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 207 | { 208 | #define _ITEMINFO_ lpItemInfo[u32Index] 209 | #define _ITEMCOPY_ lpItemCopy[u32Index] 210 | 211 | if (CHK_OUT_OF_UBOUND2(&_ITEMINFO_, sizeof(HWNP_ITEMINFO), lpFile, dwFileSize)) return (nLastError = -10); 212 | if (CHK_OUT_OF_UBOUND2(lpFile + _ITEMINFO_.u32Offset, _ITEMINFO_.u32Size, lpFile, dwFileSize)) return (nLastError = -11); 213 | 214 | _ITEMCOPY_.lpItemData = malloc(_ITEMINFO_.u32Size); 215 | if (_ITEMCOPY_.lpItemData == NULL) return (nLastError = -12); 216 | 217 | memcpy_s(_ITEMCOPY_.lpItemData, _ITEMINFO_.u32Size, lpFile + _ITEMINFO_.u32Offset, _ITEMINFO_.u32Size); 218 | _ITEMCOPY_.u32DataSize = _ITEMINFO_.u32Size; 219 | _ITEMCOPY_.ItemInfo = _ITEMINFO_; 220 | 221 | #undef _ITEMCOPY_ 222 | #undef _ITEMINFO_ 223 | } 224 | 225 | nState = -1; 226 | return 0; 227 | } 228 | 229 | int HWNP_GetItemCount(__out uint32_t *lpu32Count) 230 | { 231 | if (nState != -1) return (nLastError = -101); 232 | if (lpu32Count == NULL) return (nLastError = -102); 233 | 234 | *lpu32Count = u32ItemCount; 235 | return 0; 236 | } 237 | 238 | int HWNP_GetItemIndexById(__in uint32_t u32Id, __out uint32_t *lpu32Index) 239 | { 240 | if (nState != -1) return (nLastError = -201); 241 | 242 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 243 | { 244 | if (lpItemCopy[u32Index].ItemInfo.u32Id == u32Id) 245 | { 246 | if (lpu32Index) *lpu32Index = u32Index; 247 | return 0; 248 | } 249 | } 250 | 251 | return (nLastError = -202); 252 | } 253 | 254 | int HWNP_GetItemInfoByIndex(__in uint32_t u32Index, __out PHWNP_ITEMINFO lpItemInfo) 255 | { 256 | if (nState != -1) return (nLastError = -301); 257 | if (u32Index >= u32ItemCount) return (nLastError = -302); 258 | if (lpItemInfo == NULL) return (nLastError = -303); 259 | 260 | *lpItemInfo = lpItemCopy[u32Index].ItemInfo; 261 | return 0; 262 | } 263 | 264 | int HWNP_GetItemDataSizeByIndex(__in uint32_t u32Index, __out uint32_t *lpu32DataSize) 265 | { 266 | if (nState != -1) return (nLastError = -401); 267 | if (u32Index >= u32ItemCount) return (nLastError = -402); 268 | if (lpu32DataSize == NULL) return (nLastError = -403); 269 | 270 | *lpu32DataSize = lpItemCopy[u32Index].u32DataSize; 271 | return 0; 272 | } 273 | 274 | int HWNP_GetItemDataPointerByIndex(__in uint32_t u32Index, __out LPCVOID *lppDataPointer) 275 | { 276 | if (nState != -1) return (nLastError = -501); 277 | if (u32Index >= u32ItemCount) return (nLastError = -502); 278 | if (lppDataPointer == NULL) return (nLastError = -503); 279 | 280 | *lppDataPointer = (LPCVOID)lpItemCopy[u32Index].lpItemData; 281 | return 0; 282 | } 283 | 284 | int HWNP_GetItemDataTypeByIndex(__in uint32_t u32Index, __out LPDWORD lpDataType) 285 | { 286 | *lpDataType = 0; 287 | 288 | if (nState != -1) return (nLastError = -1501); 289 | if (u32Index >= u32ItemCount) return (nLastError = -1502); 290 | if (lpDataType == NULL) return (nLastError = -1503); 291 | if (lpItemCopy[u32Index].u32DataSize < sizeof(HW_HDR)) return (nLastError = -1504); 292 | 293 | DWORD dwType = 0; 294 | 295 | if ((*(LPDWORD)lpItemCopy[u32Index].lpItemData) == HWNP_HWHW_MAGIC) 296 | { 297 | dwType |= IDT_WHWH; 298 | 299 | if ((lpItemCopy[u32Index].u32DataSize - sizeof(HW_HDR) >= sizeof(UIMG_HDR)) && 300 | ((*(LPDWORD)((DWORD)lpItemCopy[u32Index].lpItemData + sizeof(HW_HDR))) == IH_MAGIC_LE)) 301 | { 302 | dwType |= IDT_UBOOT; 303 | } 304 | } 305 | 306 | *lpDataType = dwType; 307 | return 0; 308 | } 309 | 310 | int HWNP_GetFirmwareHeader(__out PHWNP_HEADER lpFirmwareHeader) 311 | { 312 | if (nState != -1) return (nLastError = -601); 313 | if (lpFirmwareHeader == NULL) return (nLastError = -602); 314 | 315 | *lpFirmwareHeader = hwHeader; 316 | return 0; 317 | } 318 | 319 | int HWNP_GetProductListSize(__out uint16_t *lpu16PLSize) 320 | { 321 | if (nState != -1) return (nLastError = -701); 322 | 323 | *lpu16PLSize = hwHeader.PacketHeader.u16ProductListSize; 324 | return 0; 325 | } 326 | 327 | int HWNP_GetProductList(__inout LPCH lpchProdList, __in uint16_t u16PLSize) 328 | { 329 | if (nState != -1) return (nLastError = -801); 330 | if (lpchProdList == NULL) return (nLastError = -802); 331 | 332 | memcpy_s(lpchProdList, u16PLSize, lpProductList, hwHeader.PacketHeader.u16ProductListSize); 333 | return 0; 334 | } 335 | 336 | int HWNP_SetProductList(__in LPCCH lpchProdList, __in uint16_t u16PLSize) 337 | { 338 | if (nState != -1) return (nLastError = -901); 339 | if (lpchProdList == NULL) return (nLastError = -902); 340 | 341 | if (u16PLSize == 0) 342 | { 343 | strcpy_s(lpProductList, hwHeader.PacketHeader.u16ProductListSize, lpchProdList); 344 | } 345 | else 346 | { 347 | if (u16PLSize != hwHeader.PacketHeader.u16ProductListSize) 348 | { 349 | LPCH lpDest = (LPCH)malloc(u16PLSize); 350 | if (lpDest == NULL) return (nLastError = -903); 351 | 352 | free(lpProductList); 353 | lpProductList = lpDest; 354 | hwHeader.PacketHeader.u16ProductListSize = u16PLSize; 355 | } 356 | 357 | memcpy_s(lpProductList, hwHeader.PacketHeader.u16ProductListSize, lpchProdList, u16PLSize); 358 | } 359 | 360 | HWNP_Update(); 361 | return 0; 362 | } 363 | 364 | int HWNP_SetItemData(__in uint32_t u32Index, __in LPCVOID lpNewData, __in uint32_t u32DataSize) 365 | { 366 | if (nState != -1) return (nLastError = -1001); 367 | if (u32Index >= u32ItemCount) return (nLastError = -1002); 368 | if (lpNewData == NULL || u32DataSize == 0) return (nLastError = -1003); 369 | 370 | LPVOID lpData = malloc(u32DataSize); 371 | 372 | if (lpData == NULL) return (nLastError = -1004); 373 | 374 | //释放旧数据 375 | if (lpItemCopy[u32Index].lpItemData) free(lpItemCopy[u32Index].lpItemData); 376 | 377 | //复制新数据 378 | memcpy_s(lpData, u32DataSize, lpNewData, u32DataSize); 379 | 380 | //设置项目信息 381 | lpItemCopy[u32Index].lpItemData = lpData; 382 | lpItemCopy[u32Index].u32DataSize = u32DataSize; 383 | lpItemCopy[u32Index].ItemInfo.u32Size = u32DataSize; 384 | 385 | HWNP_Update(); 386 | return 0; 387 | } 388 | 389 | int HWNP_SetItemInfo(__in uint32_t u32Index, __in uint32_t u32Mask, __in uint32_t u32Id, 390 | __in LPCCH lpchPath, __in LPCCH lpchType, __in LPCCH lpchVersion, __in uint32_t u32Policy, __in uint32_t u32Reserved) 391 | { 392 | if (nState != -1) return (nLastError = -1101); 393 | if (u32Index >= u32ItemCount) return (nLastError = -1102); 394 | 395 | if (CHK_FLAGS(u32Mask, IIFLAG_PATH) && (lpchPath == NULL)) return (nLastError = -1103); 396 | if (CHK_FLAGS(u32Mask, IIFLAG_TYPE) && (lpchType == NULL)) return (nLastError = -1104); 397 | if (CHK_FLAGS(u32Mask, IIFLAG_VERSION) && (lpchVersion == NULL)) return (nLastError = -1105); 398 | 399 | if (CHK_FLAGS(u32Mask, IIFLAG_ID)) lpItemCopy[u32Index].ItemInfo.u32Id = u32Id; 400 | 401 | if (CHK_FLAGS(u32Mask, IIFLAG_PATH)) { 402 | memset(lpItemCopy[u32Index].ItemInfo.chItemPath, 0, sizeof(HWNP_ITEMINFO::chItemPath)); 403 | strcpy_s(lpItemCopy[u32Index].ItemInfo.chItemPath, sizeof(HWNP_ITEMINFO::chItemPath), lpchPath); 404 | } 405 | 406 | if (CHK_FLAGS(u32Mask, IIFLAG_TYPE)) { 407 | memset(lpItemCopy[u32Index].ItemInfo.chItemType, 0, sizeof(HWNP_ITEMINFO::chItemType)); 408 | strcpy_s(lpItemCopy[u32Index].ItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType), lpchType); 409 | } 410 | 411 | if (CHK_FLAGS(u32Mask, IIFLAG_VERSION)) { 412 | memset(lpItemCopy[u32Index].ItemInfo.chItemVersion, 0, sizeof(HWNP_ITEMINFO::chItemVersion)); 413 | strcpy_s(lpItemCopy[u32Index].ItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion), lpchVersion); 414 | } 415 | 416 | if (CHK_FLAGS(u32Mask, IIFLAG_POLICY)) lpItemCopy[u32Index].ItemInfo.u32Policy = u32Policy; 417 | if (CHK_FLAGS(u32Mask, IIFLAG_RESERVED)) lpItemCopy[u32Index].ItemInfo.u32Reserved = u32Reserved; 418 | 419 | HWNP_Update(); 420 | return 0; 421 | } 422 | 423 | uint32_t HWNP_GetLastItemId() 424 | { 425 | if (nState != -1) return 0; 426 | 427 | BOOL blFound; 428 | 429 | for (uint32_t u32Id = 0; u32Id <= u32ItemCount; u32Id++) 430 | { 431 | blFound = FALSE; 432 | 433 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 434 | { 435 | if (strcmp(lpItemCopy[u32Index].ItemInfo.chItemType, "EFS") == 0) continue; 436 | 437 | if (u32Id == lpItemCopy[u32Index].ItemInfo.u32Id) 438 | { 439 | blFound = TRUE; 440 | break; 441 | } 442 | } 443 | 444 | if (blFound == FALSE) return u32Id; 445 | } 446 | 447 | return 0; 448 | } 449 | 450 | BOOL HWNP_CheckDuplicate() 451 | { 452 | if (nState != -1) return FALSE; 453 | 454 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 455 | { 456 | if (strcmp(lpItemCopy[u32Index].ItemInfo.chItemType, "EFS") == 0) continue; 457 | 458 | for (uint32_t u32Index2 = 0; u32Index2 < u32ItemCount; u32Index2++) 459 | { 460 | if (u32Index2 == u32Index) continue; 461 | 462 | if (strcmp(lpItemCopy[u32Index2].ItemInfo.chItemType, "EFS") == 0) continue; 463 | 464 | if (lpItemCopy[u32Index2].ItemInfo.u32Id == lpItemCopy[u32Index].ItemInfo.u32Id) 465 | return TRUE; 466 | } 467 | } 468 | 469 | return FALSE; 470 | } 471 | 472 | uint32_t HWNP_CheckCRC32() 473 | { 474 | if (nState != -1) return CHKCRC_FAILED; 475 | uint32_t u32CRC; 476 | 477 | //检查项目CRC 478 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 479 | { 480 | if (lpItemCopy[u32Index].ItemInfo.u32ItemCRC32 != crc32_fast(lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize)) 481 | return CHKCRC_ITEMCRCERR + u32Index; 482 | } 483 | 484 | //检查头部CRC 485 | u32CRC = crc32_fast(&hwHeader.PacketHeader, sizeof(HWNP_PAKHDR)); 486 | u32CRC = crc32_fast(lpProductList, hwHeader.PacketHeader.u16ProductListSize, u32CRC); 487 | 488 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 489 | u32CRC = crc32_fast(&lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), u32CRC); 490 | 491 | if (hwHeader.FileHeader2.u32HeaderCRC32 != u32CRC) return CHKCRC_HEADERCRCERR; 492 | 493 | //检查文件CRC 494 | u32CRC = crc32_fast(&hwHeader.FileHeader2, sizeof(HWNP_FILEHDR2)); 495 | u32CRC = crc32_fast(&hwHeader.PacketHeader, sizeof(HWNP_PAKHDR), u32CRC); 496 | u32CRC = crc32_fast(lpProductList, hwHeader.PacketHeader.u16ProductListSize, u32CRC); 497 | 498 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 499 | u32CRC = crc32_fast(&lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), u32CRC); 500 | 501 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 502 | u32CRC = crc32_fast(lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize, u32CRC); 503 | 504 | if (hwHeader.BasicFileHeader.u32FileCRC32 != u32CRC) return CHKCRC_FILECRCERR; 505 | 506 | return CHKCRC_OK; 507 | } 508 | 509 | void HWNP_SortItems(__in BOOL blUpdate) 510 | { 511 | if (nState != -1) return; 512 | 513 | //将EFS项目置后 514 | for (uint32_t u32Index = 0; u32Index < u32ItemCount - 1; u32Index++) 515 | { 516 | if (strcmp(lpItemCopy[u32Index].ItemInfo.chItemType, "EFS") == 0) 517 | { 518 | HWNP_SwapItemCopy(&lpItemCopy[u32ItemCount - 1], &lpItemCopy[u32Index]); 519 | break; 520 | } 521 | } 522 | 523 | //重新指定Id 524 | for (uint32_t u32Index = 0; u32Index < u32ItemCount - 1; u32Index++) 525 | { 526 | lpItemCopy[u32Index].ItemInfo.u32Id = u32Index; 527 | } 528 | 529 | if (blUpdate) HWNP_Update(); 530 | } 531 | 532 | int HWNP_AddItem(__in uint32_t u32Id, __in LPCVOID lpNewData, __in uint32_t u32DataSize, __in LPCCH lpchPath, 533 | __in LPCCH lpchType, __in LPCCH lpchVersion, __in uint32_t u32Policy, __in uint32_t u32Reserved) 534 | { 535 | if (nState != -1) return (nLastError = -1201); 536 | if (lpNewData == NULL || u32DataSize == 0) return (nLastError = -1202); 537 | if (lpchPath == NULL) return (nLastError = -1203); 538 | if (lpchType == NULL) return (nLastError = -1204); 539 | if (lpchVersion == NULL) return (nLastError = -1205); 540 | 541 | PINT_ITEMCOPY lpNewItemCopy = (PINT_ITEMCOPY)malloc((u32ItemCount + 1) * sizeof(INT_ITEMCOPY)); 542 | if (lpNewItemCopy == NULL) return (nLastError = -1206); 543 | 544 | lpNewItemCopy[u32ItemCount].lpItemData = malloc(u32DataSize); 545 | if (lpNewItemCopy[u32ItemCount].lpItemData == NULL) 546 | { 547 | free(lpNewItemCopy); 548 | return (nLastError = -1207); 549 | } 550 | 551 | memcpy_s(lpNewItemCopy[u32ItemCount].lpItemData, u32DataSize, lpNewData, u32DataSize); 552 | lpNewItemCopy[u32ItemCount].u32DataSize = u32DataSize; 553 | 554 | lpNewItemCopy[u32ItemCount].ItemInfo.u32Id = u32Id; 555 | lpNewItemCopy[u32ItemCount].ItemInfo.u32ItemCRC32 = 0; 556 | lpNewItemCopy[u32ItemCount].ItemInfo.u32Offset = 0; 557 | lpNewItemCopy[u32ItemCount].ItemInfo.u32Size = u32DataSize; 558 | strcpy_s(lpNewItemCopy[u32ItemCount].ItemInfo.chItemPath, sizeof(HWNP_ITEMINFO::chItemPath), lpchPath); 559 | strcpy_s(lpNewItemCopy[u32ItemCount].ItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType), lpchType); 560 | strcpy_s(lpNewItemCopy[u32ItemCount].ItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion), lpchVersion); 561 | lpNewItemCopy[u32ItemCount].ItemInfo.u32Policy = u32Policy; 562 | lpNewItemCopy[u32ItemCount].ItemInfo.u32Reserved = u32Reserved; 563 | 564 | memcpy_s(lpNewItemCopy, sizeof(INT_ITEMCOPY) * u32ItemCount, lpItemCopy, sizeof(INT_ITEMCOPY) * u32ItemCount); 565 | free(lpItemCopy); 566 | lpItemCopy = lpNewItemCopy; 567 | u32ItemCount++; 568 | 569 | //将EFS项目置后 570 | for (uint32_t u32Index = 0; u32Index < u32ItemCount - 1; u32Index++) 571 | { 572 | if (strcmp(lpItemCopy[u32Index].ItemInfo.chItemType, "EFS") == 0) 573 | { 574 | HWNP_SwapItemCopy(&lpItemCopy[u32ItemCount - 1], &lpItemCopy[u32Index]); 575 | break; 576 | } 577 | } 578 | 579 | HWNP_Update(); 580 | return 0; 581 | } 582 | 583 | int HWNP_DeleteItem(__in uint32_t u32Index) 584 | { 585 | if (nState != -1) return (nLastError = -1301); 586 | if (u32Index >= u32ItemCount) return (nLastError = -1302); 587 | 588 | uint32_t u32NewCount = u32ItemCount - 1; 589 | PINT_ITEMCOPY lpNewItemCopy = (PINT_ITEMCOPY)malloc(u32NewCount * sizeof(INT_ITEMCOPY)); 590 | 591 | if (lpNewItemCopy == NULL) return (nLastError = -1303); 592 | 593 | if (u32Index == 0) 594 | { 595 | memcpy_s(lpNewItemCopy, u32NewCount * sizeof(INT_ITEMCOPY), &lpItemCopy[1], u32NewCount * sizeof(INT_ITEMCOPY)); 596 | } 597 | else if (u32Index == u32NewCount) 598 | { 599 | memcpy_s(lpNewItemCopy, u32NewCount * sizeof(INT_ITEMCOPY), lpItemCopy, u32NewCount * sizeof(INT_ITEMCOPY)); 600 | } 601 | else 602 | { 603 | uint32_t u32Tmp = u32NewCount - u32Index; 604 | 605 | memcpy_s(lpNewItemCopy, u32Index * sizeof(INT_ITEMCOPY), lpItemCopy, u32Index * sizeof(INT_ITEMCOPY)); 606 | memcpy_s(&lpNewItemCopy[u32Index], u32Tmp * sizeof(INT_ITEMCOPY), &lpItemCopy[u32Index + 1], u32Tmp * sizeof(INT_ITEMCOPY)); 607 | } 608 | 609 | u32ItemCount = u32NewCount; 610 | lpItemCopy = lpNewItemCopy; 611 | HWNP_Update(); 612 | return 0; 613 | } 614 | 615 | int HWNP_Save() 616 | { 617 | if (nState != -1) return (nLastError = -1401); 618 | 619 | uint32_t u32FileSize, u32DataSize = 0; 620 | DWORD dwOffset = 0, dwTmp; 621 | 622 | HWNP_Update(); 623 | 624 | //计算数据大小 625 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 626 | u32DataSize += lpItemCopy[u32Index].u32DataSize; 627 | 628 | //计算文件大小 629 | u32FileSize = sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO) + u32DataSize; 630 | 631 | //重设文件大小 632 | SetFilePointer(hFile, u32FileSize, NULL, FILE_BEGIN); 633 | SetEndOfFile(hFile); 634 | 635 | //写入头部 636 | SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); 637 | WriteFile(hFile, &hwHeader, sizeof(HWNP_HEADER), &dwTmp, NULL); 638 | dwOffset += sizeof(HWNP_HEADER); 639 | 640 | SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); 641 | WriteFile(hFile, lpProductList, hwHeader.PacketHeader.u16ProductListSize, &dwTmp, NULL); 642 | dwOffset += hwHeader.PacketHeader.u16ProductListSize; 643 | 644 | //写入项目信息 645 | for (uint32_t u32Index = 0; u32Index < u32ItemCount ; u32Index++) 646 | { 647 | SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); 648 | WriteFile(hFile, &lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), &dwTmp, NULL); 649 | dwOffset += sizeof(HWNP_ITEMINFO); 650 | } 651 | 652 | //写入项目数据 653 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 654 | { 655 | SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN); 656 | WriteFile(hFile, lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize, &dwTmp, NULL); 657 | dwOffset += lpItemCopy[u32Index].u32DataSize; 658 | } 659 | 660 | return 0; 661 | } 662 | 663 | int HWNP_SaveAs(__in LPCWSTR lpFilePath) 664 | { 665 | if (nState != -1) return (nLastError = -1401); 666 | 667 | HANDLE hNewFile; 668 | uint32_t u32FileSize, u32DataSize = 0; 669 | DWORD dwOffset = 0, dwTmp; 670 | 671 | hNewFile = CreateFileW(lpFilePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 672 | if (hNewFile == INVALID_HANDLE_VALUE) return (nLastError = -1402); 673 | 674 | HWNP_Update(); 675 | 676 | //计算数据大小 677 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 678 | u32DataSize += lpItemCopy[u32Index].u32DataSize; 679 | 680 | //计算文件大小 681 | u32FileSize = sizeof(HWNP_HEADER) + hwHeader.PacketHeader.u16ProductListSize + u32ItemCount * sizeof(HWNP_ITEMINFO) + u32DataSize; 682 | 683 | //重设文件大小 684 | SetFilePointer(hNewFile, u32FileSize, NULL, FILE_BEGIN); 685 | SetEndOfFile(hNewFile); 686 | 687 | //写入头部 688 | SetFilePointer(hNewFile, dwOffset, NULL, FILE_BEGIN); 689 | WriteFile(hNewFile, &hwHeader, sizeof(HWNP_HEADER), &dwTmp, NULL); 690 | dwOffset += sizeof(HWNP_HEADER); 691 | 692 | SetFilePointer(hNewFile, dwOffset, NULL, FILE_BEGIN); 693 | WriteFile(hNewFile, lpProductList, hwHeader.PacketHeader.u16ProductListSize, &dwTmp, NULL); 694 | dwOffset += hwHeader.PacketHeader.u16ProductListSize; 695 | 696 | //写入项目信息 697 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 698 | { 699 | SetFilePointer(hNewFile, dwOffset, NULL, FILE_BEGIN); 700 | WriteFile(hNewFile, &lpItemCopy[u32Index].ItemInfo, sizeof(HWNP_ITEMINFO), &dwTmp, NULL); 701 | dwOffset += sizeof(HWNP_ITEMINFO); 702 | } 703 | 704 | //写入项目数据 705 | for (uint32_t u32Index = 0; u32Index < u32ItemCount; u32Index++) 706 | { 707 | SetFilePointer(hNewFile, dwOffset, NULL, FILE_BEGIN); 708 | WriteFile(hNewFile, lpItemCopy[u32Index].lpItemData, lpItemCopy[u32Index].u32DataSize, &dwTmp, NULL); 709 | dwOffset += lpItemCopy[u32Index].u32DataSize; 710 | } 711 | 712 | CloseHandle(hNewFile); 713 | return 0; 714 | } 715 | 716 | int HWNP_CalibrationImageHeaderCrc32(PUIMG_HDR lpImageHdr) { 717 | UIMG_HDR hdrTmp; 718 | 719 | if (lpImageHdr == NULL) return -1; 720 | if (lpImageHdr->ih_magic != IH_MAGIC_LE) return -2; 721 | 722 | hdrTmp = *lpImageHdr; 723 | hdrTmp.ih_hcrc = 0; 724 | 725 | lpImageHdr->ih_hcrc = EndianSwap32(crc32_fast(&hdrTmp, sizeof(UIMG_HDR))); 726 | return 0; 727 | } 728 | -------------------------------------------------------------------------------- /HWFW_GUI/HWNP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _INC_STDDEF 4 | #include 5 | #endif 6 | 7 | #ifndef _STDINT 8 | #include 9 | #endif 10 | 11 | #ifndef SPECSTRINGS_H 12 | #include 13 | #endif 14 | 15 | #ifndef _WINDEF_ 16 | #include 17 | #endif 18 | 19 | #ifndef _WINBASE_ 20 | #include 21 | #endif 22 | 23 | #include "uboot_image.h" 24 | 25 | /* 26 | 参考: 27 | http://blog.leexiaolan.tk/pwn-huawei-hg8120c-ont-via-maintenance-tool-part-2 28 | http://blog.leexiaolan.tk/pwn-huawei-hg8120c-ont-upgrade-pack-format-part-3 29 | https://github.com/LeeXiaolan/hwfw-tool 30 | */ 31 | 32 | #define CHK_FLAGS(v, f) (((v) & (f)) == (f)) 33 | #define CHK_NOFLAGS(v, f) (((v) & (f)) != (f)) 34 | #define HWNP_HEADER_MAGIC 0x504e5748 //HWNP 35 | #define HWNP_HWHW_MAGIC 'hwhw' //whwh header magic 36 | #define CHK_OUT_OF_UBOUND(pointer, start, size) ((size_t)(pointer) >= ((size_t)(start) + (size_t)(size))) //检查上标越界 37 | #define CHK_OUT_OF_UBOUND2(pointer, len, start, size) (((size_t)(pointer) + (size_t)(len)) > ((size_t)(start) + (size_t)(size))) //检查上标越界 38 | 39 | #define EndianSwap32(int32) ((((uint32_t)(int32) & 0xff000000U) >> 24) | \ 40 | (((uint32_t)(int32) & 0x00ff0000U) >> 8) | \ 41 | (((uint32_t)(int32) & 0x0000ff00U) << 8) | \ 42 | (((uint32_t)(int32) & 0x000000ffU) << 24)) 43 | 44 | #define OffsetOf(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER ) 45 | 46 | #define MakePointer32(Ptr, Offset) ((void *)(((uint32_t)(Ptr)) + ((uint32_t)(Offset)))) 47 | 48 | 49 | //ItemInfo Flags 50 | #define IIFLAG_ID 0x00000001U 51 | #define IIFLAG_PATH 0x00000002U 52 | #define IIFLAG_TYPE 0x00000004U 53 | #define IIFLAG_VERSION 0x00000008U 54 | #define IIFLAG_POLICY 0x00000010U 55 | #define IIFLAG_RESERVED 0x00000020U 56 | #define IIFLAG_ALL (IIFLAG_ID | IIFLAG_PATH | IIFLAG_TYPE | IIFLAG_VERSION | IIFLAG_POLICY | IIFLAG_RESERVED) 57 | 58 | //ItemData Type 59 | #define IDT_WHWH 0x00000001U 60 | #define IDT_UBOOT 0x00000002U 61 | 62 | 63 | 64 | #define CHKCRC_OK 0 65 | #define CHKCRC_FAILED 11 66 | #define CHKCRC_FILECRCERR 191 67 | #define CHKCRC_HEADERCRCERR 192 68 | #define CHKCRC_ITEMCRCERR 200 69 | 70 | 71 | 72 | /* 73 | HuaWei 固件结构 74 | 75 | ___________________________________ 76 | | | 77 | | Header (文件头) | 78 | |___________________________________| 79 | | | 80 | | ProductList (支持的产品列表) | 81 | |___________________________________| 82 | | | 83 | | ItemInfo (项目信息) * N | 84 | |===================================| <---通常是连续的,但是理论上可以不连续 85 | | | 86 | | 项目 RAW数据 | 87 | |___________________________________| 88 | 89 | 90 | 91 | HW项目数据 (数据不对齐): 92 | ______________________________________________ 93 | | | 94 | | HW 项目头 (whwh) | 95 | | ____________________________________________ | 96 | || || 97 | || uImage 项目头 (0x27, 0x05, 0x19, 0x56) || 98 | ||____________________________________________|| 99 | || || 100 | || 项目有效载荷 (uboot, kernel, rootfs, ...) || 101 | ||____________________________________________|| 102 | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 103 | 104 | 105 | HW项目数据 (Padding对齐): 106 | _____________________________________________ 107 | | | 108 | | HW 项目头 (whwh) | 109 | | ___________________________________________ | 110 | || || 111 | || uImage 项目头 (0x27, 0x05, 0x19, 0x56) || 112 | ||___________________________________________|| 113 | || || 114 | || 项目有效载荷 (uboot, kernel, rootfs, ...) || 115 | ||___________________________________________|| 116 | | | 117 | | 对齐用的填充数据 | 118 | |_____________________________________________| 119 | 120 | 121 | HW项目数据 (Margin对齐): 122 | _____________________________________________ 123 | | | 124 | | HW 项目头 (whwh) | 125 | | ___________________________________________ | 126 | || || 127 | || uImage 项目头 (0x27, 0x05, 0x19, 0x56) || 128 | ||___________________________________________|| 129 | || || 130 | || 项目有效载荷 (uboot, kernel, rootfs, ...) || 131 | ||___________________________________________|| 132 | |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯| 133 | | 对齐用的填充数据 | 134 | |_____________________________________________| 135 | 136 | */ 137 | 138 | //基本文件头 139 | typedef struct _HWNP_BasicFileHeader 140 | { 141 | //魔法字 142 | uint32_t u32Magic; 143 | 144 | //文件大小 (计算公式为.bin的文件大小 - 76) big-endian 145 | __be32 beu32FileSize; 146 | 147 | //从HWNP_FILEHDR2开始到文件结束的CRC32值 (包含项目数据) 148 | uint32_t u32FileCRC32; 149 | } HWNP_BASFILEHDR, *PHWNP_BASFILEHDR; 150 | 151 | //文件头2 152 | typedef struct _HWNP_FileHeader2 153 | { 154 | //头部大小 155 | //计算公式有2种: 156 | //1: sizeof(HWNP_HEADER) + Header.u16ProductListSize + Header.u32ItemCount * Header.u16ItemInfoSize 157 | //2: Header.u16ProductListSize + Header.u32ItemCount * Header.u16ItemInfoSize 158 | //前一种多了文件头大小 159 | //新版本固件一般是第一种公式,好像V100版本的固件是第二种计算公式 160 | //该数值不是计算头部CRC32时的大小 161 | uint32_t u32HeaderSize; 162 | 163 | //从HWNP_PAKHDR开始到N个HWNP_ITEMINFO结束的CRC32值 (不包含项目数据) 164 | uint32_t u32HeaderCRC32; 165 | } HWNP_FILEHDR2, *PHWNP_FILEHDR2; 166 | 167 | //包头 168 | typedef struct _HWNP_PacketHeader 169 | { 170 | uint32_t u32ItemCount; 171 | uint8_t u8PackTotal; 172 | uint8_t u8PackNum; 173 | uint16_t u16ProductListSize; 174 | 175 | union { 176 | uint16_t u16ItemInfoSize; //== sizeof(HWNP_ITEMINFO) 177 | uint32_t _u32ItemInfoSize; //== sizeof(HWNP_ITEMINFO) 178 | }; 179 | 180 | uint32_t u32Reserved; 181 | } HWNP_PAKHDR, *PHWNP_PAKHDR; 182 | 183 | /* 184 | HWNP: Hua Wei Network Packet ? 185 | */ 186 | typedef struct _HWNP_Header 187 | { 188 | HWNP_BASFILEHDR BasicFileHeader; 189 | //file crc32 start comupte 190 | HWNP_FILEHDR2 FileHeader2; 191 | //header crc32 start comupte 192 | HWNP_PAKHDR PacketHeader; 193 | } HWNP_HEADER, *PHWNP_HEADER; 194 | 195 | 196 | typedef struct _HWNP_ItemInfo 197 | { 198 | uint32_t u32Id; //原 Index 199 | uint32_t u32ItemCRC32; 200 | uint32_t u32Offset; 201 | uint32_t u32Size; //原 Len 202 | char chItemPath[256]; //原 Destination 203 | char chItemType[16]; //原 Name 204 | char chItemVersion[64]; 205 | uint32_t u32Policy; 206 | uint32_t u32Reserved; 207 | } HWNP_ITEMINFO, *PHWNP_ITEMINFO; 208 | 209 | 210 | enum HW_SubItemType : uint32_t 211 | { 212 | hwType_Invalid = 0U, 213 | hwType_Kernel = 1U, 214 | hwType_RootFS, 215 | hwType_System, 216 | hwType_MiniSYS, 217 | hwType_UNK_5, 218 | hwType_UNK_6, 219 | hwType_L2Boot, 220 | hwType_UBoot, 221 | hwType_UNK_9, 222 | hwType_UNK_10, 223 | hwType_SignInfo, 224 | hwType_Limit 225 | }; 226 | 227 | const char * const HW_SubItemType_Text[hwType_Limit] = { 228 | "? Invalid", 229 | "1 Kernel", 230 | "2 RootFS", 231 | "3 System", 232 | "4 MiniSYS", 233 | "5 UNK_5", 234 | "6 UNK_6", 235 | "7 L2Boot", 236 | "8 UBoot", 237 | "9 UNK_9", 238 | "10 UNK_10", 239 | "11 SignInfo", 240 | }; 241 | 242 | 243 | const WCHAR * const HW_ItemType_Text[] = { 244 | L"UPGRDCHECK", 245 | L"MODULE", 246 | L"FLASH_CONFIG", 247 | L"UBOOT", 248 | L"L2BOOT", 249 | L"MINISYS", 250 | L"KERNEL", 251 | L"ROOTFS", 252 | L"UPDATEFLAG", 253 | L"EFS", 254 | L"SIGNINFO", 255 | L"UNKNOWN", 256 | NULL 257 | }; 258 | 259 | typedef struct _HW_Header 260 | { 261 | //魔法字 262 | uint32_t u32Magic; 263 | char chItemVersion[64]; 264 | __time32_t u32Time; 265 | HW_SubItemType u32Type; 266 | uint32_t u32RearSize; 267 | uint32_t u32RearCRC; 268 | } HW_HEADER, HW_HDR, *PHW_HEADER, *PHW_HDR; 269 | 270 | //内存文件是否已更改 271 | BOOL HWNP_IsChanged(); 272 | 273 | //获取最后的错误码 274 | int HWNP_GetLastError(); 275 | 276 | //获取状态值: -1为已正确打开固件文件 277 | int HWNP_GetState(); 278 | 279 | //获取头部大小的计算方式 280 | int HWNP_GetHeaderSizeType(); 281 | 282 | //设置头部大小的计算方式 283 | int HWNP_SetHeaderSizeType(__in int nNewType); 284 | 285 | //更新信息 (CRC, 项目偏移, 项目大小 等) 286 | void HWNP_Update(); 287 | 288 | //释放一切资源 289 | void HWNP_Release(); 290 | 291 | //打开固件文件 292 | int HWNP_OpenFirmware(__in LPCWSTR lpFilePath); 293 | 294 | //获取项目数量 295 | int HWNP_GetItemCount(__out uint32_t *lpu32Count); 296 | 297 | //获取项目索引通过项目Id 298 | int HWNP_GetItemIndexById(__in uint32_t u32Id, __out uint32_t *lpu32Index); 299 | 300 | //获取项目信息 301 | int HWNP_GetItemInfoByIndex(__in uint32_t u32Index, __out PHWNP_ITEMINFO lpItemInfo); 302 | 303 | //获取项目数据大小 304 | int HWNP_GetItemDataSizeByIndex(__in uint32_t u32Index, __out uint32_t *lpu32DataSize); 305 | 306 | //获取项目数据 (仅用于访问, 勿写入) 307 | int HWNP_GetItemDataPointerByIndex(__in uint32_t u32Index, __out LPCVOID *lppDataPointer); 308 | 309 | //获取项目数据类型 (whwh / uboot) 310 | int HWNP_GetItemDataTypeByIndex(__in uint32_t u32Index, __out LPDWORD lpDataType); 311 | 312 | //获取固件头部 313 | int HWNP_GetFirmwareHeader(__out PHWNP_HEADER lpHeader); 314 | 315 | //获取产品支持列表大小 316 | int HWNP_GetProductListSize(__out uint16_t *lpu16PLSize); 317 | 318 | //获取产品支持列表 319 | int HWNP_GetProductList(__inout LPCH lpchProdList, __in uint16_t u16PLSize); 320 | 321 | //设置产品支持列表 322 | int HWNP_SetProductList(__in LPCCH lpchProdList, __in uint16_t u16PLSize); 323 | 324 | //设置项目数据 325 | int HWNP_SetItemData(__in uint32_t u32Index, __in LPCVOID lpNewData, __in uint32_t u32DataSize); 326 | 327 | //设置项目信息 328 | int HWNP_SetItemInfo(__in uint32_t u32Index, __in uint32_t u32Mask, __in uint32_t u32Id, __in LPCCH lpchPath, __in LPCCH lpchType, __in LPCCH lpchVersion, __in uint32_t u32Policy, __in uint32_t u32Reserved); 329 | 330 | //获取项目最后的Id (未使用的id) 331 | uint32_t HWNP_GetLastItemId(); 332 | 333 | //检查是否有重复的Id 334 | BOOL HWNP_CheckDuplicate(); 335 | 336 | //校验CRC (0: 没有问题, 191:文件CRC不正确, 192: 头部CRC不正确, 200+: 项目CRC不正确) 337 | uint32_t HWNP_CheckCRC32(); 338 | 339 | //按照顺序,重新为项目Id排序 340 | void HWNP_SortItems(__in BOOL blUpdate); 341 | 342 | //添加新项目 343 | int HWNP_AddItem(__in uint32_t u32Id, __in LPCVOID lpNewData, __in uint32_t u32DataSize, __in LPCCH lpchPath, __in LPCCH lpchType, __in LPCCH lpchVersion, __in uint32_t u32Policy, __in uint32_t u32Reserved); 344 | 345 | //删除项目 346 | int HWNP_DeleteItem(__in uint32_t u32Index); 347 | 348 | //保存到文件 349 | int HWNP_Save(); 350 | 351 | //保存到其它文件 352 | int HWNP_SaveAs(__in LPCWSTR lpFilePath); 353 | 354 | //校准uImage Header CRC32 355 | int HWNP_CalibrationImageHeaderCrc32(__inout PUIMG_HDR lpImageHdr); 356 | -------------------------------------------------------------------------------- /HWFW_GUI/HWPDB.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/HWPDB.ini -------------------------------------------------------------------------------- /HWFW_GUI/Licenses/gpl-3.0-chs.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/Licenses/gpl-3.0-chs.txt -------------------------------------------------------------------------------- /HWFW_GUI/Licenses/gpl-3.0-cht.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/Licenses/gpl-3.0-cht.txt -------------------------------------------------------------------------------- /HWFW_GUI/Licenses/gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /HWFW_GUI/ListView_Events.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DlgMain.h" 3 | #include "HWFW_GUI.hpp" 4 | 5 | static WNDPROC wfnLV = NULL; 6 | static int nLastItem = -1; 7 | 8 | static LRESULT CALLBACK ListView_WndProc(HWND hCtrl, UINT Msg, WPARAM wParam, LPARAM lParam) 9 | { 10 | if (!wfnLV) 11 | return DefWindowProc(hCtrl, Msg, wParam, lParam); 12 | 13 | if (Msg == WM_DROPFILES) 14 | { 15 | WCHAR wsFile[MAX_PATH]; 16 | 17 | if (DragQueryFile((HDROP)wParam, 0, wsFile, MAX_PATH)) 18 | OpenFirmware(wsFile); 19 | 20 | DragFinish((HDROP)wParam); 21 | return 0; 22 | } 23 | 24 | return CallWindowProc(wfnLV, hCtrl, Msg, wParam, lParam); 25 | } 26 | 27 | void ListView_SetProc(HWND hCtrl) 28 | { 29 | wfnLV = (WNDPROC)SetWindowLongPtr(hCtrl, GWL_WNDPROC, (LONG)&ListView_WndProc); 30 | } 31 | 32 | void ListView_RightClick(LPNMITEMACTIVATE lpnmItemActivate) 33 | { 34 | if (lpnmItemActivate->iItem == -1) return; 35 | //if (lpnmItemActivate->lParam == NULL) return; 36 | 37 | LVITEMW lvi; 38 | PLVS lpLVS; 39 | POINT pt; 40 | 41 | nLastItem = lpnmItemActivate->iItem; 42 | //ListView_SetHotItem(lpnmItemActivate->hdr.hwndFrom, lpnmItemActivate->iItem); 43 | 44 | lvi.mask = LVIF_PARAM; 45 | lvi.iItem = lpnmItemActivate->iItem; 46 | lvi.iSubItem = lpnmItemActivate->iSubItem; 47 | 48 | ListView_GetItem(lpnmItemActivate->hdr.hwndFrom, &lvi); 49 | lpLVS = (PLVS)lvi.lParam; 50 | 51 | if (lpLVS == NULL) return; 52 | 53 | switch (lpLVS->ltType) 54 | { 55 | case LT_ITEMINFO: 56 | GetCursorPos(&pt); 57 | TrackPopupMenu(hmItemInfo, TPM_LEFTALIGN, pt.x, pt.y, 0, hMainDlg, NULL); 58 | break; 59 | } 60 | 61 | } 62 | 63 | int ListView_AddColumn(HWND hCtrl, int nWidth, int nIndex, LPWSTR lpText) 64 | { 65 | LVCOLUMNW lvc; 66 | 67 | ZeroMemory(&lvc, sizeof(LVCOLUMNW)); 68 | lvc.mask = LVCF_TEXT | LVCF_WIDTH; 69 | 70 | lvc.pszText = lpText; 71 | lvc.cx = nWidth; 72 | return ListView_InsertColumnW(hCtrl, nIndex, &lvc); 73 | } 74 | 75 | int ListView_AddItemA(HWND hCtrl, int iItem, int iSubItem, LPSTR lpText, LVI_TYPE ltType, DWORD dwFlags, DWORD dwUserData, LPARAM lParam) 76 | { 77 | LVITEMA lvi; 78 | int nResult; 79 | 80 | ZeroMemory(&lvi, sizeof(LVITEMA)); 81 | 82 | lvi.iItem = iItem; 83 | lvi.iSubItem = iSubItem; 84 | lvi.pszText = lpText; 85 | 86 | if (iSubItem == 0) 87 | { 88 | PLVS lpLVS = (PLVS)calloc(1, sizeof(LVS)); 89 | 90 | if (!lpLVS) return -1; 91 | 92 | lpLVS->ltType = ltType; 93 | lpLVS->dwFlags = dwFlags; 94 | lpLVS->dwUserData = dwUserData; 95 | lpLVS->lParam = lParam; 96 | 97 | lvi.lParam = (LPARAM)lpLVS; 98 | lvi.mask = LVIF_TEXT | LVIF_PARAM; 99 | nResult = ListView_InsertItemA(hCtrl, &lvi); 100 | } 101 | else 102 | { 103 | lvi.mask = LVIF_TEXT; 104 | nResult = ListView_SetItemA(hCtrl, &lvi); 105 | } 106 | 107 | return nResult; 108 | } 109 | 110 | int ListView_AddItemW(HWND hCtrl, int iItem, int iSubItem, LPWSTR lpText, LVI_TYPE ltType, DWORD dwFlags, DWORD dwUserData, LPARAM lParam) 111 | { 112 | LVITEMW lvi; 113 | int nResult; 114 | 115 | ZeroMemory(&lvi, sizeof(LVITEMW)); 116 | 117 | lvi.iItem = iItem; 118 | lvi.iSubItem = iSubItem; 119 | lvi.pszText = lpText; 120 | 121 | if (iSubItem == 0) 122 | { 123 | PLVS lpLVS = (PLVS)calloc(1, sizeof(LVS)); 124 | 125 | if (!lpLVS) return -1; 126 | 127 | lpLVS->ltType = ltType; 128 | lpLVS->dwFlags = dwFlags; 129 | lpLVS->dwUserData = dwUserData; 130 | lpLVS->lParam = lParam; 131 | 132 | lvi.lParam = (LPARAM)lpLVS; 133 | lvi.mask = LVIF_TEXT | LVIF_PARAM; 134 | nResult = ListView_InsertItemW(hCtrl, &lvi); 135 | } 136 | else 137 | { 138 | lvi.mask = LVIF_TEXT; 139 | nResult = ListView_SetItemW(hCtrl, &lvi); 140 | } 141 | 142 | return nResult; 143 | } 144 | 145 | int ListView_CurHotItem() 146 | { 147 | return nLastItem; 148 | } -------------------------------------------------------------------------------- /HWFW_GUI/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | WIN32 应用程序:HWFW_GUI 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 HWFW_GUI 应用程序。 6 | 7 | 本文件概要介绍组成 HWFW_GUI 应用程序的每个文件的内容。 8 | 9 | 10 | HWFW_GUI.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | HWFW_GUI.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | HWFW_GUI.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 应用程序向导创建了下列资源: 21 | 22 | HWFW_GUI.rc 23 | 这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。 24 | 25 | Resource.h 26 | 这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 27 | 28 | HWFW_GUI.ico 29 | 这是用作应用程序图标 (32x32) 的图标文件。此图标包括在主资源文件 HWFW_GUI.rc 中。 30 | 31 | small.ico 32 | 这是一个图标文件,其中包含应用程序的图标的较小版本 (16x16)。此图标包括在主资源文件 HWFW_GUI.rc 中。 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | 其他标准文件: 36 | 37 | StdAfx.h, StdAfx.cpp 38 | 这些文件用于生成名为 HWFW_GUI.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | 其他注释: 42 | 43 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 44 | 45 | ///////////////////////////////////////////////////////////////////////////// 46 | -------------------------------------------------------------------------------- /HWFW_GUI/TreeView_Events.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DlgMain.h" 3 | #include "HWFW_GUI.hpp" 4 | 5 | #define LV_CFG_SHOW_DATAINFO 0 6 | 7 | static WNDPROC wfnTV = NULL; 8 | 9 | extern CHAR chIniPath[MAX_PATH]; 10 | 11 | static void ListFileHeader(HWND hListView) 12 | { 13 | int nIndex = 0; 14 | HWNP_HEADER fwHeader; //firmware header 15 | WCHAR wsTemp[128]; 16 | 17 | DragAcceptFiles(hListView, FALSE); 18 | ListView_SetView(hListView, LV_VIEW_DETAILS); 19 | ListView_SetExtendedListViewStyle(hListView, LVS_EX_DEFAULT); 20 | 21 | 22 | ListView_AddColumn(hListView, 128, 0, L"文件偏移"); 23 | ListView_AddColumn(hListView, 264, 1, L"成员数值"); 24 | ListView_AddColumn(hListView, 460, 2, L"成员描述"); 25 | 26 | if (HWNP_GetFirmwareHeader(&fwHeader) != 0) return; 27 | 28 | 29 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, BasicFileHeader.u32Magic)); 30 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 31 | swprintf_s(wsTemp, SF_HEX, fwHeader.BasicFileHeader.u32Magic); 32 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 33 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"Magic # 魔法签名 (Little-Endian)", LT_NONE, 0, 0, 0); 34 | 35 | 36 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, BasicFileHeader.beu32FileSize)); 37 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 38 | swprintf_s(wsTemp, SF_HEX_DEC, EndianSwap32(fwHeader.BasicFileHeader.beu32FileSize), EndianSwap32(fwHeader.BasicFileHeader.beu32FileSize)); 39 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 40 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"FileSize # 文件大小 (Big-Endian)", LT_NONE, 0, 0, 0); 41 | 42 | 43 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, BasicFileHeader.u32FileCRC32)); 44 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 45 | swprintf_s(wsTemp, SF_HEX, fwHeader.BasicFileHeader.u32FileCRC32); 46 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 47 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"FileCRC32 # 文件CRC32 (Little-Endian)", LT_NONE, 0, 0, 0); 48 | 49 | 50 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, FileHeader2.u32HeaderSize)); 51 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 52 | swprintf_s(wsTemp, SF_HEX_DEC, fwHeader.FileHeader2.u32HeaderSize, fwHeader.FileHeader2.u32HeaderSize); 53 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 54 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"HeaderSize # 头部大小 (Little-Endian)", LT_NONE, 0, 0, 0); 55 | 56 | 57 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, FileHeader2.u32HeaderCRC32)); 58 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 59 | swprintf_s(wsTemp, SF_HEX, fwHeader.FileHeader2.u32HeaderCRC32); 60 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 61 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"HeaderCRC32 # 头部CRC32 (Little-Endian)", LT_NONE, 0, 0, 0); 62 | 63 | 64 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u32ItemCount)); 65 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 66 | swprintf_s(wsTemp, SF_HEX_DEC, fwHeader.PacketHeader.u32ItemCount, fwHeader.PacketHeader.u32ItemCount); 67 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 68 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"ItemCount # 项目信息计数 (Little-Endian)", LT_NONE, 0, 0, 0); 69 | 70 | 71 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u8PackTotal)); 72 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 73 | swprintf_s(wsTemp, SF_HEX8, LOBYTE(fwHeader.PacketHeader.u8PackTotal)); 74 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 75 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"PackTotal # PackTotal", LT_NONE, 0, 0, 0); 76 | 77 | 78 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u8PackNum)); 79 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 80 | swprintf_s(wsTemp, SF_HEX8, LOBYTE(fwHeader.PacketHeader.u8PackNum)); 81 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 82 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"PackNum # PackNum", LT_NONE, 0, 0, 0); 83 | 84 | 85 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u16ProductListSize)); 86 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 87 | swprintf_s(wsTemp, SF_HEX_DEC16, fwHeader.PacketHeader.u16ProductListSize, fwHeader.PacketHeader.u16ProductListSize); 88 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 89 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"ProductListSize # 产品列表大小 (Little-Endian)", LT_NONE, 0, 0, 0); 90 | 91 | 92 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u16ItemInfoSize)); 93 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 94 | swprintf_s(wsTemp, SF_HEX_DEC16, fwHeader.PacketHeader.u16ItemInfoSize, fwHeader.PacketHeader.u16ItemInfoSize); 95 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 96 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"ItemSize # 项目信息大小 (Little-Endian)", LT_NONE, 0, 0, 0); 97 | 98 | 99 | swprintf_s(wsTemp, SF_HEX, OffsetOf(HWNP_HEADER, PacketHeader.u32Reserved)); 100 | ListView_AddItemW(hListView, ItemIndex(nIndex), 0, wsTemp, LT_NONE, 0, 0, 0); 101 | swprintf_s(wsTemp, SF_HEX_DEC, fwHeader.PacketHeader.u32Reserved, fwHeader.PacketHeader.u32Reserved); 102 | ListView_AddItemW(hListView, ItemIndex(nIndex), 1, wsTemp, LT_NONE, 0, 0, 0); 103 | ListView_AddItemW(hListView, ItemIndexPlus(nIndex), 2, L"Reserved # 保留 (Little-Endian)", LT_NONE, 0, 0, 0); 104 | } 105 | 106 | static void ListProductInfo(HWND hListView) 107 | { 108 | int nIndex = 0; 109 | LPCH lpProdList, lpStr, lpEndStr, lpTmp; 110 | BOOL blInterface = FALSE; 111 | uint16_t u16Size = 0; 112 | CHAR chTmp[256], chTmp2[256]; 113 | 114 | DragAcceptFiles(hListView, FALSE); 115 | ListView_SetView(hListView, LV_VIEW_DETAILS); 116 | ListView_SetExtendedListViewStyle(hListView, LVS_EX_DEFAULT); 117 | 118 | 119 | ListView_AddColumn(hListView, 96, 0, L"产品标识"); 120 | ListView_AddColumn(hListView, 512, 1, L"匹配的产品名称"); 121 | 122 | HWNP_GetProductListSize(&u16Size); 123 | 124 | if (u16Size == 0) return; 125 | 126 | u16Size += 4; 127 | lpProdList = (LPCH)calloc(u16Size, sizeof(CHAR)); 128 | 129 | if (lpProdList == NULL) return; 130 | 131 | HWNP_GetProductList(lpProdList, u16Size); 132 | 133 | lpStr = lpProdList; 134 | 135 | while (*lpStr != 0) 136 | { 137 | if (*lpStr == '|') 138 | { 139 | lpStr++; 140 | continue; 141 | } 142 | 143 | lpEndStr = strchr(lpStr, '|'); 144 | 145 | if (lpEndStr == NULL) break; 146 | 147 | strncpy_s(chTmp, lpStr, lpEndStr - lpStr); 148 | lpTmp = chTmp; 149 | 150 | if (*lpTmp == ';') 151 | { 152 | lpTmp++; 153 | 154 | if (blInterface == FALSE) 155 | { 156 | blInterface = TRUE; 157 | 158 | ListView_AddItemA(hListView, ItemIndex(nIndex), 0, ";;;", LT_MODELINFO, 0, 0, 0); 159 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, ";;; WEB Interface [WEB界面] ;;;", LT_MODELINFO, 0, 0, 0); 160 | } 161 | } 162 | 163 | if (blInterface) 164 | { 165 | ListView_AddItemA(hListView, ItemIndex(nIndex), 0, lpTmp, LT_MODELINFO, 0, 0, 0); 166 | 167 | if (strcmp(lpTmp, "E8C") == 0) 168 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, "中国电信界面 [China Telecom WEB Interface]", LT_MODELINFO, 0, 0, 0); 169 | else if (strcmp(lpTmp, "COMMON") == 0) 170 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, "华为原厂界面 [HuaWei WEB Interface]", LT_MODELINFO, 0, 0, 0); 171 | else if (strcmp(lpTmp, "CHINA") == 0) 172 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, "中国联通界面 [China Unicom WEB Interface]", LT_MODELINFO, 0, 0, 0); 173 | else if (strcmp(lpTmp, "CMCC") == 0) 174 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, "中国移动界面 [China Mobile WEB Interface]", LT_MODELINFO, 0, 0, 0); 175 | else 176 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, "未知界面 [Unknown Interface]", LT_MODELINFO, 0, 0, 0); 177 | } 178 | else 179 | { 180 | GetPrivateProfileStringA("HW_ProductDatabase", lpTmp, "< N/A >", chTmp2, sizeof(chTmp2), chIniPath); 181 | 182 | ListView_AddItemA(hListView, ItemIndex(nIndex), 0, lpTmp, LT_MODELINFO, 0, 0, 0); 183 | ListView_AddItemA(hListView, ItemIndexPlus(nIndex), 1, chTmp2, LT_MODELINFO, 0, 0, 0); 184 | } 185 | 186 | lpStr = lpEndStr + 1; 187 | } 188 | 189 | free(lpProdList); 190 | } 191 | 192 | 193 | void ListItemInfo(HWND hListView) 194 | { 195 | //int nIndex = 0; 196 | uint32_t u32Count; 197 | HWNP_HEADER hwPakHdr; 198 | HWNP_ITEMINFO hwItemInfo; 199 | WCHAR wsTemp[260]; 200 | 201 | DragAcceptFiles(hListView, FALSE); 202 | ListView_SetView(hListView, LV_VIEW_DETAILS); 203 | ListView_SetExtendedListViewStyle(hListView, LVS_EX_DEFAULT); 204 | 205 | 206 | ListView_AddColumn(hListView, 128, 0, L"项目信息偏移"); 207 | ListView_AddColumn(hListView, 56, 1, L"Id"); 208 | ListView_AddColumn(hListView, 304, 2, L"项目路径"); 209 | ListView_AddColumn(hListView, 112, 3, L"项目策略"); 210 | ListView_AddColumn(hListView, 112, 4, L"项目CRC32"); 211 | #if LV_CFG_SHOW_DATAINFO 212 | ListView_AddColumn(hListView, 100, 5, L"项目数据偏移"); 213 | ListView_AddColumn(hListView, 200, 6, L"项目数据大小"); 214 | ListView_AddColumn(hListView, 104, 7, L"项目类型"); 215 | ListView_AddColumn(hListView, 256, 8, L"项目版本"); 216 | ListView_AddColumn(hListView, 90, 9, L"保留数据"); 217 | #else 218 | ListView_AddColumn(hListView, 112, 5, L"项目类型"); 219 | ListView_AddColumn(hListView, 256, 6, L"项目版本"); 220 | ListView_AddColumn(hListView, 112, 7, L"保留数据"); 221 | #endif 222 | 223 | 224 | if (HWNP_GetFirmwareHeader(&hwPakHdr) != 0) return; 225 | if (HWNP_GetItemCount(&u32Count) != 0) return; 226 | 227 | for (uint32_t u32Index = 0; u32Index < u32Count; u32Index++) 228 | { 229 | size_t stOut; 230 | 231 | swprintf_s(wsTemp, SF_HEX, sizeof(HWNP_HEADER) + hwPakHdr.PacketHeader.u16ProductListSize + u32Index * sizeof(HWNP_ITEMINFO)); 232 | ListView_AddItemW(hListView, u32Index, 0, wsTemp, LT_ITEMINFO, 0, u32Index, 0); 233 | 234 | if (HWNP_GetItemInfoByIndex(u32Index, &hwItemInfo) != 0) continue; 235 | 236 | swprintf_s(wsTemp, SF_DEC, hwItemInfo.u32Id); 237 | ListView_AddItemW(hListView, u32Index, 1, wsTemp, LT_ITEMINFO, 0, 0, 0); 238 | 239 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemPath, sizeof(HWNP_ITEMINFO::chItemPath)); 240 | ListView_AddItemW(hListView, u32Index, 2, wsTemp, LT_ITEMINFO, 0, 0, 0); 241 | 242 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Policy); 243 | ListView_AddItemW(hListView, u32Index, 3, wsTemp, LT_ITEMINFO, 0, 0, 0); 244 | 245 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32ItemCRC32); 246 | ListView_AddItemW(hListView, u32Index, 4, wsTemp, LT_ITEMINFO, 0, 0, 0); 247 | 248 | #if LV_CFG_SHOW_DATAINFO 249 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Offset); 250 | ListView_AddItemW(hListView, u32Index, 5, wsTemp, LT_ITEMINFO, 0, 0, 0); 251 | 252 | swprintf_s(wsTemp, SF_HEX_DEC, hwItemInfo.u32Size, hwItemInfo.u32Size); 253 | ListView_AddItemW(hListView, u32Index, 6, wsTemp, LT_ITEMINFO, 0, 0, 0); 254 | 255 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType)); 256 | ListView_AddItemW(hListView, u32Index, 7, wsTemp, LT_ITEMINFO, 0, 0, 0); 257 | 258 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion)); 259 | ListView_AddItemW(hListView, u32Index, 8, wsTemp, LT_ITEMINFO, 0, 0, 0); 260 | 261 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 262 | ListView_AddItemW(hListView, u32Index, 9, wsTemp, LT_ITEMINFO, 0, 0, 0); 263 | #else 264 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType)); 265 | ListView_AddItemW(hListView, u32Index, 5, wsTemp, LT_ITEMINFO, 0, 0, 0); 266 | 267 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion)); 268 | ListView_AddItemW(hListView, u32Index, 6, wsTemp, LT_ITEMINFO, 0, 0, 0); 269 | 270 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 271 | ListView_AddItemW(hListView, u32Index, 7, wsTemp, LT_ITEMINFO, 0, 0, 0); 272 | #endif 273 | } 274 | } 275 | 276 | void UpdateItemInfo(HWND hListView) 277 | { 278 | uint32_t u32Count; 279 | HWNP_HEADER hwPakHdr; 280 | HWNP_ITEMINFO hwItemInfo; 281 | WCHAR wsTemp[260]; 282 | 283 | ListView_DeleteAllItems(GetDlgItem(hMainDlg, IDC_LV)); 284 | 285 | if (HWNP_GetFirmwareHeader(&hwPakHdr) != 0) return; 286 | if (HWNP_GetItemCount(&u32Count) != 0) return; 287 | 288 | for (uint32_t u32Index = 0; u32Index < u32Count; u32Index++) 289 | { 290 | size_t stOut; 291 | 292 | swprintf_s(wsTemp, SF_HEX, sizeof(HWNP_HEADER) + hwPakHdr.PacketHeader.u16ProductListSize + u32Index * sizeof(HWNP_ITEMINFO)); 293 | ListView_AddItemW(hListView, u32Index, 0, wsTemp, LT_ITEMINFO, 0, u32Index, 0); 294 | 295 | if (HWNP_GetItemInfoByIndex(u32Index, &hwItemInfo) != 0) continue; 296 | 297 | swprintf_s(wsTemp, SF_DEC, hwItemInfo.u32Id); 298 | ListView_AddItemW(hListView, u32Index, 1, wsTemp, LT_ITEMINFO, 0, 0, 0); 299 | 300 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemPath, sizeof(HWNP_ITEMINFO::chItemPath)); 301 | ListView_AddItemW(hListView, u32Index, 2, wsTemp, LT_ITEMINFO, 0, 0, 0); 302 | 303 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Policy); 304 | ListView_AddItemW(hListView, u32Index, 3, wsTemp, LT_ITEMINFO, 0, 0, 0); 305 | 306 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32ItemCRC32); 307 | ListView_AddItemW(hListView, u32Index, 4, wsTemp, LT_ITEMINFO, 0, 0, 0); 308 | 309 | #if LV_CFG_SHOW_DATAINFO 310 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Offset); 311 | ListView_AddItemW(hListView, u32Index, 5, wsTemp, LT_ITEMINFO, 0, 0, 0); 312 | 313 | swprintf_s(wsTemp, SF_HEX_DEC, hwItemInfo.u32Size, hwItemInfo.u32Size); 314 | ListView_AddItemW(hListView, u32Index, 6, wsTemp, LT_ITEMINFO, 0, 0, 0); 315 | 316 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType)); 317 | ListView_AddItemW(hListView, u32Index, 7, wsTemp, LT_ITEMINFO, 0, 0, 0); 318 | 319 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion)); 320 | ListView_AddItemW(hListView, u32Index, 8, wsTemp, LT_ITEMINFO, 0, 0, 0); 321 | 322 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 323 | ListView_AddItemW(hListView, u32Index, 9, wsTemp, LT_ITEMINFO, 0, 0, 0); 324 | #else 325 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemType, sizeof(HWNP_ITEMINFO::chItemType)); 326 | ListView_AddItemW(hListView, u32Index, 5, wsTemp, LT_ITEMINFO, 0, 0, 0); 327 | 328 | mbstowcs_s(&stOut, wsTemp, hwItemInfo.chItemVersion, sizeof(HWNP_ITEMINFO::chItemVersion)); 329 | ListView_AddItemW(hListView, u32Index, 6, wsTemp, LT_ITEMINFO, 0, 0, 0); 330 | 331 | swprintf_s(wsTemp, SF_HEX, hwItemInfo.u32Reserved); 332 | ListView_AddItemW(hListView, u32Index, 7, wsTemp, LT_ITEMINFO, 0, 0, 0); 333 | #endif 334 | } 335 | } 336 | 337 | static LRESULT CALLBACK TreeView_WndProc(HWND hCtrl, UINT Msg, WPARAM wParam, LPARAM lParam) 338 | { 339 | if (Msg == WM_DROPFILES) 340 | { 341 | WCHAR wsFile[MAX_PATH]; 342 | 343 | if (DragQueryFile((HDROP)wParam, 0, wsFile, MAX_PATH)) 344 | { 345 | OpenFirmware(wsFile); 346 | 347 | LPWSTR lpFileName = wcsrchr(wsFile, '\\'); 348 | WCHAR wsTemp[MAX_PATH]; 349 | 350 | if (lpFileName) 351 | { 352 | lpFileName++; 353 | 354 | swprintf_s(wsTemp, L"%s %s %s Build:%s [%s]", APP_NAME, APP_VER1, APP_VER2, APP_BUILD_VER, lpFileName); 355 | SetWindowTextW(hMainDlg, wsTemp); 356 | } 357 | } 358 | 359 | DragFinish((HDROP)wParam); 360 | return 0; 361 | } 362 | 363 | if (!wfnTV) return DefWindowProc(hCtrl, Msg, wParam, lParam); 364 | return CallWindowProc(wfnTV, hCtrl, Msg, wParam, lParam); 365 | } 366 | 367 | void TreeView_SetProc(HWND hCtrl) 368 | { 369 | wfnTV = (WNDPROC)SetWindowLongPtr(hCtrl, GWL_WNDPROC, (LONG)&TreeView_WndProc); 370 | } 371 | 372 | void TreeView_SelChanged(LPNMTREEVIEW lpnmTV) 373 | { 374 | HWND hListView = GetDlgItem(hMainDlg, IDC_LV); 375 | CleanListView(); 376 | 377 | switch (lpnmTV->itemNew.lParam) 378 | { 379 | case TT_FILEHDR: 380 | ListFileHeader(hListView); 381 | break; 382 | 383 | case TT_MODELINFO: 384 | ListProductInfo(hListView); 385 | break; 386 | 387 | case TT_ITEMINFO: 388 | ListItemInfo(hListView); 389 | break; 390 | } 391 | } 392 | 393 | -------------------------------------------------------------------------------- /HWFW_GUI/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /HWFW_GUI/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/HWFW_GUI/resource.h -------------------------------------------------------------------------------- /HWFW_GUI/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /HWFW_GUI/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : 标准系统包含文件的包含文件, 2 | // 或是经常使用但不常更改的 3 | // 特定于项目的包含文件 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料 11 | // Windows 头文件: 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // C 运行时头文件 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #ifdef NDEBUG 30 | #undef NDEBUG 31 | #include 32 | #define NDEBUG 33 | #else 34 | #include 35 | #endif 36 | 37 | 38 | #define APP_NAME L"HWFW_GUI" 39 | #define APP_VER1 L"1.0.8" 40 | #define APP_VER2 L"Beta" 41 | #define APP_BUILD_VER L"005" 42 | 43 | 44 | #if defined _M_IX86 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #else 47 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 48 | #endif 49 | 50 | #define LVS_EX_DEFAULT (LVS_EX_FULLROWSELECT) 51 | 52 | #define TreeView_DlgInsertItem(hwnd, item, lpis) \ 53 | (HTREEITEM)::SendDlgItemMessage((hwnd), (int)(item), TVM_INSERTITEM, 0, (LPARAM)(lpis)) 54 | 55 | #define TreeView_DlgInsertItemA(hwnd, item, lpis) \ 56 | (HTREEITEM)::SendDlgItemMessageA((hwnd), (int)(item), TVM_INSERTITEMA, 0, (LPARAM)(lpis)) 57 | 58 | #define TreeView_DlgInsertItemW(hwnd, item, lpis) \ 59 | (HTREEITEM)::SendDlgItemMessageW((hwnd), (int)(item), TVM_INSERTITEMW, 0, (LPARAM)(lpis)) 60 | 61 | #define TreeView_DlgSelectItem(hwnd, item, hitem) \ 62 | (BOOL)::SendDlgItemMessage((hwnd), (int)(item), TVM_SELECTITEM, (WPARAM)TVGN_CARET, (LPARAM)(HTREEITEM)(hitem)) 63 | 64 | #define ListView_InsertColumnW(hwnd, iCol, pcol) \ 65 | (int)::SendMessageW((hwnd), LVM_INSERTCOLUMNW, (WPARAM)(iCol), (LPARAM)(pcol)) 66 | 67 | #define TreeView_DlgSetItemA(hwnd, item, pitem) \ 68 | (BOOL)::SendDlgItemMessageA((hwnd), (int)(item), TVM_SETITEMA, 0, (LPARAM)(const TVITEMA *)(pitem)) 69 | 70 | #define TreeView_DlgSetItemW(hwnd, item, pitem) \ 71 | (BOOL)::SendDlgItemMessageW((hwnd), (int)(item), TVM_SETITEMW, 0, (LPARAM)(const TVITEMW *)(pitem)) 72 | 73 | #define ListView_InsertItemA(hwnd, pitem) \ 74 | (int)::SendMessageA((hwnd), LVM_INSERTITEMA, 0, (LPARAM)(pitem)) 75 | 76 | #define ListView_InsertItemW(hwnd, pitem) \ 77 | (int)::SendMessageW((hwnd), LVM_INSERTITEMW, 0, (LPARAM)(pitem)) 78 | 79 | #define ListView_SetItemA(hwnd, pitem) \ 80 | (BOOL)::SendMessageA((hwnd), LVM_SETITEMA, 0, (LPARAM)(pitem)) 81 | 82 | #define ListView_SetItemW(hwnd, pitem) \ 83 | (BOOL)::SendMessageW((hwnd), LVM_SETITEMW, 0, (LPARAM)(pitem)) 84 | 85 | #define ListView_GetItemW(hwnd, pitem) \ 86 | (BOOL)::SendMessageW((hwnd), LVM_GETITEMW, 0, (LPARAM)(LVITEMW *)(pitem)) 87 | 88 | #define ComboBox_AddStringW(hwndCtl, lpsz) \ 89 | ((int)(DWORD)::SendMessageW((hwndCtl), CB_ADDSTRING, 0L, (LPARAM)(LPCWSTR)(lpsz))) 90 | 91 | #define ComboBox_InsertStringA(hwndCtl, index, lpsz) \ 92 | ((int)(DWORD)::SendMessageA((hwndCtl), CB_INSERTSTRING, (WPARAM)(int)(index), (LPARAM)(LPCSTR)(lpsz))) 93 | 94 | #define ComboBox_InsertStringW(hwndCtl, index, lpsz) \ 95 | ((int)(DWORD)::SendMessageW((hwndCtl), CB_INSERTSTRING, (WPARAM)(int)(index), (LPARAM)(LPCWSTR)(lpsz))) 96 | 97 | 98 | //String Format 99 | #define SF_DEC L"%u" 100 | #define SF_DEC16 L"%hu" 101 | #define SF_HEX L"0x%08X" 102 | #define SF_HEX_DEC L"0x%08X (Dec:%u)" 103 | #define SF_HEX16 L"0x%04hX" 104 | #define SF_HEX_DEC16 L"0x%04hX (Dec:%hu)" 105 | #define SF_HEX8 L"0x%02hX" 106 | #define SF_HEX_DEC8 L"0x%02hX (Dec:%hu)" 107 | #define SF_DATE L"%04u-%02u-%02u %02u:%02u:%02u" 108 | 109 | //Item Index 110 | #define ItemIndex(i) (i) 111 | #define ItemIndexPlus(i) (i++) 112 | 113 | 114 | uint32_t crc32_fast(const void* data, size_t length, uint32_t previousCrc32 = 0); 115 | -------------------------------------------------------------------------------- /HWFW_GUI/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /HWFW_GUI/uboot_image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _STDINT 4 | #include 5 | #endif 6 | 7 | typedef uint32_t __be32; //Big-endian unsigned int 32bits 8 | 9 | /* 10 | * (C) Copyright 2008 Semihalf 11 | * 12 | * (C) Copyright 2000-2005 13 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 14 | * 15 | * See file CREDITS for list of people who contributed to this 16 | * project. 17 | * 18 | * This program is free software; you can redistribute it and/or 19 | * modify it under the terms of the GNU General Public License as 20 | * published by the Free Software Foundation; either version 2 of 21 | * the License, or (at your option) any later version. 22 | * 23 | * This program is distributed in the hope that it will be useful, 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | * GNU General Public License for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with this program; if not, write to the Free Software 30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 31 | * MA 02111-1307 USA 32 | * 33 | ******************************************************************** 34 | * NOTE: This header file defines an interface to U-Boot. Including 35 | * this (unmodified) header file in another file is considered normal 36 | * use of U-Boot, and does *not* fall under the heading of "derived 37 | * work". 38 | ******************************************************************** 39 | */ 40 | 41 | 42 | /* 43 | * Operating System Codes 44 | * 45 | * The following are exposed to uImage header. 46 | * Do not change values for backward compatibility. 47 | */ 48 | enum IH_OS : uint8_t { 49 | IH_OS_INVALID = 0, /* Invalid OS */ 50 | IH_OS_OPENBSD, /* OpenBSD */ 51 | IH_OS_NETBSD, /* NetBSD */ 52 | IH_OS_FREEBSD, /* FreeBSD */ 53 | IH_OS_4_4BSD, /* 4.4BSD */ 54 | IH_OS_LINUX, /* Linux */ 55 | IH_OS_SVR4, /* SVR4 */ 56 | IH_OS_ESIX, /* Esix */ 57 | IH_OS_SOLARIS, /* Solaris */ 58 | IH_OS_IRIX, /* Irix */ 59 | IH_OS_SCO, /* SCO */ 60 | IH_OS_DELL, /* Dell */ 61 | IH_OS_NCR, /* NCR */ 62 | IH_OS_LYNXOS, /* LynxOS */ 63 | IH_OS_VXWORKS, /* VxWorks */ 64 | IH_OS_PSOS, /* pSOS */ 65 | IH_OS_QNX, /* QNX */ 66 | IH_OS_U_BOOT, /* Firmware */ 67 | IH_OS_RTEMS, /* RTEMS */ 68 | IH_OS_ARTOS, /* ARTOS */ 69 | IH_OS_UNITY, /* Unity OS */ 70 | IH_OS_INTEGRITY, /* INTEGRITY */ 71 | IH_OS_OSE, /* OSE */ 72 | IH_OS_PLAN9, /* Plan 9 */ 73 | IH_OS_OPENRTOS, /* OpenRTOS */ 74 | IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */ 75 | IH_OS_TEE, /* Trusted Execution Environment */ 76 | 77 | IH_OS_COUNT, 78 | }; 79 | 80 | const char * const enum_IH_OS[IH_OS_COUNT] = { 81 | "Invalid", 82 | "OpenBSD", 83 | "NetBSD", 84 | "FreeBSD", 85 | "4.4BSD", 86 | "Linux", 87 | "SVR4", 88 | "ESIX", 89 | "Solaris", 90 | "Irix", 91 | "SCO", 92 | "Dell", 93 | "NCR", 94 | "LynxOS", 95 | "VxWorks", 96 | "pSOS", 97 | "QNX", 98 | "Firmware", 99 | "RTEMS", 100 | "ARTOS", 101 | "Unity OS", 102 | "INTEGRITY", 103 | "OSE", 104 | "Plan 9", 105 | "OpenRTOS", 106 | "ARM Trusted Firmware", 107 | "Trusted Execution Environment" 108 | }; 109 | 110 | /* 111 | * CPU Architecture Codes (supported by Linux) 112 | * 113 | * The following are exposed to uImage header. 114 | * Do not change values for backward compatibility. 115 | */ 116 | enum IH_ARCH : uint8_t { 117 | IH_ARCH_INVALID = 0, /* Invalid CPU */ 118 | IH_ARCH_ALPHA, /* Alpha */ 119 | IH_ARCH_ARM, /* ARM */ 120 | IH_ARCH_I386, /* Intel x86 */ 121 | IH_ARCH_IA64, /* IA64 */ 122 | IH_ARCH_MIPS, /* MIPS */ 123 | IH_ARCH_MIPS64, /* MIPS 64 Bit */ 124 | IH_ARCH_PPC, /* PowerPC */ 125 | IH_ARCH_S390, /* IBM S390 */ 126 | IH_ARCH_SH, /* SuperH */ 127 | IH_ARCH_SPARC, /* Sparc */ 128 | IH_ARCH_SPARC64, /* Sparc 64 Bit */ 129 | IH_ARCH_M68K, /* M68K */ 130 | IH_ARCH_NIOS, /* Nios-32 */ 131 | IH_ARCH_MICROBLAZE, /* MicroBlaze */ 132 | IH_ARCH_NIOS2, /* Nios-II */ 133 | IH_ARCH_BLACKFIN, /* Blackfin */ 134 | IH_ARCH_AVR32, /* AVR32 */ 135 | IH_ARCH_ST200, /* STMicroelectronics ST200 */ 136 | IH_ARCH_SANDBOX, /* Sandbox architecture (test only) */ 137 | IH_ARCH_NDS32, /* ANDES Technology - NDS32 */ 138 | IH_ARCH_OPENRISC, /* OpenRISC 1000 */ 139 | IH_ARCH_ARM64, /* ARM64 */ 140 | IH_ARCH_ARC, /* Synopsys DesignWare ARC */ 141 | IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */ 142 | IH_ARCH_XTENSA, /* Xtensa */ 143 | IH_ARCH_RISCV, /* RISC-V */ 144 | 145 | IH_ARCH_COUNT, 146 | }; 147 | 148 | const char * const enum_IH_ARCH[IH_ARCH_COUNT] = { 149 | "Invalid", 150 | "Alpha", 151 | "ARM", 152 | "Intel x86", 153 | "IA64", 154 | "MIPS", 155 | "MIPS 64 Bit", 156 | "PowerPC", 157 | "IBM S390", 158 | "SuperH", 159 | "Sparc", 160 | "Sparc 64 Bit", 161 | "M68K", 162 | "Nios-32", 163 | "MicroBlaze", 164 | "Nios-II", 165 | "Blackfin", 166 | "AVR32", 167 | "ST200", 168 | "Sandbox architecture", 169 | "NDS32", 170 | "OpenRISC 1000", 171 | "ARM64", 172 | "ARC", 173 | "x86_64", 174 | "Xtensa", 175 | "RISC-V" 176 | }; 177 | 178 | 179 | /* 180 | * Image Types 181 | * 182 | * "Standalone Programs" are directly runnable in the environment 183 | * provided by U-Boot; it is expected that (if they behave 184 | * well) you can continue to work in U-Boot after return from 185 | * the Standalone Program. 186 | * "OS Kernel Images" are usually images of some Embedded OS which 187 | * will take over control completely. Usually these programs 188 | * will install their own set of exception handlers, device 189 | * drivers, set up the MMU, etc. - this means, that you cannot 190 | * expect to re-enter U-Boot except by resetting the CPU. 191 | * "RAMDisk Images" are more or less just data blocks, and their 192 | * parameters (address, size) are passed to an OS kernel that is 193 | * being started. 194 | * "Multi-File Images" contain several images, typically an OS 195 | * (Linux) kernel image and one or more data images like 196 | * RAMDisks. This construct is useful for instance when you want 197 | * to boot over the network using BOOTP etc., where the boot 198 | * server provides just a single image file, but you want to get 199 | * for instance an OS kernel and a RAMDisk image. 200 | * 201 | * "Multi-File Images" start with a list of image sizes, each 202 | * image size (in bytes) specified by an "uint32_t" in network 203 | * byte order. This list is terminated by an "(uint32_t)0". 204 | * Immediately after the terminating 0 follow the images, one by 205 | * one, all aligned on "uint32_t" boundaries (size rounded up to 206 | * a multiple of 4 bytes - except for the last file). 207 | * 208 | * "Firmware Images" are binary images containing firmware (like 209 | * U-Boot or FPGA images) which usually will be programmed to 210 | * flash memory. 211 | * 212 | * "Script files" are command sequences that will be executed by 213 | * U-Boot's command interpreter; this feature is especially 214 | * useful when you configure U-Boot to use a real shell (hush) 215 | * as command interpreter (=> Shell Scripts). 216 | * 217 | * The following are exposed to uImage header. 218 | * Do not change values for backward compatibility. 219 | */ 220 | 221 | enum IH_TYPE : uint8_t { 222 | IH_TYPE_INVALID = 0, /* Invalid Image */ 223 | IH_TYPE_STANDALONE, /* Standalone Program */ 224 | IH_TYPE_KERNEL, /* OS Kernel Image */ 225 | IH_TYPE_RAMDISK, /* RAMDisk Image */ 226 | IH_TYPE_MULTI, /* Multi-File Image */ 227 | IH_TYPE_FIRMWARE, /* Firmware Image */ 228 | IH_TYPE_SCRIPT, /* Script file */ 229 | IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */ 230 | IH_TYPE_FLATDT, /* Binary Flat Device Tree Blob */ 231 | IH_TYPE_KWBIMAGE, /* Kirkwood Boot Image */ 232 | IH_TYPE_IMXIMAGE, /* Freescale IMXBoot Image */ 233 | IH_TYPE_UBLIMAGE, /* Davinci UBL Image */ 234 | IH_TYPE_OMAPIMAGE, /* TI OMAP Config Header Image */ 235 | IH_TYPE_AISIMAGE, /* TI Davinci AIS Image */ 236 | /* OS Kernel Image, can run from any load address */ 237 | IH_TYPE_KERNEL_NOLOAD, 238 | IH_TYPE_PBLIMAGE, /* Freescale PBL Boot Image */ 239 | IH_TYPE_MXSIMAGE, /* Freescale MXSBoot Image */ 240 | IH_TYPE_GPIMAGE, /* TI Keystone GPHeader Image */ 241 | IH_TYPE_ATMELIMAGE, /* ATMEL ROM bootable Image */ 242 | IH_TYPE_SOCFPGAIMAGE, /* Altera SOCFPGA Preloader */ 243 | IH_TYPE_X86_SETUP, /* x86 setup.bin Image */ 244 | IH_TYPE_LPC32XXIMAGE, /* x86 setup.bin Image */ 245 | IH_TYPE_LOADABLE, /* A list of typeless images */ 246 | IH_TYPE_RKIMAGE, /* Rockchip Boot Image */ 247 | IH_TYPE_RKSD, /* Rockchip SD card */ 248 | IH_TYPE_RKSPI, /* Rockchip SPI image */ 249 | IH_TYPE_ZYNQIMAGE, /* Xilinx Zynq Boot Image */ 250 | IH_TYPE_ZYNQMPIMAGE, /* Xilinx ZynqMP Boot Image */ 251 | IH_TYPE_FPGA, /* FPGA Image */ 252 | IH_TYPE_VYBRIDIMAGE, /* VYBRID .vyb Image */ 253 | IH_TYPE_TEE, /* Trusted Execution Environment OS Image */ 254 | IH_TYPE_FIRMWARE_IVT, /* Firmware Image with HABv4 IVT */ 255 | IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */ 256 | IH_TYPE_STM32IMAGE, /* STMicroelectronics STM32 Image */ 257 | IH_TYPE_SOCFPGAIMAGE_V1, /* Altera SOCFPGA A10 Preloader */ 258 | IH_TYPE_MTKIMAGE, /* MediaTek BootROM loadable Image */ 259 | IH_TYPE_IMX8MIMAGE, /* Freescale IMX8MBoot Image */ 260 | IH_TYPE_IMX8IMAGE, /* Freescale IMX8Boot Image */ 261 | 262 | IH_TYPE_COUNT, /* Number of image types */ 263 | }; 264 | 265 | const char * const enum_IH_TYPE[IH_TYPE_COUNT] = { 266 | "Invalid", 267 | "Standalone Program", 268 | "OS Kernel Image", 269 | "RAMDisk Image", 270 | "Multi-File Image", 271 | "Firmware Image", 272 | "Script file", 273 | "Filesystem Image", 274 | "Binary Flat Device Tree Blob", 275 | "Kirkwood Boot Image", 276 | "Freescale IMXBoot Image", 277 | "Davinci UBL Image", 278 | "TI OMAP Config Header Image", 279 | "TI Davinci AIS Image", 280 | "OS Kernel Image (No load)", 281 | "Freescale PBL Boot Image", 282 | "Freescale MXSBoot Image", 283 | "TI Keystone GPHeader Image", 284 | "ATMEL ROM bootable Image", 285 | "Altera SOCFPGA Preloader", 286 | "x86 setup.bin Image", 287 | "LPC32XX Boot Image", 288 | "A list of typeless images", 289 | "Rockchip Boot Image", 290 | "Rockchip SD card", 291 | "Rockchip SPI image", 292 | "Xilinx Zynq Boot Image", 293 | "Xilinx ZynqMP Boot Image", 294 | "FPGA Image", 295 | "VYBRID .vyb Image", 296 | "TEE OS Image", 297 | "HABv4 IVT Image", 298 | "TI PMMC Firmware", 299 | "STM32 Image", 300 | "Altera SOCFPGA A10 Preloader", 301 | "MediaTek BootROM loadable Image", 302 | "Freescale IMX8MBoot Image", 303 | "Freescale IMX8Boot Image" 304 | }; 305 | 306 | 307 | /* 308 | * Compression Types 309 | * 310 | * The following are exposed to uImage header. 311 | * Do not change values for backward compatibility. 312 | */ 313 | enum IH_COMP : uint8_t { 314 | IH_COMP_NONE = 0, /* No Compression Used */ 315 | IH_COMP_GZIP, /* gzip Compression Used */ 316 | IH_COMP_BZIP2, /* bzip2 Compression Used */ 317 | IH_COMP_LZMA, /* lzma Compression Used */ 318 | IH_COMP_LZO, /* lzo Compression Used */ 319 | IH_COMP_LZ4, /* lz4 Compression Used */ 320 | 321 | IH_COMP_COUNT, 322 | }; 323 | 324 | const char * const enum_IH_COMP[IH_COMP_COUNT] = { 325 | "None", 326 | "GZip", 327 | "BZip2", 328 | "LZMA", 329 | "LZO", 330 | "LZ4" 331 | }; 332 | 333 | 334 | #define IH_MAGIC 0x27051956 /* Image Magic Number */ 335 | #define IH_MAGIC_LE 0x56190527 /* Image Magic Number */ 336 | #define IH_NMLEN 32 /* Image Name Length */ 337 | 338 | 339 | /* 340 | * Legacy format image header, 341 | * all data in network byte order (aka natural aka bigendian). 342 | */ 343 | typedef struct uimage_header { 344 | __be32 ih_magic; /* Image Header Magic Number */ 345 | __be32 ih_hcrc; /* Image Header CRC Checksum */ 346 | __be32 ih_time; /* Image Creation Timestamp */ 347 | __be32 ih_size; /* Image Data Size */ 348 | __be32 ih_load; /* Data Load Address */ 349 | __be32 ih_ep; /* Entry Point Address */ 350 | __be32 ih_dcrc; /* Image Data CRC Checksum */ 351 | IH_OS ih_os; /* Operating System */ 352 | IH_ARCH ih_arch; /* CPU architecture */ 353 | IH_TYPE ih_type; /* Image Type */ 354 | IH_COMP ih_comp; /* Compression Type */ 355 | char ih_name[IH_NMLEN]; /* Image Name */ 356 | } uimage_header_t, UIMG_HDR, *PUIMG_HDR; 357 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HWFW_GUI 2 | HuaWei ONT Firmware Editor - GUI 3 | 4 | Screenshots 5 | ------- 6 | 7 | ![PREVIEW](./Screenshots/SS_1.0.8_1.png) 8 | ![PREVIEW](./Screenshots/SS_1.0.3_2.png) 9 | ![PREVIEW](./Screenshots/SS_1.0.8_2.png) 10 | 11 | ChangeLog 12 | ------- 13 | ### 1.0.8 Beta Build 005 14 | - 修改导出子项目时,项目大小的判定规则 15 | - 修复删除子项目时崩溃的问题 16 | 17 | ### 1.0.8 Alpha Build 002 18 | - 增加编辑产品列表功能 19 | - 增加对R018, R019的子项目解析支持 20 | - 增加对V5固件的子项目对齐支持 21 | - Bug修复 22 | 23 | ### 1.0.4 Alpha Build 001 24 | - 增加浏览支持的产品型号功能 25 | 26 | ### 1.0.3 Alpha Build 003 27 | - 增加高级数据格式的编辑功能 28 | - 细节修复 29 | - 代码缩进优化 30 | 31 | Donate 32 | ------- 33 | 如果本软件对你有帮助,请考虑捐赠作者,以支持其继续开发! 34 | If the software is helpful to you, please consider donating the author to support its continued development! 35 | 36 | License 37 | ------- 38 | 39 | Copyright (C) 2019 csersoft 40 | 41 | This program is free software: you can redistribute it and/or modify 42 | it under the terms of the GNU General Public License as published by 43 | the Free Software Foundation, either version 3 of the License, or 44 | (at your option) any later version. 45 | 46 | This program is distributed in the hope that it will be useful, 47 | but WITHOUT ANY WARRANTY; without even the implied warranty of 48 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 49 | GNU General Public License for more details. 50 | 51 | You should have received a copy of the GNU General Public License 52 | along with this program. If not, see . 53 | -------------------------------------------------------------------------------- /Screenshots/SS_1.0.3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/Screenshots/SS_1.0.3_1.png -------------------------------------------------------------------------------- /Screenshots/SS_1.0.3_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/Screenshots/SS_1.0.3_2.png -------------------------------------------------------------------------------- /Screenshots/SS_1.0.3_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/Screenshots/SS_1.0.3_3.png -------------------------------------------------------------------------------- /Screenshots/SS_1.0.8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/Screenshots/SS_1.0.8_1.png -------------------------------------------------------------------------------- /Screenshots/SS_1.0.8_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csersoft/HWFW_GUI/20c7f69f6d6afbdbf5d80f6f72e114058f2d25e0/Screenshots/SS_1.0.8_2.png --------------------------------------------------------------------------------