Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Upisivanje neke vrednosti u exe fajlu

[es] :: Pascal / Delphi / Kylix :: Upisivanje neke vrednosti u exe fajlu

[ Pregleda: 1737 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mica99
Srbija

Član broj: 243749
Poruke: 90
*.dynamic.isp.telekom.rs.



+1 Profil

icon Upisivanje neke vrednosti u exe fajlu21.07.2015. u 01:26 - pre 106 meseci
Hocu da napravim mali programcic koji upisuje neke vrednosti u exe ili dll fajl tipa user name i password.
Sa borland delphi 7 sam to uspeo pomocu citanje i pisanje konstanti ali u ebarcadero to ne radi.
Nasao sam ovo http://edn.embarcadero.com/article/27979

Zatim sam nasao i kod koji radi dobro ali ima jednu manu. Moze da se upisuje samo po jedna vrednost. tj. svaaka sledeca vrednost brise prethodnu

Evo i programa pomocu kojeg mogu da generisem i upisujem password, ali kako mogu da na drugu poziciju postavim drugu vrednost.?

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Spin;

//const
//our ExeBuffer signature
// ExeBufSig = 'EB1.0';

type
//the Footer for our executable format
TExeBufFooter = record
OriginalSize : Integer;
Sig : Integer; // Array[0..4] of char;
end;

TExeBuf = array of char;

TForm1 = class(TForm)

btn1: TBitBtn;
btn2: TBitBtn;
dlgOpen1: TOpenDialog;
edt1: TEdit;
edt2: TEdit;
se1: TSpinEdit;
se2: TSpinEdit;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure SetExeData (ExeName : String; ExeBuf : TExeBuf ; ExeBufSig:integer);
procedure GetExeData (ExeName : String; var ExeBuf : TExeBuf;ExeBufSig:integer);
procedure StringToExeBuf (const S : String; var ExeBuf : TExeBuf);
function ExeBufToString (const ExeBuf : TExeBuf) : String;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
function RandomPassword(PLen: Integer): string;
var
str: string;
begin
Randomize;
//string with all possible chars
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
Result := '';
repeat
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = PLen)
end;
procedure TForm1.SetExeData (ExeName : String; ExeBuf : TExeBuf ; ExeBufSig:integer);
var
F : File;
BufSz,OrigSz : Integer;
Footer : TExeBufFooter;
begin
AssignFile (F,ExeName);
Reset (F,1);
try
//obtaining the original file size
OrigSz := FileSize(F);
//go to the EOF of the file
Seek (F,OrigSz);
//Writing our custom data beyond the EOF
BufSz := Length(ExeBuf);
BlockWrite (F,Pointer(ExeBuf)^,BufSz);
//Writing our footer
FillChar (Footer,SizeOf(Footer),0);
Footer.OriginalSize := OrigSz;
Footer.Sig := ExeBufSig;
BlockWrite (F,Footer,Sizeof(Footer));
finally
CloseFile (F);
end;
end;

procedure TForm1.GetExeData (ExeName : String; var ExeBuf : TExeBuf;ExeBufSig:integer);
var
F : File;
CurrSz, BufSize : Integer;
OldFileMode : Integer;
Footer : TExeBufFooter;
begin
AssignFile (F,ExeName);
//Saving the old FileMode
OldFileMode := FileMode;
//Setting the FileMode to ReadOnly
FileMode := 0;
try
Reset (F,1);
try
//Getting the current file size
CurrSz := FileSize (F);
//Seeking to the footer position
//and reading it
Seek (F,CurrSz-SizeOf (Footer));
BlockRead (F,Footer,Sizeof(Footer));
//if there's no signature, boom!
//no data in this executable!
if Footer.Sig <> ExeBufSig then begin
//raise EExeBuf.Create
ShowMessage ('No Data in EXE!');
Exit;
end;
//calculating the buffer size that was written
//to this executable file
BufSize :=CurrSz-Footer.OriginalSize-SizeOf(Footer);
SetLength (ExeBuf,BufSize);
//seek and read!
Seek (F,Footer.OriginalSize);
BlockRead(F,Pointer(ExeBuf)^, BufSize);
finally
CloseFile (F);
end;
finally
//returning to the previous saved
//FileMode
FileMode := OldFileMode;
end;
end;

procedure TForm1.StringToExeBuf (const S : String; var ExeBuf : TExeBuf);
begin
SetLength(ExeBuf,Length(S)*SizeOf(Char));
Move (Pointer(S)^,Pointer(ExeBuf)^,Length(S)*SizeOf(Char));
end;



function TForm1.ExeBufToString (const ExeBuf : TExeBuf) : String;
begin
SetLength (Result,Length(ExeBuf) div SizeOf(Char));
Move (Pointer(ExeBuf)^,Pointer(Result)^,Length(ExeBuf)* SizeOf(Char));
end;


procedure TForm1.btn1Click(Sender: TObject);
var
ExeBuf, ExeBuf2 : TExeBuf;
begin
if not dlgOpen1.Execute then Exit;
StringToExeBuf(edt1.Text, ExeBuf);
SetExeData(dlgOpen1.FileName, ExeBuf,se1.Value); //----'c:\Project1.exe'

end;

procedure TForm1.btn2Click(Sender: TObject);
var
ExeBuf, ExeBuf2 : TExeBuf;
begin
if not dlgOpen1.Execute then Exit;
GetExeData(dlgOpen1.FileName, ExeBuf2,se2.Value);
// ShowMessage(ExeBufToString(ExeBuf2));
edt2.Text :=ExeBufToString(ExeBuf2)
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
edt1.text:=RandomPassword(20);
end;

end.

 
Odgovor na temu

savkic
Igor Savkić

Moderator
Član broj: 92186
Poruke: 2739



+92 Profil

icon Re: Upisivanje neke vrednosti u exe fajlu21.07.2015. u 21:25 - pre 106 meseci
Moraš smisliti odgovarajući format koji to podržava, npr. na postojeći (čist exe) nalepiš sadržaj kakav god hoćeš recimo sadržaj StringListe, onda na kraj toga dodaš još dva podatka dužine po 4 bajta (Integer), prvi je originalna veličina fajla (čist exe) odnosno bajt od koga počinju tvoji podaci a drugi je veličina dodatog dela. Ako hoćeš možeš skratiti postupak i samo čuvati jedan podakat, originalna večičina fajla.

Kod čitanja prvo čitaš poslednjih 8 (ili 4) bajta, odatle saznaš gde počinju tvoji podaci i koliko su veliki i samo ih pročitaš. Ako želiš da izmeniš podatke, ideš na kraj originalnog exea, dodaš novi sadržaj i na kraj opet staviš 8/4 bajta i to proglasiš za novu veličinu fajla.
 
Odgovor na temu

komplikator
Programer / sys. inženjering
CRO

Član broj: 29755
Poruke: 158
*.adsl.net.t-com.hr.

ICQ: 13387003


+8 Profil

icon Re: Upisivanje neke vrednosti u exe fajlu28.07.2015. u 12:01 - pre 106 meseci
A antivirusni software će biti oduševljen :)
God is real unless is declared as integer.
 
Odgovor na temu

dusans
Stojanov Dušan
Pančevo

Član broj: 9551
Poruke: 1343
*.dynamic.sbb.rs.



+311 Profil

icon Re: Upisivanje neke vrednosti u exe fajlu28.07.2015. u 12:10 - pre 106 meseci
Nešto mi tu smrdi - a to je da rešava problem pogrešnim pristupom.
Koristiti exe fajl za skrivanje informacija ne vodi većoj sigurnosti.
Da li append-ovao exe fajl ili snimio te podatke u zaseban fajl je,
što se tiče nivoa sigurnosti, suštinski isto.

Ajde lepo napiši problem koji rešavaš pošto mi intuicija
govori da si na pogrešnom putu.
 
Odgovor na temu

savkic
Igor Savkić

Moderator
Član broj: 92186
Poruke: 2739



+92 Profil

icon Re: Upisivanje neke vrednosti u exe fajlu28.07.2015. u 12:25 - pre 106 meseci
> A antivirusni software će biti oduševljen :)

Zašto bi? To je sasvim regularna opcija koja ne menja code/data sekciju aplikacije.
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Upisivanje neke vrednosti u exe fajlu

[ Pregleda: 1737 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.