J'essaie d'écrire un injecteur dll avec nativeApi. Pour cette raison, j'ai écrit ce code. La fonction NtReadFile lit quelque chose mais je ne vois rien à part la première valeur de FileReadBuffer. Aussi, je ne sais rien sur la façon dont dll se pencher sur le tampon.Comment puis-je voir le contenu de la mémoire tampon et comparer avec le fichier dll?
(1) Comment puis-je comparer le tampon et le fichier dll?
(2) Comment puis-je m'assurer que le code est correct?
(3) Et s'il vous plaît dites-moi mon erreur dans le code.
bool Injector::initiationDll(const std::string& dllPath)
{
if (!isDllExist(dllPath))
{
printf("Dll not found!\n");
return false;
}
else
{
printf("LibraryPath: %s\n", dllPath);
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_READ | FILE_READ_DATA | SYNCHRONIZE,
&objAttribs,
&ioStatusBlock,
&largeInteger,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
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 is zero.\n");
return false;
}
else
{
printf("File size : %d byte.\n", fileSize);
PVOID FileReadBuffer = VirtualAlloc(NULL, fileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!FileReadBuffer)
{
printf("\nError: Unable to allocate memory(%d)\n", GetLastError());
status = NtClose(lFile);
return false;
}
else {
printf("Allocate %d byte for buffer.\n", 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;
}
else {
status = NtClose(lFile);
for (int i = 0; i < sizeof(fileSize); i++)
{
//wprintf(L"%p : %s\n", FileReadBuffer, FileReadBuffer);
}
}
}
}
}
}
}
Le bon outil pour résoudre ces problèmes est votre débogueur. Vous devez parcourir votre code ligne par ligne * avant * de demander Stack Overflow. Pour plus d'aide, veuillez lire [Comment déboguer de petits programmes (par Eric Lippert)] (https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). Au minimum, vous devriez [modifier] votre question pour inclure un exemple [Minimal, complet et vérifiable] (http://stackoverflow.com/help/mcve) qui reproduit votre problème, ainsi que les observations que vous avez faites dans le débogueur. –
@ πάνταῥεῖ Votre ['edit]' chose est en quelque sorte cassée. –
@BaummitAugen Il ne peut pas être don d'une manière générique IIRC –