CN103823663B - A kind of method and apparatus for calling member variable - Google Patents

A kind of method and apparatus for calling member variable Download PDF

Info

Publication number
CN103823663B
CN103823663B CN201210468095.0A CN201210468095A CN103823663B CN 103823663 B CN103823663 B CN 103823663B CN 201210468095 A CN201210468095 A CN 201210468095A CN 103823663 B CN103823663 B CN 103823663B
Authority
CN
China
Prior art keywords
member variable
dynamic link
link library
offset
called
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
CN201210468095.0A
Other languages
Chinese (zh)
Other versions
CN103823663A (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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201210468095.0A priority Critical patent/CN103823663B/en
Publication of CN103823663A publication Critical patent/CN103823663A/en
Application granted granted Critical
Publication of CN103823663B publication Critical patent/CN103823663B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a kind of method and apparatus for calling member variable, belong to field of computer technology.Methods described includes:The member variable that dynamic link library includes is analyzed, obtains the offset in member variable class object where it;Offset in the mark of the member variable and member variable class object where it is stored in the mark of member variable and the corresponding relation of offset;When calling member variable to be called, according to the corresponding relation of the mark of the member variable and offset, the member variable to be called is called from the dynamic link library.Described device includes:Acquisition module, memory module and calling module.The present invention occurs calling error phenomenon by before the member variable for calling dynamic link library to include, calculating the correct offset in member variable class object where it that the dynamic link library includes, when calling member variable so as to avoid.

Description

A kind of method and apparatus for calling member variable
Technical field
The present invention relates to field of computer technology, more particularly to a kind of method and apparatus for calling member variable.
Background technology
In computer systems, dynamic link library includes multiple class objects, and class object includes multiple member variables, when should During with needing to use some member variable in program operation process, it is necessary first to call the member to become from the dynamic link library Amount.
At present, the detailed process for calling member variable is:In compiling of application, compiler can be made application program Offset in member variable class object where it is recorded into application program.When needing certain in application program running During individual member variable, the first address of class object where terminal obtains the member variable, the class object according to where the member variable The offset recorded when first address and compiling, calls the member variable from dynamic link library.
During the present invention is realized, inventor has found that prior art at least has problems with:
The offset of member variable may be different in the dynamic link library of different editions, and identified skew when compiling Amount only has portion, and different terminals production firm may change dynamic link library when generating terminal, make dynamic link library In the position of member variable change, the sequence of positions of the member variable determined when such prior art is according to compiling is called Calling error phenomenon is likely to occur during the member variable that dynamic link library includes.
The content of the invention
Occur calling error phenomenon during member variable that dynamic link library includes in order to avoid calling, the embodiment of the present invention carries A kind of method and apparatus for calling member variable are supplied.The technical scheme is as follows:
On the one hand, there is provided a kind of method for calling member variable, methods described include:
The member variable that dynamic link library includes is analyzed, obtained in member variable class object where it Offset;
Offset in the mark of the member variable and member variable class object where it is stored in member In the mark of variable and the corresponding relation of offset;
When calling member variable to be called, according to the corresponding relation of the mark of the member variable and offset, from The member variable to be called is called in the dynamic link library.
Wherein, it is described that the member variable that dynamic link library includes is analyzed, the member variable is obtained where it Offset in class object, including:
The member variable included for dynamic link library sets corresponding only one evil spirit number respectively, by the dynamic link library Including member variable replace with magic number corresponding to its;
Magic number corresponding to the mark of member variable that the dynamic link library includes and the member variable is stored in into In the mark of member's variable and the corresponding relation of magic number;
According to the mark of the member variable and the corresponding relation of magic number, the member that obtaining the dynamic link library includes becomes Measure the offset in class object where it.
Wherein, the member variable included for dynamic link library sets corresponding only one evil spirit number respectively, by described in The member variable that dynamic link library includes replaces with magic number corresponding to it, including:
First member variable included from dynamic link library is scanned;
Only one evil spirit number corresponding to the member variable of the scanning is set;
The member variable is replaced with into magic number corresponding to the member variable in the dynamic link library.
Further, the mark and the corresponding relation of magic number according to the member variable, obtains the dynamic link Offset in member variable class object where it that storehouse includes, including:
From identifying in the corresponding relation with magic number for the member variable, the member that obtaining the dynamic link library includes becomes Magic number corresponding to amount;
Set pointer to point to first magic number that member variable place class object includes, set pointer to move number Initial value;
Compare the magic number magic number corresponding with the member variable that the pointer points to, if both are identical, institute is set The offset for stating member variable moves number for the pointer, if both are different, sets pointer to point to next magic number, increases Add the pointer movement number.
Wherein, it is described when calling member variable to be called, according to pair of the mark of the member variable and offset It should be related to, the member variable to be called is called from the dynamic link library, including:
When calling member variable to be called, according to the mark of the member variable to be called, become from the member The offset in member variable class object where it to be called is obtained in the mark of amount and the corresponding relation of offset;
The first address of class object where obtaining the member variable to be called;
Offset and the member to be called in member variable class object where it to be called become The first address of class object, calls the member variable to be called from the dynamic link library where amount.
On the other hand, there is provided a kind of device for calling member variable, described device include:
Acquisition module, for analyzing the member variable that dynamic link library includes, the member variable is obtained at it Offset in the class object of place;
Memory module, for the member variable to be identified into the member variable obtained with the acquisition module at it Offset in the class object of place is stored in the mark of member variable and the corresponding relation of offset;
Calling module, for the member when calling member variable to be called, stored according to the memory module The mark of variable and the corresponding relation of offset, the member variable to be called is called from the dynamic link library.
Wherein, the acquisition module includes:
Replacement unit, the member variable for including for dynamic link library set corresponding only one evil spirit number respectively, will The member variable that the dynamic link library includes replaces with magic number corresponding to it;
Memory cell, for corresponding to the mark of member variable for including the dynamic link library and the member variable Magic number is stored in the mark of member variable and the corresponding relation of magic number;
First acquisition unit, for the mark of the member variable and the correspondence of magic number stored according to the memory cell Relation, obtain the offset in member variable class object where it that the dynamic link library includes.
Wherein, the replacement unit includes:
Subelement is scanned, first member variable for including from dynamic link library is scanned;
First sets subelement, for setting only one evil spirit number corresponding to the member variable of the scanning;
Subelement is replaced, it is corresponding for the member variable to be replaced with into the member variable in the dynamic link library Magic number.
Further, the acquiring unit includes:
Subelement is obtained, for from the corresponding relation of the mark of the member variable and magic number, obtaining the dynamic chain Connect magic number corresponding to the member variable that storehouse includes;
Second sets subelement, for setting pointer to point to first evil spirit that member variable place class object includes Number, pointer is set to move the initial value of number;
3rd sets subelement, the magic number magic number corresponding with the member variable pointed to for the pointer, such as Both fruits are identical, then set the offset of the member variable to move number for the pointer, if both are different, setting refers to Pin points to next magic number, increases the pointer movement number.
Wherein, the calling module includes:
Second acquisition unit, for when calling member variable to be called, according to the member variable to be called Mark, the member variable to be called is obtained where it from the corresponding relation of the mark of the member variable and offset Offset in class object;
3rd acquiring unit, the first address for class object where obtaining the member variable to be called;
Call unit, for the offset in member variable class object where it to be called and described treat The first address of class object, calls the member variable to be called from the dynamic link library where the member variable of calling.
In embodiments of the present invention, the member variable that dynamic link library includes is analyzed, obtains the member variable and exist Offset in class object where it;By the offset in the mark of the member variable and member variable class object where it It is stored in the mark of member variable and the corresponding relation of offset;When calling member variable to be called, become according to member The mark of amount and the corresponding relation of offset, call member variable to be called from the dynamic link library.Wherein, treated in calling Before the member variable of calling, correct offset in member variable class object where it that dynamic link library includes is calculated, When calling member variable to be called, according to the first address of class object and member to be called where member variable to be called Variable correct offset in class object where it, calls member variable to be called from the dynamic link library, in this way, can Occurs the phenomenon for calling error during avoiding the member variable for calling dynamic link library to include.
Brief description of the drawings
Fig. 1 is a kind of method flow diagram for calling member variable that the embodiment of the present invention one provides;
Fig. 2 is a kind of method flow diagram for calling member variable that the embodiment of the present invention two provides;
Fig. 3 is a kind of structural representation of the dynamic link library for encapsulation that the embodiment of the present invention two provides;
Fig. 4 is a kind of apparatus structure schematic diagram for calling member variable that the embodiment of the present invention three provides.
Embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing to embodiment party of the present invention Formula is described in further detail.
Embodiment one
The embodiments of the invention provide a kind of method for calling member variable, referring to Fig. 1, this method includes:
Step 101:The member variable that dynamic link library includes is analyzed, obtains member variable class pair where it Offset as in;
Step 102:Offset in the mark of the member variable and member variable class object where it is stored in In the mark of member variable and the corresponding relation of offset;
Step 103:When calling member variable to be called, closed according to the mark of the member variable and the corresponding of offset System, calls member variable to be called from the dynamic link library.
In embodiments of the present invention, the member variable that dynamic link library includes is analyzed, obtains the member variable and exist Offset in class object where it;By the offset in the mark of the member variable and member variable class object where it It is stored in the mark of member variable and the corresponding relation of offset;When calling member variable to be called, become according to member The mark of amount and the corresponding relation of offset, call member variable to be called from the dynamic link library.Wherein, treated in calling Before the member variable of calling, correct offset in member variable class object where it that dynamic link library includes is calculated, When calling member variable to be called, according to the first address of class object and member to be called where member variable to be called Variable correct offset in class object where it, calls member variable to be called from the dynamic link library, in this way, can Occurs the phenomenon for calling error during avoiding the member variable for calling dynamic link library to include.
Embodiment two
The embodiments of the invention provide a kind of method for calling member variable.Wherein, in identical version dynamic link library, It is also possible to that member variable problem of misalignment occurs, so needing to member to be called before member variable to be called is called Offset in variable class object where it re-starts calculating.Referring to Fig. 2, this method includes:
Step 201:Terminal loads dynamic link library, the dynamic link library include public dynamic link library and difference dynamic chain Connect storehouse;
Specifically, public dynamic link library is loaded into internal memory by terminal, is obtained by dynamic link library diff manager The version identifier of the dynamic link library, the difference dynamic chain according to corresponding to the dynamic link library version identifier by the dynamic link library Storehouse is connect to be loaded into internal memory.
Wherein, for any one dynamic link library, in advance by the dynamic link of different editions corresponding to the dynamic link library The identical interface and member variable that storehouse includes are encapsulated in a public dynamic link library, will be removed in each version dynamic link library Remaining interface and member variable are encapsulated in each dynamic chain outside interface and member variable that public dynamic link library includes Connect in difference dynamic link library corresponding to storehouse, so obtain a public dynamic link library that the dynamic link library includes and each Difference dynamic link library corresponding to version.
For example, the dynamic link library of encapsulation as shown in Figure 3 includes public dynamic link library and difference dynamic link library, The version of dynamic link library includes V1.0, V2.1 and V3.2, and extraction V1.0 dynamic link libraries, V2.1 dynamic link libraries and V3.2 are moved All identical interface and member variable in state chained library, by the V1.0 dynamic link libraries, V2.1 dynamic link libraries and V3.2 of extraction All identical interface and member variable are encapsulated in public dynamic link library in dynamic link library, will be removed in V1.0 dynamic link libraries Remaining interface and member variable are encapsulated in difference dynamic chain outside interface and member variable that public dynamic link library includes Connect in storehouse 1, connect remaining in addition to the interface and member variable that public dynamic link library includes in V2.1 dynamic link libraries Mouth and member variable are encapsulated in difference dynamic link library 2, are included public dynamic link library is removed in V3.2 dynamic link libraries Interface and member variable outside remaining interface and member variable be encapsulated in difference dynamic link library 3.
Step 202:The member variable included for the dynamic link library sets corresponding only one evil spirit number respectively, and this is moved The member variable that state chained library includes replaces with magic number corresponding to it;
Specifically, first member variable included from the dynamic link library proceeds by scanning, becomes for the member of scanning Amount sets its corresponding only one evil spirit number, and the member variable of scanning is replaced with into the member variable in the dynamic link library Corresponding magic number, whether the member variable for judging scanning is last member variable that the dynamic link library includes, if not, Next member variable that the dynamic link library includes then is continued to scan on, if it is, end operation.
For example, in the class object SkBitmap of dynamic link library as follows code, class object SkBitmap Including member variable iNum, member variable iCount, member variable printCount (void) and member variable incCount (void)。
The code of the class object of dynamic link library:
The member variable iNum that the dynamic link library includes is scanned, only one evil spirit is set for the member variable iNum of scanning Number 11, member variable iNum is replaced with 11 in dynamic link library as follows;Member variable i Count is scanned, for scanning Member variable iCount only one evil spirit number 12 is set, member variable iCount is replaced in dynamic link library as follows It is changed to 12;Member variable printCount (void) is scanned, is set uniquely for the member variable printCount (void) of scanning One magic number 13, the member variable printCount (void) of scanning is replaced with 13 in dynamic link library as follows; Member's variable i ncCount (void) is scanned, only one evil spirit number 14 is set for the member variable incCount (void) of scanning, Member variable incCount (void) is replaced with 14 in dynamic link library as follows.
The code of the class object of dynamic link library:
Step 203:Magic number storage corresponding to the mark for the member variable that the dynamic link library is included and the member variable In the mark of member variable and the corresponding relation of magic number;
Wherein, in step 202, the member variable in the class object that the dynamic link library includes is scanned, is set for the member After only one evil spirit number corresponding to putting, magic number corresponding to the mark of the member variable of scanning and the member variable is stored in into In the mark of member's variable and the corresponding relation of magic number.
For example, member variable iNum's is identified as Name1, member variable iCount's is identified as Name2, member variable PrintCount's (void) is identified as Name3, and member variable incCount's (void) is identified as Name4, and scanning member becomes INum is measured, and is after only one evil spirit number corresponding to member variable 1 is set is 11, by member variable iNum mark Name1 With member variable iNum corresponding to only one evil spirit number 11 be stored in member variable as shown in table 1 mark and magic number correspondence In relation;Member variable i Count is scanned, be after only one evil spirit number is 12 corresponding to member variable iCount settings, will be into Only one evil spirit number 12 corresponding to member's variable i Count mark Name2 and member variable iCount is stored in as shown in table 1 In the mark of member variable and the corresponding relation of magic number;Member variable printCount (void) is scanned, is member variable After only one evil spirit number corresponding to printCount (void) settings is 13, by member variable printCount (void) mark Only one evil spirit number 13 corresponding to knowing Name3 and member variable printCount (void) is stored in member as shown in table 1 and become In the mark of amount and the corresponding relation of magic number, member's variable i ncCount (void) is scanned, is member variable incCount (void) after only one evil spirit number 14 corresponding to setting, by member variable incCount (void) mark Name4 and member Only one evil spirit number 14 corresponding to variable i ncCount (void) is stored in the mark of member variable as shown in table 1 and magic number In corresponding relation.
Table 1
The mark of member variable Magic number
Name1 11
Name2 12
Name3 13
Name4 14
Step 204:According to the mark of member variable and the corresponding relation of magic number, the member that the dynamic link library includes is obtained Offset in variable class object where it;
Specifically, this step can be divided into following(1)-(4)The step of:
(1), from the corresponding relation of the mark of member variable and magic number, obtain the member variable that the dynamic link library includes Corresponding magic number;
Specifically, first record in the mark of member variable and the corresponding relation of magic number is scanned, from the first of scanning Bar record in obtain the member variable that the dynamic link library includes mark and the member variable corresponding to magic number.
(2), class object according to where the mark of the member variable finds out the member variable;
Specifically, the class object according to where the identifier lookup of the member variable to the member variable, obtains the member variable The first address of the class object at place, the first address of class object, is oriented in the dynamic link library according to where the member variable The class object.
(3), set pointer to point to first magic number that class object where the member variable includes, set pointer to move number Initial value;
Specifically, first magic number that the class object includes is begun look for from the first address of the class object, sets pointer to refer to First magic number that class object where to the member variable includes, pointer is set to move the initial value of number.
Wherein, the initial value of pointer movement number could be arranged to 0.
(4), compare the magic number magic number corresponding with the member variable of pointer sensing, if both are identical, this is set The offset of member variable is that pointer moves number, return to step(1)If both are different, pointer is set to point to next Magic number, increase pointer movement number, continues executing with this step.
Specifically, the magic number that pointer points to is obtained, magic number corresponding to the magic number and the member variable that pointer is pointed to is carried out Compare, if the magic number that pointer points to is identical with magic number corresponding to the member variable, the offset for setting the member variable is Pointer moves number, return to step(1)The magic number of next member variable is obtained, and determines next member variable where it Offset in class object;If magic number corresponding to magic number and the member variable that pointer points to differs, moving pointer makes Pointer points to next magic number, and increases pointer movement number, continues executing with this step.
Wherein, increasing pointer movement number can be:Move the pointer over number and add 1.
Wherein, if the magic number of pointer sensing is identical with magic number corresponding to the member variable, the member variable is judged Whether there is magic number corresponding to member variable in the class object of place, if so, then return to step(1);Otherwise, end operation.
For example, the Article 2 record in the mark of scanning member variable and the corresponding relation of magic number, from the Article 2 of scanning Obtained in record corresponding to the mark Name2 and member variable iCount for the member variable iCount that the dynamic link library includes Magic number 12, the class object SkBitmap according to where the mark Name2 of the member variable finds out member variable iCount, obtaining should Class object SkBitmap first address 0005H, the class object SkBitmap first address according to where member variable iCount 0005H orients class object SkBitmap, and the class object bag is begun look for from class object SkBitmap first address 0005H The first magic number included, if first magic number that the class object includes is 11, pointer is set to point to magic number 11, and pointer is set The initial value of mobile number is 0, judges magic number 12 corresponding to the member variable iCount that the magic number 11 that pointer points to obtains with scanning, The magic number 12 that the magic number 11 and scanning pointed to due to pointer is obtained differs, then moves pointer and point to next magic number, by pointer Mobile number adds 1, if the magic number that pointer movement subsequently points to is 12, understands the magic number of pointer sensing and the member that scanning obtains Magic number 12 is identical corresponding to variable i Count, then it is 1 to obtain pointer movement number, so setting member's variable i Count in class pair As the offset in SkBitmap is 0001H.
Step 205:Offset in the mark of the member variable and member variable class object where it is stored in In the mark of member variable and the corresponding relation of offset;
Wherein, if pointer point to magic number and scanning member variable corresponding to magic number it is identical, set scan into Offset in member's variable class object where it moves number for pointer, and by the mark of the member variable of scanning and the member Offset in variable class object where it is stored in the mark of member variable and the corresponding relation of offset.
Wherein, when the version of dynamic link library is identical, and that this is changed when generating terminal is dynamic for different terminals production firm State chained library, the position of the member variable in dynamic link library is set to change, the method provided according to embodiments of the present invention is true Determine correct offset in member variable class object where it, can avoid calling the phenomenon to malfunction;And work as and new edition occur This dynamic link library, and the sequence of positions of member variable that includes of the redaction dynamic link library not it is also possible to according to Method provided in an embodiment of the present invention determines the correct offset of member variable, so as to avoid calling the phenomenon to malfunction, is implemented as The upward compatibility of member's variable.
Wherein, the skew of the mark of the member variable dynamic link library included and the member variable in its class object Amount is stored in after the mark of member variable and the corresponding relation of offset, discharges the public dynamic link library and the dynamic of encapsulation The internal memory that difference dynamic link library corresponding to chained library takes.
For example, offsets of the member variable iNum in class object SkBitmap is 0000H, by member variable iNum mark Know the offset of Name1 and member variable iNum in class object SkBitmap and be stored in member as shown in table 2 below for 0000H In the mark of variable and the corresponding relation of offset;Offsets of the member variable iCount in class object SkBitmap be 0001H, it is by the offset of member variable iCount mark Name2 and member variable iCount in class object SkBitmap 0001H is stored in the mark of member variable as shown in table 2 below and the corresponding relation of offset;Member variable printCount (void) offset in class object SkBitmap is 0002H, by member variable printCount (void) mark Name3 With offsets of the member variable printCount (void) in class object SkBitmap be 0002H be stored in it is as shown in table 2 below The mark of member variable and the corresponding relation of offset in;Member variable incCount (void) is in class object SkBitmap Offset be 0003H, member variable incCount (void) mark Name4 and member variable incCount (void) are existed Offset in class object SkBitmap is stored in the mark of member variable as shown in table 2 below and pair of offset for 0003H In should being related to.
Table 2
The mark of member variable Offset
Name1 0000H
Name2 0001H
Name3 0002H
Name4 0003H
Wherein, when needing to call the dynamic link library in the running of application program, the public dynamic of encapsulation is loaded Difference dynamic link library corresponding to chained library and the dynamic link library.
Step 206:When the application call dynamic link library, the public dynamic link library and the dynamic of encapsulation are loaded Difference dynamic link library corresponding to chained library;
Wherein, when the application call dynamic link library, public dynamic link library is loaded into internal memory by terminal, is led to The version identifier that dynamic link library diff manager obtains the dynamic link library is crossed, according to the version identifier of the dynamic link library, Difference dynamic link library corresponding to the dynamic link library version identifier is loaded into internal memory.
Wherein, when some member variable in the application call dynamic link library, the member variable is to wait to adjust Member variable.
Step 207:When calling member variable to be called, closed according to the mark of member variable and the corresponding of offset System, calls member variable to be called from the dynamic link library.
Specifically, when calling member variable to be called, according to the mark of member variable to be called, from member variable Mark and offset corresponding relation in obtain offset in member variable class object where it to be called, acquisition is treated The first address of class object where the member variable of calling, by the first address of class object where member variable to be called and to be called Member variable class object where it in offset addition, obtain the address of member variable to be called in internal memory, root According to the call by location of member variable to be called in internal memory member variable to be called.
Wherein, in embodiments of the present invention, when application program is run for the first time on the terminal, to dynamic link library bag The member variable included is analyzed, and obtains the offset in member variable class object where it that the dynamic link library includes, Offset in the mark and member variable internal memory where it of the member variable that the dynamic link library includes is stored in into In member's mark of variable and the corresponding relation of offset, and the corresponding relation of the mark of member variable and offset is stored in one In individual configuration file, the configuration file is stored in terminal, when the application program is run again, directly from the terminal storage The configuration file in obtain mark and the member variable class object where it of the member variable that the dynamic link library includes In offset.
Alternatively, the above method provided in an embodiment of the present invention can also be:When application program is run, to dynamic link The member variable that storehouse includes is analyzed, and obtains the skew in member variable class object where it that the dynamic link library includes Measure, the offset storage in the mark for the member variable that the dynamic link library is included and member variable class object where it It is stored in internal memory in the mark of member variable and the corresponding relation of offset, and by the corresponding relation, is transported in application program When the member variable that the dynamic link library includes is called during row, the mark and offset of the member variable preserved from internal memory Corresponding relation in obtain offset in member variable class object where it, and according to the place class pair of the member variable Offset in the first address of elephant and member variable class object where it calls the member variable, when application program terminates to transport During row, the internal memory of the mark for the member variable that the dynamic link library includes and the corresponding relation occupancy of offset is discharged;When this should When being run again with program, then the member variable included to the dynamic link library is analyzed, and obtaining the dynamic link library includes Member variable class object where it in offset.
For example, member variable to be called is the member variable printCount (void) in class object SkBitmap, According to member variable printCount (void) to be called mark Name3 from the mark of member variable and the correspondence of offset The offset 0002H of member variable printCount (void) to be called in class object SkBitmap is obtained in relation, is obtained The first address for taking the class object SkBitmap of member variable printCount (void) to be called at place is 0010H, will be treated Class object SkBitmap first address 0010H where the member variable printCount (void) of calling and member to be called become Measure offset 0002Hs of the printCount (void) in class object SkBitmap to be added, obtain member variable to be called Addresses of the printCount (void) in internal memory is 0012H, according to member variable printCount's (void) to be called Memory address 0012H calls member variable printCount (void) to be called.
In embodiments of the present invention, the member variable that dynamic link library includes is analyzed, obtains the member variable and exist Offset in class object where it;By the offset in the mark of the member variable and member variable class object where it It is stored in the mark of member variable and the corresponding relation of offset;When calling member variable to be called, become according to member The mark of amount and the corresponding relation of offset, call member variable to be called from the dynamic link library.Wherein, treated in calling Before the member variable of calling, correct offset in member variable class object where it that dynamic link library includes is calculated, When calling member variable to be called, according to the first address of class object and member to be called where member variable to be called Variable correct offset in class object where it, calls member variable to be called from the dynamic link library, in this way, can Occurs the phenomenon for calling error during avoiding the member variable for calling dynamic link library to include.
Embodiment three
Referring to Fig. 4, the embodiments of the invention provide a kind of device for calling member variable, the device includes:
Acquisition module 401, for analyzing the member variable that dynamic link library includes, the member variable is obtained at it Offset in the class object of place;
Memory module 402, for by the mark of the member variable and acquisition module acquisition the member variable where it Offset in class object is stored in the mark of member variable and the corresponding relation of offset;
Calling module 403, for the member variable that when calling member variable to be called, is stored according to memory module The corresponding relation of mark and offset, calls member variable to be called from the dynamic link library.
Wherein, acquisition module 401 includes:
Replacement unit, the member variable for including for dynamic link library set corresponding only one evil spirit number respectively, will The member variable that the dynamic link library includes replaces with magic number corresponding to it;
Memory cell, for magic number corresponding to the mark of member variable for including the dynamic link library and the member variable It is stored in the mark of member variable and the corresponding relation of magic number;
First acquisition unit, for the mark of member variable and the corresponding relation of magic number stored according to memory cell, obtain Take the offset in member variable class object where it that the dynamic link library includes.
Further, replacement unit includes:
Subelement is scanned, first member variable for including from dynamic link library is scanned;
First sets subelement, for setting only one evil spirit number corresponding to the member variable of scanning;
Subelement is replaced, for replacing with the member variable of scanning corresponding to the member variable in the dynamic link library Magic number.
Further, acquiring unit includes:
Subelement is obtained, for from the corresponding relation of the mark of member variable and magic number, obtaining the dynamic link library bag Magic number corresponding to the member variable included;
Second sets subelement, for setting pointer to point to first magic number that member variable place class object includes, Pointer is set to move the initial value of number;
3rd sets subelement, for comparing the magic number magic number corresponding with the member variable of pointer sensing, if both It is identical, then set the offset of the member variable to move number for pointer, if both are different, set pointer to point to next Magic number, increase pointer movement number.
Wherein, calling module 403 includes:
Second acquisition unit, for when calling member variable to be called, according to the mark of member variable to be called, Obtained from the corresponding relation of the mark of member variable and offset inclined in member variable class object where it to be called Shifting amount;
3rd acquiring unit, the first address for class object where obtaining member variable to be called;
Call unit, for the offset in member variable class object where it to be called and it is to be called into The first address of class object, calls member variable to be called from the dynamic link library where member's variable.
In embodiments of the present invention, the member variable that dynamic link library includes is analyzed, obtains the member variable and exist Offset in class object where it;By the offset in the mark of the member variable and member variable class object where it It is stored in the mark of member variable and the corresponding relation of offset;When calling member variable to be called, become according to member The mark of amount and the corresponding relation of offset, call member variable to be called from the dynamic link library.Wherein, treated in calling Before the member variable of calling, correct offset in member variable class object where it that dynamic link library includes is calculated, When calling member variable to be called, according to the first address of class object and member to be called where member variable to be called Variable correct offset in class object where it, calls member variable to be called from the dynamic link library, in this way, can Occurs the phenomenon for calling error during avoiding the member variable for calling dynamic link library to include.
One of ordinary skill in the art will appreciate that hardware can be passed through by realizing all or part of step of above-described embodiment To complete, by program the hardware of correlation can also be instructed to complete, described program can be stored in a kind of computer-readable In storage medium, storage medium mentioned above can be read-only storage, disk or CD etc..
The foregoing is only presently preferred embodiments of the present invention, be not intended to limit the invention, it is all the present invention spirit and Within principle, any modification, equivalent substitution and improvements made etc., it should be included in the scope of the protection.

Claims (8)

  1. A kind of 1. method for calling member variable, it is characterised in that methods described includes:
    The member variable that dynamic link library includes is analyzed, obtains the skew in member variable class object where it Amount;
    Offset in the mark of the member variable and member variable class object where it is stored in member variable Mark and offset corresponding relation in;
    When calling member variable to be called, according to the corresponding relation of the mark of the member variable and offset, from described The member variable to be called is called in dynamic link library;
    Wherein, it is described that the member variable that dynamic link library includes is analyzed, obtain member variable class pair where it Offset as in, including:
    The member variable included for dynamic link library sets corresponding only one evil spirit number respectively, and the dynamic link library is included Member variable replace with magic number corresponding to its;
    Magic number corresponding to the mark of member variable that the dynamic link library includes and the member variable is stored in into member to become In the mark of amount and the corresponding relation of magic number;
    According to the mark of the member variable and the corresponding relation of magic number, the member variable that obtaining the dynamic link library includes exists Offset in class object where it.
  2. 2. according to the method for claim 1, it is characterised in that the member variable included for dynamic link library is set respectively Only one evil spirit number corresponding to putting, the member variable that the dynamic link library includes is replaced with into magic number corresponding to it, including:
    First member variable included from dynamic link library is scanned;
    Only one evil spirit number corresponding to the member variable of the scanning is set;
    The member variable is replaced with into magic number corresponding to the member variable in the dynamic link library.
  3. 3. according to the method for claim 1, it is characterised in that the mark and pair of magic number according to the member variable It should be related to, obtain the offset in member variable class object where it that the dynamic link library includes, including:
    From identifying in the corresponding relation with magic number for the member variable, the member variable pair that the dynamic link library includes is obtained The magic number answered;
    First magic number that class object where setting pointer points to the member variable includes, pointer is set to move the first of number Value;
    Compare the magic number magic number corresponding with the member variable that the pointer points to, if both it is identical, set it is described into The offset of member's variable moves number for the pointer, if both are different, sets pointer to point to next magic number, increases institute State pointer movement number.
  4. 4. according to the method for claim 1, it is characterised in that it is described when calling member variable to be called, according to institute The mark of member variable and the corresponding relation of offset are stated, calls the member to be called to become from the dynamic link library Amount, including:
    When calling member variable to be called, according to the mark of the member variable to be called, from the member variable The offset in member variable class object where it to be called is obtained in the corresponding relation of mark and offset;
    The first address of class object where obtaining the member variable to be called;
    Offset and the member variable institute to be called in member variable class object where it to be called In the first address of class object, the member variable to be called is called from the dynamic link library.
  5. 5. a kind of device for calling member variable, it is characterised in that described device includes:
    Acquisition module, for analyzing the member variable that dynamic link library includes, the member variable is obtained where it Offset in class object;
    Memory module, for the member variable to be identified into the member variable obtained with the acquisition module where it Offset in class object is stored in the mark of member variable and the corresponding relation of offset;
    Calling module, for the member variable when calling member variable to be called, stored according to the memory module Mark and offset corresponding relation, the member variable to be called is called from the dynamic link library;
    Wherein, the acquisition module includes:
    Replacement unit, the member variable for including for dynamic link library sets corresponding only one evil spirit number respectively, by described in The member variable that dynamic link library includes replaces with magic number corresponding to it;
    Memory cell, for magic number corresponding to the mark of member variable for including the dynamic link library and the member variable It is stored in the mark of member variable and the corresponding relation of magic number;
    First acquisition unit, the mark of the member variable and the corresponding of magic number for being stored according to the memory cell are closed System, obtains the offset in member variable class object where it that the dynamic link library includes.
  6. 6. device according to claim 5, it is characterised in that the replacement unit includes:
    Subelement is scanned, first member variable for including from dynamic link library is scanned;
    First sets subelement, for setting only one evil spirit number corresponding to the member variable of the scanning;
    Subelement is replaced, it is magic corresponding to the member variable for replacing with the member variable in the dynamic link library Number.
  7. 7. device according to claim 5, it is characterised in that the acquiring unit includes:
    Subelement is obtained, for from the corresponding relation of the mark of the member variable and magic number, obtaining the dynamic link library Including member variable corresponding to magic number;
    Second sets subelement, for setting pointer to point to first magic number that member variable place class object includes, if Put the initial value of pointer movement number;
    3rd sets subelement, the magic number magic number corresponding with the member variable pointed to for the pointer, if two Person is identical, then sets the offset of the member variable to move number for the pointer, if both are different, sets pointer to refer to To next magic number, increase the pointer movement number.
  8. 8. device according to claim 5, it is characterised in that the calling module includes:
    Second acquisition unit, for when calling member variable to be called, according to the mark of the member variable to be called, Member variable to be called class pair where it is obtained from the corresponding relation of the mark of the member variable and offset Offset as in;
    3rd acquiring unit, the first address for class object where obtaining the member variable to be called;
    Call unit, for the offset in member variable class object where it to be called and described to be called Member variable where class object first address, the member variable to be called is called from the dynamic link library.
CN201210468095.0A 2012-11-19 2012-11-19 A kind of method and apparatus for calling member variable Active CN103823663B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210468095.0A CN103823663B (en) 2012-11-19 2012-11-19 A kind of method and apparatus for calling member variable

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210468095.0A CN103823663B (en) 2012-11-19 2012-11-19 A kind of method and apparatus for calling member variable

Publications (2)

Publication Number Publication Date
CN103823663A CN103823663A (en) 2014-05-28
CN103823663B true CN103823663B (en) 2017-12-01

Family

ID=50758751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210468095.0A Active CN103823663B (en) 2012-11-19 2012-11-19 A kind of method and apparatus for calling member variable

Country Status (1)

Country Link
CN (1) CN103823663B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106502745B (en) * 2016-10-26 2019-12-10 腾讯科技(深圳)有限公司 Function calling method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632761A (en) * 2003-12-24 2005-06-29 华为技术有限公司 Method for traversing and accessing object in tested application program
CN102023843A (en) * 2010-11-24 2011-04-20 北京握奇数据系统有限公司 Function calling method and device as well as smart card
CN101714075B (en) * 2009-12-17 2012-12-19 深圳市万兴软件有限公司 Function calling method and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6182186B1 (en) * 1998-06-30 2001-01-30 Sun Microsystems, Inc. Method and apparatus that utilizes lock states to lock resources
US6851111B2 (en) * 2000-12-15 2005-02-01 International Business Machines Corporation System and method for class loader constraint checking

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632761A (en) * 2003-12-24 2005-06-29 华为技术有限公司 Method for traversing and accessing object in tested application program
CN101714075B (en) * 2009-12-17 2012-12-19 深圳市万兴软件有限公司 Function calling method and device
CN102023843A (en) * 2010-11-24 2011-04-20 北京握奇数据系统有限公司 Function calling method and device as well as smart card

Also Published As

Publication number Publication date
CN103823663A (en) 2014-05-28

Similar Documents

Publication Publication Date Title
CN103559446B (en) Dynamic virus detection method and device for equipment based on Android system
CN102636704B (en) Testing method, device and system for electronic product
CN103577658B (en) The appraisal procedure and assessment system of intelligent terminal hardware
CN104331368B (en) A kind of method called based on cfg file static analysis C++ Virtual Functions
JP2005293578A5 (en)
CN106339247A (en) Loading system and loading method for DLL (Dynamic Link Library) file
CN106295340A (en) A kind of program file recovery system and method
CN105760292A (en) Assertion verification method and device for unit testing
CN103823663B (en) A kind of method and apparatus for calling member variable
CN105808256A (en) Method and system for constructing legal stack return value by avoiding function call detection
CN106776105B (en) System startup file checking and compiling method
CN106815100A (en) Interface test method and device
CN105279006A (en) Android system based screen capture method and terminal
CN111966383B (en) Method, system and medium for quantitatively analyzing kernel compatibility of operating system
CN108319850A (en) Method, sandbox system and the sandbox equipment of sandbox detection
US20050102656A1 (en) Instrumentation injection for common language runtime
CN100478914C (en) Symbol debug method and system in cross integration development environment
CN108628728A (en) Detection method and device
CN107239298B (en) Application program debugging method and device
CN103559132B (en) A kind of detection method of JAVA application program robustness and device
CN109271164A (en) The memory configuration data of application is stored in the nonvolatile memory
CN103019663B (en) The method and system of intermodule function interface in a kind of acquisition program
CN107844703B (en) Client security detection method and device based on Android platform Unity3D game
US20080115016A1 (en) System and method for analyzing unknown file format to perform software security test
CN103544317B (en) The treating method and apparatus of dimension table data

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant