Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: SARGE553413 en 16 Julio 2014, 12:07 pm



Título: Problema: .dll sin .h ni .lib en c++/cli
Publicado por: SARGE553413 en 16 Julio 2014, 12:07 pm
Hola a todos.

Tengo que desarrollar un programa para controlar una cámara que se comunica con el PC mediante un puerto FrameLink. Para ello la cámara trae un .dll para poder trabajar con este puerto. Sin embargo no trae ni .h, ni .lib, ni documentación ni nada.

Mi pregunta es primero, como poder usarla desde un proyecto de c++/cli en visual studio.

Saludos.


PD. : La otra pregunta es si dentro del .dll puede haber algo que me ayude a saber que métodos hay y como usarlos


Título: Re: Problema: .dll sin .h ni .lib en c++/cli
Publicado por: Eleкtro en 16 Julio 2014, 13:44 pm
Hola

Mi experiencia con C++ es practicamente nula, pero creo que te puedo ayudar un poco, dentro de lo que cabe.

como poder usarla desde un proyecto de c++/cli en visual studio.

Parece que sin el ".lib" es complicado, pero posible:
· http://stackoverflow.com/questions/495795/how-do-i-use-a-third-party-dll-in-visual-studio-c

La otra pregunta es si dentro del .dll puede haber algo que me ayude a saber que métodos hay y como usarlos

Aquí tienes una solución en C# P/Invokeando la librería DbgHelp.dll para enumerar los símbolos, está genial :)

Cita de: http://stackoverflow.com/questions/18249566/c-sharp-get-the-list-of-unmanaged-c-dll-exports
Código
  1. [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  2. [return: MarshalAs(UnmanagedType.Bool)]
  3. public static extern bool SymInitialize(IntPtr hProcess, string UserSearchPath, [MarshalAs(UnmanagedType.Bool)]bool fInvadeProcess);
  4.  
  5. [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  6. [return: MarshalAs(UnmanagedType.Bool)]
  7. public static extern bool SymCleanup(IntPtr hProcess);
  8.  
  9. [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  10. public static extern ulong SymLoadModuleEx(IntPtr hProcess, IntPtr hFile,
  11.     string ImageName, string ModuleName, long BaseOfDll, int DllSize, IntPtr Data, int Flags);
  12.  
  13. [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
  14. [return: MarshalAs(UnmanagedType.Bool)]
  15. public static extern bool SymEnumerateSymbols64(IntPtr hProcess,
  16.   ulong BaseOfDll, SymEnumerateSymbolsProc64 EnumSymbolsCallback, IntPtr UserContext);
  17.  
  18. public delegate bool SymEnumerateSymbolsProc64(string SymbolName,
  19.      ulong SymbolAddress, uint SymbolSize, IntPtr UserContext);
  20.  
  21. public static bool EnumSyms(string name, ulong address, uint size, IntPtr context)
  22. {
  23.  Console.Out.WriteLine(name);
  24.  return true;
  25. }    
  26.  
  27. static void Main(string[] args)
  28. {
  29.  IntPtr hCurrentProcess = Process.GetCurrentProcess().Handle;
  30.  
  31.  ulong baseOfDll;
  32.  bool status;
  33.  
  34.  // Initialize sym.
  35.  // Please read the remarks on MSDN for the hProcess
  36.  // parameter.
  37.  status = SymInitialize(hCurrentProcess, null, false);
  38.  
  39.  if (status == false)
  40.  {
  41.    Console.Out.WriteLine("Failed to initialize sym.");
  42.    return;
  43.  }
  44.  
  45.  // Load dll.
  46.  baseOfDll = SymLoadModuleEx(hCurrentProcess,
  47.                              IntPtr.Zero,
  48.                              "c:\\windows\\system32\\user32.dll",
  49.                              null,
  50.                              0,
  51.                              0,
  52.                              IntPtr.Zero,
  53.                              0);
  54.  
  55.  if (baseOfDll == 0)
  56.  {
  57.    Console.Out.WriteLine("Failed to load module.");
  58.    SymCleanup(hCurrentProcess);
  59.    return;
  60.  }
  61.  
  62.  // Enumerate symbols. For every symbol the
  63.  // callback method EnumSyms is called.
  64.  if (SymEnumerateSymbols64(hCurrentProcess,
  65.      BaseOfDll, EnumSyms, IntPtr.Zero) == false)
  66.  {
  67.    Console.Out.WriteLine("Failed to enum symbols.");
  68.  }
  69.  
  70.  // Cleanup.
  71.  SymCleanup(hCurrentProcess);
  72. }

Y aquí el resto de funciones que puedes usar en caso d enecesidad:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms679291%28v=vs.85%29.aspx

Y, por si fuera poco, con la GUI de DLL Export Viewer (http://www.nirsoft.net/utils/dll_export_viewer.html) de Nirsoft puedes obtener tanto los nombres como las direcciones y otra info.

(http://www.nirsoft.net/utils/dllexp.gif)

Saludos


Título: Re: Problema: .dll sin .h ni .lib en c++/cli
Publicado por: SARGE553413 en 17 Julio 2014, 14:39 pm
Muchas gracias, una respuesta muy completa.

Saludos.