Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

guidgen - Encountered an improper argument. 오류 해결 방법 (및 windbg 분석)

Visual Studio의 guidgen을 실행했는데, "Encountered an improper argument." 오류 메시지만 발생하고 GUID 값 출력이 안 되는 경우가 있습니다. 현상을 자세히 관찰해 보면 guidgen 실행 화면의,

guidgen_not_work_1.png

Radio button을 누를 때마다 "Encountered an improper argument." 메시지가 발생하는 것을 확인할 수 있습니다.




검색해 보면,

Fixing erroneous GUID creation in Visual Studio 2010
; https://modery.net/fixing-erroneous-guid-creation-in-visual-studio-2010/

예전 버전을 쓰라고 나오는데, 그것보다는 그냥 새롭게 확장 프로그램을 설치하는 것이 더 좋을 수도 있습니다.

GuidGen 2.0
; https://marketplace.visualstudio.com/items?itemName=AndrewLArnott.GuidGen20




일단, 문제 해결(?)은 되었는데 그래도 왜 그런 문제가 발생했는지 궁금합니다. ^^ 그래서 windbg를 통해 GUID를 생성하는 Win32 API에 bp를 걸고,

bp rpcrt4!UuidCreate

추적했을 때 RPCRT4!_imp__ProcessPrng 호출에 넘겨준 인자(esi)가,

RPCRT4!UuidCreate:
750ec790 8bff            mov     edi,edi
750ec792 55              push    ebp
750ec793 8bec            mov     ebp,esp
750ec795 56              push    esi
750ec796 8b7508          mov     esi,dword ptr [ebp+8]
750ec799 6a10            push    10h
750ec79b 56              push    esi
750ec79c ff1594f01575    call    dword ptr [RPCRT4!_imp__ProcessPrng (7515f094)]

호출 전에는 0x10h 길이의 빈 버퍼였다가,

0:000> db @esi Lf
00d3fb30  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00     ...............

호출 후에는 정상적으로 GUID 값이 들어온 것을 확인할 수 있습니다.

0:000> db @esi Lf
00d3fb30  1c 79 31 15 d8 e0 58 31-dc 2f 74 a7 fe c8 62     .y1...X1./t...b

따라서 GUID 생성 자체에는 아무런 문제가 없었습니다. 이후 문제가 되는 코드를 추적해 보면, GuidGen!CGuidGenDlg::GetFormattedGuid 호출에서 C++ 예외가 발생하는 현상을 볼 수 있습니다.

0:000> u
GuidGen!CGuidGenDlg::OnChangedSel+0x29:
00c325ce e8ea000000      call    GuidGen!CGuidGenDlg::GetFormattedGuid (00c326bd)
00c325d3 ff75f0          push    dword ptr [ebp-10h]
00c325d6 8bce            mov     ecx,esi
00c325d8 684c040000      push    44Ch
00c325dd ff15e451c300    call    dword ptr [GuidGen!_imp_?SetDlgItemTextWCWndQAEXHPB_WZ (00c351e4)]
00c325e3 8d4df0          lea     ecx,[ebp-10h]
00c325e6 ff153c53c300    call    dword ptr [GuidGen!_imp_??1?$CStringT_WV?$StrTraitMFC_DLL_WV?$ChTraitsCRT_WATLATLQAEXZ (00c3533c)]
00c325ec e81b140000      call    GuidGen!_EH_epilog3 (00c33a0c)

0:000> p
(830.67a8): C++ EH exception - code e06d7363 (first chance)
ModLoad: 552b0000 55303000   C:\WINDOWS\SysWOW64\Oleacc.dll
ModLoad: 76410000 76494000   C:\WINDOWS\SysWOW64\SHCORE.dll

희망이 보이는군요. ^^ bp를 다시 잡고,

bp GuidGen!CGuidGenDlg::GetFormattedGuid

restart로 추적하면,

0:000> uf GuidGen!CGuidGenDlg::GetFormattedGuid
GuidGen!CGuidGenDlg::GetFormattedGuid:
00c326bd 6a20            push    20h
00c326bf b84d3cc300      mov     eax,offset GuidGen!memcpy+0xdb (00c33c4d)
00c326c4 e869130000      call    GuidGen!_EH_prolog3 (00c33a32)
00c326c9 8bd9            mov     ebx,ecx
00c326cb 895df0          mov     dword ptr [ebp-10h],ebx
00c326ce 8d4dec          lea     ecx,[ebp-14h]
00c326d1 ff15d853c300    call    dword ptr [GuidGen!_imp_??0?$CStringT_WV?$StrTraitMFC_DLL_WV?$ChTraitsCRT_WATLATLQAEXZ (00c353d8)]
00c326d7 8365fc00        and     dword ptr [ebp-4],0
00c326db 8d4dec          lea     ecx,[ebp-14h]
00c326de 8b83a8000000    mov     eax,dword ptr [ebx+0A8h]
00c326e4 83c068          add     eax,68h
00c326e7 50              push    eax
00c326e8 ff15c851c300    call    dword ptr [GuidGen!_imp_?LoadStringW?$CStringT_WV?$StrTraitMFC_DLL_WV?$ChTraitsCRT_WATLATLQAEHIZ (00c351c8)]
00c326ee 85c0            test    eax,eax
00c326f0 7506            jne     GuidGen!CGuidGenDlg::GetFormattedGuid+0x3b (00c326f8)  Branch

GuidGen!CGuidGenDlg::GetFormattedGuid+0x35:
00c326f2 ff15cc51c300    call    dword ptr [GuidGen!_imp_?AfxThrowInvalidArgExceptionYGXXZ (00c351cc)]

GuidGen!CGuidGenDlg::GetFormattedGuid+0x3b:
00c326f8 0fb683bf000000  movzx   eax,byte ptr [ebx+0BFh]
...[생략]...
00c327b2 c20400          ret     4

다시 "call dword ptr [GuidGen!_imp_?LoadStringW?$CStringT_WV?$StrTraitMFC_DLL_WV?$ChTraitsCRT_WATLATLQAEHIZ" 코드로 문제를 좁힐 수 있고, 그 함수에 진입해 살펴보면,
0:000> uf @eip
mfc140u!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::LoadStringW [d:\agent\_work\3\s\src\vctools\vc7libs\ship\atlmfc\include\cstringt.h @ 2330]:
 2330 5a8742a0 55              push    ebp
 2330 5a8742a1 8bec            mov     ebp,esp
 2330 5a8742a3 56              push    esi
 2331 5a8742a4 ff7508          push    dword ptr [ebp+8]
 2330 5a8742a7 8bf1            mov     esi,ecx
 2331 5a8742a9 e8b283ffff      call    mfc140u!AfxFindStringResourceHandle (5a86c660) // bp mfc140u!AfxFindStringResourceHandle
 2332 5a8742ae 85c0            test    eax,eax
 2332 5a8742b0 740b            je      mfc140u!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::LoadStringW+0x1d (5a8742bd)  Branch

mfc140u!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::LoadStringW+0x12 [d:\agent\_work\3\s\src\vctools\vc7libs\ship\atlmfc\include\cstringt.h @ 2337]:
 2337 5a8742b2 ff7508          push    dword ptr [ebp+8]
 2337 5a8742b5 8bce            mov     ecx,esi
 2337 5a8742b7 50              push    eax
 2337 5a8742b8 e813000000      call    mfc140u!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::LoadStringW (5a8742d0)

mfc140u!ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > >::LoadStringW+0x1d [d:\agent\_work\3\s\src\vctools\vc7libs\ship\atlmfc\include\cstringt.h @ 2337]:
 2337 5a8742bd 5e              pop     esi
 2338 5a8742be 5d              pop     ebp
 2338 5a8742bf c20400          ret     4

AfxFindStringResourceHandle의 반환값(eax)이 null로 나오는 것을 확인할 수 있습니다. 혹시나 싶어서 guidgen.exe가 정상적으로 동작하는 PC에서 위의 과정을 살펴보니 AfxFindStringResourceHandle이 반환하는 값은 다음의 경로에 해당하는 DLL의 로딩 주소였습니다.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\1033\guidgenui.dll

그러고 보니, 문제가 발생한 PC의 경우에는 한글 비주얼 스튜디오가 설치되어 있었고 locale에 따라 1042 폴더 하위에 마찬가지로 guidgenui.dll 파일이 놓여 있었습니다.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\1042\guidgenui.dll

하지만, 정작 guidgen.exe가 실행되었을 때는 guidgenui.dll 파일을 1042로부터 로딩을 하지 않았습니다. 혹시나 싶어서 ^^ 기존의 "1042" 폴더를 그대로 "1033"으로 복사해 실행해 봤더니,

guidgen_not_work_2.png

아주 잘 실행이 되는군요.




그러니까, 문제의 원인은 guidgen.exe가 다국어 지원을 하는 환경은 갖췄지만 정작 코드에서는 영문 locale만을 대상으로 동작하는 버그를 갖고 있던 것입니다. 그렇다 해도 여전히 이해가 안 되는 부분이 있습니다. 일반적으로 다국어 지원은 해당 언어가 없을 때 fallback 차원에서 EXE 스스로 들고 있는 중립 리소스를 사용하는 것이 관례입니다.

실제로 guidgen.exe의 리소스 영역을 열어 보면 String Resource가 마련되어 있고 guidgenui.dll과 동일한 리소스 ID의 값들을 가지고 있습니다. 암튼, 문제 분석은 여기까지 하는 걸로. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/23/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2020-06-04 03시33분
uuidgen -s
정성태

1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13479정성태12/11/20232320개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232508닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232249닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232302닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232164개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232364닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232186C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232246Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232542닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232255닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232214닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232245오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232439닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232186개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232310닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232221오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232273오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232306닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232260닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232238닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232248닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232183VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
13456정성태11/25/20232480닷넷: 2169. C# - OpenAI를 사용해 PDF 데이터를 대상으로 OpenAI 챗봇 작성 [1]파일 다운로드1
13455정성태11/25/20232384닷넷: 2168. C# - Azure.AI.OpenAI 패키지로 OpenAI 사용파일 다운로드1
13454정성태11/23/20232728닷넷: 2167. C# - Qdrant Vector DB를 이용한 Embedding 벡터 값 보관/조회 (Azure OpenAI) [1]파일 다운로드1
13453정성태11/23/20232239오류 유형: 879. docker desktop 설치 시 "Invalid JSON string. (Exception from HRESULT: 0x83750007)"
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...