├── .gitattributes ├── .gitignore ├── LICENSE ├── drvver ├── CMakeLists.txt └── drvver.c ├── findver ├── CMakeLists.txt └── findver.c └── hexfind ├── CMakeLists.txt └── findhex.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.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 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # MSTest test Results 20 | [Tt]est[Rr]esult*/ 21 | [Bb]uild[Ll]og.* 22 | 23 | #NUNIT 24 | *.VisualState.xml 25 | TestResult.xml 26 | 27 | # Build Results of an ATL Project 28 | [Dd]ebugPS/ 29 | [Rr]eleasePS/ 30 | dlldata.c 31 | 32 | *_i.c 33 | *_p.c 34 | *_i.h 35 | *.ilk 36 | *.meta 37 | *.obj 38 | *.pch 39 | *.pdb 40 | *.pgc 41 | *.pgd 42 | *.rsp 43 | *.sbr 44 | *.tlb 45 | *.tli 46 | *.tlh 47 | *.tmp 48 | *.tmp_proj 49 | *.log 50 | *.vspscc 51 | *.vssscc 52 | .builds 53 | *.pidb 54 | *.svclog 55 | *.scc 56 | 57 | # Chutzpah Test files 58 | _Chutzpah* 59 | 60 | # Visual C++ cache files 61 | ipch/ 62 | *.aps 63 | *.ncb 64 | *.opensdf 65 | *.sdf 66 | *.cachefile 67 | 68 | # Visual Studio profiler 69 | *.psess 70 | *.vsp 71 | *.vspx 72 | 73 | # TFS 2012 Local Workspace 74 | $tf/ 75 | 76 | # Guidance Automation Toolkit 77 | *.gpState 78 | 79 | # ReSharper is a .NET coding add-in 80 | _ReSharper*/ 81 | *.[Rr]e[Ss]harper 82 | *.DotSettings.user 83 | 84 | # JustCode is a .NET coding addin-in 85 | .JustCode 86 | 87 | # TeamCity is a build add-in 88 | _TeamCity* 89 | 90 | # DotCover is a Code Coverage Tool 91 | *.dotCover 92 | 93 | # NCrunch 94 | *.ncrunch* 95 | _NCrunch_* 96 | .*crunch*.local.xml 97 | 98 | # MightyMoose 99 | *.mm.* 100 | AutoTest.Net/ 101 | 102 | # Web workbench (sass) 103 | .sass-cache/ 104 | 105 | # Installshield output folder 106 | [Ee]xpress/ 107 | 108 | # DocProject is a documentation generator add-in 109 | DocProject/buildhelp/ 110 | DocProject/Help/*.HxT 111 | DocProject/Help/*.HxC 112 | DocProject/Help/*.hhc 113 | DocProject/Help/*.hhk 114 | DocProject/Help/*.hhp 115 | DocProject/Help/Html2 116 | DocProject/Help/html 117 | 118 | # Click-Once directory 119 | publish/ 120 | 121 | # Publish Web Output 122 | *.[Pp]ublish.xml 123 | *.azurePubxml 124 | 125 | # NuGet Packages Directory 126 | packages/ 127 | ## TODO: If the tool you use requires repositories.config uncomment the next line 128 | #!packages/repositories.config 129 | 130 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 131 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) 132 | !packages/build/ 133 | 134 | # Windows Azure Build Output 135 | csx/ 136 | *.build.csdef 137 | 138 | # Windows Store app package directory 139 | AppPackages/ 140 | 141 | # Others 142 | sql/ 143 | *.Cache 144 | ClientBin/ 145 | [Ss]tyle[Cc]op.* 146 | ~$* 147 | *~ 148 | *.dbmdl 149 | *.dbproj.schemaview 150 | *.pfx 151 | *.publishsettings 152 | node_modules/ 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | *.mdf 166 | *.ldf 167 | 168 | # Business Intelligence projects 169 | *.rdl.data 170 | *.bim.layout 171 | *.bim_*.settings 172 | 173 | # Microsoft Fakes 174 | FakesAssemblies/ 175 | 176 | # ========================= 177 | # Operating System Files 178 | # ========================= 179 | 180 | # OSX 181 | # ========================= 182 | 183 | .DS_Store 184 | .AppleDouble 185 | .LSOverride 186 | 187 | # Icon must ends with two \r. 188 | Icon 189 | 190 | # Thumbnails 191 | ._* 192 | 193 | # Files that might appear on external disk 194 | .Spotlight-V100 195 | .Trashes 196 | 197 | # Windows 198 | # ========================= 199 | 200 | # Windows image file caches 201 | Thumbs.db 202 | ehthumbs.db 203 | 204 | # Folder config file 205 | Desktop.ini 206 | 207 | # Recycle Bin used on file shares 208 | $RECYCLE.BIN/ 209 | 210 | # Windows Installer files 211 | *.cab 212 | *.msi 213 | *.msm 214 | *.msp 215 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /drvver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(drvver) 2 | SET(DV_SOURCES drvver.c) 3 | ADD_EXECUTABLE(drvver ${DV_SOURCES}) -------------------------------------------------------------------------------- /drvver/drvver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* Return codes */ 9 | #define ERR_SUCCESS 0 10 | #define ERR_NOT_FOUND 1 11 | #define ERR_FILE_OPEN 2 12 | #define ERR_FILE_READ 3 13 | #define ERR_INVALID_PARAMETER 4 14 | #define ERR_OUT_OF_MEMORY 5 15 | #define ERR_UNKNOWN_VERSION 6 16 | 17 | /* String BIT */ 18 | const uint8_t bitx86_pattern[] = { 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4C, 0x01 20 | }; 21 | 22 | /* Intel GOP Driver */ 23 | /* Search pattern: "Intel (R) GOP Driver" as Unicode string */ 24 | const uint8_t snb_pattern[] = { 25 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 26 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x53, 0x00 27 | }; 28 | const uint8_t ivb_pattern[] = { 29 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 30 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x49, 0x00 31 | }; 32 | 33 | const uint8_t gop_pattern[] = { 34 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 35 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x47, 0x00, 0x4F, 0x00, 0x50, 0x00, 36 | 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 0x69, 0x00, 0x76, 0x00, 0x65, 0x00, 37 | 0x72, 0x00 38 | }; 39 | 40 | const uint8_t crv_pattern[] = { 41 | 0x43, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00, 42 | 0x20, 0x00, 0x56, 0x00, 0x69, 0x00, 0x65, 0x00, 0x77, 0x00 43 | }; 44 | 45 | /* Offset and length of parts of version string */ 46 | #define GOP_VERSION_2_OFFSET 0x98 47 | #define GOP_VERSION_3_OFFSET 0xA0 48 | #define GOP_VERSION_HSW_OFFSET 0xC0 49 | #define GOP_VERSION_BRW_OFFSET 0xF4 50 | #define GOP_VERSION_VLV_OFFSET 0x88 51 | #define GOP_VERSION_CHV_OFFSET 0x88 52 | #define GOP_VERSION_SKL_OFFSET 0xAC 53 | #define GOP_MAJOR_LENGTH 4 54 | #define GOP_MINOR_LENGTH 4 55 | #define GOP_REVISION_LENGTH 8 56 | #define GOP_BUILD_LENGTH 10 57 | 58 | /* ASPEED GOP Driver */ 59 | /* Search pattern hwx string */ 60 | const uint8_t gop_ast_pattern[] = { 61 | 0x0F, 0x10, 0x0B, 0x0D, 0x10, 0x0B, 0x0C, 0x10, 0x00, 0x00, 0x00, 0x00, 62 | 0x00, 0x00, 0x00, 0x00 63 | }; 64 | const uint8_t goprom_ast_pattern[] = { 65 | 0x00, 0x50, 0x43, 0x49, 0x52 66 | }; 67 | 68 | /* Offset and length of parts of version string */ 69 | #define GOP_AST_VERSION_OFFSET 57 70 | #define GOP_AST_VERSION_LENGTH 0x3 71 | 72 | /* AMD GOP Driver */ 73 | const uint8_t amdgop_pattern[] = { 74 | 0x41, 0x00, 0x4D, 0x00, 0x44, 0x00, 0x20, 0x00, 0x47, 0x00, 0x4F, 0x00, 75 | 0x50, 0x00 76 | }; 77 | 78 | const uint8_t ms_cert_pattern[] = { 79 | 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x52, 0x6F, 80 | 0x6F, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 81 | 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, 0x79 82 | }; 83 | 84 | #define AMDGOP1_VERSION_OFFSET 0x2E 85 | #define AMDGOP2_VERSION_OFFSET 0x3E 86 | #define AMDGOP_VERSION_LENGTH 0x18 87 | #define AMDGOP_15_VERSION_LENGTH 0x14 88 | 89 | /* Intel RST Driver */ 90 | /* Search pattern: "Intel (R) RST 1" as Unicode string */ 91 | const uint8_t rst_pattern[] = { 92 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 93 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 94 | 0x20, 0x00, 0x31, 0x00 95 | }; 96 | 97 | /* Offset and length of parts of version string */ 98 | #define RST_VERSION_OFFSET 0x1A 99 | #define RST_VERSION_LENGTH 0x16 100 | 101 | /* Intel RSTe Driver */ 102 | /* Search pattern: "Intel (R) RSTe " as Unicode string */ 103 | const uint8_t rste_pattern[] = { 104 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x20, 0x00, 105 | 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x65, 0x00, 0x20, 0x00 106 | }; 107 | 108 | /* Intel RSTe sSATA Driver */ 109 | const uint8_t ssata_pattern[] = { 110 | 0x00, 0x00, 0x49, 0x00, 0x6E, 0x00 ,0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 111 | 0x20, 0x00, 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x65, 0x00, 0x20, 0x00, 112 | 0x73, 0x00, 0x53, 0x00, 0x41, 0x00, 0x54, 0x00, 0x41, 0x00, 0x20, 0x00, 113 | 0x43, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x72, 0x00, 0x6F, 0x00, 114 | 0x6C, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x72, 0x00 115 | }; 116 | 117 | /* Intel RSTe SCU Driver */ 118 | const uint8_t scu_pattern[] = { 119 | 0x00, 0x53, 0x00, 0x43, 0x00, 0x55, 0x00 120 | }; 121 | 122 | #define RSTE_VERSION_OFFSET 0x16 123 | #define RSTE_VERSION_LENGTH 0x16 124 | 125 | 126 | /* Intel RST NVMe Driver */ 127 | const uint8_t nvme_pattern[] = { 128 | 0x4E, 0x00, 0x56, 0x00, 0x4D, 0x00, 0x65, 0x00, 0x20, 0x00, 0x55, 0x00, 129 | 0x45, 0x00, 0x46, 0x00, 0x49, 0x00, 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 130 | 0x69, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00 131 | }; 132 | 133 | #define NVME_VERSION_OFFSET 0x16 134 | #define NVME_VERSION_LENGTH 0x14 135 | 136 | 137 | /* AMD RAID Driver */ 138 | /* Search pattern: "AMD Raid Channel" as Unicode string */ 139 | const uint8_t amdu_pattern[] = { 140 | 0x52, 0x00, 0x41, 0x00, 0x49, 0x00, 0x44, 0x00, 0x20, 0x00, 0x55, 0x00, 141 | 0x74, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x74, 0x00, 0x79, 0x00, 142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x52, 0x00, 143 | 0x65, 0x00, 0x76 144 | }; 145 | 146 | #define AMDR_VERSION_OFFSET 0x28 147 | #define AMDR_VERSION_LENGTH 0x10 148 | 149 | /* AMD Utility Driver */ 150 | /* Search pattern: "AMD Utility [Rev" as Unicode string */ 151 | const uint8_t amdr_pattern[] = { 152 | 0x41, 0x00, 0x4D, 0x00, 0x44, 0x00, 0x20, 0x00, 0x52, 0x00, 0x61, 0x00, 153 | 0x69, 0x00, 0x64, 0x00, 0x20, 0x00, 0x43, 0x00, 0x68, 0x00, 0x61, 0x00, 154 | 0x6E, 0x00, 0x6E, 0x00, 0x65, 0x00, 0x6C, 0x00 155 | }; 156 | 157 | #define AMDU_VERSION_OFFSET 0x2C 158 | #define AMDU_VERSION_LENGTH 0x10 159 | 160 | /* Intel LAN Driver */ 161 | /* Search pattern HEX String*/ 162 | const uint8_t lani_pattern[] = { 163 | 0x69, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66 164 | }; 165 | const uint8_t lanGB_pattern[] = { 166 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 167 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x47, 0x00, 0x69, 0x00, 0x67, 0x00, 168 | 0x61, 0x00, 0x62, 0x00, 0x69, 0x00, 0x74, 0x00, 0x20, 0x00, 0x25, 0x00, 169 | 0x31, 0x00, 0x64, 0x00 170 | }; 171 | const uint8_t lan40_pattern[] = { 172 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 173 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x34, 0x00, 0x30, 0x00, 0x47, 0x00, 174 | 0x62, 0x00, 0x45, 0x00 175 | }; 176 | const uint8_t lan10_pattern[] = { 177 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 178 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x31, 0x00, 0x30, 0x00, 0x47, 0x00, 179 | 0x62, 0x00, 0x45, 0x00, 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 0x69, 0x00, 180 | 0x76, 0x00, 0x65, 0x00, 0x72, 0x00 181 | }; 182 | const uint8_t lans_pattern[] = { 183 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 184 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x50, 0x00, 0x52, 0x00, 0x4F, 0x00, 185 | 0x2F, 0x00, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x20, 0x00, 186 | 0x47 187 | }; 188 | 189 | const uint8_t fcoe_pattern[] = { 190 | 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x28, 0x00, 191 | 0x52, 0x00, 0x29, 0x00, 0x20, 0x00, 0x46, 0x00, 0x43, 0x00, 0x6F, 0x00, 192 | 0x45, 0x00, 0x20, 0x00, 0x42, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x74, 0x00, 193 | 0x20, 0x00, 0x4E, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x76, 0x00, 194 | 0x65, 0x00, 0x20, 0x00, 0x55, 0x00, 0x45, 0x00, 0x46, 0x00, 0x49, 0x00, 195 | 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 0x69, 0x00, 0x76, 0x00, 0x65, 0x00, 196 | 0x72, 0x00, 0x20, 0x00, 0x76, 0x00 197 | }; 198 | 199 | const uint8_t fcoeh_pattern[] = { 200 | 0xAC, 0xB6, 0xB4, 0xB6, 0x76, 0xB1, 0x5E, 0x80 201 | }; 202 | 203 | #define LANI_VERSION_4_OFFSET 0x32 204 | #define LANI_VERSION_5_OFFSET 0x22 205 | #define LANI_VERSION_LENGTH 0x3 206 | #define FCOE_VERSION_OFFSET 0x4E 207 | #define FCOE_VERSION_LENGTH 0x12 208 | 209 | /* Marwell SATA Driver */ 210 | /* Search pattern is "Marwell Connection" as Unicode string */ 211 | const uint8_t msata_pattern[] = { 212 | 0x4D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x76, 0x00, 0x65, 0x00, 0x6C, 0x00, 213 | 0x6C, 0x00, 0x20, 0x00, 0x43, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6E, 0x00, 214 | 0x6E, 0x00, 0x65, 0x00, 0x6C, 0x00 215 | }; 216 | /* Marwell RAID Driver */ 217 | /* Search pattern is "Marwell Connection" as Unicode string */ 218 | const uint8_t msatar_pattern[] = { 219 | 0x20, 0x00, 0x52, 0x00, 0x41, 0x00, 0x49, 0x00, 0x44, 0x00, 0x20 220 | }; 221 | 222 | #define MSATA_VERSION_OFFSET 56 223 | #define MSATA_VERSION_LENGTH 0x4 224 | 225 | /* Realtek LAN Driver */ 226 | /* Search pattern HEX String*/ 227 | const uint8_t lanrtk_pattern[] = { 228 | 0x52, 0x00, 0x65, 0x00, 0x61, 0x00, 0x6C, 0x00, 229 | 0x74, 0x00, 0x65, 0x00, 0x6B, 0x00, 0x20, 0x00, 230 | 0x55, 0x00, 0x45, 0x00, 0x46, 0x00, 0x49, 0x00, 231 | 0x20, 0x00, 0x55, 0x00, 0x4E, 0x00, 0x44, 0x00, 232 | 0x49, 0x00, 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 233 | 0x69, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00 234 | }; 235 | const uint8_t lanr_new_pattern[] = { 236 | 0x01, 0xB2, 0x38, 0x78, 0x81, 0x43, 0x9B, 0x43 237 | }; 238 | const uint8_t lanr_old_pattern[] = { 239 | 0x04, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00 240 | }; 241 | 242 | /* Broadcom LAN Driver */ 243 | /* Search pattern HEX String*/ 244 | const uint8_t lanb_pattern[] = { 245 | 0x55, 0x4E, 0x44, 0x49, 0x5F, 0x56, 0x45, 0x52 246 | }; 247 | 248 | #define LANB_VERSION_14_OFFSET 0x11A 249 | #define LANB_VERSION_15_OFFSET 0x12A 250 | #define LANB_VERSION_16_OFFSET 0x16A 251 | #define LANB_VERSION_16_1_OFFSET 0x1CA 252 | #define LANB_VERSION_LENGTH 0x3 253 | 254 | /* Intel CPU Microcode */ 255 | /* Search pattern HEX String*/ 256 | const uint8_t icpuskls_pattern[] = { 257 | 0x01, 0x00, 0x00, 0x00, 0xE3, 0x06, 0x05, 0x00, 0x00, 0x00 258 | }; 259 | const uint8_t icpuhe_pattern[] = { 260 | 0x01, 0x00, 0x00, 0x00, 0xF2, 0x06, 0x03, 0x00, 0x00, 0x00 261 | }; 262 | const uint8_t icpub_pattern[] = { 263 | 0x01, 0x00, 0x00, 0x00, 0x71, 0x06, 0x04, 0x00, 0x00, 0x00 264 | }; 265 | const uint8_t icpuh_pattern[] = { 266 | 0x01, 0x00, 0x00, 0x00, 0xC3, 0x06, 0x03, 0x00, 0x00, 0x00 267 | }; 268 | const uint8_t icpui_pattern[] = { 269 | 0x01, 0x00, 0x00, 0x00, 0xA9, 0x06, 0x03, 0x00, 0x00, 0x00 270 | }; 271 | const uint8_t icpus_pattern[] = { 272 | 0x01, 0x00, 0x00, 0x00, 0xA7, 0x06, 0x02, 0x00, 0x00, 0x00 273 | }; 274 | const uint8_t icpusnbe6_pattern[] = { 275 | 0x01, 0x00, 0x00, 0x00, 0xD6, 0x06, 0x02, 0x00, 0x00, 0x00 276 | }; 277 | const uint8_t icpusnbe_pattern[] = { 278 | 0x01, 0x00, 0x00, 0x00, 0xD7, 0x06, 0x02, 0x00, 0x00, 0x00 279 | }; 280 | const uint8_t icpuivbe_pattern[] = { 281 | 0x01, 0x00, 0x00, 0x00, 0xE4, 0x06, 0x03, 0x00, 0x00, 0x00 282 | }; 283 | const uint8_t icpuivbe7_pattern[] = { 284 | 0x01, 0x00, 0x00, 0x00, 0xE7, 0x06, 0x03, 0x00, 0x00, 0x00 285 | }; 286 | 287 | #define CPU_VERSION_OFFSET 0x4C 288 | #define CPU_VERSION_LENGTH 0x1 289 | 290 | /* Implementation of GNU memmem function using Boyer-Moore-Horspool algorithm 291 | * Returns pointer to the beginning of found pattern of NULL if not found */ 292 | uint8_t* find_pattern(uint8_t* begin, uint8_t* end, const uint8_t* pattern, size_t plen) 293 | { 294 | size_t scan = 0; 295 | size_t bad_char_skip[256]; 296 | size_t last; 297 | size_t slen; 298 | 299 | if (plen == 0 || !begin || !pattern || !end || end <= begin) 300 | return NULL; 301 | 302 | slen = end - begin; 303 | 304 | for (scan = 0; scan <= 255; scan++) 305 | bad_char_skip[scan] = plen; 306 | 307 | last = plen - 1; 308 | 309 | for (scan = 0; scan < last; scan++) 310 | bad_char_skip[pattern[scan]] = last - scan; 311 | 312 | while (slen >= plen) 313 | { 314 | for (scan = last; begin[scan] == pattern[scan]; scan--) 315 | if (scan == 0) 316 | return begin; 317 | 318 | slen -= bad_char_skip[begin[last]]; 319 | begin += bad_char_skip[begin[last]]; 320 | } 321 | 322 | return NULL; 323 | } 324 | 325 | /* Entry point */ 326 | int main(int argc, char* argv[]) 327 | { 328 | FILE* file; 329 | uint8_t* buffer; 330 | uint8_t* end; 331 | uint8_t* found; 332 | uint8_t* check; 333 | wchar_t* build; 334 | long filesize; 335 | long read; 336 | char *strb; 337 | char mnr; 338 | 339 | if (argc < 2) 340 | { 341 | printf("drvver v0.19.10\n"); 342 | printf("Reads versions from input EFI-file\n"); 343 | printf("Usage: drvver DRIVERFILE\n\n"); 344 | printf("Support:\n" 345 | "GOP driver Intel, AMD, ASPEED.\n" 346 | "SATA driver Intel, AMD, Marvell\n" 347 | "LAN driver Intel, Realtek, Broadcom\n" 348 | ); 349 | return ERR_INVALID_PARAMETER; 350 | } 351 | 352 | /* Opening file */ 353 | file = fopen(argv[1], "rb"); 354 | if(!file) 355 | { 356 | printf("File can't be opened.\n"); 357 | return ERR_FILE_OPEN; 358 | } 359 | 360 | /* Determining file size */ 361 | fseek(file, 0, SEEK_END); 362 | filesize = ftell(file); 363 | fseek(file, 0, SEEK_SET); 364 | 365 | /* Allocating memory for buffer */ 366 | buffer = (uint8_t*)malloc(filesize); 367 | if (!buffer) 368 | { 369 | printf("Can't allocate memory for file contents.\n"); 370 | return ERR_OUT_OF_MEMORY; 371 | } 372 | 373 | /* Reading whole file to buffer */ 374 | read = fread((void*)buffer, sizeof(char), filesize, file); 375 | if (read != filesize) 376 | { 377 | printf("Can't read file.\n"); 378 | return ERR_FILE_READ; 379 | } 380 | 381 | 382 | /* Searching for GOP pattern in file */ 383 | end = buffer + filesize - 1; 384 | if (find_pattern(buffer, end, bitx86_pattern, sizeof(bitx86_pattern))) 385 | strb=" x86"; 386 | else 387 | strb=""; 388 | 389 | found = find_pattern(buffer, end, gop_pattern, sizeof(gop_pattern)); 390 | if (found) 391 | { 392 | /* Checking for version 2 */ 393 | if (find_pattern(buffer, end, snb_pattern, sizeof(snb_pattern))) 394 | { 395 | check = found + GOP_VERSION_2_OFFSET; 396 | if ((check[0] == '2') || (check[0] == 'C')) 397 | { 398 | check += GOP_MAJOR_LENGTH; 399 | check += GOP_MINOR_LENGTH; 400 | if ((check[2] == 0x2E) || (check[2] == 0x00) || (check[10] != 0x00)) 401 | check += GOP_REVISION_LENGTH; 402 | if (check[0] == 'L') 403 | check -= 0x20; 404 | build = (wchar_t*) check; 405 | /* Printing the version found */ 406 | wprintf(L" EFI GOP Driver SandyBridge - 2.0.%s\n", build); 407 | 408 | return ERR_SUCCESS; 409 | } 410 | } 411 | 412 | /* Checking for version 3 */ 413 | if (find_pattern(buffer, end, ivb_pattern, sizeof(ivb_pattern))) 414 | { 415 | check = found + GOP_VERSION_3_OFFSET; 416 | if ((check[0] == '3') || (check[0] == 'L')) 417 | { 418 | check += GOP_MAJOR_LENGTH; 419 | check += GOP_MINOR_LENGTH; 420 | if ((check[2] == 0x2E) || (check[2] == 0x00) || (check[10] != 0x00)) 421 | check += GOP_REVISION_LENGTH; 422 | if (check[0] == 0x45) 423 | check -= 0x30; 424 | build = (wchar_t*) check; 425 | /* Printing the version found */ 426 | wprintf(L" EFI GOP Driver IvyBridge - 3.0.%s\n", build); 427 | 428 | return ERR_SUCCESS; 429 | } 430 | } 431 | 432 | /* Checking for version 5 Haswell*/ 433 | check = found + GOP_VERSION_HSW_OFFSET; 434 | if ((check[0] == '5') || (check[0] == 'H') || ((check[0] == 0x06) && (check[1] == 0x0A))) 435 | { 436 | check += GOP_MAJOR_LENGTH; 437 | check += GOP_MINOR_LENGTH; 438 | if (check[-2] == 'I') 439 | check -= 0x48; 440 | else if ((check[0] == 0x1A) && (check[1] == 0x0A) && (check[40] == '5')) 441 | check = check + 56; 442 | build = (wchar_t*) check; 443 | 444 | /* Printing the version found */ 445 | wprintf(L" EFI GOP Driver Haswell - 5.0.%s\n", build); 446 | 447 | return ERR_SUCCESS; 448 | 449 | } 450 | 451 | /* Checking for version 5.5 Broadwell*/ 452 | check = found + GOP_VERSION_BRW_OFFSET; 453 | if (check[0] == '5') 454 | { 455 | check += GOP_MAJOR_LENGTH; 456 | build = (wchar_t*) check; 457 | 458 | /* Printing the version found */ 459 | wprintf(L" EFI GOP Driver Broadwell - 5.5.%s\n", build); 460 | 461 | return ERR_SUCCESS; 462 | } 463 | 464 | /* Checking for version 6 CloverView*/ 465 | if (find_pattern(buffer, end, crv_pattern, sizeof(crv_pattern))) 466 | { 467 | check = found; 468 | if ((check[-28] == '6') && (check[-26] == '.') && (check[-24] == '0')) 469 | check -= 0x28; 470 | if ((check[-40] == '6') && (check[-38] == '.') && (check[-36] == '0')) 471 | check += 0x80; 472 | 473 | build = (wchar_t*) check; 474 | 475 | /* Printing the version found */ 476 | wprintf(L" EFI GOP Driver CloverView - 6.0.%s%S\n", build, strb); 477 | 478 | return ERR_SUCCESS; 479 | } 480 | 481 | /* Checking for version ValleyView*/ 482 | check = found + GOP_VERSION_VLV_OFFSET; 483 | if (check[0] == '7') 484 | { 485 | if ((check[4] == '0') && (check[8] == '1')) 486 | { mnr = '0'; 487 | check = check + 8;} 488 | else if (((check[4] == '1') && (check[8] == '1')) || 489 | ((check[4] == 0x00) && (check[8] == '1') && (check[20] == 0xFF))) 490 | { mnr = '1'; 491 | check = check + 8;} 492 | else if ((check[4] == '1') && (check[16] == 0xFF)) 493 | { mnr = '1'; 494 | check = check + 4;} 495 | else if (((check[4] == '2') && (check[8] == '1')) || 496 | ((check[4] == 0x00) && (check[8] == '1') && (check[20] == 0x00))) 497 | { mnr = '2'; 498 | check = check + 8;} 499 | else if ((check[4] == '1') && (check[16] == 0x00)) 500 | { mnr = '2'; 501 | check = check + 4;} 502 | 503 | build = (wchar_t*) check; 504 | wprintf(L" EFI GOP Driver ValleyView - 7.%c.%s%S\n", mnr, build, strb); 505 | return ERR_SUCCESS; 506 | } 507 | 508 | /* Checking for version 8 CherryView*/ 509 | check = found + GOP_VERSION_CHV_OFFSET; 510 | if (check[0] == '8') 511 | { 512 | if (check[4] != '1') 513 | { 514 | check += 0x4; 515 | } 516 | check += GOP_MAJOR_LENGTH; 517 | build = (wchar_t*) check; 518 | 519 | /* Printing the version found */ 520 | wprintf(L" EFI GOP Driver CherryView - 8.0.%s\n", build); 521 | 522 | return ERR_SUCCESS; 523 | } 524 | 525 | /* Checking for version 9 SkyLake*/ 526 | check = found + GOP_VERSION_SKL_OFFSET; 527 | { 528 | if (((check[0] == '9') && (check[4] == '1')) || 529 | ((check[-4] == '9') && (check[4] == '1'))) 530 | check += 4; 531 | else if ((check[8] == '9') && (check[12] == '1')) 532 | check += 12; 533 | else if ((check[52] == '9') && (check[56] == '0') && (check[60] == '1')) 534 | check += 60; 535 | 536 | build = (wchar_t*) check; 537 | 538 | /* Printing the version found */ 539 | wprintf(L" EFI GOP Driver SkyLake - 9.0.%s\n", build); 540 | 541 | return ERR_SUCCESS; 542 | } 543 | 544 | /* Unknown version */ 545 | printf (" Unknown version GOP Driver\n"); 546 | return ERR_UNKNOWN_VERSION; 547 | } 548 | 549 | /* Searching for AMD GOP pattern in file */ 550 | found = find_pattern(buffer, end, amdgop_pattern, sizeof(amdgop_pattern)); 551 | if (found) 552 | { 553 | check = found; 554 | if ((check[46] == '1') && (check[66] == '.')) 555 | { 556 | found += AMDGOP1_VERSION_OFFSET; 557 | build = (wchar_t*) found; 558 | build[AMDGOP_15_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 559 | } 560 | else if ((check[46] == '1') && (check[66] != '.')) 561 | { 562 | found += AMDGOP1_VERSION_OFFSET; 563 | build = (wchar_t*) found; 564 | build[AMDGOP_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 565 | } 566 | else if ((check[46] == 'v') && (check[82] == '.')) 567 | { 568 | found += AMDGOP2_VERSION_OFFSET; 569 | build = (wchar_t*) found; 570 | build[AMDGOP_15_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 571 | } 572 | else 573 | { 574 | found += AMDGOP2_VERSION_OFFSET; 575 | build = (wchar_t*) found; 576 | build[AMDGOP_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 577 | } 578 | 579 | /* Printing the version found */ 580 | if (find_pattern(buffer, end, ms_cert_pattern, sizeof(ms_cert_pattern))) 581 | wprintf(L" EFI AMD GOP Driver - %s_signed\n", build); 582 | else 583 | wprintf(L" EFI AMD GOP Driver - %s\n", build); 584 | 585 | return ERR_SUCCESS; 586 | } 587 | 588 | /* Searching for ASPEED GOP pattern in file */ 589 | found = find_pattern(buffer, end, gop_ast_pattern, sizeof(gop_ast_pattern)); 590 | if (found) 591 | { 592 | if ((found[GOP_AST_VERSION_OFFSET] == 37)) 593 | {check = found + GOP_AST_VERSION_OFFSET; check[-1] = 0x08; check[0] = 0x93; check[1] = 0x00;} 594 | else if ((found[GOP_AST_VERSION_OFFSET] == 33)) 595 | {check = found + GOP_AST_VERSION_OFFSET; check[-1] = 0x00; check[0] = 0x96; check[1] = 0x00;} 596 | else if ((found[GOP_AST_VERSION_OFFSET] == 144)) 597 | {check = found + GOP_AST_VERSION_OFFSET; check[-1] = 0x06; check[0] = 0x97; check[1] = 0x00;} 598 | else 599 | check = found + GOP_AST_VERSION_OFFSET; 600 | 601 | /* Printing the version found */ 602 | found = find_pattern(buffer, end, goprom_ast_pattern, sizeof(goprom_ast_pattern)); 603 | if (found) 604 | printf(" EFI GOP-in-OROM ASPEED - %x.%02x.%02x\n", check[+1], check[0], check[-1]); 605 | else 606 | printf(" EFI GOP ASPEED - %x.%02x.%02x\n", check[+1], check[0], check[-1]); 607 | 608 | return ERR_SUCCESS; 609 | } 610 | 611 | /* Searching for RST pattern in file */ 612 | found = find_pattern(buffer, end, rst_pattern, sizeof(rst_pattern)); 613 | if (found) 614 | { 615 | found += RST_VERSION_OFFSET; 616 | build = (wchar_t*) found; 617 | build[RST_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 618 | /* Printing the version found */ 619 | wprintf(L" EFI IRST RAID for SATA - %s\n", build); 620 | 621 | return ERR_SUCCESS; 622 | } 623 | 624 | /* Searching for NVMe pattern in file */ 625 | found = find_pattern(buffer, end, nvme_pattern, sizeof(nvme_pattern)); 626 | if (found) 627 | { 628 | found -= NVME_VERSION_OFFSET; 629 | build = (wchar_t*) found; 630 | build[NVME_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 631 | /* Printing the version found */ 632 | wprintf(L" EFI IRST NVMe Driver - %s\n", build); 633 | 634 | return ERR_SUCCESS; 635 | } 636 | 637 | /* Searching for AMD RAID pattern in file */ 638 | found = find_pattern(buffer, end, amdr_pattern, sizeof(amdr_pattern)); 639 | if (found) 640 | { 641 | found += AMDR_VERSION_OFFSET; 642 | build = (wchar_t*) found; 643 | build[AMDR_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 644 | /* Printing the version found */ 645 | wprintf(L" EFI AMD RAID - %s\n", build); 646 | 647 | return ERR_SUCCESS; 648 | } 649 | 650 | /* Searching for AMD Utilty pattern in file */ 651 | found = find_pattern(buffer, end, amdu_pattern, sizeof(amdu_pattern)); 652 | if (found) 653 | { 654 | check = found; 655 | found += AMDU_VERSION_OFFSET; 656 | build = (wchar_t*) found; 657 | build[AMDU_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 658 | /* Printing the version found */ 659 | if (check[52] != ']') 660 | wprintf(L" EFI AMD Utility - %s\n", build); 661 | else 662 | printf (" EFI AMD Utility - %c.0.0.%c%c\n", check[44], check[48], check[50]); 663 | return ERR_SUCCESS; 664 | } 665 | 666 | /* Searching for RSTe pattern in file */ 667 | found = find_pattern(buffer, end, rste_pattern, sizeof(rste_pattern)); 668 | if (found) 669 | { 670 | found += RSTE_VERSION_OFFSET; 671 | build = (wchar_t*) found; 672 | build[RSTE_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 673 | 674 | /* Printing the version found */ 675 | if (find_pattern(buffer, end, scu_pattern, sizeof(scu_pattern))) 676 | wprintf(L" EFI IRSTe RAID for SCU - %s\n", build); 677 | else 678 | if (find_pattern(buffer, end, ssata_pattern, sizeof(ssata_pattern))) 679 | wprintf(L" EFI IRSTe RAID for sSATA - %s\n", build); 680 | else 681 | wprintf(L" EFI IRSTe RAID for SATA - %s\n", build); 682 | return ERR_SUCCESS; 683 | } 684 | 685 | /* Searching for MSATA pattern in file */ 686 | found = find_pattern(buffer, end, msata_pattern, sizeof(msata_pattern)); 687 | if (found) 688 | { 689 | check = found + MSATA_VERSION_OFFSET; 690 | 691 | /* Printing the version found */ 692 | found = find_pattern(buffer, end, msatar_pattern, sizeof(msatar_pattern)); 693 | if (found) 694 | printf(" EFI Marvell SATA RAID - %x.%x.%x.%04x\n", (check[3] >> 4), (check[3] & 0x0F), check[2], *(uint16_t*)check); 695 | else 696 | printf(" EFI Marvell SATA AHCI - %x.%x.%x.%04x\n", (check[3] >> 4), (check[3] & 0x0F), check[2], *(uint16_t*)check); 697 | 698 | return ERR_SUCCESS; 699 | } 700 | 701 | /* Searching for LANI pattern in file */ 702 | found = find_pattern(buffer, end, lani_pattern, sizeof(lani_pattern)); 703 | if (found) 704 | { 705 | /* Checking for version 4 */ 706 | if (found[LANI_VERSION_4_OFFSET] == 4) 707 | check = found + LANI_VERSION_4_OFFSET; 708 | /* Checking for version 5 or 6 */ 709 | else if (found[LANI_VERSION_5_OFFSET] == 3 || found[LANI_VERSION_5_OFFSET] == 4 || 710 | found[LANI_VERSION_5_OFFSET] == 5 || found[LANI_VERSION_5_OFFSET] == 6 || 711 | ((found[LANI_VERSION_5_OFFSET-3] == 0) && (found[LANI_VERSION_5_OFFSET-2] == 1) && 712 | (found[LANI_VERSION_5_OFFSET-1] == 0) && (found[LANI_VERSION_5_OFFSET] == 0) && 713 | (found[LANI_VERSION_5_OFFSET+1] == 0) && (found[LANI_VERSION_5_OFFSET+30] == 0x2F)) || 714 | found[LANI_VERSION_5_OFFSET] != 0) 715 | check = found + LANI_VERSION_5_OFFSET; 716 | else if (find_pattern(buffer, end, lanGB_pattern, sizeof(lanGB_pattern))) 717 | { 718 | if (found[LANI_VERSION_5_OFFSET] == 0) 719 | check = found + LANI_VERSION_5_OFFSET; 720 | } 721 | else if (find_pattern(buffer, end, lan40_pattern, sizeof(lan40_pattern))) 722 | { 723 | if (found[LANI_VERSION_5_OFFSET] == 0) 724 | check = found - 30; 725 | } 726 | else { 727 | printf(" Unknown Intel LAN version.\n"); 728 | return ERR_NOT_FOUND; 729 | } 730 | 731 | /* Printing the version found */ 732 | 733 | if (find_pattern(buffer, end, lan40_pattern, sizeof(lan40_pattern))) 734 | printf(" EFI Intel 40GbE UNDI - %x.%x.%02x\n", check[0], check[-1], check[-2]); 735 | else if (find_pattern(buffer, end, lan10_pattern, sizeof(lan10_pattern))) 736 | printf(" EFI Intel 10GbE UNDI - %x.%x.%02x\n", check[0], check[-1], check[-2]); 737 | else if (find_pattern(buffer, end, lans_pattern, sizeof(lans_pattern))) 738 | printf(" EFI Intel PRO/Server UNDI - %x.%x.%02x\n", check[0], check[-1], check[-2]); 739 | else if (find_pattern(buffer, end, lanGB_pattern, sizeof(lanGB_pattern))) 740 | printf(" EFI Intel Gigabit UNDI - %x.%x.%02x\n", check[0], check[-1], check[-2]); 741 | else 742 | printf(" EFI Intel PRO/1000 UNDI - %x.%x.%02x\n", check[0], check[-1], check[-2]); 743 | 744 | return ERR_SUCCESS; 745 | } 746 | 747 | /* Searching for FCoE pattern in file */ 748 | found = find_pattern(buffer, end, fcoe_pattern, sizeof(fcoe_pattern)); 749 | if (found) 750 | { 751 | found += FCOE_VERSION_OFFSET; 752 | check = (found); 753 | if (check[0] == '1') 754 | { 755 | build = (wchar_t*) found; 756 | build[FCOE_VERSION_LENGTH/sizeof(wchar_t)] = 0x00; 757 | /* Printing the version found */ 758 | wprintf(L" EFI Intel FCoE Boot - %s\n", build); 759 | return ERR_SUCCESS; 760 | } 761 | else if (find_pattern(buffer, end, fcoeh_pattern, sizeof(fcoeh_pattern))) 762 | { 763 | check = (find_pattern(buffer, end, fcoeh_pattern, sizeof(fcoeh_pattern))) + 35; 764 | if (check[0] == 1) 765 | { 766 | printf(" EFI Intel FCoE Boot - %d.%d.%02d\n", check[0], check[-1],check[-2]); 767 | return ERR_SUCCESS;} 768 | } 769 | printf(" Unknown Intel FCoE version.\n"); 770 | return ERR_NOT_FOUND; 771 | } 772 | 773 | /* Searching for LANB pattern in file */ 774 | found = find_pattern(buffer, end, lanb_pattern, sizeof(lanb_pattern)); 775 | if (found) 776 | { 777 | /* Checking for version 14 */ 778 | if (found[LANB_VERSION_14_OFFSET] == 14) 779 | check = found + LANB_VERSION_14_OFFSET; 780 | /* Checking for version 15 */ 781 | else if (found[LANB_VERSION_15_OFFSET] == 15) 782 | check = found + LANB_VERSION_15_OFFSET; 783 | /* Checking for version 16 */ 784 | else if (found[LANB_VERSION_16_OFFSET] == 16) 785 | check = found + LANB_VERSION_16_OFFSET; 786 | else if (found[LANB_VERSION_16_1_OFFSET] == 16) 787 | check = found + LANB_VERSION_16_1_OFFSET; 788 | else { 789 | printf(" Unknown Broadcom LAN version.\n"); 790 | return ERR_NOT_FOUND; 791 | } 792 | /* Printing the version found */ 793 | printf(" EFI Broadcom UNDI - %d.%d.%d\n", check[0], check[-1], check[-2]); 794 | return ERR_SUCCESS; 795 | } 796 | 797 | /* Searching for LAN Realtek pattern in new file */ 798 | found = find_pattern(buffer, end, lanrtk_pattern, sizeof(lanrtk_pattern)); 799 | if (found) 800 | { 801 | if (find_pattern(buffer, end, lanr_new_pattern, sizeof(lanr_new_pattern))) 802 | { 803 | check = find_pattern(buffer, end, lanr_new_pattern, sizeof(lanr_new_pattern)); 804 | if (check[-22] == 0x20) 805 | check = check - 22; 806 | else if ((check[-23] == 0x20) || (check[-23] == 0x30)) 807 | check = check - 23; 808 | else if (check[-11] == 0x20) 809 | check = check - 11; 810 | else { 811 | printf(" Unknown Realtek LAN version.\n"); 812 | return ERR_NOT_FOUND;} 813 | } 814 | 815 | else if (find_pattern(buffer, end, lanr_old_pattern, sizeof(lanr_old_pattern))) 816 | { 817 | check = find_pattern(buffer, end, lanr_old_pattern, sizeof(lanr_old_pattern)); 818 | if ((check[-30] == 0x20) || (check[-30] != 0x2F) || 819 | (check[-29] != 0x00) || (check[-31] == 0x00)) 820 | check = check - 30; 821 | else if (check[-18] == 0x20) 822 | check = check - 18; 823 | else { 824 | printf(" Unknown Realtek LAN version.\n"); 825 | return ERR_NOT_FOUND;} 826 | } 827 | 828 | /* Printing the version found */ 829 | if (check[-2] != 0) { 830 | printf(" EFI Realtek UNDI - %x.%03X %X%s\n", check[0] >> 4, check[-1], check[-2], strb); 831 | return ERR_SUCCESS;} 832 | else { 833 | printf(" EFI Realtek UNDI - %x.%03X%s\n", check[0] >> 4, check[-1], strb); 834 | return ERR_SUCCESS;} 835 | 836 | 837 | 838 | } 839 | 840 | /* Searching for CPU pattern LGA1150 */ 841 | found = find_pattern(buffer, end, icpub_pattern, sizeof(icpub_pattern)); 842 | if (found) 843 | { 844 | check = found - CPU_VERSION_OFFSET; 845 | printf(" CPU Microcode 040671 BDW - %02X\n", check[0]); 846 | } 847 | found = find_pattern(buffer, end, icpuh_pattern, sizeof(icpuh_pattern)); 848 | if (found) 849 | { 850 | check = found - CPU_VERSION_OFFSET; 851 | printf(" CPU Microcode 0306C3 HSW - %02X\n", check[0]); 852 | return ERR_SUCCESS; 853 | } 854 | 855 | /* Searching for CPU pattern LGA1155 */ 856 | found = find_pattern(buffer, end, icpui_pattern, sizeof(icpui_pattern)); 857 | if (found) 858 | { 859 | check = found - CPU_VERSION_OFFSET; 860 | printf(" CPU Microcode 0306A9 IVB - %02X\n", check[0]); 861 | } 862 | found = find_pattern(buffer, end, icpus_pattern, sizeof(icpus_pattern)); 863 | if (found) 864 | { 865 | check = found - CPU_VERSION_OFFSET; 866 | printf(" CPU Microcode 0206A7 SNB - %02X\n", check[0]); 867 | return ERR_SUCCESS; 868 | } 869 | 870 | /* Searching for CPU pattern LGA2011 */ 871 | found = find_pattern(buffer, end, icpuivbe7_pattern, sizeof(icpuivbe7_pattern)); 872 | if (found) 873 | { 874 | check = found - CPU_VERSION_OFFSET; 875 | printf(" CPU Microcode 0306E7 IVB-E - %X%02X\n", check[1], check[0]); 876 | } 877 | found = find_pattern(buffer, end, icpuivbe_pattern, sizeof(icpuivbe_pattern)); 878 | if (found) 879 | { 880 | check = found - CPU_VERSION_OFFSET; 881 | printf(" CPU Microcode 0306E4 IVB-E - %X%02X\n", check[1], check[0]); 882 | } 883 | found = find_pattern(buffer, end, icpusnbe_pattern, sizeof(icpusnbe_pattern)); 884 | if (found) 885 | { 886 | check = found - CPU_VERSION_OFFSET; 887 | printf(" CPU Microcode 0206D7 SNB-E - %X%02X\n", check[1], check[0]); 888 | } 889 | found = find_pattern(buffer, end, icpusnbe6_pattern, sizeof(icpusnbe6_pattern)); 890 | if (found) 891 | { 892 | check = found - CPU_VERSION_OFFSET; 893 | printf(" CPU Microcode 0206D6 SNB-E - %X%02X\n", check[1], check[0]); 894 | return ERR_SUCCESS; 895 | } 896 | 897 | /* Searching for CPU pattern LGA2011v3 */ 898 | found = find_pattern(buffer, end, icpuhe_pattern, sizeof(icpuhe_pattern)); 899 | if (found) 900 | { 901 | check = found - CPU_VERSION_OFFSET; 902 | printf(" CPU Microcode 0306F2 HSW-E - %02X\n", check[0]); 903 | return ERR_SUCCESS; 904 | } 905 | 906 | /* Searching for CPU pattern LGA1151 */ 907 | found = find_pattern(buffer, end, icpuskls_pattern, sizeof(icpuskls_pattern)); 908 | if (found) 909 | { 910 | check = found - CPU_VERSION_OFFSET; 911 | printf(" CPU Microcode 0506E3 SKL-S - %02X\n", check[0]); 912 | return ERR_SUCCESS; 913 | } 914 | 915 | return ERR_NOT_FOUND; 916 | } 917 | -------------------------------------------------------------------------------- /findver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(findver) 2 | SET(FV_SOURCES findver.c) 3 | ADD_EXECUTABLE(findver ${FV_SOURCES}) -------------------------------------------------------------------------------- /findver/findver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* Return codes */ 8 | #define ERR_SUCCESS 0 9 | #define ERR_NOT_FOUND 1 10 | #define ERR_FILE_OPEN 2 11 | #define ERR_FILE_READ 3 12 | #define ERR_INVALID_PARAMETER 4 13 | #define ERR_OUT_OF_MEMORY 5 14 | #define ERR_UNKNOWN_VERSION 6 15 | #define ERR_UNKNOWN_OPTION 7 16 | 17 | /* Implementation of GNU memmem function using Boyer-Moore-Horspool algorithm 18 | * Returns pointer to the beginning of found pattern or NULL if not found */ 19 | uint8_t* find_pattern(uint8_t* begin, uint8_t* end, 20 | const uint8_t* pattern, size_t plen) 21 | { 22 | size_t scan = 0; 23 | size_t bad_char_skip[256]; 24 | size_t last; 25 | size_t slen; 26 | 27 | if (plen == 0 || !begin || !pattern || !end || end <= begin) 28 | return NULL; 29 | 30 | slen = end - begin; 31 | 32 | for (scan = 0; scan <= 255; scan++) 33 | bad_char_skip[scan] = plen; 34 | 35 | last = plen - 1; 36 | 37 | for (scan = 0; scan < last; scan++) 38 | bad_char_skip[pattern[scan]] = last - scan; 39 | 40 | while (slen >= plen) 41 | { 42 | for (scan = last; begin[scan] == pattern[scan]; scan--) 43 | if (scan == 0) 44 | return begin; 45 | 46 | slen -= bad_char_skip[begin[last]]; 47 | begin += bad_char_skip[begin[last]]; 48 | } 49 | 50 | return NULL; 51 | } 52 | 53 | /* Converts ASCII-string to hexadecimal pattern */ 54 | uint8_t read_pattern(const char* string, uint8_t* pattern[], size_t* length) 55 | { 56 | size_t i; 57 | const char* current; 58 | char buf[3]; 59 | 60 | buf[2] = 0; 61 | 62 | *length = strlen(string); 63 | if (*length % 2) 64 | return ERR_INVALID_PARAMETER; 65 | 66 | *length /= 2; 67 | 68 | *pattern = (uint8_t*) malloc(*length); 69 | 70 | for (current = string, i = 0; i < *length; i++) 71 | { 72 | buf[0] = *current++; 73 | buf[1] = *current++; 74 | 75 | if (!isxdigit(buf[0]) || !isxdigit(buf[1])) 76 | return ERR_INVALID_PARAMETER; 77 | else 78 | (*pattern)[i] = (uint8_t) strtoul(buf, NULL, 16); 79 | } 80 | 81 | return ERR_SUCCESS; 82 | } 83 | 84 | uint8_t print_version(const char* prefix, uint8_t* buffer, uint8_t* end, 85 | const uint8_t* pattern, const uint32_t size, 86 | const long offset, const uint8_t end_pattern, 87 | const unsigned long max_length, 88 | const long num_location) 89 | { 90 | uint8_t *found, *terminate; 91 | uint8_t isFound = 0; 92 | uint8_t count = 0; 93 | 94 | if (!prefix || !buffer || !end || !pattern || !size || !max_length || !num_location) 95 | return ERR_INVALID_PARAMETER; 96 | 97 | found = find_pattern(buffer, end, pattern, size); 98 | while (found != NULL && count < num_location) 99 | { 100 | isFound = 1; 101 | terminate = find_pattern(found + offset, end, &end_pattern, 1); 102 | if ((unsigned long) (terminate - found - offset) > max_length) 103 | terminate = found + offset + max_length; 104 | *terminate = 0x00; 105 | printf("%s%s\n", prefix, found + offset); 106 | count++; 107 | found = find_pattern(found + 1, end, pattern, size); 108 | } 109 | if (isFound) 110 | return ERR_SUCCESS; 111 | else 112 | return ERR_NOT_FOUND; 113 | } 114 | 115 | /* Entry point */ 116 | int main(int argc, char* argv[]) 117 | 118 | { 119 | FILE* file; 120 | uint8_t* buffer; 121 | uint8_t* end; 122 | long filesize; 123 | long read; 124 | size_t pattern_length; 125 | uint8_t* pattern; 126 | size_t end_marker_length; 127 | uint8_t* end_marker_pattern; 128 | long offset; 129 | long max_length; 130 | long num_location; 131 | uint8_t result; 132 | 133 | if (argc < 8) 134 | { 135 | printf("findver v0.3.2\n" 136 | "Prints version string found in input file\n\n" 137 | "Usage: findver prefix pattern offset end_marker max_length FILE\n" 138 | "Options:\n" 139 | "prefix - Prefix string, ASCII symbols\n" 140 | "pattern - Pattern to find, hex digits\n" 141 | "offset - Offset of version string, integer\n" 142 | "end_marker - Pattern that marks end of version string, 2 hex digits\n" 143 | 144 | /* "count_skip_end_marker - Count skip end marker"; */ 145 | 146 | "max_length - Maximum length of printed version string, integer\n" 147 | "num_location- Number of location, integer\n" 148 | ); 149 | 150 | return ERR_INVALID_PARAMETER; 151 | } 152 | 153 | 154 | 155 | /* Opening file */ 156 | file = fopen(argv[7], "rb"); 157 | if (!file) 158 | { 159 | printf("File can't be opened.\n"); 160 | return ERR_FILE_OPEN; 161 | } 162 | 163 | /* Determining file size */ 164 | fseek(file, 0, SEEK_END); 165 | filesize = ftell(file); 166 | fseek(file, 0, SEEK_SET); 167 | 168 | /* Allocating memory for buffer */ 169 | buffer = (uint8_t*) malloc(filesize); 170 | if (!buffer) 171 | { 172 | printf("Can't allocate memory for file contents.\n"); 173 | return ERR_OUT_OF_MEMORY; 174 | } 175 | 176 | /* Reading whole file to buffer */ 177 | read = fread((void*) buffer, sizeof(char), filesize, file); 178 | if (read != filesize) 179 | { 180 | printf("Can't read file.\n"); 181 | return ERR_FILE_READ; 182 | } 183 | 184 | end = buffer + filesize; 185 | 186 | /* Parse arguments */ 187 | 188 | result = read_pattern(argv[2], &pattern, &pattern_length); 189 | if (result) 190 | return ERR_INVALID_PARAMETER; 191 | 192 | offset = strtol(argv[3], NULL, 10); 193 | 194 | result = read_pattern(argv[4], &end_marker_pattern, &end_marker_length); 195 | if (result) 196 | return ERR_INVALID_PARAMETER; 197 | 198 | max_length = strtol(argv[5], NULL, 10); 199 | 200 | num_location = strtol(argv[6], NULL, 10); 201 | 202 | return print_version(argv[1], buffer, end, pattern, pattern_length, offset, *end_marker_pattern, labs(max_length), num_location); 203 | } 204 | -------------------------------------------------------------------------------- /hexfind/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(hexfind) 2 | SET(HF_SOURCES hexfind.c) 3 | ADD_EXECUTABLE(hexfind ${HF_SOURCES}) -------------------------------------------------------------------------------- /hexfind/findhex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define ERR_SUCCESS 0 8 | #define ERR_NOT_FOUND 1 9 | #define ERR_FILE_OPEN 2 10 | #define ERR_FILE_READ 3 11 | #define ERR_INVALID_PARAMETER 4 12 | #define ERR_OUT_OF_MEMORY 5; 13 | 14 | /* Implementation of GNU memmem function using Boyer-Moore-Horspool algorithm 15 | * Returns pointer to the beginning of found pattern of NULL if not found */ 16 | uint8_t* find_pattern(uint8_t* begin, uint8_t* end, const uint8_t* pattern, size_t plen) 17 | { 18 | size_t scan = 0; 19 | size_t bad_char_skip[256]; 20 | size_t last; 21 | size_t slen; 22 | 23 | if (plen == 0 || !begin || !pattern || !end || end <= begin) 24 | return NULL; 25 | 26 | slen = end - begin; 27 | 28 | for (scan = 0; scan <= 255; scan++) 29 | bad_char_skip[scan] = plen; 30 | 31 | last = plen - 1; 32 | 33 | for (scan = 0; scan < last; scan++) 34 | bad_char_skip[pattern[scan]] = last - scan; 35 | 36 | while (slen >= plen) 37 | { 38 | for (scan = last; begin[scan] == pattern[scan]; scan--) 39 | if (scan == 0) 40 | return begin; 41 | 42 | slen -= bad_char_skip[begin[last]]; 43 | begin += bad_char_skip[begin[last]]; 44 | } 45 | 46 | return NULL; 47 | } 48 | 49 | uint8_t read_pattern(const char* string, uint8_t* pattern[], size_t* length) 50 | { 51 | size_t i; 52 | const char* current; 53 | char buf[3]; 54 | 55 | buf[2] = 0; 56 | 57 | *length = strlen(string); 58 | if (*length % 2) 59 | return ERR_INVALID_PARAMETER; 60 | 61 | *length /= 2; 62 | 63 | *pattern = (uint8_t*) malloc(*length); 64 | 65 | for (current = string, i = 0; i < *length; i++) 66 | { 67 | buf[0] = *current++; 68 | buf[1] = *current++; 69 | 70 | if (!isxdigit(buf[0]) || !isxdigit(buf[1])) 71 | return ERR_INVALID_PARAMETER; 72 | else 73 | (*pattern)[i] = (uint8_t) strtoul(buf, NULL, 16); 74 | } 75 | 76 | return ERR_SUCCESS; 77 | } 78 | 79 | /* Entry point */ 80 | int main(int argc, char* argv[]) 81 | { 82 | FILE* file; 83 | uint8_t* buffer; 84 | uint8_t* end; 85 | uint8_t* found; 86 | uint8_t* pattern; 87 | size_t length; 88 | unsigned long count; 89 | long filesize; 90 | long read; 91 | 92 | if (argc < 3) 93 | { 94 | printf("hexfind v0.1.2\n\nUsage: hexfind PATTERN FILENAME\n"); 95 | return ERR_INVALID_PARAMETER; 96 | } 97 | 98 | /* Parsing pattern string */ 99 | if (read_pattern(argv[1], &pattern, &length)) 100 | { 101 | printf("Pattern can't be parsed as hex.\n"); 102 | return ERR_INVALID_PARAMETER; 103 | } 104 | 105 | /* Opening file */ 106 | file = fopen(argv[2], "rb"); 107 | if(!file) 108 | { 109 | printf("File can't be opened.\n"); 110 | return ERR_FILE_OPEN; 111 | } 112 | 113 | /* Determining file size */ 114 | fseek(file, 0, SEEK_END); 115 | filesize = ftell(file); 116 | fseek(file, 0, SEEK_SET); 117 | 118 | /* Allocating memory for buffer */ 119 | buffer = (uint8_t*)malloc(filesize); 120 | if (!buffer) 121 | { 122 | printf("Can't allocate memory for file contents.\n"); 123 | return ERR_OUT_OF_MEMORY; 124 | } 125 | 126 | /* Reading whole file to buffer */ 127 | read = fread((void*)buffer, sizeof(char), filesize, file); 128 | if (read != filesize) 129 | { 130 | printf("Can't read file.\n"); 131 | return ERR_FILE_READ; 132 | } 133 | 134 | /* Searching for pattern in file and counting matches */ 135 | count = 0; 136 | end = buffer + filesize; 137 | found = find_pattern(buffer, end, pattern, length); 138 | while (found) 139 | { 140 | count++; 141 | found = find_pattern(found + 1, end, pattern, length); 142 | } 143 | 144 | if (count) 145 | printf("%lu\n", count); 146 | else 147 | return ERR_NOT_FOUND; 148 | 149 | return ERR_SUCCESS; 150 | } 151 | --------------------------------------------------------------------------------