Skip to content

Commit

Permalink
Adhere to all Stylecop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fjeremic committed May 21, 2020
1 parent 849c918 commit 0915e6a
Show file tree
Hide file tree
Showing 63 changed files with 966 additions and 965 deletions.
12 changes: 12 additions & 0 deletions BinaryTools.Elf.Tests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this")]
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1404:Code analysis suppression should have justification")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1117:Parameters should be on same line or separate lines")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented")]
13 changes: 6 additions & 7 deletions BinaryTools.Elf.Tests/TestElfDynamicSection.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using BinaryTools.Elf.Io;
using System;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfDynamicSection
{
[Fact]
Expand Down Expand Up @@ -76,7 +75,7 @@ public void TestName()

ElfDynamicSection dynamicSection = elfFile.Sections[22] as ElfDynamicSection;
Assert.Equal("libc.so.6", dynamicSection[0].Name);
Assert.Equal(String.Empty, dynamicSection[1].Name);
Assert.Equal(string.Empty, dynamicSection[1].Name);
}
}
}
26 changes: 13 additions & 13 deletions BinaryTools.Elf.Tests/TestElfFile.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using BinaryTools.Elf.Io;
using System;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
{
using System;
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfFile
{
[Fact]
Expand All @@ -21,8 +21,8 @@ public void TestClosedStream()
var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read);
stream.Close();

void action() => new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
Assert.Throws<ArgumentException>(action);
void Action() => new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
Assert.Throws<ArgumentException>(Action);
}

[Fact]
Expand All @@ -38,29 +38,29 @@ public void TestInvalidMagicBytes()
{
var stream = new FileStream("Binaries/invalidmagicbytes", FileMode.Open, FileAccess.Read);
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
void action() => ElfFile.ReadElfFile(reader);
void Action() => ElfFile.ReadElfFile(reader);

Assert.Throws<FileFormatException>(action);
Assert.Throws<FileFormatException>(Action);
}

[Fact]
public void TestInvalidClass()
{
var stream = new FileStream("Binaries/invalidclass", FileMode.Open, FileAccess.Read);
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
void action() => ElfFile.ReadElfFile(reader);
void Action() => ElfFile.ReadElfFile(reader);

Assert.Throws<FileFormatException>(action);
Assert.Throws<FileFormatException>(Action);
}

[Fact]
public void TestInvalidEndianness()
{
var stream = new FileStream("Binaries/invalidendianness", FileMode.Open, FileAccess.Read);
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
void action() => ElfFile.ReadElfFile(reader);
void Action() => ElfFile.ReadElfFile(reader);

Assert.Throws<FileFormatException>(action);
Assert.Throws<FileFormatException>(Action);
}
}
}
10 changes: 5 additions & 5 deletions BinaryTools.Elf.Tests/TestElfHeader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfHeader
{
[Fact]
Expand Down
10 changes: 5 additions & 5 deletions BinaryTools.Elf.Tests/TestElfRelocationSection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfRelocationSection
{
[Fact]
Expand Down
12 changes: 6 additions & 6 deletions BinaryTools.Elf.Tests/TestElfSection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfSection
{
[Fact]
Expand All @@ -23,7 +23,7 @@ public void TestName()
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal("", elfFile.Sections[0].Name);
Assert.Equal(string.Empty, elfFile.Sections[0].Name);
Assert.Equal(".dynsym", elfFile.Sections[5].Name);
Assert.Equal(".plt.got", elfFile.Sections[13].Name);
Assert.Equal(".dynamic", elfFile.Sections[22].Name);
Expand Down
11 changes: 5 additions & 6 deletions BinaryTools.Elf.Tests/TestElfSegment.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfSegment
{
[Fact]
Expand Down Expand Up @@ -31,7 +31,6 @@ public void TestType()
Assert.Equal(ElfSegmentType.Note, elfFile.Segments[5].Type);
}


[Fact]
public void TestOffset()
{
Expand Down
10 changes: 5 additions & 5 deletions BinaryTools.Elf.Tests/TestElfStringTable.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfStringTable
{
[Fact]
Expand Down
12 changes: 6 additions & 6 deletions BinaryTools.Elf.Tests/TestElfSymbolTable.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BinaryTools.Elf.Io;
using System.IO;
using Xunit;

namespace BinaryTools.Elf.Tests
namespace BinaryTools.Elf.Tests
{
using System.IO;
using BinaryTools.Elf.Io;
using Xunit;

public class TestElfSymbolTable
{
[Fact]
Expand All @@ -29,7 +29,7 @@ public void TestName()
Assert.IsAssignableFrom<ElfSymbolTable>(elfFile.Sections[5]);

ElfSymbolTable symbolTable = elfFile.Sections[5] as ElfSymbolTable;
Assert.Equal("", symbolTable[0].Name);
Assert.Equal(string.Empty, symbolTable[0].Name);
Assert.Equal("__uflow", symbolTable[1].Name);
Assert.Equal("getenv", symbolTable[2].Name);
Assert.Equal("free", symbolTable[3].Name);
Expand Down
40 changes: 20 additions & 20 deletions BinaryTools.Elf/BinaryReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.IO;
using System.Text;

namespace BinaryTools.Elf
namespace BinaryTools.Elf
{
using System.IO;
using System.Text;

/// <summary>
/// An extension class providing <see cref="BinaryReader"/> utility methods for extracting ELF specific data.
/// </summary>
Expand All @@ -12,28 +11,29 @@ public static class BinaryReaderExtensions
/// <summary>
/// Reads a string value from the binary reader.
/// </summary>
///
///
/// <param name="reader">
/// The binary reader used to extract data.
/// </param>
///
///
/// <returns>
/// The string value.
/// </returns>
///
///
/// <remarks>
/// The string is defined as a null terminated sequence of character values.
/// </remarks>
public static String ReadELFString(this BinaryReader reader)
public static string ReadELFString(this BinaryReader reader)
{
StringBuilder builder = new StringBuilder();

Char c = (Char)reader.ReadByte();
char c = (char)reader.ReadByte();

// Read the entire null terminated string
while (c != 0)
{
builder.Append(c); c = (Char)reader.ReadByte();
builder.Append(c);
c = (char)reader.ReadByte();
}

return builder.ToString();
Expand All @@ -42,35 +42,35 @@ public static String ReadELFString(this BinaryReader reader)
/// <summary>
/// Reads a string value from an index into the ELF string table section.
/// </summary>
///
///
/// <param name="reader">
/// The binary reader used to extract data.
/// </param>
///
///
/// <param name="section">
/// The ELF string table section.
/// </param>
///
///
/// <param name="offset">
/// The offset of the string in the ELF string table section.
/// </param>
///
///
/// <returns>
/// The string value extracted from the ELF string table section at the specified offset.
/// </returns>
///
///
/// <remarks>
/// The string is defined as a null terminated sequence of character values.
/// </remarks>
public static String ReadELFString(this BinaryReader reader, ElfSection section, UInt64 offset)
public static string ReadELFString(this BinaryReader reader, ElfSection section, ulong offset)
{
String value = String.Empty;
string value = string.Empty;

if (section != null && offset < section.Size)
{
Int64 savedPosition = reader.BaseStream.Position;
long savedPosition = reader.BaseStream.Position;

reader.BaseStream.Position = (Int64)(section.Offset + offset);
reader.BaseStream.Position = (long)(section.Offset + offset);

// Read the entire null terminated string
value = reader.ReadELFString();
Expand Down
20 changes: 11 additions & 9 deletions BinaryTools.Elf/Bit32/ElfDynamicEntry.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using System;
using System.IO;

namespace BinaryTools.Elf.Bit32
namespace BinaryTools.Elf.Bit32
{
using System.IO;

/// <summary>
/// Represents an ELF dynamic entry.
/// </summary>
internal sealed class ElfDynamicEntry : Elf.ElfDynamicEntry
{
/// <summary>
/// Initializes a new instance of <see cref="ElfDynamicSection"/> by extracting data from a <see cref="BinaryReader"/>.
/// Initializes a new instance of the <see cref="ElfDynamicEntry"/> class by extracting data from a <see cref="BinaryReader"/>.
/// </summary>
///
///
/// <param name="reader">
/// The reader used to extract the data needed to initialize this type.
/// </param>
///
///
/// <param name="position">
/// The position within the <paramref name="reader"/> base stream at which the entry begins.
/// </param>
internal ElfDynamicEntry(BinaryReader reader, Int64 position)
internal ElfDynamicEntry(BinaryReader reader, long position)
{
reader.BaseStream.Position = position;

Expand All @@ -26,7 +28,7 @@ internal ElfDynamicEntry(BinaryReader reader, Int64 position)
// Represents Elf32_Dyn.d_val
Value = reader.ReadUInt32();

Name = String.Empty;
Name = string.Empty;
}
}
}
Loading

0 comments on commit 0915e6a

Please sign in to comment.