EasyPdb icon indicating copy to clipboard operation
EasyPdb copied to clipboard

pull request

Open fork1488 opened this issue 6 months ago • 1 comments

p fix

	int CPDB::get_attribute_offset(std::string StructName, std::wstring PropertyName)
	{
		ULONG SymInfoSize = sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR);
		SYMBOL_INFO* SymInfo = (SYMBOL_INFO*)malloc(SymInfoSize);
		if (!SymInfo)
		{
			return -1;
		}
		ZeroMemory(SymInfo, SymInfoSize);
		SymInfo->SizeOfStruct = sizeof(SYMBOL_INFO);
		SymInfo->MaxNameLen = MAX_SYM_NAME;

		// Get type information for the structure
		if (!SymGetTypeFromName(_hProcess, EZ_PDB_BASE_OF_DLL, StructName.c_str(), SymInfo))
		{
			free(SymInfo);
			return -1;
		}

		TI_FINDCHILDREN_PARAMS TempFp = { 0 };
		// Get the number of children
		if (!SymGetTypeInfo(_hProcess, EZ_PDB_BASE_OF_DLL, SymInfo->TypeIndex, TI_GET_CHILDRENCOUNT, &TempFp))
		{
			free(SymInfo);
			return -1;
		}

		ULONG ChildParamsSize = sizeof(TI_FINDCHILDREN_PARAMS) + TempFp.Count * sizeof(ULONG);
		TI_FINDCHILDREN_PARAMS* ChildParams = (TI_FINDCHILDREN_PARAMS*)malloc(ChildParamsSize);
		if (ChildParams == NULL)
		{
			free(SymInfo);
			return -1;
		}
		ZeroMemory(ChildParams, ChildParamsSize);
		memcpy(ChildParams, &TempFp, sizeof(TI_FINDCHILDREN_PARAMS));

		// Get the children information
		if (!SymGetTypeInfo(_hProcess, EZ_PDB_BASE_OF_DLL, SymInfo->TypeIndex, TI_FINDCHILDREN, ChildParams))
		{
			goto failed;
		}

		printf("%s -> %i %i\n", StructName.c_str(), ChildParams->Start, ChildParams->Count);

		for (ULONG i = ChildParams->Start; i < ChildParams->Count; i++)
		{
			WCHAR* pSymName = NULL;
			ULONG Offset = 0;

			// Get the name of the child
			if (!SymGetTypeInfo(_hProcess, EZ_PDB_BASE_OF_DLL, ChildParams->ChildId[i], TI_GET_SYMNAME, &pSymName))
			{
				continue;
			}

			// Get the offset of the child
			if (!SymGetTypeInfo(_hProcess, EZ_PDB_BASE_OF_DLL, ChildParams->ChildId[i], TI_GET_OFFSET, &Offset))
			{
				printf("%s -> %ws fail 0x%X\n", StructName.c_str(), pSymName, GetLastError());
				continue;
			}


			if (pSymName)
			{
				printf("%s -> %ws == %ws\n", StructName.c_str(), pSymName, PropertyName.c_str());
				if (wcscmp(pSymName, PropertyName.c_str()) == 0)
				{
					LocalFree(pSymName);
					free(ChildParams);
					free(SymInfo);
					return int(Offset);
				}
				LocalFree(pSymName); // Free the name after use
			}
		}

	failed:
		free(ChildParams);
		free(SymInfo);
		return -1;
	}

fork1488 avatar Aug 15 '24 20:08 fork1488