성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
[정성태] 저렇게 조각 코드 말고, 실제로 재현이 되는 예제 프로젝트를 압...
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Visual Studio 2019 + WDK Legacy Driver 제작- Hello World 예제</h1> <p> 예전에 해본 적이 있었는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Visual Studio 2010 - Device Driver 제작- Hello World 예제 ; <a target='tab' href='http://www.sysnet.pe.kr/2/0/919'>http://www.sysnet.pe.kr/2/0/919</a> </pre> <br /> 2019 환경으로 오면서 빌드 환경이 많이 개선되어 ^^ 더욱 편해졌습니다. WDK 설치한 다음,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Download the Windows Driver Kit (WDK) ; <a target='tab' href='https://learn.microsoft.com/ko-kr/windows-hardware/drivers/download-the-wdk'>https://learn.microsoft.com/ko-kr/windows-hardware/drivers/download-the-wdk</a> </pre> <br /> 신규 프로젝트를 "Empty WDM Driver" 유형으로 생성하고 지난 예제와 마찬가지로 간단하게 DriverMain.c 파일을 아래의 코드로 채운 다음,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > #include <ntddk.h> VOID DriverUnload(PDRIVER_OBJECT pDriverObject) { UNREFERENCED_PARAMETER(pDriverObject); DbgPrint("Driver Unload\n"); } NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath) { UNREFERENCED_PARAMETER(pRegistryPath); DbgPrint("DriverEntry\n"); pDriverObject->DriverUnload = DriverUnload; return STATUS_SUCCESS; } </pre> <br /> 빌드하면 됩니다. 이 와중에 만약 Visual Studio 2019 구성 요소 중 "Spectre-mitigated libs"를 설치하지 않았다면 다음과 같은 빌드 오류가 발생할 수 있습니다.<br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(428,5): error MSB8040: <span style='color: blue; font-weight: bold'>Spectre-mitigated libraries are required for this project.</span> Install them from the Visual Studio installer (Individual components tab) for any toolsets and architectures being used. Learn more: <span style='color: blue; font-weight: bold'>https://aka.ms/Ofhn4c</span> </div><br /> <br /> 해당 링크를 누르면 "<a target='tab' href='https://learn.microsoft.com/en-us/cpp/build/reference/qspectre?view=vs-2019'>https://learn.microsoft.com/en-us/cpp/build/reference/qspectre?view=vs-2019</a>" 페이지로 안내하는데 그러니까 Visual C++ Compiler 옵션에 자동으로 "/Qspectre"가 설정되므로 해당 구성 요소를 설치해야 한다는 것입니다.<br /> <br /> 이를 위해 우선 WDM 프로젝트의 "Platform Toolset"을 확인하고,<br /> <br /> <img alt='wdk_build_2019_1.png' src='/SysWebRes/bbs/wdk_build_2019_1.png' /><br /> <br /> Visual Studio 2019의 "Tools" / "Get Tools and Features..." 메뉴를 선택해 다음과 같이 "Spectre-mitigated libs" 항목을 설치합니다.<br /> <br /> <img alt='wdk_build_2019_2.png' src='/SysWebRes/bbs/wdk_build_2019_2.png' /><br /> <br /> <hr style='width: 50%' /><br /> <br /> 정상적으로 빌드가 되었으면 이제 테스트를 해봐야겠지요. ^^ <a target='tab' href='https://www.osronline.com/article.cfm%5Earticle=157.htm'>.\kit\WNET\AMD64\FRE\OSRLOADER.exe</a>를 이용해 테스트해 보면,<br /> <br /> <img alt='wdk_build_2019_3.png' src='/SysWebRes/bbs/wdk_build_2019_3.png' /><br /> <br /> "Register Service" 버튼까지는 잘 되지만 "Start Service" 단계에서 다음과 같은 식의 오류가 발생할 것입니다.<br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> Windows cannot verify the digital signature for this file. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source.<br /> </div><br /> <br /> <a name='signing'></a> 따라서 서명 작업을 거쳐야 하는데 Visual Studio 2019의 경우 WDM 프로젝트 속성 창에서 다음과 같이 옵션으로 제공하기 때문에,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='wdk_build_2019_4.png' src='/SysWebRes/bbs/wdk_build_2019_4.png' /><br /> <br /> 정식 인증서 (업데이트: 2023-05-09 현재 교차 인증서는 필요 없습니다.)<strike>와 함께 그 인증서를 발급한 루트 인증 기관의 교차 인증서만 다운로드해 "Cross-Signing Certificate"에</strike> 지정해 주면 됩니다. (<strike>교차 인증서 구하는 방법은 "<a target='tab' href='http://www.sysnet.pe.kr/2/0/2914'>정식 인증서가 있는 경우 Device Driver 서명하는 방법</a>" 글을 참고</strike>)<br /> <br /> 참고로 위의 화면에서 "File Digest Algorithm" 항목의 기본 값은 sha1이기 때문에 sha256 방식으로 서명하고 싶다면 명시적으로 지정해야 합니다.<br /> <br /> (만약 정식 인증서가 없다면 테스트 인증서로만 서명 후 여러분들의 운영체제 환경을 디버그 모드로 전환하시면 됩니다. [<a target='tab' href='https://www.sysnet.pe.kr/2/0/2904'>참고</a>])<br /> <br /> 여기까지 적용했으면 이제 OSR Loader로 "Start Service"와 "Stop Service" 버튼을 누를 때마다 소스 코드에 넣은 DbgPrint에 따라 DebugView에 다음과 같이 메시지가 출력되는 것을 확인할 수 있습니다.<br /> <br /> <img alt='wdk_build_2019_5.png' src='/SysWebRes/bbs/wdk_build_2019_5.png' /><br /> <br /> (커널 디버그 출력을 보려면 "Capture" / "Capture Kernel"과 "Enable Verbose Kernel Output" 설정을 체크해야 합니다.)<br /> <br /> <hr style='width: 50%' /><br /> <br /> 또는, 단순하게 <a target='tab' href='https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create'>sc 명령어</a>를 이용하는 것도 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > sc create mydriver1 binpath= "c:\temp\MyDriver1\x64\Debug\MyDriver1.sys" displayname= "mydriver1" start= demand type= kernel sc query mydriver1 sc start mydriver1 sc stop sc delete </pre> <br /> 마지막으로, Windows 10에서도 Legacy Kernel driver 유형의 프로그램은 EV 인증서로 서명하지 않아도 잘 동작합니다. (정식 인증 과정: <a target='tab' href='https://www.youtube.com/watch?v=3dIp_-adDQ4'>WHQL 인증</a>) 물론, Filter 드라이버 등을 구현한다면 EV 인증서가 필요합니다.<br /> <br /> (<a target='tab' href='https://www.sysnet.pe.kr/bbs/DownloadAttachment.aspx?fid=1520&boardid=331301885'>첨부 파일은 이 글의 예제 프로젝트를 포함</a>합니다.)<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1956
(왼쪽의 숫자를 입력해야 합니다.)