mirror of
https://github.com/wavestone-cdt/EDRSandblast.git
synced 2026-06-10 01:17:25 +00:00
various cosmetic changes to please the code analyzer
This commit is contained in:
@@ -32,24 +32,30 @@ typedef struct PdbInfoStreamHeader_t {
|
||||
|
||||
PVOID extractGuidFromPdb(LPWSTR filepath) {
|
||||
GUID* guid = NULL;
|
||||
HANDLE hMapping = NULL;
|
||||
PBYTE filemap = NULL;
|
||||
DWORD* StreamDirectory = NULL;
|
||||
DWORD** StreamBlocks = NULL;
|
||||
DWORD NumStreams = 0;
|
||||
|
||||
HANDLE hFile = CreateFileW(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
return NULL;
|
||||
}
|
||||
HANDLE hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
if (hMapping == NULL) {
|
||||
goto clean_file;
|
||||
goto clean;
|
||||
}
|
||||
PBYTE filemap = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
|
||||
filemap = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
|
||||
if (filemap == NULL) {
|
||||
goto clean_mapping;
|
||||
goto clean;
|
||||
}
|
||||
SuperBlock* superblock = (SuperBlock*)filemap;
|
||||
DWORD blockSize = superblock->BlockSize;
|
||||
DWORD* StreamDirectoryBlockMap = (DWORD*)(filemap + (ULONG_PTR)superblock->BlockMapAddr * blockSize);
|
||||
DWORD* StreamDirectory = calloc(superblock->NumDirectoryBytes, 1);
|
||||
StreamDirectory = calloc(superblock->NumDirectoryBytes, 1);
|
||||
if (StreamDirectory == NULL) {
|
||||
goto clean_viewoffile;
|
||||
goto clean;
|
||||
}
|
||||
DWORD StreamDirectoryBlockIndex = 0;
|
||||
DWORD StreamDirectoryRemainingSize = superblock->NumDirectoryBytes;
|
||||
@@ -62,18 +68,19 @@ PVOID extractGuidFromPdb(LPWSTR filepath) {
|
||||
StreamDirectoryBlockIndex++;
|
||||
StreamDirectoryRemainingSize -= SizeToCopy;
|
||||
}
|
||||
DWORD NumStreams = StreamDirectory[0];
|
||||
NumStreams = StreamDirectory[0];
|
||||
if (NumStreams < 2) {
|
||||
goto clean_StreamDirectory;
|
||||
NumStreams = 0;
|
||||
goto clean;
|
||||
}
|
||||
DWORD** StreamBlocks = calloc(NumStreams, sizeof(DWORD*));
|
||||
StreamBlocks = calloc(NumStreams, sizeof(DWORD*));
|
||||
if (StreamBlocks == NULL) {
|
||||
goto clean_StreamDirectory;
|
||||
goto clean;
|
||||
}
|
||||
DWORD* StreamBlocksFlat = &StreamDirectory[1 + NumStreams];
|
||||
DWORD i = 0;
|
||||
if ((1 + NumStreams) >= superblock->NumDirectoryBytes / 4) {
|
||||
goto clean_StreamBlocks;
|
||||
goto clean;
|
||||
}
|
||||
for (DWORD stream_i = 0; stream_i < NumStreams; stream_i++) {
|
||||
DWORD StreamSize = StreamDirectory[1 + stream_i];
|
||||
@@ -81,7 +88,7 @@ PVOID extractGuidFromPdb(LPWSTR filepath) {
|
||||
while (StreamBlockCount * blockSize < StreamSize) {
|
||||
PVOID tmp = realloc(StreamBlocks[stream_i], ((SIZE_T)StreamBlockCount + 1) * sizeof(DWORD));
|
||||
if (tmp == NULL) {
|
||||
goto clean_StreamBlocks;
|
||||
goto clean;
|
||||
}
|
||||
StreamBlocks[stream_i] = tmp;
|
||||
StreamBlocks[stream_i][StreamBlockCount] = StreamBlocksFlat[i];
|
||||
@@ -91,27 +98,37 @@ PVOID extractGuidFromPdb(LPWSTR filepath) {
|
||||
}
|
||||
DWORD PdbInfoStreamSize = StreamDirectory[1 + 1];
|
||||
if (PdbInfoStreamSize == 0) {
|
||||
goto clean_StreamBlocks;
|
||||
goto clean;
|
||||
}
|
||||
PdbInfoStreamHeader* PdbInfoStream = (PdbInfoStreamHeader*)(filemap + (ULONG_PTR)StreamBlocks[1][0] * blockSize);
|
||||
guid = calloc(1, sizeof(GUID));
|
||||
if (guid == NULL) {
|
||||
goto clean_StreamBlocks;
|
||||
goto clean;
|
||||
}
|
||||
memcpy(guid, &PdbInfoStream->UniqueId, sizeof(GUID));
|
||||
clean_StreamBlocks:
|
||||
for (DWORD stream_i = 0; stream_i < NumStreams; stream_i++) {
|
||||
free(StreamBlocks[stream_i]);
|
||||
clean:
|
||||
if (StreamBlocks) {
|
||||
for (DWORD stream_i = 0; stream_i < NumStreams; stream_i++) {
|
||||
#pragma warning(disable : 6001) //compiler analysis is wrong for some reason (or maybe I am)
|
||||
if (StreamBlocks[stream_i]) {
|
||||
#pragma warning(default: 6001)
|
||||
free(StreamBlocks[stream_i]);
|
||||
}
|
||||
}
|
||||
free(StreamBlocks);
|
||||
}
|
||||
if (StreamDirectory) {
|
||||
free(StreamDirectory);
|
||||
}
|
||||
if (filemap) {
|
||||
UnmapViewOfFile(filemap);
|
||||
}
|
||||
if (hMapping != NULL) {
|
||||
CloseHandle(hMapping);
|
||||
}
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
free(StreamBlocks);
|
||||
clean_StreamDirectory:
|
||||
free(StreamDirectory);
|
||||
clean_viewoffile:
|
||||
UnmapViewOfFile(filemap);
|
||||
clean_mapping:
|
||||
CloseHandle(hMapping);
|
||||
clean_file:
|
||||
CloseHandle(hFile);
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user