mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-06 14:40:28 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
97
server/FSO.Server.Debug/PacketAnalyzer/VariableLengthStringAnalyzer.cs
Executable file
97
server/FSO.Server.Debug/PacketAnalyzer/VariableLengthStringAnalyzer.cs
Executable file
|
@ -0,0 +1,97 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FSO.Server.Debug.PacketAnalyzer
|
||||
{
|
||||
public class VariableLengthStringAnalyzer : IPacketAnalyzer
|
||||
{
|
||||
public List<PacketAnalyzerResult> Analyze(byte[] data)
|
||||
{
|
||||
var result = new List<PacketAnalyzerResult>();
|
||||
|
||||
/**
|
||||
* We are looking for a uint32 with the msb flipped for length followed by that many chars within a reasonable ascii range
|
||||
*/
|
||||
for (var i = 0; i < data.Length; i++)
|
||||
{
|
||||
var stringValue = GetString(data, i);
|
||||
if (stringValue != null)
|
||||
{
|
||||
var offset = 1;
|
||||
if(stringValue.Length > 128)
|
||||
{
|
||||
offset = 2;
|
||||
}
|
||||
|
||||
result.Add(new PacketAnalyzerResult
|
||||
{
|
||||
Offset = i,
|
||||
Length = stringValue.Length + offset,
|
||||
Description = "var-string(" + stringValue + ")"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetString(byte[] data, int index)
|
||||
{
|
||||
byte lengthByte = 0;
|
||||
uint length = 0;
|
||||
int shift = 0;
|
||||
byte lengthBytes = 0;
|
||||
|
||||
do
|
||||
{
|
||||
lengthByte = data[index + lengthBytes];
|
||||
length |= (uint)((lengthByte & (uint)0x7F) << shift);
|
||||
shift += 7;
|
||||
lengthBytes++;
|
||||
} while (
|
||||
(lengthByte >> 7) == 1 &&
|
||||
index + lengthBytes < data.Length
|
||||
);
|
||||
|
||||
if (length > 600 || length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if((index + lengthBytes + length) <= data.Length)
|
||||
{
|
||||
/** Could be! **/
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
byte charValue = data[index + lengthBytes + i];
|
||||
|
||||
|
||||
if(charValue == 0x09)
|
||||
{
|
||||
//Tab
|
||||
}
|
||||
else if(charValue == 0x0A)
|
||||
{
|
||||
//Line feed
|
||||
}else if(charValue == 0x0D)
|
||||
{
|
||||
//CR
|
||||
}else if(charValue >= 0x20 && charValue <= 0x7E)
|
||||
{
|
||||
//a-z, special chars, numbers
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
str.Append((char)charValue);
|
||||
}
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue