Skip to content

Submitted files

gmolin edited this page Apr 17, 2020 · 3 revisions

The Corewar project page contains links for downloading the following files:

vm_champs.tar Archive

In this archive you can find the compiled executable file of the corewar virtual machine, the compiled compiler program asm, as well as many champions in the form of .s and .cor files.

asm Translator

The project assignment says that the program asm translates the code from the assembly language written in the .s file into the bytecode, which should be placed in a file with the extension .cor.

However, the provided program does not pay any attention to the extension of incoming files. It just searches for the last dot in the name and replaces all further contents with the extension .cor.

The question "How can such an approach be called optimal?" remains open.

After all, this makes the following situations possible, which, although they are not errors in the usual sense, still violate the declared workflow:

$ ./asm batman.cor
Writing output program to batman.cor
$ ./asm batman
Writing output program to .cor
$ ./asm dc.heroes / batman
Writing output program to dc.cor

Also, the provided program does not limit the number of champions accepted for processing.

Therefore, you can specify a lot of files with a variety of extensions as arguments at a time. Only the last of them will be processed:

$ ./asm ant-man.s iron_man.s batman.s
Writing output program to batman.cor

Asm ignores all other arguments:

$ ./asm --undefined-flag incorrect_file.s batman.s
Writing output program to batman.cor

How to deal with it?

Since such behaviour is not described by the task, in your own implementation it is possible to limit the number of accepted arguments to just one file, which must have the extension .s.

This will make the asm work more transparent and eliminate the above vulnerabilities in the workflow.

By the way, the virtual machine does not check incoming files for the presence of the .cor extension as well.

Even though this behaviour is not a source of vulnerabilities for the program corewar, in its implementation this check should still be added to comply with a single style of behaviour for all components of the system.

Champions

There are also problems with the provided examples of champions.

Unfortunately, not all files were written correctly. Therefore, the asm program will not be able to translate some of them into bytecode and will generate an error.

How to deal with it?

In this situation, it should be considered that there will be no problems with files from the champs/examples folder, but you will have to verify the operability of the others yourself.

Files op.c and op.h

The op.c file contains a structure that describes each operation defined in assembly language. The data given in this structure can be overwritten in any form and placed in the project. No restrictions have been established in this case.

We are also provided with the header file op.h. It contains important preprocessor constants that determine the parameters of the virtual machine and assembler syntax.

This file should be handled more carefully and included in the project as is. Only the most necessary changes should be made.

Thats because for the participation in "Corewar Championship" its presence is one of the conditions:

It will be executed on our own virtual machine, so the configuration will be the one you will describe in your file op.h that will be attached.

The necessary changes that must be performed on this file are related to the compliance with the Norm. Since the file does not comply with the established formatting rules, Norminette will display a number of errors found.

If your participation in the "Corewar Championship" competition is not planned, then you should not worry about the op.h file. In this case, it is possible to perform serious changes with it, unlike a simple formatting to Norm.

Clone this wiki locally