每次遇到问Symbian手机如何实现关机时,诺基亚论坛的专家们总是建议手机不用关机,离线就行,所以Symbian文档中也没有提供关机的api,
但是我们还是可以看到很多定时关机的软件,到底是如何实现的呢,找了一款这样的软件用IDA查看关键部分如下:
view source
print?
01..text:000095D8 SUB R0, R11, #0x34
02..text:000095DC LDR R3, [R11,#var_14]
03..text:000095E0 MOV R1, #3 ;R1中TType的值是3,也就是EKeyDown
04..text:000095E4 LDR R2, [R3];这里R3存储的模拟按键的值
05..text:000095E8 BL _ZN9TRawEvent3SetENS_5TTypeEi ; TRawEvent::Set(TRawEvent::TType,int)
06..text:000095EC SUB R0, R11, #0x34
07..text:000095F0 BL _ZN7UserSvr8AddEventERK9TRawEvent ; UserSvr::AddEvent(TRawEvent const&)
08..text:000095F4 SUB R0, R11, #0x54
09..text:000095F8 BL sub_9F10
10..text:000095FC SUB R0, R11, #0x54
11..text:00009600 LDR R3, [R11,#var_14]
12..text:00009604 MOV R1, #0x11 ;这里R1的值TType是17,也就是EKeyRepeat
13..text:00009608 LDR R2, [R3]
14..text:0000960C BL _ZN9TRawEvent3SetENS_5TTypeEi; TRawEvent::Set(TRawEvent::TType,int)
15..text:00009610 SUB R0, R11, #0x54
16..text:00009614 BL _ZN7UserSvr8AddEventERK9TRawEvent ; UserSvr::AddEvent(TRawEvent const&)
17..text:00009618 SUB SP, R11, #0xC
18..text:0000961C LDMFD SP, {R11,SP,PC}
由上面的代码可以看到两次调用AddEvent,第一次是EKeyDown事件,第二次是EKeyRepeat事件,因此程序是通过模拟长按某个按键实现关机的,
显然是关机键了,用IDA往上一步查看传进来的参数值是0xa6,在MR SDK的头文件e32keys.h中找到对应的是EStdKeyDevice2,所以关机只需要下面几句代码就可以实现了
view source
print?
1.TRawEvent iRawEvt;
2.iRawEvt.Set(TRawEvent::EKeyDown,EStdKeyDevice2);
3.UserSvr::AddEvent(iRawEvt);
4.iRawEvt.Set(TRawEvent::EKeyRepeat,EStdKeyDevice2);
5.UserSvr::AddEvent(iRawEvt);