# Roll My Own



## -Fabez- (Jul 28, 2008)

As a way of practising my coding abilities I would like to make several projects, however I am unsure about how to start or where to go from there. Below are the projects I would like to make along with some information about each one.

1) An operating system: Only a basic one, perhaps using the Linux kernel and moving on from there like in Linux From Scratch. The trouble with this one is all of the sites I have been through don't explain in a clear, detailed manor. However I do know I will need to make a boot-strapper and other such programs, but don't know how.

2) Password protecting a file: I want to create a small program that will combine any chosen .Exe file with another .Exe that will check for a password and run the password protected .Exe if the password provided is correct. The end result of merging the two files would be a .Exe that will execute the password .Exe first as well as the first .Exe having access to the second one and vice-versa.

3) Remote learning software: A good example of this is ClassLink, but I have no idea which language to use or where to start. Any pointers or advice would be much appreciated.

4) Windows GUI editor: A small tool to change the look of Windows Xp's or Windows Vista's GUI, like the close and minimize buttons and the title bar in windows, with little overhead.


----------



## mt2002 (Sep 14, 2005)

> 1) An operating system: Only a basic one, perhaps using the Linux kernel and moving on from there like in Linux From Scratch. The trouble with this one is all of the sites I have been through don't explain in a clear, detailed manor. However I do know I will need to make a boot-strapper and other such programs, but don't know how.


Check out my site  OS Development Series Speaking of OS's, my previous post was for developing a merging program for my (real) systems boot loader 

The only thing is that my series starts at the boot loader stage and moves onto a MSVC++ kernel. If you want to use an existing bootloader (like GRUB) you can try JamesM's tutorials


----------



## pvc_ (Feb 18, 2008)

For the OS, you'd be better off creating a OS simulator than an actual OS. I actually happen to take an OS class in university right now, and we have to code an OS simulator. The nice thing about the simulator is that you wont have to worry about drivers and the actual hardware, instead you focus on the OS design, CPU scheduling, threads and processes...but I guess it depends on wether you want to deal with the drivers or not...

For the Windows GUI editor, I think you first have to figure out how you can create your own windows skin, and then you can import that into the list of windows templates or whatever.

Password protection: I did something similar to this when I was designing my own application installer. It works similar to the file binder programs that "h4ackers" use to send you trojans hidden in other programs. essentially, you'll have to make 2 separate programs. One that creates the "combined" executables and one that will be the one that does the password checking. The one that does the exe creation will read the password checker and will write it to a separate file, then will make a header to define the size and position of the "hidden executable" in that file. Then it will read the executable that you want to protect and writes it after the header to that same file.
The second application which will be the password protector will read itself till it finds the header and then will find the exe that it's hiding and writes it to another separate file and then executes it if the password is correct. 
Finding the hidden exe at the correct position will be the most challenging part, but once you understand the concept, getting it done shouldn't take you longer than a week. 
One last thing that you might have to do is to delete the extracted executables, once they are terminated.


----------



## -Fabez- (Jul 28, 2008)

Thanks for your replies  mt202 I am going to read through your website and pvc_, I am going to look into Os stimulators. For the GUI editor, I have read somewhere about patching Uxtheme.dll, so how would I go about patching it ? For the password protection of a .Exe I understand the need for two files, one to check the password, another to bind it to the users chosen .Exe, but do not get how to bind them and specify which one should run first and have them be able to accsess each other. Any input would be gratefully appreciated, thanks


----------



## pvc_ (Feb 18, 2008)

Let's refer to the password program as the "stub." With the binder program you'll be writting the stub as well as the header and the program you are trying to protect, to a new file (back to back). So, you'll end up with a single file. When you execute that single file, the OS goes to the header part of the stub (this header is generated by the compiler) and reads the size of the Stub and executes it. So, when the stub is loaded, you have to code it to read itself and extract the hidden program and write it to a temporary location. 

The secret is that you can add whatever you want to the end of executables, images,... The OS simply doesn't care about what you add to the end of the files because every file has a header containing the size of the file. That header tells the OS, the actual size of a program. Although, keep in mind that you won't be able to load a program into notepad and modify it because notepad changes the encoding of sequential files. However, if you load a program into a hex editor, you can add as much garbage to the end of it as you want without changing the properties of the program.


----------



## -Fabez- (Jul 28, 2008)

I understand the binding program will write the password protection file, then the file being protected to a single file. I dont understand about what happens when it is executed, how binding them in the first place works and how the code can read itself. Thanks for explaining a lot of things, but could you clarify on the questions above please ?


----------



## pvc_ (Feb 18, 2008)

A program is nothing but a sequential file. You can read it the same way you read a text file; you can even open it in a notepad. What I mean by reading itself is that you would read your Binded Progarm as binary, then you will split it in half and then you write the second half to another location. Then if the password is correct, you would use shell to execute it (the second half) from the new location. As I said before, when you execute that single file, the OS would only care about the Stub program and will only execute the stub; this means everything else is ignored (the second half of the binded file is ignored).


----------



## -Fabez- (Jul 28, 2008)

Thanks a lot  That clarifies a lot of things. Now I only have two more questions, how do I bind them together and distinguish where the stub ends and the file binded to it starts as well as how to define the password protection file as the stub to be executed when the combined .Exe is run.


----------



## pvc_ (Feb 18, 2008)

Since you write the stub first, it will be executed like any other application and you dont have to worry about anything; just give the file a .exe extension and you'll be set. To distinguish them, you'll have to design your own header/footer that will tell you what the size of the each program is. Then search for it when you wanna split the files. It'd be probably easier to put the header at the bottom of the whole thing (in that case it'd be a footer). That way you can just seek to the end of file and grab the footer.


----------



## -Fabez- (Jul 28, 2008)

After some research, I stumbled upon ADS, this method works fine for binding two or more files together and I could implement my password protection program but, it only works on NTFS file systems, so now my only problem is implementing it on other Windows file systems, any input would be much appreciated  For the remote learning software, what would be the most efficient way to transfer screen shots, videos of what the user is doing and other data types ? I thought about using Python as it is easy to done some of the things I want to do, but it will be slow compared to languages like C and C++. For the Windows GUI editor, how would I replace resources on the fly ? An example of a program like this is True Transparency. Thanks -Fabez-


----------



## pvc_ (Feb 18, 2008)

didn't know it doesnt work on FAT, but I won't worry much about it because most people use NTFS. However, to work around it, you can replace all the programs that you want to protect with a password protection program, which will connect to a database to get the path to a "secret" folder where the programs are hidden and protected. To accomplish this, you can just associate the name of the programs with their executation path.
To transfer screen shots, you can take the screen shot of the active portions of the screen and transfer those to cut-down on bandwidth usage. I'm not sure what exactly you're trying to do, but FTP is a good choice for file transfer.


----------



## -Fabez- (Jul 28, 2008)

I did a test using Mt2002's code from his other thread and it binded the two .Exe's successfully, and running the output runs the first program that was entered, so how would I run the second program, would I need to jump to directly after the end of the first one and how would I, or is there another method ? Finally does anyone have any idea's on items 3 and 4 ? Thanks -Fabez-


----------



## mt2002 (Sep 14, 2005)

> I did a test using Mt2002's code from his other thread and it binded the two .Exe's successfully, and running the output runs the first program that was entered, so how would I run the second program, would I need to jump to directly after the end of the first one and how would I, or is there another method ?


I havn't touched it in a little while but directly jumping to it does not work (Not inside of Windows, anyways.) Through my testing, the 2nd program is never loaded directly after the 1st when loaded into memory by Windows (Which is required for it to work).

I suspect Windows only loads the first program from the image do to the 1st programs header information size data matching that of only the 1st program.

It may also be possible that Windows loads the segments within the programs in different locations in the address space rather then as a flat binary image that may be causing it to not work. I dont know though as I dont know how Windows loads *.exe programs in memory.

Perhaps someone can find anything?

Ill see if I can experiment with it further tomorrow...Who knows, mabey find a way to get it working in Windows


----------



## pvc_ (Feb 18, 2008)

I don't think windows loads the second program, it just grabs the size of the first program from the header and loads the first program. However, one thing you can look at is dll injection (also known as rootkits or process hijacking). With dll injection they load the second program as a dll into the first program. Although, I think my method is far easier to implement and saves you a lot of headache.


----------



## -Fabez- (Jul 28, 2008)

Thanks for your replies, pvc_ you have a good idea, but somebody could just navagate to the secret folder and run the files. Mt2002 would it be possible to make a variable in the first program containing its length in bytes and when the second program needs to be run, jump to that variable plus one byte, resulting in the start of the second program ?


----------



## mt2002 (Sep 14, 2005)

> Mt2002 would it be possible to make a variable in the first program containing its length in bytes and when the second program needs to be run, jump to that variable plus one byte, resulting in the start of the second program ?


Of course. In my test program I read the header information of program 1 to obtain the size of the program and the starting address that it should be loaded at. However the data following the program in memory is not the loaded 2nd program but rather breakpoint instructions (0xcd and 0xcc when it should be 0x4d5a 'MZ', the signature for program 2 ) which makes me believe the 2nd program isnt getting loaded.

If this is indeed the case then it should be easy to fix: just have merger.exe update the header information to match that of the final binary image. I'll need to experiment with it though.


----------



## pvc_ (Feb 18, 2008)

-Fabez- said:


> Thanks for your replies, pvc_ you have a good idea, but somebody could just navagate to the secret folder and run the files. Mt2002 would it be possible to make a variable in the first program containing its length in bytes and when the second program needs to be run, jump to that variable plus one byte, resulting in the start of the second program ?


The files are placed into that folder only when you have checked the password and will be deleted once they are terminated. Although, I'm really interested to see if mt2002's approach will work.


----------



## -Fabez- (Jul 28, 2008)

Okay then, but how would I get the size of my first program from its header and modfy it to include the second program ? Also how would I move the read position to the end of the program add one byte in C++ ? Pvc_ , where would the programs be stored in the mean time ? Thanks -Fabez-


----------



## -Fabez- (Jul 28, 2008)

After running Mt2002's example, it is evident that two or more programs can be combined, however only the first one will be run, does anyone have any ideas on how to run the second one ? Thanks -Fabez-


----------



## mt2002 (Sep 14, 2005)

I dont have a clue  It works fine in my system only because Windows doesnt exist. But when running it in Windows, as you see, Windows only executes the second program.

There may be ways around it but I have not found any yet..


----------

