API Hooking for FreeStyle

Everything else that doesn't fall into one of the other PB categories.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

API Hooking for FreeStyle

Post by PolyVector »

I need to hook a shared API in Windows9x to continue development on FreeStyle. Without this capability FreeStyle can't function properly in 9x! Here's what I know so far:
  • VirtualProtect_() won't allow me to modify permissions on a shared API...
  • I can bypass VirtualProtect_() by using an undocumented API called VxDCall()
  • With VxDCall() I can call _PageModifyPermissions directly and make shared memory writable
If anybody thinks they can help, I have code to access VxDCall() and _PageModifyPermissions... Although I'd rather PM it than post it here...
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Not sure if this helps but have you tried VirtualProtectEx
MSDN SDK wrote:The VirtualProtect function changes the protection on a region of committed pages in the virtual address space of the calling process.

To change the access protection of any process, use the VirtualProtectEx function.

Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

no form of VirtualProtect will allow you to modify permissions of Shared memory :(
Windows Me/98/95: You cannot use VirtualProtectEx on any memory region located in the shared virtual address space (from 0x80000000 through 0xBFFFFFFF).
If anybody could help me getting this asm to work w/ PB it would be great:
It uses INT 2Eh to copy shared memory (on win9x)... It's the lowlevel equivilent of CopyMemory() on win9x

Code: Select all

                        i2E_RtlCopyMemory     equ     0000010Ah

                        mov     eax, i2E_RtlCopyMemory
                        lea     edx, stk
                        int     2Eh
                        ...
stk:                    dd      0BFF7xxxxh      ; edi (destination)
                        dd      offset vir_code ; esi (source)
                        dd      vir_size        ; ecx (length in bytes)

EDIT: SOLVED!
Here's the function if anybody's interested... It can copy ANY MEMORY on 9x... this includes protected/shared/whatever...

Code: Select all

Procedure Win9x_RtlCopyMemory(SourceMemory.l,DestinationMemory.l,Length.l)
  stk=AllocateMemory(3*4)
  PokeL(stk+0,DestinationMemory)
  PokeL(stk+4,SourceMemory)
  PokeL(stk+8,Length)
  MOV     eax, #i2E_RtlCopyMemory
  MOV     edx, stk
  INT     2Eh
  FreeMemory(Buffer)
EndProcedure
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

solved polyvector?
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

yes, win89's memory-handling is very secure ;)
SPAMINATOR NR.1
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

solved polyvector?
Well I solved that one hurtle for 9x api hooking... Now I need to write a small code-generator to create functions in shared memory that check what the current process is and compare it with a list... And ever time i try code that fails I have to reboot :evil:
At least VMWare is my friend!
My work is never done! :o
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Alright, this problem has been completely solved! Thanks for your help everyone!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

gotta' love vmware! although i managed to crash the host now one time by doing something within vmware, security is not a 100% tight it appears
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply