elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  GetMethod en VB6? y CreateObject(...) mediante API?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: GetMethod en VB6? y CreateObject(...) mediante API?  (Leído 3,799 veces)
EddyW

Desconectado Desconectado

Mensajes: 187



Ver Perfil WWW
GetMethod en VB6? y CreateObject(...) mediante API?
« en: 11 Noviembre 2010, 16:30 pm »

Wenas,

Tengo una duda, programando en FreeBasic me fije que no hay CreateObject como en VB6, es decir no se pueden cargar objetos mediante código, como podría hacerse desde la API? (En VB6 o en FreeBasic)

En VB.Net es posible enumerar los métodos de una Dll, he intentando hacerlo desde VB6 pero no hallo modo, alguna idea?

SaluDOS!!!


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: GetMethod en VB6? y CreateObject(...) mediante API?
« Respuesta #1 en: 11 Noviembre 2010, 19:23 pm »

.
Se maneja igual que CreateObject()

Código
  1.  
  2. Option Explicit
  3.  
  4. '[rm_code]
  5. 'CodeId=64499
  6. Private Declare Function CallWindowProc Lib "user32" _
  7. Alias "CallWindowProcA" ( _
  8.    ByVal adr As Long, _
  9.    ByVal p1 As Long, _
  10.    ByVal p2 As Long, _
  11.    ByVal p3 As Long, _
  12.    ByVal p4 As Long _
  13. ) As Long
  14.  
  15. Private Declare Function LoadLibrary Lib "kernel32" _
  16. Alias "LoadLibraryA" ( _
  17.    ByVal szLib As String _
  18. ) As Long
  19.  
  20. Private Declare Function GetProcAddress Lib "kernel32" ( _
  21.    ByVal hModule As Long, _
  22.    ByVal szFnc As String _
  23. ) As Long
  24.  
  25. Private Declare Function GetModuleHandle Lib "kernel32" _
  26. Alias "GetModuleHandleA" ( _
  27.    ByVal szModule As String _
  28. ) As Long
  29.  
  30. Private Declare Function LoadTypeLibEx Lib "oleaut32" ( _
  31.    ByVal szFile As Long, _
  32.    ByVal REGKIND As Long, _
  33.    pptlib As Any _
  34. ) As Long
  35.  
  36. Private Declare Function StringFromGUID2 Lib "ole32" ( _
  37.    tGuid As Any, _
  38.    ByVal lpszString As String, _
  39.    ByVal lMax As Long _
  40. ) As Long
  41.  
  42. Private Declare Sub CpyMem Lib "kernel32" _
  43. Alias "RtlMoveMemory" ( _
  44.    pDst As Any, _
  45.    pSrc As Any, _
  46.    ByVal dlen As Long _
  47. )
  48.  
  49. Private Type IUnknown
  50.    QueryInterface          As Long
  51.    AddRef                  As Long
  52.    Release                 As Long
  53. End Type
  54.  
  55. Private Type IClassFactory
  56.    IUnk                    As IUnknown
  57.    CreateInstance          As Long
  58.    Lock                    As Long
  59. End Type
  60.  
  61. Private Type ITypeInfo
  62.    IUnk                    As IUnknown
  63.    GetTypeAttr             As Long
  64.    GetTypeComp             As Long
  65.    GetFuncDesc             As Long
  66.    GetVarDesc              As Long
  67.    GetNames                As Long
  68.    GetRefTypeOfImplType    As Long
  69.    GetImplTypeFlags        As Long
  70.    GetIDsOfNames           As Long
  71.    Invoke                  As Long
  72.    GetDocumentation        As Long
  73.    GetDllEntry             As Long
  74.    GetRefTypeInfo          As Long
  75.    AddressOfMember         As Long
  76.    CreateInstance          As Long
  77.    GetMops                 As Long
  78.    GetContainingTypeLib    As Long
  79.    ReleaseTypeAttr         As Long
  80.    ReleaseFuncDesc         As Long
  81.    ReleaseVarDesc          As Long
  82. End Type
  83.  
  84. Private Type ITypeLib
  85.    IUnk                    As IUnknown
  86.    GetTypeInfoCount        As Long
  87.    GetTypeInfo             As Long
  88.    GetTypeInfoType         As Long
  89.    GetTypeInfoOfGuid       As Long
  90.    GetLibAttr              As Long
  91.    GetTypeComp             As Long
  92.    GetDocumentation        As Long
  93.    IsName                  As Long
  94.    FindName                As Long
  95.    ReleaseTLibAttr         As Long
  96. End Type
  97.  
  98. Private Type TYPEATTR
  99.    guid(15)                As Byte
  100.    lcid                    As Long
  101.    dwReserved              As Long
  102.    memidConstructor        As Long
  103.    memidDestructor         As Long
  104.    pstrSchema              As Long
  105.    cbSizeInstance          As Long
  106.    TYPEKIND                As Long
  107.    cFuncs                  As Integer
  108.    cVars                   As Integer
  109.    cImplTypes              As Integer
  110.    cbSizeVft               As Integer
  111.    cbAlignment             As Integer
  112.    wTypeFlags              As Integer
  113.    wMajorVerNum            As Integer
  114.    wMinorVerNum            As Integer
  115.    tdescAlias              As Long
  116.    idldescType             As Long
  117. End Type
  118.  
  119. Private Enum TYPEKIND
  120.    TKIND_ENUM
  121.    TKIND_RECORD
  122.    TKIND_MODULE
  123.    TKIND_INTERFACE
  124.    TKIND_DISPATCH
  125.    TKIND_COCLASS
  126.    TKIND_ALIAS
  127.    TKIND_UNION
  128.    TKIND_MAX
  129. End Enum
  130.  
  131. Private Enum HRESULT
  132.    S_OK = 0
  133. End Enum
  134.  
  135. Private Type CoClass
  136.    Name                As String
  137.    guid()              As Byte
  138. End Type
  139.  
  140. Private Type guid
  141.    data1               As Long
  142.    data2               As Integer
  143.    data3               As Integer
  144.    data4(7)            As Byte
  145. End Type
  146.  
  147. Private Enum REGKIND
  148.    REGKIND_DEFAULT
  149.    REGKIND_REGISTER
  150.    REGKIND_NONE
  151. End Enum
  152.  
  153. Public Function CreateObjectFromFile( _
  154.    ByVal strLibrary As String, _
  155.    ByVal strClassName As String _
  156. ) As stdole.IUnknown
  157.  
  158.    Dim newobj              As stdole.IUnknown
  159.    Dim udtCF               As IClassFactory
  160.  
  161.    Dim classid             As guid
  162.    Dim IID_ClassFactory    As guid
  163.    Dim IID_IUnknown        As guid
  164.    Dim lib                 As String
  165.  
  166.    Dim obj                 As Long
  167.    Dim vtbl                As Long
  168.  
  169.    Dim hModule             As Long
  170.    Dim pFunc               As Long
  171.    Dim udtCoCls()          As CoClass
  172.  
  173.    Dim i                   As Long
  174.  
  175.    With IID_ClassFactory
  176.        .data1 = &H1
  177.        .data4(0) = &HC0
  178.        .data4(7) = &H46
  179.    End With
  180.  
  181.    With IID_IUnknown
  182.        .data4(0) = &HC0
  183.        .data4(7) = &H46
  184.    End With
  185.  
  186.    ' get all CoClasses from the type lib of
  187.    ' the file, and find the GUID of the Prog ID
  188.    If Not GetCoClasses(strLibrary, udtCoCls) Then
  189.        Exit Function
  190.    End If
  191.  
  192.    For i = 0 To UBound(udtCoCls)
  193.        If StrComp(udtCoCls(i).Name, strClassName, vbTextCompare) = 0 Then
  194.            CpyMem classid, udtCoCls(i).guid(0), Len(classid)
  195.            Exit For
  196.        End If
  197.    Next
  198.  
  199.    If i = UBound(udtCoCls) + 1 Then
  200.        Exit Function
  201.    End If
  202.  
  203.    ' load the file, if it isn't yet
  204.    hModule = GetModuleHandle(strLibrary)
  205.    If hModule = 0 Then
  206.        hModule = LoadLibrary(strLibrary)
  207.        If hModule = 0 Then Exit Function
  208.    End If
  209.  
  210.    pFunc = GetProcAddress(hModule, "DllGetClassObject")
  211.    If pFunc = 0 Then Exit Function
  212.  
  213.    ' call DllGetClassObject to get a
  214.    ' class factory for the class ID
  215.    If 0 <> CallPointer(pFunc, _
  216.                        VarPtr(classid), _
  217.                        VarPtr(IID_ClassFactory), _
  218.                        VarPtr(obj)) Then
  219.  
  220.        Exit Function
  221.    End If
  222.  
  223.    ' IClassFactory VTable
  224.    CpyMem vtbl, ByVal obj, 4
  225.    CpyMem udtCF, ByVal vtbl, Len(udtCF)
  226.  
  227.    ' create an instance of the object
  228.    If 0 <> CallPointer(udtCF.CreateInstance, _
  229.                        obj, _
  230.                        0, _
  231.                        VarPtr(IID_IUnknown), _
  232.                        VarPtr(newobj)) Then
  233.  
  234.        ' Set IClassFactory = Nothing
  235.        CallPointer udtCF.IUnk.Release, obj
  236.        Exit Function
  237.    End If
  238.  
  239.    ' Set IClassFactory = Nothing
  240.    CallPointer udtCF.IUnk.Release, obj
  241.  
  242.    Set CreateObjectFromFile = newobj
  243. End Function
  244.  
  245. Private Function GetCoClasses( _
  246.    ByVal strFile As String, _
  247.    udtCoClasses() As CoClass _
  248. ) As Boolean
  249.  
  250.    Dim hRes            As HRESULT
  251.  
  252.    Dim udtITypeLib     As ITypeLib
  253.    Dim udtITypeInfo    As ITypeInfo
  254.    Dim udtTypeAttr     As TYPEATTR
  255.  
  256.    Dim oTypeLib        As Long
  257.    Dim oTypeInfo       As Long
  258.    Dim pVTbl           As Long
  259.    Dim pAttr           As Long
  260.  
  261.    Dim lngTypeInfos    As Long
  262.    Dim lngCoCls        As Long
  263.    Dim strTypeName     As String
  264.  
  265.    Dim i               As Long
  266.  
  267.    ' load the type lib of the file
  268.    hRes = LoadTypeLibEx(StrPtr(strFile), REGKIND_NONE, oTypeLib)
  269.    If hRes <> S_OK Then Exit Function
  270.  
  271.    ' ITypeLib's VTable
  272.    CpyMem pVTbl, ByVal oTypeLib, 4
  273.    CpyMem udtITypeLib, ByVal pVTbl, Len(udtITypeLib)
  274.  
  275.    lngTypeInfos = CallPointer(udtITypeLib.GetTypeInfoCount, oTypeLib)
  276.  
  277.    For i = 0 To lngTypeInfos - 1
  278.  
  279.        hRes = CallPointer(udtITypeLib.GetTypeInfo, _
  280.                           oTypeLib, i, _
  281.                           VarPtr(oTypeInfo))
  282.  
  283.        If hRes <> S_OK Then GoTo NextItem
  284.  
  285.        ' ITypeInfo's VTable
  286.        CpyMem pVTbl, ByVal oTypeInfo, 4
  287.        CpyMem udtITypeInfo, ByVal pVTbl, Len(udtITypeInfo)
  288.  
  289.        ' TYPEATTR struct, which describes the type
  290.        CallPointer udtITypeInfo.GetTypeAttr, oTypeInfo, VarPtr(pAttr)
  291.        CpyMem udtTypeAttr, ByVal pAttr, Len(udtTypeAttr)
  292.        CallPointer udtITypeInfo.ReleaseTypeAttr, oTypeInfo, pAttr
  293.  
  294.        ' name of the type
  295.        CallPointer udtITypeLib.GetDocumentation, _
  296.                    oTypeLib, i, _
  297.                    VarPtr(strTypeName), _
  298.                    0, 0, 0
  299.  
  300.        If udtTypeAttr.TYPEKIND = TKIND_COCLASS Then
  301.            ReDim Preserve udtCoClasses(lngCoCls) As CoClass
  302.  
  303.            With udtCoClasses(lngCoCls)
  304.                .guid = udtTypeAttr.guid
  305.                .Name = strTypeName
  306.            End With
  307.  
  308.            lngCoCls = lngCoCls + 1
  309.        End If
  310.  
  311.        ' Set ITypeInfo = Nothing
  312.        CallPointer udtITypeInfo.IUnk.Release, oTypeInfo
  313.        oTypeInfo = 0
  314.  
  315. NextItem:
  316.    Next
  317.  
  318.    ' Set ITypeLib = Nothing
  319.    CallPointer udtITypeLib.IUnk.Release, oTypeLib
  320.    '
  321.    GetCoClasses = True
  322. End Function
  323.  
  324. Private Function CallPointer( _
  325.    ByVal fnc As Long, _
  326.    ParamArray params() _
  327. ) As Long
  328.  
  329.    Dim btASM(&HEC00& - 1)  As Byte
  330.    Dim pASM                As Long
  331.    Dim i                   As Integer
  332.  
  333.    pASM = VarPtr(btASM(0))
  334.  
  335.    AddByte pASM, &H58                  ' POP EAX
  336.    AddByte pASM, &H59                  ' POP ECX
  337.    AddByte pASM, &H59                  ' POP ECX
  338.    AddByte pASM, &H59                  ' POP ECX
  339.    AddByte pASM, &H59                  ' POP ECX
  340.    AddByte pASM, &H50                  ' PUSH EAX
  341.  
  342.    For i = UBound(params) To 0 Step -1
  343.        AddPush pASM, CLng(params(i))   ' PUSH dword
  344.    Next
  345.  
  346.    AddCall pASM, fnc                   ' CALL rel addr
  347.    AddByte pASM, &HC3                  ' RET
  348.  
  349.    CallPointer = CallWindowProc(VarPtr(btASM(0)), _
  350.                                 0, 0, 0, 0)
  351. End Function
  352.  
  353. Private Sub AddPush(pASM As Long, lng As Long)
  354.    AddByte pASM, &H68
  355.    AddLong pASM, lng
  356. End Sub
  357.  
  358. Private Sub AddCall(pASM As Long, addr As Long)
  359.    AddByte pASM, &HE8
  360.    AddLong pASM, addr - pASM - 4
  361. End Sub
  362.  
  363. Private Sub AddLong(pASM As Long, lng As Long)
  364.    CpyMem ByVal pASM, lng, 4
  365.    pASM = pASM + 4
  366. End Sub
  367.  
  368. Private Sub AddByte(pASM As Long, bt As Byte)
  369.    CpyMem ByVal pASM, bt, 1
  370.    pASM = pASM + 1
  371. End Sub
  372.  
  373. ' http://www.aboutvb.de/khw/artikel/khwcreateguid.htm
  374. Private Function GUID2Str( _
  375.    GUIDBytes() As Byte _
  376. ) As String
  377.  
  378.    Dim nTemp       As String
  379.    Dim nGUID(15)   As Byte
  380.    Dim nLength     As Long
  381.  
  382.    nTemp = Space$(78)
  383.    CpyMem nGUID(0), GUIDBytes(0), 16
  384.    nLength = StringFromGUID2(nGUID(0), nTemp, Len(nTemp))
  385.    GUID2Str = Left$(StrConv(nTemp, vbFromUnicode), nLength - 1)
  386. End Function
  387.  
  388.  


En línea

The Dark Shadow is my passion.
EddyW

Desconectado Desconectado

Mensajes: 187



Ver Perfil WWW
Re: GetMethod en VB6? y CreateObject(...) mediante API?
« Respuesta #2 en: 12 Noviembre 2010, 01:05 am »

Wenas,

Gracias por la ayuda, me sirvió el código para encontrar lo que buscaba exactamente :P
Gracias!

SaluDOS!!!
PD: Solucionado (las 2 dudas :P)
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines