diff --git a/patches/Fixed the getting of names and look-up entries of DLL imports.patch b/patches/Fixed the getting of names and look-up entries of DLL imports.patch new file mode 100644 index 00000000..08e317e9 --- /dev/null +++ b/patches/Fixed the getting of names and look-up entries of DLL imports.patch @@ -0,0 +1,36 @@ +From 03423a19f71a0d7d30ca26b1d3b0bfbf7d58c6e1 Mon Sep 17 00:00:00 2001 +From: Dimitar Dobrev +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 +--- + 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(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(IntPtr); + return object_error::success; +-- +1.9.0.msysgit.0 + diff --git a/src/AST/SymbolContext.cs b/src/AST/SymbolContext.cs index 21b9f79d..dccbeaf1 100644 --- a/src/AST/SymbolContext.cs +++ b/src/AST/SymbolContext.cs @@ -16,6 +16,7 @@ namespace CppSharp.AST public NativeLibrary() { Symbols = new List(); + Dependencies = new List(); } /// @@ -27,6 +28,8 @@ namespace CppSharp.AST /// Symbols gathered from the library. /// public IList Symbols; + + public IList Dependencies { get; private set; } } public class SymbolContext diff --git a/src/Core/Parser/Parser.cs b/src/Core/Parser/Parser.cs index 2fdcd34c..30869813 100644 --- a/src/Core/Parser/Parser.cs +++ b/src/Core/Parser/Parser.cs @@ -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 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; } diff --git a/src/CppParser/AST.cpp b/src/CppParser/AST.cpp index 4d6a2dd3..964bbb28 100644 --- a/src/CppParser/AST.cpp +++ b/src/CppParser/AST.cpp @@ -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) diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index 687c2dcf..98a7024c 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -798,6 +798,7 @@ struct CS_API NativeLibrary { STRING(FileName) VECTOR_STRING(Symbols) + VECTOR_STRING(Dependencies) }; class CS_API ASTContext diff --git a/src/CppParser/Bindings/CLI/AST.cpp b/src/CppParser/Bindings/CLI/AST.cpp index 1952d82c..2fc066b5 100644 --- a/src/CppParser/Bindings/CLI/AST.cpp +++ b/src/CppParser/Bindings/CLI/AST.cpp @@ -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(__ret); +} + +void CppSharp::Parser::AST::NativeLibrary::addDependencies(System::String^ s) +{ + auto _arg0 = clix::marshalString(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() 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; diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index 9a2d877a..4403ad43 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -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 diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs index 13057930..537c3a57 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/AST.cs @@ -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 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 [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 public NativeLibrary() { - __Instance = Marshal.AllocHGlobal(24); + __Instance = Marshal.AllocHGlobal(36); Internal.ctor_1(__Instance); } @@ -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 return __ret; } } + + public uint DependenciesCount + { + get + { + var __ret = Internal.getDependenciesCount_0(__Instance); + return __ret; + } + } } public unsafe partial class ASTContext : IDisposable diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs index f76f3bc3..6fc55c58 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/AST.cs @@ -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 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 [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 public NativeLibrary() { - __Instance = Marshal.AllocHGlobal(36); + __Instance = Marshal.AllocHGlobal(48); Internal.ctor_1(__Instance); } @@ -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 return __ret; } } + + public uint DependenciesCount + { + get + { + var __ret = Internal.getDependenciesCount_0(__Instance); + return __ret; + } + } } public unsafe partial class ASTContext : IDisposable diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs index 0fca2a83..c659e861 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/AST.cs @@ -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 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 [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 public NativeLibrary() { - __Instance = Marshal.AllocHGlobal(32); + __Instance = Marshal.AllocHGlobal(56); Internal.ctor_2(__Instance); } @@ -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 return __ret; } } + + public uint DependenciesCount + { + get + { + var __ret = Internal.getDependenciesCount_0(__Instance); + return __ret; + } + } } public unsafe partial class ASTContext : IDisposable diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index db7ed353..eadfb864 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -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, 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, } if (auto ObjectFile = llvm::dyn_cast(Bin.get())) { - res->Kind = ParseObjectFile(File, ObjectFile, res->Library); + res->Kind = ParseSharedLib(File, ObjectFile, res->Library); if (res->Kind == ParserResultKind::Success) return res; }