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)
13503정성태12/27/20232191Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
13502정성태12/26/20232298닷넷: 2187. C# - 다른 프로세스의 환경변수 읽는 예제파일 다운로드1
13501정성태12/25/20232098개발 환경 구성: 700. WSL + uwsgi - IPv6로 바인딩하는 방법
13500정성태12/24/20232180디버깅 기술: 194. Windbg - x64 가상 주소를 물리 주소로 변환
13498정성태12/23/20232857닷넷: 2186. 한국투자증권 KIS Developers OpenAPI의 C# 래퍼 버전 - eFriendOpenAPI NuGet 패키지
13497정성태12/22/20232296오류 유형: 885. Visual Studiio - error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
13496정성태12/21/20232311Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
13495정성태12/20/20232322Linux: 65. clang++로 공유 라이브러리의 -static 옵션 빌드가 가능할까요?
13494정성태12/20/20232502Linux: 64. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) - 두 번째 이야기
13493정성태12/19/20232563닷넷: 2185. C# - object를 QueryString으로 직렬화하는 방법
13492정성태12/19/20232266개발 환경 구성: 699. WSL에 nopCommerce 예제 구성
13491정성태12/19/20232233Linux: 63. 리눅스 - 다중 그룹 또는 사용자를 리소스에 권한 부여
13490정성태12/19/20232350개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/20232136개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232069오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232383개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232197개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232088오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232162개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232301닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20232877닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232271개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232612개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232309개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232484닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232212닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...