flat assembler
Message board for the users of flat assembler.

Index > Windows > Drivers for 98/2000

Goto page Previous  1, 2, 3, 4, 5  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 17 Sep 2003, 08:59
This is how the import sections should be done to be the same as in the original .sys files you're talking about:
Code:
section '.rdata' readable notpageable

data 12

  ImportLookup:
        dd rva szRead_port_uc
        dd rva szWrite_port_uc
        dd rva szHalmakebeep
        dd 0

end data

section 'INIT' import readable notpageable

        dd rva ImportLookup
        dd 0
        dd 0
        dd rva szHal_dll
        dd rva ImportAddress
        times 5 dd 0

  ImportAddress:
        imp_READ_PORT_UCHAR         dd rva szRead_port_uc
        imp_WRITE_PORT_UCHAR        dd rva szWrite_port_uc
        imp_HalMakeBeep             dd rva szHalmakebeep

  szHalmakebeep     dw 0
                    db 'HalMakeBeep',0
  szRead_port_uc    dw 0
                    db 'READ_PORT_UCHAR',0
  szWrite_port_uc   dw 0
                    db 'WRITE_PORT_UCHAR',0

  szHal_dll db 'HAL.dll',0    

You can also use "data import" in order to combine those two resources into one section.
With some macros it would be easier to maintain, you can try to modify standard import macros to generate the structures as above.
Post 17 Sep 2003, 08:59
View user's profile Send private message Visit poster's website Reply with quote
BiDark



Joined: 22 Jun 2003
Posts: 109
Location: .th
BiDark 17 Sep 2003, 11:05
That's why I had combine the two into one section (INIT section) and set it to share the same thunk table (may save some space? the system memory for the drivers is expensive?).

Okey, modified it already, thanks.
Post 17 Sep 2003, 11:05
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 22 Sep 2003, 02:45
I tried, but I think its still wrong .sys Neutral

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 22 Sep 2003, 02:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 22 Sep 2003, 07:57
Details?
Post 22 Sep 2003, 07:57
View user's profile Send private message Visit poster's website Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng 22 Sep 2003, 12:30
Hi,Privalov:
I found must present the 'reloc' section, the sys file is OK.
Please see the belowing code:
Code:
format PE DLL native 4.0 at 10000h
entry main

include '%include%\win32a.inc'

section '.text' code readable executable notpageable
proc MakeBeep1,dwPitch
 enter
       cli
 mov     al,0B6h
     out     43h,al
      mov     eax,[dwPitch]
       out     42h,al
      mov     al,ah
       out     42h,al
      in      al,61h
      or      al,3
        out     61h,al
      sti
 mov     eax,1800000h
     .delay_loop:
       dec     eax
 or      eax,eax
     jnz     .delay_loop
 cli
 in      al,61h
      and     al,0FCh
     out     61h,al
      sti
 return


proc MakeBeep2,dwPitch
    enter
       cli
 push    0B6h
        push    43h
 call    [imp_WRITE_PORT_UCHAR]
      mov     eax,[dwPitch]
       push    0
   movzx   ax,al
       push    ax
  push    42h
 call    [imp_WRITE_PORT_UCHAR]
      mov     eax,[dwPitch]
       push    0
   mov     al,ah
       movzx   ax,al
       push    ax
  push    42h
 call    [imp_WRITE_PORT_UCHAR]
      push    61h
 call    [imp_READ_PORT_UCHAR]
       or      al,3
        push    0
   movzx   ax,al
       push    ax
  push    61h
 call    [imp_WRITE_PORT_UCHAR]
      sti
 mov     eax,1800000h
.delay_loop:
    dec     eax
 or      eax,eax
     jnz     .delay_loop
 cli
 push    61h
 call    [imp_READ_PORT_UCHAR]
       and     al,0FCh
     push    0
   movzx   ax,al
       push    ax
  push    61h
 call    [imp_WRITE_PORT_UCHAR]
      sti
 return


proc main,pDriverObject,pDriverPath
       enter
       push    474h
        call    MakeBeep1
   push    389h
        call    MakeBeep2
   push    620h
        call    [imp_HalMakeBeep]
   mov     eax,1800000h
.delay_loop:
    dec     eax
 or      eax,eax
     jnz     .delay_loop
 push    0
   call    [imp_HalMakeBeep]
   mov     eax,0C0000182h
      return
      
section '.rdata' readable notpageable 

data 12 

  ImportLookup: 
        dd rva szRead_port_uc 
        dd rva szWrite_port_uc 
        dd rva szHalmakebeep 
        dd 0 

end data 

section 'INIT' import readable notpageable 

        dd rva ImportLookup 
        dd 0 
        dd 0 
        dd rva szHal_dll 
        dd rva ImportAddress 
        times 5 dd 0 

  ImportAddress: 
        imp_READ_PORT_UCHAR         dd rva szRead_port_uc 
        imp_WRITE_PORT_UCHAR        dd rva szWrite_port_uc 
        imp_HalMakeBeep             dd rva szHalmakebeep 

  szHalmakebeep     dw 0 
                    db 'HalMakeBeep',0 
  szRead_port_uc    dw 0 
                    db 'READ_PORT_UCHAR',0 
  szWrite_port_uc   dw 0 
                    db 'WRITE_PORT_UCHAR',0 

  szHal_dll db 'HAL.dll',0

section '.reloc' data fixups readable discardable
    

And others, I have collect all the files, please used the build.bat for building all the files.


Description:
Download
Filename: beeper.zip
Filesize: 10.11 KB
Downloaded: 759 Time(s)

Post 22 Sep 2003, 12:30
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 22 Sep 2003, 13:56
Yes, of course it must contain the fixups - it was already discussed here (and BiDark's example has the relocation section).
Post 22 Sep 2003, 13:56
View user's profile Send private message Visit poster's website Reply with quote
BiDark



Joined: 22 Jun 2003
Posts: 109
Location: .th
BiDark 25 Sep 2003, 04:10
Ah..., I found out that when specified 'PE native' alone it doesn't produce .sys format. I have put 'DLL' by accident sorry hehe, so whether it have the 'DLL' flag or not it should produce .sys file (becuase the original doesn't have 'DLL' flag specified in File Header.

And others, If you have troble with 'Unable to load the driver' message, try this.

Goto HKLM\System\ControlSet001\Service and find the 'beeper' entry, delete it and restart the machine.
Post 25 Sep 2003, 04:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 25 Sep 2003, 09:09
BiDark wrote:
Ah..., I found out that when specified 'PE native' alone it doesn't produce .sys format.

It does. Or maybe do you mean that the .sys extension is not generated by FASMW in that case?
Post 25 Sep 2003, 09:09
View user's profile Send private message Visit poster's website Reply with quote
BiDark



Joined: 22 Jun 2003
Posts: 109
Location: .th
BiDark 25 Sep 2003, 10:46
Privalov wrote:

It does. Or maybe do you mean that the .sys extension is not generated by FASMW in that case?


Yes, FASMW doesn't generates .sys extension when specified the 'PE native' format without the 'DLL' flag, It generates .exe insteed. It should generates .sys in this case, sorry about my english hehe.
Post 25 Sep 2003, 10:46
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 15 Oct 2003, 04:01
Code:
data 12 

  ImportLookup: 
        dd rva szRead_port_uc 
        dd rva szWrite_port_uc 
        dd rva szHalmakebeep 
        dd 0 

end data    


What does data do?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 15 Oct 2003, 04:01
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 16 Oct 2003, 04:12
Here maybe this is clean example? Run "scm.exe beeper.sys"

Code:
macro syslibrary [name,string]
 { forward
    local _label
    if ~ name#.needed
    dd RVA name,0,0,RVA _label,RVA name
    end if
   common
    dd 0,0,0,0,0
   forward
    if ~ name#.needed
    _label db string,0
    end if }    


Description:
Download
Filename: beeper.zip
Filesize: 5.55 KB
Downloaded: 817 Time(s)


_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 16 Oct 2003, 04:12
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng 28 Oct 2003, 11:31
Dear All:
Why the returned value of DriverEntry is C000182H? Since standard WDM driver programmer guide, the return value should be 0. So I used 0 as return vaule. And then found the driver can't load more one. The error code is 1072. From MSDN, the error code is ERROR_SERVICE_MARKED_FOR_DELETE.

And others, I used MASM for building the same as driver and returned value is zero, the driver can load more one and worked OK.
Who known the reason about the result? I guest that it maybe FASM doesn't support fully sys file format.
Post 28 Oct 2003, 11:31
View user's profile Send private message MSN Messenger Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng 28 Oct 2003, 15:39
Hi,Privalov:
I have known the answer about the fasm doesn't support finally WDM sys
format. Because the FASM set the DllCharacteristics of OptionHeader is 0000H, But the WDM file should be 2000H . I modifed the value and recaluate the checksum. The driver runed OK.
Please see the web site for the description :
Code:
DllCharacteristics 
DLL characteristics of the image. The following values are defined. Value Meaning 
0x0001 Reserved 
0x0002 Reserved 
0x0004 Reserved 
0x0008 Reserved 
0x2000 A WDM driver.     

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/image_optional_header_str.asp
Post 28 Oct 2003, 15:39
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 28 Oct 2003, 16:06
OK, fixed it (check the latest prerelease on this board). I was misguided by the fact, that none of WDM drivers I've found on my system actually have this flag set... Confused
Post 28 Oct 2003, 16:06
View user's profile Send private message Visit poster's website Reply with quote
ProgramMan



Joined: 25 Jan 2004
Posts: 5
ProgramMan 28 Jan 2004, 07:41
Greetings to all.
I write through PROMT. Sad
How to establish the control over file system, using the driver (*.sys)
It is possible with examples. Arrow
Post 28 Jan 2004, 07:41
View user's profile Send private message ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4225
Location: vpcmpistri
bitRAKE 03 Feb 2004, 05:46
Post 03 Feb 2004, 05:46
View user's profile Send private message Visit poster's website Reply with quote
ProgramMan



Joined: 25 Jan 2004
Posts: 5
ProgramMan 08 Feb 2004, 11:34
Also what?
How to establish the control over file system, using the driver (*.sys)
It is possible with examples.
Post 08 Feb 2004, 11:34
View user's profile Send private message ICQ Number Reply with quote
Ralph



Joined: 04 Oct 2003
Posts: 86
Ralph 16 Apr 2004, 05:03
Hey,

I've been desperatly trying to get anything to assemble here, without any luck. All the examples provided here either error out with "unexpected end of file" or some macro error. Additionally %include% doesn't seem to work for me. I have to use absolute path names. I managed to patch together a version that assembled, but the .sys failed to load. I tried using fasm 1.52 for windows console as well as GUI, both produce the same errors.
I hate to ask something like this, but could anyone please provide me with a concise version that actually assembles or maybe tell me how to make these assemble?

This is the code I was trying to work with, it assembles but it wont load:

Code:
format PE DLL native 4.0 at 10000h
entry Start

include 'C:\tools\fasmw\INCLUDE\win32a.inc'     ;%include& doesn't work

section '.text' code readable executable notpageable
proc Start,pDriverObject,pusRegistryPath
        enter
        cli
        ; speaker ON
        in      al,61h
        or      al,11b
        out     61h,al
        sti
        mov     ecx,18000000h
@@:     loop    @B
        cli
        ; speaker OFF
        in      al,61h
        and     al,11111100b
        out     61h,al
        sti
.hal:   stdcall [imp_HalMakeBeep],1568
        mov     ecx,18000000h
@@:     loop    @B
        stdcall [imp_HalMakeBeep],0
.quit:  mov     eax,0C0000182h
        return
endp   ;i need this or else i get an unexpected end of file error

section '.rdata' readable notpageable

;data 12    ;this errors out with "symbol already defined", and I have no idea what 'data' does

  ImportLookup:
        dd rva szRead_port_uc
        dd rva szWrite_port_uc
        dd rva szHalmakebeep
        dd 0

;end data

section 'INIT' import readable notpageable   

        dd rva FirstThunk
        dd 0
        dd 0
        dd rva szHal_dll
        dd rva FirstThunk
        times 5 dd 0

FirstThunk:
        imp_READ_PORT_UCHAR         dd rva szRead_port_uc
        imp_WRITE_PORT_UCHAR        dd rva szWrite_port_uc
        imp_HalMakeBeep             dd rva szHalmakebeep
                                    dd 0

szHalmakebeep     dw 0
                  db 'HalMakeBeep',0
szRead_port_uc    dw 0
                  db 'READ_PORT_UCHAR',0
szWrite_port_uc   dw 0
                  db 'WRITE_PORT_UCHAR',0

szHal_dll db 'HAL.dll',0

section '.reloc' data fixups readable discardable    
    


Last edited by Ralph on 16 Apr 2004, 05:29; edited 1 time in total
Post 16 Apr 2004, 05:03
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 16 Apr 2004, 05:23
get old includes

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 16 Apr 2004, 05:23
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Ralph



Joined: 04 Oct 2003
Posts: 86
Ralph 16 Apr 2004, 05:33
Thanks. What version and where can I get them? Why wouldn't the new includes work? Is there a way to make them work? Any idea why %include% doesn't work?
Post 16 Apr 2004, 05:33
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.