So I am using Easy Coder IDE to help me along as I slowly relearn ASM. I try to compile and everything works fine. When I try to build the EXE however it gives the error "DBGHELP.lib not found" and lists all the places it wasn't found. I look in my code but don't see a reference to that lib file. Anyone use EasyCoder and can give advice?
Thanks!
Thanks!
I know nothing about Easy Coder.I suggest you to useRadasm!You can try.
Command_Prompt,
I don't use EasyCode but I have friends who do, from what I remember Libraries can be added to the project from the IDE (not just in your code). I would check for extensions to the command line under Project->Properties (iirc) and also check under the "Libraries" list in your Project window. Either one of those could be a place where the IDE could be harboring an additional .lib file.
ekin,
IDE's are an acquired taste. Everyone has one that they like for whatever reason they do. EasyCode is popular because it's the most "Visual" of the IDE's (I've heard it called the Visual Basic of Assembler IDE's). RadASM is popular as it supports the most assemblers while still having a decent amount of functionality. I personally still use Notepad or VI (depending on what system I'm on).
Regards,
Bryant Keller
I don't use EasyCode but I have friends who do, from what I remember Libraries can be added to the project from the IDE (not just in your code). I would check for extensions to the command line under Project->Properties (iirc) and also check under the "Libraries" list in your Project window. Either one of those could be a place where the IDE could be harboring an additional .lib file.
ekin,
IDE's are an acquired taste. Everyone has one that they like for whatever reason they do. EasyCode is popular because it's the most "Visual" of the IDE's (I've heard it called the Visual Basic of Assembler IDE's). RadASM is popular as it supports the most assemblers while still having a decent amount of functionality. I personally still use Notepad or VI (depending on what system I'm on).
Regards,
Bryant Keller
Thanks both of you for your replies. I downloaded RadAsm and tried to compile and build a sample project that was included and here is the error I got (below).
EasyCode also gave me a "can't find lib" error too for another project I tried. Do I need to set a path for these .lib files or do I need to D/L then separately?
C:\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" "Window.asm"
Assembling: Window.asm
C:\Masm32\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\Masm32\Lib" /OUT:"Window.exe" "Window.obj" "Window.res"
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
LINK : fatal error LNK1104: cannot open file "kernel32.lib"
Make error(s) occured.
Total compile time 741 ms
EasyCode also gave me a "can't find lib" error too for another project I tried. Do I need to set a path for these .lib files or do I need to D/L then separately?
C:\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" "Window.asm"
Assembling: Window.asm
C:\Masm32\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\Masm32\Lib" /OUT:"Window.exe" "Window.obj" "Window.res"
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
LINK : fatal error LNK1104: cannot open file "kernel32.lib"
Make error(s) occured.
Total compile time 741 ms
Nevermind! MASM did not create the lib files for some reason. I reinstalled and it works fine now! And now to start cranking out code!!! :P
Thats what we like to hear :)
For future reference: MASM32 (Hutch's repack of masm) creates some 'Environmental Variables', and since those are loaded by the OS during bootup, they do not become active until you reboot.
The same is true of OBJASM32 (Biterider's OOP framework for masm).
For future reference: MASM32 (Hutch's repack of masm) creates some 'Environmental Variables', and since those are loaded by the OS during bootup, they do not become active until you reboot.
The same is true of OBJASM32 (Biterider's OOP framework for masm).
OK so Masm works now and I put my procedure in the file to compile a dll. So encryption procedure is written (yay!) and I insert it into EasyCode's generic dll template (code below. Easycode includes the lib files and all in a separate step it seems, so no need to declare them here or anything). Now I am still new at this so I compile/build and no errors are reported. I try to call it from VB and it says no DLL entry point CryptyFile is found :shock:. I've never written a dll before...any hints :D? (i'm a n00b at this win32 asm thing so I'm sure there will be dumb and obvious errors).
Thanks!
; Start of file
.Const
.Data?
.Data
hInstEntry HINSTANCE NULL
.Code
DllEntryPoint Proc Private hInstance:HINSTANCE, dwReason:DWord, lpvReserved:LPVOID
.If dwReason == DLL_PROCESS_ATTACH
Mov Eax, hInstance
Mov hInstEntry, Eax
.ElseIf dwReason == DLL_PROCESS_DETACH
.ElseIf dwReason == DLL_THREAD_ATTACH
.ElseIf dwReason == DLL_THREAD_DETACH
.EndIf
Return TRUE
DllEntryPoint EndP
CryptyFile Proc Public InFileName:DWord, KeyFileName:DWord, OutFileName:DWord, KeyOffset:DWord, hInst:HINSTANCE
;// InFileName: path of file to be encrypted
;// KeyFileName: path of key file
;// OutFileName: path of file to create and store encrypted text
;// KeyOffset: Position in the key file to start reading
Local hInFile:DWord
Local hKeyFile:DWord
Local hOutFile:DWord
Local InputLength:DWord
Local KeyLength:DWord
Local BytesRead:DWord
ShortKeyTitle DB "Error with File Key", 0
ShortKeyMsg DB "Key file's length is too short.", 0
;// Buffers //
InFileBuffer DB 256 Dup (0) ;Store data read from source file
KeyFileBuffer DB 256 Dup (0) ;Store data read from key file
OutFileBuffer DB 256 Dup (0) ;Stores XORed Data for write to output file
Start:
;// Create the output file for write //
Invoke CreateFile, OutFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ;Create Output file
Mov hOutFile, Eax ;Store Output file's handle
;// Open Source file for read //
Invoke CreateFile, Addr InFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hInFile, Eax
;// Open key file for read //
Invoke CreateFile, Addr KeyFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hKeyFile, Eax
;// Get Input file's size and store
Invoke GetFileSize, hInFile, NULL
Mov InputLength, Eax
;// Get Key file's size and store
Invoke GetFileSize, hKeyFile, NULL ; eax stores key file's length
;// Compare to make sure sure Key file is long enough for source file
Sub Eax, KeyOffset ;(after substracting keyOffset from key file's length to account for starting point)
Cmp Eax, InputLength ;Compare
Jb _Key_Too_Short ;if shorter then give messagebox and exit
;// Start of reading and XORing loop
_ReadXOR:
;// Read 256 bytes from Source and Key files
Invoke ReadFile, hInFile, Addr InFileBuffer, 256, Addr BytesRead, NULL
Push BytesRead ;Push length of text read from source to stack
Push BytesRead ;Push length of text read from source to stack a second time
Invoke ReadFile, hInFile, Addr KeyFileBuffer, 256, Addr BytesRead, NULL
Pop Ecx ;Pop length of text read (from source) from stack to CX
Mov Si, 0
_XORLoop:
Mov Al, InFileBuffer ;Get first byte from source file to al
Mov Ah, KeyFileBuffer ;Get first byte from key file to ah
Xor Ah, Al ;xor and store result in ah
Mov OutFileBuffer, Ah ;move XOR'd value to output string
Inc Si ;increase SI by 1
Loop _XORLoop ;Loop for length of string read
;// Write string to file
Pop Ecx
Invoke WriteFile, hOutFile, Addr OutFileBuffer, Ecx, Addr BytesRead, NULL
Cmp Ecx, 256 ;Does # of bytes written=256?
Je _ReadXOR ;If not then EOF was reached, so jump to exit. if yes then do another iteration of read and XORing
Mov Eax, BytesRead ; return written byte count
Jmp _Done
_Key_Too_Short:
Invoke MessageBox, hInst, Addr ShortKeyMsg, Addr ShortKeyTitle, MB_OK
_Done:
Invoke CloseHandle, hInFile
Invoke CloseHandle, hOutFile
Invoke CloseHandle, hKeyFile
Ret
CryptyFile EndP
End DllEntryPoint
;End of file
Thanks!
; Start of file
.Const
.Data?
.Data
hInstEntry HINSTANCE NULL
.Code
DllEntryPoint Proc Private hInstance:HINSTANCE, dwReason:DWord, lpvReserved:LPVOID
.If dwReason == DLL_PROCESS_ATTACH
Mov Eax, hInstance
Mov hInstEntry, Eax
.ElseIf dwReason == DLL_PROCESS_DETACH
.ElseIf dwReason == DLL_THREAD_ATTACH
.ElseIf dwReason == DLL_THREAD_DETACH
.EndIf
Return TRUE
DllEntryPoint EndP
CryptyFile Proc Public InFileName:DWord, KeyFileName:DWord, OutFileName:DWord, KeyOffset:DWord, hInst:HINSTANCE
;// InFileName: path of file to be encrypted
;// KeyFileName: path of key file
;// OutFileName: path of file to create and store encrypted text
;// KeyOffset: Position in the key file to start reading
Local hInFile:DWord
Local hKeyFile:DWord
Local hOutFile:DWord
Local InputLength:DWord
Local KeyLength:DWord
Local BytesRead:DWord
ShortKeyTitle DB "Error with File Key", 0
ShortKeyMsg DB "Key file's length is too short.", 0
;// Buffers //
InFileBuffer DB 256 Dup (0) ;Store data read from source file
KeyFileBuffer DB 256 Dup (0) ;Store data read from key file
OutFileBuffer DB 256 Dup (0) ;Stores XORed Data for write to output file
Start:
;// Create the output file for write //
Invoke CreateFile, OutFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ;Create Output file
Mov hOutFile, Eax ;Store Output file's handle
;// Open Source file for read //
Invoke CreateFile, Addr InFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hInFile, Eax
;// Open key file for read //
Invoke CreateFile, Addr KeyFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hKeyFile, Eax
;// Get Input file's size and store
Invoke GetFileSize, hInFile, NULL
Mov InputLength, Eax
;// Get Key file's size and store
Invoke GetFileSize, hKeyFile, NULL ; eax stores key file's length
;// Compare to make sure sure Key file is long enough for source file
Sub Eax, KeyOffset ;(after substracting keyOffset from key file's length to account for starting point)
Cmp Eax, InputLength ;Compare
Jb _Key_Too_Short ;if shorter then give messagebox and exit
;// Start of reading and XORing loop
_ReadXOR:
;// Read 256 bytes from Source and Key files
Invoke ReadFile, hInFile, Addr InFileBuffer, 256, Addr BytesRead, NULL
Push BytesRead ;Push length of text read from source to stack
Push BytesRead ;Push length of text read from source to stack a second time
Invoke ReadFile, hInFile, Addr KeyFileBuffer, 256, Addr BytesRead, NULL
Pop Ecx ;Pop length of text read (from source) from stack to CX
Mov Si, 0
_XORLoop:
Mov Al, InFileBuffer ;Get first byte from source file to al
Mov Ah, KeyFileBuffer ;Get first byte from key file to ah
Xor Ah, Al ;xor and store result in ah
Mov OutFileBuffer, Ah ;move XOR'd value to output string
Inc Si ;increase SI by 1
Loop _XORLoop ;Loop for length of string read
;// Write string to file
Pop Ecx
Invoke WriteFile, hOutFile, Addr OutFileBuffer, Ecx, Addr BytesRead, NULL
Cmp Ecx, 256 ;Does # of bytes written=256?
Je _ReadXOR ;If not then EOF was reached, so jump to exit. if yes then do another iteration of read and XORing
Mov Eax, BytesRead ; return written byte count
Jmp _Done
_Key_Too_Short:
Invoke MessageBox, hInst, Addr ShortKeyMsg, Addr ShortKeyTitle, MB_OK
_Done:
Invoke CloseHandle, hInFile
Invoke CloseHandle, hOutFile
Invoke CloseHandle, hKeyFile
Ret
CryptyFile EndP
End DllEntryPoint
;End of file
Not only you have to make the CryptyFile function public, but you have to export it as well.
D'oh! I suppose making it public is simple but how do I export it? :sad:
*added* Wait isn't it public already? I declared it as "CryptyFile Proc Public" or do I have to do something else, too?
*added* Wait isn't it public already? I declared it as "CryptyFile Proc Public" or do I have to do something else, too?
Find out what .DEF files are.
OK, I've got my def file now and it has been included. Everything compiles and gives no errors. I load VB up and call my proc from it and...VB crashes :sad:. So to see what could be going wrong I comment out everything but a message box line in my .dll to see if it is a problem with the code I wrote. It compiles and crashes again when VB calls it. so now I effectively have only the following code in my dll: (Below) I'm thinking there is something going wrong when VB loads the dll or tries to access it but what? Any guesses? Sorry about the noob questions, guys. I am still...well new...at win32 asm.
.Const
.Data?
.Data
Msg DB "Inside Crypty Proc now", 0
MsgTitle DB "Test title", 0
hInstEntry HINSTANCE NULL
.Code
DllEntryPoint Proc Private hInstance:HINSTANCE, dwReason:DWord, lpvReserved:LPVOID
.If dwReason == DLL_PROCESS_ATTACH
Mov Eax, hInstance
Mov hInstEntry, Eax
.ElseIf dwReason == DLL_PROCESS_DETACH
.ElseIf dwReason == DLL_THREAD_ATTACH
.ElseIf dwReason == DLL_THREAD_DETACH
.EndIf
Return TRUE
DllEntryPoint EndP
CryptyFile Proc Public InFileName:DWord, KeyFileName:DWord, OutFileName:DWord, KeyOffset:DWord, hInst:HINSTANCE
Start:
Invoke MessageBox, hInst, Addr Msg, Addr MsgTitle, MB_OK
Ret
CryptyFile EndP
End DllEntryPoint
.Const
.Data?
.Data
Msg DB "Inside Crypty Proc now", 0
MsgTitle DB "Test title", 0
hInstEntry HINSTANCE NULL
.Code
DllEntryPoint Proc Private hInstance:HINSTANCE, dwReason:DWord, lpvReserved:LPVOID
.If dwReason == DLL_PROCESS_ATTACH
Mov Eax, hInstance
Mov hInstEntry, Eax
.ElseIf dwReason == DLL_PROCESS_DETACH
.ElseIf dwReason == DLL_THREAD_ATTACH
.ElseIf dwReason == DLL_THREAD_DETACH
.EndIf
Return TRUE
DllEntryPoint EndP
CryptyFile Proc Public InFileName:DWord, KeyFileName:DWord, OutFileName:DWord, KeyOffset:DWord, hInst:HINSTANCE
Start:
Invoke MessageBox, hInst, Addr Msg, Addr MsgTitle, MB_OK
Ret
CryptyFile EndP
End DllEntryPoint
What calling convention does VB use?
BTW: as you can see, high-level languages 'hide' many things from coder's eyes. In asm you have to know much more than a HLL coder ;)
BTW: as you can see, high-level languages 'hide' many things from coder's eyes. In asm you have to know much more than a HLL coder ;)
VB uses _stdcall as far as I know. The sad thing is that I have this procedure working in the dos-asm version and it works great. I just can't get it to work in windows dll version. I timed how long it took the VB version as well and it took ~35 seconds to run through a 10mb file while the dos asm version did the same thing in just over 2 seconds. Needless to say I'm sold on the asm version...if only I can get it to work here...Gaaaaaaaaah!
If you could attach the VB code along with the ASM dll anyone who whishes to should be able to help you find the cause ^^
Try the following line.
Maybe, just maybe, the MessageBox API could not digest the handle of an instance instead of the expected handle of a window (0 being allowed).
Raymond
Invoke MessageBox, 0, Addr Msg, Addr MsgTitle, MB_OK
Maybe, just maybe, the MessageBox API could not digest the handle of an instance instead of the expected handle of a window (0 being allowed).
Raymond
Good call and thanks, Raymond! The message box pops up now (woot!) but when I click the ok button after to close the message box VB still crashes :sad:
the vb code as it is now (for dll testing) is simply as shown below with only a single window and one command button (to call the dll).
Option Explicit
Private Declare Sub CryptyFile Lib "E:\Crypty DLL\Debug\Crypty.dll" (ByRef Infile As String, ByRef Keyfile As String, ByRef Outfile As String, ByVal Offset As Long)
Private Sub Command1_Click()
Call CryptyFile("c:\source.txt", "C:\key.txt", "C:\out.txt", 1)
End Sub
the vb code as it is now (for dll testing) is simply as shown below with only a single window and one command button (to call the dll).
Option Explicit
Private Declare Sub CryptyFile Lib "E:\Crypty DLL\Debug\Crypty.dll" (ByRef Infile As String, ByRef Keyfile As String, ByRef Outfile As String, ByVal Offset As Long)
Private Sub Command1_Click()
Call CryptyFile("c:\source.txt", "C:\key.txt", "C:\out.txt", 1)
End Sub
Sweet! I got the message boxes to work now and the file name arguments are processed correctly. VB Code is:
Option Explicit
Private Declare Sub CryptyFile Lib "E:\Crypty DLL\Debug\Crypty.dll" (ByVal Infile As String, ByVal Keyfile As String, ByVal Outfile As String, Offset As Long)
Private Sub Command1_Click()
Call CryptyFile("c:\source.txt", "C:\key.txt", "C:\out.txt", 1)
End Sub
and the messagebox invokes are:
Invoke MessageBox, 0, OutFileName, Addr Title, MB_OK
Thanks so far guys! I was doubting I whether I could get even this far. Hopefully the next steps will be a breeze now!
Option Explicit
Private Declare Sub CryptyFile Lib "E:\Crypty DLL\Debug\Crypty.dll" (ByVal Infile As String, ByVal Keyfile As String, ByVal Outfile As String, Offset As Long)
Private Sub Command1_Click()
Call CryptyFile("c:\source.txt", "C:\key.txt", "C:\out.txt", 1)
End Sub
and the messagebox invokes are:
Invoke MessageBox, 0, OutFileName, Addr Title, MB_OK
Thanks so far guys! I was doubting I whether I could get even this far. Hopefully the next steps will be a breeze now!
Retrospective wisdom:
Whenever I stumble, whenever I feel trapped, whenever I am challenged by problems, whenever I am 'pressing my envelope', I have learned to view that as a positive experience, regardless of the actual outcome... it means I'm about to learn something, I'm about to grow.
If you're not challenged by what you do, then you are stagnating, decaying, dying. Keep pressing that envelope, expand your horizons !!
Whenever I stumble, whenever I feel trapped, whenever I am challenged by problems, whenever I am 'pressing my envelope', I have learned to view that as a positive experience, regardless of the actual outcome... it means I'm about to learn something, I'm about to grow.
If you're not challenged by what you do, then you are stagnating, decaying, dying. Keep pressing that envelope, expand your horizons !!
One last question (hopefully). So everything is working well. no crashes or anything, files encrypt and decrypt fine :D. I am however still trying to get to get one last thing working. One of the arguments is a DWord (Long) that tells where in the key file to start reading. I call this and then try to read and I get a readbyte length of 0. Here is my code (or at least the parts that matter): Opening and writing works fine unless I try to set file pointer. Then it reads a length of 0 and doesn't write. I get the feeling this will be something simple (read stupid) that I overlooked. Any ideas would be great as this should pretty much be the last problem before my first ever win32 asm library is set to go :D!
.data
...
variables ect...
...
.code
OffsetTest Proc Public InFileName:DWord, OutFileName:DWord, KeyOffset:DWord
;// Open Source file for read //
Invoke CreateFile, InFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hInFile, Eax
;// Create the output file for write //
Invoke CreateFile, OutFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ;Create Output file
Mov hOutFile, Eax ;Store Output file's handle
; Set file pointer in source file
Invoke SetFilePointer, hInFile, KeyOffset, NULL, FILE_BEGIN
Cmp BytesRead, 0FFFFFFFFH
Je Read_Done
_Read:
;// Read 256 bytes from Source and Key files
Invoke ReadFile, hInFile, Addr InFileBuffer, 256, Addr BytesRead, NULL
Cmp BytesRead, FALSE ;make sure data was read
Je Read_Done ;If not then exit
;writing routine stuff...
; Here the program always goes to Read_Done and the output file length is always 0
Read_Done:
... end of proc stuff
.data
...
variables ect...
...
.code
OffsetTest Proc Public InFileName:DWord, OutFileName:DWord, KeyOffset:DWord
;// Open Source file for read //
Invoke CreateFile, InFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL
Mov hInFile, Eax
;// Create the output file for write //
Invoke CreateFile, OutFileName, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ;Create Output file
Mov hOutFile, Eax ;Store Output file's handle
; Set file pointer in source file
Invoke SetFilePointer, hInFile, KeyOffset, NULL, FILE_BEGIN
Cmp BytesRead, 0FFFFFFFFH
Je Read_Done
_Read:
;// Read 256 bytes from Source and Key files
Invoke ReadFile, hInFile, Addr InFileBuffer, 256, Addr BytesRead, NULL
Cmp BytesRead, FALSE ;make sure data was read
Je Read_Done ;If not then exit
;writing routine stuff...
; Here the program always goes to Read_Done and the output file length is always 0
Read_Done:
... end of proc stuff
Do you close your files somewhere?
Raymond
Raymond