Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 4 odgovora
  • 2.350 pregleda

Najnovija ↓

Upisivanje neke vrednosti u exe fajlu 21.07.2015. u 02:26 · pre 137 meseci #1
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.

Re: Upisivanje neke vrednosti u exe fajlu 21.07.2015. u 22:25 · pre 137 meseci #2
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.
Potpis
Do not be a help vampire (http://slash7.com/pages/vampires), use the google.

How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html
http://solair.eunet.rs/~fangor...stions/smart-questions.sr.html
Re: Upisivanje neke vrednosti u exe fajlu 28.07.2015. u 13:01 · pre 137 meseci #3
A antivirusni software će biti oduševljen :)
Potpis
God is real unless is declared as integer.
Re: Upisivanje neke vrednosti u exe fajlu 28.07.2015. u 13:10 · pre 137 meseci #4
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.
Re: Upisivanje neke vrednosti u exe fajlu 28.07.2015. u 13:25 · pre 137 meseci #5
> A antivirusni software će biti oduševljen :)

Zašto bi? To je sasvim regularna opcija koja ne menja code/data sekciju aplikacije.
Potpis
Do not be a help vampire (http://slash7.com/pages/vampires), use the google.

How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html
http://solair.eunet.rs/~fangor...stions/smart-questions.sr.html
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme