Skip to content

Commit

Permalink
upload all lab assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
tinylcy committed Dec 13, 2016
1 parent 499c6c2 commit bbb9a20
Show file tree
Hide file tree
Showing 68 changed files with 760 additions and 1,242 deletions.
Binary file added Architecture Lab (Y86)/archlab32-handout.tar
Binary file not shown.
Binary file added Architecture Lab (Y86)/archlab32.pdf
Binary file not shown.
Binary file added Architecture Lab/archlab-handout.tar
Binary file not shown.
Binary file added Architecture Lab/archlab.pdf
Binary file not shown.
Binary file added Attack Lab/attacklab.pdf
Binary file not shown.
Binary file added Attack Lab/target1.tar
Binary file not shown.
Binary file added Bomb Lab/bomb.tar
Binary file not shown.
1 change: 1 addition & 0 deletions Bomb Lab/bomb/README
@@ -0,0 +1 @@
This is an x86-64 bomb for self-study students.
Binary file added Bomb Lab/bomb/bomb
Binary file not shown.
115 changes: 115 additions & 0 deletions Bomb Lab/bomb/bomb.c
@@ -0,0 +1,115 @@
/***************************************************************************
* Dr. Evil's Insidious Bomb, Version 1.1
* Copyright 2011, Dr. Evil Incorporated. All rights reserved.
*
* LICENSE:
*
* Dr. Evil Incorporated (the PERPETRATOR) hereby grants you (the
* VICTIM) explicit permission to use this bomb (the BOMB). This is a
* time limited license, which expires on the death of the VICTIM.
* The PERPETRATOR takes no responsibility for damage, frustration,
* insanity, bug-eyes, carpal-tunnel syndrome, loss of sleep, or other
* harm to the VICTIM. Unless the PERPETRATOR wants to take credit,
* that is. The VICTIM may not distribute this bomb source code to
* any enemies of the PERPETRATOR. No VICTIM may debug,
* reverse-engineer, run "strings" on, decompile, decrypt, or use any
* other technique to gain knowledge of and defuse the BOMB. BOMB
* proof clothing may not be worn when handling this program. The
* PERPETRATOR will not apologize for the PERPETRATOR's poor sense of
* humor. This license is null and void where the BOMB is prohibited
* by law.
***************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "support.h"
#include "phases.h"

/*
* Note to self: Remember to erase this file so my victims will have no
* idea what is going on, and so they will all blow up in a
* spectaculary fiendish explosion. -- Dr. Evil
*/

FILE *infile;

int main(int argc, char *argv[])
{
char *input;

/* Note to self: remember to port this bomb to Windows and put a
* fantastic GUI on it. */

/* When run with no arguments, the bomb reads its input lines
* from standard input. */
if (argc == 1) {
infile = stdin;
}

/* When run with one argument <file>, the bomb reads from <file>
* until EOF, and then switches to standard input. Thus, as you
* defuse each phase, you can add its defusing string to <file> and
* avoid having to retype it. */
else if (argc == 2) {
if (!(infile = fopen(argv[1], "r"))) {
printf("%s: Error: Couldn't open %s\n", argv[0], argv[1]);
exit(8);
}
}

/* You can't call the bomb with more than 1 command line argument. */
else {
printf("Usage: %s [<input_file>]\n", argv[0]);
exit(8);
}

/* Do all sorts of secret stuff that makes the bomb harder to defuse. */
initialize_bomb();

printf("Welcome to my fiendish little bomb. You have 6 phases with\n");
printf("which to blow yourself up. Have a nice day!\n");

/* Hmm... Six phases must be more secure than one phase! */
input = read_line(); /* Get input */
phase_1(input); /* Run the phase */
phase_defused(); /* Drat! They figured it out!
* Let me know how they did it. */
printf("Phase 1 defused. How about the next one?\n");

/* The second phase is harder. No one will ever figure out
* how to defuse this... */
input = read_line();
phase_2(input);
phase_defused();
printf("That's number 2. Keep going!\n");

/* I guess this is too easy so far. Some more complex code will
* confuse people. */
input = read_line();
phase_3(input);
phase_defused();
printf("Halfway there!\n");

/* Oh yeah? Well, how good is your math? Try on this saucy problem! */
input = read_line();
phase_4(input);
phase_defused();
printf("So you got that one. Try this one.\n");

/* Round and 'round in memory we go, where we stop, the bomb blows! */
input = read_line();
phase_5(input);
phase_defused();
printf("Good work! On to the next...\n");

/* This phase will never be used, since no one will get past the
* earlier ones. But just in case, make this one extra hard. */
input = read_line();
phase_6(input);
phase_defused();

/* Wow, they got it! But isn't something... missing? Perhaps
* something they overlooked? Mua ha ha ha ha! */

return 0;
}
Binary file added Bomb Lab/bomblab.pdf
Binary file not shown.
Binary file added Buffer Lab (IA32)/buflab32-handout.tar
Binary file not shown.
Binary file added Buffer Lab (IA32)/buflab32.pdf
Binary file not shown.
Binary file added Cache Lab/cachelab-handout.tar
Binary file not shown.
Binary file added Cache Lab/cachelab.pdf
Binary file not shown.
Binary file added Chapters/chapter2/a.out
Binary file not shown.
File renamed without changes.
23 changes: 23 additions & 0 deletions Chapters/chapter2/exercise_2_23.c
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>

int func1(unsigned word) {
return (int) ((word << 24) >> 24);
}

int func2(unsigned word) {
return ((int) word << 24) >> 24;
}

int main(void) {
unsigned w = 0x00000076;
printf("func1: %x, func2: %x\n", func1(w), func2(w));
w = 0x87654321;
printf("func1: %x, func2: %x\n", func1(w), func2(w));
w = 0x000000C9;
printf("func1: %x, func2: %x\n", func1(w), func2(w));
w = 0xEDCBA987;
printf("func1: %x, func2: %x\n", func1(w), func2(w));

return 0;
}
24 changes: 24 additions & 0 deletions Chapters/chapter2/exercise_2_25.c
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>

float sum_element(float a[], unsigned length) {
int i;
float result = 0;
for(i = 0; i <= (int)(length - 1); i++) {
result += a[i];
}

return result;
}

int main(void) {
float a[] = {1.0, 2.0};
int alen = 2;
printf("%f\n", sum_element(a, alen));

float b[] = {};
int blen = 0;
printf("%f\n", sum_element(b, blen));

return 0;
}
16 changes: 16 additions & 0 deletions Chapters/chapter2/exercise_2_27.c
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>

int uadd_ok(unsigned x, unsigned y) {
unsigned s = x + y;
return s < x || s < y;
}

int main(void) {
unsigned x = 0xFFFFFFFF;
unsigned y = 0xEEEEEEEE;

printf("add ok: %d\n", uadd_ok(x, y));
printf("x + y = %x\n", x + y);
return 0;
}
24 changes: 24 additions & 0 deletions Chapters/chapter2/exercise_2_31.c
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>

int tadd_ok(int x, int y) {
int s;
if(x > 0 && y > 0) {
s = x + y;
return s <= 0;
}
if(x < 0 && y < 0) {
return s >= 0;
}
return 0;
}

int main(void) {
int x = 0x7FFFFFFF;
int y = 0x00000001;

printf("tadd ok: %d\n", tadd_ok(x, y));
printf("x + y = %x\n", x + y);

return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Data Lab/datalab-handout.tar
Binary file not shown.
12 changes: 12 additions & 0 deletions Data Lab/datalab-handout/Driverhdrs.pm
@@ -0,0 +1,12 @@
#
# This file contains configuration variables for drivers.
# It was generated by genhdrs.pl. Do not modify it.
#
package Driverhdrs;

$LAB = "datalab";
$SERVER_NAME = "changeme.ics.cs.cmu.edu";
$SERVER_PORT = 8081;
$COURSE_NAME = "csapp";
$AUTOGRADE_TIMEOUT = 0;
1;
@@ -1,11 +1,8 @@
###############################################################################
# Driverlib.pm - A package of helper functions for Perl Autolab drivers
###############################################################
# Driverlib.pm - A package of helper functions for Perl drivers
#
# Copyright (c) 2005 David R. O'Hallaron, All rights reserved.
# May not be used, modified, or copied without permission.
#
# $Id: Driverlib.pm,v 1.8 2005/08/18 04:51:44 autolab Exp $
###############################################################################
###############################################################

package Driverlib;

Expand All @@ -29,7 +26,7 @@ use strict;

#
# driver_post - This is the routine that a driver calls when
# it needs to transmit an autoresult string to Autolab.
# it needs to transmit an autoresult string to the result server.
#
sub driver_post ($$) {
my $userid = shift; # User id for this submission
Expand All @@ -39,28 +36,28 @@ sub driver_post ($$) {
# Echo the autoresult string to stdout if the driver was called
# by an autograder
if ($autograded) {
print "\n";
print "AUTORESULT_STRING=$result\n";
return;
print "\n";
print "AUTORESULT_STRING=$result\n";
return;
}

# If the driver was called with a specific userid, then submit
# the autoresult string to the Autolab server over the Internet.
# the autoresult string to the result server over the Internet.
if ($userid) {
my $status = submitr($Driverhdrs::SERVER_NAME,
$Driverhdrs::SERVER_PORT,
$Driverhdrs::COURSE_NAME,
$userid,
$Driverhdrs::LAB,
$result);
# Print the status of the transfer
if (!($status =~ /OK/)) {
print "$status\n";
print "Did not send autoresult string to the Autolab server.\n";
exit(1);
}
print "Success: Sent autoresult string for $userid to the Autolab server.\n";
my $status = submitr($Driverhdrs::SERVER_NAME,
$Driverhdrs::SERVER_PORT,
$Driverhdrs::COURSE_NAME,
$userid,
$Driverhdrs::LAB,
$result);
# Print the status of the transfer
if (!($status =~ /OK/)) {
print "$status\n";
print "Did not send autoresult string to the result server.\n";
exit(1);
}
print "Success: Sent autoresult string for $userid to the result server.\n";
}
}

Expand All @@ -70,8 +67,7 @@ sub driver_post ($$) {
#

#
# submitr - Sends an autoresult string to the submitr.pl CGI program
# on the Autolab server.
# submitr - Sends an autoresult string to the result server
#
sub submitr ($$$$$$) {
my $hostname = shift;
Expand All @@ -92,42 +88,41 @@ sub submitr ($$$$$$) {
# Establish the connection to the server
socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$internet_addr = inet_aton($hostname)
or die "Cound not convert $hostname to an internet address: $!\n";
or die "Could not convert $hostname to an internet address: $!\n";
$paddr = sockaddr_in($port, $internet_addr);
connect(SERVER, $paddr)
or die "Could not connect to $hostname:$port:$!\n";
or die "Could not connect to $hostname:$port:$!\n";

select((select(SERVER), $| = 1)[0]); # enable command buffering

# Send HTTP request to server
$enc_result = url_encode($result);
print SERVER "GET /unofficialSubmit.rb?course=$course&user=$userid&assessment=$lab&result=$enc_result HTTP/1.0\r\n";
print SERVER "Host: $hostname\r\n";
print SERVER "\r\n";
print SERVER "GET /$course/submitr.pl/?userid=$userid&lab=$lab&result=$enc_result&submit=submit HTTP/1.0\r\n\r\n";

# Get first HTTP response line
$line = <SERVER>;
chomp($line);
($http_version, $errcode, $errmsg) = split(/\s+/, $line);
if ($errcode != 200) {
return "Error: HTTP request failed with error $errcode: $errmsg";
return "Error: HTTP request failed with error $errcode: $errmsg";
}

# Read the remaining HTTP response header lines
while ($line = <SERVER>) {
if ($line =~ /^\r\n/) {
last;
}
if ($line =~ /^\r\n/) {
last;
}
}

# Read and return the response from the Autolab server
# Read and return the response from the result server
$line = <SERVER>;
chomp($line);

close SERVER;
return $line;

}

#
# url_encode - Encode text string so it can be included in URI of GET request
#
Expand Down
Expand Up @@ -2,7 +2,7 @@
# Makefile that builds btest and other helper programs for the CS:APP data lab
#
CC = gcc
CFLAGS = -O1 -Wall -m32
CFLAGS = -O -Wall -m32
LIBS = -lm

all: btest fshow ishow
Expand Down

0 comments on commit bbb9a20

Please sign in to comment.