IDENTITY_ATTRIBUTE_BLOB 구조체
어셈블리의 단일 특성에 대한 정보를 포함하고 세 개의 s로 구성됩니다 DWORD
. 각각 DWORD
은 IEnumIDENTITY_ATTRIBUTE 인터페이스의 메서드에 의해 CurrentIntoBuffer
생성된 문자 버퍼에 대한 오프셋입니다.
구문
typedef struct _IDENTITY_ATTRIBUTE_BLOB {
DWORD ofsNamespace;
DWORD ofsName;
DWORD ofsValue;
} IDENTITY_ATTRIBUTE_BLOB;
멤버
멤버 | 설명 |
---|---|
ofsNamespace |
문자 버퍼에 대한 첫 번째 오프셋입니다. 이 오프셋 뒤에는 특성의 네임스페이스가 아니라 일련의 null 문자가 옵니다. 따라서 사용되지 않습니다. |
ofsName |
문자 버퍼에 대한 두 번째 오프셋입니다. 이 위치는 특성 이름의 시작을 표시합니다. |
ofsValue |
문자 버퍼에 대한 세 번째 오프셋입니다. 이 위치는 특성 값의 시작을 표시합니다. |
샘플
다음 예제에서는 몇 가지 기본 단계를 보여 줍니다. 이로 인해 결국 구조체가 채워집니다 IDENTITY_ATTRIBUTE_BLOB
.
어셈블리에 대한 IReferenceIdentity 를 가져옵니다.
IReferenceIdentity::EnumAttributes
메서드를 호출하고 IEnumIDENTITY_ATTRIBUTE를 가져옵니다.문자 버퍼를 만들고 구조체
IDENTITY_ATTRIBUTE_BLOB
로 캐스팅합니다.인터페이스의
CurrentIntoBuffer
메서드를 호출합니다IEnumIDENTITY_ATTRIBUTE
. 이 메서드는 특성Namespace
,Name
및Value
를 문자 버퍼에 복사합니다. 이러한 문자열에 대한 세 가지 오프셋은 구조체에서IDENTITY_ATTRIBUTE_BLOB
사용할 수 있게 됩니다.
// EnumAssemblyAttributes.cpp : main project file.
#include "stdafx.h"
#include "fusion.h"
#include "windows.h"
#include "stdio.h"
#include "mscoree.h"
#include "isolation.h"
typedef HRESULT (__stdcall *PFNGETREF)(LPCWSTR pwzFile, REFIID riid, IUnknown **ppUnk);
typedef HRESULT (__stdcall *PFNGETAUTH)(IIdentityAuthority **ppIIdentityAuthority);
PFNGETREF g_pfnGetAssemblyIdentityFromFile = NULL;
PFNGETAUTH g_pfnGetIdentityAuthority = NULL;
IUnknown *g_pUnk = NULL;
bool Init()
{
HRESULT hr = S_OK;
DWORD dwSize = 0;
bool bRC = false;
hr = CorBindToRuntimeEx(NULL, L"wks", 0, CLSID_CorRuntimeHost,
IID_ICorRuntimeHost, (void **)&g_pUnk);
if(FAILED(hr)) {
printf("Error: Failed to initialize CLR runtime! hr = 0x%0x\n",
hr);
goto Exit;
}
if (SUCCEEDED(hr)) {
hr = GetRealProcAddress("GetAssemblyIdentityFromFile",
(VOID **)&g_pfnGetAssemblyIdentityFromFile);
}
if (SUCCEEDED(hr)) {
hr = GetRealProcAddress("GetIdentityAuthority",
(VOID **)&g_pfnGetIdentityAuthority);
}
if (!g_pfnGetAssemblyIdentityFromFile ||
!g_pfnGetIdentityAuthority)
{
printf("Error: Cannot get required APIs from fusion.dll!\n");
goto Exit;
}
bRC = true;
Exit:
return bRC;
}
void Shutdown()
{
if(g_pUnk) {
g_pUnk->Release();
g_pUnk = NULL;
}
}
void Usage()
{
printf("EnumAssemblyAttributes: A tool to enumerate the identity
attributes of a given assembly.\n\n");
printf("Usage: EnumAssemblyAttributes AssemblyFilePath\n");
printf("\n");
}
int _cdecl wmain(int argc, LPCWSTR argv[])
{
int iResult = 1;
IUnknown *pUnk = NULL;
IReferenceIdentity *pRef = NULL;
HRESULT hr = S_OK;
IEnumIDENTITY_ATTRIBUTE *pEnum = NULL;
BYTE abData[1024];
DWORD cbAvailable;
DWORD cbUsed;
IDENTITY_ATTRIBUTE_BLOB *pBlob;
if(argc != 2) {
Usage();
goto Exit;
}
if(!Init()) {
printf("Failure initializing EnumIdAttr.\n");
goto Exit;
}
hr = g_pfnGetAssemblyIdentityFromFile(argv[1],
__uuidof(IReferenceIdentity), &pUnk);
if (FAILED(hr)) {
printf("GetAssemblyIdentityFromFile failed with hr = 0x%x",
hr);
goto Exit;
}
hr = pUnk->QueryInterface(__uuidof(IReferenceIdentity),
(void**)&pRef);
if (FAILED(hr)) {
goto Exit;
}
hr = pRef->EnumAttributes(&pEnum);
if (FAILED(hr)) {
printf("IReferenceIdentity::EnumAttributes failed with hr =
0x%x", hr);
goto Exit;
}
pBlob = (IDENTITY_ATTRIBUTE_BLOB *)(abData);
while (1) {
cbAvailable = sizeof(abData);
hr = pEnum->CurrentIntoBuffer(cbAvailable, abData, &cbUsed);
if (FAILED(hr)) {
printf("IEnumIDENTITY_ATTRIBUTE::CurrentIntoBuffer failed
with hr = 0x%x", hr);
goto Exit;
}
if (! cbUsed) {
break;
}
LPWSTR pwzNameSpace = (LPWSTR)(abData + pBlob->ofsNamespace);
LPWSTR pwzName = (LPWSTR)(abData + pBlob->ofsName);
LPWSTR pwzValue = (LPWSTR)(abData + pBlob->ofsValue);
printf("%ws: %ws = %ws\n", pwzNameSpace, pwzName, pwzValue);
hr = pEnum->Skip(1);
if (FAILED(hr)) {
printf("IEnumIDENTITY_ATTRIBUTE::Skip failed with hr =
0x%x", hr);
goto Exit;
}
}
iResult = 0;
Exit:
Shutdown();
if (pUnk) {
pUnk->Release();
}
if (pRef) {
pRef->Release();
}
if (pEnum) {
pEnum->Release();
}
return iResult;
}
이 샘플을 실행하려면
C:\> EnumAssemblyAttributes.exe C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
샘플 출력
문화권 = 중립
name = System
processorArchitecture = MSIL
PublicKeyToken = b77a5c561934e089
Version = 2.0.0.0
요구 사항
플랫폼:시스템 요구 사항을 참조하세요.
헤더: Isolation.h
.NET Framework 버전: 2.0부터 사용 가능
참고 항목
.NET