flat assembler
Message board for the users of flat assembler.

Index > Windows > bad image error

Author
Thread Post new topic Reply to topic
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed
Hi, I'm running on win2k advanced server and I keep getting this error from 2k about my dll I'm trying to test:
Quote:
spkr_t.exe - Bad Image : The application or DLL C:\Inetpub\wwwroot\speaker.dll is not a valid Windows image. Please check this against your installation diskette.
Here's the test prog source:
Code:
format PE GUI 4.0
entry WinMain

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
length dd 44010

section '.code' readable executable
proc WinMain, hInst, hPrevInst, lpCmdLine, nCmdShow
     invoke Speaker, dword[length]
     return
endp

section '.idata' import data readable writeable
library spkr, 'speaker.dll'

import spkr,\
       Speaker, 'Speaker'

section '.reloc' fixups data discardable    

And the dll source:
Code:
;Copyright © 2004 Peter Moore. All rights reserved

;Redistribution and use in source and binary forms, with or without modification,
;are permitted provided that the following conditions are met:
;
;
;   1. Redistributions of source code must retain the above copyright notice,
;      this list of conditions and the following disclaimer.
;   2. Redistributions in binary form must reproduce the above copyright notice,
;      this list of conditions and the following disclaimer in the documentation
;      and/or other materials provided with the distribution.
;   3. The name of the author may not be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
;WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
;PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
;OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
;OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
;ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.;

format PE GUI 4.0 DLL
entry DllStart

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
nop

section '.code' code readable executable
proc DllStart, hInstDLL, fdwReason, lpvReserved
     enter
     invoke GetModuleHandle, 0
     mov eax, TRUE
     return
endp

SpeakerOn:
     in al, 0x61
     and al, 0xFC
     out 0x61, al
     ret

SpeakerOff:
     in al, 0x61
     or al, 2
     out 0x61, al
     ret

proc Speaker, length
     call SpeakerOn
     mov cx, word [length]
     spkrLoop:
        call SpeakerOff
        call SpeakerOn
     loop spkrLoop
     mov eax, 0
     return
endp

section '.idata' import data readable writeable
library kernel, 'kernel32.dll'
import kernel, GetModuleHandle, 'GetModuleHandleA'

section '.edata' export data readable
export 'speaker.dll',\
       Speaker, 'Speaker',\
       SpeakerOn, 'SpeakerOn',\
       SpeakerOff, 'SpeakerOff'

section '.reloc' fixups data discardable    

Hope someone can help me. Thx.

-Consumed


Last edited by Consumed on 04 Nov 2004, 00:13; edited 2 times in total
Post 03 Nov 2004, 09:41
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16843
Location: In your JS exploiting you and your system
revolution
You have no "ret" or "return" in your proc's. I think this may a problem.

Also Win NT and up (2K and XP) do not allow "in" and "out" instructions to most ports. they are privileged instructions. I am not sure about the speaker port perhaps that port is open. If not you can try USERPORT. I can't remember where I downloaded it from but it has been very useful for me when I use the parallel port for direct I/O transfer.

You can set the access for all the ports as you need. And you can set how the access is applied, for eg. you can set some ports to be always open to every program and set other ports just for access for your program etc.


Description: Give userland I/O access
Download
Filename: userport.zip
Filesize: 29.84 KB
Downloaded: 145 Time(s)



Last edited by revolution on 10 Nov 2008, 10:49; edited 2 times in total
Post 03 Nov 2004, 10:37
View user's profile Send private message Visit poster's website Reply with quote
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed
I added the returns and I'm still getting the bad image error. And I tried out some of that speaker code in a com app and it worked fine. I don't know what's up with this thing but it sure is stumping me. Confused
Post 03 Nov 2004, 17:54
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
You need to sort the exported functions. Case sensitive.
Post 03 Nov 2004, 17:59
View user's profile Send private message Yahoo Messenger Reply with quote
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed
I've tried exporting the functions in several different orders, yet I still get the same error.
Post 03 Nov 2004, 19:41
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
One more thing: you need to import at least one function from kernel32 API in order to have the dll loaded.

Look at this thread: http://board.flatassembler.net/topic.php?t=428
Post 03 Nov 2004, 21:54
View user's profile Send private message Yahoo Messenger Reply with quote
Consumed



Joined: 30 Sep 2004
Posts: 13
Location: Right behind you
Consumed
Ok, the dll is valid now. Though the pc speaker isn't making any sound. Sad
Post 04 Nov 2004, 00:13
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16843
Location: In your JS exploiting you and your system
revolution
You don't have any delays between SpeakerOn and SpeakerOff. Depending on your PC the loop is probably running at MHz.
Post 04 Nov 2004, 05:31
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
hello, can i recommend a delay less sound output code?

http://board.flatassembler.net/topic.php?t=2432

Smile

well the topic says bad image
Post 04 Nov 2004, 07:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2019, Tomasz Grysztar.

Powered by rwasa.