If I would be a virus writer, I would definitely open at least one db (virus
master copy:) with exclusive mode right after reset, thus making it
unreadable, (DmOpenDatabase will fail). Sure I would need to store the dbref
somewhere:).
I have seen some system databases also use the exclusive open mode.
The only way to read such databases is to perform a "no-notify" reset.

Best regards,
    Miro Pomsar


----- Original Message ----- 
From: "Robert Moynihan" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[email protected]>
Sent: Wednesday, April 13, 2005 01:22
Subject: Re: reading stored memory


> Scott Erickson wrote:
>
> >Bob,
> >    Here is what I got at this point.  Is this pretty much what I need to
do
> >to read through all dbs on the device?
> >
> >
>
> Here's a function that I use to build a list of databases in one of my
> apps.  I haven't really typed this out all that well, but it should give
> some ideas.
>
> First I initialize the 2 variables, then call BuildDBList() with the
> type of db that I am looking for.  Note that this ONLY looks for dbs
> created by my app, so the CreatorID is hardcoded as RPNAppID.  Using
> NULL here would search for all creators.  Once the list has been created
> in memory, it is really easy to refer to it; see the bit of code at the
> bottom.
>
> //these are globals that I can access from any part of my app
> MemHandle    dbListH=NULL;
> UInt16        gLockCount=0;
>
> //this defines the structure for dbList
> typedef struct {
>     UInt16    card;
>     LocalID    currentDB;
>     UInt16    other;
> } myDbListType;
>
> //this function builds the list.  I do this once, and only again when I
> detect that a change has been made.
> void BuildDBList(UInt32 type)
> //type could be NULL if you want to search for ALL types.
> {
>     DmSearchStateType state;
>     Boolean        latestVer=false;  //this is usually false for apps
>     UInt16        card;
>     LocalID     currentDB=0;
>     UInt16        attributesP;
>     UInt16        count=0;
>     UInt16        maxCount=10;
>     Err        Error;
>     Char        dbName[32];
>     LocalID        appInfoIDP;
>     Char        *ch=(void*)&type;
>     myDbListType    *dbListP;
>
>     //initialize memory for dblist
>     if (dbListH){
>         MemHandleFree(dbListH);
>         dbListH=NULL;
>     }
>     dbListH=MemHandleNew(maxCount*sizeof(myDbListType));
>     dbListP=myMemHandleLock(dbListH);
>
>     Error = DmGetNextDatabaseByTypeCreator(true, &state, type, RPNAppID,
> latestVer, &card, &currentDB);
>     //Build list of names
>     while (!Error && currentDB && count<256) {
>         Error = DmDatabaseInfo(card, currentDB,
> dbName,&attributesP,NULL,NULL,NULL,NULL,NULL,&appInfoIDP,NULL,NULL,NULL);
>         if (StrNCompare(ch+1,dbName+4,3)==0){
>             //grow the list if necessary
>             if (count==maxCount){
>                 Err err;
>                 maxCount+=10;
>                 myMemPtrUnlock(dbListP);
>
err=MemHandleResize(dbListH,maxCount*sizeof(myDbListType));
>                 dbListP=myMemHandleLock(dbListH);
>                 if (err){
>                     maxCount-=10;
>                     break;
>                 }
>             }
>             //add entry to dbList
>             dbListP[count].card=card;
>             dbListP[count].currentDB=currentDB;
>             if (type=='BPgm'){
>                 DmOpenRef    db;
>                 UInt16        key;
>                 db=DmOpenDatabase(card,currentDB,dmModeReadOnly);
>                 GetProgHeader(db, NULL, &key, NULL);
>                 DmCloseDatabase(db);
>                 dbListP[count].other=key;
>             }
>             else
>                 dbListP[count].other=0;
>         count++;
>         }
>         Error = DmGetNextDatabaseByTypeCreator(false, &state, type,
> RPNAppID, latestVer, &card, &currentDB);
>     }
>     dbListCount=count;
>     SysQSort (dbListP, count, sizeof(myDbListType), myCompareDBNames, 0);
>     myMemPtrUnlock(dbListP);
> }
>
>
> The list is a list of card numbers and localIDs for databases.  With
> this list in place it is easy to populate a popup list, for instance.
> If I wanted to find the name of the databases in my list I would do
> something like this...
> {
>         myDbListType    *dbListP;
>         UInt16         dbIndex=index; //this is the index of the list
> member that I am interested in
>           char         name[32];
>
>         dbListP=myMemHandleLock(dbListH);
>         DmDatabaseInfo(dbListP[dbIndex].card,
> dbListP[dbIndex].currentDB,
> name,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
>         myMemPtrUnlock(dbListP);
> }
>
> When you are done with the list just do MemHandleFree(dbListH) and set
> dbListCount to 0.
>
> Bob.
>
>
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to