Skip to content

Commit 6d1dabb

Browse files
committed
Handle only cases where long mattered
1 parent 2e33789 commit 6d1dabb

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

SabreTools.Serialization/Wrappers/LinearExecutable.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public int GetObjectPageMapEntryOffset(int index)
166166
return -1;
167167

168168
// Get the end of the file, if possible
169-
int endOfFile = GetEndOfFile();
169+
long endOfFile = GetEndOfFile();
170170
if (endOfFile == -1)
171171
return -1;
172172

@@ -268,7 +268,7 @@ public int GetResourceTableEntryOffset(int index)
268268
return -1;
269269

270270
// Get the end of the file, if possible
271-
int endOfFile = GetEndOfFile();
271+
long endOfFile = GetEndOfFile();
272272
if (endOfFile == -1)
273273
return -1;
274274

@@ -301,7 +301,7 @@ public int GetResourceTableEntryOffset(int index)
301301
/// <param name="length">How many bytes to read, -1 means read until end</param>
302302
/// <returns>Byte array representing the range, null on error</returns>
303303
[Obsolete]
304-
public byte[]? ReadArbitraryRange(int rangeStart = -1, int length = -1)
304+
public byte[]? ReadArbitraryRange(int rangeStart = -1, long length = -1)
305305
{
306306
// If we have an unset range start, read from the start of the source
307307
if (rangeStart == -1)
@@ -313,16 +313,16 @@ public int GetResourceTableEntryOffset(int index)
313313
switch (_dataSource)
314314
{
315315
case DataSource.ByteArray:
316-
length = _byteArrayData!.Length - _byteArrayOffset;
316+
length = _byteArrayData!.Length - _initialPosition;
317317
break;
318318

319319
case DataSource.Stream:
320-
length = (int)_streamData!.Length;
320+
length = _streamData!.Length - _initialPosition;
321321
break;
322322
}
323323
}
324324

325-
return ReadFromDataSource(rangeStart, length);
325+
return ReadFromDataSource(rangeStart, (int)length);
326326
}
327327

328328
#endregion

SabreTools.Serialization/Wrappers/NewExecutable.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public byte[]? OverlayData
121121
return _overlayData;
122122

123123
// Get the end of the file, if possible
124-
int endOfFile = GetEndOfFile();
124+
long endOfFile = GetEndOfFile();
125125
if (endOfFile == -1)
126126
return null;
127127

@@ -169,8 +169,8 @@ public byte[]? OverlayData
169169
}
170170

171171
// Otherwise, cache and return the data
172-
int overlayLength = endOfFile - endOfSectionData;
173-
_overlayData = ReadFromDataSource(endOfSectionData, overlayLength);
172+
long overlayLength = endOfFile - endOfSectionData;
173+
_overlayData = ReadFromDataSource(endOfSectionData, (int)overlayLength);
174174
return _overlayData;
175175
}
176176
}
@@ -190,7 +190,7 @@ public List<string>? OverlayStrings
190190
return _overlayStrings;
191191

192192
// Get the end of the file, if possible
193-
int endOfFile = GetEndOfFile();
193+
long endOfFile = GetEndOfFile();
194194
if (endOfFile == -1)
195195
return null;
196196

@@ -239,10 +239,10 @@ public List<string>? OverlayStrings
239239

240240
// TODO: Revisit the 16 MiB limit
241241
// Cap the check for overlay strings to 16 MiB (arbitrary)
242-
int overlayLength = Math.Min(endOfFile - endOfSectionData, 16 * 1024 * 1024);
242+
long overlayLength = Math.Min(endOfFile - endOfSectionData, 16 * 1024 * 1024);
243243

244244
// Otherwise, cache and return the strings
245-
_overlayStrings = ReadStringsFromDataSource(endOfSectionData, overlayLength, charLimit: 3);
245+
_overlayStrings = ReadStringsFromDataSource(endOfSectionData, (int)overlayLength, charLimit: 3);
246246
return _overlayStrings;
247247
}
248248
}
@@ -396,7 +396,7 @@ public NewExecutable(Executable? model, Stream? data)
396396
return null;
397397

398398
// Get the end of the file, if possible
399-
int endOfFile = GetEndOfFile();
399+
long endOfFile = GetEndOfFile();
400400
if (endOfFile == -1)
401401
return null;
402402

@@ -474,7 +474,7 @@ public int GetResourceLength(int id)
474474
public int GetResourceOffset(int id)
475475
{
476476
// Get the end of the file, if possible
477-
int endOfFile = GetEndOfFile();
477+
long endOfFile = GetEndOfFile();
478478
if (endOfFile == -1)
479479
return -1;
480480

@@ -570,7 +570,7 @@ public int GetSegmentOffset(int index)
570570
return -1;
571571

572572
// Get the end of the file, if possible
573-
int endOfFile = GetEndOfFile();
573+
long endOfFile = GetEndOfFile();
574574
if (endOfFile == -1)
575575
return -1;
576576

@@ -599,7 +599,7 @@ public int GetSegmentOffset(int index)
599599
/// <param name="length">How many bytes to read, -1 means read until end</param>
600600
/// <returns>Byte array representing the range, null on error</returns>
601601
[Obsolete]
602-
public byte[]? ReadArbitraryRange(int rangeStart = -1, int length = -1)
602+
public byte[]? ReadArbitraryRange(int rangeStart = -1, long length = -1)
603603
{
604604
// If we have an unset range start, read from the start of the source
605605
if (rangeStart == -1)
@@ -611,16 +611,16 @@ public int GetSegmentOffset(int index)
611611
switch (_dataSource)
612612
{
613613
case DataSource.ByteArray:
614-
length = _byteArrayData!.Length - _byteArrayOffset;
614+
length = _byteArrayData!.Length - _initialPosition;
615615
break;
616616

617617
case DataSource.Stream:
618-
length = (int)_streamData!.Length;
618+
length = _streamData!.Length - _initialPosition;
619619
break;
620620
}
621621
}
622622

623-
return ReadFromDataSource(rangeStart, length);
623+
return ReadFromDataSource(rangeStart, (int)length);
624624
}
625625

626626
#endregion

SabreTools.Serialization/Wrappers/PortableExecutable.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public int OverlayAddress
208208
return _overlayAddress.Value;
209209

210210
// Get the end of the file, if possible
211-
int endOfFile = GetEndOfFile();
211+
long endOfFile = GetEndOfFile();
212212
if (endOfFile == -1)
213213
return -1;
214214

@@ -279,7 +279,7 @@ public byte[]? OverlayData
279279
return _overlayData;
280280

281281
// Get the end of the file, if possible
282-
int endOfFile = GetEndOfFile();
282+
long endOfFile = GetEndOfFile();
283283
if (endOfFile == -1)
284284
return null;
285285

@@ -336,8 +336,8 @@ public byte[]? OverlayData
336336
}
337337

338338
// Otherwise, cache and return the data
339-
int overlayLength = endOfFile - endOfSectionData;
340-
_overlayData = ReadFromDataSource(endOfSectionData, overlayLength);
339+
long overlayLength = endOfFile - endOfSectionData;
340+
_overlayData = ReadFromDataSource(endOfSectionData, (int)overlayLength);
341341
return _overlayData;
342342
}
343343
}
@@ -357,7 +357,7 @@ public List<string>? OverlayStrings
357357
return _overlayStrings;
358358

359359
// Get the end of the file, if possible
360-
int endOfFile = GetEndOfFile();
360+
long endOfFile = GetEndOfFile();
361361
if (endOfFile == -1)
362362
return null;
363363

@@ -415,10 +415,10 @@ public List<string>? OverlayStrings
415415

416416
// TODO: Revisit the 16 MiB limit
417417
// Cap the check for overlay strings to 16 MiB (arbitrary)
418-
int overlayLength = Math.Min(endOfFile - endOfSectionData, 16 * 1024 * 1024);
418+
long overlayLength = Math.Min(endOfFile - endOfSectionData, 16 * 1024 * 1024);
419419

420420
// Otherwise, cache and return the strings
421-
_overlayStrings = ReadStringsFromDataSource(endOfSectionData, overlayLength, charLimit: 3);
421+
_overlayStrings = ReadStringsFromDataSource(endOfSectionData, (int)overlayLength, charLimit: 3);
422422
return _overlayStrings;
423423
}
424424
}

SabreTools.Serialization/Wrappers/Quantum.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public bool ExtractFile(int index, string outputDirectory, bool includeDebug)
135135

136136
// Read the entire compressed data
137137
int compressedDataOffset = (int)CompressedDataOffset;
138-
int compressedDataLength = GetEndOfFile() - compressedDataOffset;
139-
var compressedData = ReadFromDataSource(compressedDataOffset, compressedDataLength);
138+
long compressedDataLength = GetEndOfFile() - compressedDataOffset;
139+
var compressedData = ReadFromDataSource(compressedDataOffset, (int)compressedDataLength);
140140

141141
// Print a debug reminder
142142
if (includeDebug) Console.WriteLine("Quantum archive extraction is unsupported");

0 commit comments

Comments
 (0)