- Prison Code Breaker Diary -

=> aka: Nhật Kí Code Tù

Categories

Now, I will introduce you a very, very popular widget that is used most of the time, GtkMessageDialog.

As you use software, sometimes it will pops up a small dialog that contains message which can be in types of either about Information, or Warning, or Question, or Error.
Like this:

Under Windows, it's known as MessageBox, right? You might be familiar with this Message Box already.

Let's look over its documentation.
Reference GtkMessageDialog

First of all, in the inherited hierarchy, GtkMessageDialog is from GtkDialog, so it certainly contains all the properties and accessing methods of GtkDialog. Simply, it's a pre-decorated dialog.

Secondly, these are the properties that you need to consider when creating a MessageDialog:
[+] Title: inherited from GtkWindow
[+] Dialog Flags: either GTK_DIALOG_MODAL or GTK_DIALOG_DESTROY_WITH_PARENT
[+] Message Type: is one of the four: GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING, GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR
[+] Button Type: either GTK_BUTTONS_*{ NONE, OK, CLOSE, CANCEL, YES_NO, OK_CANCEL } or you can create and add your own button by gtk_dialog_add_buttons().
[+] Secondary Text: is the detail info what you want to describe.

[!] 'Til now, since I haven't introduced about GtkDialog, but just stick with what I mention below:
- use gtk_dialog_run() to run the message dialog.
- gtk_dialog_run() return a response signal, therefore, always try to handle the signal.
- always use gtk_widget_destroy() to close message dialog, to avoid memory leak.
Some reference you need to read about what I mentioned:
Reference gtk_dialog_run()
Reference GtkResponseType

So far, it's enough for you at the present.

Practice: write a Gtk+ application that contains 4 buttons that will emits different types of GtkMessageDialog.


Try to read documentation and what I've mentioned so far then make your code. Make it simple and clear.

Below is my source for reference:


/*
* @author [JaPh]
* @date 15 August, 2009
* @file GtkMessageDialog_01.c
* @site http://xjaphx.blogspot.com/
*/

#include <gtk/gtk.h>

/* declare a message box widget */
GtkWidget *msg_box;

/* construct a message box dialog */
void
MessageBox( GtkMessageType mType, GtkButtonsType bType, const gchar *title,
const gchar *msg, const gchar *details )
{
/* message box response code */
int res;
/* create a message box dialog */
msg_box = gtk_message_dialog_new( NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
mType, bType, msg );
/* set message box title */
gtk_window_set_title( GTK_WINDOW( msg_box ), title );
/* set detail text */
gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( msg_box ), details );
/* run the message box dialog */
res = gtk_dialog_run( GTK_DIALOG( msg_box ) );
/* check for dialog response and handle */
if( res == GTK_RESPONSE_OK )
gtk_widget_destroy( msg_box );
}

void
btn_info_clicked( GtkButton *btn, gpointer data )
{
MessageBox( GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "[JaPh] Dialog: INFO" ,
"GtkMessageDialog: Info", "This is an example of INFO Dialog" );
}
void
btn_warn_clicked( GtkButton *btn, gpointer data )
{
MessageBox( GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "[JaPh] Dialog: WARNING",
"GtkMessageDialog: Warning", "This is an example of WARNING Dialog" );
}
void
btn_ques_clicked( GtkButton *btn, gpointer data )
{
MessageBox( GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK, "[JaPh] Dialog: QUESTION",
"GtkMessageDialog: Question", "This is an example of QUESTION Dialog" );
}
void
btn_erro_clicked( GtkButton *btn, gpointer data )
{
MessageBox( GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "[JaPh] Dialog: ERROR",
"GtkMessageDialog: Error", "This is an example of QUESTION Dialog" );
}

/* MAIN */
int
main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *btn_info, *btn_warn, *btn_ques, *btn_erro;
GtkWidget *btn_exit;

gtk_init( &argc, &argv );
/* construct main window */
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW( window ), "[JaPh]Lesson 11: GtkMessageDialog" );
gtk_widget_set_size_request( window, 200, 180 );
/* create vbox layout */
vbox = gtk_vbox_new( TRUE, 5 );
/* create buttons */
btn_info = gtk_button_new_with_mnemonic( "Show _Info" );
btn_warn = gtk_button_new_with_mnemonic( "Show _Warning" );
btn_ques = gtk_button_new_with_mnemonic( "Show _Question" );
btn_erro = gtk_button_new_with_mnemonic( "Show _Error" );
btn_exit = gtk_button_new_with_mnemonic( "E_xit" );
/* pack buttons to vbox from TOP to BOTTOM */
gtk_box_pack_start( GTK_BOX(vbox), btn_info, TRUE, TRUE, 0 );
gtk_box_pack_start( GTK_BOX(vbox), btn_warn, TRUE, TRUE, 0 );
gtk_box_pack_start( GTK_BOX(vbox), btn_ques, TRUE, TRUE, 0 );
gtk_box_pack_start( GTK_BOX(vbox), btn_erro, TRUE, TRUE, 0 );
gtk_box_pack_start( GTK_BOX(vbox), btn_exit, TRUE, TRUE, 0 );
/* add layout widget to main window */
gtk_container_add( GTK_CONTAINER(window), vbox );
/* button signal */
g_signal_connect( GTK_BUTTON( btn_info ), "clicked",
G_CALLBACK( btn_info_clicked ), NULL );
g_signal_connect( GTK_BUTTON( btn_warn ), "clicked",
G_CALLBACK( btn_warn_clicked ), NULL );
g_signal_connect( GTK_BUTTON( btn_ques ), "clicked",
G_CALLBACK( btn_ques_clicked ), NULL );
g_signal_connect( GTK_BUTTON( btn_erro ), "clicked",
G_CALLBACK( btn_erro_clicked ), NULL );

g_signal_connect( GTK_BUTTON( btn_exit), "clicked",
G_CALLBACK( gtk_main_quit ), NULL );
/* window signal */
g_signal_connect( window, "destroy", G_CALLBACK( gtk_main_quit ), NULL );
/* show window & widgets */
gtk_widget_show_all( window );

/* run Gtk+ app */
gtk_main();
return 0;
}

Remember to keep your practice always, don't forget!

Have fun!@

Under Linux:


$ ./program `perl -e 'print "param"'`

Under Windows

\>perl.exe -e "exec 'program.exe','param'"

Have fun!@

By default, when you first launch Cygwin, your username is yet recognized, the warning message is shown like below:

Your group is currently "mkpasswd". This indicates that
the /etc/passwd (and possibly /etc/group) files should be rebuilt.
See the man pages for mkpasswd and mkgroup then, for example, run
mkpasswd -l [-d] > /etc/passwd
mkgroup -l [-d] > /etc/group
Note that the -d switch is necessary for domain users.

As the warning suggestions, run those above commands and your home user directory will be created, which is in : ~/cygwin/home/username

The created username is the same as the current Windows username.

Have fun!@

This is a freaking great joke.....I just couldn't help laughing this news...

Here a small quote:

It sounds like a joke. But, it's real and it's anything but a joke for Microsoft. Judge Leonard Davis, of the U.S. District Court for the Eastern District of Texas, has issued an injunction (PDF Link) that "prohibits Microsoft from selling or importing to the United States any Microsoft Word products that have the capability of opening .XML, .DOCX or DOCM files (XML files) containing custom XML."

Microsoft had been sued by i4i, a collaborative content solution and technology company. Its founder, Michel Vulpe, owned a patent covering a way of reading XML (Extended Markup Language) documents. XML is the basis of Microsoft's controversial Open XML document formats. The U.S. District Court for the Eastern District of Texas is infamous for supporting patent lawsuits and fast-tracking them. In intellectual property law circles, this Court has become known as "A Haven for Patent Pirates."


Reference:

http://blogs.computerworld.com/14532/microsoft_banned_from_selling_word

http://blogs.computerworld.com/14536/you_cant_buy_ms_word_i4i_xml_patent_ruling

http://blogs.computerworld.com/14537/microsoft_word_ban_its_time_to_banish_patent_lawyers

I've just found a new interesting page on cryptography and reversing.

It's called: +Ma's Reversing
Seem to be very interesting. I searched and looked up a place for sign up.
Well, it's well-said at INTRO, I have to solve the riddle to gain access to the site.
Read everything...then I wonder password is ....
=> Firefox, fire up View Source, I saw lines of comments in between. Wow, this is what mentioned in the last message line, "read between the lines".
Hum...so password is unsual. Because I have to solve a ciphered-text to gain password.

As in the comment, you can see that message:
<!-- MAL TIRRUEZF CR MAL RKZYIOL EX MAL OIY UAE RICF "MAL ACWALRM -->

<!-- DYEUPLFWL CR ME DYEU MAIM UL IZL RKZZEKYFLF GH OHRMLZH" -->

Interesting! So, how can we decode this message?
First, I thought of Caesar, the most popular one; however, failed.
I re-read the instructions carefully...It said to read his lesson-01.
Download the file, I read => got the idea menari.
Follow the idea w/ the hint "the message is written in English" ... I solved the riddle and gained access to the site.
Wow! This is so fun and interesting....
If you don't know this site, then you'd better try out.

Have fun!@

I've spent the whole night troubling w/ setting environments for exploit...but still not workingnangih.
Bang...at least I've gained something on my way...

Like Windows, Linux also provides modules for creating static library.

1. What is static library?
[A] It's a library that contains a list of API for a certain work, or to do something specifically that is pre-compiled and you don't have to recompile it again. If you know more about Linux, then you may know that a static library simply is just a compilation or a package of object code.
[*] Static library under Linux has extension ".a", while it is ".lib" in Windows.

2. What is the purpose of static library?
[A] As far as I know, firstly, since it's a library, it certainly gives APIs for convenient programming. It's already precompiled, so it costs less time to compile and load APIs than other types of libraries. Additionally, in case the author of the library wants to hide the actual source code.

3. When should I use static library?
[A] Well, you can use it any time you want. However, nowadays, Linux-ers don't prefer static library due to the faster computers and compilers.

Let's create our first Linux static library. Certainly, the programming language in use is C, or you can use C++.

I - Creating the library
1. Prepare:
[+] You need to create 2 files: one is the header, one is the source.
[+] Naming: all Linux libraries start with prefix "lib"

--[libhello.h]--


/*
* @author [JaPh]
* @date 14 August, 2009
* @file libhello.h
* @license freeware
*/

void hello( );

--[libhello.c]--

/*
* @author [JaPh]
* @date 14 August, 2009
* @file libhello.c
* @license freeware
*/

#include <stdio.h>

void hello( ) {
printf("[JaPh]Tutorial: Creating Linux Static Library\n"
"Message: Hello! This is a static library.\n");
}

2 - Compile the object code

[japh@localhost C]$ gcc -c libhello.c

3 - Create the library

[japh@localhost C]$ ar -cvsq libhello.a libhello.o
a - libhello.o

Finally, the file libhello.a created. This is our target static library

II - Use the library
The next thing we need to do is to test whether our library works or not.
Let's write a simple program to call the function hello() inside the library libhello.a

--[hello_main.c]--

/*
* @author [JaPh]
* @date 14 August, 2009
* @file hello_main.c
* @license freeware
*/

#include "libhello.h"

int main( ) {
hello( );
return 0;
}

Then compile:

[japh@localhost C]$ gcc -o hello hello_main.c -L/path/to/library -lhello

You need to specify the location where you put the file libhello.a
Since it's a standard under Linux, you don't have to specify -libhello, use -lhello instead.
Finally, run our program

[japh@localhost C]$ ./hello
[JaPh]Tutorial: Creating Linux Static Library
Message: Hello! This is a static library.

There you have your first Linux static library. Pretty simple and very handy
If you don't want to type again and again for those steps, I've written this tiny script for auto-work everything. You just need to put all 3 files above into the same directory, then run the script below. You can change things in the script for personally wants.

#!/bin/sh
echo "[1] Compiling Object Code"
gcc -Wall -c libhello.c

echo "[2] Creating library"
ar -cvsq libhello.a libhello.o

echo "[3] Compiling program"
gcc -o hello hello_main.c -L. -lhello

echo "[4] Running program"
./hello


Well, that's all I have for you in this topic.

Have fun!@