NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: toad1359 on October 10, 2013, 03:01:33 PM

Title: Making a password system
Post by: toad1359 on October 10, 2013, 03:01:33 PM
How would I open a file, read a line from it, close it, get user input, and then check to see if the two are the same? I know how to in c++ if that helps.
Title: Re: Making a password system
Post by: Frank Kotler on October 10, 2013, 03:24:59 PM
What OS? If this for your "text OS", you're going to need a filesystem  first. If you know the head/cylinder/sector, you can read it with int 13h (if you're still in real mode). Otherwise, you're going to need to write a heap of code.

If for some existing OS, which one? It matters.

Best,
Frank

Title: Re: Making a password system
Post by: toad1359 on October 10, 2013, 10:56:16 PM
Who says it is for an OS? I am just looking for some code. I am using nasm of course.
Title: Re: Making a password system
Post by: Frank Kotler on October 10, 2013, 11:25:00 PM
Okay, what filesystem does this mystery OS - or not - use?

Best,
Frank

Title: Re: Making a password system
Post by: toad1359 on October 11, 2013, 03:25:48 PM
Who says it is for an OS? The file with the password would be a text file.
Title: Re: Making a password system
Post by: Frank Kotler on October 11, 2013, 03:43:31 PM
What makes it a "text fie"? I understand that it has text in it, but what makes it a "file"?

Best,
Frank

Title: Re: Making a password system
Post by: toad1359 on October 11, 2013, 05:50:55 PM
password.txt would be the file.
Title: Re: Making a password system
Post by: Frank Kotler on October 11, 2013, 06:52:28 PM
Yes, but what makes it a "file"? The answer depends on "what OS?". If you don't know or won't say "what OS?", you'd better stick to C++.

Best,
Frank

Title: Re: Making a password system
Post by: toad1359 on October 12, 2013, 12:48:25 PM
Fine my text based one which would be loaded using virtual box and on a virtual hard drive.
Title: Re: Making a password system
Post by: toad1359 on October 12, 2013, 03:17:29 PM
The virtual hard drive would have password.txt on it.
Title: Re: Making a password system
Post by: Frank Kotler on October 12, 2013, 06:48:28 PM
Okay, now we're getting somewhere!

Your virtual hard drive "probably" doesn't have a filesystem on it - I would guess - unless you've put one there. This means you're up against head/cylinder/sector. If you put your password information immediately after your bootsector - in sector 2 - this shouldn't be too difficult. It won't give you a "named file" though.

I have a bootsector written by Deb Wiles (she helped a lot with the Nasm Manual). It parses a FAT12 filesystem and loads the named file "loader.bin" into memory. IF you can convince virtual box to format your virtual hard drive as FAT12, it should be fairly easy to modify this to load "password.txt" instead of "loader.bin". Note that directory entries (in FAT12) are all uppercase and the "." is not stored - the "first name" is space-padded to 8 bytes, followed by the three byte extension. Debs' filename is "LOADER  BIN", your filename will be "PASSWORDTXT" - or you could rename it to "loader.bin". :)

Keep in mind that I did not write this myself, and I haven't looked at it for a long time, so it may take me a while to get "oriented" before I can help you with it. I think this has been modified from Debs' original bootsector. It's what I've got.
Code: [Select]
deleted, drat it!

I don't know what the capabilities of virtual box are - you'll have to tell me. If it balks (pun) at formatting your virtual hard drive as FAT12, maybe it'll do FAT16. That might be even easier. FAT32 is tougher since we don't know the size of the root directory in advance. Maybe just ASSume that it isn't too big and will fit. These are all obsolete filesystems. I don't know the specifications for NTFS (or any of the Linux filesystems, which I assume you won't be using). NTFS was not well documented originally, but I think it is now. You'll have to look it up. Pray it'll do FAT12!

Are you still using "MikeOS" as an example to go by? How far have you gotten with it? If you've already loaded a "kernel", you may want to put this filesystem stuff in your kernel instead of squeezing it into a 512 byte bootsector. Up to you, it's "YourOS" now...

I hope you find the above useful... or at least understand why I want to know "what OS?"/"what filesystem?" before I can tell you how to open a file. If I haven't mentioned it, http://www.osdev.org has a lot of documentation you may find useful!

Best,
Frank

Well, curses - the Forum advises me that this message is too long! Lemme try to attach the code instead...


Title: Re: Making a password system
Post by: toad1359 on October 15, 2013, 05:06:39 PM
How would I create a bootsector? All I have is bootloader code.
Title: Re: Making a password system
Post by: nullptr on October 15, 2013, 07:38:52 PM
hi toad1359,
follow that link:
http://forum.osdev.org/ (http://forum.osdev.org/)

this is OS developers forum. You don't have to even ask just use the search bar and you will surely find what you need and much more.
Title: Re: Making a password system
Post by: Frank Kotler on October 15, 2013, 08:28:32 PM
Well, I guess it's a matter of terminology. My answer would be "it's the same thing". I guess some people refer to the first sector as a "bootsector" and what I would call a "second stage loader" as the "bootloader". More info here:

http://wiki.osdev.org/Bootloader

In any case, the first thing you want to do is:
Code: [Select]
nasm -f bin boot11.asm -o boot.bin

Now you've created a "bootsector". If you had a real floppy drive, you'd put a real floppy disk into it, format it if it isn't already formatted ("format a:"), copy some file named "loader.bin" to it, and write "boot.bin" to sector 1. "Copy" won't do this. John Fine's "partcopy" used to be popular, or "rawwrite", or DEBUG will do it. Then reboot your machine, telling the BIOS setup that you want to boot from "drive a:" if it isn't already set to do so.

I ASSume what you want to do is to "fool" virtual box into thinking that's what you did, if possible. If it isn't possible, you'll have to modify the code to comply with what it will do. I'm not familiar with virtual box, so you'll have to tell me about it. What does it say in the manual? (you have read the manual, right?) What did you do? What happened?

We've got a general rule on the Forum: "the less they give us, the less we give them". In other words, if you (this means "everybody" not just "you" personally) expect us to "give me the code" you aren't likely to get what you want. If you can show that you've put some effort into it and tried to solve the problem, we'll bend over backwards to help you. Before we can possibly help you, we need to know:
1) what are you trying to do (OS, other tools besides Nasm, etc.)
2) exactly what did you do?
3) what did you "expect" (hope) would happen?
4) what actually happened? (exact error message(s), no output, "garbage" output, etc.)

So far, it's been "like pulling teeth" to get any information out of you. "Give us more" and we'll try to "give you more"!

Best,
Frank

Title: Re: Making a password system
Post by: toad1359 on October 15, 2013, 09:50:44 PM
Thanks, I will look at all of this.
Title: Re: Making a password system
Post by: toad1359 on October 19, 2013, 03:00:48 PM
So, I just got to look at boot11.asm and there is like no formatting and I can't read it. You want info?

INFO:
-I want my OS to pretty much be a word processing operating system with built in c++ compiler so it can handle basic text c++ programs.
-I need help with user input, new lines, the compiler, and opening, reading from, and closing files, and checking for equality.
-I am fine with tag teaming with as many people who want to do this.
-I am still using Mike berlios's code.
-I don't want a kernel
-Currently all my code is in the bootloader and I don't know how to end the bootloader and start the OS
Code: [Select]
BITS 16

start:
mov ax, 07C0h
add ax, 288
mov ss, ax
mov sp, 4096

mov ax, 07C0h
mov ds, ax


mov si, text_string
call print_string
mov si, string2
call print_string
 
jmp $


text_string db 'Password Please and then there will be more loading.', 0
string2 db ' What is your password?', 0
;Newline here
;Get user input
;Check for equality between input and password.txt
;Load
;Display os


print_string:
mov ah, 0Eh

.repeat:
lodsb
cmp al, 0
je .done
int 10h
jmp .repeat
.done:

ret


times 510-($-$$) db 0
dw 0xAA55
Thanks for helping as much as you have Frank Kotler.
Title: Re: Making a password system
Post by: Bryant Keller on October 19, 2013, 06:28:02 PM
So, I just got to look at boot11.asm and there is like no formatting and I can't read it.

If you are trying to view it under windows, open the file with Wordpad and use "Save As..." and choose the MS-DOS plain text format. Newlines are different between operating systems, this is why the text looks unformatted.

-I want my OS to pretty much be a word processing operating system with built in c++ compiler so it can handle basic text c++ programs.

I wouldn't suggest doing this. First you should try writing a word processor and a C++ compiler on whatever operating system you're using before trying to embed such a feature into the complexities of an operating system.

-I need help with user input, new lines, the compiler, and opening, reading from, and closing files, and checking for equality.

I'm sorry, but are you crazy? I see no reason that you can't get help with things like user I/O, console operations (like newlines and scrolling), reading/writing hard drives, and comparing values. But if you really think you can learn a subject as broad as compiler development by posting requests on a forum, you're sadly mistaken. Go buy some books, maybe take a class on finite automata at your local college, but I don't think you're going to find much information through general forum discussions. Compiler creation is about as broad a subject as operating systems development itself is (likely more so).

-I am fine with tag teaming with as many people who want to do this.

I'm sure you are. However, given the apparent shortcomings I doubt you're going to find anyone that'll help you with such an "ambitious project".

-I am still using Mike berlios's code.

Great, it's good to have a working starting point for your edification.

-I don't want a kernel

Then you don't want an operating system. The kernel is the core of all operating systems, it technically IS the operating system. Even DOS had a kernel as part of COMMAND.COM. Even further back, the C64 (which was mostly just a BASIC interpreter in ROM) had a "kernal". You may not want a kernel, but you're not going to be doing an operating system without one.

-Currently all my code is in the bootloader and I don't know how to end the bootloader and start the OS

You end the bootloader by doing a call to the kernel's entrypoint routine. Below is a list of links to help you in the next few steps. The Multiboot specification by GNU[1] will help you to make your bootloader more "compliant". Basically, a multiboot loader is capable of loading any operating system which follows that specification (like Linux, BSD, and more). Also included are two really good kernel development tutorials[2][3] which both run on top of multiboot loaders. These kernels should give you a good understanding of what it takes to get your system up and running.

You should really try and take baby steps with this, you seem to be biting off more than you can chew. I'd hate to see you give up trying to learn OS Dev or assembly simply because you decided to pick an unreasonably difficult project for a beginner to start with.

Regards,
Bryant Keller