Announcement

Collapse
No announcement yet.

Geladene DLL's in Windows

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Geladene DLL's in Windows

    Wie kann ich alle geladenen DLL's in Windows auslesen?

  • #2
    Hallo,

    der folgende Quelltexte zeigt dir alle geladenen DLL's und EXE's in einer Listbox an. Ich hatte den Code mal so erweitert, das nur EXE Dateien angezeigt werden, kann ihn aber nicht wiederfinden. Dieses kannst du aber leicht selbst dazu programmieren. Bevor der Eintrag in die ListBox gesetzt wirst, überprüfst du die letzten drei Zeichen des Eintrags, ob diese DLL lauten. Hierzu hilft dir Z.B. die VCL Funktion SubString. Wenn das der Fall ist, setzt du den Eintrag in die ListBox, andernfalls nicht. Viel Glück.

    <pre>
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop

    #include <tlhelp32.hpp>
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------

    bool TForm1::GetProcessModule(DWORD ProcessID, DWORD ModuleID,
    MODULEENTRY32* CallerModuleEntry){

    HANDLE ModuleSnapHandle = CreateToolhelp32Snapshot(
    TH32CS_SNAPMODULE, ProcessID);

    if(ModuleSnapHandle == reinterpret_cast <HANDLE> (-1))
    return false;

    MODULEENTRY32 ProcessModuleEntry;
    memset(&ProcessModuleEntry, 0, sizeof(MODULEENTRY32));
    ProcessModuleEntry.dwSize = sizeof(MODULEENTRY32);

    bool Found = false;

    if(Module32First(ModuleSnapHandle, &ProcessModuleEntry))
    {
    do
    {
    if(ProcessModuleEntry.th32ModuleID == ModuleID)
    {
    memcpy(CallerModuleEntry, &ProcessModuleEntry, sizeof(MODULEENTRY32));
    Found = true;
    }
    }while(!Found && Module32Next(ModuleSnapHandle, &ProcessModuleEntry));
    }

    CloseHandle(ModuleSnapHandle);

    return Found;
    }
    //---------------------------------------------------------------------------

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    ListBox1->Clear();

    HANDLE ProcessSnapHandle = CreateToolhelp32Snapshot(
    TH32CS_SNAPPROCESS, 0);

    if(ProcessSnapHandle == reinterpret_cast <HANDLE> (-1))
    {
    ShowMessage("CreateToolhelp32Snapshot() failed");
    return;
    }

    PROCESSENTRY32 ProcessEntry;
    ProcessEntry.dwSize = sizeof(PROCESSENTRY32);

    if(Process32First(ProcessSnapHandle, &ProcessEntry))
    {
    MODULEENTRY32 ModuleEntry;
    memset(&ModuleEntry, 0, sizeof(MODULEENTRY32));

    do
    {
    bool GotModule = GetProcessModule(ProcessEntry.th32ProcessID,
    ProcessEntry.th32ModuleID, &ModuleEntry);

    if(GotModule)
    ListBox1->Items->Add(ModuleEntry.szExePath);

    }while(Process32Next(ProcessSnapHandle, &ProcessEntry));

    }

    CloseHandle(ProcessSnapHandle);
    }
    //---------------------------------------------------------------------------

    </pre>

    Ciao Philip

    Comment


    • #3

      Comment

      Working...
      X