Ist sicherlich ne ganz einfach Frage, aber wie verwende ich die TFilestreams genau?
Also folgender Code:
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 savestream,loadstream :tfilestream; lpBuffer: Pointer; 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 =(