Registriert seit: 6. Okt 2003
372 Beiträge
|
Re: Dateien an eine exe Datei mit dranhängen
13. Jan 2004, 10:28
ich hab sowas auch mal gemacht: Ich habe sfs-dateien an exe-dateien angehängt, das geht aber auch mit allen anderen dateien, und zwar hab ich das so gemacht:
Delphi-Quellcode:
function AppendSFSFileToExe(const aExeFile, aSFSFile, aOutFile: string): Boolean;
var
ExeStream, SFSStream, OutStream: TFileStream;
SizeExe, SizeSFS: LongInt;
begin
Result := False;
if (aSFSFile <> '') and (aExeFile <> '') then
begin
OutStream := TFileStream.Create(aOutFile, fmCreate);
ExeStream := TFileStream.Create(aExeFile, fmOpenRead);
SFSStream := TFileStream.Create(aSFSFile, fmOpenRead);
OutStream.CopyFrom(ExeStream, ExeStream.Size);
OutStream.CopyFrom(SFSStream, SFSStream.Size);
SizeExe := ExeStream.Size;
SizeSFS := SFSStream.Size;
OutStream.Write(SizeExe, SizeOf(SizeExe));
OutStream.Write(SizeSFS, SizeOf(SizeSFS));
ExeStream.Free;
SFSStream.Free;
OutStream.Free;
Result := True;
end;
end;
function ExtractSFSFileFromExe(const aFileName: string): string;
var
InStream, SFSStream: TFileStream;
SizeExe, SizeSFS: LongInt;
SFSFile: string;
begin
Result := '';
if not FileExists(aFileName) then exit;
InStream := TFileStream.Create(aFileName, fmOpenRead);
InStream.Position := InStream.Size - SizeOf(SizeExe) - SizeOf(SizeSFS);
InStream.Read(SizeExe, SizeOf(SizeExe));
InStream.Position := InStream.Size - SizeOf(SizeSFS);
InStream.Read(SizeSFS, SizeOf(SizeSFS));
if SizeExe + SizeSFS + SizeOf(SizeExe) + SizeOf(SizeSFS) <> InStream.Size then
InStream.Free
else begin
SFSFile := utlWindows.GetTempFileName('.sfs');
SFSStream := TFileStream.Create(SFSFile, fmCreate);
InStream.Position := SizeExe;
SFSStream.CopyFrom(InStream, SizeSFS);
SFSStream.Free;
InStream.Free;
Result := SFSFile;
end;
end;
|
|
Zitat
|