0 Replies - 3304 Views - Last Post: 26 March 2013 - 05:01 PM

#1 drakethedragon  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 61
  • Joined: 26-March 13

Emulated Running Process Project

Posted 26 March 2013 - 05:01 PM

Emulated Running Process Project

I have been working on a language of my own and want to know what others think. (It closely resembles assembly code) It is compiled in to binary code, then run in a virtual machine.

What's so special about this code?

Unlike other code, each virtual machine can be radically different from another. This allows a layer of security and control that can be used for a wide verity of uses. Example:

Say you are making an image editor that supports plug-ins. These plug-ins should only change image data. If you make the plug-ins an executable or Dll, you really don't know what code you are calling. This is where emulated process code (epc) comes in. You can make a custom virtual machine that allows only certain calls to work, while simply ignoring others.

But, why your own code?

Because I find making things from scratch fun! :)/>

Basics

The code has two components: Data and Code (naturally)
--The Data section contains raw data in the forms of bytes,shorts,floats,ints,doubles,longs,and c-strings.
--The Code section contains binary instructions to complete tasks. See just below.

Code Commands are required to be exact in each Virtual Machine. Without these, the program won't be able to operate at all.

Here is a list of commands and their corresponding binary amount:

Command to Bin ID
0 - mov -X=A
1 - add -X=X+A
2 - sub -X=X-A
3 - mul -X=X*A
4 - div -X=X/A
5 - ife -if equal
6 - ifl -if less
7 - ifg -if greater
8 - ifle -is less or equal
9 - ifge -if greater or equal
10 - ifne -if not equal
11 - mod -X=X%A
12 - inc -X++
13 - dec -X--
14 - foc -Change number of bytes read at once (FC)
15 - set -Set X equal to A (Writes data as well)
16 - step -Step to location in code without setting the return counter
17 - null -X=0
18 - pos -Position X to Counter
19 - seek -Set Counter to X
20 - jump -Goto a position noted by a #
21 - call -Calls an operation (ID pointer at X)(Ram Data at A)
22 - xor -X=X xor A
23 - push -Adds X to the stack as an int
24 - pop -Sets X to the stack as an int
25 - time -Set X to the current time (in seconds)
26 - state -Get state in to X
27 - mill -Set X to the current millisecond (in millisecs())
28 - sleep -Delays the process by X milliseconds.
29 - eif -End if statement
30 - end -End the process, no matter what
31 - back -Returns from last jump, or, if no jumps made, ends the proc.
32 - lau -Launches a new process in the same thread
33 - run -Runs a process through the current process
34 - yell -Set the state to X
35 - 63 -Reserved

Registers are values that can be used to operate on data. These are the only variables that can store information outside the Ram and the Data Bank. Take note that registers can hold different amounts, and the some OVERLAP:

Registers: Positions and Sizes
Reg - Size (Starts at Byte)
A - 4 Bytes (0)
B - 4 Bytes (4)
C - 4 Bytes (8)
H - 4 Bytes (12)
I - 2 Bytes (12)
J - 2 Bytes (14)
K - 1 Byte (16)
L - 1 Byte (17)
M - 1 Byte (18)
N - 1 Byte (19)
O - 2 Bytes (16)
P - 2 Bytes (18)
Q - 4 Bytes (16)
X - 4 Bytes (20)
Y - 4 Bytes (24)
Z - 4 Bytes (28)

Calls are the most important part of the language. This is where the process can request the host Virtual Machine to do something. In order to call something, you just use the call command. (Note: Call commands have access to the all ram memory and registers of all processes in that VM)

Here is an example of a call command:
call "wchr",A


This command tells a VM that supports a console to print the ASCII value of the amount stored in register A.

Call commands can differ from machine to machine, making it hard for people to write a virus through Emulated Running Process (ERPC) files.

A note on the call 'strings' "wchr": Quotes are always seen as what are called 6 letter ints, and are not strings! 6 letter ints can only be up to 6 characters, and support only alpha letters (A-Z) and space. They are also not case sensitive, so "WCHR" is the same as "wchr"!

If a VM does not support a call, it will just ignore it. This means your code could be writing as many characters as it wants, and nothing will show. Console calls are best used for debugging.

The Code Syntax
;This is a comment...
*Name        ;This is a 6 letter int name (Don't use quotes)
#label       ;This is a label
%input_str   ;This is a snip (more on that below)
'A'          ;This is a character literal that is 65
"letter"     ;This is a 6 letter int (again, and int value)
jump #label  ;This jumps the program back to #label
*****        ;This is a file break (used in the ide)



Snips
Snips are marked with '%' and point to code #labels you want to import from outside your code. These are already pre-written by you or someone else. Here is an example of a snip:

;This code waits for a key to be pressed
; on the console.
#key_waitkey
	ife B,0
		set B,50
	eif
	sleep B
	call "rchr",A
	ifne A,0
		back
	eif
step #key_waitkey
back



This is a simple snip that checks what keys are being hit while in the console. If there are any, it used the "back" command to return to the calling point (if none, then ends the thread.)

Using Snips
*Main        ;Name this file main to run first.
%key_waitkey ;Wait for the user to press a key.
end          ;End the process



Here we simply close the console when a key is pressed.

Phrasing is done by the IDE to replace snips to jump commands and attach all the labels needed to make your code stand alone. This is done automatically when compiling. Below is a fully phrased code file for the snip #input_str.

I will stop the long post here with just one last code to give you an idea of how simple the code is:

Phrased Input Code Example

This is a snip-free phrased code to input a string:
#input_str
	set B,0
	set Y,0
	seek RC,C
	
	#input_str_loop
	jump #input_str_key_waitkey
	
	;Enter
	ife A,13
		set RC,0
		call "wchr",'\n'
		back
	eif

	;Backspace
	ife A,8
		foc 1
		set RC,0
		dec B
		dec RC
		set Z,0
		ifl B,0
			set B,0
			set Z,1
			pos RC,C
		eif
		ife Z,0
			call "wchr",8
			call "wchr",32
			call "wchr",8
		eif
		step #input_str_loop
	eif
	
	jump #char_printable
	ife A,0
		step #input_str_loop
	eif
	
	foc 1
	call "wchr",A
	set RC,A
	inc B
	inc RC
step #input_str_loop


#input_str_key_waitkey
	sleep 25
	call "rchr",A
	ifne A,0
		back
	eif
step #input_str_key_waitkey
back


#char_printable
	ifl A,32
		set A,0
	eif
	ifg A,126
		set A,0
	eif
back



Is This A Good Question/Topic? 2
  • +

Page 1 of 1