aboutsummaryrefslogtreecommitdiff
blob: 93a1f8f8a854e51033405713e9c3b89d2663dacf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
diff -Naur mono-5.10.0.179.orig/mcs/class/corlib/System/TermInfoReader.cs mono-5.10.0.179/mcs/class/corlib/System/TermInfoReader.cs
--- mono-5.10.0.179.orig/mcs/class/corlib/System/TermInfoReader.cs	2018-03-19 07:46:31.000000000 +0000
+++ mono-5.10.0.179/mcs/class/corlib/System/TermInfoReader.cs	2018-03-25 20:57:57.721279733 +0100
@@ -72,16 +72,16 @@
 	//
 
 	class TermInfoReader {
-		//short nameSize;
-		short boolSize;
-		short numSize;
-		short strOffsets;
-		//short strSize;
+		int boolSize;
+		int numSize;
+		int strOffsets;
 
 		//string [] names; // Last one is the description
 		byte [] buffer;
 		int booleansOffset;
 		//string term;
+		
+		int intOffset;
 
 		public TermInfoReader (string term, string filename)
 		{
@@ -114,12 +114,21 @@
 //			get { return term; }
 //		}
 
+		void DetermineVersion (short magic)
+		{
+			if (magic == 0x11a)
+				intOffset = 2;
+			else if (magic == 0x21e)
+				intOffset = 4;
+			else
+				throw new Exception (String.Format ("Magic number is unexpected: {0}", magic));
+		}
+
 		void ReadHeader (byte [] buffer, ref int position)
 		{
 			short magic = GetInt16 (buffer, position);
 			position += 2;
-			if (magic != 282)
-				throw new Exception (String.Format ("Magic number is wrong: {0}", magic));
+			DetermineVersion (magic);
 			
 			/*nameSize =*/ GetInt16 (buffer, position);
 			position += 2;
@@ -161,8 +170,8 @@
 			if ((offset % 2) == 1)
 				offset++;
 
-			offset += ((int) number) * 2;
-			return GetInt16 (buffer, offset);
+			offset += ((int) number) * intOffset;
+			return GetInteger (buffer, offset);
 		}
 
 		public string Get (TermInfoStrings tstr)
@@ -175,7 +184,7 @@
 			if ((offset % 2) == 1)
 				offset++;
 
-			offset += numSize * 2;
+			offset += numSize * intOffset;
 			int off2 = GetInt16 (buffer, offset + (int) tstr * 2);
 			if (off2 == -1)
 				return null;
@@ -193,7 +202,7 @@
 			if ((offset % 2) == 1)
 				offset++;
 
-			offset += numSize * 2;
+			offset += numSize * intOffset;
 			int off2 = GetInt16 (buffer, offset + (int) tstr * 2);
 			if (off2 == -1)
 				return null;
@@ -211,6 +220,27 @@
 			return (short) (uno + dos * 256);
 		}
 
+		int GetInt32 (byte [] buffer, int offset)
+		{
+			int b1 = (int) buffer [offset];
+			int b2 = (int) buffer [offset + 1];
+			int b3 = (int) buffer [offset + 2];
+			int b4 = (int) buffer [offset + 3];
+			if (b1 == 255 && b2 == 255 && b3 == 255 && b4 == 255)
+				return -1;
+
+			return b1 + b2 << 8 + b3 << 16 + b4 << 24;
+		}
+
+		int GetInteger (byte [] buffer, int offset)
+		{
+			if (intOffset == 2)
+				return GetInt16 (buffer, offset);
+			else
+				// intOffset == 4
+				return GetInt32 (buffer, offset);
+		}
+
 		string GetString (byte [] buffer, int offset)
 		{
 			int length = 0;