Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mo 21.05.07 10:44 
Ist sicherlich ne ganz einfach Frage, aber wie verwende ich die TFilestreams genau?
Also folgender Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
procedure getsections(name:String;a:TStrings);
var
  { Datei Öffnen }
  savestream,loadstream :tfilestream;
  { Zwischenspeicherung }
  lpBuffer: Pointer;
  { PE-Stuff }
  Alignment: dword;
  ImageNtHeaders: PImageNtHeaders;
  PSections: ^TSections;
  SectionLoop,i: dword;
  s:String;
begin
  loadstream := tfilestream.Create(name,fmOpenRead);
  getmem(lpBuffer,loadstream.size );
  loadstream.read(lpBuffer^,loadstream.Size);
  ImageNtHeaders := PImageNtHeaders(Cardinal(lpBuffer) + Cardinal(PImageDosHeader(lpBuffer)._lfanew));
  PSections := pointer(pchar(@(ImageNtHeaders.OptionalHeader)) + ImageNtHeaders.FileHeader.SizeOfOptionalHeader);
  for SectionLoop := 0 to ImageNtHeaders.FileHeader.NumberOfSections - 1 do
  begin
    if PSections[SectionLoop].Misc.VirtualSize <> 0 then
    begin
      s:='';
      For i:=0 to Length(PSections[SectionLoop].name)-1 do begin
        if(PSections[SectionLoop].name[i]=0) then break;
        s:=s+chr(PSections[SectionLoop].name[i]);
      end;
      a.add(s+' '+inttohex(PSections[SectionLoop].VirtualAddress,8)+' '+inttohex(PSections[SectionLoop].Sizeofrawdata,8)+' '+inttohex(PSections[SectionLoop].Misc.VirtualSize,8)+' '+inttohex(PSections[SectionLoop].Characteristics,8));
      if(s='.rsrc') then begin
        PSections[SectionLoop].Sizeofrawdata:=PSections[SectionLoop].Sizeofrawdata+255;
      end;
    end;
  end;
  savestream := TFilestream.Create('TEMP.exe',fmCreate);
  savestream.CopyFrom(loadstream,0);
  loadstream.Free;
  savestream.Free;
end;


Kurze Erklärung:
1) Datei öffnen und in TStream laden
2) Header auslesen+ändern wenn sectionname='.rsrc'

Jetzt will ich die so veränderte "Datei" speichern. Wie mach ich das?
Meine Variante geht leider ne =(
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Do 24.05.07 10:35 
Versuch mal das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
savestream := TFilestream.Create('TEMP.exe',fmCreate);
// HINZUFÜGEN
loadstream.Position := 0; // damit loadstream wieder am anfang steht. sonst lässt er sich nicht kopieren
// ENDE HINZUFÜGEN
savestream.CopyFrom(loadstream,0);
loadstream.Free;
savestream.Free;