Trick:Hack wallpaper(Symbian/UIQ)

类别:软件工程 点击:0 评论:0 推荐:

There is no public API which we can use to achieve the goal.So we have to hack the launcher.mbm which is used to hold the wallpaper image.
The following code segment which was used in our project demontrates this:

void PutQuad( TPtr8& des, TInt val )
{
 TUint8 buffer[4];
 TUint8* ptr = (TUint8*)&buffer;
 TUint8* pt = (TUint8*)&val;
 *ptr++ = *(pt++);
 *ptr++ = *(pt++);
 *ptr++ = *(pt++);
 *ptr++ = *(pt++);
 des.Append((TUint8*)&buffer, 4);
}

_LIT(KMbmFileName, "c:\\system\\Data\\Themes\\wallpaper\\launcher.mbm");
void SaveWallpaper(BYTE* grBuf8, TSize size)
{
 TSize size1=size;
 TSize size2(143, 101);

 TInt fileHeaderLen = 5*4;
 TInt firstSize = 10*4 + (size1.iHeight * size1.iWidth << 1);
 TInt secondSize = 10*4 + (size2.iHeight * (size2.iWidth+1) << 1); // 4 byte align for width
 TInt trailerPos = fileHeaderLen + firstSize + secondSize;
 TInt firstDataPos = fileHeaderLen;
 TInt secondDataPos = firstDataPos + firstSize;
 TInt noBitmaps = 2;
 TInt trailerSize = 4 + noBitmaps*4;
 TInt len = secondDataPos + secondSize + trailerSize;
 HBufC8* outBuf = HBufC8::NewL(len);
 TPtr8 des = outBuf->Des();

 // file header
 PutQuad(des, UID1);
 PutQuad(des, UID2);
 PutQuad(des, UID3);
 PutQuad(des, SIG);
 PutQuad(des, trailerPos);

 // first bitmap header
 PutQuad(des, firstSize);
 PutQuad(des, 40);
 PutQuad(des, size1.iWidth);
 PutQuad(des, size1.iHeight);
 PutQuad(des, 0);
 PutQuad(des, 0);
 PutQuad(des, 16);
 PutQuad(des, 1);
 PutQuad(des, 0);
 PutQuad(des, 0);

 // first bitmap data
 TInt sx = 1,
  sy = 39;
 TInt height = size1.iHeight;
 TInt width = size.iWidth<<1;
 TInt scan = size1.iWidth<<1;
 TUint8* ptr = grBuf8;// + ((sy-1)*width + sx<<1);
 TInt j;
 for( j=0; j< height; j++ )
 {
  ptr += width;
  des.Append(ptr, scan);
 }

 // second bitmap header
 PutQuad(des, secondSize);
 PutQuad(des, 40);
 PutQuad(des, size2.iWidth);
 PutQuad(des, size2.iHeight);
 PutQuad(des, 0);
 PutQuad(des, 0);
 PutQuad(des, 12);
 PutQuad(des, 1);
 PutQuad(des, 0);
 PutQuad(des, 0);

 // second bitmap data
 sx = 1, sy = 39;
 scan = (size2.iWidth+1)<<1;
 height = size2.iHeight;
 ptr = grBuf8;// + ((sy-1)*width + sx<<1);
 for( j=0; j< height; j++ )
 {
  ptr += width;
  des.Append(ptr, scan);
 }

 // mbm trailer
 PutQuad(des, noBitmaps);
 PutQuad(des, firstDataPos);
 PutQuad(des, secondDataPos);

 TInt aStat = KErrNone;
 RFs m_fs;
 if( (aStat=m_fs.Connect()) != KErrNone )
  return;
 //aStat = m_fs.SetSessionPath( kMFPath() );

 // Write MBM Data to file
 RFile file;
 TInt res = file.Replace(m_fs, KMbmFileName, EFileShareAny | EFileWrite | EFileStream );
 User::LeaveIfError(res);
 file.Write(des);
 file.Close();
 delete outBuf;

 m_fs.Close();
 //delete outBuf;
}

 

本文地址:http://com.8s8s.com/it/it32906.htm