Skip to content

Commit

Permalink
Implemented the working with export functions from PE files. As part of
Browse files Browse the repository at this point in the history
#3 features

+ILoader.ExportFunctionNames
  • Loading branch information
3F committed Aug 16, 2016
1 parent 78c5ed4 commit 5500110
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Conari/Conari.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Core\IConfig.cs" />
<Compile Include="Core\Dynamic.cs" />
<Compile Include="Core\ProviderDLR.cs" />
<Compile Include="Exceptions\PECorruptDataException.cs" />
<Compile Include="Extensions\IntPtrExtension.cs" />
<Compile Include="IConari.cs" />
<Compile Include="Core\IBinder.cs" />
Expand All @@ -75,6 +76,9 @@
<Compile Include="Native\Core\BType.cs" />
<Compile Include="Native\Core\Raw.cs" />
<Compile Include="Native\NativeData.cs" />
<Compile Include="PE\Hole\ExportFunctions.cs" />
<Compile Include="PE\WinNT\IMAGE_EXPORT_DIRECTORY.cs" />
<Compile Include="PE\WinNT\IMAGE_SECTION_HEADER.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Types\Action\Ref\ActionRef.cs" />
<Compile Include="Types\Action\Out\ActionOut.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Conari/Core/ILoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public interface ILoader
/// Active library.
/// </summary>
Link Library { get; }

/// <summary>
/// Gets names of all available export functions from current library.
/// </summary>
string[] ExportFunctionNames { get; }
}
}
18 changes: 18 additions & 0 deletions Conari/Core/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

using System;
using net.r_eg.Conari.Exceptions;
using net.r_eg.Conari.PE.Hole;
using net.r_eg.Conari.WinAPI;

namespace net.r_eg.Conari.Core
Expand Down Expand Up @@ -54,6 +55,21 @@ public Link Library
protected set;
}

/// <summary>
/// Gets names of all available export functions from current library.
/// </summary>
public string[] ExportFunctionNames
{
get
{
if(_exportFuncNames == null) {
_exportFuncNames = ExportFunctions.GetNames(Library.LibName);
}
return _exportFuncNames;
}
}
private string[] _exportFuncNames;

/// <summary>
/// Loads library into the address space.
/// </summary>
Expand All @@ -75,6 +91,8 @@ protected bool load(string lib)
throw new LoadLibException($"Failed loading '{Library.LibName}': Check used architecture or existence of file.", true);
}

_exportFuncNames = null; // to update export list

AfterLoad(this, new DataArgs<Link>(Library));
return true;
}
Expand Down
44 changes: 44 additions & 0 deletions Conari/Exceptions/PECorruptDataException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Denis Kuzmin <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace net.r_eg.Conari.Exceptions
{
[Serializable]
public class PECorruptDataException: CommonException
{
public PECorruptDataException(string message)
: base(message)
{

}

public PECorruptDataException()
: this("Incorrect or damaged PE-format.")
{

}
}
}
Loading

0 comments on commit 5500110

Please sign in to comment.