Understanding Linux, its memory layout, and system calls in x86_64

There are three objectives for this assignment:

  1. Demonstrate that you can write simple programs in the Linux environment.
  2. Demonstrate that you understand how system calls are done at the x86_64 assembly language level for Linux.
  3. Demonstrate that you understand memory layout characteristics in the Linux environment.

Your goal is to write a NASM program named xor.nasm that performs a fixed key XOR encryption on a list of files, sending the results to stdout. (This is not secure and should never be used for securing data — it is one of the easiest possible systems to crack.)

Your program should take n + 1 arguments, where the first argument is the string that you wish to use as a key, and the remaining n arguments should be the names of the files that you wish to encrypt. All output should go to stdout.

Here are some reference test files:

The following are encryptions of each of the above using the key "HelloWorld":

Your assembled program xor should run in the following fashion:

$ ./xor HelloWorld ref1.txt > ref1.enc
$ ./xor HelloWorld ref2.txt > ref2.enc
$ ./xor HelloWorld ref3.txt > ref3.enc
$ ./xor HelloWorld ref1.txt ref2.txt ref3.txt > all.enc
      

The following file sizes and checksums should match:

$ ls -l ref* all.enc
-rw-r--r-- 1 user user 3626 Sep  6 16:15 all.enc
-rw-r--r-- 1 user user 1509 Sep  6 16:14 ref1.enc
-rw-r--r-- 1 user user 1509 Sep  6 16:10 ref1.txt
-rw-r--r-- 1 user user 1006 Sep  6 16:14 ref2.enc
-rw-r--r-- 1 user user 1006 Sep  6 16:13 ref2.txt
-rw-r--r-- 1 user user 1111 Sep  6 16:14 ref3.enc
-rw-r--r-- 1 user user 1111 Sep  6 16:06 ref3.txt
$ cksum ref* all.enc
1372939279 1509 ref1.enc
329295634 1509 ref1.txt
545883245 1006 ref2.enc
126579316 1006 ref2.txt
1930161385 1111 ref3.enc
1429895899 1111 ref3.txt
3826327218 3626 all.enc
      

And, of course, when applying the password back to the encrypted files, you should get the originals:

$ ./xor HelloWorld ref1.enc
The Duke of Marlborough succeeded Lord Gower in the Privy Seal,
and the Duke of Rutland, a nobleman of great worth and goodness,
returned to Court, which he had long quitted, yet without enlisting
in any faction, though governed too much by a mercenary brother;
and was appointed Lord Steward.

France sent a haughty answer, accompanied with these inadmissible
proposals; that each nation should destroy all their forts on the
south of the Ohio, which would leave them in possession of all
the north side of that river; and whereas the Five Nations were
allotted to the division of England by the Treaty of Utrecht, and
the French had built forts amongst them contrary to that Treaty,
and we agreeably to it, they demanded that we should destroy
such forts, while they should be permitted to maintain theirs.
Lord Hertford’s journey was suspended; at the same time that his
brother, Colonel Conway, rose merely on the basis of his merit
to a distinguished situation, entirely unsought, uncanvassed.
The Ministry had perceived that it was unsafe to venture Ireland
again under the Duke of Dorset’s rule; and they had fixed on Lord
Hartington to succeed, as the most devoted to their views, and as
the least likely, from the wariness of his temper, to throw himself
into the scale of either faction. He refused to accept so uncommon
an honour, unless Mr Conway, with whom he was scarce acquainted,
would consent to accompany him as Secretary and Minister. Mr.
Conway’s friends would not let him hesitate.
$ ./xor HelloWorld ref2.enc
On the 29th, it was known that the French squadron was sailed,
and that our fleet was ordered to follow and attack them, if they
went to the Bay of St. Lawrence, even though they designed for
Louisbourg. It was a hardy step, and not expected by France: our
tameness and connivance at their encroachments had drawn them into
a false security; they could not believe us disposed to war, nor
had calculated that it would arrive so soon: their debts were not
paid, their fleets not re-established, their Ministry was divided,
and the spirit of their Parliaments not abashed. These were
advantages in our scale; but our incumbrances were not inferior
nor dissimilar to theirs. Our debts were weighty, not to be wiped
out by a _De-par-le-Roy_; our troops, our sailors were disbanded;
our Ministry was weak and factious, if not divided; and, headed by
the Duke of Newcastle’s jealousy, how long could it preserve any
stability?--Our Parliament, indeed, was not mutinous; it was ready
to receive any impression.
[fsucs@localhost new-assign-assembly-xor]$ ./xor HelloWorld ref3.enc
March 6th.--The Marquis of Hartington was declared Lord Lieutenant
of Ireland; and the same day, the Earl of Rochford, Minister at
Turin, having been appointed to succeed the late Lord Albemarle,
as Groom of the Stole; Earl Poulet, First Lord of the Bed-chamber,
resenting that a younger Lord had, contrary to custom, been
preferred to him, resigned his employment. He had served the
King twenty years in that station; and yet his disgrace was not
lamentable, but ridiculous. He did not want sense, but that sense
wanted every common requisite. He had dabbled in factions, but
always when they were least creditable; he had lived in a Court,
without learning the very rudiments of mankind; and was formal upon
the topics which of all others least admit solemnity. For about two
months the town was entertained with the episode of his patriotism:
it vented itself in reams of papers without meaning, and of verses
without metre, which were chiefly addressed to the Mayor of
Bridgewater, where the Earl had been dabbling in an opposition.
His fury died in the fright of a measure which I shall mention
presently.
$ ./xor HelloWorld all.enc
The Duke of Marlborough succeeded Lord Gower in the Privy Seal,
and the Duke of Rutland, a nobleman of great worth and goodness,
returned to Court, which he had long quitted, yet without enlisting
in any faction, though governed too much by a mercenary brother;
and was appointed Lord Steward.

France sent a haughty answer, accompanied with these inadmissible
proposals; that each nation should destroy all their forts on the
south of the Ohio, which would leave them in possession of all
the north side of that river; and whereas the Five Nations were
allotted to the division of England by the Treaty of Utrecht, and
the French had built forts amongst them contrary to that Treaty,
and we agreeably to it, they demanded that we should destroy
such forts, while they should be permitted to maintain theirs.
Lord Hertford’s journey was suspended; at the same time that his
brother, Colonel Conway, rose merely on the basis of his merit
to a distinguished situation, entirely unsought, uncanvassed.
The Ministry had perceived that it was unsafe to venture Ireland
again under the Duke of Dorset’s rule; and they had fixed on Lord
Hartington to succeed, as the most devoted to their views, and as
the least likely, from the wariness of his temper, to throw himself
into the scale of either faction. He refused to accept so uncommon
an honour, unless Mr Conway, with whom he was scarce acquainted,
would consent to accompany him as Secretary and Minister. Mr.
Conway’s friends would not let him hesitate.
On the 29th, it was known that the French squadron was sailed,
and that our fleet was ordered to follow and attack them, if they
went to the Bay of St. Lawrence, even though they designed for
Louisbourg. It was a hardy step, and not expected by France: our
tameness and connivance at their encroachments had drawn them into
a false security; they could not believe us disposed to war, nor
had calculated that it would arrive so soon: their debts were not
paid, their fleets not re-established, their Ministry was divided,
and the spirit of their Parliaments not abashed. These were
advantages in our scale; but our incumbrances were not inferior
nor dissimilar to theirs. Our debts were weighty, not to be wiped
out by a _De-par-le-Roy_; our troops, our sailors were disbanded;
our Ministry was weak and factious, if not divided; and, headed by
the Duke of Newcastle’s jealousy, how long could it preserve any
stability?--Our Parliament, indeed, was not mutinous; it was ready
to receive any impression.
March 6th.--The Marquis of Hartington was declared Lord Lieutenant
of Ireland; and the same day, the Earl of Rochford, Minister at
Turin, having been appointed to succeed the late Lord Albemarle,
as Groom of the Stole; Earl Poulet, First Lord of the Bed-chamber,
resenting that a younger Lord had, contrary to custom, been
preferred to him, resigned his employment. He had served the
King twenty years in that station; and yet his disgrace was not
lamentable, but ridiculous. He did not want sense, but that sense
wanted every common requisite. He had dabbled in factions, but
always when they were least creditable; he had lived in a Court,
without learning the very rudiments of mankind; and was formal upon
the topics which of all others least admit solemnity. For about two
months the town was entertained with the episode of his patriotism:
it vented itself in reams of papers without meaning, and of verses
without metre, which were chiefly addressed to the Mayor of
Bridgewater, where the Earl had been dabbling in an opposition.
His fury died in the fright of a measure which I shall mention
presently.
      

For your submission, please create a tar file with both your xor.nasm code and a makefile that invokes nasm and your choice of a) either a call to ld to link (not gold, please), or b) you can use a straight binary form like we talked about on Tuesday.

Your submission is due by 11:59pm on Wednesday, September 12. Please email the tar file to me at langley@cs.fsu.edu