Skip to content

Commit

Permalink
Merge pull request #2 from zarroboogs/offset-calc
Browse files Browse the repository at this point in the history
Base Offset Calc Changes + Misc Fixes
  • Loading branch information
TGE authored Jan 19, 2020
2 parents 52b23ce + e7df908 commit 15fcc4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
22 changes: 11 additions & 11 deletions Source/RPCS3PatchEboot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

using YamlDotNet.Serialization;
using ELFSharp.ELF;
using ELFSharp.ELF.Sections;
using System.Runtime.CompilerServices;
using ELFSharp.ELF.Segments;

namespace RPCS3PatchEboot
{
class Program
{
private static byte[] ElfMagic = { 0x7F, ( byte ) 'E', ( byte ) 'L', ( byte ) 'F' };
private static byte[] SceMagic = { ( byte ) 'S', ( byte ) 'C', ( byte ) 'E', 0x00 };
private static readonly byte[] ElfMagic = { 0x7F, ( byte ) 'E', ( byte ) 'L', ( byte ) 'F' };
private static readonly byte[] SceMagic = { ( byte ) 'S', ( byte ) 'C', ( byte ) 'E', 0x00 };

public static string InEbootPath { get; private set; }

Expand Down Expand Up @@ -149,7 +148,7 @@ static bool TryParseArguments( string[] args )
case "FilterByName":
if ( i + 1 == args.Length )
{
Console.WriteLine( "Missing argument for option FilterByHash" );
Console.WriteLine( "Missing argument for option FilterByName" );
return false;
}

Expand Down Expand Up @@ -273,15 +272,16 @@ static bool TryGetBaseOffsetFromElfFile( string path, out int baseOffset )
}
else
{
var firstCodeSection = elf.GetSections<Section<ulong>>().FirstOrDefault( x => x.Type == SectionType.ProgBits );
if ( firstCodeSection == null )
var firstExecSegment = elf.Segments.FirstOrDefault( x => x.Flags.HasFlag( SegmentFlags.Execute ) );

if ( firstExecSegment == null )
{
Console.WriteLine( "Invalid ELF. No code (ProgBits) section found." );
Console.WriteLine( "Invalid ELF. No executable segment found." );
return false;
}
else
{
baseOffset = ( int )( firstCodeSection.LoadAddress - firstCodeSection.Offset );
baseOffset = ( int )( firstExecSegment.Address - (ulong)firstExecSegment.Offset );
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ static PatchYamlParseResult ParsePatchYaml()
continue;

// read patch unit
if ( TryParsePatchUnits( yamlMapEntry, patchUnitMap, out var parsedPatchUnits ) )
if ( TryParsePatchUnits( yamlMapEntry, patchUnitMap, out var parsedPatchUnits ) && parsedPatchUnits[0] != null )
{
if ( PPUHashString != null )
patchUnitMap[parsedPatchUnits[0].Name] = parsedPatchUnits[0];
Expand Down Expand Up @@ -480,7 +480,7 @@ static bool TryApplyPatchUnitsToEBOOT( int ebootBaseOffset, List<PatchUnit> patc

foreach ( var patch in patchUnit.Patches )
{
outFileStream.Position = ( patch.Offset - ebootBaseOffset );
outFileStream.Position = patch.Offset - (uint)ebootBaseOffset;
var valueStr = Math.Truncate((double)patch.Value) == patch.Value ? ((ulong)patch.Value).ToString("X8") : patch.Value.ToString();
Console.WriteLine( $"{outFileStream.Position:X8} -> {valueStr} ({patch.Type})" );

Expand Down
21 changes: 8 additions & 13 deletions Source/RPCS3PatchEboot/RPCS3PatchEboot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ELFSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22f480d29a3ced83, processorArchitecture=MSIL">
<HintPath>..\packages\ELFSharp.1.0.4\lib\net40\ELFSharp.dll</HintPath>
</Reference>
<Reference Include="MiscUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3c42c4bfacf7596, processorArchitecture=MSIL">
<HintPath>..\packages\JonSkeet.MiscUtil.0.1\lib\net35-Client\MiscUtil.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="YamlDotNet, Version=4.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.4.2.2\lib\net35\YamlDotNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patch.cs" />
Expand All @@ -63,7 +51,14 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ELFSharp">
<Version>1.0.4</Version>
</PackageReference>
<PackageReference Include="YamlDotNet">
<Version>5.0.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
7 changes: 0 additions & 7 deletions Source/RPCS3PatchEboot/packages.config

This file was deleted.

0 comments on commit 15fcc4e

Please sign in to comment.