1 // IoEaTest.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 6 #include <stdio.h> 7 #include <windows.h> 8 9 typedef struct _FILE_FULL_EA_INFORMATION { 10 ULONG NextEntryOffset; 11 UCHAR Flags; 12 UCHAR EaNameLength; 13 USHORT EaValueLength; 14 CHAR EaName[1]; 15 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION; 16 17 #define ULONG_PTR unsigned char* 18 19 #define NTSTATUS unsigned int 20 21 #define STATUS_EA_LIST_INCONSISTENT 0x80000014L 22 #define STATUS_SUCCESS 0x00000000L 23 24 /* 25 * @implemented 26 */ 27 NTSTATUS 28 NTAPI 29 IoCheckEaBufferValidityROS(IN PFILE_FULL_EA_INFORMATION EaBuffer, 30 IN ULONG EaLength, 31 OUT PULONG ErrorOffset) 32 { 33 PFILE_FULL_EA_INFORMATION EaBufferEnd; 34 ULONG NextEaBufferOffset; 35 UINT IntEaLength; 36 37 /* Length of the rest. Initialize it to EaLength */ 38 IntEaLength = EaLength; 39 /* Initialize EaBuffer to EaBuffer */ 40 EaBufferEnd = EaBuffer; 41 42 /* The rest length of the buffer */ 43 /* 8 = sizeof(ULONG) + sizeof(UCHAR) + sizeof(UCHAR) + sizeof(USHORT) */ 44 while (IntEaLength >= 8) 45 { 46 /* The rest of the buffer must be greater than sizeof(FILE_FULL_EA_INFORMATION) + buffer */ 47 NextEaBufferOffset = EaBufferEnd->EaNameLength+EaBufferEnd->EaValueLength + 9; 48 if (IntEaLength >= NextEaBufferOffset) 49 { 50 /* is the EaBufferName terminated with zero? */ 51 if (EaBufferEnd->EaName[EaBufferEnd->EaNameLength]==0) 52 { 53 /* more EaBuffers ahead */ 54 if (EaBufferEnd->NextEntryOffset == 0) 55 { 56 /* test the rest buffersize */ 57 IntEaLength = IntEaLength - NextEaBufferOffset; 58 if (IntEaLength>=0) 59 { 60 return STATUS_SUCCESS; 61 } 62 } 63 else 64 { 65 /* 66 From MSDN (http://msdn2.microsoft.com/en-us/library/ms795740.aspx). 67 For all entries except the last, the value of NextEntryOffset must be greater 68 than zero and must fall on a ULONG boundary. 69 */ 70 NextEaBufferOffset = ((NextEaBufferOffset + 3) & 0xFFFFFFFC); 71 if ((EaBufferEnd->NextEntryOffset == NextEaBufferOffset) && (EaBufferEnd->NextEntryOffset>0)) 72 { 73 /* The rest of the buffer must be greater than the next offset */ 74 IntEaLength = IntEaLength - EaBufferEnd->NextEntryOffset; 75 if (IntEaLength>=0) 76 { 77 EaBufferEnd = (PFILE_FULL_EA_INFORMATION)((ULONG_PTR)EaBufferEnd + EaBufferEnd->NextEntryOffset); 78 continue; 79 } 80 } 81 } 82 } 83 } 84 break; 85 } 86 87 if (ErrorOffset != NULL) 88 { 89 /* calculate the error offset. */ 90 *ErrorOffset = (ULONG)((ULONG_PTR)EaBufferEnd - (ULONG_PTR)EaBuffer); 91 } 92 93 return STATUS_EA_LIST_INCONSISTENT; 94 } 95 96 97 98 99 100 void CheckROSAgainstWinAndPrintResult(PFILE_FULL_EA_INFORMATION WinEaBuffer,PFILE_FULL_EA_INFORMATION ROSEaBuffer,NTSTATUS WinStatus,NTSTATUS ROSStatus,ULONG WinErrorOffset,ULONG ROSErrorOffset,int iBufferLength,int iTestCount,ULONG TestEaLength) 101 { 102 printf("Subtest:%i Status:%x EaErrorOffset:%x TestEaLength:%i passed - ",iTestCount,WinStatus,WinErrorOffset,TestEaLength); 103 if (memcmp(WinEaBuffer,ROSEaBuffer,iBufferLength)==0) 104 { 105 if (WinStatus == ROSStatus) 106 { 107 if (WinErrorOffset == ROSErrorOffset) 108 { 109 printf("okay\n"); 110 return; 111 } 112 } 113 } 114 printf("*failed*\n"); 115 } 116 117 typedef NTSTATUS (*NTAPI pIoCheckEaBufferValidity) (IN PFILE_FULL_EA_INFORMATION EaBuffer,IN ULONG EaLength,OUT PULONG ErrorOffset); 118 119 typedef PVOID (*NTAPI pMmPageEntireDriver) (IN PVOID AddressWithinSection); 120 121 #define RANDOM_INIT_ERROR 0xDEADBAD0 122 #define TEST_BUFFER_LEN 256 123 124 int _tmain(int argc, _TCHAR* argv[]) 125 { 126 void *pFunction; 127 pIoCheckEaBufferValidity IoCheckEaBufferValidity; 128 129 HMODULE hKrnlMod = LoadLibrary(L"ntoskrnl.exe"); 130 if (hKrnlMod) 131 { 132 pFunction = GetProcAddress(hKrnlMod,"IoCheckEaBufferValidity"); 133 IoCheckEaBufferValidity = (pIoCheckEaBufferValidity)pFunction; 134 if (IoCheckEaBufferValidity!=NULL) 135 { 136 /* Check tes Windows Function */ 137 ULONG ulWinError; 138 ULONG ulROSError; 139 NTSTATUS WinStatus; 140 NTSTATUS ROSStatus; 141 PFILE_FULL_EA_INFORMATION WinEaBuffer; 142 PFILE_FULL_EA_INFORMATION ROSEaBuffer; 143 char szTest[100] = "FltMgr"; 144 int iTestCount,i; 145 ULONG TestEaLength; 146 UCHAR TestEaBufferFlags; 147 148 // Test the flag 149 TestEaBufferFlags = 0; 150 151 iTestCount = 1; 152 WinEaBuffer = (PFILE_FULL_EA_INFORMATION)malloc(TEST_BUFFER_LEN); 153 ROSEaBuffer = (PFILE_FULL_EA_INFORMATION)malloc(TEST_BUFFER_LEN); 154 155 156 printf("1.) Test : *********************\n"); 157 158 /* Check EaLength calculation */ 159 /* Here all zero : only i>9 pass the test with STATUS_SUCCESS */ 160 161 for (i=0;i<TEST_BUFFER_LEN;i++) 162 { 163 TestEaLength = i; 164 // Windows 165 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 166 ulWinError = RANDOM_INIT_ERROR; 167 WinEaBuffer->Flags = TestEaBufferFlags; 168 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 169 170 // ROS 171 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 172 ulROSError = RANDOM_INIT_ERROR; 173 ROSEaBuffer->Flags = TestEaBufferFlags; 174 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 175 176 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 177 iTestCount++; 178 } 179 180 printf("2.) Test : *********************\n"); 181 182 /* Here all zero but EaBuffer::EaName is set : will always end in STATUS_EA_LIST_INCONSISTENT */ 183 /* There must a link to EaBuffer::EaName */ 184 for (i=0;i<TEST_BUFFER_LEN;i++) 185 { 186 TestEaLength = i; 187 // Windows 188 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 189 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 190 ulWinError = RANDOM_INIT_ERROR; 191 WinEaBuffer->Flags = TestEaBufferFlags; 192 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 193 194 // ROS 195 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 196 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 197 ulROSError = RANDOM_INIT_ERROR; 198 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 199 200 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 201 iTestCount++; 202 } 203 204 printf("3.) Test : *********************\n"); 205 206 /* Here EaBuffer::EaName is set and EaBuffer::EaNameLength is count up. EaLength is maxbuffer: STATUS_SUCCESS when EaBuffer::EaNameLength>strlen(EaBuffer::EaName) */ 207 TestEaLength = TEST_BUFFER_LEN; 208 for (i=0;i<TEST_BUFFER_LEN;i++) 209 { 210 211 // Windows 212 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 213 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 214 WinEaBuffer->EaNameLength = i; 215 ulWinError = RANDOM_INIT_ERROR; 216 WinEaBuffer->Flags = TestEaBufferFlags; 217 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 218 219 // ROS 220 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 221 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 222 ROSEaBuffer->EaNameLength = i; 223 ulROSError = RANDOM_INIT_ERROR; 224 ROSEaBuffer->Flags = TestEaBufferFlags; 225 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 226 227 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 228 iTestCount++; 229 } 230 231 printf("4.) Test : *********************\n"); 232 233 /* Here EaBuffer::EaName is set and EaBuffer::EaNameLength is strlen(EaBuffer::EaName). EaLength is count: STATUS_SUCCESS when EaLength>=17 (EaBuffer::EaNameLength+9) */ 234 for (i=0;i<TEST_BUFFER_LEN;i++) 235 { 236 TestEaLength = i; 237 // Windows 238 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 239 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 240 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName); 241 ulWinError = RANDOM_INIT_ERROR; 242 WinEaBuffer->Flags = TestEaBufferFlags; 243 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 244 245 // ROS 246 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 247 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 248 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName); 249 ulROSError = RANDOM_INIT_ERROR; 250 ROSEaBuffer->Flags = TestEaBufferFlags; 251 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 252 253 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 254 iTestCount++; 255 } 256 257 printf("5.) Test : *********************\n"); 258 259 /* Here EaBuffer::EaName is set and EaBuffer::EaNameLength is strlen(EaBuffer::EaName) EaBuffer::EaValueLength is strlen(EaBuffer::EaName)+1. EaLength is count: STATUS_SUCCESS when EaLength>=26 (EaBuffer::EaNameLength+EaBuffer::EaValueLength+9) */ 260 for (i=0;i<TEST_BUFFER_LEN;i++) 261 { 262 TestEaLength = i; 263 // Windows 264 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 265 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 266 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName); 267 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName)+1; 268 ulWinError = RANDOM_INIT_ERROR; 269 WinEaBuffer->Flags = TestEaBufferFlags; 270 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 271 272 // ROS 273 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 274 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 275 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName); 276 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName)+1; 277 ulROSError = RANDOM_INIT_ERROR; 278 ROSEaBuffer->Flags = TestEaBufferFlags; 279 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 280 281 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 282 iTestCount++; 283 } 284 285 286 printf("6.) Test : *********************\n"); 287 288 /* The same test like 5.) but more data in the buffer*/ 289 /* Here EaBuffer::EaName is set and EaBuffer::EaNameLength is strlen(EaBuffer::EaName) EaBuffer::EaValueLength is strlen(EaBuffer::EaName)+1. EaLength is count: STATUS_SUCCESS when EaLength>=26 (EaBuffer::EaNameLength+EaBuffer::EaValueLength+9) */ 290 291 for (i=0;i<TEST_BUFFER_LEN;i++) 292 { 293 TestEaLength = i; 294 // Windows 295 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 296 sprintf(WinEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 297 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 298 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName); 299 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName)+1; 300 ulWinError = RANDOM_INIT_ERROR; 301 WinEaBuffer->Flags = TestEaBufferFlags; 302 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 303 304 // ROS 305 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 306 sprintf(ROSEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 307 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 308 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName); 309 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName)+1; 310 ulROSError = RANDOM_INIT_ERROR; 311 ROSEaBuffer->Flags = TestEaBufferFlags; 312 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 313 314 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 315 iTestCount++; 316 } 317 318 printf("7.) Test : *********************\n"); 319 320 /* The same test like 6.) but wrong strlen */ 321 /* Here EaBuffer::EaName is set and EaBuffer::EaNameLength is strlen(EaBuffer::EaName) EaBuffer::EaValueLength is strlen(EaBuffer::EaName)+1. EaLength is count: will always end in STATUS_EA_LIST_INCONSISTENT */ 322 for (i=0;i<TEST_BUFFER_LEN;i++) 323 { 324 TestEaLength = i; 325 // Windows 326 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 327 sprintf(WinEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 328 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 329 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName)-1; 330 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName)+2; 331 ulWinError = RANDOM_INIT_ERROR; 332 WinEaBuffer->Flags = TestEaBufferFlags; 333 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 334 335 // ROS 336 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 337 sprintf(ROSEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 338 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 339 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName)-1; 340 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName)+2; 341 ulROSError = RANDOM_INIT_ERROR; 342 ROSEaBuffer->Flags = TestEaBufferFlags; 343 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 344 345 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 346 iTestCount++; 347 } 348 349 350 printf("8.) Test : *********************\n"); 351 352 /* Here WinEaBuffer->NextEntryOffset test : STATUS_SUCCESS when NextEntryOffset=0 else STATUS_EA_LIST_INCONSISTENT when NextEntryOffset = 28 = 8+8+9 ((WinEaBuffer->EaNameLength+WinEaBuffer->EaNameLength+9)+3)&0xFFFFFFFC then ErrorOffset 28 */ 353 /* From the MSDN (http://msdn2.microsoft.com/en-us/library/ms795740.aspx). For all entries except the last, the value of NextEntryOffset must be greater than zero and must fall on a ULONG boundary.*/ 354 for (i=0;i<TEST_BUFFER_LEN;i++) 355 { 356 TestEaLength = TEST_BUFFER_LEN; 357 // Windows 358 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 359 sprintf(WinEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 360 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 361 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName); 362 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName); 363 ulWinError = RANDOM_INIT_ERROR; 364 WinEaBuffer->Flags = TestEaBufferFlags; 365 WinEaBuffer->NextEntryOffset = i; 366 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 367 368 // ROS 369 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 370 sprintf(ROSEaBuffer->EaName,"%x%x%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 371 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 372 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName); 373 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName); 374 ulROSError = RANDOM_INIT_ERROR; 375 ROSEaBuffer->Flags = TestEaBufferFlags; 376 ROSEaBuffer->NextEntryOffset = i; 377 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 378 379 printf("%i-",ROSEaBuffer->NextEntryOffset); 380 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 381 iTestCount++; 382 } 383 384 printf("9.) Test : *********************\n"); 385 386 /* Here WinEaBuffer->NextEntryOffset test wrong strlen: STATUS_SUCCESS NextEntryOffset=0 & NextEntryOffset = 28 = 8+8+9 ((WinEaBuffer->EaNameLength+WinEaBuffer->EaNameLength+9)+3)&0xFFFFFFFC */ 387 /* From the MSDN (http://msdn2.microsoft.com/en-us/library/ms795740.aspx). For all entries except the last, the value of NextEntryOffset must be greater than zero and must fall on a ULONG boundary.*/ 388 for (i=0;i<TEST_BUFFER_LEN;i++) 389 { 390 TestEaLength = TEST_BUFFER_LEN; 391 // Windows 392 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 393 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 394 395 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName)-1; 396 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName); 397 ulWinError = RANDOM_INIT_ERROR; 398 WinEaBuffer->Flags = TestEaBufferFlags; 399 WinEaBuffer->NextEntryOffset = i; 400 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 401 402 // ROS 403 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 404 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 405 406 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName)-1; 407 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName); 408 ulROSError = RANDOM_INIT_ERROR; 409 ROSEaBuffer->Flags = TestEaBufferFlags; 410 ROSEaBuffer->NextEntryOffset = i; 411 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 412 413 printf("%i-",ROSEaBuffer->NextEntryOffset); 414 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 415 iTestCount++; 416 } 417 418 printf("10.) Test : *********************\n"); 419 420 /* Here WinEaBuffer->NextEntryOffset test wrong strlen: STATUS_SUCCESS NextEntryOffset=0 & NextEntryOffset = 28 = 8+8+9 ((WinEaBuffer->EaNameLength+WinEaBuffer->EaNameLength+9)+3)&0xFFFFFFFC */ 421 /* From the MSDN (http://msdn2.microsoft.com/en-us/library/ms795740.aspx). For all entries except the last, the value of NextEntryOffset must be greater than zero and must fall on a ULONG boundary.*/ 422 for (i=0;i<TEST_BUFFER_LEN;i++) 423 { 424 TestEaLength = TEST_BUFFER_LEN; 425 // Windows 426 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 427 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 428 429 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName)+1; 430 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName)+1; 431 ulWinError = RANDOM_INIT_ERROR; 432 WinEaBuffer->Flags = TestEaBufferFlags; 433 WinEaBuffer->NextEntryOffset = i; 434 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 435 436 // ROS 437 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 438 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR); 439 440 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName)+1; 441 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName)+1; 442 ulROSError = RANDOM_INIT_ERROR; 443 ROSEaBuffer->Flags = TestEaBufferFlags; 444 ROSEaBuffer->NextEntryOffset = i; 445 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 446 447 printf("%i-",ROSEaBuffer->NextEntryOffset); 448 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 449 iTestCount++; 450 } 451 452 printf("11.) Test : *********************\n"); 453 454 /* Here WinEaBuffer->NextEntryOffset : */ 455 for (i=0;i<TEST_BUFFER_LEN;i++) 456 { 457 TestEaLength = TEST_BUFFER_LEN; 458 // Windows 459 memset(WinEaBuffer,0,TEST_BUFFER_LEN); 460 sprintf(WinEaBuffer->EaName,"%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 461 462 WinEaBuffer->EaNameLength = (UCHAR)strlen(WinEaBuffer->EaName); 463 WinEaBuffer->EaValueLength = (UCHAR)strlen(WinEaBuffer->EaName); 464 ulWinError = RANDOM_INIT_ERROR; 465 WinEaBuffer->Flags = TestEaBufferFlags; 466 WinEaBuffer->NextEntryOffset = ((WinEaBuffer->EaNameLength+WinEaBuffer->EaNameLength+9)+3)&0xFFFFFFFC; 467 WinStatus = IoCheckEaBufferValidity(WinEaBuffer,TestEaLength,&ulWinError); 468 469 // ROS 470 memset(ROSEaBuffer,0,TEST_BUFFER_LEN); 471 sprintf(ROSEaBuffer->EaName,"%x",RANDOM_INIT_ERROR,RANDOM_INIT_ERROR); 472 473 ROSEaBuffer->EaNameLength = (UCHAR)strlen(ROSEaBuffer->EaName); 474 ROSEaBuffer->EaValueLength = (UCHAR)strlen(ROSEaBuffer->EaName); 475 ulROSError = RANDOM_INIT_ERROR; 476 ROSEaBuffer->Flags = TestEaBufferFlags; 477 ROSEaBuffer->NextEntryOffset = ((ROSEaBuffer->EaNameLength+ROSEaBuffer->EaNameLength+9)+3)&0xFFFFFFFC; 478 ROSStatus = IoCheckEaBufferValidityROS(ROSEaBuffer,TestEaLength,&ulROSError); 479 480 printf("%i-",ROSEaBuffer->NextEntryOffset); 481 CheckROSAgainstWinAndPrintResult(WinEaBuffer,ROSEaBuffer,WinStatus,ROSStatus,ulWinError,ulWinError,TEST_BUFFER_LEN,iTestCount,TestEaLength); 482 iTestCount++; 483 } 484 485 486 free(WinEaBuffer); 487 free(ROSEaBuffer); 488 } 489 490 FreeLibrary(hKrnlMod); 491 } 492 else 493 { 494 DWORD dwLastError = GetLastError(); 495 switch (dwLastError) 496 { 497 case ERROR_MOD_NOT_FOUND: 498 printf("ERROR_MOD_NOT_FOUND\n"); 499 break; 500 case ERROR_BAD_EXE_FORMAT: 501 printf("ERROR_BAD_EXE_FORMAT\n"); 502 break; 503 } 504 } 505 return 0; 506 } 507 508