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)
13533정성태1/18/20242450닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242345닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242235닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242190닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20242051닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242178Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20242107오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242204닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242158오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242220오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20242028오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242190닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242256닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20242001오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20242093닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242353닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242198스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242304닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242582닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242255개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242176닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20242143개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20242162닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20242099닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20242122오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242141오류 유형: 886. ORA-28000: the account is locked
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...