CN102662789A - Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file - Google Patents

Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file Download PDF

Info

Publication number
CN102662789A
CN102662789A CN2012100837854A CN201210083785A CN102662789A CN 102662789 A CN102662789 A CN 102662789A CN 2012100837854 A CN2012100837854 A CN 2012100837854A CN 201210083785 A CN201210083785 A CN 201210083785A CN 102662789 A CN102662789 A CN 102662789A
Authority
CN
China
Prior art keywords
file
verification
crc check
elf
head
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2012100837854A
Other languages
Chinese (zh)
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.)
Zhuzhou CRRC Times Electric Co Ltd
Original Assignee
Zhuzhou CSR Times Electric 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 Zhuzhou CSR Times Electric Co Ltd filed Critical Zhuzhou CSR Times Electric Co Ltd
Priority to CN2012100837854A priority Critical patent/CN102662789A/en
Publication of CN102662789A publication Critical patent/CN102662789A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a method for adding CRC (cyclic redundancy check) to an ELF (executable linkable format) file. The method includes: a check file header which contains CRC and version of the ELF file, CRC of the check file header and the like is added to the end of the ELF file, the CRC of the file is calculated when the ELF file is loaded and updated, the CRC obtained by calculating is compared to a CRC value in the check file header for consistence, the file is complete if consistence is positive, and the file is incomplete if consistence is negative. By the method, use of bad and corrupt files is avoided, reliability of an embedded system is improved, loading of correct files and correctness of file updating are effectively guaranteed, and completeness of the files is guaranteed.

Description

A kind of ELF file adds the method for CRC check
Technical field
The present invention relates to the embedded system data communications field, particularly a kind of ELF file verification method.
Background technology
Along with embedded high-speed development of science and technology, embedded product is used more and more widely, such as high-speed railway, communication apparatus etc.; Embedded development comprises the hardware and software exploitation, in order to improve tempo of development, in embedded software developing, generally can adopt file system; File and data are kept in the middle of the file system; File system is used and can be brought a lot of benefits, such as easy to use, api interface abundant, left-hand seat and tempo of development are fast, file transfers is also very convenient simultaneously.
But embedded system is applied in the harsh occasion of environment sometimes, and complicated surrounding environment, software defect etc. possibly cause file content to be destroyed or to rewrite, and in particular cases also might cause the damage of file system.Usually, read application program from the file system the inside when embedded system starts and carry out,, may cause system start-up or operation exception so, cause system unstable if the inner application file of file system is damaged; In addition, because the host-host protocol under the embedded system is comparatively simple, lack enough fault tolerant mechanisms; Situation such as loss of data, output biography mistake also might take place in the file renewal process, and the file that is transferred to file system like this possibly rewritten, and the file of this damage is out of use; The consequence of bringing is unpredictable usually; In present embedded system, the file integrality method of calibration generally is not provided, can not judge whether file is correct available; In addition, even file is damaged, can not detect at once, the integrality of file can not be protected.
At present, in the design of general embedded system, use file system to preserve file and data; The file of preserving comprises start-up routine and application program, generally is placed on vxWorks image file and application program (.out file) etc. in the file system such as the embedded system of using the vxWorks real time operating system, and vxWorks image and .out application program all belong to ELF file (Executable and Linkable Format); The ELF file structure is seen Fig. 1; The foremost is ELF head (ELF Header), and then is each section of ELF file, such as code segment; Also want some supplementary structures at last, such as string table, symbol table etc.; The ELF head that the ELF file begins has defined information such as ELF evil spirit number, file machine byte length, data storage method, version, operation platform, ABI version, ELF reorientation type, hardware platform, entry address, segment table position and length; Wherein crucial a bit is position and the length that has write down segment table (Section Table); The segment table content can be read in position through segment table from the ELF file, therefrom obtain position, length and other attributes of code segment, data segment etc. then.Operating system can be used the attribute information that each section located and visited to segment table in loading ELF document; Obtain address and the length information of code segment, data segment from segment table the inside and copy code segment, data segment relevant position from file the respective regions of internal memory to, thereby realize the loading and the operation of executable file.
When the integrality of file was mainly reflected in loading and renewal, the loading error file can cause starting failure perhaps unusually in the time of loading, also can make mistakes in the time of the file renewal.Present scheme is, generally is to rely on operating system that detection method is provided when loading, and whether inspection ELF head is effective, but can not check whole ELF file; In transmission course; The general host-host protocol that relies on guarantees that such as agreements such as FTP, xmodem, host-host protocol can only guarantee the accuracy in the transmission course in embedded environment; But the content that can not guarantee to write on the storer is correct, and the preservation process also might be made mistakes.
CRC check at present generally has dual mode: (1) with the CRC check of file and file be placed on different positions, such as other another one file of use deposit need the CRC check of the file of verification and; (2), promptly begin to add a verification file head at file with CRC check with wait some information to be placed on the verification file head.
Above-mentioned two kinds of methods all have shortcoming: method 1 since file and CRC check with deposit respectively, the CRC check that need get from other places and, make checking procedure bother, and verification appears easily and lose after can't verification situation; Method 2 can be destroyed the ELF file structure; Because the ELF standard-required the ELF file to begin be the ELF head; If after a verification file head is added in the file front, be ELF file (becoming a kind of new file) no longer just, therefore do like this and can destroy the ELF file structure, cause operating system can not directly load the type file; If the words that load need to write loading procedure for this new file type separately in addition; Can improve the complexity of system like this, and loading procedure needs to rewrite after changing operating system platform, reduces versatility.
Summary of the invention
Technical matters to be solved by this invention is; Not enough to prior art; The method that provides a kind of ELF file to add CRC check avoids the use of file wrong and damage, improves the reliability of embedded system; Effectively guarantee to load the correctness of correct file and file renewal, the integrality of safeguard file.
For solving the problems of the technologies described above, the technical scheme that the present invention adopted is: a kind of ELF file adds the method for CRC check, and this method may further comprise the steps:
1) adds a verification file head in the ELF end of file;
2) open the ELF file that has added the verification file head;
3) file pointer is pointed to the end of file, obtain the length of file;
4) from the end of file toward skip before, jump to the starting position of verification file head, judge whether file size also littler than verification file head length degree, if jump to 9); If not, get into 5);
5) content of verification file header is read internal memory, the CRC check of calculating whole verification file head with, judge whether the verification file head effective,, entering 6 if effectively); If invalid, jump to 8);
6) jump to file and begin, judge whether the ELF file reads to finish) if jump to 8; If not, get into 7);
7) read file piecemeal, the CRC check of calculating this segment file with, return 6);
8) adopt CRC check that accumulate mode calculates file and, the CRC check of comparison document be kept at the verification file head in CRC check with whether consistent, as if unanimity, then file is correct; Otherwise file verification failure;
9) finish.
In the method for the present invention; The verification file head is added on the afterbody of ELF file; Can not influence the use of ELF file, promptly adding the verification file head is the same with not adding the verification file head for operating system afterwards, and operating system can not handled this verification file head when loading has the ELF file of verification file head; The code of loading ELF document need not to change, and can directly use; Calculate CRC and adopt progressively calculation mode, simple and reliable, and need not apply for a large amount of internal memories, and save memory, this is even more important in embedded system; In the file that adds, can put into a large amount of useful informations,, further expand range of application such as FileVersion, special identifier, temporal information etc.; The present invention has avoided using file wrong and damage, has improved the reliability of embedded system, has guaranteed to load the correctness of correct file and file renewal effectively, has ensured the integrality of file.
Description of drawings
Fig. 1 is an ELF file structure synoptic diagram;
Fig. 2 is the process flow diagram that one embodiment of the invention ELF file adds the verification file head;
Fig. 3 is the process flow diagram of one embodiment of the invention ELF file CRC check.
Embodiment
As shown in Figures 2 and 3; After the CRC check of one embodiment of the invention ELF file is used in before the ELF file load and upgrades with file, the CRC of first verification file before loading, verification is through loading afterwards; Information such as version that in addition can verification file prevent to start illegal file; After file upgraded, the CRC of calculation document guaranteed mistake not occur in the renewal process, and checking procedure is:
1) the ELF file of verification file head of having opened the interpolation that needs verification;
2) file pointer is pointed to the end of file; Use the ftell function to obtain the length of file; And judge whether file size is also littler than verification file head length degree, because the verification file head is the end that is placed on the ELF file, obviously correct file size wants verification file head length degree to grow;
3) the past skip before from the end of file; Jump to the starting position of verification file head; Suppose that file size is a; The size of verification file head be b(this be fixed value; In the design verification file header, confirm), be the starting position of verification file head from end of file toward a skip before b byte so;
4) content of verification file header is read internal memory, and verification verification file head: judge that earlier first field is the special identifier that the AddFileHead instrument is filled, this special identifier shows to be the reference position of verification file head; Read then deposit self CRC check and field; With put self CRC check and field make 0 into; Calculate the CRC of whole verification file head, whether self CRC check of preserving that relatively calculate and original with consistent, consistently explains that this is the verification file head of a correct and effective;
5) jump to the beginning of file, read file piecemeal, adopt accumulate mode calculate piecemeal CRC check and, the CRC check that calculates file with;
The CRC check of 6) relatively calculating is with whether the CRC check of face is with consistent in front with being kept at verification file, and consistent supporting paper is correct, otherwise the file verification failure.
Special identifier in the step 4) can be numeral, letter or other signs.
The AddFileHead instrument uses Visual C++6.0 exploitation; Function is the verification file head of afterbody interpolation at an ELF file: first field of verification file head is a special sign; To show that this is the beginning of verification file head; The special identifier symbol is according to actual request for utilization definition, can be numeral or letter; Other information such as CRC check and version that also contain the ELF file in the verification file head; The CRC check that the verification file head also contains self with; This verification and be used for checking whether the verification file head is correct; This verification and computing method be: will deposit self verification and field fill out 0; The CRC check of calculating whole verification file head then with, and with CRC check and be filled into verification file in front face deposit self verification and field.
The AddFileHead instrument is relevant with the definition of verification file head; Be to develop according to the verification file head of design; Different verification file head uses different AddFileHead instruments, such as because of reality uses need verification file in front face added a kind of new information, AddFileHead also needs modification so; When adding file header, to add this new information, guarantee the file header of AddFileHead instrument interpolation and first the causing of verification file of design.
Add a verification file head in the ELF end of file; The information such as CRC of the CRC check that this verification file head contains the ELF file and, version, verification file head self; In loading and updating file, calculate the CRC of ELF file; Whether the CRC that relatively calculates then and the verification file crc value of face in front be consistent, if consistent supporting paper is complete, if inconsistent supporting paper is imperfect.Its implementation process is: on PC; Add a verification file head to vxWorks image, application file ELF files such as (.out files) through an AddFileHead tool software; This verification file head is added on the back of ELF file, therefore can not influence the normal running (when operating system use ELF file only be concerned about the ELF head of ELF file front) of operating system to this file; In ELF files such as loading vxWorks image, whether the CRC of inspection file is correct earlier, guarantees that so whole ELF file is complete available; In updating file; Write file after the file system; Read the CRC of file calculation document once more; If find so inconsistently can also take remedial measuress such as deletion error file, re-transmission, guarantee that the inner file of file system is correct, rather than incomplete or ruinate; In system's operation, whether the interface function calculation document that can also call calculation document CRC is correct, can conveniently be positioned at the unexpected rewriting problem of file in the operational process.

Claims (5)

1. an ELF file adds the method for CRC check, it is characterized in that this method may further comprise the steps:
1) adds a verification file head in the ELF end of file;
2) open the ELF file that has added the verification file head;
3) file pointer is pointed to the end of file, obtain the length of file;
4) from the end of file toward skip before, jump to the starting position of verification file head, judge whether file size also littler than verification file head length degree, if jump to 9); If not, get into 5);
5) content of verification file header is read internal memory, the CRC check of calculating whole verification file head with, judge whether the verification file head effective,, entering 6 if effectively); If invalid, jump to 9);
6) jump to file and begin, judge whether the ELF file reads to finish) if jump to 8; If not, get into 7);
7) read file piecemeal, the CRC check of calculating this segment file with, return 6);
8) adopt CRC check that accumulate mode calculates file and, the CRC check of comparison document be kept at the verification file head in CRC check with whether consistent, as if unanimity, then file is correct; Otherwise file verification failure;
9) finish.
2. ELF file according to claim 1 adds the method for CRC check, it is characterized in that, in the said step 3), adopts the ftell function to obtain the length of file.
3. ELF file according to claim 1 adds the method for CRC check; It is characterized in that; In the said step 5), judge whether effective process is the verification file head: define a verification file head special identifier, judge that earlier first field is a special identifier; If then this special identifier shows it is the reference position of verification file head; Read out deposit self CRC check and field; With deposit self CRC check and field make 0 into; The CRC check of calculating whole verification file head with; The CRC check of relatively calculating with original self CRC check and whether consistent of preserving of verification file head, consistently explain that this is the file header of a correct and effective.
4. ELF file according to claim 3 adds the method for CRC check, it is characterized in that, said special identifier is numeral or letter.
5. ELF file according to claim 1 adds the method for CRC check, it is characterized in that the CRC check and the information of the CRC check that the verification file head of said interpolation contains the ELF file and, version, verification file head self.
CN2012100837854A 2012-03-27 2012-03-27 Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file Pending CN102662789A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2012100837854A CN102662789A (en) 2012-03-27 2012-03-27 Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2012100837854A CN102662789A (en) 2012-03-27 2012-03-27 Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file

Publications (1)

Publication Number Publication Date
CN102662789A true CN102662789A (en) 2012-09-12

Family

ID=46772288

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2012100837854A Pending CN102662789A (en) 2012-03-27 2012-03-27 Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file

Country Status (1)

Country Link
CN (1) CN102662789A (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103309710A (en) * 2013-06-09 2013-09-18 南车株洲电力机车研究所有限公司 Method and system for loading OUT file through VXWORKS operating system
CN103679054A (en) * 2013-12-13 2014-03-26 Tcl集团股份有限公司 Method and system for detecting integrity of boot animation file of intelligent terminal
CN103701922A (en) * 2013-12-31 2014-04-02 曙光云计算技术有限公司 Deployment method and system for application safety of PAAS (platform-as-a-service) platform
CN105487888A (en) * 2015-11-26 2016-04-13 武汉光迅科技股份有限公司 Method for generating upgrade file in system upgrade and/or application upgrade
CN106126367A (en) * 2016-06-28 2016-11-16 湖北锐世数字医学影像科技有限公司 A kind of self checking method and system of file
CN106909469A (en) * 2015-12-22 2017-06-30 中国移动通信集团公司 A kind of file verification method and apparatus
CN107450960A (en) * 2017-09-18 2017-12-08 珠海亿智电子科技有限公司 A kind of method for linking and loading again to can perform ELF files
CN107861832A (en) * 2017-09-27 2018-03-30 深信服科技股份有限公司 Data verification method, device and readable storage medium storing program for executing
CN109271758A (en) * 2018-08-24 2019-01-25 广州优视网络科技有限公司 Method, unit and the server for preventing So file stolen
CN111090889A (en) * 2019-12-05 2020-05-01 深圳和而泰家居在线网络科技有限公司 Method for detecting ELF file and electronic equipment
CN112099954A (en) * 2020-09-18 2020-12-18 百度时代网络技术(北京)有限公司 Method, device, equipment and storage medium for deploying and downloading resources
CN112579547A (en) * 2021-01-27 2021-03-30 深圳市亿联无限科技有限公司 Embedded system mirror image file compression method and device
CN112596749A (en) * 2020-12-28 2021-04-02 厦门亿联网络技术股份有限公司 Method and device for system power-on self-test and self-repair
CN113590227A (en) * 2021-08-02 2021-11-02 中国大恒(集团)有限公司北京图像视觉技术分公司 Binary programming format loading method and system under embedded system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5991774A (en) * 1997-12-22 1999-11-23 Schneider Automation Inc. Method for identifying the validity of an executable file description by appending the checksum and the version ID of the file to an end thereof
CN1770051A (en) * 2004-11-04 2006-05-10 华为技术有限公司 File safety detection method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5991774A (en) * 1997-12-22 1999-11-23 Schneider Automation Inc. Method for identifying the validity of an executable file description by appending the checksum and the version ID of the file to an end thereof
CN1770051A (en) * 2004-11-04 2006-05-10 华为技术有限公司 File safety detection method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
曾勇军: "基于MAC的ELF文件执行安全性的提高", 《计算机工程》, vol. 32, no. 21, 30 November 2006 (2006-11-30) *
朱裕禄: "Linux系统下的ELF文件分析", 《电脑知识与技术》, no. 26, 15 September 2006 (2006-09-15), pages 111 - 113 *

Cited By (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103309710A (en) * 2013-06-09 2013-09-18 南车株洲电力机车研究所有限公司 Method and system for loading OUT file through VXWORKS operating system
CN103679054A (en) * 2013-12-13 2014-03-26 Tcl集团股份有限公司 Method and system for detecting integrity of boot animation file of intelligent terminal
CN103701922A (en) * 2013-12-31 2014-04-02 曙光云计算技术有限公司 Deployment method and system for application safety of PAAS (platform-as-a-service) platform
CN103701922B (en) * 2013-12-31 2017-06-06 曙光云计算技术有限公司 The method and system of the application security deployment of PAAS platforms
CN105487888A (en) * 2015-11-26 2016-04-13 武汉光迅科技股份有限公司 Method for generating upgrade file in system upgrade and/or application upgrade
CN106909469B (en) * 2015-12-22 2020-02-14 中国移动通信集团公司 File checking method and device
CN106909469A (en) * 2015-12-22 2017-06-30 中国移动通信集团公司 A kind of file verification method and apparatus
CN106126367B (en) * 2016-06-28 2019-09-20 湖北锐世数字医学影像科技有限公司 A kind of self checking method and system of file
CN106126367A (en) * 2016-06-28 2016-11-16 湖北锐世数字医学影像科技有限公司 A kind of self checking method and system of file
CN107450960A (en) * 2017-09-18 2017-12-08 珠海亿智电子科技有限公司 A kind of method for linking and loading again to can perform ELF files
CN107861832B (en) * 2017-09-27 2020-11-13 深信服科技股份有限公司 Data verification method and device and readable storage medium
CN107861832A (en) * 2017-09-27 2018-03-30 深信服科技股份有限公司 Data verification method, device and readable storage medium storing program for executing
CN109271758B (en) * 2018-08-24 2021-04-20 阿里巴巴(中国)有限公司 Method, equipment, device and server for preventing So file from being stolen
CN109271758A (en) * 2018-08-24 2019-01-25 广州优视网络科技有限公司 Method, unit and the server for preventing So file stolen
CN111090889A (en) * 2019-12-05 2020-05-01 深圳和而泰家居在线网络科技有限公司 Method for detecting ELF file and electronic equipment
CN112099954A (en) * 2020-09-18 2020-12-18 百度时代网络技术(北京)有限公司 Method, device, equipment and storage medium for deploying and downloading resources
CN112596749A (en) * 2020-12-28 2021-04-02 厦门亿联网络技术股份有限公司 Method and device for system power-on self-test and self-repair
CN112579547A (en) * 2021-01-27 2021-03-30 深圳市亿联无限科技有限公司 Embedded system mirror image file compression method and device
CN112579547B (en) * 2021-01-27 2024-01-23 深圳市亿联无限科技有限公司 Image file compression method and device for embedded system
CN113590227A (en) * 2021-08-02 2021-11-02 中国大恒(集团)有限公司北京图像视觉技术分公司 Binary programming format loading method and system under embedded system
CN113590227B (en) * 2021-08-02 2023-11-28 中国大恒(集团)有限公司北京图像视觉技术分公司 Method and system for loading binary programming format under embedded system

Similar Documents

Publication Publication Date Title
CN102662789A (en) Method for adding CRC (cyclic redundancy check) to ELF (executable linkable format) file
EP1934727B1 (en) Method and system for in-place updating content stored in a storage device
CN105049486A (en) Version management and file pulling control methods for static files, version management and file pulling control devices, and version control system
US20130332647A1 (en) Method and apparatus for fault tolerant fota update with single backup block write
CN109710185B (en) Data processing method and device
US9053107B1 (en) Determining updates for files based on an organization of the files on different blocks of a storage device
KR20140124774A (en) Generating and caching software code
CN104932973A (en) Version compatibility test method and apparatus
US9043680B2 (en) Method and system for in-place updating content stored in a storage device
CN111240722B (en) Method for upgrading firmware over the air, and terminal, server and system applied by same
US20080172584A1 (en) Method and system for in-place updating content stored in a storage device
CN111740948A (en) Data packet issuing method, dynamic updating method, device, equipment and medium
CN106201640A (en) A kind of method and device of BootLoader program of upgrading
CN101430705A (en) Memory method and apparatus based on embedded database
US9552277B2 (en) Synchronized java debugger
CN108694049B (en) Method and equipment for updating software
CN104036193A (en) Local cross-domain vulnerability detection method and device for application program
CN111930408A (en) Software upgrading method
KR101005979B1 (en) Display control apparatus, medium having display control program recorded therein and display control method
CN115599361A (en) Software development method, device, equipment and medium
CN104937560B (en) Method and apparatus for remote system debugging
CN110874285A (en) Method for realizing reducible write operation of EXT file system
Kiyohara et al. A delta representation scheme for updating between versions of mobile phone software
CN113282325B (en) Method and device for upgrading file system, storage medium and computing equipment
US20170357558A1 (en) Apparatus and method to enable a corrected program to take over data used before correction thereof

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20120912