/
monster.h
105 lines (91 loc) · 2.38 KB
/
monster.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef MONSTER
#define MONSTER
#include <stdlib.h>
#include <iostream>
#include "order.h"
#include <vector>
#include <string>
const uint8_t ARRSIZE = 7;
const std::string FLAVORS[ARRSIZE] {
"Regular (gross)",
"Ultra White",
"Ultra Blue",
"Ultra Fiesta",
"Ultra Black",
"Ultra Sunrise",
"Ultra Violet",
};
class Monster : public Order {
private:
uint32_t buffer;
uint32_t buffer2 ;
uint32_t quantities[ARRSIZE];
public:
Monster() { price = Price();}
Monster(Monster& other) {
price = Price(other.price);
memcpy(quantities, other.quantities, sizeof(quantities));
number = other.number;
state = other.state;
buffer = 0x20;
}
Monster(Monster*& other) {
price = Price(other->price);
memcpy(quantities, other->quantities, sizeof(quantities));
number = other->number;
state = other->state;
}
void get_params();
void edit_params();
void print_params(std::ostream& out) const;
std::string get_type() const { return "Monster (TM)"; }
};
void Monster::get_params() {
std::cout << "Choose y/n and enter a quantity for each Monster (TM) type\n";
int i = 0;
char in;
int qty;
while (i < ARRSIZE) {
qty = 0;
std::cout << "Would you like any " << FLAVORS[i] << "? ";
std::cin >> in;
if (in == 'y') {
std::cout << "How many would you like? ";
std::cin >> quantities[i];
}
i++;
}
}
void Monster::edit_params() {
long long n;
n = 0;
for (; n < ARRSIZE; n++)
std::cout << n + 1 << ". " << FLAVORS[n] << std::endl;
printf("Choose an flavor to edit: ");
std::cin >> n;
if (n < 0) goto fail;
else {
// vuln here - logic sequence error
// entering index 0 allows an OOB write at quantities[0xff]
n--;
long long s = ARRSIZE;
if (n < s) {
std::cout << "Enter a new quantity: ";
std::cin >> quantities[(uint8_t)n];
return;
}
else { goto fail; }
}
fail:
std::cout << "[ ERROR ] : invalid flavor index\n";
return;
}
void Monster::print_params(std::ostream& out) const {
out << "Order quantities: \n";
int j = 0;
for (auto i : quantities) {
out << FLAVORS[j] << ": " << i << std::endl;
j++;
}
}
#endif