Author Topic: VB6 Extended  (Read 18385 times)

0 Members and 2 Guests are viewing this topic.

JRS

  • Guest
Re: VB6 Extended
« Reply #30 on: October 30, 2014, 07:38:35 PM »
Dave converted an ASM/DisASM DLL project by Oleh Yuschuk to work with VB6.

Quote
Disassembler understands all standard 80x86 commands, FPU, MMX, AMD's MMX extensions, Athlon/PIII MMX extensions and 3DNow! instructions. It does not decode SSI or SSI2 commands. Disassembler assumes 32 bit code and data segments but correctly decodes prefixed 16-bit commands. Several decoding modes allow you to select the amount of returned information (which is inversely proportional to execution speed): command length only, basic information useful for code analysis, or full decoding with dump and assembler form. Multiple options select desired format. Disassembler and Assembler support both MASM and Borland's IDEAL modes.

Assembler converts single command from the ASCII form to the binary code. It allows to find several possible encodings, or even to create search patterns with undefined operands.



Documentation

Generic DLL project site (see attached OllyDBG screen shot)

OllyDbg Quick start

.
« Last Edit: October 30, 2014, 10:35:49 PM by John »

Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #31 on: October 30, 2014, 10:43:53 PM »
Olly's Assembl.c is mostly sufficient to create, with some effort, a simple 32-bit JIT Asm compiler for ScriptBASIC. :)

JRS

  • Guest
Re: VB6 Extended
« Reply #32 on: October 30, 2014, 10:48:24 PM »
I'm thinking the same but I have no ASM experience. It would be a great way to learn. :)

I'm thinking that using DLLC would the quickest way to get a prototype working.

@Charles - Would you have time to create a simple framework for a JIT assembler for SB?
« Last Edit: October 30, 2014, 11:15:39 PM by John »

Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #33 on: October 30, 2014, 11:21:26 PM »
You don't need to know anything about assembly for that, John. assembl.c provides a recursive descent parser and a line-by-line line compiler while asmserv.c contains a lookup table for a fair subset of asm instructions (many are still missing and some are faulty though). The developer will have to design a "linker" function that will supply lines of asm code to Assemble() and will receive assembled byte sequences and copy them into a sequential buffer in executable memory. Then the "linker" will have to run a brief second pass to imprint the numeric values of actual label offsets into the jump and call instruction blanks left over during the first pass for that purpose. The entry point addresses of the resultant assembled procs can be used for calling from the C code of SB engine proper.

The entire thing could be compiled as a DLL extension module. Perhaps Dave can accept the challenge? :)

JRS

  • Guest
Re: VB6 Extended
« Reply #34 on: October 30, 2014, 11:35:30 PM »
Quote
Perhaps Dave can accept the challenge?

Dave is out of commission with tendinitis in his arms. (too painful to code anymore)

If you would be willing to mentor this along, I would be wiling to do as much of the leg work as possible. If you, Charles and I  put our heads together on this, everyone would benefit in the end. It would be a great way to get BASIC programmers introduced to ASM. I have already put a similar effort into C BASIC.

 

Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #35 on: October 31, 2014, 12:18:29 AM »
Oh, I'm sorry, I didn't know that. :(

I started fiddling with asm in FBSL v3 a decade ago with such an Olly-based DLL. I'll see if I can find the sources and I will send them to you if I can.


JRS

  • Guest
Re: VB6 Extended
« Reply #36 on: October 31, 2014, 12:24:53 AM »
I would be happy with an ASM stub function that does the setup for a in-line ASM routine that is created with the Olly DLL on the fly.

That would seem to be a good first step. You would call the function with something similar to bes_CallArgsEx() that describes the arguments being passed.


JRS

  • Guest
Re: VB6 Extended
« Reply #37 on: October 31, 2014, 12:43:34 AM »
Attached it the current source for Krool's replacement common controls OCX.


.

Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #38 on: October 31, 2014, 07:57:50 AM »
Hello John,

Luckily I've found the sources so your OllyASM effort is feasible. Attached please find the DLL (compiled with MinGW GCC v4.3.3), two FBSL scripts to get an idea of how to deploy it, and two precompiled executables to see it in action jumping around happily and calling external and internal functions.

Be forewarned however that IIRC the DLL is not bugless nor is its asm instruction LUT complete.

I will send you the sources as a Code::Blocks project in an e-mail.


Be sure to have your DEP service disabled because it JIT-compiles the code into conventional, not executable, memory!

.

JRS

  • Guest
Re: VB6 Extended
« Reply #39 on: October 31, 2014, 11:15:39 AM »
Thanks Mike for the download and e-mail. I'm probably the last person of our group to be spearheading this effort. My plan is to understand Dave's version in VB first, before looking at any possible migration to SB. My hope is Charles will whip up an ASM stub function in DLLC to give this some legs.


Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #40 on: October 31, 2014, 04:06:35 PM »
You're welcome, John.

Though the assembl.c and asmserv.c files are still bearing their original Olly names, they have been revised to contain code that's only relevant to assembler. It also includes my debug helper functions that enable you to inspect the assembly process in your console. Those can be safely deleted or better compiled conditionally in order to reduce the DLL size. Moreover, the project doesn't need -O3 optimization and can be compiled with a -Os (optimize for size) switch to minify the DLL still further. The resultant machine code isn't dependent on source code optimization and the compilation speed will stay very high regardless. Finally, exepacking the resultant DLL with UPX in a -force --ultra-brute mode will make it absolutely tiny.

If Charles or somebody else in the know agrees to develop the stub functions, here's an absolute minimum of what should be done:

1. Memory allocation in Build() should be changed from HeapAlloc() to VirtualAlloc() with a WRITABLE attribute that should then be changed again to READABLE+EXECUTABLE once the compilation process is successfully over. This will enable you to bypass the existing DEP restrictions.

2. Alternatively, the Build() function's buffer which is always 64KB large may be memcpy-ed into a buffer of exact size VirtualAlloc-ated by the procedure that's supposed to call Build() on the SB side. The exact byte size of resultant machine code is returned by Build() on successful compilation. The pointer to the 64KB buffer may be returned in an additional argument to the function and should be free-d on copying.

3. The call-by-pointer stub functions should be variadic to allow for an arbitrary number of arguments to be passed to the JIT assembled routines. The machine code entry pointer value is returned in the second argument to Build().

4. The last argument to Build() was meant for syncing the line numbers in the FBSL source script with the debug output in the compilation console. It may be omitted if this functionality is irrelevant to SB.
« Last Edit: October 31, 2014, 07:56:50 PM by Mike Lobanovsky »

JRS

  • Guest
Re: VB6 Extended
« Reply #41 on: October 31, 2014, 07:17:24 PM »
Mike,

I wish I had the experience and understanding of ASM like you and Charles has. I'm just being honest and saying up front that I'm not capable of integrating Olly with SB. The JIT linking part is beyond my reach.

JRS

  • Guest
Re: VB6 Extended
« Reply #42 on: October 31, 2014, 07:54:57 PM »
I ran into this tutorial about how to make .NET forms COM visible.

Making a .NET Dll COM-Visible

Script BASIC .NET example

Mike Lobanovsky

  • Guest
Re: VB6 Extended
« Reply #43 on: October 31, 2014, 08:35:09 PM »
John,

If I understand the purpose of DLLC correctly, you can use it as it is to call Build() in OllyASM.dll passing to it the pointer to the asm source string and getting back the pointer to the corresponding JIT compiled procedure. This is where DLLC's usability in its current form ends.

Now you must also have a mechanism to bind the JIT compiled asm procedure's pointer returned by Build() with a C prototype of this procedure, which would allow you to call this procedure in a usual C way passing (in fact, pushing on the stack) the required arguments and accepting its return if the procedure is a function rather than a sub.

This should be a trivial task for the person who has already done similar things in DLLC. This is why let us request Charles together to help you out with this because I can hardly afford studying the SB sources from scratch reinventing the wheel whose plot Charles should still be keeping in his head. :)

JRS

  • Guest
Re: VB6 Extended
« Reply #44 on: October 31, 2014, 08:54:26 PM »
Your observation and research is dead on. As you say it's up to Charles to fill in the missing piece in DLLC. I'm a user of DLLC, not it's author. Charles has created a low level C interface with DLLC. It brings out the multi-threading features of SB and does some fancy footwork sharing the IUP message pump between threads.

I would love to have a ASM JIT option for SB as it would fill out the offering nicely.