-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.cpp
605 lines (570 loc) · 17 KB
/
Parser.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
#include "Parser.h"
Parser::Parser(){}
void Parser::lexicalAnalysis(const string expr){
// step 1, create words mask
string mask, buffer;
int flag = 0; // mark that character is not space ' '
for(int i = 0; i < expr.length(); i++){
if(expr[i] != ' ' && flag == 0){
flag = 1;
}
if(expr[i] == ' '){
flag = 0;
}
mask += (char) (flag + 48);
}
// step 2, parsing tokens
flag = 0;
for(int i = 0; i < expr.length(); i++){
if(mask[i] == '1'){ // character not space only
buffer += expr[i];
flag = 1;
if(i == expr.length() - 1)
tokens.push(buffer);
}
else if(flag == 1){
tokens.push(buffer);
buffer = "";
flag = 0;
}
}
convertToPostfix();
}
int Parser::isField(string token){
string fields[22] = {"ver", "iphdrlen", "tos", "ttlen", "ttl", "proto", "ipsrc", "ipdst", "sport", "dport", "seqno", "ackno", "tcphdrlen", "urgflag", "ackflag", "pshflag", "rstflag", "synflag", "finflag", "windowsiz", "urgpnt", "udplen"};
for(int i = 0; i < 22; i++)
if(token == fields[i]){
return 1;
}
return -1;
}
int Parser::getPriority(string op){
if( op == "&&" || op == "||" )
return 1;
else if( op == "!=" || op == "==" || op == ">" || op == ">=" || op == "<" || op == "<=")
return 2;
else return -1;
}
int Parser::isOperator(string op){
if(getPriority(op) == -1){
if( op != "(" && op != ")") return -1;
else return -2;
}
return 1;
}
void Parser::convertToPostfix(){
stack<string> Stack;
string token;
while(!tokens.empty()){
token = tokens.front();
// kiem tra co phai toan tu hay khong
if(isOperator(token) == 1){
if(!Stack.empty()){
string topStack = Stack.top();
if(getPriority(topStack) > getPriority(token)){
postFix.push(topStack);
Stack.pop();
}
Stack.push(token);
}
else{
Stack.push(token);
}
}
else{
if(token == "(")
Stack.push(token);
else if(token == ")"){
string topStack;
while((topStack = Stack.top()) != "("){
postFix.push(topStack);
Stack.pop();
}
Stack.pop();
}
else
postFix.push(token);
}
tokens.pop();
}
while(!Stack.empty()){
postFix.push(Stack.top());
Stack.pop();
}
}
//v2.0
void Parser::genCode(struct sock_filter *bpfCode, struct sock_fprog *bpfProg){
string token;
vector<BlockCode> codeStack;
stack<string> expr;
offOr = 0;
offAnd = 2;
int j = 0;
while(!postFix.empty()){
token = postFix.front();
if(j == 0){
if(isField(token) == 1){
expr.push(token);
}
else{
cout<<"Wrong syntax: "<<token<< " is not a \"field\" in IP, or TCP, or UDP header!"<<endl;
exit(-1);
}
}
else{
if(isOperator(token) == 1){
if(getPriority(token) == 1){ // logical operator
if(codeStack.size() >= 2){
if(token == "&&"){
struct BlockCode b2 = codeStack.back();
codeStack.pop_back();
struct BlockCode b1 = codeStack.back();
codeStack.pop_back();
codeStack.push_back((struct BlockCode)genAnd(b1, b2));
}
else{
struct BlockCode b2 = codeStack.back();
codeStack.pop_back();
struct BlockCode b1 = codeStack.back();
codeStack.pop_back();
codeStack.push_back((struct BlockCode)genOr(b1, b2));
}
}
}
else{ // comparison operator
if(expr.size() >= 2){
string value = expr.top();
expr.pop();
string field = expr.top();
expr.pop();
if(isField(field) == 1)
codeStack.push_back((struct BlockCode)genCmp(field, value, token));
else{
cout<<"Wrong syntax!: \""<<field<<"\" is not a field"<<endl;
exit(-1);
}
}
else{
cout<<"Wrong syntax!"<<endl;
exit(-1);
}
}
}
else{// token is a value or field
expr.push(token);
}
}
postFix.pop();
j++;
}
// gen return code
struct BlockCode missRet = codeStack.back();
codeStack.pop_back();
codeStack.push_back(genRet(missRet));
// gen filter IP packet
struct BlockCode missIP = codeStack.back();
codeStack.pop_back();
codeStack.push_back(genFilterIP(missIP));
// create bpf program
struct BlockCode rs = codeStack.back();
int codeLen = rs.codeSegment.size();
if(codeLen <= 50){
bpfProg->len = codeLen;
for(int i = 0; i < codeLen; i++){
bpfCode[i].code = rs.codeSegment.front().code;
bpfCode[i].jt = rs.codeSegment.front().jt;
bpfCode[i].jf = rs.codeSegment.front().jf;
bpfCode[i].k = rs.codeSegment.front().k;
rs.codeSegment.pop();
}
}
for(int j = 0; j < codeLen; j++){
printf("Code: %.8X | Jump true: %u | Jump false: %u | K: %.8X\n", bpfCode[j].code, bpfCode[j].jt, bpfCode[j].jf, bpfCode[j].k);
}
}
struct BlockCode Parser::genRet(struct BlockCode b1){
struct BlockCode resultRet;
int b1Size = b1.codeSegment.size();
int i = 0;
while(!b1.codeSegment.empty()){
if(i == b1Size - 1){
struct my_sock_filter stmt = b1.codeSegment.front();
if(stmt.reverse != 1){
stmt.jt = (uint8_t)0;
stmt.jf = (uint8_t)1;
}
else{
stmt.jt = (uint8_t)1;
stmt.jf = (uint8_t)0;
}
resultRet.codeSegment.push(stmt);
b1.codeSegment.pop();
i++;
}
else{
resultRet.codeSegment.push(b1.codeSegment.front());
b1.codeSegment.pop();
i++;
}
}
resultRet.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_RET+BPF_K, 262144));
resultRet.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_RET+BPF_K, 0));
return resultRet;
}
struct BlockCode Parser::genFilterIP(struct BlockCode b1){
struct BlockCode resultIP;
uint8_t jumpFalse = (uint8_t)b1.codeSegment.size() - 1;
resultIP.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12));
resultIP.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, jumpFalse, 0));
while(!b1.codeSegment.empty()){
resultIP.codeSegment.push(b1.codeSegment.front());
b1.codeSegment.pop();
}
return resultIP;
}
struct BlockCode Parser::genCmp(string field, string value, string op){
struct BlockCode resultCmp;
uint32_t offset;
uint8_t jumpCode = 0;
uint8_t reverseBit = 0;
if(op == "=="){
jumpCode = BPF_JEQ;
reverseBit = 0;
}
if(op == ">"){
jumpCode = BPF_JGT;
reverseBit = 0;
}
if(op == ">="){
jumpCode = BPF_JGE;
reverseBit = 0;
}
if(op == "!="){
jumpCode = BPF_JEQ;
reverseBit = 1;
}
if(op == "<"){
jumpCode = BPF_JGE;
reverseBit = 1;
}
if(op == "<="){
jumpCode = BPF_JGT;
reverseBit = 1;
}
if(field == "ipsrc" || field == "ipdst"){
struct sockaddr_in sin;
if(inet_aton(value.c_str(), &(sin.sin_addr)) != 1){
cout<<"Wrong IP address syntax!: \""<<value<<"\""<<endl;
exit(-1);
}
uint32_t ip = ntohl((uint32_t)sin.sin_addr.s_addr);
if(field == "ipsrc")
offset = 26;
else
offset = 30;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, ip, 0, 0, reverseBit));
}
if(field == "ver"){
uint8_t ver = (uint8_t)atoi(value.c_str());
if(ver >= 64){ // version field's length = 4 bits -> max value = 63
cout<<"Wrong \"version\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 14;
resultCmp.codeSegment.push(((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset)));
// version field's length = 4 bits -> shifting right 4 bits
resultCmp.codeSegment.push(((struct my_sock_filter)MY_BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, 4)));
resultCmp.codeSegment.push(((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, ver, 0, 0, reverseBit)));
}
}
if(field == "iphdrlen"){
uint8_t iphdrlen = (uint8_t)atoi(value.c_str());
if(iphdrlen >= 64){ // header length field's length = 4 bits -> max value = 63
cout<<"Wrong \"header length\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 14;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
// select the 4 bits last
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_ALU+BPF_AND+BPF_K, 0xF));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, iphdrlen, 0, 0, reverseBit));
}
}
if(field == "tos"){
uint8_t tos = (uint8_t)atoi(value.c_str());
if(tos >= 256){ // type of service field length = 8 bits -> max value = 255
cout<<"Wrong \"tos\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 15;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, tos, 0, 0, reverseBit));
}
}
if(field == "ttlen"){
uint16_t ttlen = (uint16_t)atoi(value.c_str());
if(ttlen >= 65536){ // total length field's length = 16 bits -> max value = 65536
cout<<"Wrong \"total length\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 16;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, ttlen, 0, 0, reverseBit));
}
}
if(field == "ttl"){
uint8_t ttl = (uint8_t)atoi(value.c_str());
if(ttl >= 256){ // time-to-live field's length = 8 bits -> max value = 255
cout<<"Wrong \"time-to-live\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 22;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, ttl, 0, 0, reverseBit));
}
}
if(field == "proto"){
uint8_t proto = (uint8_t)atoi(value.c_str());
if(proto >= 256){ // protocol field's length = 8 bits -> max value = 255
cout<<"Wrong \"protocol\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else{
offset = 23;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, proto, 0, 0, reverseBit));
}
}
if(field == "sport") {
uint16_t sport = (uint16_t)atoi(value.c_str());
if(sport >= 65566) { // source port field's length = 16bits -> max value = 65535
cout<<"Wrong \"source port\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 34;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, sport, 0, 0, reverseBit));
}
}
if(field == "dport") {
uint16_t dport = (uint16_t)atoi(value.c_str());
if(dport >= 65536) { // destination port field's length = 16bits -> max value = 65535
cout<<"Wrong \"destination port\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 36;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, dport, 0, 0, reverseBit));
}
}
if(field == "seqno") {
uint32_t seqno = (uint32_t)atol(value.c_str());
if(seqno > 0xffffffff) { // sequence number field's length = 32bits -> max value = 0xffffffff
cout<<"Wrong \"sequence number\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 38;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, seqno, 0, 0, reverseBit));
}
}
if(field == "ackno") {
uint32_t ackno = (uint32_t)atol(value.c_str());
if(ackno > 0xffffffff) { //ack number field's length = 32bits -> max value = 0xffffffff
cout<<"Wrong \"acknowledgment number\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 42;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, ackno, 0, 0, reverseBit));
}
}
if(field == "tcphdrlen") {
uint8_t tcphdrlen = (uint8_t)atoi(value.c_str());
if(tcphdrlen >= 16 ) { // tcp header field's length = 4bits -> max value = 15
cout<<"Wrong \"TCP header length value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 46;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
// tcp header length field's length = 4 bits -> shifting right 4 bits
resultCmp.codeSegment.push(((struct my_sock_filter)MY_BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, 4)));
resultCmp.codeSegment.push(((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, tcphdrlen, 0, 0, reverseBit)));
}
}
if(field == "urgflag" || field == "ackflag" || field == "pshflag" || field == "rstflag" || field == "synflag" || field == "finflag") {
uint8_t flag = (uint8_t)atoi(value.c_str());
if(flag > 1) { // flag only store in 1 bit
cout<<"Wrong \""<<field<<"\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
int mask = 0, bitShift = 0;
if(field == "urgflag") {
mask = 0x20;
bitShift = 5;
}
if(field == "ackflag") {
mask = 0x10;
bitShift = 4;
}
if(field == "pshflag") {
mask = 0x08;
bitShift = 3;
}
if(field == "rstflag") {
mask = 0x04;
bitShift = 2;
}
if(field == "synflag") {
mask = 0x02;
bitShift = 1;
}
if(field == "finflag") {
mask = 0x01;
bitShift = 0;
}
offset = 47;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_B+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_ALU+BPF_AND+BPF_K, mask));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, bitShift));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, flag, 0, 0, reverseBit));
}
}
if(field == "windowsiz") {
uint16_t windowsiz = (uint16_t)atoi(value.c_str());
if(windowsiz > 0xffff) { // window size field's length = 16bits -> max value = 0xffff
cout<<"Wrong \"window size\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 48;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, windowsiz, 0, 0, reverseBit));
}
}
if(field == "urgpnt") {
uint16_t urgpnt = (uint16_t)atoi(value.c_str());
if(urgpnt > 0xffff) { // urgent pointer field's length = 16bits -> max value = 0xffff
cout<<"Wrong \"urgent pointer\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 52;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, urgpnt, 0, 0, reverseBit));
}
}
if(field == "udplen") {
uint16_t udplen = (uint16_t)atoi(value.c_str());
if(udplen > 0xffff) { // urgent pointer field's length = 16bits -> max value = 0xffff
cout<<"Wrong \"udp length\" value: \""<<value<<"\""<<endl;
exit(-1);
}
else {
offset = 38;
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_STMT(BPF_LD+BPF_H+BPF_ABS, offset));
resultCmp.codeSegment.push((struct my_sock_filter)MY_BPF_JUMP(BPF_JMP+jumpCode+BPF_K, udplen, 0, 0, reverseBit));
}
}
return resultCmp;
}
struct BlockCode Parser::genAnd(struct BlockCode b1, struct BlockCode b2){
uint8_t b1Size = (uint8_t)b1.codeSegment.size();
uint8_t b2Size = (uint8_t)b2.codeSegment.size();
uint8_t jumpTrue;
uint8_t jumpFalse;
if(offOr != 0){
offAnd = b2Size + 2;
jumpTrue = 0;
jumpFalse = b2Size + 2 - offOr;
}
else{
offAnd = b2Size + 2;
jumpTrue = 0;
jumpFalse = b2Size + 2 - 1;
}
struct BlockCode resultAnd;
uint8_t i = 0;
while(!b1.codeSegment.empty()){
if(i == b1Size - 1){ // BPF_JUMP()
struct my_sock_filter stmt = b1.codeSegment.front();
if(stmt.reverse != 1){
stmt.jt = jumpTrue;
stmt.jf = jumpFalse;
}
else{
stmt.jt = jumpFalse;
stmt.jf = jumpTrue;
}
resultAnd.codeSegment.push(stmt);
b1.codeSegment.pop();
i++;
}
else{
resultAnd.codeSegment.push(b1.codeSegment.front());
b1.codeSegment.pop();
i++;
}
}
while(!b2.codeSegment.empty()){
resultAnd.codeSegment.push(b2.codeSegment.front());
b2.codeSegment.pop();
}
return resultAnd;
}
struct BlockCode Parser::genOr(struct BlockCode b1, struct BlockCode b2){
uint8_t b1Size = (uint8_t)b1.codeSegment.size();
uint8_t b2Size = (uint8_t)b2.codeSegment.size();
uint8_t jumpTrue;
uint8_t jumpFalse;
if(offAnd != 0){
offOr = b2Size + 2;
jumpTrue = b2Size + 2 - offAnd;
jumpFalse = 0;
}
else{
offOr = b2Size + 2;
jumpTrue = b2Size + 2 - 2;
jumpFalse = 0;
}
struct BlockCode resultOr;
uint8_t i = 0;
while(!b1.codeSegment.empty()){
if(i == b1Size - 1){
struct my_sock_filter stmt = b1.codeSegment.front();
if(stmt.reverse != 1){
stmt.jt = jumpTrue;
stmt.jf = jumpFalse;
}
else{
stmt.jt = jumpFalse;
stmt.jf = jumpTrue;
}
resultOr.codeSegment.push(stmt);
b1.codeSegment.pop();
i++;
}
else{
resultOr.codeSegment.push(b1.codeSegment.front());
b1.codeSegment.pop();
i++;
}
}
while(!b2.codeSegment.empty()){
resultOr.codeSegment.push(b2.codeSegment.front());
b2.codeSegment.pop();
}
return resultOr;
}