📜 ⬆️ ⬇️

Work with the 1C: Enterprise configuration format

I decided to publish the C # source code for working with the 1C: Enterprise configuration format.


https://github.com/elisy/MdInternals


MdInternals understands the format of cf, cfu, epf, erf, unpacks the content into readable Xml and text files and loads it back. Allows you to programmatically access the internal files and properties of objects.


The project consists of parts:




Upload files cf, cfu, epf, erf to disk


var cf = new CfPackage(); // var cf = new EpfPackage(); // var cf = new ErfPackage(); // var cf = new CfuPackage(); cf.Open(@"D:\config.cf"); var project = new CfProject(); project.Save(epf, @"D:\Config\Xml\Config.cfproj", ProjectType.Xml); 

Recognized files are written to the directory tree by object type. Unrecognized are placed in the Unresolved directory:



')

Recognized files are uploaded in XML format. The XML format allows you to control the logical integrity of files and process files with third-party programs. Known properties are moved to the appropriate sections (attributes or tags) of the XML structure:





Read from MSSQL table


 var image = ImageReader.ReadImageFromConfig(@"data source=192.168.1.2\SQL2005;user=login;pwd=password;database=Database1C"); 


Accessing internal files


 var mp = new EpfPackage(); mp.Open(file); var root = mp.MetadataObjects.Where(m => m.ImageRow.FileName == "root").FirstOrDefault(); var rp = new RootPointer(root.ImageRow); var part = mp.MetadataObjects.Where(m => m.ImageRow.FileName == rp.MetadataPackageFileName.ToString()).FirstOrDefault(); 

Creating a file from the uploaded xml format


 var project = new CfProject(); var mp = project.Load(@"D:\Config\Xml\Config.cfproj"); mp.Save(@"D:\config.cf"); 

Cf Format Description


The cf file consists of the image header (ImageHeader) and the following pages (ImagePage1-ImagePageN). The image header consists of 4 bytes of the signature, which is 0xFF 0xFF 0xFF 0x7F, 4x page size bytes and 8 reserved bytes. After the header of the file are in order of the page with the data. Each previous page refers to the next.





Each page (ImagePage) consists of a page header (ImagePageHeader), a group of pointers to ImageRowPointers entries, and an ImageRows area.





The header of the ImagePageHeader page contains: reserved 2 bytes 0x0D 0x0A, 27 bytes of text information, and reserved 2 bytes 0x0D 0x0A. Text information contains 3 hexadecimal numbers: the total data size of all pages (FullSize), the size of the current page (PageSize) and the address of the next page in the file (NextPageAddress). FullSize is affixed only for the first page of the page chain. For the remaining pages of the thread, this value is 0. For the last page of the thread, the NextPageAddress is taken to be 0xFF 0xFF 0xFF 0x7F.


The block of pointers ImageRowPointers is the size specified in the PageSize value of the page. Each pointer consists of 4 bytes of the HeaderAddress header address and 4 bytes of the BodyAddress body address. At the end of each pointer is placed the signature 0xFF 0xFF 0xFF 0x7F. Addresses indicate locations within the current page to the ImageRows area.


The ImageRowHeader header starts with the ImagePageHeader page title block, which tells you how many bytes are allocated for the header. Next come 20 reserved bytes, a UTF-16 data identifier string (Id) and 4 reserved bytes.


The body of ImageRowBody begins with the block header of the ImagePageHeader page, which tells you how many bytes are allocated to the data body. If the data body starts at 0xEF 0xBB 0xBF (signature UTF8), then the body contains a UTF-8 string. Otherwise, the data body contains packed data. If the unpacked data starts with 0xFF 0xFF 0xFF 0x7F, then the contents are a sequence of objects, and they are written in CF format. Otherwise, the content is a serialization string.



What is not implemented


Source: https://habr.com/ru/post/434974/


All Articles