____________________________________________________________________________________________
             ...:: Another Method to travel Directorys Downwards in Win32 ::...
                                    - by DiA /auXnet -
                                        [GermanY]
____________________________________________________________________________________________

Hello folkz,
before I describe the Method and the Code I wanna say don't grumble about the tut -> it's my
first tut =)     Have fun...


+++++Disclaimer+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+I am NOT responsible for any damage that you do! You can need the code however you want...+
+My motherlanguage is not English, I hope you understand what I mean.                      +
+Feel FREE to write any Comments to                                                        +
+                                       DiA_hates_machine@gmx.de                           +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



.........................
.                       .
. Index: _1_  :  Method .
.                       .
.        _2_  :  Code   .
.                       .
.........................


____________________________________________________________________________________________
-----_1_-----Method-------------------------------------------------------------------------
____________________________________________________________________________________________

Needed API's: o GetCommandLineA      ;get da commandline  it's da name of the prog who runs
              o lstrcpyA             ;copy the commandline to a variable
              o SetCurrentDirectoryA ;change da current dir

What must we do:
- read the CommandLine
- copy it to a variable
- find the '.' in the CommandLine(Variable)
- clear all after the '.' 
* find the '\' in the CommandLine(Variable)
- clear all after the '\'
- if found ':' exit the procedure
- set the current directory
- go to *
- whatever you want after the travel :)

Command Line looks like these:
1. C:\TASM32\MyProgs\DotDot.EXE"
2. C:\TASM32\MyProgs\DotDot
3. C:\TASM32\MyProgs\
4. C:\TASM32\
5. C:\


I think when you see the code you understand it better ;) [My FIRST Tut]

____________________________________________________________________________________________
--------------------------------------------------------------------------------------------
____________________________________________________________________________________________





;___________________________________________________________________________________________
;-----_2_-----Code-----Cut------------------------------------------------------------------
;___________________________________________________________________________________________
;
;Ok here comes da code...
;compile it with TASM32 (I think you can do this ;)
; -DiA- /auXnet (c)02

.386					;for 386ers +
.model flat				;no segmentZ yeah
jumps					;TASM rulez

extrn GetCommandLineA:PROC		;needed APIs
extrn lstrcpyA:PROC
extrn SetCurrentDirectoryA:PROC
extrn MessageBoxA:PROC			;only to show you that it workz
extrn ExitProcess:PROC			;go home

.data
oTitle		db 'Another way to cd..     DiA /auXnet',0
oCommandLine	db 260d dup (0)		;define place for da CommandLine

.code
start:					;3 2 1 go!

call GetCommandLineA			;get it   now in eax

mov esi,offset oCommandLine		;save there
inc eax					;fuck the "
push eax				;from CommandLine to
push esi				;variable
call lstrcpyA				;copy it

GetPoint:				;here comes da GetPoint procedure
cmp byte ptr [esi],'.'			;find it
jz ClearAfter				;when it found jmp 2 ClearAfter

inc esi					;scan next palce
jmp GetPoint				;repeat it

ClearAfter:				;fuck it
mov dword ptr [esi],00000000h		;all

GetSlash:				;get the '\'
cmp byte ptr [esi],'\'			;is it?
jz FuckIt				;clear all after the slash

cmp byte ptr [esi],':'			;C:\ reach?
jz exit					;C:\ -> cd.. -> suckZ

dec esi					;go backward -1
jmp GetSlash				;go on

FuckIt:					;heh
inc esi					;don't clear the '\'
mov dword ptr [esi],00000000h		;clear
sub esi,2				;go before the '\'

mov edx,offset oCommandLine		;there is the next dir downwards
push edx
call SetCurrentDirectoryA		;set it

call Message				;only to show

jmp GetSlash				;travel again

exit:					;here you can do whatever you want
xor eax,eax
push eax
call ExitProcess			;I exit and go home...

Message:				;procedure
mov eax,offset oTitle
mov edx,offset oCommandLine		;see it
xor ebx,ebx
push ebx
push eax
push edx
push ebx
call MessageBoxA
ret					;return

end start

;___________________________________________________________________________________________
;----------cut------------------------------------------------------------------------------
;___________________________________________________________________________________________




Allright, thats all...
I hope you understand anything, Code On!
Thank you and good night   -DiA- (c)02