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

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

Info

Publication number
CN111813663B
CN111813663B CN202010566799.6A CN202010566799A CN111813663B CN 111813663 B CN111813663 B CN 111813663B CN 202010566799 A CN202010566799 A CN 202010566799A CN 111813663 B CN111813663 B CN 111813663B
Authority
CN
China
Prior art keywords
memory
pointer
value
pointed
acquiring
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.)
Active
Application number
CN202010566799.6A
Other languages
Chinese (zh)
Other versions
CN111813663A (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

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, and taking the length as the reference memory length; acquiring the name of the reference method implementation body in the memory mapping table as a reference name; 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; when the name to be detected is matched with the reference name, acquiring a memory value, which is used for identifying the class where the method is located, in the memory pointed by the memory pointer to be identified as a memory value to be matched, and acquiring a memory value, which is used for identifying the class where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a 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 a method pointer. The method can rapidly judge whether the memory pointer is a 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 pointer type identification method, apparatus, medium, and device.
Background
When the application is in the bottom layer crash, the crash reason needs to be analyzed by checking a java call stack, so that the existing crash collection program generally calls back to the java layer after sensing a crash signal, and the call stack of the crash thread is obtained through a getStackTrace method at the java layer.
However, after the bottom layer is crashed, the java call stack of the crashed thread cannot be acquired accurately sometimes, 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, so that the java call stack of the crashed thread cannot be acquired at this time. At this time, it needs to identify whether an address pointer is a method pointer, and it needs to identify whether this pointer points to the underlying representation of a java method, to determine the java call stack of the crashed thread.
BRIEF SUMMARY OF THE PRESENT DISCLOSURE
The present disclosure aims to provide a pointer type identification method, device, medium and apparatus, which can solve at least one technical problem mentioned above. The specific scheme is as follows:
according to a specific embodiment 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, and taking the length as the reference memory length; acquiring the name of the reference method implementation body in a memory mapping table as a reference name; 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; 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 identified, acquiring a memory value, used for identifying the class where the method is located, 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 where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a 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 a method pointer.
Optionally, the obtaining the length of the implementation body of the pre-declared reference method in the memory, as the 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 preregistration auxiliary class through a reflection mechanism in 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 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 includes: acquiring a memory value of a memory pointed by the first method pointer type object and a memory value of a memory pointed by the second method pointer type object; and calculating the difference 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 the name of the reference method implementation body in the memory mapping table, as a reference name, includes: and acquiring corresponding names in the memory mapping table, which are pointed to by the first method pointer type object and the second method pointer type object, and recording the names as reference names of the reference method implementation bodies in the memory mapping table.
Optionally, the obtaining, as the reference memory value, the 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 identified includes: acquiring a memory value, which is used for identifying the class of the method, in a 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, which is 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 used for identifying the class of the method includes memory values of the first four bytes in the memory.
According to a second aspect of the present disclosure, there is provided a pointer type identifying apparatus comprising: the first acquisition unit is used for acquiring the length of an implementation body of the pre-declared reference method in the memory and taking the length as the reference memory length; the second acquisition unit is used for acquiring the name of the reference method implementation body in the memory mapping table and taking the name as a reference name; the third acquisition unit is used for 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; the matching unit is used for acquiring a memory value used for identifying the class where the method is located in the memory pointed by the memory pointer to be identified as a memory value to be matched based on the reference memory length and the memory position pointed by the memory pointer to be identified when the name to be detected is matched with the reference name, and acquiring a memory value used for identifying the class where the method is located in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value; 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 of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a method as claimed in any one of the above.
According to a fourth aspect of the present disclosure, there is provided an electronic device comprising: one or more processors; storage means for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the method of any of the preceding claims.
Compared with the prior art, the scheme of the embodiment of the disclosure has at least the following beneficial effects: the method identifies whether other pointers are method pointers by pre-declaring the length and the name of normal method pointers and taking the length and the name as references and based on the same characteristics of the method where the method pointers point to the memory. This is because the first four bytes of the ArtMethod point to the class in which it is located, and multiple methods of the same class in memory are arranged in succession, and when there are more than two methods in a class, any one method pointer must satisfy the above-described detection condition. Therefore, whether the memory pointer is a method pointer can be rapidly identified, and the method pointer is accurately applied to the underlying technologies such as stack backtracking and memory processing, and is convenient for analyzing events such as thread crashes.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure. It will be apparent to those of ordinary skill in the art that the drawings in the following description are merely examples of the disclosure and that other drawings may be derived from them without undue effort. In the drawings:
FIG. 1 illustrates a pointer type identification method flow diagram according to an embodiment of the present disclosure;
FIG. 2 illustrates a pointer type identification method initialization flow diagram according to an embodiment of the present disclosure;
FIG. 3 illustrates a pointer type identification method decision flow chart according to an embodiment of the present disclosure;
FIG. 4 is a schematic diagram showing the structure of a pointer type recognition apparatus according to an embodiment of the present disclosure;
fig. 5 shows a schematic diagram of an electronic device connection structure according to an embodiment of the present disclosure.
Detailed Description
For the purpose of promoting an understanding of the principles and advantages of the disclosure, reference will now be made in detail to the drawings, in which it is apparent that the embodiments described are only some, but not all embodiments of the disclosure. Based on the embodiments in this disclosure, all other embodiments that a person of ordinary skill in the art would obtain without making any inventive effort are within the scope of protection of this disclosure.
The terminology used in the embodiments of the disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure of 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, the "plurality" generally includes at least two.
It should be understood that the term "and/or" as used herein is merely one relationship describing the association of the associated objects, meaning that there may be three relationships, e.g., a and/or B, may represent: a exists alone, A and B exist together, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship.
It should be understood that although the terms first, second, third, etc. may be used to describe … … in the presently disclosed embodiments, these … … should not be limited to these terms. These terms are only used to distinguish … …. For example, the first … … may also be referred to as the second … …, and similarly the second … … may also be referred to as the first … …, without departing from the scope of the disclosed embodiments.
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 phrase "if determined" or "if detected (stated condition or event)" may be interpreted as "when determined" or "in response to determination" or "when detected (stated condition or event)" or "in response to detection (stated condition or event), depending on the context.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a product 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 product or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a commodity or device comprising such element.
Alternative embodiments of the present disclosure are described in detail below with reference to the drawings.
After the application program is written in the java language, each java method has a corresponding memory area at the bottom layer. The memory area stores all information of the method, and the virtual machine needs to use the memory area when executing the java method. In this embodiment, android 5.0 and above are taken as an example to describe the method, but the method is not limited to the android system, and in android 5.0 and above, this memory area is the pointer object ArtMethod. How to determine whether a memory pointer points to the pointer object ArtMethod is described in the following embodiments.
As shown in fig. 1, according to a specific embodiment of the present disclosure, the present disclosure provides a method for identifying a pointer type, including the following method steps:
step S102: and acquiring the length of the implementation body of the pre-declared reference method in the memory, and taking the length as the reference memory length.
An application program initialization step: as shown in fig. 2, when initializing is applied, the length of the implementation body (pointer object ArtMethod) of the reference method needs to be acquired, that is, the number of bytes occupied by the pointer object ArtMethod needs to be acquired, and the length is taken as the reference memory length for subsequent comparison. The specific implementation mode is as follows:
the length of the pointer object is dynamically acquired, the length of the pointer object can be acquired in a self-adaptive mode, the pointer object is prevented from being acquired in a manual mode, and the process of acquiring the length of the pointer object is more intelligent in a dynamic acquisition mode. The method for dynamically acquiring the length of the pointer object comprises the following method substeps:
step S102-1: an auxiliary class is created, the auxiliary class comprising 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 in 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 running 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, which is mainly written in the Java language. For the program development and execution process, the Java layer can call the executable functions of the original layer to execute related tasks through the virtual machine layer.
Wherein, according to the first method pointer type object and the second method pointer type object, calculating the length of the pointer object includes the following sub-steps:
step S102-4-1: acquiring a memory location value of the first method pointer type object and a memory location value of the second method pointer type object;
Step S102-4-2: and calculating the difference value between the memory location value of the pointer type object of the first method and the memory location value of the pointer type object of the second method to obtain the length of the pointer object.
The specific implementation process is that a Helper class is firstly declared in the application program, and the Helper class internally includes two methods, for example, the two methods are respectively named as a first method and a second method (the specific naming mode is not limited thereto). Obtaining Method objects corresponding to the first Method and the second Method through a reflection mechanism in the java layer, recording the Method objects as a first Method object Method1 and a second Method object Method2, and transmitting the Method objects to the active layer through a JNI (just noticeable interface) form. The native layer converts the first Method object Method1 and the second Method object Method2 into corresponding Method pointer type object jmethod id type objects through a from reflection Method function, which are marked as first Method pointer type object jmethod id1 and second Method pointer type object jmethod id2, wherein the first Method pointer type object jmethod id1 and the second Method pointer type object jmethod id2 point to corresponding first pointer object ArtMethod1 and second pointer object image ArtMethod2 respectively, the first pointer object ArtMethod1 and the second pointer object image ArtMethod2 are adjacent in a memory, and each have respective memory location values, and the length of the pointer object ArtMethod is obtained after subtracting the smaller memory location value from the 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 the name of the reference method implementation body in the memory mapping table, as a reference name, includes: and acquiring corresponding names in the memory mapping table, which are pointed to by the first method pointer type object and the second method pointer type object, and recording the names as reference names of the reference method implementation bodies in the memory mapping table.
The specific implementation process is that after the active layer converts the first Method object Method1 and the second Method object Method2 into the first Method pointer type object jmethod id1 and the second Method pointer type object jmethod id2 through the from reflection Method function, the corresponding names in the memory mapping table pointed by the first Method pointer type object jmethod id1 and the second Method pointer type object jmethod id2 are searched, for example, the names can be recorded as mapsnameoftmethod, and the names mapsnameoftmethod are used as reference names in the 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.
The name of the memory pointer to be identified can be obtained by searching the name of the memory pointed by the memory pointer to be identified in the memory mapping table, and the name is recorded as the name to be detected, for example, mapsNameOfArtMethodA.
Step S108: 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 identified, acquiring a memory value, used for identifying the class where the method is located, 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 where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
Preliminary confirmation: the method can acquire the name mapsNameOfArtMethodA to be detected of the memory pointer in the memory mapping table, and after comparison, when the name mapsNameOfArtMethodA to be detected of the memory pointer is matched with the reference name mapsNameOfArtMethod of the method pointer acquired in advance, the memory pointer is initially confirmed to be the method pointer.
When it is required to determine whether a memory pointer is a method pointer, firstly checking whether the name to be measured in the memory mapping table corresponding to the memory pointer is the reference name mapsNameOfArtMethod determined in step S104, if not, directly determining that the memory pointer is not a method pointer. If the name to be measured in the memory mapping table corresponding to the memory pointer is the reference name mapsNameOfArtmethod, the memory pointer can be primarily confirmed to be the method pointer, but secondary confirmation is needed to be performed to finally confirm that the memory pointer is the method pointer, because the name is likely to be repeated at times, the secondary confirmation process comprises the following method steps:
Based on the reference memory length and the memory location pointed by the memory pointer to be identified, acquiring a memory value, used for identifying the class where the method is located, 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 where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
The method for identifying the memory of the memory pointer to be identified comprises the following steps of:
in the first embodiment, a memory value, which is 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.
Specific examples are: 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 forward 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, the memory value, which is 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 the reference memory value.
Specific examples are: 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, which is 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 obtaining a memory value, which is 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 are: 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 forward 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 reference memory values; and shifting the first memory value backwards by the length of the pointer object to obtain a third memory value, and acquiring the first four bytes of the third memory value as the 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.
And further determining whether the memory pointer is a method pointer according to the length of the pointer object, and determining that the memory pointer is a method pointer when the memory pointer is the method pointer after further determination, otherwise, determining that the memory pointer is not the method pointer, as shown in fig. 3.
After the primary confirmation, the name in the memory mapping table corresponding to the memory pointer is the name mapsNameOfArtmethod determined in the step, and a secondary confirmation process is performed, which specifically comprises the following steps: firstly, obtaining the 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 memory values of the two 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 steps. And comparing the memory pointer to be determined with the acquired two shifted four-byte memory values, and determining that the memory pointer is a method pointer only by matching with one of the two shifted 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 in memory are arranged in succession. When there are more than two methods in a class, any one of the method pointers must satisfy the above 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 forward by the length of the pointer object to obtain a second memory value, and obtaining 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 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 backwards by the length of the pointer object to obtain a third memory value, and obtaining 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.
In the third 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 forward by the length of the pointer object to obtain a second memory value, and obtaining the first four bytes of the second memory value; shifting the first memory value backwards by the length of the pointer object to obtain a third memory value, and obtaining 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 match 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 before and after the memory pointed by the memory pointer and the name of the memory mapping table where the memory pointed by the memory pointer exists, thereby being accurately applied to the bottom technologies such as stack backtracking, memory processing and the like and being convenient for analyzing events such as thread crashes and the like.
In addition, the disclosure further provides an embodiment of the apparatus adapted to the above embodiment, so as to implement the method steps described in the above embodiment, and the explanation based on the meaning of the same names is the same as that of the above embodiment, which has the same technical effects as those of the above embodiment, and will not be repeated herein.
As shown in fig. 4, according to a specific embodiment of the present disclosure, the present disclosure provides an apparatus for identifying a method pointer, including:
the first acquisition unit 402: the length of the implementation body in the memory for acquiring the pre-declared reference method is used as the reference memory length.
The first acquisition unit is further configured to: an auxiliary class is created, the auxiliary class comprising 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 in 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 the length of the pointer object according to the first method pointer type object and the second method pointer type object includes: acquiring a memory location value of the first method pointer type object and a memory location value of the second method pointer type object; and calculating the difference value between the memory location value of the pointer type object of the first method and the memory location value of the pointer type object of the second method to obtain the length of the pointer object.
The second acquisition unit 404: and the method is used for acquiring the name of the reference method implementation body in the memory mapping table and taking the name as a reference name.
Optionally, the obtaining the name of the reference method implementation body in the memory mapping table, as a reference name, includes: and acquiring corresponding names in the memory mapping table, which are pointed to by the first method pointer type object and the second method pointer type object, and recording the names as reference names of the reference method implementation bodies in the memory mapping table.
Third acquisition unit 406: the method is used for acquiring the name of the memory pointed by the memory pointer to be identified in the memory mapping table and taking the name as the name to be detected.
Matching unit 408: and 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 identified, acquiring a memory value, which is used for identifying the class where the 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, which is used for identifying the class where the 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.
Based on the reference memory length and the memory location pointed by the memory pointer to be identified, acquiring a memory value, used for identifying the class where the method is located, 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 where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value.
The method for identifying the memory of the memory pointer to be identified comprises the following steps of:
in the first embodiment, a memory value, which is 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.
Specific examples are: 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 forward 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, the memory value, which is 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 the reference memory value.
Specific examples are: 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, which is 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 obtaining a memory value, which is 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 are: 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 forward 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 reference memory values; and shifting the first memory value backwards by the length of the pointer object to obtain a third memory value, and acquiring the first four bytes of the third memory value as the second reference memory value.
The determination unit 410: and 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 forward by the length of the pointer object to obtain a second memory value, and obtaining 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 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 backwards by the length of the pointer object to obtain a third memory value, and obtaining 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.
In the third 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 forward by the length of the pointer object to obtain a second memory value, and obtaining the first four bytes of the second memory value; shifting the first memory value backwards by the length of the pointer object to obtain a third memory value, and obtaining 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 match 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 before and after the memory pointed by the memory pointer and the name of the memory mapping table where the memory pointed by the memory pointer exists, thereby being accurately applied to the bottom technologies such as stack backtracking, memory processing and the like and being convenient for analyzing events such as thread crashes 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 enable the at least one processor to perform the method steps described in the embodiments above.
The disclosed embodiments provide a non-transitory computer storage medium storing computer executable instructions that perform the method steps described in the embodiments above.
Referring now to fig. 5, a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 5 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 5, the electronic device may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 501, which 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 required for the operation of the electronic device are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 505. An input/output (I/O) interface 505 is also connected to bus 505.
In general, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 505 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 508 including, for example, magnetic tape, hard disk, etc.; 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 shows an electronic device having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to 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 shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via communication means 505, or installed from storage means 508, or installed from ROM 502. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 501.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this 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 the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. 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, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
Computer program code for carrying out operations of the present disclosure may be written in 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 kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts 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 involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.

Claims (10)

1. A pointer type identification method, characterized by comprising:
acquiring the length of an implementation body of a pre-declared reference method in a memory, wherein the length of the memory is used as the reference memory, and the memory comprises a plurality of methods which are arranged continuously and belong to the same class;
acquiring the name of the reference method implementation body in a memory mapping table as a reference name;
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;
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 identified, acquiring a memory value, used for identifying the class where the method is located, 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 where the method is located, in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a 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 a method pointer.
2. The method of claim 1, wherein the obtaining the length of the implementation 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 preregistration auxiliary class through a reflection mechanism in 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 a memory value of a memory pointed by the first method pointer type object and a memory value of a memory pointed by the second method pointer type object;
And calculating the difference 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. A method according to claim 2 or 3, wherein said obtaining the name of the reference method implementation in the memory map table as the reference name comprises:
and acquiring corresponding names in the memory mapping table, which are pointed to by the first method pointer type object and the second method pointer type object, and recording the names as reference names of the reference method implementation bodies in the memory mapping table.
5. The method of claim 1, wherein the obtaining, as the reference memory value, the 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 identified includes:
acquiring a memory value, which is used for identifying the class of the method, in a 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, which is 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 of claim 5, wherein determining the memory pointer to be identified as a method pointer when the memory value to be matched matches the 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 identifying the class of the method comprises a first four bytes of memory value in memory.
8. A pointer type identifying apparatus, characterized by comprising:
the first acquisition unit is used for acquiring the length of an implementation body of a pre-declared reference method in a memory, and taking the length of the memory as the reference memory, wherein the memory comprises a plurality of methods which are arranged continuously and belong to the same class;
the second acquisition unit is used for acquiring the name of the reference method implementation body in the memory mapping table and taking the name as a reference name;
the third acquisition unit is used for 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;
the matching unit is used for acquiring a memory value used for identifying the class where the method is located in the memory pointed by the memory pointer to be identified as a memory value to be matched based on the reference memory length and the memory position pointed by the memory pointer to be identified when the name to be detected is matched with the reference name, and acquiring a memory value used for identifying the class where the method is located in the memory pointed by the adjacent pointer corresponding to the memory pointed by the memory pointer to be identified as a reference memory value;
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, characterized in that the program, when being executed by a processor, implements 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 implement the method of any 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 CN111813663A (en) 2020-10-23
CN111813663B true 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 (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6944722B2 (en) * 2003-04-14 2005-09-13 Sun Microsystems, Inc. Method and system for postmortem identification of falsely shared memory objects

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 (1)

* Cited by examiner, † Cited by third party
Title
C程序中的内存泄漏机制分析与检测方法设计;张静;黄志球;沈国华;喻垚慎;艾磊;;计算机工程与科学(第05期);全文 *

Also Published As

Publication number Publication date
CN111813663A (en) 2020-10-23

Similar Documents

Publication Publication Date Title
CN111813641B (en) Method, device, medium and equipment for collecting crash information
CN110489345B (en) Crash aggregation method, device, medium and equipment
CN110865898B (en) Method, device, medium and equipment for converging crash call stack
CN110502357A (en) A kind of stack retrogressive method, device, medium and equipment
CN111813465B (en) Information acquisition method, device, medium and equipment
CN109284108B (en) Unmanned vehicle data storage method and device, electronic equipment and storage medium
CN110764941A (en) Method, device, medium and equipment for acquiring call stack frame instruction offset
CN110489159A (en) Installation kit compressing method and data analysis method, device, medium and equipment
CN111738316B (en) Zero sample learning image classification method and device and electronic equipment
CN110908860B (en) Java thread acquisition method and device, medium and electronic equipment
CN113391860B (en) Service request processing method and device, electronic equipment and computer storage medium
CN110888773B (en) Method, device, medium and electronic equipment for acquiring thread identification
CN111045926B (en) Application program jamming detection method, device, medium and electronic equipment
CN110941549B (en) Memory leak detection method, device, medium and electronic equipment
CN111813663B (en) Pointer type identification method, device, medium and equipment
CN110674050A (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN110489164A (en) It is a kind of to hide acquisition methods, device, medium and the equipment for asserting information
CN112379967B (en) Simulator detection method, device, equipment and medium
CN111813664B (en) Crash information collection method, device, medium and equipment
CN111124627A (en) Method, device, terminal and storage medium for determining application program caller
CN113760631B (en) Page loading time length determining method, device, equipment and storage medium
CN111626045A (en) Character length calculation method and device and electronic equipment
CN113220128B (en) Self-adaptive intelligent interaction method and device and electronic equipment
CN111428544B (en) Scene recognition method and device, electronic equipment and storage medium
CN114185608B (en) File descriptor detection method and device

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