All pastes #280842 Raw Edit

Seykron

public text v1 · immutable
#280842 ·published 2006-12-16 05:39 UTC
rendered paste body
Sub Main()
        Dim sLib$, sFunc$
        Dim sCmdLine$
        Dim hLib&
        Dim lProcAddr&
        Dim sMsg$

  'Obtiene la linea de comandos.
  '
  sCmdLine = Command$
 
  If sCmdLine Like vbNullString Then
    sMsg = "Debes ingresar la librería y el nombre de la función:" & vbCrLf & vbCrLf & _
           "USO: FndOffset librería función"

    Call MsgBox(sMsg)
    Exit Sub
  End If
  
  'Obtiene los argumentos desde la linea de comandos.
  '
  sLib = RTrim$(Left$(sCmdLine, InStr(1, sCmdLine, " ")))
  sFunc = Trim$(Mid$(sCmdLine, InStr(1, sCmdLine, " ")))
 
  'Carga la librería en memoria y devuelve
  'la dirección en donde se cargó.
  '
  hLib = LoadLibrary(sLib)
 
  If hLib Then
    'Obtiene el offset relativo (RVA) de la función
    '
    lProcAddr = GetProcAddress(hLib, sFunc)
   
    If lProcAddr Then
      sMsg = "El offset de '" & sFunc & "' en '" & sLib & "' es 0x" & _
            Hex$(lProcAddr) & " (" & lProcAddr & ")"

      Call Clipboard.SetText(sMsg, vbCFText)  'Copia los datos al portapapeles.
      Call MsgBox(sMsg, vbExclamation)
      Call MsgBox("Los datos se copiaron al portapapeles.", vbInformation)
     
    Else
      Call MsgBox("No se encontró la función u ordinal '" & sFunc & "' en '" & sLib & "'", vbCritical)
    End If
   
    'Descarga la librearía de memoria.
    '
    Call FreeLibrary(hLib)
  Else
    Call MsgBox("No se pudo cargar la librería '" & sLib & "'", vbCritical)
  End If
End Sub