Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: msdl en 29 Abril 2012, 15:47 pm



Título: [HELP] How to use & invoke API function "MulDiv"
Publicado por: msdl en 29 Abril 2012, 15:47 pm
Hello..
The Win32 API function MulDiv can be used to get the address of a variable.
It can be used as an alternative for StrPtr/VarPtr/ObjPtr..
I've already managed to use it as a replacement for VarPtr but I couldn't find out how
to use it as StrPtr/ObjPtr!!

example: "Credit's to karcrack"
Código:
Private Declare Function var2ptr Lib "KERNEL32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) as Long
            Dim x   As Long
 
            x = 1337
            MsgBox "Is it working? " & Format$(var2ptr(x) = VarPtr(x), "Yes/No")

I need help to:
1. Use it as replacement for StrPtr/ObjPtr.
2. know how to invoke this API.


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: BlackZeroX en 29 Abril 2012, 21:43 pm
.
MulDiv function (http://msdn.microsoft.com/en-us/library/aa383718(v=vs.85).aspx)

Citar

Multiplies two 32-bit values and then divides the 64-bit result by a third 32-bit value. The final result is rounded to the nearest integer.

Código
  1.  
  2. int MulDiv(
  3.  __in  int nNumber,
  4.  __in  int nNumerator,
  5.  __in  int nDenominator
  6. );
  7.  
  8.  

Parameters
nNumber [in]

The multiplicand.
nNumerator [in]

The multiplier.
nDenominator [in]

The number by which the result of the multiplication operation is to be divided.

Return value

If the function succeeds, the return value is the result of the multiplication and division, rounded to the nearest integer. If the result is a positive half integer (ends in .5), it is rounded up. If the result is a negative half integer, it is rounded down.

If either an overflow occurred or nDenominator was 0, the return value is -1.


Nota: es curioso que funcione para obtener el puntero... ponlo en un proceso X, por lo que veo lo hace con el byref,. es curioso...

Dulces Lunas!¡.


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: x64core en 30 Abril 2012, 06:59 am
deberia ser así, un ejemplo:


Código:
Private Declare Function var2ptr Lib "kernel32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (dest As Any, src As Any, ByVal ln As Long)
Private Declare Function MessageBox Lib "User32" Alias "MessageBoxW" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long


Private Const cadena As String = "texto texto"
 
 
Private Sub Form_Load()
dim x   As Long

call RtlMoveMemory(x, ByVal (var2ptr(cadena) + 4), 4)
MessageBox 0, x, x, 0

 ::)


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: msdl en 30 Abril 2012, 18:16 pm
thanks a lot..
but still i can't figure out how to use at a replacement of ObjPtr
:(


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: Karcrack en 30 Abril 2012, 20:41 pm
If you look at MSVBVM60's export table you'll see there's no functions called StrPtr() or ObjPtr()... Those are just macros of VarPtr()... So in theory you'd be able to replace those macros but sadly is not posible with StrPtr().

You cannot replace StrPtr() because VB6 always create a copy of the string you're passing to an external function... so if you try to pass the string to the MulDiv() func it will recieve a copy of the string, therefore you'll be getting the pointer to a copied string that after the API call will be deleted from memory. Here you got a sample that shows it won't work:
Código
  1. 'KERNEL32
  2. Private Declare Function VarPtr__ Lib "KERNEL32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
  3. 'MSVBVM60
  4. Private Declare Sub GetMem4 Lib "MSVBVM60" (ByVal lPtr As Long, ByRef ret As Long)
  5. 'USER32
  6. Private Declare Function MessageBoxW Lib "USER32" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long
  7.  
  8. Private Sub Form_Load()
  9.    Dim cadena      As String
  10.    Dim ptr1        As Long
  11.    Dim ptr2        As Long
  12.  
  13.    cadena = "karcrack"
  14.  
  15.    ptr1 = StrPtr(cadena)
  16.    'StrPtr__
  17.    Call GetMem4(VarPtr__(cadena) + 4, ptr2)
  18.  
  19.    MsgBox (ptr1 = ptr2)
  20.  
  21.    Call MessageBoxW(0, ptr2, 0, 0)
  22.    Call MessageBoxW(0, ptr1, 0, 0)
  23. End Sub

About ObjPtr() there's no problem about it... just need to change ByRef to ByVal because of the VB6 object instance creator...
Código
  1. 'KERNEL32
  2. Private Declare Function ObjPtr__ Lib "KERNEL32" Alias "MulDiv" (ByVal a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
  3.  
  4. Private Sub Form_Load()
  5.    Dim ptr1        As Long
  6.    Dim ptr2        As Long
  7.  
  8.    ptr1 = ObjPtr(Me)
  9.    ptr2 = ObjPtr__(Me)
  10.  
  11.    MsgBox (ptr1 = ptr2)
  12. End Sub


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: msdl en 30 Abril 2012, 21:16 pm
Finally I got it now I understood why it's not working with strptr
thanks a lot karcrack you are always the best :)

one last question
is it possible to invoke this API (without using strptr or varptr) ?
and if yes can you show me how ?


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: Karcrack en 30 Abril 2012, 21:22 pm
I can't understand your question. You're already calling this API (MulDiv) without using [Str/Var/Obj]Ptr... you're actually using MulDiv instead of [Var/Obj]Ptr... So I don't understand what you mean with:
is it possible to invoke this API (without using strptr or varptr) ?


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: msdl en 30 Abril 2012, 21:38 pm
i mean can i call this api with callapibyname function (with out declaration)?


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: Karcrack en 1 Mayo 2012, 00:01 am
No


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: SantaMorte en 8 Mayo 2012, 17:31 pm
Strptr Can Be Fully Replaced Without Any Problems
KarCrack made some error Try This :D
Código
  1. 'KERNEL32
  2. Private Declare Function VarPtr__ Lib "KERNEL32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
  3. 'MSVBVM60
  4. Private Declare Sub GetMem4 Lib "MSVBVM60" (ByVal lPtr As Long, ByRef ret As Long)
  5. 'USER32
  6. Private Declare Function MessageBoxW Lib "USER32" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long
  7.  
  8. Private Sub Form_Load()
  9.    Dim cadena      As String
  10.    Dim ptr1        As Long
  11.    Dim ptr2        As Long
  12.  
  13.    cadena = "karcrack"
  14.  
  15.    ptr1 = StrPtr(cadena)
  16.    'StrPtr__
  17.    Call GetMem4(VarPtr__(cadena) + 8, ptr2)
  18.  
  19.    MsgBox (ptr1 = ptr2)
  20.  
  21.    Call MessageBoxW(0, ptr2, 0, 0)
  22.    Call MessageBoxW(0, ptr1, 0, 0)
  23. End Sub
  24.  
STPRT Get the BSTR Address(where the string is stored) so is simple get it

Readmemory(Varptr + 8) = BSTR

enjoy


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: SantaMorte en 8 Mayo 2012, 17:49 pm
i mean can i call this api with callapibyname function (with out declaration)?

Yes it's possible


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: x64core en 8 Mayo 2012, 18:44 pm
deberían bloquear estos temas donde escriben en ingles, no lo digo por Karcrack sino por
los que inician los temas, aquí se escribe español/castellano, no ingles  >:(
Si quieren ayuda entonces que usen el Put0 traductor de google al menos  ::)


Título: Re: [HELP] How to use & invoke API function "MulDiv"
Publicado por: Swellow en 10 Junio 2012, 21:46 pm
Strptr Can Be Fully Replaced Without Any Problems
KarCrack made some error Try This :D

'KERNEL32
Private Declare Function VarPtr__ Lib "KERNEL32" Alias "MulDiv" (ByRef a As Any, Optional ByVal b As Long = 1, Optional ByVal c As Long = 1) As Long
'MSVBVM60
Private Declare Sub GetMem4 Lib "MSVBVM60" (ByVal lPtr As Long, ByRef ret As Long)
'USER32
Private Declare Function MessageBoxW Lib "USER32" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long
 
Private Sub Form_Load()
    Dim cadena      As String
    Dim ptr1        As Long
    Dim ptr2        As Long
 
    cadena = "karcrack"
 
    ptr1 = StrPtr(cadena)
    'StrPtr__
    Call GetMem4(VarPtr__(cadena) + 8, ptr2)
 
    MsgBox (ptr1 = ptr2)
 
    Call MessageBoxW(0, ptr2, 0, 0)
    Call MessageBoxW(0, ptr1, 0, 0)
End Sub

STPRT Get the BSTR Address(where the string is stored) so is simple get it

Readmemory(Varptr + 8) = BSTR

enjoy

This won't work on every situation I just tried.