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
정성태

... 16  17  18  [19]  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13147정성태10/25/20224761오류 유형: 823. Visual Studio 2022 - Unable to attach to CoreCLR. The debugger's protocol is incompatible with the debuggee.
13146정성태10/24/20225590.NET Framework: 2060. C# - Java의 Xmx와 유사한 힙 메모리 최댓값 제어 옵션 HeapHardLimit
13145정성태10/21/20225855오류 유형: 822. db2 - Password validation for user db2inst1 failed with rc = -2146500508
13144정성태10/20/20225700.NET Framework: 2059. ClrMD를 이용해 윈도우 환경의 메모리 덤프로부터 닷넷 모듈을 추출하는 방법파일 다운로드1
13143정성태10/19/20226223오류 유형: 821. windbg/sos - Error code - 0x000021BE
13142정성태10/18/20224945도서: 시작하세요! C# 12 프로그래밍
13141정성태10/17/20226708.NET Framework: 2058. [in,out] 배열을 C#에서 C/C++로 넘기는 방법 - 세 번째 이야기파일 다운로드1
13140정성태10/11/20226076C/C++: 159. C/C++ - 리눅스 환경에서 u16string 문자열을 출력하는 방법 [2]
13139정성태10/9/20225910.NET Framework: 2057. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프로부터 모든 닷넷 모듈을 추출하는 방법파일 다운로드1
13138정성태10/8/20227193.NET Framework: 2056. C# - await 비동기 호출을 기대한 메서드가 동기로 호출되었을 때의 부작용 [1]
13137정성태10/8/20225586.NET Framework: 2055. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프로부터 닷넷 모듈을 추출하는 방법
13136정성태10/7/20226160.NET Framework: 2054. .NET Core/5+ SDK 설치 없이 dotnet-dump 사용하는 방법
13135정성태10/5/20226404.NET Framework: 2053. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프를 분석하는 방법 - 두 번째 이야기
13134정성태10/4/20225135오류 유형: 820. There is a problem with AMD Radeon RX 5600 XT device. For more information, search for 'graphics device driver error code 31'
13133정성태10/4/20225452Windows: 211. Windows - (commit이 아닌) reserved 메모리 사용량 확인 방법 [1]
13132정성태10/3/20225322스크립트: 42. 파이썬 - latexify-py 패키지 소개 - 함수를 mathjax 식으로 표현
13131정성태10/3/20227985.NET Framework: 2052. C# - Windows Forms의 데이터 바인딩 지원(DataBinding, DataSource) [2]파일 다운로드1
13130정성태9/28/20225090.NET Framework: 2051. .NET Core/5+ - 에러 로깅을 위한 Middleware가 동작하지 않는 경우파일 다운로드1
13129정성태9/27/20225386.NET Framework: 2050. .NET Core를 IIS에서 호스팅하는 경우 .NET Framework CLR이 함께 로드되는 환경
13128정성태9/23/20227948C/C++: 158. Visual C++ - IDL 구문 중 "unsigned long"을 인식하지 못하는 #import파일 다운로드1
13127정성태9/22/20226411Windows: 210. WSL에 systemd 도입
13126정성태9/15/20227025.NET Framework: 2049. C# 11 - 정적 메서드에 대한 delegate 처리 시 cache 적용
13125정성태9/14/20227235.NET Framework: 2048. C# 11 - 구조체 필드의 자동 초기화(auto-default structs)
13124정성태9/13/20226976.NET Framework: 2047. Golang, Python, C#에서의 CRC32 사용
13123정성태9/8/20227413.NET Framework: 2046. C# 11 - 멤버(속성/필드)에 지정할 수 있는 required 예약어 추가
13122정성태8/26/20227415.NET Framework: 2045. C# 11 - 메서드 매개 변수에 대한 nameof 지원
... 16  17  18  [19]  20  21  22  23  24  25  26  27  28  29  30  ...