Browse Source

Merge pull request #298 from ddobrev/master

Added reading of dependencies of DLL-s
pull/299/head
João Matos 12 years ago
parent
commit
26cb4d858f
  1. 36
      patches/Fixed the getting of names and look-up entries of DLL imports.patch
  2. 3
      src/AST/SymbolContext.cs
  3. 5
      src/Core/Parser/Parser.cs
  4. 1
      src/CppParser/AST.cpp
  5. 1
      src/CppParser/AST.h
  6. 25
      src/CppParser/Bindings/CLI/AST.cpp
  7. 11
      src/CppParser/Bindings/CLI/AST.h
  8. 52
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs
  9. 52
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs
  10. 52
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs
  11. 10
      src/CppParser/Parser.cpp

36
patches/Fixed the getting of names and look-up entries of DLL imports.patch

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
From 03423a19f71a0d7d30ca26b1d3b0bfbf7d58c6e1 Mon Sep 17 00:00:00 2001
From: Dimitar Dobrev <dpldobrev@yahoo.com>
Date: Wed, 30 Jul 2014 21:22:39 +0300
Subject: [PATCH] Fixed the getting of names and look-up entries of DLL
imports.
Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
---
lib/Object/COFFObjectFile.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp
index 46ef87d..9b5e954 100644
--- a/lib/Object/COFFObjectFile.cpp
+++ b/lib/Object/COFFObjectFile.cpp
@@ -1022,7 +1022,7 @@ std::error_code ImportDirectoryEntryRef::getImportTableEntry(
std::error_code ImportDirectoryEntryRef::getName(StringRef &Result) const {
uintptr_t IntPtr = 0;
if (std::error_code EC =
- OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr))
+ OwningObject->getRvaPtr((ImportTable + Index)->NameRVA, IntPtr))
return EC;
Result = StringRef(reinterpret_cast<const char *>(IntPtr));
return object_error::success;
@@ -1032,7 +1032,7 @@ std::error_code ImportDirectoryEntryRef::getImportLookupEntry(
const import_lookup_table_entry32 *&Result) const {
uintptr_t IntPtr = 0;
if (std::error_code EC =
- OwningObject->getRvaPtr(ImportTable->ImportLookupTableRVA, IntPtr))
+ OwningObject->getRvaPtr((ImportTable + Index)->ImportLookupTableRVA, IntPtr))
return EC;
Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr);
return object_error::success;
--
1.9.0.msysgit.0

3
src/AST/SymbolContext.cs

@ -16,6 +16,7 @@ namespace CppSharp.AST @@ -16,6 +16,7 @@ namespace CppSharp.AST
public NativeLibrary()
{
Symbols = new List<string>();
Dependencies = new List<string>();
}
/// <summary>
@ -27,6 +28,8 @@ namespace CppSharp.AST @@ -27,6 +28,8 @@ namespace CppSharp.AST
/// Symbols gathered from the library.
/// </summary>
public IList<string> Symbols;
public IList<string> Dependencies { get; private set; }
}
public class SymbolContext

5
src/Core/Parser/Parser.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using CppSharp.AST;
using CppSharp.Parser;
using ASTContext = CppSharp.Parser.AST.ASTContext;
@ -103,6 +104,10 @@ namespace CppSharp @@ -103,6 +104,10 @@ namespace CppSharp
var symbol = library.getSymbols(i);
newLibrary.Symbols.Add(symbol);
}
for (uint i = 0; i < library.DependenciesCount; i++)
{
newLibrary.Dependencies.Add(library.getDependencies(i));
}
return newLibrary;
}

1
src/CppParser/AST.cpp

@ -581,6 +581,7 @@ DEF_VECTOR(TranslationUnit, MacroDefinition*, Macros) @@ -581,6 +581,7 @@ DEF_VECTOR(TranslationUnit, MacroDefinition*, Macros)
// NativeLibrary
DEF_STRING(NativeLibrary, FileName)
DEF_VECTOR_STRING(NativeLibrary, Symbols)
DEF_VECTOR_STRING(NativeLibrary, Dependencies)
// ASTContext
DEF_VECTOR(ASTContext, TranslationUnit*, TranslationUnits)

1
src/CppParser/AST.h

@ -798,6 +798,7 @@ struct CS_API NativeLibrary @@ -798,6 +798,7 @@ struct CS_API NativeLibrary
{
STRING(FileName)
VECTOR_STRING(Symbols)
VECTOR_STRING(Dependencies)
};
class CS_API ASTContext

25
src/CppParser/Bindings/CLI/AST.cpp

@ -2959,6 +2959,25 @@ void CppSharp::Parser::AST::NativeLibrary::clearSymbols() @@ -2959,6 +2959,25 @@ void CppSharp::Parser::AST::NativeLibrary::clearSymbols()
((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->clearSymbols();
}
System::String^ CppSharp::Parser::AST::NativeLibrary::getDependencies(unsigned int i)
{
auto __ret = ((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->getDependencies(i);
if (__ret == nullptr) return nullptr;
return clix::marshalString<clix::E_UTF8>(__ret);
}
void CppSharp::Parser::AST::NativeLibrary::addDependencies(System::String^ s)
{
auto _arg0 = clix::marshalString<clix::E_UTF8>(s);
auto arg0 = _arg0.c_str();
((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->addDependencies(arg0);
}
void CppSharp::Parser::AST::NativeLibrary::clearDependencies()
{
((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->clearDependencies();
}
CppSharp::Parser::AST::NativeLibrary::NativeLibrary()
{
NativePtr = new ::CppSharp::CppParser::AST::NativeLibrary();
@ -2994,6 +3013,12 @@ unsigned int CppSharp::Parser::AST::NativeLibrary::SymbolsCount::get() @@ -2994,6 +3013,12 @@ unsigned int CppSharp::Parser::AST::NativeLibrary::SymbolsCount::get()
return __ret;
}
unsigned int CppSharp::Parser::AST::NativeLibrary::DependenciesCount::get()
{
auto __ret = ((::CppSharp::CppParser::AST::NativeLibrary*)NativePtr)->getDependenciesCount();
return __ret;
}
CppSharp::Parser::AST::ASTContext::ASTContext(::CppSharp::CppParser::AST::ASTContext* native)
{
NativePtr = native;

11
src/CppParser/Bindings/CLI/AST.h

@ -1956,11 +1956,22 @@ namespace CppSharp @@ -1956,11 +1956,22 @@ namespace CppSharp
unsigned int get();
}
property unsigned int DependenciesCount
{
unsigned int get();
}
System::String^ getSymbols(unsigned int i);
void addSymbols(System::String^ s);
void clearSymbols();
System::String^ getDependencies(unsigned int i);
void addDependencies(System::String^ s);
void clearDependencies();
};
public ref class ASTContext : ICppInstance

52
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs

@ -7255,7 +7255,7 @@ namespace CppSharp @@ -7255,7 +7255,7 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
[StructLayout(LayoutKind.Explicit, Size = 36)]
public partial struct Internal
{
[SuppressUnmanagedCodeSecurity]
@ -7288,6 +7288,21 @@ namespace CppSharp @@ -7288,6 +7288,21 @@ namespace CppSharp
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary12clearSymbolsEv")]
internal static extern void clearSymbols_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15getDependenciesEj")]
internal static extern global::System.IntPtr getDependencies_0(global::System.IntPtr instance, uint i);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15addDependenciesEPKc")]
internal static extern void addDependencies_0(global::System.IntPtr instance, global::System.IntPtr s);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary17clearDependenciesEv")]
internal static extern void clearDependencies_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary11getFileNameEv")]
@ -7302,6 +7317,11 @@ namespace CppSharp @@ -7302,6 +7317,11 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15getSymbolsCountEv")]
internal static extern uint getSymbolsCount_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary20getDependenciesCountEv")]
internal static extern uint getDependenciesCount_0(global::System.IntPtr instance);
}
public global::System.IntPtr __Instance { get; protected set; }
@ -7323,7 +7343,7 @@ namespace CppSharp @@ -7323,7 +7343,7 @@ namespace CppSharp
public NativeLibrary()
{
__Instance = Marshal.AllocHGlobal(24);
__Instance = Marshal.AllocHGlobal(36);
Internal.ctor_1(__Instance);
}
@ -7358,6 +7378,25 @@ namespace CppSharp @@ -7358,6 +7378,25 @@ namespace CppSharp
Internal.clearSymbols_0(__Instance);
}
public string getDependencies(uint i)
{
var __ret = Internal.getDependencies_0(__Instance, i);
if (__ret == global::System.IntPtr.Zero) return null;
return Marshal.PtrToStringAnsi(__ret);
}
public void addDependencies(string s)
{
var arg0 = Marshal.StringToHGlobalAnsi(s);
Internal.addDependencies_0(__Instance, arg0);
Marshal.FreeHGlobal(arg0);
}
public void clearDependencies()
{
Internal.clearDependencies_0(__Instance);
}
public string FileName
{
get
@ -7383,6 +7422,15 @@ namespace CppSharp @@ -7383,6 +7422,15 @@ namespace CppSharp
return __ret;
}
}
public uint DependenciesCount
{
get
{
var __ret = Internal.getDependenciesCount_0(__Instance);
return __ret;
}
}
}
public unsafe partial class ASTContext : IDisposable

52
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs

@ -7255,7 +7255,7 @@ namespace CppSharp @@ -7255,7 +7255,7 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 36)]
[StructLayout(LayoutKind.Explicit, Size = 48)]
public partial struct Internal
{
[SuppressUnmanagedCodeSecurity]
@ -7288,6 +7288,21 @@ namespace CppSharp @@ -7288,6 +7288,21 @@ namespace CppSharp
EntryPoint="?clearSymbols@NativeLibrary@AST@CppParser@CppSharp@@QAEXXZ")]
internal static extern void clearSymbols_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getDependencies@NativeLibrary@AST@CppParser@CppSharp@@QAEPBDI@Z")]
internal static extern global::System.IntPtr getDependencies_0(global::System.IntPtr instance, uint i);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?addDependencies@NativeLibrary@AST@CppParser@CppSharp@@QAEXPBD@Z")]
internal static extern void addDependencies_0(global::System.IntPtr instance, global::System.IntPtr s);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?clearDependencies@NativeLibrary@AST@CppParser@CppSharp@@QAEXXZ")]
internal static extern void clearDependencies_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getFileName@NativeLibrary@AST@CppParser@CppSharp@@QAEPBDXZ")]
@ -7302,6 +7317,11 @@ namespace CppSharp @@ -7302,6 +7317,11 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getSymbolsCount@NativeLibrary@AST@CppParser@CppSharp@@QAEIXZ")]
internal static extern uint getSymbolsCount_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall,
EntryPoint="?getDependenciesCount@NativeLibrary@AST@CppParser@CppSharp@@QAEIXZ")]
internal static extern uint getDependenciesCount_0(global::System.IntPtr instance);
}
public global::System.IntPtr __Instance { get; protected set; }
@ -7323,7 +7343,7 @@ namespace CppSharp @@ -7323,7 +7343,7 @@ namespace CppSharp
public NativeLibrary()
{
__Instance = Marshal.AllocHGlobal(36);
__Instance = Marshal.AllocHGlobal(48);
Internal.ctor_1(__Instance);
}
@ -7358,6 +7378,25 @@ namespace CppSharp @@ -7358,6 +7378,25 @@ namespace CppSharp
Internal.clearSymbols_0(__Instance);
}
public string getDependencies(uint i)
{
var __ret = Internal.getDependencies_0(__Instance, i);
if (__ret == global::System.IntPtr.Zero) return null;
return Marshal.PtrToStringAnsi(__ret);
}
public void addDependencies(string s)
{
var arg0 = Marshal.StringToHGlobalAnsi(s);
Internal.addDependencies_0(__Instance, arg0);
Marshal.FreeHGlobal(arg0);
}
public void clearDependencies()
{
Internal.clearDependencies_0(__Instance);
}
public string FileName
{
get
@ -7383,6 +7422,15 @@ namespace CppSharp @@ -7383,6 +7422,15 @@ namespace CppSharp
return __ret;
}
}
public uint DependenciesCount
{
get
{
var __ret = Internal.getDependenciesCount_0(__Instance);
return __ret;
}
}
}
public unsafe partial class ASTContext : IDisposable

52
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs

@ -7254,7 +7254,7 @@ namespace CppSharp @@ -7254,7 +7254,7 @@ namespace CppSharp
public unsafe partial class NativeLibrary : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 32)]
[StructLayout(LayoutKind.Explicit, Size = 56)]
public partial struct Internal
{
[SuppressUnmanagedCodeSecurity]
@ -7287,6 +7287,21 @@ namespace CppSharp @@ -7287,6 +7287,21 @@ namespace CppSharp
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary12clearSymbolsEv")]
internal static extern void clearSymbols_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15getDependenciesEj")]
internal static extern global::System.IntPtr getDependencies_0(global::System.IntPtr instance, uint i);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15addDependenciesEPKc")]
internal static extern void addDependencies_0(global::System.IntPtr instance, global::System.IntPtr s);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary17clearDependenciesEv")]
internal static extern void clearDependencies_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary11getFileNameEv")]
@ -7301,6 +7316,11 @@ namespace CppSharp @@ -7301,6 +7316,11 @@ namespace CppSharp
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary15getSymbolsCountEv")]
internal static extern uint getSymbolsCount_0(global::System.IntPtr instance);
[SuppressUnmanagedCodeSecurity]
[DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="_ZN8CppSharp9CppParser3AST13NativeLibrary20getDependenciesCountEv")]
internal static extern uint getDependenciesCount_0(global::System.IntPtr instance);
}
public global::System.IntPtr __Instance { get; protected set; }
@ -7322,7 +7342,7 @@ namespace CppSharp @@ -7322,7 +7342,7 @@ namespace CppSharp
public NativeLibrary()
{
__Instance = Marshal.AllocHGlobal(32);
__Instance = Marshal.AllocHGlobal(56);
Internal.ctor_2(__Instance);
}
@ -7357,6 +7377,25 @@ namespace CppSharp @@ -7357,6 +7377,25 @@ namespace CppSharp
Internal.clearSymbols_0(__Instance);
}
public string getDependencies(uint i)
{
var __ret = Internal.getDependencies_0(__Instance, i);
if (__ret == global::System.IntPtr.Zero) return null;
return Marshal.PtrToStringAnsi(__ret);
}
public void addDependencies(string s)
{
var arg0 = Marshal.StringToHGlobalAnsi(s);
Internal.addDependencies_0(__Instance, arg0);
Marshal.FreeHGlobal(arg0);
}
public void clearDependencies()
{
Internal.clearDependencies_0(__Instance);
}
public string FileName
{
get
@ -7382,6 +7421,15 @@ namespace CppSharp @@ -7382,6 +7421,15 @@ namespace CppSharp
return __ret;
}
}
public uint DependenciesCount
{
get
{
var __ret = Internal.getDependenciesCount_0(__Instance);
return __ret;
}
}
}
public unsafe partial class ASTContext : IDisposable

10
src/CppParser/Parser.cpp

@ -3050,7 +3050,7 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File, @@ -3050,7 +3050,7 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File,
for (auto dep = COFFObjectFile->import_directory_begin(); dep != COFFObjectFile->import_directory_end(); ++dep)
{
llvm::StringRef Name;
if (!dep->getName(Name))
if (!dep->getName(Name) && (Name.endswith(".dll") || Name.endswith(".DLL")))
NativeLib->Dependencies.push_back(Name);
}
}
@ -3059,12 +3059,6 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File, @@ -3059,12 +3059,6 @@ ParserResultKind Parser::ParseSharedLib(llvm::StringRef File,
return ParserResultKind::Error;
}
}
/*for (auto dep = ObjectFile->needed_library_begin(); dep != ObjectFile->needed_library_end(); ++dep)
{
llvm::StringRef path;
if (!dep->getPath(path))
NativeLib->Dependencies.push_back(path);
}*/
return ParserResultKind::Success;
}
@ -3139,7 +3133,7 @@ ParserResultKind Parser::ReadSymbols(llvm::StringRef File, @@ -3139,7 +3133,7 @@ ParserResultKind Parser::ReadSymbols(llvm::StringRef File,
}
if (auto ObjectFile = llvm::dyn_cast<llvm::object::ObjectFile>(Bin.get()))
{
res->Kind = ParseObjectFile(File, ObjectFile, res->Library);
res->Kind = ParseSharedLib(File, ObjectFile, res->Library);
if (res->Kind == ParserResultKind::Success)
return res;
}

Loading…
Cancel
Save