Skip to content

Commit 7d0dfed

Browse files
authored
Add files via upload
1 parent 5059930 commit 7d0dfed

File tree

3 files changed

+186
-0
lines changed

3 files changed

+186
-0
lines changed

zero_runtime/function_call.asm

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; MIT License
2+
;
3+
; Copyright (c) 2022 m!haly4
4+
;
5+
; Permission is hereby granted, free of charge, to any person obtaining a copy
6+
; of this software and associated documentation files (the "Software"), to deal
7+
; in the Software without restriction, including without limitation the rights
8+
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
; copies of the Software, and to permit persons to whom the Software is
10+
; furnished to do so, subject to the following conditions:
11+
;
12+
; The above copyright notice and this permission notice shall be included in all
13+
; copies or substantial portions of the Software.
14+
;
15+
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
; SOFTWARE.
22+
23+
global system_read
24+
global system_write
25+
global system_errno
26+
27+
section .text
28+
29+
main_system_call:
30+
push ebp
31+
mov ebp, esp
32+
push ebx
33+
mov ebx, [ebp+8]
34+
mov ecx, [ebp+12]
35+
mov edx, [ebp+16]
36+
int 80h
37+
mov edx, eax
38+
and edx, 0fffff000h
39+
cmp edx, 0fffff000h
40+
jnz .success
41+
mov [system_errno], eax
42+
mov eax, -1
43+
.success: pop ebx
44+
mov esp, ebp
45+
pop ebp
46+
ret
47+
48+
system_read: mov eax, 3
49+
jmp main_system_call
50+
51+
system_write: mov eax, 4
52+
jmp main_system_call
53+
54+
section .bss
55+
56+
system_errno: resd 1

zero_runtime/main.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2022 m!haly4
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
/*function declaration*/
26+
int system_write(int fd, const void *buf, int size);
27+
28+
/*declaration of few strings*/
29+
static const char error_message[] = "Invalid input:\nPlease enter the password\n";
30+
static const char password[] = "Hello";
31+
static const char data[] = "Success!\nThe secret data: <the data was deleted> :)\n";
32+
33+
/*function for calculating the length of the string*/
34+
static int string_length(const char *string)
35+
{
36+
int i = 0;
37+
while (string[i])
38+
{
39+
i++;
40+
}
41+
42+
return i;
43+
}
44+
45+
/*function for comparing two strings*/
46+
static int string_compare(char *string, const char *bufer)
47+
{
48+
int i = 0;
49+
50+
/*to check that both lines are the same length*/
51+
if((string_length(bufer)) == (string_length(string)))
52+
{
53+
while (string[i])
54+
{
55+
if(string[i] == bufer[i])
56+
{
57+
++i;
58+
}
59+
else
60+
{
61+
break;
62+
}
63+
}
64+
}
65+
else
66+
{
67+
return 0;
68+
}
69+
70+
return i;
71+
}
72+
73+
int main(int argc, char **argv)
74+
{
75+
/*check at least 1 argument exist and check the password correctness*/
76+
if((argc > 1) && (string_compare(argv[1], password) == 5))
77+
{
78+
system_write(1, data, sizeof(data)-1);
79+
/*
80+
system_write(1, argv[1], string_length(argv[1]));
81+
system_write(1, "\n", 1);
82+
*/
83+
}
84+
else
85+
{
86+
/*error message*/
87+
system_write(1, error_message, sizeof(error_message)-1);
88+
return 1;
89+
}
90+
91+
return 0;
92+
}

zero_runtime/start.asm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; MIT License
2+
;
3+
; Copyright (c) 2022 m!haly4
4+
;
5+
; Permission is hereby granted, free of charge, to any person obtaining a copy
6+
; of this software and associated documentation files (the "Software"), to deal
7+
; in the Software without restriction, including without limitation the rights
8+
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
; copies of the Software, and to permit persons to whom the Software is
10+
; furnished to do so, subject to the following conditions:
11+
;
12+
; The above copyright notice and this permission notice shall be included in all
13+
; copies or substantial portions of the Software.
14+
;
15+
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
; SOFTWARE.
22+
23+
global _start
24+
25+
extern main
26+
27+
section .text
28+
29+
_start: mov ecx, [esp] ; argc -> ecx
30+
mov eax, esp
31+
add eax, 4 ; argv -> eax
32+
push eax
33+
push ecx
34+
call main
35+
add esp, 8 ; clean the stack
36+
mov ebx, eax ; call _exit
37+
mov eax, 1
38+
int 80h

0 commit comments

Comments
 (0)