News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Virtual Disk Service

Started by colinramsden, July 20, 2010, 10:31:00 PM

Previous topic - Next topic

colinramsden

Hi Guys,

I am hoping someone can help me here!

I am not new to assembler (4+ years, early 1990's MC68000) but I am reasonably new to Intel x86 assembly (1 yr with much to learn!).

I am trying to write a program which will take disks offline and bring them online, also set and clear the readonly attribute.

There is a C header (vds.h) and a library (UUID.lib) which will allow this functionality (provided in Windows SDK 7.0), however, C means nothing to me whatsoever.

Does anyone already own or have the ability to convert these files to asm, preferably with sample code.

Thank you very much in advance for any assistance in this matter.

Colin.


redskull

All the VDS stuff is implemented in COM which, while possible to do in assembly language, it much more suited to higher levels like C.  There are macros around to help automate it, but they end up turning things very C-like anyway.  Since COM is a fairly time-intensive to learn, and you are essentially trying to google-and-paste it anyhow, you are much better off doing it in C.  Otherwise, you need to google 'CoCreateInstance' and 'VDS Interfaces' and search the forum for COM in MASM samples.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

colinramsden

OK, for anyone who is interested, after a bit of research, this is what I have achieved so far:

The code appears to work and it does load the VDS, however, I am not entirely certain what it does and how much more I am going to have to write before commands can be issued to the VDS.

A mate of mine wrote me a DiskPart replacement app in C, I have reversed some of it and with internet research, come up with the following:


.486
.model flat, stdcall
option casemap :none

include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
include shell32.inc
include ole32.inc

include \masm32\macros\macros.asm
include masm32.inc
includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
includelib shell32.lib
includelib ole32.lib

.data

TempBuffer dd ?
TempBuffer2 dd ?

CLSID_VdsLoader GUID {9C38ED61h,0D565h,4728h,{0AEh,0EEh,0C8h,09h,52h,0F0h,0ECh,0DEh}}
IUnknown GUID {00000000h,0000h,0000h,{0c0h,00,00,00,00,00,00,46h}}
VDSProxyStub GUID {0E0393303h,90D4h,4A97h,{0ABh,71h,0E9h,0B6h,71h,0EEh,27h,29h}} ;VDS ProxyStub

Start:
invoke CoInitialize,NULL
lea eax, TempBuffer

invoke CoCreateInstance,addr CLSID_VdsLoader,NULL,CLSCTX_LOCAL_SERVER,addr IUnknown,eax

mov ecx, TempBuffer
invoke OleRun,ecx

mov eax,TempBuffer
mov edx,dword ptr[eax]

lea edi, TempBuffer2
push edi
push offset VDSProxyStub
push eax
mov eax, dword ptr[edx]
call eax

mov esi, eax
mov eax, TempBuffer
mov ecx, dword ptr[eax]
mov edx, dword ptr[ecx+8]
push eax
call edx
test esi, esi
jge NoError
nop
NoError:
ret
End Start


It was written using WinASM Studio with MASM32 and it should copy out alright.

Once again, if anyone can shed any light onto what the later part of this code actually does and how much more is required it will be appreciated.

Thanks, Colin

redskull

Big, thick books have been written about COM so i can barely do it justice, but I'll give it a shot:

A COM interface is, informally, a group of functions.  When you use CoCreateInstance, the O/S finds the particular DLL which provides the functions from the interface you specify, and gives you back a doubly-indirected pointer to a table of function addressess (eax, after the call).  To actually get the addressess of the functions in that interface, you defrerence it twice (mov edx, dword ptr [eax] retrieves the pointer to the table, mov eax, dword ptr [edx] retrieves the address of the first function).

Every interface implements three particular ones, known by the confusingly-named IUnknown.  These are the first three addressess in the table of functions, so the first call instruction is a call to QueryInterface(), a function which can tell a program which interfaces a particular library will support, which essentially says "do you support IVdsServiceLoader interface, and if you do, please give me another doubly-indirected pointer to it".

Then it does the same thing again, but this time calls the third function in the table (ecx+8), which I believe is the Release() function, tells the object you no longer require the services, and will make everything shutdown gracefully.

This page references all the various interfaces you will need to query and release and use: http://msdn.microsoft.com/en-us/library/aa383370(VS.85).aspx

As you can see, it's a lot of overhead programming for even the most trivial program.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

ecube

this shows you where all the COM CLISIDS and file info etc are stored in the registry http://msdn.microsoft.com/en-us/library/ms691424%28VS.85%29.aspx

also this tool is real nice, generates code and stuff for COM components http://www.masm32.com/board/index.php?topic=14397.0 Also minor28, obviously knows a lot about the topic, so if you have more specific questions I bet he could help.

colinramsden

Thanks guys, you've been a great help, i am getting a little further now.

Once I have made significant progress, I will update the code above to reflect this as someone else may want the code.