![]() |
Modify Resource im Speicher
Hallo
Ich möchte gerne eine DFM (RC_DATA) Resource im Speicher modifizieren. Bisher habe ich nur gefunden wie ich mit UpdateResource + BeginUpdateResource eine EXE Datei modizifzieren kann. und dieses Stückchen Code
Delphi-Quellcode:
Das wäre im Prinzip schon sowas was ich brauche, nur habe ich das Problem das ich da den Inhalt nicht nur überschreiben will, osndenr sich auch die Größe ändert (kleiner - geht ja eventuell) aber auch größer.
procedure WriteResource(const ResName: string; ResType: PChar; data : PChar; len : integer);
var Res: HRSRC; ResHandle: HGLOBAL; Ptr: Pointer; OldProtect: DWORD; begin Res := FindResource(HInstance, PChar(ResName), ResType); Win32Check(Res <> 0); ResHandle := LoadResource(HInstance, Res); Win32Check(ResHandle <> 0); Ptr := LockResource(ResHandle); Win32Check(Ptr <> nil); Win32Check(VirtualProtect(Ptr, SizeofResource(HInstance, Res), PAGE_READWRITE, OldProtect)); ZeroMemory(Ptr, SizeofRes ource(HInstance, Res)); Win32Check(VirtualProtect(Ptr, SizeofResource(HInstance, Res), OldProtect, OldProtect)); end; Hat da wer eine Idee? |
AW: Modify Resource im Speicher
Ich habe es noch nicht versucht aber ich würde zu erst es so probieren wie es Microsoft
![]() C++ Code Auszug vom Beispiel:
Delphi-Quellcode:
HGLOBAL hResLoad; // handle to loaded resource
HMODULE hExe; // handle to existing .EXE file HRSRC hRes; // handle/ptr. to res. info. in hExe HANDLE hUpdateRes; // update resource handle LPVOID lpResLock; // pointer to resource data BOOL result; #define IDD_HAND_ABOUTBOX 103 #define IDD_FOOT_ABOUTBOX 110 // Load the .EXE file that contains the dialog box you want to copy. hExe = LoadLibrary(TEXT("hand.exe")); if (hExe == NULL) { ErrorHandler(TEXT("Could not load exe.")); return; } // Locate the dialog box resource in the .EXE file. hRes = FindResource(hExe, MAKEINTRESOURCE(IDD_HAND_ABOUTBOX), RT_DIALOG); if (hRes == NULL) { ErrorHandler(TEXT("Could not locate dialog box.")); return; } // Load the dialog box into global memory. hResLoad = LoadResource(hExe, hRes); if (hResLoad == NULL) { ErrorHandler(TEXT("Could not load dialog box.")); return; } // Lock the dialog box into global memory. lpResLock = LockResource(hResLoad); if (lpResLock == NULL) { ErrorHandler(TEXT("Could not lock dialog box.")); return; } // Open the file to which you want to add the dialog box resource. hUpdateRes = BeginUpdateResource(TEXT("foot.exe"), FALSE); if (hUpdateRes == NULL) { ErrorHandler(TEXT("Could not open file for writing.")); return; } // Add the dialog box resource to the update list. result = UpdateResource(hUpdateRes, // update resource handle RT_DIALOG, // change dialog box resource MAKEINTRESOURCE(IDD_FOOT_ABOUTBOX), // dialog box id MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language lpResLock, // ptr to resource info SizeofResource(hExe, hRes)); // size of resource info if (result == FALSE) { ErrorHandler(TEXT("Could not add resource.")); return; } // Write changes to FOOT.EXE and then close it. if (!EndUpdateResource(hUpdateRes, FALSE)) { ErrorHandler(TEXT("Could not write changes to file.")); return; } // Clean up. if (!FreeLibrary(hExe)) { ErrorHandler(TEXT("Could not free executable.")); return; } |
AW: Modify Resource im Speicher
Der code ändert ja nur eine Resource in der Exe Datei, ich "muss" die Resource in der bereits geladene EXE im Speicher umändern.
Mittlerweile verfolge ich einen anderen Ansatz, indem ich einen Hook auf die Classes.InitInheritedComponent mache, und dann die TResourceStream umändere. Das könnte ach funtkionieren, aber die Resource selber ändern wäre mir noch lieber. |
AW: Modify Resource im Speicher
Gehen wir doch mal einen Schritt weiter weg: Was hast du eigentlich vor?
|
AW: Modify Resource im Speicher
ich möchte die DFM die in der EXE eingebunden sind zur Laufzeit patchen.
|
AW: Modify Resource im Speicher
Hallo Hans,
nur als eine mögliche Idee: Mit MemoryModule.pas / FuncHook.pas/ MemoryModuleHook.pas ![]() und/oder ![]() kann man Resourcen z.B. aus DLL’s in den Speicher laden und ausführen. Vielleicht kann man damit auf die Resourece auch schreibend zugreifen und modifizieren? Gruß, Andreas |
AW: Modify Resource im Speicher
Zitat:
|
AW: Modify Resource im Speicher
DLL/EXE laden, ohne sie zu "laden" (starten), dann würde ich dafür LoadLibraryEx+LOAD_LIBRARY_AS_DATAFILE verwenden.
Aber ganz im Ernst, wenn, dann mach es doch einfach so, wie so manche Übersetzungskomponente, also hooke die Lade-Funktionen und gibt einen Zeiger auf was Anderes zurück. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz