BBC BASIC for Windows
« Bit 2 of OPT is useful after all! »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:25pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Bit 2 of OPT is useful after all!  (Read 598 times)
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Bit 2 of OPT is useful after all!
« Thread started on: Jun 4th, 2009, 09:51am »

The OPT pseudo-op controls various aspects of the assembly process in BBC BASIC. When bit 2 is set (i.e. when OPT has the values 4, 5, 6, 7, 12, 13, 14 or 15) the location at which the assembled code is stored in memory, and the address at which it is designed to run, can be different (O% and P% respectively).

This feature was provided in the original versions of BBC BASIC to allow code to be assembled which would subsequently be relocated, for example into a 'sideways' ROM or RAM. I have always considered it to have virtually no practical value in BBC BASIC for Windows, because almost invariably you will want to run the code in the location to which it has been assembled.

I'm pleased to say I was wrong. I have recently been experimenting with 'injecting code into another process' (in particular, to allow subclassing a window belonging to another process) and the above-mentioned feature of the assembler is ideally suited to that.

One first allocates a block of memory in the 'remote' process (VirtualAllocEx), the address of which is determined by Windows, and is likely not to be a valid address in one's own process. Next one assembles some code which is stored in the BASIC heap as normal. Then the assembled code is copied to the remote process's address space (WriteProcessMemory).

So for the 'injected' code to run successfully in the remote process it must be assembled to run at the allocated address but actually stored in BASIC's local heap. This is something which would be extremely difficult to achieve were it not for the facility provided by setting bit 2 of OPT.

Richard.
User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: Bit 2 of OPT is useful after all!
« Reply #1 on: Jun 5th, 2009, 08:09am »

This is *very* interesting. I suppose it will be 'easy' now to get GWL_WNDPROC from that process for subclassing.

Michael
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls