Add import libary enumaration routine.


git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@4308 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/crt/pesect.c b/mingw-w64-crt/crt/pesect.c
index d4d6571..22ed6e4 100644
--- a/mingw-w64-crt/crt/pesect.c
+++ b/mingw-w64-crt/crt/pesect.c
@@ -184,3 +184,44 @@
     return FALSE;
   return (pSection->Characteristics & IMAGE_SCN_MEM_WRITE) == 0;
 }
+
+const char *
+__mingw_enum_import_library_names (int i)
+{
+  PBYTE pImageBase;
+  PIMAGE_NT_HEADERS pNTHeader;
+  PIMAGE_IMPORT_DESCRIPTOR importDesc;
+  PIMAGE_SECTION_HEADER pSection;
+  DWORD importsStartRVA;
+
+  pImageBase = (PBYTE) &__ImageBase;
+  if (! _ValidateImageBase (pImageBase))
+    return NULL;
+
+  pNTHeader = (PIMAGE_NT_HEADERS) (pImageBase + ((PIMAGE_DOS_HEADER) pImageBase)->e_lfanew);
+  
+  importsStartRVA = pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
+  if (!importsStartRVA)
+    return NULL;
+
+  pSection = _FindPESection (pImageBase, importsStartRVA);
+  if (!pSection)
+      return NULL;
+
+  importDesc = (PIMAGE_IMPORT_DESCRIPTOR) (pImageBase + importsStartRVA);
+  if (!importDesc)
+    return NULL;
+            
+  for (;;)
+    {
+      if (importDesc->TimeDateStamp == 0 && importDesc->Name == 0)
+        break;
+
+      if (i <= 0)
+      	return (char *) (pImageBase + importDesc->Name));
+      --i;
+      importDesc++;
+    }
+
+  return NULL;
+}