nativeApi로 dll injector를 작성하려고합니다. 나의 첫 번째 질문은 그것을하는 좋은 방법인가? 둘째 : NtReadFile은 실패하지 않지만 읽지 않습니다. 버퍼가 잘못되었다고 생각하지만 확실하지 않습니까? 이 문제를 어떻게 해결할 수 있습니까? NtCreateFile를 들어NtReadFile이 읽지 않습니다
bool initiationDll(const std::string& dllPath){
if (!isDllExist(dllPath))
{
printf("Dll doesn't exist!\n");
return false;
}
else
{
printf("LibraryPath :%s\n", dllPath.c_str());
NTSTATUS status;
HANDLE lFile;
OBJECT_ATTRIBUTES objAttribs = { 0 };
UNICODE_STRING unicodeString;
std::string dllPathWithprefix = "\\??\\" + dllPath;
std::wstring wString = std::wstring(dllPathWithprefix.begin(), dllPathWithprefix.end()); PCWSTR toPcwstr = wString.c_str();
RtlInitUnicodeString(&unicodeString, toPcwstr);
InitializeObjectAttributes(&objAttribs, &unicodeString, OBJ_CASE_INSENSITIVE, NULL, NULL);
objAttribs.Attributes = 0;
const int allocSize = 2048;
LARGE_INTEGER largeInteger;
largeInteger.QuadPart = allocSize;
IO_STATUS_BLOCK ioStatusBlock;
status = NtCreateFile(
&lFile,
GENERIC_ALL,
&objAttribs,
&ioStatusBlock,
&largeInteger,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
NULL
);
if (!NT_SUCCESS(status)) {
printf("CreateFile failed..\n");
return false;
}
else {
printf("Library Handle : %p\n", lFile);
DWORD fileSize = getDllSize(dllPath);
if (fileSize == 0)
{
printf("File size 0.\n");
return false;
}
else
{
printf("File size : %d byte.\n", fileSize);
PVOID FileReadBuffer;
FileReadBuffer = new CHAR[fileSize];
status = NtReadFile(
lFile,
NULL,
NULL,
NULL,
&ioStatusBlock,
FileReadBuffer,
sizeof(FileReadBuffer),
0, // ByteOffset
NULL);
if (!NT_SUCCESS(status))
{
printf("Unable to read the dll... : %d\n", GetLastError());
return false;
}
}
}}
:
status -> 0
ioStatusBlock : Status -> 0
Pointer -> 0x00000000
Information -> 1
내가 NtOpenFile과 같은 결과를 시도
는 이제 다음과 같이합니다. NtReadFile를 들어
:
status -> -1073741811
ioStatusBlock : Status -> 0
Pointer -> 0x00000000
Information -> 1
Result values right after NtCreateFile function
Result values right after NtReadFile function
그냥'NtReadFile' 호출 후 중단 점을 넣고 반환 값을 확인 값. GetLastError()는 네이티브 API가 아닌 Windows API를 사용할 때만 설정되므로 여기서는 도움이되지 않습니다. – MrEricSir