Wilfrido
Wilfrido

Reputation: 11

How can I delete a file with assembly (x86) on Windows?

I created a program that can create files and update them, but now I want to delete them, but I haven't found a solution.

I am using the Irvine Library and there I found a method to create files, but there is no method to delete them.

I have heard about using int 80h and int 41h, but nothing works.

Upvotes: 0

Views: 1092

Answers (1)

Cody Gray
Cody Gray

Reputation: 244732

Irvine32 is a library designed to make it easier to write Windows applications using MASM. If there is no built-in function to delete a file, you will need to call the function provided by the Windows API, DeleteFile. The code might look like this:

push   DWORD PTR [pszFileName]   ; push a pointer to the name of the file to be deleted
call   DeleteFile                ; returns 0 on failure; non-zero on success

where pszFileName is a pointer to an array of WORD-sized characters, terminated by a NUL (0) character, which will be treated as a string containing the name of the file to be deleted.

Because the DeleteFile function is exported by Kernel32, you will need to link to kernel32.lib using INCLUDELIB or a linker option. Also, if you have a windows.inc include file, then you should include that to give you access to the function's prototype. Otherwise, you can define it yourself:

EXTRN _DeleteFileW@4:PROC

(assuming a 32-bit target; on 64-bit, it would be _DeleteFile@8, since pointers are 8 bytes in size).

Upvotes: 1

Related Questions