Skip to content

Commit

Permalink
add class-3 class-4 code.
Browse files Browse the repository at this point in the history
  • Loading branch information
forhappy committed Nov 16, 2011
1 parent 0047c36 commit efda613
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Code/class-3/echo.c
@@ -0,0 +1,32 @@
/*
* =====================================================================================
*
* Filename: echo.c
*
* Description: echo
*
* Version: 1.0
* Created: 10/21/2011 09:14:08 PM
* Revision: none
* Compiler: gcc
*
* Author: Fu Haiping
* Company: ICT
*
* =====================================================================================
*/
/* Echo Line */
#include <stdio.h>
void echo()
{
char buf[4];
gets(buf);
puts(buf);
}

int main(int argc, const char *argv[])
{
echo();
return 0;
}

Binary file added Code/class-3/echo.s
Binary file not shown.
Binary file added Code/class-3/exploit
Binary file not shown.
42 changes: 42 additions & 0 deletions Code/class-3/exploit.c
@@ -0,0 +1,42 @@
/*
* =====================================================================================
*
* Filename: exploit.c
*
* Description: simple exploit
*
* Version: 1.0
* Created: 10/21/2011 09:19:42 PM
* Revision: none
* Compiler: gcc
*
* Author: Fu Haiping
* Company: ICT
*
* =====================================================================================
*/

#include <stdio.h>

void echo()
{
printf("hello in echo.\n");
}


void callee()
{
printf("hello in caller.\n");
}
void caller()
{
int dummy[3];
callee();
printf("done in callee.\n");
}

int main(int argc, const char * argv[])
{
caller();
return 0;
}
57 changes: 57 additions & 0 deletions Code/class-4/time-consume.c
@@ -0,0 +1,57 @@
/*
* =====================================================================================
*
* Filename: time-consume.c
*
* Description: a time-comsuming application.
*
* Version: 1.0
* Created: 10/25/2011 10:07:20 AM
* Revision: r1
* Compiler: gcc
*
* Author: Fu Haiping
* Company: ICT
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int a(void)
{
int i=0,g=0;
while(i++<100000)
{
g+=i;
}
return g;
}

int b(void)
{
int i=0,g=0;
while(i++<400000)
{
g+=i;
}
return g;
}
int main(int argc, char** argv)
{
int iterations;
if(argc != 2)
{
printf("Usage %s <No of Iterations>\n", argv[0]);
exit(-1);
}
else
iterations = atoi(argv[1]);
printf("No of iterations = %d\n", iterations);
while(iterations--)
{
a();
b();
}
}

0 comments on commit efda613

Please sign in to comment.