CN108762962A - It prevents using abnormal method and apparatus, storage medium and electronic equipment - Google Patents
It prevents using abnormal method and apparatus, storage medium and electronic equipment Download PDFInfo
- Publication number
- CN108762962A CN108762962A CN201810479337.3A CN201810479337A CN108762962A CN 108762962 A CN108762962 A CN 108762962A CN 201810479337 A CN201810479337 A CN 201810479337A CN 108762962 A CN108762962 A CN 108762962A
- Authority
- CN
- China
- Prior art keywords
- unconsummated
- application
- message forwarding
- abnormal
- message
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/0703—Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
- G06F11/0793—Remedial or corrective actions
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
Embodiments of the present invention provide a kind of prevent using abnormal method.This method includes:During application operation, when the unconsummated method of the first object reference of the application, judge that this applies inbound message forwarding mechanism, executes following first message forwarding operation:Generate random class;Increase above-mentioned unconsummated method for the random class, and adds the realization logic of this method;And the second object of above-mentioned random class is created, so that the second object is executed the above method after realizing, and implementing result is sent to the first object.This method is forwarded by above-mentioned first message and is operated, and can be effectively prevented application and is abnormal, overcome the deficiencies in the prior art.In addition, embodiments of the present invention provide a kind of prevent using abnormal device, storage medium and electronic equipment.
Description
Technical field
Embodiments of the present invention are related to field of computer technology, more specifically, embodiments of the present invention are related to one kind
It prevents using abnormal method and apparatus, storage medium and electronic equipment.
Background technology
Currently, with the development of computer technology and electronics technology, the electronic equipments such as smart mobile phone or tablet computer
Function it is more and more, corresponding calculation processing function is also stronger and stronger.
In recent years, there is the extensive application (APP, Application) for various operating system platforms, these applications
Contacting in also gradually penetrating into daily life and working, and between all trades and professions is further inseparable.
Common operating system includes Linux, UNIX, Windows, IOS (apple Mobile operating system) and Android
Operating systems such as (Android operation systems), using the electronic equipment of such as aforesaid operations system by it is desirable to possess more
While fast processing speed, it is also desirable to more stable process performance can be possessed.
Invention content
But the existing application for such as above-mentioned various operating systems, often there is program exception.
Therefore in the prior art, user by such as electronic equipment using some in application, by due to some
When the application being made to be abnormal, which for example can kill process by operating system, and what is be presented to the user may be then that equipment is returned
To operation main interface or even blank screen or crash etc., this is very bothersome process.
Thus, it is also very desirable to a method of it prevents using abnormal (APP Carsh), so that using effective during operation
Ground prevents exception.
In the present context, embodiments of the present invention are intended to provide and a kind of prevent using abnormal method and apparatus, deposit
Contain the storage medium and electronic equipment of program.
In the first aspect of embodiment of the present invention, a kind of method prevented using exception is provided, including:Described
During application operation, when the unconsummated method of the first object reference of the application, the application inbound message forwarding is judged
Mechanism executes following first message forwarding operation:Generate random class;Increase the unconsummated method for the random class, and
Add the realization logic of this method;And the second object of the random class is created, after so that second object is executed realization
The method, and implementing result is sent to first object.
In one embodiment of the invention, the unconsummated method of the first object reference of the application includes:Described
The unconsummated method is not found in the caching method list of first object and method list.
In another embodiment of the present invention, the unconsummated method of the first object reference of the application further includes:?
The parent of first object is not until finding the unconsummated side yet in the caching method list of root class and method list
Method.
In yet another embodiment of the present invention, after the step of judging the application inbound message forwarding mechanism, and
Before the step of executing the first message forwarding operation, further include:Dynamic approach solution is carried out to the unconsummated method
Analysis failure.
In yet another embodiment of the present invention, it is described prevent further include using abnormal method:Executing described first
After message forwarding operation, whether judgement predetermined condition is true, and executes following second in the case where the predetermined condition is set up
Message forwarding operation:Message to be sent corresponding with the unconsummated method is sent to other recipients, and is received from institute
State the implementing result of other recipients return.
In yet another embodiment of the present invention, the predetermined condition includes:What the first message forwarding operation returned
Value is NO.
In yet another embodiment of the present invention, when the application starts, forwarded using corresponding to the first message
The predetermined message forwarding function of operation replaces root class (NSObject) message fast-forwarding function of the application
(forwardingTargetForSelector)。
In yet another embodiment of the present invention, it is described addition this method realization logic the step of include:Pass through Block
The function pointer (imp_implementationWithBlock) for being directed toward unconsummated method is created, addition this method is completed
Realize logic, and return value is null value.
In the second aspect of embodiment of the present invention, a kind of storage medium having program stored therein, described program are provided
Above-mentioned prevent using abnormal method is realized when being executed by processor.
In the third aspect of embodiment of the present invention, a kind of device prevented using exception is provided, including:Judgement is single
Member is suitable for during the application operation, when the unconsummated method of the first object reference of the application, judges the application
Inbound message forwarding mechanism, output first message forward trigger signal;And Dispatch Unit, it is adapted for described first
Message forwards trigger signal, executes following first message forwarding operation:Random class is generated, is unreal described in the random class increase
Existing method, and the realization logic of this method is added, and the second object of the random class is created, so that second object is held
The method after row realization, and implementing result is sent to first object.
In another embodiment of the present invention, the judging unit is suitable for the caching method list in first object
In the case of not finding the unconsummated method in method list, judge that the first object reference of the application is not implemented
Method.
In yet another embodiment of the present invention, the judging unit is suitable for the caching method list in first object
With method list and first object parent until not searched in the caching method list of root class and method list
In the case of the unconsummated method, the unconsummated method of the first object reference of the application is judged.
In yet another embodiment of the present invention, described device further includes dynamic method resolution unit;The judging unit
Suitable for exporting dynamic method resolution trigger signal after judging the application inbound message forwarding mechanism, to trigger the dynamic side
Method resolution unit carries out dynamic method resolution to the unconsummated method, and the dynamic method resolution unit to it is described not
The method of realization carries out exporting the first message forwarding trigger signal in the case of dynamic method resolution failure.
In yet another embodiment of the present invention, the Dispatch Unit is suitable for:Executing the first message forwarding
After operation, whether judgement predetermined condition is true, and following second message forwarding is executed in the case where the predetermined condition is set up
Operation:Message to be sent corresponding with the unconsummated method is sent to other recipients, and receives and is connect from described other
The implementing result that receipts person returns.
In yet another embodiment of the present invention, the Dispatch Unit is suitable for returning in first message forwarding operation
The value returned is to judge that the predetermined condition is set up in the case of NO.
In yet another embodiment of the present invention, it is described prevent further include using abnormal device:Function replacement unit is fitted
In when the application starts, answered using described in the predetermined message forwarding function replacement corresponding to first message forwarding operation
Root class (NSObject) message fast-forwarding function (forwardingTargetForSelector).
In yet another embodiment of the present invention, the Dispatch Unit is suitable for the realization logic in addition this method
When, it is created by Block and is directed toward the function pointer (imp_implementationWithBlock) of unconsummated method to complete
The realization logic of this method is added, and return value is null value.
In the fourth aspect of embodiment of the present invention, a kind of electronic equipment, including above-mentioned storage medium are provided.
According to preventing using abnormal method and apparatus, storage medium and electronic equipment for embodiment of the present invention,
When the unconsummated method of the object reference of application, the realization of this method is added by executing corresponding first message forwarding operation
Logic simultaneously to execute this method and sends result to the first object by the second object of newly-built random class, so as to big
Amplitude reduction is caused by calling unconsummated method using abnormal.In addition, according to the above-mentioned skill of embodiment of the present invention
Art scheme is, it can be achieved that without intrusion code (need not change application source code) and without writing decision logic (on not needing
State the prior art it is required before each execution method increase judge whether object realizes the process of the logic of this method) feelings
Under condition, it effectively prevent not only enormously simplifying development using exception caused by calling unconsummated method, but also
It is not error-prone.
Description of the drawings
Detailed description below, above-mentioned and other mesh of exemplary embodiment of the invention are read by reference to attached drawing
, feature and advantage will become prone to understand.In the accompanying drawings, if showing the present invention's by way of example rather than limitation
Dry embodiment, wherein:
Fig. 1 is a kind of exemplary process prevented using abnormal method schematically shown according to the embodiment of the present disclosure
Flow chart;
Fig. 2 is a kind of flow chart for the possible processing for schematically showing step S110 shown in FIG. 1;
Fig. 3 is the flow chart for the alternatively possible processing for schematically showing step S110 shown in FIG. 1;
Fig. 4 is the exemplary place of another kind prevented using abnormal method schematically shown according to the embodiment of the present disclosure
The flow chart of reason;
Fig. 5 is another the exemplary place prevented using abnormal method schematically shown according to the embodiment of the present disclosure
The flow chart of reason;
Fig. 6 is the preferable example prevented using abnormal method schematically shown according to the embodiment of the present disclosure
Flow chart;
Fig. 7 is the exemplary structure prevented using abnormal device schematically shown according to the embodiment of the present disclosure
Block diagram;
Fig. 8 is another the exemplary knot prevented using abnormal device schematically shown according to the embodiment of the present disclosure
Structure block diagram;
Fig. 9 is another the exemplary knot prevented using abnormal device schematically shown according to the embodiment of the present disclosure
Structure block diagram;
Figure 10 is the structural schematic diagram for showing the computer according to the embodiment of the present disclosure;
Figure 11 is the schematic diagram for showing the computer readable storage medium according to the embodiment of the present disclosure.
In the accompanying drawings, identical or corresponding label indicates identical or corresponding part.
Specific implementation mode
The principle and spirit of the invention are described below with reference to several illustrative embodiments.It should be appreciated that providing this
A little embodiments are used for the purpose of making those skilled in the art can better understand that realizing the present invention in turn, and be not with any
Mode limits the scope of the invention.On the contrary, these embodiments are provided so that the disclosure is more thorough and complete, and energy
It is enough that the scope of the present disclosure is completely communicated to those skilled in the art.
One skilled in the art will appreciate that embodiments of the present invention can be implemented as a kind of system, device, equipment, method
Or computer program product.Therefore, the disclosure can be with specific implementation is as follows, i.e.,:Complete hardware, complete software
The form that (including firmware, resident software, microcode etc.) or hardware and software combine.
According to the embodiment of the present invention, it is proposed that a kind of to prevent using abnormal method and apparatus, storage medium and electricity
Sub- equipment.
Herein, it is to be understood that any number of elements in attached drawing is used to example and unrestricted and any
Name is only used for distinguishing, without any restrictions meaning.
Below with reference to several representative embodiments of the present invention, the principle and spirit of the invention are illustrated in detail.
Summary of the invention
The inventors discovered that the prior art of the application for various operating systems, during application operation, if prominent
Application exception so occurs, which can often stop running or kill process by operating system, and may then go out on a user device
Now screen-picture is static to operate, or returns to operating system main interface, in some instances it may even be possible to the serious feelings such as blank screen or crash occur
Condition.Above application is abnormal so that the stability of application during operation is poor, and can be brought not to the work or life of user
Just so that the experience of user is poor.If in addition, user is carrying out significant data operation or opens certain vital document, but not having
When having backup, what is occurred suddenly can make the even all of significant data of user's lost part or file using abnormal, and this will
The work or life of user can be seriously affected.
Above application is abnormal, such as since Objective-C (or other object-oriented languages etc.) calling is unconsummated
Method and cause.This is because for such as similar to C language for this kind of programming language, function when being invoked at compiling i.e.
Determine which function called;And the function call of Objective-C belongs to dynamic call process, not can determine that when it is compiled
Which function is really called, only just can find corresponding function according to the title of function in real operation to call, this is just
So that the application that the object-oriented languages such as Objective-C are compiled, if some object of application is during operation
Unconsummated method is had invoked, entirely application will be caused abnormal or collapse.
The present invention provides a kind of prevent using abnormal method and apparatus, storage medium and electronics for the technical problem
Equipment, when the unconsummated method of the first object reference of the application, judges that this turns using inbound message during application operation
Hair mechanism executes following first message forwarding operation:Generate random class;Increase above-mentioned unconsummated method for the random class, and
Add the realization logic of this method;And the second object of above-mentioned random class is created, so that second object is executed the institute after realizing
Method is stated, and implementing result is sent to the first object;It follows that the technical solution that embodiment of the present invention provides is due to energy
Enough in the unconsummated method of the object reference of application, this method is added by executing corresponding first message forwarding operation
It realizes logic and this method is executed by the second object of newly-built random class, it is unconsummated due to calling so as to reduce
Using abnormal caused by method.
Currently, more existing prevent using abnormal technology, such as by increasing whether judge object before execution method
Realize that the logic of this method applies exception to reduce, which needs to calling each opaque object method that will increase
It is subject to judgement, this can influence code writing speed and quality.Therefore, this existing scheme can only rely on the coding water of developer
Gentle carefulness degree, this makes compiling workload huge, and development efficiency is relatively low;Also, since application is usually by many developers
Co-development together can not ensure everyone code robustness so that code is also easier to malfunction.With the above-mentioned prior art
It compares, of the invention preventing need not be in each execution method using abnormal method and apparatus, storage medium and electronic equipment
Preceding increase judges whether object realizes the logic of this method, not only enormously simplifies development, improves efficiency, and be not easy
Error.
After the basic principle for describing the present invention, lower mask body introduces the various non-limiting embodiment party of the present invention
Formula.
Illustrative methods
It describes to be prevented using abnormal method according to exemplary embodiment of the invention with reference to Fig. 1.It needs to note
Meaning, it is above-mentioned to prevent using abnormal method object-oriented language institute such as can be applied to such as Objective-C
The application of compiling and other applicable any scenes.
Fig. 1 schematically shows the illustrative place of one kind prevented using abnormal method according to the embodiment of the present disclosure
Manage flow 100.
As shown in Figure 1, after process flow 100 starts, step S110 is executed.
S110, during application operation, when the unconsummated method of the first object reference of the application, judge the application into
Enter message forwarding mechanism, then executes the first message forwarding operation as shown in step S121~S123.
As an example, the application in embodiment of the present invention can for example be adapted in such as intelligent mobile phone, tablet
The application run in the operating system of the intelligent electronic devices such as computer, notebook computer or desktop computer, or can be
Suitable for the application run on single server or computing cluster.The operating system that the application is applicable in for example may include but not
It is limited to:The operating systems such as Linux, UNIX, Windows, Android or iOS.The application for example can be using such as
The application that the object-oriented languages such as Objective-C are compiled, or can be the application using the compiling of other programming languages
Deng.
Furthermore, it is necessary to explanation, above-mentioned unconsummated method also includes undefined method.
As an example, the first object of the application in embodiment of the present invention for example can be some class in memory
Load a certain example, for example, in Objective-C any NSObject subclasses example.
During application operation, when some object O1 of application calls some method M1, can using object O1 as
First object, and may determine that whether the above method M1 that object O1 is called is unconsummated method:If method M1 is unrealized
Method, then judge this apply inbound message forwarding mechanism;Otherwise, it returns and re-executes step S110 to continue to judge.For example,
When object O1 subsequently calls another method M2 again, object O1 is determined as the first object again, and determine object O1 is called
Above method M2 whether be unconsummated method:If method M2 is unconsummated method, judge that this turns using inbound message
Hair mechanism;Otherwise, it returns and re-executes step S110 to continue to judge.For another example, as another object O2 call method M3, this
When object O2 is determined as the first object, and judge whether the above method M3 that object O2 is called is unconsummated method:If side
Method M3 is unconsummated method, then judges that this applies inbound message forwarding mechanism;Otherwise, return re-execute step S110 with after
It is continuous to judge, and so on.
It should be understood that one or more first objects can be existed simultaneously, executed respectively for each first object
Above-mentioned process flow 100.
As an example, in the step S110 in executing embodiment of the present invention, such as can be in the caching of the first object
Judge that the first object reference of the application is not implemented when not finding the unconsummated method in method list and method list
Method.
As shown in Fig. 2, in one example, in step S210, during application operation, as object O1 call methods M1
When, using object O1 as the first object, then execute step S220.
In step S220, this method M1 can be searched first in the caching method list of the first object O1:If searching
To this method M1, S230 is thened follow the steps;Otherwise (this method M1 is not found), execute step S240.
In step S230, this method M1 can be turned to and be implemented to carry out this method accordingly, to obtain implementing result, knot
Beam process flow 100.
In step S240, it can continue to search this method M1 in the method list of the first object O1:If finding this
Method M1, thens follow the steps S230;Otherwise (this method M1 is not found), execute step S250.
In step s 250, judge that this (subsequently for example executes step S121 or hereafter will using inbound message forwarding mechanism
The step S421 or S693 to be described etc.).
Above step S210~S250 as shown in Figure 2 can be as a kind of possible processing of step S110 shown in FIG. 1
Flow.
In addition, as an example, in the step S110 in executing embodiment of the present invention, such as can be in the first object
The unconsummated method is not found in caching method list and method list and in the parent of the first object until root class
In the case of also not finding the unconsummated method in caching method list and method list, the first couple of the application is judged
As calling unconsummated method.
As shown in figure 3, in another example, in step S310, during application operation, when object O1 call methods
When M1, using object O1 as the first object, step S320 is then executed.
In step s 320, this method M1 can be searched first in the caching method list of the first object O1:If searching
To this method M1, S330 is thened follow the steps;Otherwise (this method M1 is not found), execute step S340.
In step S330, this method M1 can be turned to and be implemented to carry out this method accordingly, to obtain implementing result, knot
Beam process flow 100.
In step S340, it can continue to search this method M1 in the method list of the first object O1:If finding this
Method M1, thens follow the steps S330;Otherwise (this method M1 is not found), execute step S350.
In step S350, it can continue to search this method in the caching method list of the parent F1 of the first object O1
M1:If finding this method M1, S330 is thened follow the steps;Otherwise (this method M1 is not found), execute step S360.
In step S360, it can continue to search this method M1 in the method list of the parent F1 of the first object O1:If
This method M1 is found, S330 is thened follow the steps;Otherwise (this method M1 is not found), execute step S370.
In step S370, it can continue to search this method in the caching method list of the parent F2 of above-mentioned parent F1
M1:If finding this method M1, S330 is thened follow the steps;Otherwise (this method M1 is not found), execute step S380.
In step S380, it can continue to search this method M1 in the method list of the parent F2 of above-mentioned parent F1:If
This method M1 is found, S330 is thened follow the steps;Otherwise (this method M1 is not found), execute step S390.
In the example shown in Fig. 3, it is assumed that the parent F2 of above-mentioned parent F1 is root class, that is to say, that in the first object O1
Caching method list and method list in do not find the unconsummated method, and the parent of the first object O1 until
The unconsummated method is not found in the caching method list of root class and method list in this way, in step S390 to sentence yet
Fixed this applies inbound message forwarding mechanism (the step S421 or S693 that subsequently for example executes step S121 or will be described below
Deng).
Above step S310~S390 as shown in Figure 3 can be as the alternatively possible place of step S110 shown in FIG. 1
Manage flow.
Fig. 2 and Fig. 3 respectively describe how to judge two kinds of the unconsummated method of the first object reference of application it is possible
Processing procedure, it should be appreciated that in other embodiments of the invention, however it is not limited to using Fig. 2 or shown in Fig. 3 processes come
Judge whether the object of the application calls unconsummated method, the process of the judgement for example can be according to suitable for different operation system
System and/or different programming language and use different judgements to handle, no longer repeat one by one here.
Step S121, random class is generated.
As an example, mechanism generation when random class can be run by RunTime, that is, at runtime, random to generate one
Random train A, and random train A is generated into class as class name.
For example, in step S121, random () function can be used to generate a character string classNameA, use word
Symbol string classNameA creates class A as class name.The corresponding pseudocode of the process for example can be as follows:
Step S122, the random class to be generated in step S121 increases unconsummated method, and adds the realization of this method
Logic.
As an example, the step of adding the realization logic of this method in embodiment of the present invention for example may include:Pass through
Block creates the function pointer (imp_implementationWithBlock) for being directed toward unconsummated method, completes the addition party
The realization logic of method, and return value is null value.Alternatively, the realization of this method can also be added in such a way that other are applicable in
Logic.
For example, in step S122, can be come in example above by using method class_addMethod when operation
The random class A just created increases method functionB,
In this way, by creating a method (such as functionB), the function pointer of this method is obtained, when by collapsing
The function pointer called is directed toward this method again by way of message forwarding, and this method will not cause collapse, to
It avoids and this time calls, and the above processing mode is fast.
Step S123, the second object for creating above-mentioned random class makes the second object execute the method after realizing, and will execute
As a result it is sent to the first object.End processing flow 100.
For example, in step S123, the random class generated in step S121 generates second pair by instantiating at runtime
As second object executes the method (such as functionB) after above-mentioned realization, and the implementing result obtained by execution this method is returned
Return the first object.
As an example, execute embodiment of the present invention step S110 in judge this using inbound message forwarding mechanism it
Afterwards, and before executing first message forwarding operation shown in step S121~S123, can also include:It is not implemented to above-mentioned
Method carry out dynamic method resolution failure.In this way, when the first object reference for determining the application in step S110 is not implemented
Method when, judge this apply inbound message forwarding mechanism;It is not to be immediately performed first after inbound message forwarding mechanism
Message forwarding operation, but dynamic method resolution first is carried out to above-mentioned unconsummated method, it is just held in the case where parsing failure
Row above-mentioned first message forwarding operation is as a result, user for calling the situation of unconsummated method to increase a kind of remedy
Chance.
With reference to Fig. 4 descriptions according to the illustrative place of another kind of the embodiment of the present disclosure prevented using abnormal method
Manage flow 400.
As shown in figure 4, in process flow 400, step S410 is first carried out.
In step S410, during application operation, when the first object O1 of the application calls unconsummated method M1
Judge that this applies inbound message forwarding mechanism.Then, step S420 is executed.
In the step s 420, dynamic method resolution is carried out to above-mentioned unconsummated method M1:If successfully resolved executes step
Rapid S430;If parsing failure, thens follow the steps S421.
Wherein, in step S430, middle this method M1 is realized accordingly based on analysis result executes this method M1, and terminates
Process flow 400.
In step S421, random class is generated.Then, step S422 is executed.
In step S422, the random class to be generated in step S421 increases unconsummated method, and adds this method
Realize logic.Then, step S423 is executed.
In step S423, the second object of above-mentioned random class is created, so that the second object is executed the method after realizing, and will
Implementing result is sent to the first object.End processing flow 400.
It should be noted that preventing from not including " to above-mentioned unreal using abnormal method according to the embodiment of the present disclosure
In the case of the step of existing method progress dynamic method resolution failure ", that is, when determining the first of the application in step S110
When the unconsummated method of object reference, judge that this applies inbound message forwarding mechanism, and inbound message forwarding mechanism it
After be immediately performed first message forwarding operation, without undergo above-mentioned dynamic method resolution the step of.Such processing mode energy
Enough it is suitable for some special scenes, such as is not necessarily to or the inconvenient scene etc. for carrying out dynamic method resolution to unconsummated method, by
This can improve treatment effeciency.
As an example, according to the embodiment of the present disclosure prevent using abnormal method exemplary process flow 100 or
In 400, it can also include the following steps:In executing such as Fig. 1 in step S121~S123 or Fig. 4 shown in step S421~S423
First message forwarding operation after, whether judgement predetermined condition true, and executes in the case where predetermined condition is set up following the
The forwarding operation of two message:Message to be sent corresponding with unconsummated method is sent to other recipients, and is received from other
The implementing result that recipient returns.
Wherein, above-mentioned predetermined condition for example may include:The value that first message forwarding operation returns is NO.With reference to figure
5 describe another illustrative process flow 500 prevented using abnormal method according to the embodiment of the present disclosure.
As shown in figure 5, step S510, S520, S521, S522, S523 and S530 in process flow 500 respectively can be with
Performed processing in correspondence step S410, S420, S421, S422, S423 and S430 in process flow 400 shown in Fig. 4
It is identical, and can realize similar function and technique effect, which is not described herein again.
In process flow 500 shown in Fig. 5, after executing the step S523, step S540 is executed.
In step S540, whether the value that judgement first message forwarding operation returns is NO:If first message forwarding operation
The value of return is NO, thens follow the steps the second message forwarding operation in S550;Otherwise, flow 500 is ended processing.
In step S550, message to be sent corresponding with above-mentioned unconsummated method is sent to other recipients, and
The implementing result returned from other recipients is received, flow 500 is ended processing.
In this way, when the return value of first message forwarding operation is NO, show current first message forwarding operation without
To expected handling result, operation can be forwarded to complete the complete forwarding of message by the second message of subsequent execution, from it
His recipient receives the implementing result for this method returned, calls the situation of unconsummated method to increase to be directed to for user
The chance that another is remedied is added.
It should be noted that in other embodiments of the invention, above-mentioned predetermined condition can also be that " first message forwards
The value that operation returns is other conditions except NO ", for example, the predetermined condition can rule of thumb be set, or by experiment or
It is set in conjunction with actual demand, which is not described herein again.
However, it should be understood that the step S520 and S530 in process flow 500 are optional rather than necessary steps
Suddenly, that is to say, that in other examples, S510 can also be executed the step and skip step S520 later and directly execute step
S521。
As an example, can when application starts (execute step S110 shown in FIG. 1, step S410 shown in Fig. 4 or
Before step S510 shown in fig. 5), application is replaced using the predetermined message forwarding function corresponding to first message forwarding operation
Root class (NSObject) message fast-forwarding function (forwardingTargetForSelector) (replace by hereinafter referred function
Operation).
In other words, step S121~S123 shown in FIG. 1 is (or shown in step S421~S423 or Fig. 5 shown in Fig. 4
Step S521~S523) can be realized by the above-mentioned function replacement operation when application starts.That is, this field skill
Art personnel can obtain according to the specific steps of above-mentioned first message forwarding operation and forward operation corresponding one with the first message
A predetermined message forwards function, this is replaced at the beginning of application starts with this predetermined message forwarding function applies original class
Message fast-forwarding function, come make the first object of the application after calling unconsummated method (alternatively it is also possible to be
First object is after calling unconsummated method and carrying out dynamic method resolution failure to above-mentioned unconsummated method), it is based on
The predetermined message forwards function and executes corresponding first message forwarding operation, so that entire application is not unconsummated because calling
Method and lead to exception.
In the following, describing the preferable example prevented using abnormal method according to the embodiment of the present disclosure in conjunction with Fig. 6
Process flow 600.
As shown in fig. 6, when application starts, process flow 600 starts, and executes step S601.
In step s 601, function replacement operation as described above is executed.Then, step S610 is executed.
In step S610, during application operation, as object O1 call method M1, using object O1 as first pair
As executing step S620.
In step S620, this method M1 can be searched first in the caching method list of the first object O1:If searching
To this method M1, S630 is thened follow the steps;Otherwise (this method M1 is not found), execute step S640.
In step S630, this method M1 can be turned to and be implemented to carry out this method accordingly, to obtain implementing result, knot
Beam process flow 600.
In step S640, it can continue to search this method M1 in the method list of the first object O1:If finding this
Method M1, thens follow the steps S630;Otherwise (this method M1 is not found), execute step S650.
In step S650, it can continue to search this method in the caching method list of the parent F1 of the first object O1
M1:If finding this method M1, S630 is thened follow the steps;Otherwise (this method M1 is not found), execute step S660.
In step S660, it can continue to search this method M1 in the method list of the parent F1 of the first object O1:If
This method M1 is found, S630 is thened follow the steps;Otherwise (this method M1 is not found), execute step S670.
In step S670, it can continue to search this method in the caching method list of the parent F2 of above-mentioned parent F1
M1:If finding this method M1, S630 is thened follow the steps;Otherwise (this method M1 is not found), execute step S680.
In step S680, it can continue to search this method M1 in the method list of the parent F2 of above-mentioned parent F1:If
This method M1 is found, S630 is thened follow the steps;Otherwise (this method M1 is not found), execute step S690.
In the example shown in Fig. 6, it is assumed that the parent F2 of above-mentioned parent F1 is root class, that is to say, that in the first object O1
Caching method list and method list in do not find the unconsummated method, and the parent of the first object O1 until
The unconsummated method is not found in the caching method list of root class and method list in this way, in step S690 to sentence yet
Fixed this applies inbound message forwarding mechanism, then executes step S691.
In step S691, dynamic method resolution is carried out to above-mentioned unconsummated method M1:If successfully resolved executes step
Rapid S692;If parsing failure, the first message forwarding operation of S693~S695 is thened follow the steps.
Wherein, in step S692, middle this method M1 is realized accordingly based on analysis result executes this method M1, and terminates
Process flow 600.
In step S693, random class is generated, then executes step S694.
In step S694, the random class to be generated in step S693 increases unconsummated method, and adds this method
Realize logic.Then step S695 is executed.
In step S695, the second object O2 of above-mentioned random class is created, the second object O2 is made to execute the method after realizing,
And implementing result is sent to the first object O1.Then, step S696 is executed.
In step S696, whether the value that judgement first message forwarding operation returns is that NO (is i.e. sent out in determination step S695
Whether the value for giving the implementing result of the first object O2 is NO):If the value is NO, the second message forwarding of S697 is thened follow the steps
Operation;Otherwise, flow 600 is ended processing.
In step S697, message to be sent corresponding with above-mentioned unconsummated method is sent to other recipients, and
The implementing result returned from other recipients is received, flow 600 is then ended processing.
As can be seen from the above description, the method for exemplary embodiment of the invention prevented using exception, in pair of application
When as calling unconsummated method, the realization logic of this method can be added by executing corresponding first message forwarding operation
And this method is executed by the second object of newly-built random class, so as to be greatly lowered due to calling unconsummated side
Using abnormal caused by method.
In addition, exemplary embodiment of the invention prevents from may be implemented in without intrusion code (i.e. not using abnormal method
Need to change application source code) and without writing decision logic (it is required in each side of execution that the above-mentioned prior art is not needed
Increase before method and judge whether object realizes the process of the logic of this method) in the case of, it is effectively prevented and is not implemented due to calling
Method caused by using abnormal, not only enormously simplify development, improve development efficiency, and not error-prone.
In addition, in the case of the application method according to the ... of the embodiment of the present invention prevented using exception, due to being greatly reduced
Using abnormal caused by calling unconsummated method so that in user level also can largely improve user
Experience reduces the generation that application is abnormal, collapses, and improves the operation stability of application or even equipment, can be effectively protected user
Data/file etc..
Exemplary embodiment of the invention is prevented using abnormal method, by executing above-mentioned first message forwarding behaviour
Make, can not invade the side of original class while being substantially reduced caused by calling unconsummated method using exception
Method list will not judge to have an impact to method list interrelated logic.That is, can be prevented above-mentioned using abnormal side
Method is embodied as an independent SDK component, and any application (such as iOS is applied or Android application) access can come into force, without
Change application source code.
Exemplary means
After describing the method for exemplary embodiment of the invention prevented using exception, next, right with reference to figure 7
Exemplary embodiment of the invention prevents from illustrating using abnormal device.
Referring to Fig. 7, it is schematically shown that according to an embodiment of the invention to prevent the structure using abnormal device from showing
Be intended to, which can be set in terminal device, for example, the device can be set to desktop computer, notebook computer,
In the intelligent electronic devices such as intelligent mobile phone and tablet computer;Certainly, the device of embodiment of the present invention can also be arranged
In server.The device 700 of embodiment of the present invention may include following component units:Judging unit 710 and message forwarding
Unit 720.
As shown in fig. 7, judging unit 710 is suitable for during application operation, when the first object reference of the application is not implemented
Method when, judge this apply inbound message forwarding mechanism, output first message forward trigger signal.
Dispatch Unit 720 is adapted for the first message forwarding trigger signal of the output of judging unit 710, executes the
The forwarding operation of one message:Random class is generated, increases above-mentioned unconsummated method for the random class, and the realization for adding this method is patrolled
Volume, and the second object of the random class is created, so that second object is executed the above method after realizing, and implementing result is sent out
Give the first object.Wherein, above-mentioned first message forwarding operation can for example execute and above in conjunction with step described in Fig. 1
S121~S123 (or step S421~S423 shown in Fig. 4, step S521~S523 shown in fig. 5, step shown in fig. 6
S693~S695 etc.) in the identical processing of processing, and similar function and effect can be reached, which is not described herein again.
As an example, Dispatch Unit 720 can for example be created when adding the realization logic of this method by Block
It builds and is directed toward the function pointer of unconsummated method to complete the realization logic of addition this method, and return value is null value.Alternatively,
Dispatch Unit 720 can also add the realization logic of this method in such a way that other are applicable in.
As an example, the judging unit 710 in embodiment of the present invention can for example be arranged in the caching method of the first object
In the case of not finding the unconsummated method in table and method list, judge that the first object reference of the application is not implemented
Method, to judge this apply inbound message forwarding mechanism, for example, judging unit 710 can by execute it is above in conjunction
Step S210~S250 described in Fig. 2 is identical to be handled to realize the above processing, and can reach similar function and effect
Fruit, which is not described herein again.
As an example, the judging unit 710 in embodiment of the present invention can also be in the caching method list of the first object
With method list and the first object parent until not finding this in the caching method list of root class and method list
In the case of unconsummated method, the unconsummated method of the first object reference of the application is judged, to judge that the application enters
Message forwarding mechanism, for example, judging unit 710 can be by executing step S310~S390 described in Fig. 3 above in conjunction
It is identical to handle to realize the above processing, and similar function and effect can be reached, which is not described herein again.
It should be understood that in other embodiments of the invention, judging unit 710 is not limited to use Fig. 2 or Fig. 3 institutes
The process shown judges whether the object of the application calls unconsummated method, the process of the judgement for example can according to suitable for
Different operating system and/or different programming language and use different judgements to handle, no longer repeat one by one here.
Fig. 8 shows another example arrangement prevented using abnormal device according to embodiment of the present invention.
As shown in figure 8, preventing from using abnormal device 800 may include judging unit 810,820 and of Dispatch Unit
Dynamic method resolution unit 830.
It is shown in Fig. 8 to prevent using in abnormal device 800, judging unit 810 for example can during application operation,
When the unconsummated method of the first object reference of the application, judges that this applies inbound message forwarding mechanism, export dynamic approach
Trigger signal is parsed, dynamic method resolution is carried out to above-mentioned unconsummated method to trigger dynamic method resolution unit 830.
It is successful to above-mentioned unconsummated method progress dynamic method resolution in dynamic method resolution unit 830,
Such as middle this method it can realize accordingly based on analysis result and execute this method.
In the case where dynamic method resolution unit 830 carries out dynamic method resolution failure to above-mentioned unconsummated method,
It enables judging unit 810 export above-mentioned first message forwarding trigger signal executing above-mentioned first to trigger Dispatch Unit 820 and disappear
Breath forwarding operation.Wherein, triggering Dispatch Unit 820 can for example execute the described triggering message of Fig. 7 above in conjunction
First message forwarding performed by retransmission unit 720 operates identical processing, and can reach similar function and effect, this
In repeat no more.
Wherein, dynamic method resolution unit 830 can for example execute step S420 described in Fig. 4 above in conjunction and
The similar processing of alignment processing in S430, and can realize similar function and technique effect, which is not described herein again.
In this way, when judging unit 810 determines the unconsummated method of the first object reference of the application, the application is judged
Inbound message forwarding mechanism, and after inbound message forwarding mechanism is not to execute the by Dispatch Unit 820 immediately
The forwarding operation of one message, but first pass through dynamic method resolution unit 830 and dynamic approach solution is carried out to above-mentioned unconsummated method
Analysis just triggers Dispatch Unit 820 and executes the forwarding operation of above-mentioned first message parsing the in the case of of failing, as a result, for
Family increases a kind of chance remedied for the situation of the unconsummated method of calling.
Furthermore, it is necessary to which explanation, prevents from not including dynamic side using abnormal device according to the embodiment of the present disclosure
In the case of method resolution unit, that is, when judging unit 810 determines the unconsummated method of the first object reference of the application
When, judge that this applies inbound message forwarding mechanism, and Dispatch Unit is triggered immediately after inbound message forwarding mechanism
820 execute first message forwarding operation.Such processing mode can be suitable for some special scenes, such as be not necessarily to or inconvenient right
Unconsummated method carries out the scene etc. of dynamic method resolution, and thus, it is possible to improve treatment effeciency.
In addition, as an example, the Dispatch Unit 720 or 820 in embodiment of the present invention disappears in execution above-mentioned first
After breath forwarding operation, it can also judge whether predetermined condition is true, and following second is executed in the case where predetermined condition is set up
Message forwarding operation:Message to be sent corresponding with above-mentioned unconsummated method is sent to other recipients, and is received from this
The implementing result that other recipients return.
Wherein, Dispatch Unit 720 or 820 can first message forward operation return value be NO in the case of sentence
Fixed above-mentioned predetermined condition is set up.For example, Dispatch Unit 720 or 820 can be by executing described in Fig. 5 above in conjunction
The identical processing of step S540~S550, and similar function and effect can be reached, which is not described herein again.
In this way, when the return value of first message forwarding operation is NO, show current first message forwarding operation without
To expected handling result, Dispatch Unit 720 or 820 can be continued through and execute second message forwarding operation to complete to disappear
The complete forwarding ceased receives the implementing result for this method returned from other recipients, is called not to be directed to for user
The situation of the method for realization increases another chance remedied.
It should be noted that in other embodiments of the invention, above-mentioned predetermined condition can also be that " first message forwards
The value that operation returns is other conditions except NO ", for example, the predetermined condition can rule of thumb be set, or by experiment or
It is set in conjunction with actual demand, which is not described herein again.
Fig. 9 shows another example arrangement prevented using abnormal device according to embodiment of the present invention.Such as
Shown in Fig. 9, prevent from using abnormal device 900 may include judging unit 910, Dispatch Unit 920, dynamic method resolution
Unit 930 and function replacement unit 940.Wherein, judging unit 910, Dispatch Unit 920 and dynamic method resolution unit
930 can for example execute judging unit 810, Dispatch Unit 820 and dynamic side described in Fig. 8 above in conjunction respectively
The 830 identical processing of method resolution unit, and similar function and effect can be reached, which is not described herein again.
As shown in figure 9, function replacement unit 940 can for example execute function described above when application starts replaces behaviour
Make, that is, this is replaced using the predetermined message forwarding function for corresponding to the forwarding operation of above-mentioned first message at the beginning of application starts and is answered
Root class (NSObject) message fast-forwarding function (forwardingTargetForSelector).
Wherein, function replacement unit 940 can for example execute the correspondence in step S601 described in Fig. 6 above in conjunction
Similar processing is handled, and can realize similar function and technique effect, which is not described herein again.
It should be noted that those skilled in the art can obtain according to the specific processing of above-mentioned first message forwarding operation
It obtains a predetermined message corresponding with first message forwarding operation and forwards function, pass through the processing of function replacement unit 940, use
This predetermined message forwards function to be replaced at the beginning of application starts using original class message fast-forwarding function, to make
First object of the application is after calling unconsummated method (alternatively it is also possible to be unconsummated in calling in the first object
Method and after carrying out dynamic method resolution failure to above-mentioned unconsummated method), execute corresponding first message forwarding behaviour
Make, so that entire application does not cause because calling unconsummated method using abnormal
It should be noted that the dynamic method resolution unit 930 in Fig. 9 adopts the dynamic method resolution list that is indicated by the dashed box
Member 930 is optional rather than necessary.That is, in other examples, it is shown in Fig. 9 to prevent from also using abnormal device 900
Not include dynamic method resolution unit 930, in this case, judging unit 910 and Dispatch Unit 920 for example can be with
The 720 identical processing of judging unit 710 described in Fig. 7 above in conjunction and Dispatch Unit is executed respectively, and can be reached
To similar function and effect, which is not described herein again.
As can be seen from the above description, the device of exemplary embodiment of the invention prevented using exception, in pair of application
When as calling unconsummated method, the realization logic of this method can be added by executing corresponding first message forwarding operation
And this method is executed by the second object of newly-built random class, so as to be greatly lowered due to calling unconsummated side
Using abnormal caused by method.
In addition, exemplary embodiment of the invention prevents from may be implemented in without intrusion code (i.e. not using abnormal device
Need to change application source code) and without writing decision logic (it is required in each side of execution that the above-mentioned prior art is not needed
Increase before method and judge whether object realizes the process of the logic of this method) in the case of, it is effectively prevented and is not implemented due to calling
Method caused by using abnormal, not only enormously simplify development, improve development efficiency, and not error-prone.
In addition, in the case of the application device according to the ... of the embodiment of the present invention prevented using exception, due to being greatly reduced
Using abnormal caused by calling unconsummated method so that in user level also can largely improve user
Experience reduces the generation that application is abnormal, collapses, and improves the operation stability of application or even equipment, can be effectively protected user
Data/file etc..
Exemplary embodiment of the invention is prevented using abnormal device, by executing above-mentioned first message forwarding behaviour
Make, can not invade the side of original class while being substantially reduced caused by calling unconsummated method using exception
Method list will not judge to have an impact to method list interrelated logic.That is, can be prevented above-mentioned using abnormal dress
It sets and is embodied as an independent SDK component, any application (such as iOS is applied or Android application) access can come into force, without
Change application source code.
Figure 10 shows the frame of the exemplary computer system/server 1000 suitable for being used for realizing embodiment of the present invention
Figure.The computer system/server 1000 that Figure 10 is shown is only an example, to the function of the embodiment of the present invention and should not be made
With range band come any restrictions.
As shown in Figure 10, computer system/server 1000 is showed in the form of universal electronic device.Computer system/
The component of server 1000 can include but is not limited to:One or more processor or processing unit 1001, system storage
Device 1002, the bus 1003 of connection different system component (including system storage 1002 and processing unit 1001).
Computer system/server 1000 typically comprises a variety of computer system readable media.These media can be
Any usable medium that can be accessed by computer system/server 1000, including volatile and non-volatile media move
And immovable medium.
System storage 1002 may include the computer system readable media of form of volatile memory, such as deposit at random
Access to memory (RAM) 10021 and/or cache memory 10022.Computer system/server 1000 can be wrapped further
Include other removable/nonremovable, volatile/non-volatile computer system storage mediums.Only as an example, ROM10023
It can be used for reading and writing immovable, non-volatile magnetic media (not shown in Figure 10, commonly referred to as " hard disk drive ").Although
It is not shown in FIG. 10, it can provide for the disc driver to moving non-volatile magnetic disk (such as " floppy disk ") read-write,
And the CD drive to moving anonvolatile optical disk (such as CD-ROM, DVD-ROM or other optical mediums) read-write.?
In the case of these, each driver can be connected by one or more data media interfaces with bus 1003.System stores
May include at least one program product in device 1002, which has one group of (for example, at least one) program module, this
A little program modules are configured to perform the function of various embodiments of the present invention.
Program/utility 10025 with one group of (at least one) program module 10024, can be stored in and be for example
In system memory 1002, and such program module 10024 includes but not limited to:Operating system, one or more apply journey
Sequence, other program modules and program data may include network environment in each or certain combination in these examples
It realizes.Program module 10024 usually executes function and/or method in embodiment described in the invention.
Computer system/server 1000 can also with one or more external equipments 1004 (such as keyboard, sensing equipment,
Display etc.) communication.This communication can be carried out by input/output (I/O) interface 1005.Also, computer system/service
Device 1000 can also pass through network adapter 1006 and one or more network (such as LAN (LAN), wide area network (WAN)
And/or public network, such as internet) communication.As shown in Figure 10, network adapter 1006 passes through bus 1003 and department of computer science
Other modules (such as processing unit 1001) of system/server 1000 communicate.It, can be with it should be understood that although being not shown in Figure 10
Other hardware and/or software module are used in conjunction with computer system/server 1000.
Processing unit 1001 is stored in the program in system storage 1002 by operation, to perform various functions application
And data processing, for example, executing and realizing each step prevented using in abnormal method;For example, during application operation,
When the unconsummated method of the first object reference of the application, judges that this applies inbound message forwarding mechanism, execute following first
Message forwarding operation:Generate random class;Increase above-mentioned unconsummated method for the random class, and the realization for adding this method is patrolled
Volume;And the second object of above-mentioned random class is created, so that the second object is executed the above method after realizing, and implementing result is sent out
Give first pair;The specific implementation of each step this will not be repeated here as.
One specific example of computer readable storage medium of embodiment of the present invention is as shown in figure 11.
The computer readable storage medium of Figure 11 is CD 1100, is stored thereon with computer program (i.e. program product),
When the program is executed by processor, each step recorded in above method embodiment can be realized, for example, in application run-time
Between, when the unconsummated method of the first object reference of the application, judges that this applies inbound message forwarding mechanism, execute following the
The forwarding operation of one message:Generate random class;Increase above-mentioned unconsummated method for the random class, and the realization for adding this method is patrolled
Volume;And the second object of above-mentioned random class is created, so that the second object is executed the above method after realizing, and implementing result is sent out
Give the first object;This will not be repeated here for the specific implementation of each step.
It should be noted that although being referred in above-detailed prevents several units using abnormal device, module
Or submodule, but it is this division be only exemplary it is not enforceable.In fact, according to the embodiment of the present invention,
The feature and function of two or more above-described modules can embody in a module.Conversely, above-described one
The feature and function of a module can be further divided into be embodied by multiple modules.
In addition, although describing the operation for the method that the present invention is prevented using exception with particular order in the accompanying drawings,
This, which does not require that or implies, to execute these operations according to the particular order, or has to carry out and operated shown in whole
It could realize desired result.Additionally or alternatively, it is convenient to omit multiple steps are merged into a step and held by certain steps
Row, and/or a step is decomposed into execution of multiple steps.
Although by reference to several spirit and principle that detailed description of the preferred embodimentsthe present invention has been described, it should be appreciated that, this
It is not limited to the specific embodiments disclosed for invention, does not also mean that the feature in these aspects cannot to the division of various aspects
Combination is this to divide the convenience merely to statement to be benefited.The present invention is directed to cover appended claims spirit and
Included various modifications and equivalent arrangements in range.
Finally, it is to be noted that, in the disclosure, such as left and right, first and second or the like relational terms
It is only used to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying these
There are any actual relationship or orders between entity or operation.Moreover, the terms "include", "comprise" or its is any
Other variants are intended to non-exclusive inclusion, so that including the process, method, article or equipment of a series of elements
Include not only those elements, but also include other elements that are not explicitly listed, or further includes for this process, side
Method, article or the intrinsic element of equipment.In the absence of more restrictions, limited by sentence "including a ..."
Element, it is not excluded that there is also other identical elements in the process, method, article or apparatus that includes the element.
To sum up, in accordance with an embodiment of the present disclosure, present disclose provides following scheme, but not limited to this:
Scheme 1. is a kind of to be prevented using abnormal method, it is characterised in that including:
During the application operation, when the unconsummated method of the first object reference of the application, answered described in judgement
With inbound message forwarding mechanism, following first message forwarding operation is executed:
Generate random class;
Increase the unconsummated method for the random class, and adds the realization logic of this method;And
The second object for creating the random class makes second object execute the method after realizing, and will execute
As a result it is sent to first object.
Scheme 2. is prevented according to scheme 1 using abnormal method, which is characterized in that the first object of the application
The unconsummated method is called to include:It is unreal this is not found in the caching method list of first object and method list
Existing method.
Scheme 3. is prevented according to scheme 2 using abnormal method, which is characterized in that the first object of the application
The unconsummated method is called to further include:First object parent until in the caching method list of root class and method list
The unconsummated method is not found yet.
Scheme 4. is prevented according to any one of scheme 1-3 using abnormal method, which is characterized in that in judgement institute
After stating the step of applying inbound message forwarding mechanism, and before the step of executing the first message forwarding operation, also wrap
It includes:Dynamic method resolution failure is carried out to the unconsummated method.
Scheme 5. is prevented according to any one of scheme 1-4 using abnormal method, it is characterised in that further includes:?
After executing the first message forwarding operation, whether judgement predetermined condition is true, and in the case where the predetermined condition is set up
Execute following second message forwarding operation:
Message to be sent corresponding with the unconsummated method is sent to other recipients, and receive from it is described other
The implementing result that recipient returns.
Scheme 6. is prevented according to scheme 5 using abnormal method, which is characterized in that the predetermined condition includes:
The value that the first message forwarding operation returns is NO.
Scheme 7. is prevented according to any one of scheme 1-6 using abnormal method, which is characterized in that is answered described
When with starting, using the root class for replacing the application corresponding to the predetermined message forwarding function of first message forwarding operation
(NSObject) message fast-forwarding function (forwardingTargetForSelector).
Scheme 8. is prevented according to any one of scheme 1-7 using abnormal method, which is characterized in that the addition
The step of realization logic of this method includes:Function pointer (the imp_ for being directed toward unconsummated method is created by Block
ImplementationWithBlock), the realization logic of addition this method is completed, and return value is null value.
The storage medium that scheme 9. has program stored therein is realized when described program is executed by processor according in scheme 1 to 8
Any one of them is prevented using abnormal method.
Scheme 10. is a kind of to be prevented using abnormal device, it is characterised in that including:
Judging unit is suitable for during the application operation, when the unconsummated method of the first object reference of the application
When, judge that the application inbound message forwarding mechanism, output first message forward trigger signal;And
Dispatch Unit is adapted for the first message forwarding trigger signal, executes following first message forwarding
Operation:Random class is generated, increases the unconsummated method for the random class, and add the realization logic of this method, and
The second object for creating the random class makes second object execute the method after realizing, and implementing result is sent
To first object.
Scheme 11. is prevented according to scheme 10 using abnormal device, which is characterized in that the judging unit is suitable for
In the case of the unconsummated method not being found in the caching method list of first object and method list, judgement
The unconsummated method of the first object reference of the application.
Scheme 12. is prevented according to scheme 10 using abnormal device, which is characterized in that the judging unit is suitable for
The caching method list of first object and method list and first object parent until root class caching
In the case of not finding the unconsummated method in method list and method list, the first object tune of the application is judged
With unconsummated method.
Scheme 13. is prevented according to any one of scheme 10-12 using abnormal device, it is characterised in that further includes
Dynamic method resolution unit;
The judging unit is suitable for the output dynamic method resolution triggering after judging the application inbound message forwarding mechanism
Signal carries out dynamic method resolution to trigger the dynamic method resolution unit to the unconsummated method, and described dynamic
State method resolution unit exports the first message in the case of carrying out dynamic method resolution failure to the unconsummated method
Forward trigger signal.
Scheme 14. is prevented according to any one of scheme 10-13 using abnormal device, which is characterized in that described
Dispatch Unit is suitable for:
After executing first message forwarding operation, whether judgement predetermined condition true, and the predetermined condition at
Following second message forwarding operation is executed in the case of vertical:Message to be sent corresponding with the unconsummated method is sent to
Other recipients, and receive the implementing result returned from other described recipients.
Scheme 15. is prevented according to scheme 14 using abnormal device, which is characterized in that the Dispatch Unit
Value suitable for forwarding operation to return in the first message judges that the predetermined condition is set up in the case of being NO.
Scheme 16. is prevented according to any one of scheme 10-15 using abnormal device, it is characterised in that is also wrapped
It includes:
Function replacement unit is suitable for when the application starts, using corresponding to the pre- of first message forwarding operation
Determine root class (NSObject) message fast-forwarding function that message forwarding function replaces the application
(forwardingTargetForSelector)。
Scheme 17. is prevented according to any one of scheme 10-16 using abnormal device, which is characterized in that described
Dispatch Unit is suitable for, when adding the realization logic of this method, the function for being directed toward unconsummated method being created by Block
Pointer (imp_implementationWithBlock) completes the realization logic of addition this method, and return value is null value.
18. electronic equipment of scheme includes the storage medium according to scheme 9.
Claims (10)
1. a kind of prevent using abnormal method, it is characterised in that including:
During the application operation, when the unconsummated method of the first object reference of the application, judgement it is described apply into
Enter message forwarding mechanism, executes following first message forwarding operation:
Generate random class;
Increase the unconsummated method for the random class, and adds the realization logic of this method;And
The second object for creating the random class makes second object execute the method after realizing, and by implementing result
It is sent to first object.
2. according to claim 1 prevent using abnormal method, which is characterized in that the first object reference of the application
Unconsummated method includes:It is unconsummated this is not found in the caching method list of first object and method list
Method.
3. according to claim 2 prevent using abnormal method, which is characterized in that the first object reference of the application
Unconsummated method further includes:First object parent until in the caching method list of root class and method list also
The unconsummated method is not found.
4. according to any one of claim 1-3 prevent using abnormal method, which is characterized in that answered described in judgement
After the step of inbound message forwarding mechanism, and before the step of executing the first message forwarding operation, further include:It is right
The unconsummated method carries out dynamic method resolution failure.
5. being prevented using abnormal method according to any one of claim 1-4, it is characterised in that further include:It is executing
After the first message forwarding operation, whether judgement predetermined condition is true, and is executed in the case where the predetermined condition is set up
Following second message forwarding operation:
Message to be sent corresponding with the unconsummated method is sent to other recipients, and is received from other described receptions
The implementing result that person returns.
6. according to any one of claims 1-5 prevent using abnormal method, which is characterized in that opened in the application
When dynamic, the root class message that the application is replaced using the predetermined message forwarding function corresponding to first message forwarding operation is fast
Speed forwarding function.
7. being prevented using abnormal method according to any one of claim 1-6, which is characterized in that the addition party
The step of realization logic of method includes:The function pointer for being directed toward unconsummated method is created by Block, completes addition this method
Realization logic, and return value is null value.
8. the storage medium having program stored therein is realized when described program is executed by processor according to any one of claim 1-7
Described prevents using abnormal method.
9. a kind of prevent using abnormal device, it is characterised in that including:
Judging unit is suitable for during the application operation, when the unconsummated method of the first object reference of the application, sentences
The fixed application inbound message forwarding mechanism, output first message forward trigger signal;And
Dispatch Unit is adapted for the first message forwarding trigger signal, executes following first message forwarding operation:
Random class is generated, increases the unconsummated method for the random class, and add the realization logic of this method, and create institute
The second object for stating random class makes second object execute the method after realizing, and implementing result is sent to described
First object.
10. electronic equipment, including storage medium according to claim 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810479337.3A CN108762962A (en) | 2018-05-18 | 2018-05-18 | It prevents using abnormal method and apparatus, storage medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810479337.3A CN108762962A (en) | 2018-05-18 | 2018-05-18 | It prevents using abnormal method and apparatus, storage medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN108762962A true CN108762962A (en) | 2018-11-06 |
Family
ID=64007239
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810479337.3A Pending CN108762962A (en) | 2018-05-18 | 2018-05-18 | It prevents using abnormal method and apparatus, storage medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108762962A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110083474A (en) * | 2019-04-22 | 2019-08-02 | 无线生活(杭州)信息科技有限公司 | Prevent the method and device of application crash |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2015035574A1 (en) * | 2013-09-11 | 2015-03-19 | 华为技术有限公司 | Failure processing method, computer system, and apparatus |
US20170230457A1 (en) * | 2016-02-05 | 2017-08-10 | Microsoft Technology Licensing, Llc | Idempotent Server Cluster |
CN107436832A (en) * | 2016-05-27 | 2017-12-05 | 阿里巴巴集团控股有限公司 | A kind of dynamic buries method, apparatus and electronic equipment a little |
CN107479984A (en) * | 2016-09-29 | 2017-12-15 | 北京超图软件股份有限公司 | Message based distributed space data processing system |
-
2018
- 2018-05-18 CN CN201810479337.3A patent/CN108762962A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2015035574A1 (en) * | 2013-09-11 | 2015-03-19 | 华为技术有限公司 | Failure processing method, computer system, and apparatus |
US20170230457A1 (en) * | 2016-02-05 | 2017-08-10 | Microsoft Technology Licensing, Llc | Idempotent Server Cluster |
CN107436832A (en) * | 2016-05-27 | 2017-12-05 | 阿里巴巴集团控股有限公司 | A kind of dynamic buries method, apparatus and electronic equipment a little |
CN107479984A (en) * | 2016-09-29 | 2017-12-15 | 北京超图软件股份有限公司 | Message based distributed space data processing system |
Non-Patent Citations (3)
Title |
---|
LEA_DONGYANG: "" iOS开发-Runtime详解(简书)"", 《HTTPS://BLOG.CSDN.NET/LEA_DONGYANG/ARTICLE/DETAILS/74942718》 * |
一个低调的IOS开发: ""iOS开发-Runtime详解"", 《HTTPS://WWW.CNBLOGS.COM/IOSHE/P/5489086.HTML》 * |
陶泽宇: "Baymax:网易iOS App运行时Crash自动防护实践", 《HTTPS://MP.WEIXIN.QQ.COM/S?__BIZ=MZUXMZCXMZE5NG==&MID=2247488311&IDX=1&SN=0DB090C8D4A5EFAFA47F00AF4B3F174F》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110083474A (en) * | 2019-04-22 | 2019-08-02 | 无线生活(杭州)信息科技有限公司 | Prevent the method and device of application crash |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9336201B2 (en) | Regular expression word verification | |
US8626786B2 (en) | Dynamic language checking | |
CN103853650A (en) | Test case generating method and device for fuzz testing | |
US20210089587A1 (en) | System and Method for Determining Application Programming Interface and Object Bindings on Natural Language Processed Inputs | |
CN109243425A (en) | Speech recognition test method, device, system, computer equipment and storage medium | |
CN110688096B (en) | Method and device for constructing application program containing plug-in, medium and electronic equipment | |
WO2021175053A1 (en) | Method and apparatus for executing functional module in virtual machine | |
CN114328208A (en) | Code detection method and device, electronic equipment and storage medium | |
CN113051895A (en) | Method, apparatus, electronic device, medium, and program product for speech recognition | |
US7716531B2 (en) | System and method for fault mapping of exceptions across programming models | |
CN110765069B (en) | Data migration method, device and system | |
CN111078228A (en) | Method and device for converting webpage into small program, server and storage medium | |
CN108762962A (en) | It prevents using abnormal method and apparatus, storage medium and electronic equipment | |
CN114201756A (en) | Vulnerability detection method and related device for intelligent contract code segment | |
CN106502707B (en) | Code generation method and device | |
CN111399842B (en) | Code compiling method and device | |
CN113272799B (en) | Code information extractor | |
CN111783401A (en) | Character string processing method and device, computer storage medium and electronic equipment | |
US20050289525A1 (en) | Extensible command line parsing | |
US20230418566A1 (en) | Programmatically generating evaluation data sets for code generation models | |
CN109788126A (en) | Verify code imput method and equipment | |
CN112306694B (en) | Memory analysis method and device, computer readable storage medium and electronic equipment | |
EP3872630A2 (en) | Request processing method and apparatus, electronic device, and computer storage medium | |
CN112748930A (en) | Compilation detection method, device, equipment and storage medium | |
US20160171018A1 (en) | Append structured data system for maintaining structured format compatibility |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |