Use recognizer to write your own boot auto-Start Program

Source: Internet
Author: User
Disclaimer: Do not use this program to create mobile phone viruses or malware. Otherwise, the serious consequences are irrelevant to the author.

In fact, the title of the article is somewhat inaccurate. It should be said that the functions provided by recognizer can enable your program to be automatically loaded after the Symbian system is started. After recognizer is compiled, it is actually an MDL, which is similar to a DLL. I don't know how the Symbian OS calls it, but it is certain that after the Symbian OS kernel is started, MDL will be loaded whether or not it implements the functions it should implement. I saw Symbian OS SDK and Nokia Forum (http://forum.nokia.com .) some posts (you can also find them in the corresponding places), and find that recognizer is used for self-starting software from time to time, but now it seems that even the official Symbian has used this feature as the boot software. We do not know the specific API. It may only be available to Nokia's core partners.

Back to the question, how can we use recognizer to enable our programs to start after startup? The method is very simple. You can implement a recognizer by yourself. Paste the code first, and then explain it carefully.

// CPP; note: the header file to be added is marked as additional.

# Include <f32file. h>

# Ifdef _ series60_3x __

# Include <implementationproxy. h>

# Endif/* _ series60_3x __*/

# Include "myrecognizerrecog. H"

// Additional

# Include <apmrec. h>

# Include <apmstd. h>

# Include "apacmdln. H"

 

Static const tint kmyrecognizerrecogdatatypecount = 1;

_ Lit8 (kmyrecognizerrecogmimetype, "application/Ogg ");

 

Cmyrecognizerrecog: cmyrecognizerrecog (): capadatarecognizertype (kmyrecognizerrecogdlluid, capadatarecognizertype: ehigh)

{

Icountdatatypes = kmyrecognizerrecogdatatypecount;

}

 

Tuint cmyrecognizerrecog: preferredbufsize ()

{

Return 0;

}

 

Tdatatype cmyrecognizerrecog: supporteddatatypel (tint/* aindex */) const

{

Return tdatatype (kmyrecognizerrecogmimetype );

}

 

Void cmyrecognizerrecog: dorecognizel (const tdesc & aname, const tdesc8 &/* abuffer */)

{

Tparse parse;

User: leaveiferror (PARSE. Set (aname, null, null ));

_ Resolve (kdotogg, ". Ogg ");

 

If (PARSE. extpresent ()&&! Parse. Ext (). comparef (kdotogg ))

{

Iconfidence = ecertain;

Idatatype = tdatatype (kmyrecognizerrecogmimetype );

}

}

 

Void cmyrecognizerrecog: startthread ()

{

Tint res = kerrnone;

 

// Create a new thread for starting our application

Rthread * startappthread;

Startappthread = new rthread ();

 

User: leaveiferror (RES = startappthread-> Create (

_ L ("mythreadname "),

Cmyrecognizerrecog: startappthreadfunction,

Kdefastackstacksize,

Kminheapsize,

Kminheapsize,

Null,

Eownerthread ));

 

Startappthread-> setpriority (eprioritynormal/* epriorityless */);

 

Startappthread-> resume ();

 

Startappthread-> close ();

 

}

Tint cmyrecognizerrecog: startappthreadfunction (Tany */* aparam */)

{

// Wait 5 seconds...

Rtimer timer; // the asynchronous timer and...

Trequeststatus timerstatus; //... its associated Request status

Timer. createlocal (); // always created for this thread.

// Get current time (microseconds since 0ad nominal Gregorian)

TTime time;

Time. hometime ();

// Add ten seconds to the time

Ttimeintervalseconds timeintervalseconds (5 );

Time + = timeintervalseconds;

// Issue and wait

Timer. At (timerstatus, time );

User: waitforrequest (timerstatus );

 

 

Cactivescheduler * scheduler = new cactivescheduler ();

If (Scheduler = NULL)

Return kerrnomemory;

 

Cactivescheduler: Install (Scheduler );

// Create a trap cleanup

Ctrapcleanup * cleanup = ctrapcleanup: New ();

Tint err;

If (cleanup = NULL)

{

Err = kerrnomemory;

}

Else

{

Trap (err, startappthreadfunctionl ());

}

Delete cleanup;

Delete cactivescheduler: Current ();

 

Return err;

 

}

Void cmyrecognizerrecog: startappthreadfunctionl ()

{

// Absolute file path to our application

Tfilename fnapppath = _ L ("// system // apps // MyApp. app ");

 

RFS fssession; // File Server session

User: leaveiferror (fssession. Connect ());

Cleanupclosepushl (fssession );

Tfindfile findfile (fssession );

User: leaveiferror (findfile. findbydir (fnapppath, knulldesc ));

 

Capacommandline * cmdline = capacommandline: newlc ();

Using line-> setlibrarynamel (findfile. File ());

Using line-> setcommandl (eapacommandopen );

 

Rapalssession ls;

User: leaveiferror (LS. Connect ());

Cleanupclosepushl (LS );

 

User: leaveiferror (LS. Startapp (* using line ));

Cleanupstack: popanddestroy (3); // destroy fssession, ls and cmdline

}

 

Export_c capadatarecognizertype * createrecognizer ()

{

Capadatarecognizertype * thing = new cmyrecognizerrecog ();

 

// Start thread for our application

Cmyrecognizerrecog: startthread ();

Return thing;

 

}

 

# Ifdef _ series60_3x __

Const timplementationproxy implementationtable [] =

{

Implementation_proxy_entry (kmyrecognizerrecogimplementationuid, cmyrecognizerrecog: createrecognizerl)

};

 

Export_c const timplementationproxy * implementationgroupproxy (tint & atablecount)

{

Atablecount = sizeof (implementationtable)/sizeof (timplementationproxy );

Return implementationtable;

}

 

Capadatarecognizertype * cmyrecognizerrecog: createrecognizerl ()

{

Return new (eleave) cmyrecognizerrecog ();

}

# Else

Gldef_c tint e32dll (tdllreason/* areason */)

{

Return kerrnone;

}

 

/*

Export_c capadatarecognizertype * createrecognizer ()

{

Return new cmyrecognizerrecog ();

}*/

 

# Endif/* _ series60_3x __*/

 

// Heaher

 

# Ifndef _ myrecognizerrecog_h __

# DEFINE _ myrecognizerrecog_h __

 

# Include <apmrec. h>

// Additional

# Include <apgcli. h>

# Include <f32file. h>

# Include <apacmdln. h>

# Include <e32std. h>

# Include <apmstd. h>

Const tuid kmyrecognizerrecogdlluid = {0x07545de0 };

# Ifdef _ series60_3x __

Const tint kmyrecognizerrecogimplementationuid = 0x07545de0;

# Endif/* _ series60_3x __*/

 

Class cmyrecognizerrecog: Public capadatarecognizertype

{

 

Public:

 

# Ifdef _ series60_3x __

Static capadatarecognizertype * createrecognizerl ();

# Endif/* _ series60_3x __*/

 

Cmyrecognizerrecog ();

Tuint preferredbufsize ();

Tdatatype supporteddatatypel (tint aindex) const;

// Start my app

Static void startthread ();

Static tint startappthreadfunction (Tany * aparam );

Static void startappthreadfunctionl ();

PRIVATE:

Void dorecognizel (const tdesc & aname, const tdesc8 & abuffer );

};

# Endif/* _ myrecognizerrecog_h __*/

Lib to be added: apparc. Lib

 

From the code above, you can find that you do not have much work to do.

Select the MIME type recognizer when creating the project. This will automatically generate a lot of code. Here is your work. Static void startthread (); static tint startappthreadfunction (Tany * aparam); static void startappthreadfunctionl (); the functions implemented by these three functions are simple: initializing a thread and starting it, of course, there are still some necessary work, such as the handling of abnormal exit. The key is here: tfilename fnapppath = _ L ("// system // apps // MyApp. APP "); fnapppath is the complete path name of the app to be automatically started (note that the path here is on the Z disk of the simulator ). Note that the function annotation of the export_c capadatarecognizertype * createrecognizer () automatically generated by CPP is removed from the Code above at the end of the CPP file, otherwise, an error is reported.

After compilation, you will find the myrecognizer. Def, myrecognizer. Lib, and myrecognizer. MDL files under the/z/system/recogs directory. In fact, this MDL file is useful. Start the simulator and you will find that the program you want to automatically start is already in front of you. If you want to publish it to a real machine (mobile phone), you need to put myrecognizer. MDL under the corresponding recogs directory.

To sum up, the entire running process is to start the Symbian OS Kernel-> call the MDL-> MDL startup thread (to load the program we need to start ourselves)-> our program runs.

Here, by the way, there are other methods to implement the program self-startup, such as using ezboot, which is currently popular. However, I have read the author's introduction, but it is actually implemented using recognizer, but it is simpler. What I want to say is that it will benefit a lot if you do it yourself. We would also like to remind everyone that everything has two sides, especially recognizer. Be very careful when writing a function in it, because it is the core MDL to be loaded after the OS is loaded, if the implemented functions are not safe enough or the operations are improper, the mobile phone may be replaced. The most serious problem is that flash is damaged. So... However, the above Code has been tested and can be used safely.

Once again, they warned those who are eager to use the program to release malware or create mobile phone viruses. Otherwise, the serious consequences are irrelevant to the author!

All codes that need to be compiled are marked in italic; I hope this will be helpful to everyone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.