-
Notifications
You must be signed in to change notification settings - Fork 0
/
KFS bridge.cpp
179 lines (151 loc) · 4.33 KB
/
KFS bridge.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <stdio.h>
#include <iostream>
#include <fstream>
#include "main.h"
#include "GPT.h"
#include "kfs.h"
std::fstream MainFile;
char* filePath;
int main()
{
filePath = (char*)"D:\\Data\\users\\Konect\\1Documents\\programmation\\Kot\\Data\\debugDisk.vhd";
GPT::Partition dataPartition = GPT::Partition(GPT::GetPartitionByGUID(GPT::GetDataGUIDPartitionType()));
FileSystem::KFS* Fs = new FileSystem::KFS(&dataPartition);
Fs->flist((char*)"system/background");
FileSystem::File* Picture = Fs->fopen((char*)"system/background/1.bmp", (char*)"r");
char* filename = (char*)"D:\\Data\\users\\Konect\\1Documents\\programmation\\Kot\\Data\\1.bmp";
FILE* f = fopen(filename, "r");
fseek(f, 0, SEEK_END);
size_t pictureSize = ftell(f);
rewind(f);
char* bufferPicture = (char*)malloc(sizeof(char) * pictureSize);
fread(bufferPicture, 1, pictureSize, f);
Picture->Write(0, pictureSize, bufferPicture);
fclose(f);
}
bool Bitmap::operator[](uint64_t index) {
return Get(index);
}
bool Bitmap::Get(uint64_t index) {
if (index > Size * 8) return false;
uint64_t byteIndex = index / 8;
uint8_t bitIndex = index % 8;
uint8_t bitIndexer = 0b10000000 >> bitIndex;
if ((Buffer[byteIndex] & bitIndexer) > 0) {
return true;
}
return false;
}
bool Bitmap::Set(uint64_t index, bool value) {
if (index > Size * 8) return false;
uint64_t byteIndex = index / 8;
uint8_t bitIndex = index % 8;
uint8_t bitIndexer = 0b10000000 >> bitIndex;
Buffer[byteIndex] &= ~bitIndexer;
if (value) {
Buffer[byteIndex] |= bitIndexer;
}
return true;
}
BitmapHeap::BitmapHeap(uint64_t size) {
bitmap = (Bitmap*)malloc(sizeof(Bitmap));
bitmap->Size = size;
bitmap->Buffer = (uint8_t*)malloc(Divide(size, 8));
}
void BitmapHeap::Free() {
free(bitmap->Buffer);
free(bitmap);
}
bool BitmapHeap::operator[](uint64_t index) {
return bitmap->Get(index);
}
bool BitmapHeap::Get(uint64_t index) {
return bitmap->Get(index);
}
bool BitmapHeap::Set(uint64_t index, bool value) {
return bitmap->Set(index, value);
}
char** split(char* str, char* delimiters) {
char* entry = str;
int len = strlen(str);
char** ReturnValue = (char**)malloc(0x200);
memset(ReturnValue, 0, 0x200);
int currentItemNumber = 0;
int checkNum = 0;
char* c = delimiters;
int currentCharNumber = 0;
int charNumberStart = 0;
int lastCharEnd = 0;
while (*str != 0) {
ReturnValue[currentItemNumber] = (char*)malloc(0x1000);
memset(ReturnValue[currentItemNumber], 0, 0x1000);
currentCharNumber++;
if (*str == *c) {
checkNum++;
c++;
}
else {
c = delimiters;
checkNum = 0;
}
if (checkNum >= strlen(delimiters)) {
c = delimiters;
charNumberStart = currentCharNumber - strlen(delimiters);
if (charNumberStart < 0) {
charNumberStart = 0;
}
int y = 0;
for (int i = lastCharEnd; i < charNumberStart; i++) {
ReturnValue[currentItemNumber][y++] = entry[i];
}
lastCharEnd = charNumberStart + strlen(delimiters);
c = delimiters;
currentItemNumber++;
checkNum = 0;
}
str++;
}
ReturnValue[currentItemNumber] = (char*)malloc(0x1000);
memset(ReturnValue[currentItemNumber], 0, 0x1000);
int y = 0;
for (int i = lastCharEnd; i < len; i++) {
ReturnValue[currentItemNumber][y++] = entry[i];
}
return ReturnValue;
}
bool ReadBit(uint8_t byte, int position)
{
return (byte >> position) & 0x1;
}
uint8_t WriteBit(uint8_t byte, int position, bool value)
{
if (value) {
byte |= 1 << position;
}
else {
byte &= ~(1 << position);
}
return byte;
}
uint64_t Divide(uint64_t value, uint64_t divider) {
uint64_t returnValue = value / divider;
if ((value % divider) != 0) {
returnValue++;
}
return returnValue;
}
bool strcmpKot(char* a, char* b) {
int alen = strlen(a);
int blen = strlen(b);
if (alen == blen) {
for (int i = 0; i < alen; i++) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}
else {
return false;
}
}