Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[TUT] Delphi with MySQL

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Mon Jan 21, 2008 9:34 am    Post subject: [TUT] Delphi with MySQL Reply with quote

Hello everyone,

I started coding with delphi+MySQL 2 days ago and noticed that it's pretty easy to understand.

I'm working without components, I'm working with uMySQL (or whatever it's called). Download: http://downloads.sourceforge.net/directsql/DirectMySQLObjects122.zip?modtime=1132929129&big_mirror=0
Just move the files stored in the .zip/.rar in the Borland/DelphiX/Lib dir and compile them.

If you've done this, let's start! Razz
In this tut, I use this Table: (Which is called tutorialTABLE)


Then I already added some random ppl (from which I know the realname) to the table as example:


Now, with this TUT I gonna show you how to Add/Edit/Remove/check-if-exist or read an entry. Let's go!


First add this to the uses line:
Code:
.... umysqlvio, uMysqlCT, uMysqlClient, uMysqlHelpers;

And this to the global variable list:
Code:
sql: TMysqlClient;                       // This is our "component"


1. Connecting to the databse
Of course, first we gotta connect to the database. This is how to:
Code:
procedure TForm1.Button1.Click(Sender: TObject);
begin
  sql := TMysqlClient.create;
  sql.Host := 'HOST';                      // Here replace the "HOST" with your database-host
  sql.port := PORT;                        // Here replace the "PORT" with your database-port, standart = 3306
  sql.user :='USER';                       // Here replace the "USER" with your database-username
  sql.password := 'PASS';                  // Here replace the "PASS" with your database-password
  sql.UnixSocket := '';                    // I've no idea what this is...
  sql.Db := 'DATABASE';                    // Here replace the "DATABSE" with the name of your database
  sql.UseNamedPipe := false;               // I don't know what this is, just let it "false"
  sql.UseSSL := false;                     // Something with Secure login or so..dunno
  sql.Compress := true;                    // Also no idea here
  sql.TrySockets := false;                 // and here

if sql.Connect then                     // Finally we connect
    ShowMessage('Connected!')              // If successfully connected then this Message will come up
  else
    ShowMessage('Could not connect: '+sql.LastError);   // If it couldn't connect it will show up this message
end;



2. Creating an entry

Well now, if you're connected you've like full controll over the database.
So what do you want to do as first? Let's start with Adding aka Create a new entry.

Code:
procedure TFOrm1.CreateEntry(Sender: TObject);
var
Boolresult: boolean;
begin
Sql.query('INSERT INTO tutorialTABLE (Nickname, PostCount, RealName) VALUES ("Yipang", "dunno", "Conor")', true, Boolresult);
end;


You see. You set strings betwen "String here".
Idk for what the first boolean (which is true in this case) is.
But you see the second is identified and it returns the result value.
So you can to a check then:
Code:
if boolresult then ShowMessage('Worked') else ShowMessage('It didn't work for some reason');

But it's not like it checks if it really created that entry or if you used the correct syntax, it just checks if the MySQL-server got the query.
So you could just send a query like this:
Code:
sql.query('nub', true, boolresult);

and the result would be true (unless you're not connected).

Now, since we created a entry into the table, it looks like that now:


3. Editing an entry

As next, we gonna try to edit an entry.
Code:
procedure TFOrm1.EditEntry(Sender: TObject);
var
Boolresult: boolean;
begin
Sql.query('UPDATE tutorialTABLE SET Realname = "bitch" WHERE Nickname = "rEakW0n"', true, Boolresult);
end;


You can see, it's pretty easy to understand these MySQL-commands.
Code:
UPDATE tutorialTABLE  // With that you chose the table where you want to update an entry (tutorialTABLE is this case)
SET RealName                // Here you chose the column (RealName to "bitch" in this case)
WHERE Nickname              // Now it doesn't know from who has to change the RealName, so you just gotta tell it something about it. (Nickname= "rEakW0n" in this case)


And tada:


4. Removing an entry

Removing an entry is almost the same than editing one:
Code:
procedure TFOrm1.DeleteEntry(Sender: TObject);
var
Boolresult: boolean;
begin
Sql.query('DELETE FROM tutorialTABLE WHERE Nickname = "appalsap"', true, Boolresult);
end;


Nothing much to exlplain: It deletes the whole entry where the nickname is "appalsap"
So:


5. Check if an entry exists

Now, it's the first time you gotta use TMySQLResult and a second bool.

Code:
procedure TFOrm1.CheckEntry(Sender: TObject);
var
Boolresult, found: boolean;
Result: TMySQLResult;
begin
  Result := FMySQL.query('SELECT COUNT(*) AS Anzahl FROM tutorialTABLE WHERE Nickname = "x0r", true, Boolresult);
  gefunden := IsOK and (Result.FieldValueByName('Anzahl') <> '0');
end;


In this procedure, it checks if a Nickname called "x0r" exists. If yes then found is true.
Check with
Code:
if found then ShowMessage('x0r exists') else ShowMessage('x0r doesn't exist');


6. Read an entry

Now, as last we read out of it which is actually the sense of "databasing".
And again we use a TMySQL result and a string.

Code:
procedure TFOrm1.CheckEntry(Sender: TObject);
var
Boolresult: boolean;
Result: TMySQLResult;
StringResult: String;
begin
   result := FMysql.query('SELECT PostCount FROM tutorialTABLE WHERE NickName = "Rot1"', true, Boolresult);
   StringResult := result.FieldValueByName('PostCount', true);
   ShowMessage('Rot1 has '+StringResult+' posts');
end;


It selects PostCount from the table called tutorialTABLE where the nickanme is "Rot1".
Then it declares it to the string by the result.

7. Close the connection

As last you gotta close the connection if you're done. (well it will disconnect if you close the application anyway)

Code:
procedure TForm1.Disconnect(Sender: TObject);
  if sql.Connected then
    sql.close;
  end;


I hope this helped. If you found any bugs or so...just say it. Thanks


Last edited by Reak on Tue Feb 12, 2008 8:58 am; edited 4 times in total
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 21, 2008 9:37 am    Post subject: Reply with quote

This is really cool.

You could make a crackme with this.

MySQL is pretty easy to use aswell but good job reakw0n :]

advice. Show the commands for the mySQL and tell what each parameter means.

_________________
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Mon Jan 21, 2008 10:04 am    Post subject: Reply with quote

Heyy,

Yea, but I think it's impossible to get the pass then Very Happy
You could also use this as protection.
If your hwid exists in table then continue else Application.Terminate.

Well I haven't got that much MySQL experince, as I said I started like 2 days ago.
But here's maybe something interesting for you:
http://www.pantz.org/software/mysql/mysqlcommands.html
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Jan 21, 2008 10:17 am    Post subject: Reply with quote

thanks, now i will start learning Delphi + MySQL,

it's useful to make licensed application (E.g: 30 days left Evu)
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 21, 2008 5:03 pm    Post subject: Reply with quote

reakw0n, packet sniff the program to get pass to crack
_________________
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Mon Jan 21, 2008 6:07 pm    Post subject: Reply with quote

Well the problem is, if you don't protect the file by packing it (e.g: Themida) you can read out the MySQL information with OllyDBG and everyone could access to your database and edit/delete/w.e things.

Of course you you could pack it...but there's already a unpacker out for Themida..too bad.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Jan 22, 2008 7:49 am    Post subject: Reply with quote

i don't belive someone would release a stripper for themida, hard work doesn't worth release
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Tue Jan 22, 2008 7:59 am    Post subject: Reply with quote

it is released.Google for tmdunpacker or so (lol im oline with my handy)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites