我有一些西门子 S7-300 PLC 的配置(备份)文件,扩展名为 *.PG。其他一些文件的扩展名为 *.DBF,可以使用 OLEDB 连接读取。但无法读取 *.PG 文件。
我搜索了很多,但找不到太多关于 pg 文件的信息。它还包含一些关于 PLC 模块的文本信息,我想解析这些信息。为了测试,我尝试使用https://filext.com/online-file-viewer.html在线文件查看器,我可以像文本文件一样正确读取文件的文本内容。这意味着文件应该被打开。但我如何用 C# 以编程方式做到这一点?
我发现以下 dbf 文件代码不适合我的情况。
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;
}
}
以下是完整的文件内容(十六进制)
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
该文件包含二进制数据。文件的作者为每个字节赋予了含义,但如果没有文档,您就无法知道这些含义是什么。
例如字节 1 表示一件事,字节 2 表示另一件事,依此类推。
您可能没有简单的方法来对该文件的内容进行逆向工程,或提取任何有意义的内容。