I try to debug this code and understand why the exit from the loop occurs at the first iteration, and the value 0 is returned.
WORD GetNumberOfSections (PVOID pMem) { PIMAGE_DOS_HEADER pDOSh; PIMAGE_NT_HEADERS pNTh; PIMAGE_SECTION_HEADER pSECTh; WORD numOfSect = 0; __try { pDOSh = (PIMAGE_DOS_HEADER) pMem; pNTh = (PIMAGE_NT_HEADERS) ((DWORD) pDOSh + pDOSh->e_lfanew); pSECTh = IMAGE_FIRST_SECTION (pNTh); for (WORD i = 0; i < pNTh->FileHeader.NumberOfSections; i++) { if (!pSECTh->PointerToRelocations && !pSECTh->PointerToLinenumbers && !pSECTh->NumberOfRelocations && !pSECTh->NumberOfLinenumbers && pSECTh->Characteristics) numOfSect++; else return numOfSect; pSECTh++; } return numOfSect; } __except (EXCEPTION_EXECUTE_HANDLER) { return 0; } } I work in VS 2010. Of local variables, only pMem and i are visible. How to make sure that the structures are initialized correctly and see the values of some fields?