Pārlūkot izejas kodu

first commit

master
myitinos pirms 6 gadiem
revīzija
818086c96f
3 mainītis faili ar 262 papildinājumiem un 0 dzēšanām
  1. Binārs
      blackmarket
  2. +260
    -0
      blackmarket.c
  3. +2
    -0
      test.sh

Binārs
blackmarket Parādīt failu


+ 260
- 0
blackmarket.c Parādīt failu

@ -0,0 +1,260 @@
//gcc -m32 -fno-stack-protector -z execstack -no-pie blackmarket.c -o blackmarket
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "blackmarket.h"
#define BUFSIZE 0x1ff
int diamond;
void not_used(){
system("/bin/sh");
}
Node *Node_create(){
Node *node = malloc(sizeof(Node));
assert(node != NULL);
node->data = "";
node->next = NULL;
}
List *List_create(){
List *list = malloc(sizeof(List));
assert(list != NULL);
Node *node = Node_create();
list->first = node;
return list;
}
void List_append(List *list, char *str){
assert(list != NULL);
assert(str != NULL);
Node *node = list->first;
while(node->next != NULL){
node = node->next;
}
node->data = str;
node->next = Node_create();
}
int List_find(List *list, char *str){
assert(list != NULL);
assert(str != NULL);
int index = 0;
Node *node = list->first;
while(node->next != NULL){
int cmp = strcmp(str, node->data);
if(cmp == 0){
return index;
}
node = node->next;
index++;
}
return -1;
}
int List_length(List *list){
assert(list != NULL);
Node *node = list->first;
int length = 0;
while(node->next != NULL){
length++;
node = node->next;
}
return length;
}
void Node_destroy(Node *node){
assert(node != NULL);
free(node);
}
void List_remove(List *list, int index){
assert(list != NULL);
if(index < 0){
exit(0);
}else{
assert(index < List_length(list));
if(index == 0){
Node *node = list->first;
list->first = list->first->next;
Node_destroy(node);
}else{
Node *before = list->first;
for(int i=1; i<index; ++i){
before = before->next;
index--;
}
Node *node = before->next;
before->next = before->next->next;
Node_destroy(node);
}
}
}
void List_print(List *list){
if(list != NULL){
printf("[");
Node *node = list->first;
if(node->next == NULL){
printf("NULL");
}
while(node->next != NULL){
printf("%s", node->data);
node = node->next;
if (node->next != NULL){
printf(", ");
}
}
printf("]\n");
}
}
int sell_item(char *item){
int current_wallet = 0;
if(strcmp(item, "potatoes") == 0){
printf("You've earn 50 wallet!\n");
current_wallet = 50;
return current_wallet;
}else if(strcmp(item, "grape") == 0){
printf("You've earn 100 wallet!\n");
current_wallet = 100;
return current_wallet;
}else if(strcmp(item, "apel") == 0){
printf("You've earn 60 wallet!\n");
current_wallet = 60;
return current_wallet;
}
}
void message(){
printf("You don't have enough wallet!\n");
}
void success_msg(char *item){
printf("%s added to the list!\n", item);
}
void menu(){
printf("+-----------------------+\n");
printf("MASSIVE BLACKMARKET STORE\n");
printf("+-----------------------+\n");
printf("1. buy flag (200 Diamond)\n");
printf("2. buy potatoes (50 Wallet)\n");
printf("3. buy grape (100 Wallet)\n");
printf("4. buy apel (60 Wallet)\n");
printf("5. show items\n");
printf("6. sell items\n");
printf("7. check wallet\n");
printf("8. check diamond\n");
printf("9. get free diamond!\n");
printf("10. exit\n");
}
int main(){
List *l = List_create();
char buffer[BUFSIZE+1], ans[2];
int wallet = 300, temp, try = 0;
LOOP:while(1){
menu();
printf(">>");
fflush(stdout);
scanf("%s", &ans);
if(strcmp(ans, "1") == 0){
if(diamond < 200){
printf("Not enough diamond to buy flag!\nnothing to add.\n");
goto LOOP;
}else if(diamond >= 200){
diamond = diamond - 200;
List_append(l, "flag");
success_msg("flag");
goto LOOP;
}
}else if(strcmp(ans, "2") == 0){
if(wallet < 50){
message();
goto LOOP;
}
success_msg("potatoes");
wallet = wallet - 50;
List_append(l, "potatoes");
goto LOOP;
}else if(strcmp(ans, "3") == 0){
if(wallet < 100){
message();
goto LOOP;
}
success_msg("grape");
wallet = wallet - 100;
List_append(l, "grape");
goto LOOP;
}else if(strcmp(ans, "4") == 0){
if(wallet < 60){
message();
goto LOOP;
}
success_msg("apel");
wallet = wallet - 60;
List_append(l, "apel");
goto LOOP;
}else if(strcmp(ans, "5") == 0){
printf("\nYour Items :\n");
List_print(l);
goto LOOP;
}else if(strcmp(ans, "6") == 0){
getchar();
printf("What items you want to sell ?\n");
fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
printf("You sell : ");
printf(buffer);
strtok(buffer, "\n");
int check = List_find(l, buffer);
if(check == (-1)){
printf("Not Found!\n");
exit(1);
}else{
List_remove(l, List_find(l, buffer));
wallet = wallet + sell_item(buffer);
}
}else if(strcmp(ans, "7") == 0){
printf("\nYour Wallet : %d\n", wallet);
goto LOOP;
}else if(strcmp(ans, "8") == 0){
printf("\nYour diamond : %d\n", diamond);
goto LOOP;
}else if(strcmp(ans, "9") == 0){
try += 1;
srand(time(NULL));
int r = rand() % 10;
if(try <= 4){
printf("You get %d diamond\n", r);
diamond = diamond + r;
goto LOOP;
}
printf("No diamond for you!\n");
goto LOOP;
}else if(strcmp(ans, "10") == 0){
printf("Thankyou for visiting!");
exit(0);
}else{
fprintf(stderr, "Bad Request!\n");
exit(0);
}
}
}

+ 2
- 0
test.sh Parādīt failu

@ -0,0 +1,2 @@
#!/bin/bash
socat TCP-LISTEN:2324,reuseaddr,fork EXEC:"./blackmarket"

Notiek ielāde…
Atcelt
Saglabāt