home *** CD-ROM | disk | FTP | other *** search
- // Coded by yoda(_f2f@gmx.net) of FReAK2FReAK
- // You are allowed to use parts of this code by mention of by name !
- //
- // Have fun :)
- //
-
- // the loader images
- {$R loader.res}
-
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Buttons, StdCtrls, ComCtrls, ExtCtrls,d32lib, Gauges, Menus,hexfun,pelib,
- shellapi,inifiles;
-
- type
- TForm1 = class(TForm)
- ListView1: TListView;
- GroupBox1: TGroupBox;
- Edit1: TEdit;
- Panel3: TPanel;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- SpeedButton2: TSpeedButton;
- SpeedButton3: TSpeedButton;
- SpeedButton4: TSpeedButton;
- SpeedButton5: TSpeedButton;
- SpeedButton7: TSpeedButton;
- SpeedButton8: TSpeedButton;
- SpeedButton9: TSpeedButton;
- SpeedButton10: TSpeedButton;
- SpeedButton1: TSpeedButton;
- SpeedButton12: TSpeedButton;
- PopupMenu1: TPopupMenu;
- clearall1: TMenuItem;
- deleteselected1: TMenuItem;
- edit2: TMenuItem;
- N2: TMenuItem;
- Label1: TLabel;
- procedure SpeedButton1Click(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- procedure SpeedButton3Click(Sender: TObject);
- procedure SpeedButton5Click(Sender: TObject);
- procedure SpeedButton10Click(Sender: TObject);
- procedure SpeedButton7Click(Sender: TObject);
- procedure SpeedButton11Click(Sender: TObject);
- procedure ListView1DblClick(Sender: TObject);
- procedure SpeedButton9Click(Sender: TObject);
- procedure SpeedButton4Click(Sender: TObject);
- procedure SpeedButton8Click(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure ListView1Change(Sender: TObject; Item: TListItem;
- Change: TItemChange);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure SpeedButton12Click(Sender: TObject);
- procedure edit2Click(Sender: TObject);
- procedure deleteselected1Click(Sender: TObject);
- procedure clearall1Click(Sender: TObject);
- procedure RadioButton1Click(Sender: TObject);
- private
- { Private-Deklarationen }
- public
- { Public-Deklarationen }
- end;
-
- const maxpatchbytesnum : integer = 500; // prevents a crash while comparing files
- loadersize_b : longint = $8000;
- icoOFF_b : longint = $70a0;
- loadersize_s : longint = $2c50;
- icoOFF_s : longint = $28A4;
- nullterm : dword = 0;
- waitsign : dword = 1;
- resumesign : dword = 2;
- s_n_r_sign : dword = 3;
- SR_first : byte = 0;
- SR_all : byte = 1;
- datasectionname : string = 'yoda';
- fineicosize : integer = $2fe;
- inifilename : string = 'ypp.ini';
-
- var
- Form1 : TForm1;
- fileh : THandle;
- fsize : DWORD;
- newitem : TListItem;
- loader : Tmemorystream;
- loaderdata : TMemorystream;
- // Tmemorystream is one of the best Delphi classes, I think !!!
- // if you know whether there exists something like that in C/C++ then please mail me
- checknum : real;
- currsel : longint;
- i,ii : dword;
- tmpnum : dword;
- tmpstring : string;
- editing : boolean;
- theICO : Ticon;
- tmpICO : Ticon;
- IniFile : Tinifile;
- inidir : string;
- // PE variables
- dosh : PIMAGE_DOS_HEADER;
- peh : PIMAGE_NT_HEADERS;
- sectionh : PIMAGE_SECTION_HEADER;
- sectionh2 : PIMAGE_SECTION_HEADER; // needed for the Offset2va function
-
- implementation
-
- uses Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8;
- {$R *.DFM}
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- opendialog1.filter:='Executable Files|*.exe|All files|*.*';
- opendialog1.filename:='';
- if opendialog1.execute then
- edit1.text:=extractfilename(opendialog1.filename)
- end;
-
- procedure processedit;
- var i : integer;
- begin
- with form1.listview1 do
- if selcount > 0 then // else we would crash
- begin
- editing:=true;
- i:=selected.index;
- if items[i].caption = 'Patch' then // edit a patch
- begin
- patchform.Edit1.text:=items[i].subitems[0];
- patchform.edit3.text:=items[i].subitems[1];
- patchform.edit2.text:=items[i].subitems[2];
- patchform.show;
- end;
- if items[i].caption[1]= 'W' then //edit a wait
- begin
- tmpnum:=10; // position of the wait number
- while items[i].caption[tmpnum] <> chr($20) do
- begin
- waitform.edit1.text:=waitform.edit1.text+items[i].caption[tmpnum];
- inc(tmpnum);
- end;
- waitform.show;
- end;
- if items[i].caption[1] = 'S' then // edit Search & Replace
- begin
- if items[i].caption[19] = 'A' then srform.checkbox1.checked:=true;
- srform.edit1.text:=items[i].SubItems[1];
- srform.edit2.text:=items[i].subitems[2];
- srform.show;
- end;
- end;
- end;
-
- function makeloader:boolean;
- var hres : THandle;
- pres : pointer;
- rs,ro,vs,vo : dword;
- nrs,nro,nvs,nvo : dword;
- sectionalign : dword;
- ico : TMemoryStream;
- begin
- result:=false;
- loaderdata:=tmemorystream.create;
- // process the attack number
- tmpnum:=hex2int(optionform.edit1.text);
- loaderdata.write(tmpnum,4);
- // process the target filename
- tmpstring:=form1.edit1.text;
- loaderdata.write(pchar(tmpstring)^,succ(length(tmpstring)));
- // process all items in the listview
- with form1.listview1 do
- for i:=0 to items.count-1 do
- begin
- // a patch
- if items[i].Caption = 'Patch' then
- begin
- tmpnum:=hex2int(items[i].subitems[0]);
- loaderdata.write(tmpnum,4); // the patch VA
- // write the byte size
- tmpnum:=round(length(items[i].subitems[1])/2);
- loaderdata.write(tmpnum,1);
- // original bytes
- tmpstring:='';
- for ii:=1 to length(items[i].subitems[1]) do
- begin
- checknum:=ii/2;
- if frac(checknum) = 0 then
- begin
- tmpstring:=tmpstring+items[i].subitems[1][ii];
- tmpnum:=hex2int(tmpstring);
- loaderdata.write(tmpnum,1);
- tmpstring:='';
- continue;
- end;
- tmpstring:=items[i].subitems[1][ii]+tmpstring;
- end;
- // write the patch bytes
- tmpstring:='';
- for ii:=1 to length(items[i].subitems[2]) do
- begin
- checknum:=ii/2;
- if frac(checknum) = 0 then
- begin
- tmpstring:=tmpstring+items[i].subitems[2][ii];
- tmpnum:=hex2int(tmpstring);
- loaderdata.write(tmpnum,1);
- tmpstring:='';
- continue;
- end;
- tmpstring:=items[i].subitems[2][ii]+tmpstring;
- end;
- end;
- // Search and Replace
- if items[i].caption[1] = 'S' then
- begin
- // write the sign
- loaderdata.write(s_n_r_sign,4);
- // replace the first
- if items[i].caption[19] = 'F' then
- loaderdata.write(SR_first,1)
- else // or all
- loaderdata.write(SR_all,1);
- // write the byte size
- tmpnum:=round(length(items[i].subitems[1])/2);
- loaderdata.write(tmpnum,1);
- // search bytes
- tmpstring:='';
- for ii:=1 to length(items[i].subitems[1]) do
- begin
- checknum:=ii/2;
- if frac(checknum) = 0 then
- begin
- tmpstring:=tmpstring+items[i].subitems[1][ii];
- tmpnum:=hex2int(tmpstring);
- loaderdata.write(tmpnum,1);
- tmpstring:='';
- continue;
- end;
- tmpstring:=items[i].subitems[1][ii]+tmpstring;
- end;
- // write the replace bytes
- tmpstring:='';
- for ii:=1 to length(items[i].subitems[2]) do
- begin
- checknum:=ii/2;
- if frac(checknum) = 0 then
- begin
- tmpstring:=tmpstring+items[i].subitems[2][ii];
- tmpnum:=hex2int(tmpstring);
- loaderdata.write(tmpnum,1);
- tmpstring:='';
- continue;
- end;
- tmpstring:=items[i].subitems[2][ii]+tmpstring;
- end;
- end;
- // WAIT
- if items[i].Caption[1] = 'W' then
- begin
- tmpnum:=10;
- tmpstring:='';
- while items[i].caption[tmpnum] <> chr($20) do
- begin
- tmpstring:=tmpstring+items[i].caption[tmpnum];
- inc(tmpnum);
- end;
- loaderdata.write(waitsign,4);
- tmpnum:=hex2int(tmpstring);
- loaderdata.write(tmpnum,2);
- end;
- //resume
- if items[i].caption = 'Resume the Process' then
- loaderdata.write(resumesign,4);
- end; // of main loop
- // write NULL-terminator
- loaderdata.write(nullterm,4);
- // all patch infos are now in the loaderdata stream
-
- // catch the loader image out of the resource ...
- if optionform.radiobutton1.checked then
- begin // the small exe image
- hres:=findresource(0,'LOADER_IMAGE_S','BAD_THINGS');
- hres:=loadresource(0,hres);
- pres:=lockresource(hres);
- end
- else
- begin
- hres:=findresource(0,'LOADER_IMAGE_B','BAD_THINGS');
- hres:=loadresource(0,hres);
- pres:=lockresource(hres);
- end;
- if pres = nil then
- begin
- mb('Hey !! What did you do with this proggy ?'#13+
- 'Where''s my Loader Image ?...aborting !','Arrghhh...',mb_iconerror);
- loaderdata.free;
- exit;
- end;
- //...and put it into the loader stream
- loader:=tmemorystream.create;
- if optionform.radiobutton1.checked then
- loader.write(pres^,loadersize_s)
- else
- loader.write(pres^,loadersize_b);
- loader.seek(0,sofromend);
- // write a new section into the section header
- dosh := PIMAGE_DOS_HEADER(loader.memory);
- peh:= PIMAGE_NT_HEADERS(Longword(dosh) + Longword(dosh.e_lfanew));
- sectionh:=PIMAGE_SECTION_HEADER(peh);
- inc(pimage_nt_headers(sectionh));
- // go to the last section..
- for i:=1 to peh.FileHeader.NumberOfSections-1 do
- inc(sectionh);
- ro:=sectionh.PointerToRawData; //.. and get its infos
- rs:=sectionh.SizeOfRawData;
- vo:=sectionh.VirtualAddress;
- vs:=sectionh.PhysicalAddress;
- sectionalign:=peh.OptionalHeader.SectionAlignment;
- inc(sectionh); // go to the new section
- // some alignment shit (get valid sizes and offsets/addresses which fit to the Alignments)
- peh.OptionalHeader.FileAlignment:=$200; // doesn't interested anything...I hope :)
- nrs:=((loaderdata.size div $200) + 1) * $200;
- tmpnum:=loaderdata.size;
- loaderdata.setsize(nrs);
- Fillchar((pchar(loaderdata.memory)+tmpnum)^,(loaderdata.size-tmpnum),0); // force Zero's in the data section
- nro:=rs+ro;
- if (nro mod $200) <> 0 then
- nro:=((nro div $200) +1) * $200;
- nvo:=vs+vo;
- if (nvo mod sectionalign) <> 0 then
- nvo:=((nvo div sectionalign) +1) * sectionalign;
- nvs:=((nrs div sectionalign) + 1) * sectionalign;
- // write the section values of the new section
- strcopy(sectionh.Name,pchar(datasectionname));
- sectionh.PhysicalAddress:=nvs;
- sectionh.VirtualAddress:=nvo;
- sectionh.SizeOfRawData:=nrs;
- sectionh.PointerToRawData:=nro;
- sectionh.Characteristics:=$C0000040;
- peh.OptionalHeader.SizeOfImage:=nvo+nvs;
- inc(peh.FileHeader.NumberOfSections);
- loader.seek(nro,sofrombeginning);
- loader.write(loaderdata.memory^,nrs); // write the data at the end of the loader image
- // process the loader icon
- ico:=tmemorystream.create;
- theico.SaveToStream(ico);
- if ico.size = fineICOsize then
- begin
- if optionform.radiobutton1.checked then
- loader.seek(icooff_s,soFromBeginning)
- else
- loader.seek(icooff_b,sofrombeginning);
- loader.write((PChar(ico.Memory)+$16)^,ico.Size-$16);
- end
- else mb('The size of the selected icon isn''t supported !'#13+
- 'I use the standart icon...',':(',mb_iconwarning);
- ico.free;
- // save the loader
- form1.savedialog1.filename:='loader.exe';
- form1.savedialog1.title:='Where to save the generated Loader ?';
- if form1.savedialog1.execute then
- begin
- loader.savetofile(form1.savedialog1.filename);
- mb('Loader done - Have fun !',':)',mb_iconinformation+mb_topmost);
- exit;
- end;
- // OK OK here's the memory back
- loaderdata.free;
- loader.free;
- result:=true;
- end;
-
- procedure TForm1.SpeedButton2Click(Sender: TObject);
- begin
- form1.enabled:=false;
- with patchform do
- begin
- edit1.text:='';
- edit2.text:='';
- edit3.text:='';
- show;
- end;
- end;
-
- procedure TForm1.SpeedButton3Click(Sender: TObject);
- begin
- // save some settings
- with inifile do
- begin
- inifile:=tinifile.create(inidir+inifilename);
- WriteString('LastSettings','attacknumber',optionform.edit1.text);
- if optionform.radiobutton1.checked then
- writestring('LastSettings','smallloader?','1')
- else
- writestring('LastSettings','smallloader?','0');
- writestring('LastSettings','lastdirectory',Getcurrentdir);
- Free;
- end;
- close;
- end;
-
- procedure TForm1.SpeedButton5Click(Sender: TObject);
- begin
- waitform.show;
- end;
-
- procedure TForm1.SpeedButton10Click(Sender: TObject);
- begin
- optionform.show;
- end;
-
- procedure TForm1.SpeedButton7Click(Sender: TObject);
- begin
- // check whether there's already a resume
- with listview1 do
- if items.count > 0 then
- for i:=0 to Items.Count-1 do
- if items[i].caption='Resume the Process' then
- begin
- mb('The Resume command can only be inserted one time !',':(',mb_iconerror);
- exit;
- end;
- resumeform.show;
- end;
-
- procedure TForm1.SpeedButton11Click(Sender: TObject);
- begin
- processedit;
- end;
-
- procedure TForm1.ListView1DblClick(Sender: TObject);
- begin
- processedit;
- end;
-
- procedure TForm1.SpeedButton9Click(Sender: TObject);
- begin
- if listview1.items.count = 0 then
- begin
- mb('You have to add something in the list before creating the loader !','!!!',mb_iconerror);
- exit;
- end;
- if edit1.text = '' then
- begin
- mb('No filename entered up to now !','!!!',mb_iconerror);
- exit;
- end;
- makeloader;
- end;
-
- procedure TForm1.SpeedButton4Click(Sender: TObject);
- begin
- aboutform.show;
- end;
-
- procedure TForm1.SpeedButton8Click(Sender: TObject);
- begin
- compareform.show;
- end;
-
- procedure TForm1.FormShow(Sender: TObject);
- begin
- // disable the popup menu items
- edit2.enabled:=false;
- deleteselected1.enabled:=false;
- clearall1.enabled:=false;
-
- // restore some setting
- inidir:=GetCurrentdir;
- if inidir[length(inidir)] <> '\' then inidir:=inidir+'\';
- with inifile do
- begin
- inifile:=tinifile.create(inidir+inifilename);
- setcurrentdirectory(pchar(readstring('LastSettings','lastdirectory','.')));
- if readstring('LastSettings','smallloader?','1') = '1' then
- optionform.radiobutton1.checked:=true
- else
- optionform.radiobutton2.checked:=true;
- optionform.Edit1.text:=readstring('LastSettings','attacknumber','1');
- end;
-
- // initialize some variables
- currsel:=-1;
- editing:=false;
-
- // show the icon of the program in the options form
- theico:=ticon.create;
- tmpico:=ticon.create;
- theico.Handle:=ExtractIcon(hInstance,pchar(application.exename),0);
- end;
-
- procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
- Change: TItemChange);
- begin
- if listview1.SelCount > 0 then
- begin
- if listview1.Selected.Caption[1] <> 'R' then edit2.Enabled:=true;
- deleteselected1.Enabled:=true;
- currsel:=listview1.Selected.Index;
- end
- else
- begin
- deleteselected1.Enabled:=false;
- edit2.enabled:=false;
- currsel:=-1;
- end;
- if listview1.Items.Count = 0 then
- clearall1.Enabled:=false
- else
- clearall1.Enabled:=true;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- // clean the icon shit up
- theico.free;
- tmpico.free;
- end;
-
- procedure TForm1.SpeedButton12Click(Sender: TObject);
- begin
- srform.show;
- end;
-
- procedure TForm1.edit2Click(Sender: TObject);
- begin
- processedit;
- end;
-
- procedure TForm1.deleteselected1Click(Sender: TObject);
- begin
- if listview1.SelCount > 0 then
- with listview1 do
- for i:=0 to Items.Count-1 do
- if items[i].Selected then // delete the selected item
- begin
- items[i].Delete;
- exit;
- end
- else begin;end
- end;
-
- procedure TForm1.clearall1Click(Sender: TObject);
- begin
- if messagebox(0,'Are you sure that you want to clear the Action list ?',
- 'agreement',mb_iconquestion+mb_topmost+mb_yesno) = ID_YES then
- listview1.Items.Clear;
- end;
-
- procedure TForm1.RadioButton1Click(Sender: TObject);
- begin
- speedbutton1.enabled:=true;
- end;
-
- end.
-