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

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [HELP] How to use & invoke API function "MulDiv"
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: [HELP] How to use & invoke API function "MulDiv"  (Leído 8,661 veces)
msdl

Desconectado Desconectado

Mensajes: 9


Ver Perfil
[HELP] How to use & invoke API function "MulDiv"
« 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.


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #1 en: 29 Abril 2012, 21:43 pm »

.
MulDiv function

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!¡.


« Última modificación: 29 Abril 2012, 21:57 pm por BlackZeroX (Astaroth) » En línea

The Dark Shadow is my passion.
x64core


Desconectado Desconectado

Mensajes: 1.908


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #2 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

 ::)
En línea

msdl

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #3 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
:(
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #4 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
« Última modificación: 30 Abril 2012, 20:43 pm por Karcrack » En línea

msdl

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #5 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 ?
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #6 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) ?
En línea

msdl

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #7 en: 30 Abril 2012, 21:38 pm »

i mean can i call this api with callapibyname function (with out declaration)?
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #8 en: 1 Mayo 2012, 00:01 am »

No
En línea

SantaMorte

Desconectado Desconectado

Mensajes: 6



Ver Perfil
Re: [HELP] How to use & invoke API function "MulDiv"
« Respuesta #9 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
« Última modificación: 11 Junio 2012, 04:33 am por raul338 » En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Ayuda] modificar "start page" en "internet explorer" con "batch"
Scripting
taton 7 16,585 Último mensaje 20 Septiembre 2006, 01:45 am
por taton
problema "procedimiento sub o function no definido"
Programación Visual Basic
.:UND3R:. 4 6,957 Último mensaje 15 Junio 2011, 20:41 pm
por .:UND3R:.
recursos visual basic, """"""proceso inmortal"""""
Análisis y Diseño de Malware
Dark4ngel 7 13,295 Último mensaje 3 Noviembre 2011, 10:42 am
por Dark4ngel
[JS] "a.charAt is not a function", ¿por qué?
Scripting
Linton 6 5,311 Último mensaje 4 Septiembre 2013, 19:32 pm
por Linton
Me arroja error "Sub or function not defined" « 1 2 »
Programación Visual Basic
antihelio 12 5,262 Último mensaje 12 Febrero 2015, 18:37 pm
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines