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)
13018정성태3/29/20226917.NET Framework: 1185. C# - Unsafe.AsPointer가 반환한 포인터는 pinning 상태일까요? [5]
13017정성태3/28/20226767.NET Framework: 1184. C# - GC Heap에 위치한 참조 개체의 주소를 알아내는 방법 - 두 번째 이야기 [3]
13016정성태3/27/20227584.NET Framework: 1183. C# 11에 추가된 ref 필드의 (우회) 구현 방법파일 다운로드1
13015정성태3/26/20228943.NET Framework: 1182. C# 11 - ref struct에 ref 필드를 허용 [1]
13014정성태3/23/20227560VC++: 155. CComPtr/CComQIPtr과 Conformance mode 옵션의 충돌 [1]
13013정성태3/22/20225881개발 환경 구성: 641. WSL 우분투 인스턴스에 파이썬 2.7 개발 환경 구성하는 방법
13012정성태3/21/20225214오류 유형: 803. C# - Local '...' or its members cannot have their address taken and be used inside an anonymous method or lambda expression
13011정성태3/21/20226672오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/20225637오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/20227191개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/20226452VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/20226144.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/20227161.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/20226061오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/20226086디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/20226226.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/20226978.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/20227361.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/20226939.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/20226435.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/20226047.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202210356오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202215571VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
12995정성태3/8/20227878.NET Framework: 1173. .NET에서 Producer/Consumer를 구현한 BlockingCollection<T>
12994정성태3/8/20227169오류 유형: 798. WinDbg - Failed to load data access module, 0x80004002
12993정성태3/4/20226959.NET Framework: 1172. .NET에서 Producer/Consumer를 구현하는 기초 인터페이스 - IProducerConsumerCollection<T>
... 16  17  18  19  20  21  22  23  [24]  25  26  27  28  29  30  ...