VFPA como funcionan los codigo ASM en 64 bits?

119 views
Skip to first unread message

Fernando Mora

unread,
Apr 20, 2022, 11:31:58 AM4/20/22
to Comunidad de Visual Foxpro en Español
Saludos comunidad!

En VFP9 usaba unos códigos de assembler para ejecutar dirección de procesos con CallWindowProc, una codificación bastante sencilla que consistía en empujar direcciones a la pila de memoria, empujar una dirección de proceso y ejecutar. Intento hacer lo mismo en 64 bits pero no funciona.

código ASM 32 bits
cAsm = cAsm + chr(0x68) + lcMemAdd1            && PUSH PARAM1
cAsm = cAsm + chr(0x68) + lcMemAdd2            && PUSH PARAM2
cAsm = cAsm + chr(0xB8) + lcProcAddress       && MOV EAX, PROCADD
cAsm = cAsm + chr(0xFF) + chr(0xD0)                && CALL EAX
cAsm = cAsm + chr(0xA3) + lcResult                   && MOV DWORD PTR ADDRESULT, EAX
cAsm = cAsm + chr(0xC3)                                      && RETN

Este código en VFP9 funciona excelente, pero no en VFPA
He intentado cambiando la instrucción de MOV EAX, PROCADD por MOV RAX, pero no funciona. 
Alguien tiene una idea de como ejecutar codigos assemlber en VFPA?

Dsan

unread,
Apr 20, 2022, 12:09:08 PM4/20/22
to publice...@googlegroups.com

Hola buen dia, 

tal vez hay que cambiar algo para 64bit
te dejo este pdf, check pag 37


saludos

Ds




--
Blog de la Comunidad Visual FoxPro en Español: http://comunidadvfp.blogspot.com
---
Has recibido este mensaje porque estás suscrito al grupo "Comunidad de Visual Foxpro en Español" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a publicesvfoxp...@googlegroups.com.
Para ver esta conversación en el sitio web, visita https://groups.google.com/d/msgid/publicesvfoxpro/bcfe279f-f2d9-41ef-abd5-010604475c49n%40googlegroups.com.

Fernando Mora

unread,
Apr 29, 2022, 11:33:46 AM4/29/22
to Comunidad de Visual Foxpro en Español
Gracias por responder DSanchez.
Si efectivamente hubo que realizar cambios.... al parecer ya no se vale hacer un simple PUSH a la memoria, uffff.

Les comparto mi trabajo para poder ejecutar códigos ASM en VFPA, esto es util para poder llamar a dirección de procesos, muy necesario para trabajar ciertas funciones de la API de windows y otras APIS. 
Luego de revisar y revisar, probar y probar esto es lo que conseguí: 

*-- Main
Clear
Set Talk Off
Set Safety Off

lhModule = GetModuleHandleA("User32")
lpProcce = GetProcAddress(lhModule, "MessageBoxA")

lcProcAdd     = BinToC(lpProcce,"4RS")
lchWnd         = BinToC(_Screen.HWnd,"4RS")
lstrText     = BinToC(GetHeapAllocPtr("Hola, este es mi mensaje desde VFPA"+Chr(0)),"4RS")
lstrTitle     = BinToC(GetHeapAllocPtr("MI Titulo VFPA"+Chr(0)),"4RS")
lcuType     = BinToC(4+64,"4RS")

lnHex = 16
lcLenMem = Chr(0x20)
lcCero = Strconv("00000000",lnHex)
lcASM = ""
lcASM = lcASM + Strconv("55", lnHex)
lcASM = lcASM + Strconv("48 89 E5", lnHex)
lcASM = lcASM + Strconv("48 83 EC", lnHex)+ lcLenMem

lcASM = lcASM + Strconv("49 B9", lnHex ) + lcUType + lcCero
lcASM = lcASM + Strconv("49 B8", lnHex) + lstrTitle + lcCero
lcASM = lcASM + Strconv("48 BA", lnHex) + lstrText + lcCero
lcASM = lcASM + Strconv("48 B9", lnHex) + lchWnd + lcCero
lcASM = lcASM + Strconv("48 B8", lnHex) + lcProcAdd + lcCero

lcASM = lcASM + Strconv("FF D0", lnHex)
lcASM = lcASM + Strconv("48 83 C4", lnHex)+ lcLenMem
lcASM = lcASM + Strconv("5D", lnHex)
lcASM = lcASM + Strconv("C3", lnHex)

nbp = GetHeapCreate(4096, lcASM)
? nbp  
lnRet = -2
Local oError As Exception
try
    lnRet = CallWindowProc( nbp, 0, 0, 0, 0 )
Catch to oError
    ? oError.ErrorNo, oError.Message
EndTry
? lnRet
O=NULL
Release O
Return

*--------- REGION DE FUNCIONES
Function GetModuleHandleA()
    Lparameters tcModule As String
    *----- Declaration API
    Declare Long GetModuleHandleA In Kernel32;
        String    lpModuleName    
    *----- Obtenemos modulo
    lhModulo = GetModuleHandleA(tcModule)
    Clear Dlls GetModuleHandleA
    Return lhModulo    
EndFunc

Function GetProcAddress()
    Lparameters thModule As Long, tcProcName As String
    *----- Declaration API
    Declare Long GetProcAddress In Kernel32;
        Long    hModule,;
        String    lpProcName
    *----- Obtenemos un proceso
    lhProcess = GetProcAddress(thModule, tcProcName)
    Clear Dlls GetProcAddress
    Return lhProcess
EndFunc

Function CallWindowProc()
    Lparameters tpPrevWndFunc As Long, tnhWnd As Long, tnMsg As Long, tnwParam As Long, tplParam As Long
    *----- Declaration API
    Declare Long CallWindowProc In User32;
        Long     lpPrevWndFunc,;
        String     nHWnd,;
        Long     Msg,;
        Long     wParam,;
        Long     lParam
    *----- Llamamos a un proceso
    nResp = CallWindowProc(tpPrevWndFunc, tnhWnd, tnMsg, tnwParam, tplParam)
    Clear Dlls CallWindowProcA
    Return  nResp
EndFunc

Function GetHeapCreate()
    Lparameters tnLenHeap As Integer, tcStrToMemo As String
    *----- Declaration API
    Declare Long HeapCreate In Kernel32;
        Long    flOptions,;
        Long    dwInitialSize,;
        Long    dwMaximumSize
   
    Declare Long HeapAlloc In Kernel32;
        Long    hHeap,;
        Long    dwFlags,;
        Long    dwBytes
   
    Declare RtlMoveMemory In Kernel32;
        Long    Destination,;
        String @Source,;
        Long    Length

    *----- Cargamos dato a memoria
    lhHeap = HeapCreate(0x00040000, tnLenHeap, tnLenHeap)  
    lpAddr = HeapAlloc(lhHeap, 0, Len(tcStrToMemo)+16)  
    RtlMoveMemory(lpAddr, tcStrToMemo, Len(tcStrToMemo))  
    Clear Dlls HeapCreate, HeapAlloc, RtlMoveMemory
    Return lpAddr
EndFunc

Function GetHeapAllocPtr()
    Lparameters tcStrToPtr As String, tnFlags_Opc As Integer
    *----- Declaration API
    Declare Long GetProcessHeap In Kernel32
   
    Declare Long HeapAlloc In Kernel32;
        Long    hHeap,;
        Long    dwFlags,;
        Long    dwBytes
   
    Declare RtlMoveMemory In Kernel32;
        Long    Destination,;
        String @Source,;
        Long    Length
       
    *----- Variables locales
    Local lnFlags, lpAddressMem
    lnFlags = Iif(Vartype(tnFlags_Opc)=="N", tnFlags_Opc, 0x00000008)
    lnFlags = Iif(lnFlags=0, 0x00000008, lnFlags)
    lpAddr = 0
    *----- Creamos puntero y colocamos datos
    lpAddr = HeapAlloc(GetProcessHeap(), lnFlags, Len(tcStrToPtr))
    RtlMoveMemory(lpAddr, @tcStrToPtr, Len(tcStrToPtr))
    Return lpAddr
EndFunc
Reply all
Reply to author
Forward
0 new messages