The content of the invention
In view of this, the embodiment of the present invention provides a kind of method and device for determining mobile device connection status,
The connection status of mobile device can rapidly and accurately be obtained.
In a first aspect, the embodiment of the present invention provides a kind of method for determining mobile device connection status, including:
Calling for message transfer function in Windows operating system is monitored;
Whether the message for judging currently to want transfer is equipment connection Notification of Changes message;
If the message for currently wanting transfer is equipment connection Notification of Changes message, Notification of Changes is connected according to equipment
Message determines the connection status of mobile device.
It is described that Windows is operated with reference in a first aspect, in the first embodiment of first aspect
Calling for message transfer function in system monitored, including:By Hook Function to the message transfer
Calling for function is monitored;Wherein, the Hook Function is included in the driving of application program.
In with reference to the first embodiment of first aspect, in second embodiment of first aspect,
The judgement currently wants whether the message of transfer is equipment connection Notification of Changes message, including:By the hook
Subfunction judges whether the type parameter of the current message for wanting transfer is predetermined parameter value, if, it is determined that
The message for currently wanting transfer is equipment connection Notification of Changes message, otherwise, it is determined that currently want the message of transfer
It is not equipment connection Notification of Changes message.
In with reference to second embodiment of first aspect, in the third embodiment of first aspect,
If the current message for want transfer is equipment connection Notification of Changes message, according to equipment connection Notification of Changes
Message determines the connection status of mobile device, including:If the message for currently wanting transfer is equipment, and connection change is logical
Know message, the Hook Function then obtains the information related to equipment connection Notification of Changes message, and root
The connection status of mobile device is determined according to described information.
With reference to first aspect and first aspect the first to any one in the third embodiment can
Embodiment, in the 4th kind of embodiment of first aspect, the connection status bag of the mobile device
Include:Insertion equipment, extraction equipment, equipment are already inserted into and/or equipment has been extracted.
In with reference to the 4th kind of embodiment of first aspect, in the 5th kind of embodiment of first aspect,
It is determined that after the connection status of the mobile device, methods described also includes:
Relevant treatment is carried out to the mobile device;
After relevant treatment is carried out to the mobile device, the Hook Function calls the message transfer letter
It is several that transfer is carried out to the message.
In with reference to the 5th kind of embodiment of first aspect, in the 6th kind of embodiment of first aspect,
If it is determined that the connection status of the mobile device is insertion equipment, then relevant treatment is carried out to the mobile device,
Including:Before mobile device opening, virus scan treatment is carried out to the file in the mobile device.
Second aspect, the embodiment of the present invention provides a kind of device for determining mobile device connection status, including:
Monitoring module, for being monitored to the calling for message transfer function in Windows operating system;First
Judge module, whether the message for judging currently to want transfer is equipment connection Notification of Changes message;Second sentences
Disconnected module, if being equipment connection Notification of Changes message for currently wanting the message of transfer, connects according to equipment
Notification of Changes message determines the connection status of mobile device.
With reference to second aspect, in the first embodiment of second aspect, the monitoring module is located at should
With in the drive module of program.
With reference to the first embodiment of second aspect, in second embodiment of second aspect,
First judge module, including:First acquisition submodule, the class for obtaining the current message for wanting transfer
Shape parameter;First judging submodule, for judging whether the type parameter is predetermined parameter value, if so,
The message for then determining currently to want transfer is equipment connection Notification of Changes message, otherwise, it is determined that currently want transfer
Message be not equipment connection Notification of Changes message;First notifies submodule, if for currently wanting disappearing for transfer
Breath is equipment connection Notification of Changes message, then notify second judge module.
With reference to second embodiment of second aspect, in the third embodiment of second aspect,
Second judge module, including:Second acquisition submodule, if the message for currently wanting transfer is equipment
Connection Notification of Changes message, then obtain the information related to equipment connection Notification of Changes message;Second sentences
Disconnected submodule, for according to the information related to equipment connection Notification of Changes message, determining mobile device
Connection status.
With reference to second aspect and second aspect the first to any one in the third embodiment can
Embodiment, in the 4th kind of embodiment of second aspect, the connection status bag of the mobile device
Include:Insertion equipment, extraction equipment, equipment are already inserted into and/or equipment has been extracted.
With reference to the 4th kind of embodiment of second aspect, in the 5th kind of embodiment of second aspect,
The device of described determination mobile device connection status, also includes:Processing module, for it is determined that the shifting
After the connection status of dynamic equipment, relevant treatment is carried out to the mobile device;Calling module, for right
The mobile device is carried out after relevant treatment, call the message transfer function pair described in message carry out transfer.
With reference to the 5th kind of embodiment of second aspect, in the 6th kind of embodiment of second aspect,
The processing module, including:Scanning submodule, for if it is determined that the connection status of the mobile device is slotting
Enter equipment, then before mobile device opening, virus scan is carried out to the file in the mobile device
Treatment;Remind submodule, for it is determined that there is virus in the mobile device or during Malware, to
Reminded at family.
The method and device for determining mobile device connection status provided in an embodiment of the present invention, by Windows
Calling for message transfer function in operating system is monitored, when there is message to need transfer, judges current
Whether the message for wanting transfer is equipment connection Notification of Changes message, if so, then can be logical according to equipment connection change
Know that message determines the connection status of mobile device, so can in the message turn the connection change of function pair equipment logical
Know that message carries out transfer before processing, you can capture equipment connection Notification of Changes message, calmly can be quickly accurate
Really obtain the connection status of mobile device.
Specific embodiment
The method and device for determining mobile device connection status a kind of to the embodiment of the present invention is entered below in conjunction with the accompanying drawings
Row is described in detail.
It will be appreciated that described embodiment is only a part of embodiment of the invention, rather than whole realities
Apply example.Based on the embodiment in the present invention, those of ordinary skill in the art are not before creative work is made
The all other embodiment for being obtained is put, the scope of present invention protection is belonged to.
Fig. 1 is present invention determine that the schematic flow sheet of the embodiment of the method one of mobile device connection status.Referring to
Fig. 1, present invention determine that the embodiment of the method for mobile device connection status, comprises the following steps:
S101, the calling for message transfer function in Windows operating system is monitored.
In the present embodiment, the mobile device, also referred to as running gear (Mobile device), flowing
Device, hand-held device (handheld device) etc., are a kind of computing devices of pocket size, are generally had
One small display screens, touch-control input, or small-sized keyboard.
The type of mobile device has a lot, such as mobile phone, USB flash disk etc..For being provided with Windows operations system
The computer equipment of system, when have mobile device into and out when, Windows operating system can all be produced and disappeared
Breath, this message definition is WM_DEVICECHANGE, and it is 0x0219 to be worth.
In Windows operating system kernel, by message transfer function, i.e., all of Message Processing is all
NtUserMessageCall functions carry out transfer.In the present embodiment, by NtUserMessageCall letters
Several calling monitored, being capable of the Notification of Changes message of capture device connection in time.
S102, judgement currently want whether the message of transfer is equipment connection Notification of Changes message.
In the present embodiment, the type parameter of the message of transfer can be currently wanted by acquisition, according to such shape parameter
Whether the message for judging currently to want transfer is equipment connection Notification of Changes message.
If S103, the current message for want transfer are equipment connection Notification of Changes message, according to equipment connection change
More notification message determines the connection status of mobile device.
In the present embodiment, if the current message for want transfer is that equipment connects Notification of Changes message, can according to
The related information of equipment connection Notification of Changes message determines the connection status of mobile device.
The method for determining mobile device connection status provided in an embodiment of the present invention, operates by Windows
Calling for message transfer function in system is monitored, when there is message to need transfer, in judging currently to want
Whether the message for turning is equipment connection Notification of Changes message, if so, Notification of Changes then can be connected according to equipment disappearing
Breath determines the connection status of mobile device, so can in the message turn function pair equipment connection Notification of Changes and disappear
Breath carries out transfer before processing, you can capture equipment connection Notification of Changes message, calmly can be rapidly and accurately
Obtain the connection status of mobile device.
Fig. 2 is present invention determine that the schematic flow sheet of the embodiment of the method two of mobile device connection status.Referring to
Fig. 2, present invention determine that the embodiment of the method for mobile device connection status, comprises the following steps:
S201, the calling for message transfer function is monitored by Hook Function;Wherein, the hook
Subfunction is included in the driving of application program.
In the present embodiment, the mobile device, also referred to as running gear (Mobile device), flowing
Device, hand-held device (handheld device) etc., are a kind of computing devices of pocket size, are generally had
One small display screens, touch-control input, or small-sized keyboard.
The type of mobile device has a lot, such as mobile phone, USB flash disk etc..For being provided with Windows operations system
The computer equipment of system, when have mobile device into and out when, Windows operating system can all be produced and disappeared
Breath, this message definition is WM_DEVICECHANGE, and it is 0x0219 to be worth.
In Windows operating system kernel, by message transfer function, i.e., all of Message Processing is all
NtUserMessageCall functions carry out transfer.In the present embodiment, by NtUserMessageCall letters
Several calling monitored, being capable of the Notification of Changes message of capture device connection in time.
Before this step, can be by programming personnel in the driving of application program, such as in the anti-of Jinshan anti-virus software
In imperial driving, hook (HOOK) function is set up.
Hook Function is actually a program segment for treatment message, is called by system, and it is linked into system.
Whenever specific message sends, before without purpose window is reached, Hook Function just first captures the message, also
I.e. Hook Function first obtains control.At this moment Hook Function be can be with the working process message, it is also possible to do not make
Process and continue to transmit the message, the transmission of end can also be forced.
In the present embodiment, the present embodiment is revised as in the original entry address of NtUserMessageCall functions
In Hook Function entry address.Windows operating system when NtUserMessageCall functions are called,
Because the original entry address of NtUserMessageCall functions has been modified to the Hook Function of the present embodiment
Entry address, called by NtUserMessageCall functions, you can skip to the hook of the present embodiment
The execution of subfunction, is achieved in the monitoring to NtUserMessageCall functions.
In order to realize the readjustment to NtUserMessageCall functions, by NtUserMessageCall letters
Several original entry addresses be revised as the entry address of the Hook Function in the present embodiment before, it is necessary to right
The original entry address of NtUserMessageCall functions is preserved.
S202, judgement currently want whether the type parameter of the message of transfer is predetermined parameter value.
In the present embodiment, by the Hook Function judge the current message for wanting transfer type parameter whether be
Predetermined parameter value, that is, whether the type parameter for judging the current message for wanting transfer is 0x0219, if so, then
Step S203 is performed, otherwise, step S205 is performed.
S203, the acquisition information related to equipment connection Notification of Changes message, and it is true according to described information
Determine the connection status of mobile device.
By the related information of Hook Function acquisition and equipment connection Notification of Changes message, and according to
Described information determines the connection status of mobile device.
In the present embodiment, the information related to equipment connection Notification of Changes message has a lot, it is preferable that this reality
Apply example and be only concerned following three kinds of information:
(1), DBT_DEVICEARRIVAL, it is 0x8000 to be worth, and represents that equipment reaches information, that is, insert equipment;
(2), DBT_DEVICEREMOVECOMPLETE, it is 0x8004 to be worth, and represents that equipment deletes information, that is, dial
Go out equipment;
(3), DBT_DEVNODES_CHANGED, it is 0x0007 to be worth, and represents that facility information changes, that is, set
It is standby to be already inserted into or transferred to.
In the present embodiment, can be according to the information parameter value related to equipment connection Notification of Changes message, it is determined that moving
The connection status of dynamic equipment.
In the present embodiment, by judging to connect the related information of Notification of Changes message to equipment, if above
One kind in three kinds, then perform step S204, if not the one kind in above three kinds, then performs step S205.
S204, relevant treatment is carried out to the mobile device.
In the present embodiment, it is determined that after the connection status of the mobile device, can enter to the mobile device
Row relevant treatment.
Such as, however, it is determined that the connection status of the mobile device is insertion equipment, then beaten in the mobile device
Before opening, virus scan treatment is carried out to the file in the mobile device.If being found the malice such as virus
Software, then can remind user to carry out killing.
If it is determined that the connection status of the mobile device is extraction equipment, the text in it there is the mobile device
When part is in open mode, user can be reminded first to close the file of opening, mobile device is then extracted again.
If it is determined that the connection status of the mobile device automatically can then set the movement to be already inserted into equipment
It is standby to open.
If it is determined that the connection status of the mobile device can then cancel that the movement is set to have extracted equipment
The display of standby drive.
More than, only it is the illustrative explanation that relevant treatment is carried out to the mobile device, the invention is not restricted to this,
The mobile device can also be processed using other processing modes.
S205, call the message transfer function pair described in message carry out transfer.
In the present embodiment, after relevant treatment is carried out to the mobile device, the Hook Function calls institute
Message described in stating message transfer function pair carries out transfer.
In the present embodiment, original of the Hook Function according to the NtUserMessageCall functions for pre-saving
Beginning entry address, call NtUserMessageCall functions, it is complete by NtUserMessageCall functions
The transfer of the paired message.
The method for determining mobile device connection status provided in an embodiment of the present invention, by setting up in application program
Driving in Hook Function, calling for NtUserMessageCall functions is monitored, Neng Gou
The inner nuclear layer of windows operating systems is monitored to calling for NtUserMessageCall functions, quick accurate
Really capture the connection status of mobile device, and before can not yet being opened after mobile device insertion, to moving
File in dynamic equipment carries out previously-scanned treatment, if being found the Malwares such as virus, can remind use
Family carries out killing.
Fig. 3 is present invention determine that the structural representation of the device embodiment one of mobile device connection status.Referring to
Fig. 3, present invention determine that the device embodiment of mobile device connection status, including:Monitoring module 31, first
The judge module 33 of judge module 32 and second;Wherein,
Monitoring module 31, for being monitored to the calling for message transfer function in Windows operating system.
In the present embodiment, the mobile device, also referred to as running gear (Mobile device), flowing
Device, hand-held device (handheld device) etc., are a kind of computing devices of pocket size, are generally had
One small display screens, touch-control input, or small-sized keyboard.
The type of mobile device has a lot, such as mobile phone, USB flash disk etc..For being provided with Windows operations system
The computer equipment of system, when have mobile device into and out when, Windows operating system can all be produced and disappeared
Breath, this message definition is WM_DEVICECHANGE, and it is 0x0219 to be worth.
In Windows operating system kernel, by message transfer function, i.e., all of Message Processing is all
NtUserMessageCall functions carry out transfer.In the present embodiment, by NtUserMessageCall letters
Several calling monitored, being capable of the Notification of Changes message of capture device connection in time.
First judge module 32, whether the message for judging currently to want transfer is that equipment connection Notification of Changes disappears
Breath.In the present embodiment, the type parameter of the message of transfer can be currently wanted by acquisition, according to such shape parameter
Whether the message for judging currently to want transfer is equipment connection Notification of Changes message.
Second judge module 33, if being equipment connection Notification of Changes message for currently wanting the message of transfer,
The connection status that Notification of Changes message determines mobile device is connected according to equipment.In the present embodiment, if currently
The message of transfer is equipment connection Notification of Changes message, then can be according to related to equipment connection Notification of Changes message
Information determine the connection status of mobile device.
The device for determining mobile device connection status provided in an embodiment of the present invention, operates by Windows
Calling for message transfer function in system is monitored, when there is message to need transfer, in judging currently to want
Whether the message for turning is equipment connection Notification of Changes message, if so, Notification of Changes then can be connected according to equipment disappearing
Breath determines the connection status of mobile device, so can in the message turn function pair equipment connection Notification of Changes and disappear
Breath carries out transfer before processing, you can capture equipment connection Notification of Changes message, calmly can be rapidly and accurately
Obtain the connection status of mobile device.
The device of the present embodiment, can be used for performing the technical scheme of embodiment of the method shown in Fig. 1, and it realizes former
Reason is similar with technique effect, and here is omitted.
Fig. 4 is present invention determine that the structural representation of the device embodiment two of mobile device connection status.This reality
Apply in example, the monitoring module is in the drive module of application program.Referring to Fig. 4, the device of the present embodiment
On the basis of Fig. 3 shown device structures, further, first judge module 32 can include:
First acquisition submodule 321, the first judging submodule 322 and first notify submodule 323;Wherein,
First acquisition submodule 321, the type parameter for obtaining the current message for wanting transfer.
First judging submodule 322, for judging whether the type parameter is predetermined parameter value, if so,
The message for then determining currently to want transfer is equipment connection Notification of Changes message, otherwise, it is determined that currently want transfer
Message be not equipment connection Notification of Changes message.
Whether it is predetermined parameter value by the type parameter for judging the current message for wanting transfer in the present embodiment,
Whether the type parameter for judging the current message for wanting transfer is 0x0219, if, it is determined that currently want transfer
Message be equipment connection Notification of Changes message, otherwise, it is determined that the current message for want transfer is not equipment company
Connect Notification of Changes message.
First notifies submodule 323, if being equipment connection Notification of Changes message for currently wanting the message of transfer,
Second judge module is then notified, if the message for currently wanting transfer is not equipment connection Notification of Changes message,
Then notify the calling module 35.
In the present embodiment, further, second judge module 33 can include:Second obtains submodule
The judging submodule 332 of block 331 and second;Wherein,
Second acquisition submodule 331, if being equipment connection Notification of Changes message for currently wanting the message of transfer,
Then obtain the information related to equipment connection Notification of Changes message.
In embodiment, the information related to equipment connection Notification of Changes message has a lot, it is preferable that this implementation
Example is only concerned following three kinds of information:
(1), DBT_DEVICEARRIVAL, it is 0x8000 to be worth, and represents that equipment reaches information, that is, insert equipment;
(2), DBT_DEVICEREMOVECOMPLETE, it is 0x8004 to be worth, and represents that equipment deletes information, that is, dial
Go out equipment;
(3), DBT_DEVNODES_CHANGED, it is 0x0007 to be worth, and represents that facility information changes, that is, set
It is standby to be already inserted into or transferred to.
Second judging submodule 332, for connecting the related information of Notification of Changes message to equipment according to described,
Determine the connection status of mobile device.
In the present embodiment, can be according to the information parameter value related to equipment connection Notification of Changes message, it is determined that moving
The connection status of dynamic equipment.
In the present embodiment, further, the device of described determination mobile device connection status also includes:
Processing module 34 and calling module 35;Wherein,
Processing module 34, for it is determined that after the connection status of the mobile device, to the mobile device
Carry out relevant treatment.In the present embodiment, it is determined that after the connection status of the mobile device, can be to described
Mobile device carries out relevant treatment.
Such as, however, it is determined that the connection status of the mobile device is insertion equipment, then beaten in the mobile device
Before opening, virus scan treatment is carried out to the file in the mobile device.If being found the malice such as virus
Software, then can remind user to carry out killing.
If it is determined that the connection status of the mobile device is extraction equipment, the text in it there is the mobile device
When part is in open mode, user can be reminded first to close the file of opening, mobile device is then extracted again.
If it is determined that the connection status of the mobile device automatically can then set the movement to be already inserted into equipment
It is standby to open.
If it is determined that the connection status of the mobile device can then cancel that the movement is set to have extracted equipment
The display of standby drive.
More than, only it is the illustrative explanation that relevant treatment is carried out to the mobile device, the invention is not restricted to this,
The mobile device can also be processed using other processing modes.
Calling module 35, for after relevant treatment is carried out to the mobile device, calling the message in
Turning message described in function pair carries out transfer.
In the present embodiment, according to the original entry address of the NtUserMessageCall functions for pre-saving,
NtUserMessageCall functions are called, is completed to the message by NtUserMessageCall functions
Transfer.
In the present embodiment, further, the processing module 34, including:Scanning submodule 341 and prompting
Submodule 342;Wherein, submodule 341 is scanned, for if it is determined that the connection status of the mobile device is slotting
Enter equipment, then before mobile device opening, virus scan is carried out to the file in the mobile device
Treatment reminds submodule 342, right for when it is determined that there is virus or Malware in the mobile device
User is reminded.
The device for determining mobile device connection status provided in an embodiment of the present invention, by right
Calling for NtUserMessageCall functions monitored, can be in the inner nuclear layer pair of windows operating systems
Calling for NtUserMessageCall functions monitored, rapidly and accurately captures the connection shape of mobile device
State, and can mobile device insertion after not yet open before, the file in mobile device is carried out previously-scanned
Treatment, if being found the Malwares such as virus, can remind user to carry out killing.
The device of the present embodiment, can be used for performing the technical scheme of embodiment of the method shown in Fig. 2, and it realizes former
Reason is similar with technique effect, and here is omitted.
One of ordinary skill in the art will appreciate that all or part of flow in realizing above-described embodiment method,
Computer program be can be by instruct the hardware of correlation to complete, described program can be stored in a calculating
In machine read/write memory medium, the program is upon execution, it may include such as the flow of the embodiment of above-mentioned each method.
Wherein, described storage medium can for magnetic disc, CD, read-only memory (Read-Only Memory,
) or random access memory (Random Access Memory, RAM) etc. ROM.
The above, specific embodiment only of the invention, but protective range of the invention is not limited to
This, any one skilled in the art the invention discloses technical scope in, can readily occur in
Change or replacement, should all cover within protective range of the invention.Therefore, protective range of the invention
Should be defined by the protective range of claim.