0

I have some configuration (backup) files of a Siemens S7-300 PLC with the extension *.PG. Some other files have the extension *.DBF and can be read with the OLEDB Connection. But it is not possible to read the *.PG files.

I googled a lot but could not find much info about pg files. It contains also some text informations about the PLC modules, and these I want to parse. Just for testing I tried to use the https://filext.com/online-file-viewer.html online file viewer and I could read the file's text content correctly as like a text file. That means the file should be opened. But how can I do it programatically with C#?

I have found following code for dbf file that is not suitable for my case.

public override bool OpenFile(string fileName, string subFileName = "") { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(fileName) + ";Extended Properties=dBASE IV;User ID=;Password=;"); try { if (con.State == ConnectionState.Closed) { con.Open(); } OleDbDataAdapter da = new OleDbDataAdapter("select * from " + Path.GetFileName(fileName), con); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); int i = ds.Tables[0].Rows.Count; return true; } catch { return false; } } 

Here the complete files content as HEX

07 00 0b 00 d0 07 02 03 f0 06 00 00 42 03 00 00 00 00 00 00 60 03 00 00 00 00 03 e5 a2 88 39 e7 00 00 00 00 12 2d 80 00 00 00 53 54 45 50 20 37 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 04 00 4a e9 31 72 4a 10 00 00 00 00 0e 0c c4 c0 00 01 03 00 02 02 fe 00 00 00 01 20 00 16 00 2e 00 4e 00 f4 00 f6 00 02 01 7c 02 5a 00 0e 00 f8 01 00 01 06 01 0a 00 00 01 6a 01 4c 02 06 01 2c 00 0b 00 96 00 01 00 00 65 df 0a 7e 01 00 00 01 00 75 00 18 07 ff 00 00 00 00 01 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b 00 25 00 96 00 00 00 00 3e 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 02 00 08 04 17 00 00 00 05 00 06 00 02 00 01 00 04 00 05 00 60 00 00 00 ff 00 00 00 00 00 02 00 00 00 00 ff 01 00 00 02 01 00 00 00 0c 00 0c 00 0c 00 00 00 00 00 ff 00 00 00 6c 00 00 04 fe 00 00 00 00 00 00 00 00 00 00 01 00 02 02 02 02 02 02 00 0f 04 71 00 0b 00 25 00 96 00 00 e6 94 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 ff 00 00 00 ff ff 01 00 00 00 00 00 00 00 00 de 08 03 00 1c 00 1c 00 2c 00 54 00 5a 00 92 00 d2 00 d4 00 0a 00 00 00 00 00 da 00 00 00 c0 a0 00 40 40 f0 00 00 01 00 00 00 00 00 00 00 28 38 02 02 0b be ce 00 c0 00 08 00 00 00 00 40 00 6b 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 10 10 20 ff 00 38 03 04 1f fd 00 ff 21 ff 28 01 00 00 00 00 01 ff 21 ff 28 01 01 00 00 00 01 01 00 01 02 ff 21 ff 28 01 01 00 00 01 01 01 80 00 03 ff 21 ff 28 01 00 01 80 00 01 01 00 4a 3e 3d 3c 3b 3a 39 38 37 35 00 00 be ce 00 03 e8 40 01 02 40 02 08 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 06 00 00 02 00 00 02 00 ea 48 04 00 1c 00 1c 00 2c 00 56 00 5c 00 9e 00 de 00 e0 00 0a 00 00 00 00 00 e6 00 00 00 cc a0 00 80 40 f0 00 00 01 00 00 00 00 00 00 00 29 38 02 02 0b 80 e0 00 c0 61 00 11 21 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 20 01 00 38 09 00 38 09 00 20 08 00 ff 00 06 00 10 10 20 00 42 04 05 1f fe 00 ff 21 ff 28 01 00 00 1f fc 01 ff 21 ff 28 01 00 00 00 02 02 ff 21 ff 28 01 01 00 00 02 01 01 00 03 03 ff 21 ff 28 01 01 00 00 03 01 01 80 01 04 ff 21 ff 28 01 00 01 80 01 01 01 00 4a 3e 3d 3c 3b 3a 39 38 37 35 00 00 80 e0 00 00 64 80 01 02 80 02 08 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 06 00 00 02 00 00 02 00 15 0c 45 41 4e ff ff ff ff 02 51 14 00 00 00 00 be 09 00 6f 00 a9 b2 01 00 4d 00 00 00 00 26 06 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 48 e8 01 00 00 00 00 00 00 00 00 00 02 02 02 02 02 01 00 71 da 02 00 6c 00 68 00 08 00 ed 00 94 da 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2c 01 0c 00 0c 00 19 00 08 00 68 08 00 00 42 01 08 00 69 08 00 00 42 00 08 00 6a 08 00 00 42 01 0b 00 71 08 00 00 4c 00 00 00 00 0b 00 73 08 00 00 4c 00 00 00 00 0b 00 74 08 00 00 4c 00 00 00 00 08 00 05 10 00 00 41 00 08 00 06 10 00 00 41 00 0c 45 4e 00 ff ff ff ff 02 51 14 00 00 00 00 34 50 52 4f 46 49 42 55 53 28 31 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 56 01 00 00 00 00 00 00 00 00 00 0c 43 00 00 00 00 02 02 04 10 24 00 1c 4f 41 00 16 00 00 00 9b 10 14 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 02 00 08 00 61 b1 01 00 42 ff 08 00 62 b1 01 00 42 ff 0e 37 00 00 16 01 00 00 1a 12 24 00 04 00 0c 4d 00 00 16 01 04 00 d8 11 24 00 0c 4d 00 00 16 01 05 00 19 14 14 00 0c 45 41 00 16 01 05 00 19 14 14 00 00 00 00 11 01 00 0b 00 b6 b2 01 00 4c 00 00 00 00 0c 4d 00 00 16 01 06 00 19 14 14 00 0c 45 41 00 16 01 06 00 19 14 14 00 00 00 00 11 01 00 0b 00 b6 b2 01 00 4c 00 00 00 00 0c 4d 00 00 16 01 07 00 90 1f 24 00 0c 45 41 00 16 01 07 00 90 1f 24 00 00 00 00 11 01 00 0b 00 b6 b2 01 00 4c 00 00 00 00 40 4e 00 00 16 02 00 00 ac 10 14 00 03 00 42 33 31 32 42 45 43 45 2e 47 53 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 0c 45 41 00 16 02 00 00 ac 10 14 00 00 00 00 11 01 00 0b 00 73 b2 01 00 4c 00 00 00 00 40 44 00 00 16 02 04 00 b3 10 14 00 03 00 42 33 31 32 42 45 43 45 2e 47 53 45 00 38 20 42 69 74 20 64 69 67 69 74 61 6c 20 69 6e 70 75 74 73 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 0c 45 41 00 16 02 04 00 b3 10 14 00 00 00 00 11 01 00 0b 00 04 b3 01 00 4c 6f 00 00 00 40 44 00 00 16 02 05 00 b3 10 14 00 03 00 42 33 31 32 42 45 43 45 2e 47 53 45 00 38 20 42 69 74 20 64 69 67 69 74 61 6c 20 69 6e 70 75 74 73 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 0c 45 41 00 16 02 05 00 b3 10 14 00 00 00 00 11 01 00 0b 00 04 b3 01 00 4c 6f 00 00 00 40 44 00 00 16 02 06 00 b3 10 14 00 03 00 42 33 31 32 42 45 43 45 2e 47 53 45 00 38 20 42 69 74 20 64 69 67 69 74 61 6c 20 6f 75 74 70 75 74 73 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 0c 45 41 00 16 02 06 00 b3 10 14 00 00 00 00 11 01 00 0b 00 04 b3 01 00 4c 80 00 00 00 ff 
18
  • I don't know anything about it, but have you confirmed that the .pg files aren't just something like a zip file with a .pg extension? Commented Sep 11, 2024 at 6:42
  • 2
    If it is plain text, then you cannot treat it as a database file. Simply open it as a text file (File.ReadAllLines, for instance) . Getting the correct data from the text is then up to you, unfortunately Commented Sep 11, 2024 at 6:47
  • @Hans Kesting Its not directly text file but its containing text. When I open it with a text editor, I see alot of special caracters. It also definitly not a zip file. Commented Sep 11, 2024 at 6:55
  • 2
    Without you posting some bytes from a sample file, I'm not quite sure how you'd expect us to guess. This seems a niche proprietary and undocumented file format. There is no single simple way of reading a file "correctly" without knowing the format. If you can post bytes (emphasis: hex of the bytes: not string), we might be able to help. For all we know the "special caracters" [sic] here could just be UTF8 non-BMP units; or it could be some kind of common format like protobuf, msgpack, etc; or it could be entirely custom to that family of devices Commented Sep 11, 2024 at 8:27
  • 1
    If you look in the image you posted originally, you can see those same strings on the right-hand side, interspersed with the binary data. All that website has done is to list the strings that it found: it hasn't parsed or decoded the file in any way Commented Sep 11, 2024 at 9:19

1 Answer 1

3

This file contains binary data. Each byte has been assigned a meaning by the author of the file, but you can't tell what those meanings are without documentation.

So e.g. byte 1 will mean one thing, byte 2 will mean a different thing, and so on.

There's likely no easy way for you to reverse-engineer the content of that file, or extract anything meaningful.

Sign up to request clarification or add additional context in comments.

4 Comments

Unsure why you are posting this as an answer. Question should be close-voted as not enough details are provided
@DarkBee I think enough details have been provided for us to answer "you can't". We don't close other questions because the answer happens to be "you can't do it like that". What other details would OP be able to provide, anyway?
@DarkBee OK I don't want to take peoples time here. I posted this question just because I opened the file with the filext.com and it showed me the text part correctly. So I thought it could be parsed anyway. I am aware that author specific binary files cannot be extracted with reverse engineering. If someone can tell me I can deactivate or close the question
If I were you I'd post this on a PLC forum and not on StackOverflow

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.