-
Notifications
You must be signed in to change notification settings - Fork 0
/
wipe.asm
171 lines (145 loc) · 4.23 KB
/
wipe.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
; simple three pass rm for FreeBSD i386, same method as rm -P
; nasm -f elf wipe.asm ; ld -s -o wipe wipe.o
section .data
fsize dd 0
asize dd 0
fname dd 0
count db 0
section .bss
buffersize equ 8192
buffer resb buffersize
section .text
global _start
_start:
pop eax ; arg count
pop eax ; program name
pop ecx ; file to wipe
jecxz .sparms
pop eax
or eax,eax ; too many args?
jne .sparms
push dword 2 ; read/write
push ecx
mov eax,5 ; open
push eax
int 0x80
jc .fail
mov ebp,eax
mov [fname],ecx
push dword 2 ; move to eof
push dword 0
push dword 0
push ebp
mov eax,478 ; lseek
push eax
int 0x80
jc .fail
mov [fsize],eax
mov [asize],eax
push dword 0 ; move to sof
push dword 0
push dword 0
push ebp
mov eax,478 ; lseek
push eax
int 0x80
jc .fail
mov dword [count],0 ; zero our counter
call .filledz
jmp .loopy
.fail:
push dword 5
push dword logo2
push dword 1
mov eax,4 ; write
push eax
int 0x80
mov eax,1 ; exit
push eax
int 0x80
.sparms:
push dword 21
push dword logo
push dword 1 ; stdout
mov eax,4 ; write
push eax
int 0x80
mov eax,1 ; exit
push eax
int 0x80
.loopy:
push dword 5
push dword 8192
push dword buffer
push ebp
mov eax,4 ; write
push eax
int 0x80
test eax,eax ; test for eax -1 instead of carry
js .fail
push ebp
mov eax,95
push eax
int 0x80
test eax,eax
js .fail
push dword 0 ; move to sof
push dword 0
push dword 0
push ebp
mov eax,478 ; lseek
push eax
int 0x80
mov ecx,[fsize] ; subtract what we wrote from the org fsize
sub ecx,8192
test ecx,ecx
js .endpass
mov [fsize],ecx
jmp .loopy
.endpass:
inc dword [count]
cmp dword [count],1
je .filledo
cmp dword [count],2
je .passtwo
cmp dword [count],3
je .endloop
jmp .loopy
.passtwo:
call .filledz
jmp .loopy
.filledz:
mov ecx,buffersize
mov esi,buffer
mov edi,esi
.zeros:
lodsb
xor al,al
stosb ; fill buffer with 0x00
loop .zeros
ret
.filledo:
mov ecx,buffersize
mov esi,buffer
mov edi,esi
.ones:
lodsb
mov al,0xff
stosb ; fill buffer with 0xff
loop .ones
jmp .loopy
.endloop:
push ebp
mov eax,6 ; close
push eax
int 0x80
mov eax,[fname]
push eax
mov eax,10 ; unlink
push eax
int 0x80
mov eax,1 ; exit
push eax
int 0x80
logo db 'usage: wipe filename', 0x0a
logo2 db 'fail', 0x0a