CN111813663A - Pointer type identification method, device, medium and equipment - Google Patents

Pointer type identification method, device, medium and equipment Download PDF

Info

Publication number
CN111813663A
CN111813663A CN202010566799.6A CN202010566799A CN111813663A CN 111813663 A CN111813663 A CN 111813663A CN 202010566799 A CN202010566799 A CN 202010566799A CN 111813663 A CN111813663 A CN 111813663A
Authority
CN
China
Prior art keywords
memory
pointer
value
pointed
name
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.)
Granted
Application number
CN202010566799.6A
Other languages
Chinese (zh)
Other versions
CN111813663B (en
Inventor
刘洪凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010566799.6A priority Critical patent/CN111813663B/en
Publication of CN111813663A publication Critical patent/CN111813663A/en
Application granted granted Critical
Publication of CN111813663B publication Critical patent/CN111813663B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Stored Programmes (AREA)

Abstract

The present disclosure provides a pointer type identification method, apparatus, medium, and device, the method comprising: acquiring the length of an implementation body of a pre-declared reference method in a memory as the length of the reference memory; acquiring a name of a reference method implementation body in a memory mapping table as a reference name; acquiring the name of a memory pointed by a memory pointer to be identified in a memory mapping table as a name to be detected; when the name to be detected is matched with the reference name, acquiring a memory value of the class in which the identification method is located in the memory pointed by the memory pointer to be identified as the memory value to be matched, and acquiring a memory value of the class in which the identification method is located in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as the reference memory value; and when the memory value to be matched is matched with the reference memory value, determining the memory pointer to be identified as the method pointer. The method can quickly judge whether the memory pointer is the method pointer, and is convenient for analyzing events such as thread crash and the like.

Description

Pointer type identification method, device, medium and equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a medium, and a device for identifying a pointer type.
Background
When the bottom layer of the application is crashed, the crash reason needs to be analyzed by checking the java call stack, so that the conventional crash collection program usually calls back to the java layer after sensing a crash signal, and the call stack of the crash thread is obtained by the getStackTrace method at the java layer.
However, after the bottom layer is crashed, the java call stack of the crashed thread cannot be accurately acquired sometimes, and because the bottom layer is crashed at this time, the virtual machine responsible for executing the java code may be damaged, so that the java code cannot be executed, and therefore the java call stack of the crashed thread cannot be acquired because the java call stack cannot be called back to the java layer at this time. At this time, it is necessary to identify whether an address pointer is a method pointer, and whether the address pointer points to an underlying representation of a java method, so as to determine the java call stack of the crashed thread.
BRIEF SUMMARY OF THE PRESENT DISCLOSURE
An object of the present disclosure is to provide a pointer type identification method, apparatus, medium, and device, which can solve at least one of the above-mentioned technical problems. The specific scheme is as follows:
according to a specific implementation manner of the present disclosure, in a first aspect, the present disclosure provides a pointer type identification method, including: acquiring the length of an implementation body of a pre-declared reference method in a memory as the length of the reference memory; acquiring the name of the reference method implementation body in a memory mapping table as a reference name; acquiring the name of a memory pointed by a memory pointer to be identified in a memory mapping table as a name to be detected; when the name to be detected is matched with the reference name, acquiring a memory value used for identifying the class of the identification method in the memory pointed by the memory pointer to be identified as a memory value to be matched and acquiring a memory value used for identifying the class of the identification method in the memory pointed by the memory pointer to be identified as a reference memory value based on the length of the reference memory and the memory position pointed by the memory pointer to be identified; and when the memory value to be matched is matched with the reference memory value, determining the memory pointer to be identified as a method pointer.
Optionally, the obtaining a length of an implementation body of the pre-declared reference method in the memory as a reference memory length includes: acquiring a first method object corresponding to a first method and a second method object corresponding to a second method in a pre-registration auxiliary class through a reflection mechanism at a java layer; at a native layer, respectively converting the first method object into a first method pointer type object and converting the second method object into a second method pointer type object through a conversion function; and calculating the length of the reference memory according to the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object.
Optionally, the calculating a length of a reference memory according to the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object includes: acquiring the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object; and calculating the difference value between the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object to obtain the length of the reference memory.
Optionally, the obtaining a name of the reference method implementation body in the memory mapping table as a reference name includes: and acquiring the corresponding names in the memory mapping table pointed by the first method pointer type object and the second method pointer type object, and recording the names as the reference names of the reference method realization bodies in the memory mapping table.
Optionally, the obtaining, as a reference memory value, a memory value of a class in which the identification method is located in a memory pointed by an adjacent pointer corresponding to a memory pointed by the memory pointer to be identified includes: acquiring a memory value used for identifying the class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value; and/or; and acquiring a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
Optionally, when the memory value to be matched is matched with the reference memory value, determining the memory pointer to be identified as a method pointer includes: and when the memory value to be matched is consistent with the reference memory value of the forward offset and/or the reference memory value of the backward offset, determining the memory pointer to be identified as a method pointer.
Optionally, the memory value for identifying the class in which the method is located includes memory values of the first four bytes in the memory.
According to a second aspect, the present disclosure provides a pointer type identification apparatus, including: the first acquisition unit is used for acquiring the length of an implementation body of a pre-declared reference method in a memory as the length of the reference memory; a second obtaining unit, configured to obtain a name of the reference method implementation body in a memory mapping table as a reference name; a third obtaining unit, configured to obtain a name of a memory pointed by the memory pointer to be identified in a memory mapping table, where the name is used as a name to be detected; a matching unit, configured to, when the name to be detected is matched with the reference name, based on the reference memory length and the memory location pointed by the memory pointer to be recognized, obtain, as a memory value to be matched, a memory value in a memory pointed by the memory pointer to be recognized, which is used for the class in which the identification method is located, and obtain, as a reference memory value, a memory value in a memory pointed by an adjacent pointer corresponding to the memory pointed by the memory pointer to be recognized, which is used for the class in which the identification method is located; and the determining unit is used for determining the memory pointer to be identified as a method pointer when the memory value to be matched is matched with the reference memory value.
According to a third aspect, the present disclosure provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of any one of the above.
According to a fourth aspect thereof, the present disclosure provides an electronic device, comprising: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out a method as claimed in any preceding claim.
Compared with the prior art, the scheme of the embodiment of the disclosure at least has the following beneficial effects: the method identifies whether other pointers are method pointers or not by declaring the length and the name of a normal method pointer in advance, taking the length and the name as a reference and based on the same characteristic of the class of the method pointer pointing to the memory. This is because the first four bytes of ArtMethod point to the class where it is located, and multiple methods of the same class are arranged in series in the memory, and when there are more than two methods in a class, any one method point must satisfy the above detection condition. Therefore, whether the memory pointer is a method pointer or not can be quickly identified, and the method is accurately applied to bottom technologies such as stack backtracking and memory processing, and is convenient for analyzing events such as thread crash.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty. In the drawings:
FIG. 1 illustrates a flow chart of a pointer type identification method according to an embodiment of the present disclosure;
FIG. 2 illustrates a pointer type identification method initialization flow diagram in accordance with an embodiment of the present disclosure;
FIG. 3 illustrates a pointer type identification method decision flow diagram in accordance with an embodiment of the present disclosure;
FIG. 4 is a schematic structural diagram of a pointer type identification apparatus according to an embodiment of the present disclosure;
fig. 5 shows an electronic device connection structure schematic according to an embodiment of the present disclosure.
Detailed Description
To make the objects, technical solutions and advantages of the present disclosure clearer, the present disclosure will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present disclosure, rather than all embodiments. All other embodiments, which can be derived by one of ordinary skill in the art from the embodiments disclosed herein without making any creative effort, shall fall within the scope of protection of the present disclosure.
The terminology used in the embodiments of the present disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in the disclosed embodiments and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, and "a plurality" typically includes at least two.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
It should be understood that although the terms first, second, third, etc. may be used to describe … … in embodiments of the present disclosure, these … … should not be limited to these terms. These terms are used only to distinguish … …. For example, the first … … can also be referred to as the second … … and, similarly, the second … … can also be referred to as the first … … without departing from the scope of embodiments of the present disclosure.
The words "if", as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that an article or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in the article or device in which the element is included.
Alternative embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
After the application program is written by adopting java language, each java method has a corresponding memory area on the bottom layer. This memory area stores all the information of the method and is needed when the virtual machine executes the java method. In this embodiment, the android 5.0 and the above version are taken as examples for description, but the method is not limited to the android system, and in the android 5.0 and the above version, this memory area is the pointer object ArtMethod. How to determine whether a memory pointer points to a target like ArtMethod is described in the following embodiments.
As shown in fig. 1, according to an embodiment of the present disclosure, the present disclosure provides a method for pointer type identification, including the following method steps:
step S102: and acquiring the length of the implementation body of the pre-declared reference method in the memory as the length of the reference memory.
Initializing an application program: as shown in fig. 2, when initializing an application, the length of an implementation body (pointer object ArtMethod) of a reference method needs to be obtained, that is, the number of bytes occupied by the pointer object ArtMethod needs to be obtained, and the obtained length is used as a length of a reference memory for subsequent comparison. The specific implementation mode is as follows:
the length of the pointer object is obtained dynamically, the length of the pointer object can be obtained in a self-adaptive mode, manual obtaining is avoided, and the process of obtaining the length of the pointer object is more intelligent due to the dynamic obtaining mode. The method for dynamically acquiring the length of the pointer object comprises the following method sub-steps:
step S102-1: an auxiliary class is created that includes a first method and a second method.
Step S102-2: acquiring a first method object corresponding to a first method and a second method object corresponding to a second method through a reflection mechanism on a java layer;
step S102-3: at a native layer, respectively converting the first method object into a first method pointer type object and converting the second method object into a second method pointer type object through a conversion function;
step S102-4: and calculating the length of the pointer object according to the first method pointer type object and the second method pointer type object.
The operating program for system development generally includes a native layer (native layer) developed based on an editing language such as C or C + +, an art virtual machine layer running on the native layer (native layer), and a Java assembly layer running on the art virtual machine layer, and the Java assembly layer is mainly written in Java language. In the process of program development and execution, the Java layer can call the executable function of the native layer through the virtual machine layer to execute related tasks.
Wherein said calculating the length of the pointer object based on the first method pointer type object and the second method pointer type object comprises the sub-steps of:
step S102-4-1: acquiring a memory position value of the first method pointer type object and a memory position value of the second method pointer type object;
step S102-4-2: and calculating the difference value of the memory position value of the first method pointer type object and the memory position value of the second method pointer type object to obtain the length of the pointer object.
The specific implementation process is to first declare a Helper auxiliary class in the application, where the Helper auxiliary class includes two methods inside, for example, the two methods are named as a first method and a second method respectively (the specific naming manner is not limited thereto). The Method objects corresponding to the first Method and the second Method are obtained through a reflection mechanism at a java layer and are marked as a first Method object Method1 and a second Method object Method2, and then the first Method object and the second Method object are transmitted to a native layer through a JNI (just noticeable interface) form. The native layer converts the first Method object 1 and the second Method object 2 into objects of a corresponding Method pointer type object jmethodID type through a fromreflect Method function, which are denoted as a first Method pointer type object jmethodID1 and a second Method pointer type object jmethodID2, the first Method pointer type object jmethodID1 and the second Method pointer type object jmethodID2 respectively point to corresponding first pointer object ArtMethod1 and second pointer object ArtMethod2, the first pointer object ArtMethod1 and the second pointer object ArtMethod2 are adjacent in the memory and both have respective memory location values, and the length of the pointer object ArtMethod is obtained after subtracting a smaller memory location value from a larger memory location value.
Step S104: and acquiring the name of the reference method implementation body in the memory mapping table as a reference name.
Optionally, the obtaining a name of the reference method implementation body in the memory mapping table as a reference name includes: and acquiring the corresponding names in the memory mapping table pointed by the first method pointer type object and the second method pointer type object, and recording the names as the reference names of the reference method realization bodies in the memory mapping table.
Specifically, after the first Method object 1 and the second Method object 2 are converted into the first Method pointer type object jmethod id1 and the second Method pointer type object jmethod id2 by a fromreflect Method function at the native layer, a name corresponding to a memory mapping table exists in directions pointed by the first Method pointer type object jmethod id1 and the second Method pointer type object jmethod id2, for example, the name may be recorded as a mapnameoffartmethod, and the name is applied as a reference name in a subsequent searching and comparing process.
Step S106: and acquiring the name of the memory pointed by the memory pointer to be identified in the memory mapping table as the name to be detected.
By searching the name of the memory pointed by the memory pointer to be identified in the memory mapping table, the name of the memory pointer to be identified can be obtained and recorded as the name to be detected, such as mapNameOfArtMethoda.
Step S108: when the name to be detected is matched with the reference name, based on the length of the reference memory and the memory position pointed by the memory pointer to be recognized, acquiring a memory value used for identifying the class of the method in the memory pointed by the memory pointer to be recognized as a memory value to be matched, and acquiring a memory value used for identifying the class of the method in the memory pointed by an adjacent pointer corresponding to the memory pointed by the memory pointer to be recognized as a reference memory value.
A preliminary confirmation step: by the method, the name mapNameOfArtMethod dA of the memory pointer to be detected in the memory mapping table can be obtained, and when the name mapNameOfArtMethod dA of the memory pointer to be detected is matched with the pre-obtained reference name mapNameOfArtMethod of the method pointer, the memory pointer is preliminarily confirmed to be the method pointer.
When it is necessary to determine whether a memory pointer is a method pointer, first, it is checked whether a name to be tested in a memory mapping table corresponding to the memory pointer is the reference name mapNameOfArtMethod determined in step S104, and if not, it is directly determined that the memory pointer is not a method pointer. If the name to be tested in the memory mapping table corresponding to the memory pointer is the reference name mapNameOfArtMethod, the memory pointer can be preliminarily confirmed to be the method pointer, but secondary confirmation is needed to finally confirm that the memory pointer is the method pointer, because the name can be repeated sometimes, the secondary confirmation process comprises the following method steps:
based on the length of the reference memory and the memory position pointed by the memory pointer to be recognized, acquiring a memory value used for identifying the class of the method in the memory pointed by the memory pointer to be recognized as a memory value to be matched, and acquiring a memory value used for identifying the class of the method in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be recognized as a reference memory value.
The method for identifying the class of the method includes the following steps that a memory value used for identifying the class of the method in a memory pointed by an adjacent pointer corresponding to the memory pointed by the memory pointer to be identified is obtained and used as a reference memory value:
in the first embodiment, a memory value used for identifying a class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; and shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value as a reference memory value.
In the second embodiment, a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; and shifting the first memory value backwards by the pointer object length to obtain a third memory value, and acquiring the first four bytes of the third memory value as a reference memory value.
In the third embodiment, a memory value used for identifying the class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value; and acquiring a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value as one of the reference memory values; and shifting the first memory value backwards by the pointer object length to obtain a third memory value, and acquiring the first four bytes of the third memory value as a second reference memory value.
Step S110: and when the memory value to be matched is matched with the reference memory value, determining the memory pointer to be identified as a method pointer.
Further determining whether the memory pointer is a method pointer according to the length of the pointer object, determining that the memory pointer is a method pointer when the memory pointer is determined to be a method pointer, otherwise, determining that the memory pointer is not a method pointer, as shown in fig. 3.
After the preliminary confirmation, performing a secondary confirmation process after the name in the memory mapping table corresponding to the memory pointer is the name mapNameOfArtMethod determined in the above step, specifically including: firstly, obtaining memory values of the first four bytes pointed by the memory pointer to be determined, and respectively obtaining two memories with four byte lengths, wherein the two memories with four byte lengths and the memory pointer to be determined have front-back offset, and the offset is the reference length value of the pointer object determined in the step. And comparing the memory pointer to be determined with the acquired two offset four-byte memory values, and determining that the memory pointer is a method pointer as long as the memory pointer is matched with one of the two offset four-byte memories. Because the first four bytes of the pointer object ArtMethod point to the class in which it is located, multiple methods of the same class are arranged in series in the memory. When there are more than two methods in a class, any one method pointer must satisfy the above-described detection condition.
As alternative examples, the following three embodiments are included:
in the first embodiment, a first memory value pointed by the memory pointer is obtained, and the first four bytes of the first memory value are obtained; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value; and matching the first four bytes of the first memory value with the first four bytes of the second memory value, wherein if the matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
In the second implementation mode, a first memory value pointed by the memory pointer is obtained, and the first four bytes of the first memory value are obtained; shifting the pointer object length backwards for the first memory value to obtain a third memory value, and acquiring the first four bytes of the third memory value; and matching the first four bytes of the first memory value with the first four bytes of the third memory value, wherein if the matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
Acquiring a first memory value pointed by the memory pointer and acquiring the first four bytes of the first memory value; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value; shifting the pointer object length backwards for the first memory value to obtain a third memory value, and acquiring the first four bytes of the third memory value; and matching the first four bytes of the first memory value with the first four bytes of the second memory value and the third memory value, wherein if at least one matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
The method judges whether the memory pointer is a method pointer or not by judging the memory value characteristics of the front and back of the memory pointed by the memory pointer and the name of the memory mapping table of the memory pointed by the memory pointer, thereby being accurately applied to the bottom layer technologies such as stack backtracking, memory processing and the like and being convenient for analyzing events such as thread crash and the like.
In addition, the present disclosure also provides an apparatus embodiment adapted to the above embodiment, for implementing the method steps described in the above embodiment, and the explanation based on the same name and meaning is the same as that of the above embodiment, and has the same technical effect as that of the above embodiment, and is not described again here.
As shown in fig. 4, according to an embodiment of the present disclosure, the present disclosure provides an apparatus for identifying a method pointer, including:
the first acquisition unit 402: the method is used for acquiring the length of an implementation body of a pre-declared reference method in the memory as the length of the reference memory.
The first obtaining unit is further configured to: an auxiliary class is created that includes a first method and a second method. Acquiring a first method object corresponding to a first method and a second method object corresponding to a second method through a reflection mechanism on a java layer; at a native layer, respectively converting the first method object into a first method pointer type object and converting the second method object into a second method pointer type object through a conversion function; and calculating the length of the pointer object according to the first method pointer type object and the second method pointer type object.
Wherein the calculating a length of the pointer object according to the first method pointer type object and the second method pointer type object includes: acquiring a memory position value of the first method pointer type object and a memory position value of the second method pointer type object; and calculating the difference value of the memory position value of the first method pointer type object and the memory position value of the second method pointer type object to obtain the length of the pointer object.
The second acquisition unit 404: and the name of the reference method implementation body in the memory mapping table is obtained and used as the reference name.
Optionally, the obtaining a name of the reference method implementation body in the memory mapping table as a reference name includes: and acquiring the corresponding names in the memory mapping table pointed by the first method pointer type object and the second method pointer type object, and recording the names as the reference names of the reference method realization bodies in the memory mapping table.
The third acquisition unit 406: and the name of the memory pointed by the memory pointer to be identified in the memory mapping table is acquired as the name to be detected.
The matching unit 408: and when the name to be detected is matched with the reference name, acquiring a memory value used for identifying the class of the method in the memory pointed by the memory pointer to be identified as a memory value to be matched based on the length of the reference memory and the memory position pointed by the memory pointer to be identified, and acquiring a memory value used for identifying the class of the method in the memory pointed by the memory pointer to be identified as a reference memory value.
Based on the length of the reference memory and the memory position pointed by the memory pointer to be recognized, acquiring a memory value used for identifying the class of the method in the memory pointed by the memory pointer to be recognized as a memory value to be matched, and acquiring a memory value used for identifying the class of the method in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be recognized as a reference memory value.
The method for identifying the class of the method includes the following steps that a memory value used for identifying the class of the method in a memory pointed by an adjacent pointer corresponding to the memory pointed by the memory pointer to be identified is obtained and used as a reference memory value:
in the first embodiment, a memory value used for identifying a class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; and shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value as a reference memory value.
In the second embodiment, a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; and shifting the first memory value backwards by the pointer object length to obtain a third memory value, and acquiring the first four bytes of the third memory value as a reference memory value.
In the third embodiment, a memory value used for identifying the class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified is obtained as a reference memory value; and acquiring a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
Specific examples thereof include: acquiring a first memory value pointed by the memory pointer, and acquiring the first four bytes of the first memory value; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value as one of the reference memory values; and shifting the first memory value backwards by the pointer object length to obtain a third memory value, and acquiring the first four bytes of the third memory value as a second reference memory value.
The determination unit 410: and the method is used for determining the memory pointer to be identified as a method pointer when the memory value to be matched is matched with the reference memory value.
As alternative examples, the following three embodiments are included:
in the first embodiment, a first memory value pointed by the memory pointer is obtained, and the first four bytes of the first memory value are obtained; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value; and matching the first four bytes of the first memory value with the first four bytes of the second memory value, wherein if the matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
In the second implementation mode, a first memory value pointed by the memory pointer is obtained, and the first four bytes of the first memory value are obtained; shifting the pointer object length backwards for the first memory value to obtain a third memory value, and acquiring the first four bytes of the third memory value; and matching the first four bytes of the first memory value with the first four bytes of the third memory value, wherein if the matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
Acquiring a first memory value pointed by the memory pointer and acquiring the first four bytes of the first memory value; shifting the first memory value forwards by the pointer object length to obtain a second memory value, and acquiring the first four bytes of the second memory value; shifting the pointer object length backwards for the first memory value to obtain a third memory value, and acquiring the first four bytes of the third memory value; and matching the first four bytes of the first memory value with the first four bytes of the second memory value and the third memory value, wherein if at least one matching is successful, the memory pointer is a method pointer, otherwise, the memory pointer is not a method pointer.
The device judges whether the memory pointer is a method pointer or not by judging the memory value characteristics of the front and back of the memory pointed by the memory pointer and the name of the memory mapping table of the memory pointed by the memory pointer, thereby being accurately applied to the bottom layer technologies such as stack backtracking, memory processing and the like and being convenient for analyzing events such as thread crash and the like.
As shown in fig. 5, the present embodiment provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the one processor to cause the at least one processor to perform the method steps of the above embodiments.
The disclosed embodiments provide a non-volatile computer storage medium having stored thereon computer-executable instructions that may perform the method steps as described in the embodiments above.
Referring now to FIG. 5, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 5, the electronic device may include a processing means (e.g., central processing unit, graphics processor, etc.) 501 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage means 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other by a bus 505. An input/output (I/O) interface 505 is also connected to bus 505.
Generally, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 505 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, magnetic tape, hard disk, etc.; and a communication device 505. The communication means 505 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 505, or installed from the storage means 508, or installed from the ROM 502. The computer program performs the above-described functions defined in the methods of the embodiments of the present disclosure when executed by the processing device 501.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.

Claims (10)

1. A pointer type identification method, comprising:
acquiring the length of an implementation body of a pre-declared reference method in a memory as the length of the reference memory;
acquiring the name of the reference method implementation body in a memory mapping table as a reference name;
acquiring the name of a memory pointed by a memory pointer to be identified in a memory mapping table as a name to be detected;
when the name to be detected is matched with the reference name, acquiring a memory value used for identifying the class of the identification method in the memory pointed by the memory pointer to be identified as a memory value to be matched and acquiring a memory value used for identifying the class of the identification method in the memory pointed by the memory pointer to be identified as a reference memory value based on the length of the reference memory and the memory position pointed by the memory pointer to be identified;
and when the memory value to be matched is matched with the reference memory value, determining the memory pointer to be identified as a method pointer.
2. The method as claimed in claim 1, wherein said obtaining the length of the implementation body of the pre-declared reference method in the memory as the reference memory length comprises:
acquiring a first method object corresponding to a first method and a second method object corresponding to a second method in a pre-registration auxiliary class through a reflection mechanism at a java layer;
at a native layer, respectively converting the first method object into a first method pointer type object and converting the second method object into a second method pointer type object through a conversion function;
and calculating the length of the reference memory according to the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object.
3. The method of claim 2, wherein calculating the length of the reference memory based on the memory value of the memory pointed to by the first method pointer type object and the memory value of the memory pointed to by the second method pointer type object comprises:
acquiring the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object;
and calculating the difference value between the memory value of the memory pointed by the first method pointer type object and the memory value of the memory pointed by the second method pointer type object to obtain the length of the reference memory.
4. The method as claimed in claim 2 or 3, wherein said obtaining the name of the reference method implementer in the memory mapping table as the reference name comprises:
and acquiring the corresponding names in the memory mapping table pointed by the first method pointer type object and the second method pointer type object, and recording the names as the reference names of the reference method realization bodies in the memory mapping table.
5. The method according to claim 1, wherein the obtaining a memory value used for identifying a class in which a method is located in a memory pointed by a neighboring pointer corresponding to a memory pointed by the memory pointer to be identified as a reference memory value comprises:
acquiring a memory value used for identifying the class of the method in the memory pointed by the forward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value; and/or;
and acquiring a memory value used for identifying the class of the method in the memory pointed by the backward offset pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
6. The method as claimed in claim 5, wherein said determining said memory pointer to be identified as a method pointer when said memory value to be matched matches said reference memory value comprises:
and when the memory value to be matched is consistent with the reference memory value of the forward offset and/or the reference memory value of the backward offset, determining the memory pointer to be identified as a method pointer.
7. The method of claim 1, wherein the memory value used to identify the class in which the method resides comprises a memory value of the first four bytes in memory.
8. A pointer type identification apparatus, comprising:
the first acquisition unit is used for acquiring the length of an implementation body of a pre-declared reference method in a memory as the length of the reference memory;
a second obtaining unit, configured to obtain a name of the reference method implementation body in a memory mapping table as a reference name;
a third obtaining unit, configured to obtain a name of a memory pointed by the memory pointer to be identified in a memory mapping table, where the name is used as a name to be detected;
a matching unit, configured to, when the name to be detected is matched with the reference name, based on the reference memory length and the memory location pointed by the memory pointer to be recognized, obtain, as a memory value to be matched, a memory value in a memory pointed by the memory pointer to be recognized, which is used for the class in which the identification method is located, and obtain, as a reference memory value, a memory value in a memory pointed by an adjacent pointer corresponding to the memory pointed by the memory pointer to be recognized, which is used for the class in which the identification method is located;
and the determining unit is used for determining the memory pointer to be identified as a method pointer when the memory value to be matched is matched with the reference memory value.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method according to any one of claims 1 to 7.
10. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 7.
CN202010566799.6A 2020-06-19 2020-06-19 Pointer type identification method, device, medium and equipment Active CN111813663B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010566799.6A CN111813663B (en) 2020-06-19 2020-06-19 Pointer type identification method, device, medium and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010566799.6A CN111813663B (en) 2020-06-19 2020-06-19 Pointer type identification method, device, medium and equipment

Publications (2)

Publication Number Publication Date
CN111813663A true CN111813663A (en) 2020-10-23
CN111813663B CN111813663B (en) 2024-03-22

Family

ID=72846256

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010566799.6A Active CN111813663B (en) 2020-06-19 2020-06-19 Pointer type identification method, device, medium and equipment

Country Status (1)

Country Link
CN (1) CN111813663B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040205302A1 (en) * 2003-04-14 2004-10-14 Bryan Cantrill Method and system for postmortem identification of falsely shared memory objects
CN104346267A (en) * 2013-08-08 2015-02-11 腾讯科技(深圳)有限公司 Method and device for generating program bug positioning information
CN106557300A (en) * 2015-09-24 2017-04-05 腾讯科技(深圳)有限公司 A kind of function stack information of wild pointer determines method, device and electronic equipment
CN110908860A (en) * 2019-10-28 2020-03-24 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for acquiring Java threads

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040205302A1 (en) * 2003-04-14 2004-10-14 Bryan Cantrill Method and system for postmortem identification of falsely shared memory objects
CN104346267A (en) * 2013-08-08 2015-02-11 腾讯科技(深圳)有限公司 Method and device for generating program bug positioning information
CN106557300A (en) * 2015-09-24 2017-04-05 腾讯科技(深圳)有限公司 A kind of function stack information of wild pointer determines method, device and electronic equipment
CN110908860A (en) * 2019-10-28 2020-03-24 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for acquiring Java threads

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JVM内存分配模型: "JVM内存分配模型", Retrieved from the Internet <URL:https://blog.csdn.net/peng864534630/article/details/78526756> *
张静;黄志球;沈国华;喻?慎;艾磊;: "C程序中的内存泄漏机制分析与检测方法设计", 计算机工程与科学, no. 05 *

Also Published As

Publication number Publication date
CN111813663B (en) 2024-03-22

Similar Documents

Publication Publication Date Title
CN109213611B (en) Cross-process communication method, device, terminal and storage medium
CN111813641B (en) Method, device, medium and equipment for collecting crash information
CN110865898B (en) Method, device, medium and equipment for converging crash call stack
CN110502357B (en) Stack backtracking method, device, medium and equipment
CN110489179B (en) Method, device, medium and equipment for acquiring call stack frame function signature
CN110764941B (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN110489165B (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN111221572A (en) Method, device, medium and equipment for automatically adapting to operating environment
CN109218393A (en) A kind of implementation method of push, device, equipment and computer storage medium
CN109284108B (en) Unmanned vehicle data storage method and device, electronic equipment and storage medium
CN110674050B (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN111813663B (en) Pointer type identification method, device, medium and equipment
CN111124627B (en) Method and device for determining call initiator of application program, terminal and storage medium
CN109408387B (en) Page testing method and device
CN110908860B (en) Java thread acquisition method and device, medium and electronic equipment
CN111045926A (en) Application program jamming detection method, device, medium and electronic equipment
CN115576484A (en) Data reading and writing method and device, electronic equipment and storage medium
CN112379967B (en) Simulator detection method, device, equipment and medium
CN111813664B (en) Crash information collection method, device, medium and equipment
CN114063964A (en) Volume compensation optimization method and device, electronic equipment and readable storage medium
CN113760631A (en) Page loading duration determination method, device, equipment and storage medium
CN110727480A (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN113220128B (en) Self-adaptive intelligent interaction method and device and electronic equipment
CN115470292B (en) Block chain consensus method, device, electronic equipment and readable storage medium
CN110389862B (en) Data storage method, device, equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant