Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-2008, 10:27 AM
maple23 maple23 is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
maple23 is on a distinguished road
Default Assembler: finding shared directories problem

For my next project, I am making a program which searches for all of the shared directories on a computer. My idea is if the directory contains the string "share", then it must be shared.

Program Breakdown:
  1. change directory to C:\ drive
  2. find first directory
  3. convert directory name to upper-case
  4. compare upper-case directory character-by-character for the string "SHARE"
  5. if the string is found, display the directory name (with a message box)
  6. if the string is not found, goto step 2
  7. if there are no more directories on the C:\ drive, exit


Each one of these functions works on their own (converting to upper-case, looking for "SHARE", enumerating all directories on the C:\ drive). When I put them all together, I get errors. The program executes fine until it finds a shared directory, then it fails.

Any idea what's wrong with my code?

Code:
.386
.MODEL FLAT

EXTRN	FindFirstFileA		:PROC
EXTRN	MessageBoxA		:PROC
EXTRN	FindNextFileA		:PROC
EXTRN	FindClose		:PROC
EXTRN	SetCurrentDirectoryA	:PROC
EXTRN	lstrcpyA		:PROC

MAX_PATH			equ	256

WIN32_FIND_DATA STRUC
	dwFileAttributes	dd ?
	ftCreationTime		dq ?
	ftLastAccessTime	dq ?
	ftLastWriteTime		dq ?
	nFileSizeHigh		dd ?
	nFileSizeLow		dd ?
	Reserved0		dd ?
	Reserved1		dd ?
	cFileName		db MAX_PATH dup(?)
	cAlternateFileName	db 14 dup(?)
WIN32_FIND_DATA ENDS

.DATA
	hFind		dd ?
	szMask		db "*.*", 0
	szBackDir	db "..", 0
	szDirectory	db MAX_PATH dup(?)
	win32FindData	WIN32_FIND_DATA <?>
	szDrive		db "C:\", 0

.CODE
MAIN:
	push	offset szDrive
	call	SetCurrentDirectoryA

findFirstFile:
	push	offset win32FindData
	push	offset szMask
	call	FindFirstFileA				; find first file in C:\ drive
	mov	[hFind], eax

checkType:
	cmp	eax, 0					; no files?
	je	downDirectory
	cmp	byte ptr [win32FindData.cFileName], "."
	je	findNextFile
	cmp	[win32FindData.dwFileAttributes], 10h
	je	upDirectory
	cmp	[win32FindData.dwFileAttributes], 30h
	je	upDirectory

findNextFile:
	push	offset win32FindData
	push	[hFind]
	call	FindNextFileA
	jmp	checkType

upDirectory:
	push	offset win32FindData.cFileName
	push	offset szDirectory
	call	lstrcpyA

	mov	eax, offset szDirectory

	cmp	byte ptr [eax], 90				; already uppercase? (90 = Z)
	jle	toUpperCase
	xor	byte ptr [eax], 32				; convert

toUpperCase:
	inc	eax
	cmp	byte ptr [eax], 0				; at end of string?
	je	endOfString
	cmp	byte ptr [eax], 90				; already uppercase?
	jle	toUpperCase
	xor	byte ptr [eax], 32				; convert
	jmp	toUpperCase

endOfString:
	mov	eax, 0
	mov	eax, offset szDirectory

searchShare:
	inc	eax
	cmp	byte ptr [eax], 0				; end of string?
	jne	noShare
	cmp	byte ptr [eax], "S"				; check for S
	jne	searchShare
	cmp	byte ptr [eax + 1], "H"				; check for H
	jne	searchShare
	cmp	byte ptr [eax + 2], "A"				;
	jne	searchShare
	cmp	byte ptr [eax + 3], "R"				;
	jne	searchShare
	cmp	byte ptr [eax + 4], "E"				;
	jne	searchShare

	push	0
	push	offset szDirectory
	push	offset szDirectory
	push	0
	call	MessageBoxA					; display directory

noShare:
	push	offset szDirectory
	call	SetCurrentDirectoryA
	cmp	eax, 0
	je	findNextFile

	push	hFind
	jmp	findFirstFile

downDirectory:
	push	offset szBackDir
	call	SetCurrentDirectoryA
	push	[hFind]
	call	FindClose
	pop	[hFind]
	cmp	[hFind], 0
	jne	findNextFile

theEnd:
	ret
	END	MAIN
I am using TASM 5.0 and TLINK32 to compile.

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-07-2008, 11:07 AM
v0id's Avatar   
v0id v0id is online now
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,004
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default Re: Assembler: finding shared directories problem

I'm not a Windows programmer, so I can't help much, but have you tried using a debugger? You can use "debug" which comes with Windows, or use OllyDbg, if you prefer a graphical user interface.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 01:01 PM
maple23 maple23 is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
maple23 is on a distinguished road
Default Re: Assembler: finding shared directories problem

Yes, I have Olly Debug, but I can't seem to get anywhere with it... I'm new with debuggers, and am having trouble setting a breakpoint before the program displays a messagebox.

Last edited by maple23; 05-07-2008 at 01:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 02:56 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 3,471
Last Blog:
Web slideshow in JavaS...
Rep Power: 30
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Assembler: finding shared directories problem

Does the code compile? If not, it's a typo. If it does, you know it's some sort of runtime error - in that case, debug the code line by line, to check it executes in the way you want it to.
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-08-2008, 12:48 AM
maple23 maple23 is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
maple23 is on a distinguished road
Default Re: Assembler: finding shared directories problem

Yes, the code compiles. I will work try to debug the program tomorrow.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-08-2008, 02:49 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 3,471
Last Blog:
Web slideshow in JavaS...
Rep Power: 30
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Assembler: finding shared directories problem

Good idea - debuggers really help to make a programmer's job easier, especially when handling errors.
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 10:30 AM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads