flat assembler
Message board for the users of flat assembler.
Index
> Windows > Renaming Files (using MSVCRT)? |
Author |
|
edfed 07 Mar 2008, 19:32
[erf mode]
to modify the name, right clic on icon, then, rename. or F2 or ren file.axt file.ext [/erf mode] i insert a general question in this thread. how to modify, access, create, delete, read, write etc files in a "FILE SYSTEM independant" way? is it possible? |
|||
07 Mar 2008, 19:32 |
|
wisepenguin 07 Mar 2008, 19:48
hello,
this works successfully for me using latest fasm 1.67.26 Code: start: cinvoke printf, strMain cinvoke rename, strOld, strNew cinvoke exit, 0 section '.data' data readable writeable strMain db 'Renaming cool.txt to mool.txt ',0 strOld db 'cool.txt',0 strNew db 'mool.txt',0 you need to null terminate strings manually in FASM have a good day |
|||
07 Mar 2008, 19:48 |
|
optiplex 07 Mar 2008, 20:05
Thank you wisepenguin.
But it didnt work for me Im also using the latest fasm 1.67.26, but the code doesnt work. Code: ; rename example ; by optiplex format PE CONSOLE 4.0 include 'INCLUDE\win32a.inc' start: cinvoke printf, strMain cinvoke rename, strOld, strNew cinvoke getchar, 0 cinvoke exit, 0 section '.data' data readable writeable strMain db 'Renaming cool.txt to mool.txt ',0 strOld db 'cool.txt',0 strNew db 'mool.txt',0 section '.idata' import data readable writeable library msvcrt, 'msvcrt.dll' import msvcrt,\ printf, 'printf',\ getchar, 'getchar',\ rename, 'rename',\ exit, 'exit' Any idea? Thanks again. |
|||
07 Mar 2008, 20:05 |
|
wisepenguin 07 Mar 2008, 20:18
i ran mine on windows xp, with the following set up
my documents\test.exe (your code) my documents\cool.txt so the file to rename is in the same directory as the program. but your first code hard coded it to "C:\cool.txt". if you like change it back to C:\cool.txt and make sure C:\cool.txt exists initially. but i can still confirm, it works successfully here by null terminating the strings. i hope this helps, or you find the fault if it doesn't. |
|||
07 Mar 2008, 20:18 |
|
dap 07 Mar 2008, 20:33
optiplex wrote: Thank you wisepenguin. 1 - getchar() doesn't require any parameter 2 - you don't need to call exit() here, you can use the instruction "ret" instead but remember that EAX must contain the return value of main() |
|||
07 Mar 2008, 20:33 |
|
optiplex 08 Mar 2008, 07:27
Okay, I got it working now
Thank wisepenguin, and thank you too dap for the tips |
|||
08 Mar 2008, 07:27 |
|
wisepenguin 08 Mar 2008, 11:51
anytime.
what was the problem in the end ? |
|||
08 Mar 2008, 11:51 |
|
optiplex 08 Mar 2008, 21:34
I think it was because of the pathes, i used C:\cool.txt > C:\mool.txt, but when I had them in the same directory as the program, like you did, it worked for me.
|
|||
08 Mar 2008, 21:34 |
|
Goplat 09 Mar 2008, 03:29
Why is this in the DOS forum?
|
|||
09 Mar 2008, 03:29 |
|
dap 09 Mar 2008, 10:02
This works on my computer :
Code: format PE console 4.0 entry start include 'win32a.inc' section '.text' code readable executable start: push ebp mov ebp, esp push new push old call [rename] pop ecx ecx ; rename() returns zero if the operation succeeds test eax, eax jnz .failure push success call [puts] pop ecx .failure: pop ebp xor eax, eax ret section '.rdata' data readable old db 'C:\Documents and Settings\Bastien\Bureau\cool.txt', 0 new db 'C:\Documents and Settings\Bastien\Bureau\mool.txt', 0 success db 'Success', 0 section '.idata' data readable import library msvcrt, 'msvcrt.dll' import msvcrt, \ rename, 'rename', \ puts, 'puts' |
|||
09 Mar 2008, 10:02 |
|
revolution 09 Mar 2008, 10:05
You can also use the API MoveFile or MoveFileEx, no need to use msvcrt.
|
|||
09 Mar 2008, 10:05 |
|
DOS386 10 Mar 2008, 06:46
..
Last edited by DOS386 on 12 Mar 2008, 01:02; edited 1 time in total |
|||
10 Mar 2008, 06:46 |
|
revolution 10 Mar 2008, 06:53
Okay, no problem, if ever I manage to catch a mod roaming around doing nothing I will be sure to grab him by the collar point him here.
|
|||
10 Mar 2008, 06:53 |
|
asmrox 10 Mar 2008, 13:34
when you use pe format, why dont u call from kernel32? MoveFile.
and you dont have to 'exit'. Pogram is loading by call from CsrCreateThread, and must return to CsrExitThread. Code: format PE CONSOLE 4.0
entry start also entrypoint is not needed. format pe console is enought. |
|||
10 Mar 2008, 13:34 |
|
revolution 10 Mar 2008, 13:38
asmrox wrote: also entrypoint is not needed. format pe console is enought. |
|||
10 Mar 2008, 13:38 |
|
asmrox 10 Mar 2008, 17:20
in exe no. Program will start executing from executable section, or smth like tat
|
|||
10 Mar 2008, 17:20 |
|
revolution 10 Mar 2008, 17:22
asmrox wrote: in exe no. Program will start executing from executable section, or smth like tat |
|||
10 Mar 2008, 17:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.