A compiler variable address random compilation method and system
Through the combination of multiple random methods and hash table mapping tables, the problem of insufficient security of compiler variable address allocation is solved, effective address allocation on different compilers and operating systems is realized, and cracking difficulty and time efficiency is improved.
Patent Information
- Application Number
- CN202111404476.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2041-11-24
AI Technical Summary
In the prior art, compilers have problems such as insufficient security and low cracking when allocating variable addresses, and the memory allocation methods of different compilers and operating systems are inconsistent, resulting in insufficient randomness of address allocation.
Multiple random methods are used to allocate variable addresses, and random sequences are generated by obtaining random seeds, and random sequences of variable indexes and address numbering are generated in a cross-random manner. Combining a hash table and a memory address numbering mapping table, random allocation of variable addresses is realized.
It improves the security and cracking difficulty of variable address allocation, so that addresses can be effectively allocated on different compilers and operating systems, reduces the prediction difficulty and collision probability of memory address allocation results, and improves time efficiency.
Smart Images

Figure CN114116217B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of industrial automation control, and in particular relates to a compiler variable address random compilation method and system. Background Art
[0002] In industrial automation control, control systems composed of configuration software and controllers (also called host computers and slave computers) are widely used in various control fields: such as distributed control systems (DCS), programmable controllers (PLC), etc. The configuration software is responsible for generating algorithm programs, and the controller is responsible for executing the program to realize the control function. When the configuration software writes the algorithm program, it is necessary to define a number of data to realize its logic, and save the calculation results in the data memory of the controller for monitoring. A simple address allocation method is to allocate the variable address as a fixed address during compilation, but because this allocation method is less difficult to crack, the security is not enough. Therefore, the present invention provides a random address allocation method, which uses multiple random methods to allocate variable addresses. Even if the logic is not changed, the results of multiple compilations are quite different. It can improve security and increase the difficulty of cracking.
[0003] In the prior art, compiler dynamic memory allocation depends on the type of compiler and operating system. Different compilers need to use different memory allocation methods. The randomness of these methods is actually only the randomness of the operating system's memory allocation, not the randomness of the compiler's allocation algorithm. The same heap memory is often allocated and released multiple times in the application, which means that the same address is used repeatedly. Summary of the invention
[0004] In order to solve the deficiencies in the prior art, the object of the present invention is to provide a compiler variable address random compilation method and system.
[0005] The present invention adopts the following technical solution:
[0006] A variable address random compilation method of a compiler comprises the following steps:
[0007] Step 1, collect the industrial automation control data needed to be used in the program to be run, and count the number of variables of all addresses to be allocated;
[0008] Step 2: According to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part, obtain the random seed A and the random seed B and generate the random number sequence S respectively. A With S B ;
[0009] Step 3: Use the S generated in step 2 A With S B , cross random generation variable index random number sequence b aAnd the address number random number sequence a b ;
[0010] Step 4: group the variables to be compiled, sort the groups and count the number of variables in each group;
[0011] Step 5, collect all available memory space memory addresses and number the bytes of the memory addresses, and then use a hash table to store the bytes of each memory address and its corresponding number to obtain a number address mapping table;
[0012] Step 6: Select the groups in order and randomly select the variable v to be compiled in the selected group. x , calculate the number of aligned bytes of the variable align v And length Size v ;
[0013] Step 7: For the variable v selected in step 6 to be compiled x Perform memory address allocation;
[0014] Step 8: Repeat steps 6 and 7 until all variables in the group are allocated to available memory space addresses or all available memory space addresses are used up.
[0015] In step 1, the variables to be assigned addresses include industrial automation control data, operation symbols, and function variables required to be used in the program to be run.
[0016] Step 2 includes the following:
[0017] Step 201: At the moment when the user selects the compile operation, the system time t1 is recorded, a random seed A is generated based on t1, and a random number sequence S is generated from the random seed A. A ;
[0018] The random seed A is the total number of milliseconds from January 1, 1970 to t1 or the total number of milliseconds from any specified time to t1;
[0019] Random number sequence S A The number of digits in must be at least the same as the number of variables to which addresses need to be assigned;
[0020] Generate a random number sequence S using a linear congruential generator A ;
[0021] Step 202: When the program runs to the address allocation part, the system time t2 is recorded, a random seed B is generated based on t2, and a random number sequence S is generated from the random seed B. B ;
[0022] The random seed B is the total number of milliseconds from January 1, 1970 to t2 or the total number of milliseconds from any specified time to t2;
[0023] Random number sequence S B At least the same as the random number sequence S A The number of random numbers in is the same;
[0024] Generate a random number sequence S using a linear congruential generator B .
[0025] In step 3, the variable index random number sequence b a The generation method is: from S A Select the first random number a1, calculate x1 = a1 mod size (S B ), S B The x1th number in is used as the variable to index the random number sequence b a Repeat this method until the variable indexes the random number sequence b. a The number of elements in the address is the same as the number of variables that need to be allocated addresses; size (S B ) is the random number sequence S B Length;
[0026] Address number random number sequence a b The generation method is: from S B Select a random number b1 and calculate x2=b1modsize(S A ), such as S A The x2th number in the random number sequence a is used as a variable to index the random number sequence a b Repeat this method until the variable indexes the random number sequence a b The number of elements in the same as the number of variables to be allocated addresses, size (S A ) is the random number sequence S A Length.
[0027] Step 4 includes the following:
[0028] Step 401: Group all variables to be assigned addresses according to their lengths, and sort the groups in descending order of their lengths; assuming that the variables are divided into m groups, the variable groups are Group 1, Group 2, ... Group 3 according to their lengths from largest to smallest. m , Group1 represents the group consisting of all variables with the longest length, Group m Represents a group consisting of all variables with the shortest length;
[0029] Step 402: Calculate the number of variables in all groups, Group 1, Group 2, ... Group mThe number of variables in are Size1, Size2…Size m .
[0030] Step 5 includes the following:
[0031] Step 501, during the initial allocation, the bytes of all available memory addresses are numbered by the difference between the byte and the first byte of the memory address plus 1;
[0032] Step 502, create a hash table, the key in the hash table is the number of the memory address byte, and the value corresponding to the key is the byte of the memory address;
[0033] Step 503: If the number of bytes of a memory address is mm and there are b occupied bytes, the numbers of the b occupied bytes are reallocated to bytes mm-b+1 to mm, and the byte numbers in the hash table are updated.
[0034] In step 6, let the selected group be Group i ,i=1,2,...m, according to the equation x=ba1 mod Size i The value of x in selects the xth variable v in this group x , Size i Represents Group i The number of variables in , ba1 is the random number sequence from variable index b a A random number selected randomly from .
[0035] Step 7 includes the following:
[0036] Step 701: According to the equation index x =ab1 mod Size memory , calculate the temporary number index x , Size memory The size of all available memory space; get the temporary number index from the number address mapping table in step 5 x Corresponding memory address offset x , and calculate the offset x Divide the align obtained in step 6 by x The remainder mod x ; According to the remainder mod x Calculate the variable v x Allocate memory address offset vx and offset vx The corresponding assumed number index vx ; ab1 can be a random number sequence indexed from variable a bA random number randomly selected from can also be any random number;
[0037] Step 702: Look up the assumed number index in the number address mapping table vx The current corresponding memory address offset1 and number index vx +Size v The corresponding address is offset2; if offset1 is equal to offset vx And offset2–offset1 is equal to Size v When the memory address offset vx Assigned to the compiled variable v x , variable v to be compiled x The memory address allocation is completed, and the process goes to step 703; otherwise, the allocation fails and the process returns to step 701;
[0038] Step 703: At this time, the variable v x The memory address is offset vx , the length is Size v , that is, from index vx to index vx +Size v The memory addresses between are occupied, occupying a total of Size v bytes; Size according to the method in step 503 v The bytes are renumbered and the variable v x Remove from group.
[0039] In step 701, the variable v is calculated x Allocate memory address offset vx and offset vx The corresponding assumed number index vx The method is:
[0040] If mod x If it is equal to 0, then offset vx =offset x , at this time offset vx The corresponding assumed number is index vx =index x ;
[0041] If mod x Not equal to 0 and greater than Then offset vx =offset x –mod x , at this time offset vxThe corresponding assumed number is index vx =index x –mod x ;
[0042] If mod x Not equal to 0 and less than or equal to Then offset vx =offset x +align x –mod x , assuming that offset vx The corresponding assumed number is index vx =index x +align x –mod x .
[0043] The present invention also discloses a compiler variable address random compilation system based on the compiler variable address random compilation method:
[0044] The system is arranged in the compiler or connected to the compiler externally;
[0045] It includes a variable collection and statistics module, a random number sequence generation module, a variable grouping module, a number address mapping table creation module and a variable memory address allocation module;
[0046] The variable collection and statistics module is responsible for collecting the industrial automation control data needed in the program to be run, and counting the number of variables to be assigned addresses; this module inputs all variables to be assigned addresses into the variable grouping module;
[0047] The random number sequence generation module cross-randomly generates variable index random number sequences and address number random number sequences according to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part;
[0048] The variable grouping module groups all variables to be assigned addresses according to the variable length and sorts the groups in descending order according to the variable length;
[0049] The numbered address mapping table creation module collects all available memory space memory addresses and uses the result of the random number sequence generation module to number the bytes of the memory addresses, and then uses a hash table to store the bytes of each memory address and its corresponding number to obtain a numbered address mapping table;
[0050] The variable memory address allocation module allocates the available memory space memory addresses to the variables in each group according to the grouping results of the variable grouping module and the numbered address mapping table obtained by the numbered address mapping table creation module, until all variables in all groups are allocated to the available memory space memory addresses or all available memory space memory addresses are used up.
[0051] The beneficial effects of the present invention are as follows:
[0052] 1. The variable address random compilation method proposed in the present invention is not limited by the types of compilers and operating systems, and can achieve effective address allocation effects on different compilers and operating systems;
[0053] 2. The technical solution of the present invention does not rely on the memory of the operating system. Even if the addresses allocated by the operating system are the same for multiple times, the address of the final variable is random as described herein;
[0054] 3. When the same program is run with the same variables, the results of memory address allocation in any two compilations using the compilation method of the present invention are different, which effectively increases the difficulty of predicting memory address allocation and makes the cracking cost higher; the proposed memory address selection calculation method makes the collision probability of memory address allocation results lower, successfully taking into account time efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 The present invention is a method flow chart of a variable address random compilation method of a compiler. DETAILED DESCRIPTION
[0056] The present application is further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present application.
[0057] Figure 1 The present invention is a method flow chart of a variable address random compilation method of a compiler, which specifically includes the following steps:
[0058] Step 1, collect the industrial automation control data needed to be used in the program to be run, and count the number of variables of all addresses to be allocated;
[0059] The variables to be assigned addresses include industrial automation control data, operation symbols, and function variables required to be used in the program to be run;
[0060] In this embodiment, each piece of industrial automation control data to be used in the program to be run corresponds to a variable to be assigned an address; Step 2: According to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part, obtain the random seed A and the random seed B and generate the random number sequence S respectively.A With S B .
[0061] The specific implementation of this step is as follows:
[0062] Step 201, at the moment when the user selects the compile operation, the system time t1 is recorded, and a random seed A is generated according to t1, and then a random number sequence S is generated from the random seed A. A .
[0063] Among them, the random seed refers to the initial value of the random number that generates the random number sequence;
[0064] Preferably, the random seed A is the total number of milliseconds from January 1, 1970 to t1, or the total number of milliseconds from any specified time to t1;
[0065] Random number sequence S A The number of digits in must be at least the same as the number of variables to which addresses need to be assigned;
[0066] Preferably, a linear congruential generator can be used to generate the random number sequence S A ;
[0067] Step 202, when the program runs to the address allocation part, the system time t2 is recorded, a random seed B is generated based on t2, and a random number sequence S is generated from the random seed B. B .
[0068] Preferably, the random seed B is the total number of milliseconds from January 1, 1970 to t2, or the total number of milliseconds from any specified time to t2;
[0069] Random number sequence S B At least the same as the random number sequence S A The number of random numbers in is the same;
[0070] Preferably, a linear congruential generator can be used to generate the random number sequence S B ;
[0071] System hardware, running processes, CPU memory load, etc. all affect the operation of the program, so the system time is highly random.
[0072] Step 3: Use the S generated in step 2 A With S B , cross random generation variable index random number sequence b a And the address number random number sequence a b .
[0073] From S A Select the first random number a1, calculate x1 = a1 mod size (SB ), S B The x1th number in is used as the variable to index the random number sequence b a Repeat this method until the variable indexes the random number sequence b. a The number of elements in the address is the same as the number of variables that need to be allocated addresses; size (S B ) is the random number sequence S B Length;
[0074] Address number random number sequence a b The generation method is: from S B Select a random number b1 and calculate x2=b1modsize(S A ), such as S A The x2th number in the random number sequence a is used as a variable to index the random number sequence a b Repeat this method until the variable indexes the random number sequence a b The number of elements in the same as the number of variables to be allocated addresses, size (S A ) is the random number sequence S A Length.
[0075] Step 4: group the variables to be compiled, sort the groups and count the number of variables in each group;
[0076] The specific implementation of this step is as follows:
[0077] Step 401, group all variables to be assigned addresses according to the length of the variables, and sort the groups in descending order of the length of the variables. Assuming that the variables are divided into m groups, the variable groups are as follows from the largest to the smallest length: Group 1, Group 2...Group m , Group1 represents the group consisting of all variables with the longest length, Group m Represents a group consisting of all variables with the shortest length;
[0078] Step 402, calculate the number of variables in all groups, Group 1, Group 2...Group m The number of variables in are Size1, Size2…Size m .
[0079] Step 5, collect all available memory space memory addresses and number the bytes of the memory addresses, and then use a hash table to store the bytes of each memory address and its corresponding number to obtain a number address mapping table;
[0080] The specific implementation of this step is as follows: Step 501, during the initial allocation, the bytes of all available memory addresses are numbered by the difference between the byte and the first byte of the memory address plus 1.
[0081] Assume that the bytes of the memory address are 10K (1K = 2 10 ), the first byte is numbered 1, and so on, the last byte is numbered 10K;
[0082] Step 502, create a hash table, the key in the hash table is the number of the memory address byte, and the value corresponding to the key is the byte of the memory address;
[0083] Step 503: if the number of bytes of a memory address is mm and there are b occupied bytes, the numbers of the b occupied bytes are reallocated to the mm-b+1th to the mmth bytes in sequence, and the byte numbers in the hash table are updated;
[0084] In this embodiment, after the first allocation is completed, assuming that the four bytes numbered n to n+3 are occupied, then b is 4, and numbers n to n+3 are reallocated to bytes 10K-4+1 to 10K, that is, 10K-3 to 10K. At this time, the new number of the 10K-3 byte is n, the new number of the 10K-2 byte is n+1, the new number of the 10K-1 is n+2, and the new number of the 10K is n+3. In this way, the new numbering becomes 1 to 10K–4, and the byte numbers in the hash table are updated.
[0085] Step 6: Select the groups in order and randomly select the variable v to be compiled in the selected group. x , calculate the number of aligned bytes of the variable align v And length Size v ; Set the selected group to Group i ,i=1,2,...m, according to the equation x=ba1 mod Size i The value of x in selects the xth variable v in this group x , Size i Represents Group i The number of variables in , ba1 is the random number sequence from variable index b a A random number selected randomly from .
[0086] Step 7: For the variable v selected in step 6, x Perform memory address allocation
[0087] The specific implementation of this step is as follows:
[0088] Step 701, according to the equation indexx =ab1 mod Size memory , calculate the temporary number index x , Size memory is the size of all available memory space, ab1 can be the random number sequence from variable index a b The random number randomly selected in the step can also be any random number. Get the temporary number index from the number address mapping table in step 5 x Corresponding memory address offset x , and calculate the offset x Divide the align obtained in step 6 by x The remainder mod x ; If mod x is equal to 0, then the variable v is calculated using the following method x Allocate memory address offset vx :
[0089] offset vx =offset x , at this time offset vx The corresponding assumed number is index vx =index x ;
[0090] If mod x Not equal to 0 and greater than The variable v is calculated using the following method x Allocate memory address offset vx :
[0091] offset vx =offset x –mod x , at this time offset vx The corresponding assumed number is index vx =index x –mod x ;
[0092] If mod x Not equal to 0 and less than or equal to The variable v is calculated using the following method x Allocate memory address offset vx :offset vx =offset x +align x –mod x , assuming that offset vx The corresponding assumed number is index vx=index x +align x –mod
[0093] Step 702: Look up the assumed number index in the number address mapping table vx The current corresponding memory address offset1 and number index vx +Size v The corresponding address is offset2; if offset1 is equal to offset vx And offset2–offset1 is equal to Size v When the memory address offset vx Assigned to the compiled variable v x , variable v to be compiled x The memory address allocation is completed, and the process goes to step 703; otherwise, the allocation fails and the process returns to step 701;
[0094] Step 703, at this time, the variable v x The memory address is offset vx , the length is Size v , that is, from index vx to index vx +Size v The memory addresses between are occupied, occupying a total of Size v bytes; Size according to the method in step 503 v The bytes are renumbered and the variable v x Remove from group.
[0095] Step 8, repeating steps 6 and 7 until all variables in the group are allocated to available memory space addresses or all available memory space addresses are used up.
[0096] The present invention also discloses a compiler variable address random compilation system, which can be set in the compiler or connected to the compiler externally, and includes a variable collection and statistics module, a random number sequence generation module, a variable grouping module, a number address mapping table creation module and a variable memory address allocation module;
[0097] The variable collection and statistics module is responsible for collecting the industrial automation control data needed in the program to be run, and counting the number of variables to be assigned addresses; this module inputs all variables to be assigned addresses into the variable grouping module;
[0098] The random number sequence generation module cross-randomly generates variable index random number sequences and address number random number sequences according to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part;
[0099] The variable grouping module groups all variables to be assigned addresses according to the variable length and sorts the groups in descending order according to the variable length;
[0100] The numbered address mapping table creation module collects all available memory space memory addresses and uses the result of the random number sequence generation module to number the bytes of the memory addresses, and then uses a hash table to store the bytes of each memory address and its corresponding number to obtain a numbered address mapping table;
[0101] The variable memory address allocation module allocates the available memory space memory addresses to the variables in each group according to the grouping results of the variable grouping module and the numbered address mapping table obtained by the numbered address mapping table creation module, until all variables in all groups are allocated to the available memory space memory addresses or all available memory space memory addresses are used up.
[0102] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
Claims
1. A variable address random compilation method of a compiler, characterized in that: The variable address random compilation method of the compiler comprises the following steps: Step 1, collect the industrial automation control data needed to be used in the program to be run, and count the number of variables of all addresses to be allocated; Step 2: According to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part, obtain the random seed A and the random seed B and generate the random number sequence S respectively. A With S B ; Step 3: Use the S generated in step 2 A With S B , cross random generation variable index random number sequence b a And the address number random number sequence a b ; Step 4: group the variables to be compiled, sort the groups and count the number of variables in each group; Step 5, collect all available memory space memory addresses and number the bytes of the memory addresses, and then use a hash table to store the bytes of each memory address and its corresponding number to obtain a number address mapping table; Step 6: Select the groups in order and randomly select the variable v to be compiled in the selected group. x , calculate the number of aligned bytes of the variable align v And length Size v ; Step 7: For the variable v selected in step 6 to be compiled x Perform memory address allocation; Step 8: Repeat steps 6 and 7 until all variables in the group are allocated to available memory space addresses or all available memory space addresses are used up.
2. The variable address random compilation method of the compiler according to claim 1, characterized in that: In step 1, the variables to be assigned addresses include industrial automation control data, operation symbols, and function variables required to be used in the program to be run.
3. The variable address random compilation method of the compiler according to claim 1, characterized in that: The step 2 includes the following contents: Step 201: At the moment when the user selects the compile operation, the system time t1 is recorded, a random seed A is generated based on t1, and then a random number sequence S is generated from the random seed A. A ; The random seed A is the total number of milliseconds from January 1, 1970 to t1 or the total number of milliseconds from any specified time to t1; Random number sequence S A The number of digits in must be at least the same as the number of variables to which addresses need to be assigned; Generate a random number sequence S using a linear congruential generator A ; Step 202: When the program runs to the address allocation part, the system time t2 is recorded, a random seed B is generated based on t2, and a random number sequence S is generated from the random seed B. B ; The random seed B is the total number of milliseconds from January 1, 1970 to t2 or the total number of milliseconds from any specified time to t2; Random number sequence S B At least the same as the random number sequence S A The number of random numbers in is the same; Generate a random number sequence S using a linear congruential generator B .
4. The variable address random compilation method of the compiler according to claim 1 or 3, characterized in that: In step 3, the variable index random number sequence b a The generation method is: from S A Select the first random number a1, calculate x1 = a1mod size (S B ), S B The x1th number in is used as the variable to index the random number sequence b a Repeat this method until the variable indexes the random number sequence b. a The number of elements in the address is the same as the number of variables that need to be allocated addresses; size (S B ) is the random number sequence S B Length; Address number random number sequence a b The generation method is: from S B Select a random number b1 and calculate x2=b1mod size(S A ), such as S A The x2th number in the random number sequence a is used as a variable to index the random number sequence a b Repeat this method until the variable indexes the random number sequence a b The number of elements in the same as the number of variables to be allocated addresses, size (S A ) is the random number sequence S A Length.
5. The variable address random compilation method of a compiler according to claim 1, characterized in that: The step 4 includes the following contents: Step 401: group all variables to be allocated addresses according to variable length, and sort the groups in descending order according to variable length; Assuming that the variables are divided into m groups, the variable groups are grouped in descending order of length: Group1, Group2…Group m , Group1 represents the group consisting of all variables with the longest length, Group m Represents a group consisting of all variables with the shortest length; Step 402: Calculate the number of variables in all groups, Group 1, Group 2, ... Group m The number of variables in are Size1, Size2…Size m .
6. The variable address random compilation method of a compiler according to claim 1, characterized in that: The step 5 includes the following contents: Step 501, during the initial allocation, the bytes of all available memory addresses are numbered by the difference between the byte and the first byte of the memory address plus 1; Step 502, create a hash table, the key in the hash table is the number of the memory address byte, and the value corresponding to the key is the byte of the memory address; Step 503: If the number of bytes of a memory address is mm and there are b occupied bytes, the numbers of the b occupied bytes are reallocated to bytes mm-b+1 to mm, and the byte numbers in the hash table are updated.
7. The variable address random compilation method of a compiler according to claim 1 or 5, characterized in that: In step 6, the selected group is Group i ,i=1,2,...m, according to the equation x=ba1 mod Size i The value of x in selects the xth variable v in this group x , Size i Represents Group i The number of variables in , ba1 is the random number sequence from variable index b a A random number selected randomly from .
8. The variable address random compilation method of a compiler according to claim 1, characterized in that: The step 7 includes the following contents: Step 701: According to the equation index x =ab1 mod Size memory , calculate the temporary number index x , Size memory The size of all available memory space; get the temporary number index from the number address mapping table in step 5 x Corresponding memory address offset x , and calculate the offset x Divide the align obtained in step 6 by x The remainder mod x ; According to the remainder mod x Calculate the variable v x Allocate memory address offset vx and offset vx The corresponding assumed number index vx ; ab1 is the random number sequence from variable index a b A random number randomly selected from , or any random number; Step 702: Look up the assumed number index in the number address mapping table vx The current corresponding memory address offset1 and number index vx +Size v The corresponding address is offset2; if offset1 is equal to offset vx And offset2–offset1 is equal to Size v When the memory address offset vx Assigned to the compiled variable v x , variable v to be compiled x The memory address allocation is completed, and the process goes to step 703; otherwise, the allocation fails and the process returns to step 701; Step 703: At this time, the variable v x The memory address is offset vx , the length is Size v , that is, from index vx to index vx +Size v The memory addresses between are occupied, occupying a total of Size v bytes; Size according to the method in step 503 v The bytes are renumbered and the variable v x Remove from group.
9. The variable address random compilation method of the compiler according to claim 8, characterized in that: In step 701, the variable v is calculated. x Allocate memory address offset vx and offset vx The corresponding assumed number index vx The method is: If mod x If it is equal to 0, then offset vx =offset x , at this time offset vx The corresponding assumed number is index vx =index x ; If mod x Not equal to 0 and greater than Then offset vx =offset x –mod x , at this time offset vx The corresponding assumed number is index vx =index x –mod x ; If mod x Not equal to 0 and less than or equal to Then offset vx =offset x +align x –mod x , assuming that offset vx The corresponding assumed number is index vx =index x +align x –mod x .
10. A compiler variable address random compilation system based on the compiler variable address random compilation method according to any one of claims 1 to 9, characterized in that: The system is arranged in the compiler or is externally connected to the compiler; It includes a variable collection and statistics module, a random number sequence generation module, a variable grouping module, a number address mapping table creation module and a variable memory address allocation module; The variable collection and statistics module is responsible for collecting the industrial automation control data needed in the program to be run, and counting the number of variables to be assigned addresses; this module inputs all variables to be assigned addresses into the variable grouping module; The random number sequence generation module randomly generates variable index random number sequences and address number random number sequences according to the moment when the user selects the compile operation and the moment when the program runs to the address allocation part; The variable grouping module groups all variables to be assigned addresses according to variable lengths and sorts the groups in descending order according to variable lengths; The numbered address mapping table creation module collects all available memory space memory addresses and uses the result of the random number sequence generation module to number the bytes of the memory addresses, and then uses a hash table to store the bytes of each memory address and its corresponding number to obtain a numbered address mapping table; The variable memory address allocation module allocates the available memory space memory address to the variables in each group according to the grouping result of the variable grouping module and the number address mapping table obtained by the number address mapping table creation module, until the variables in all groups are allocated to the available memory space memory address or all the available memory space memory addresses are used up.