Skip to content

Commit

Permalink
Merge pull request #760 from SteamRE/nha2-syntax
Browse files Browse the repository at this point in the history
NHA2: Tweaks/Fixes
  • Loading branch information
yaakov-h authored Oct 20, 2019
2 parents d878702 + 628e848 commit e4a0bbf
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 191 deletions.
39 changes: 25 additions & 14 deletions Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ public MainForm()
specializations = LoadMessageObjectSpecializations();
}

#pragma warning disable IDE0069 // Disposable fields should be disposed

IDisposable itemsListViewFirstColumnHiderDisposable;
FileSystemWatcher folderWatcher;

#pragma warning restore IDE0069 // Disposable fields should be disposed

readonly ISpecialization[] specializations;

static ISpecialization[] LoadMessageObjectSpecializations()
Expand All @@ -49,9 +54,9 @@ static ISpecialization[] LoadMessageObjectSpecializations()
new ArtifactCacheSubscribedGCSpecialization(),
new ArtifactSOMultipleObjectsGCSpecialization(),
new ArtifactSOSingleObjectGCSpecialization(),
new UnderlordsCacheSubscribedGCSpecialization(),
new UnderlordsSOMultipleObjectsGCSpecialization(),
new UnderlordsSOSingleObjectGCSpecialization(),
new UnderlordsCacheSubscribedGCSpecialization(),
new UnderlordsSOMultipleObjectsGCSpecialization(),
new UnderlordsSOSingleObjectGCSpecialization(),
}
}
};
Expand Down Expand Up @@ -147,21 +152,27 @@ void OnExitToolStripMenuItemClick(object sender, EventArgs e)
Application.Exit();
}

void OnOpenToolStripMenuItemClick(object sender, EventArgs e)
void OnOpenToolStripMenuItemClick( object sender, EventArgs e )
{
var dialog = new FolderBrowserDialog { ShowNewFolderButton = false };
var latestNethookDir = GetLatestNethookDumpDirectory();
if (latestNethookDir != null)
{
dialog.SelectedPath = GetLatestNethookDumpDirectory();
}
string dumpDirectory;

if (dialog.ShowDialog() != WinForms.DialogResult.OK)
using ( var dialog = new FolderBrowserDialog() )
{
return;
}
dialog.ShowNewFolderButton = false;

var dumpDirectory = dialog.SelectedPath;
var latestNethookDir = GetLatestNethookDumpDirectory();
if ( latestNethookDir != null )
{
dialog.SelectedPath = GetLatestNethookDumpDirectory();
}

if ( dialog.ShowDialog() != WinForms.DialogResult.OK )
{
return;
}

dumpDirectory = dialog.SelectedPath;
}

var dump = new NetHookDump();
dump.LoadFromDirectory(dumpDirectory);
Expand Down
10 changes: 0 additions & 10 deletions Resources/NetHookAnalyzer2/NetHookAnalyzer2/MessageTypeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ static bool FilterProtobufMessageBodyType(Type type, EMsg eMsg)
return true;
}

static bool FilterNonProtobufMessageBodyTypes(Type type, EMsg eMsg)
{
if (type.GetInterfaces().ToList().Find(@interface => @interface == typeof(ISteamSerializableMessage)) == null)
return false;

var gcMsg = Activator.CreateInstance(type) as ISteamSerializableMessage;

return gcMsg.GetEMsg() == eMsg;
}

#endregion

static IEnumerable<string> GetPossibleGCTypePrefixes(uint appid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@
<ProjectReference Include="..\..\..\SteamKit2\SteamKit2\SteamKit2.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>
10 changes: 4 additions & 6 deletions Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ public bool LoadFromFile(FileInfo fileInfo)
return false;
}

int sequence;
if (!int.TryParse(m.Groups["num"].Value, out sequence))
if (!int.TryParse(m.Groups["num"].Value, out var sequence))
{
return false;
}

Timestamp = fileInfo.LastWriteTime;

var direction = m.Groups[ "direction" ].Value;
PacketDirection packetDirection;
if (!Enum.TryParse<PacketDirection>(direction, ignoreCase: true, result: out packetDirection))

if (!Enum.TryParse<PacketDirection>(direction, ignoreCase: true, result: out var packetDirection))
{
return false;
}

uint emsg;
if (!uint.TryParse(m.Groups["emsg"].Value, out emsg))
if (!uint.TryParse(m.Groups["emsg"].Value, out var emsg))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ public static Dictionary<int, List<object>> ReadProtobuf(Stream stream)
}
}

if (!fields.ContainsKey(field))
if (fields.TryGetValue(field, out var values))
{
fields[field] = new List<object>();
values.Add( fieldValue );
}
else
{
values = new List<object> { fieldValue };
fields[ field ] = values;
}

fields[field].Add(fieldValue);
}

if (fields.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId)
{
try
{
using (var ms = new MemoryStream(sharedObject))
using var ms = new MemoryStream( sharedObject );
if ( ArtifactSOHelper.SOTypes.TryGetValue( typeId, out var t ) )
{
Type t;
if (ArtifactSOHelper.SOTypes.TryGetValue(typeId, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
using var ms = new MemoryStream( sharedObject.object_data );
if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) )
{
Type t;
if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
using var ms = new MemoryStream( sharedObject.object_data );
if ( ArtifactSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) )
{
Type t;
if (ArtifactSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId)
{
try
{
using (var ms = new MemoryStream(sharedObject))
using var ms = new MemoryStream( sharedObject );
if ( CSGOSOHelper.SOTypes.TryGetValue( typeId, out var t ) )
{
Type t;
if (CSGOSOHelper.SOTypes.TryGetValue(typeId, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
{
Type t;
if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
}
}
using var ms = new MemoryStream( sharedObject.object_data );
if ( CSGOSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) )
{
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
{
return "Error parsing SO data: " + ex.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
using var ms = new MemoryStream( sharedObject.object_data );
if ( CSGOSOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) )
{
Type t;
if (CSGOSOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId)
{
try
{
using (var ms = new MemoryStream(sharedObject))
using var ms = new MemoryStream( sharedObject );
if ( Dota2SOHelper.SOTypes.TryGetValue( typeId, out var t ) )
{
Type t;
if (Dota2SOHelper.SOTypes.TryGetValue(typeId, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ object ReadExtraObject(CMsgSOMultipleObjects.SingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
using var ms = new MemoryStream(sharedObject.object_data);
if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out var t))
{
Type t;
if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ object ReadExtraObject(CMsgSOSingleObject sharedObject)
{
try
{
using (var ms = new MemoryStream(sharedObject.object_data))
using var ms = new MemoryStream( sharedObject.object_data );
if ( Dota2SOHelper.SOTypes.TryGetValue( sharedObject.type_id, out var t ) )
{
Type t;
if (Dota2SOHelper.SOTypes.TryGetValue(sharedObject.type_id, out t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,40 @@ public IEnumerable<KeyValuePair<string, object>> ReadExtraObjects(object message
yield break;
}

using (var ms = new MemoryStream(gameCoordinatorMessage.payload))
{
var header = ReadHeader(gameCoordinatorMessage.msgtype, ms);
var gcBody = ReadMessageBody(gameCoordinatorMessage.msgtype, ms, gameCoordinatorMessage.appid);
if (gcBody == null)
{
yield break;
}
using var ms = new MemoryStream( gameCoordinatorMessage.payload );
var header = ReadHeader( gameCoordinatorMessage.msgtype, ms );
var gcBody = ReadMessageBody( gameCoordinatorMessage.msgtype, ms, gameCoordinatorMessage.appid );
if ( gcBody == null )
{
yield break;
}

var gc = new
{
emsg = EMsgExtensions.GetGCMessageName(gameCoordinatorMessage.msgtype, gameCoordinatorMessage.appid),
header = header,
body = gcBody,
};
var gc = new
{
emsg = EMsgExtensions.GetGCMessageName( gameCoordinatorMessage.msgtype, gameCoordinatorMessage.appid ),
header = header,
body = gcBody,
};

var specializations = new List<TreeNode>();
var specializations = new List<TreeNode>();

yield return new KeyValuePair<string, object>("Game Coordinator Message", gc);
yield return new KeyValuePair<string, object>( "Game Coordinator Message", gc );

if (GameCoordinatorSpecializations != null)
{
foreach (var gameSpecificSpecialization in GameCoordinatorSpecializations)
{
foreach (var specializedObject in gameSpecificSpecialization.GetExtraObjects(gcBody, gameCoordinatorMessage.appid))
{
yield return specializedObject;
}
}
}
}
}
if ( GameCoordinatorSpecializations != null )
{
foreach ( var gameSpecificSpecialization in GameCoordinatorSpecializations )
{
foreach ( var specializedObject in gameSpecificSpecialization.GetExtraObjects( gcBody, gameCoordinatorMessage.appid ) )
{
yield return specializedObject;
}
}
}
}

static IGCSerializableHeader ReadHeader(uint rawEMsg, Stream stream)
{
IGCSerializableHeader header = null;
IGCSerializableHeader header;

if (MsgUtil.IsProtoBuf(rawEMsg))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ object ReadExtraObject(byte[] sharedObject, int typeId)
{
try
{
using (var ms = new MemoryStream(sharedObject))
using var ms = new MemoryStream( sharedObject );
if ( TF2SOHelper.SOTypes.TryGetValue( typeId, out var t ) )
{
if (TF2SOHelper.SOTypes.TryGetValue(typeId, out var t))
{
return RuntimeTypeModel.Default.Deserialize(ms, null, t);
}
return RuntimeTypeModel.Default.Deserialize( ms, null, t );
}
}
catch (ProtoException ex)
Expand Down
Loading

0 comments on commit e4a0bbf

Please sign in to comment.