Skip to content

Commit 55e30b1

Browse files
committed
up
1 parent fa58018 commit 55e30b1

File tree

16 files changed

+253
-172
lines changed

16 files changed

+253
-172
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "ClientSDKUpdateUI.h"
2+
#include "Engine.h"
3+
#include "KBEvent.h"
4+
#include "KBEngine.h"
5+
#include "KBEventTypes.h"
6+
#include "SlateOptMacros.h"
7+
8+
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
9+
void SClientSDKUpdateUI::Construct(const FArguments& args)
10+
{
11+
FTextBlockStyle textStyle = FCoreStyle::Get().GetWidgetStyle< FTextBlockStyle >("NormalText");
12+
textStyle.SetFont(FSlateFontInfo("Veranda", 26));
13+
textStyle.SetColorAndOpacity(FLinearColor::White);
14+
15+
ChildSlot
16+
[
17+
SNew(SOverlay)
18+
/*+ SOverlay::Slot()
19+
.HAlign(HAlign_Center)
20+
.VAlign(VAlign_Top)
21+
[
22+
SNew(STextBlock)
23+
.ColorAndOpacity(FLinearColor::White)
24+
.ShadowColorAndOpacity(FLinearColor::Black)
25+
.ShadowOffset(FIntPoint(-1, 1))
26+
.Font(FSlateFontInfo("Arial", 26))
27+
.Text(FText::FromString("Main Menu"))
28+
]*/
29+
+ SOverlay::Slot()
30+
.HAlign(HAlign_Center)
31+
.VAlign(VAlign_Center)
32+
[
33+
SNew(SVerticalBox)
34+
+ SVerticalBox::Slot()
35+
.Padding(20)
36+
[
37+
SNew(SButton)
38+
.Text(FText::FromString("Update SDK"))
39+
.TextStyle(&textStyle)
40+
.ContentPadding(FMargin(30.0, 15.0))
41+
.ButtonColorAndOpacity(FLinearColor::Green)
42+
.HAlign(HAlign_Center)
43+
.VAlign(VAlign_Top)
44+
.OnClicked(this, &SClientSDKUpdateUI::UpdateSDKClicked)
45+
]
46+
]
47+
];
48+
}
49+
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
50+
51+
FReply SClientSDKUpdateUI::UpdateSDKClicked()
52+
{
53+
if (GEngine)
54+
{
55+
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Yellow, TEXT("Update SDK!"));
56+
}
57+
58+
UKBEventData_onDownloadSDK* pEventData = NewObject<UKBEventData_onDownloadSDK>();
59+
pEventData->isDownload = true;
60+
KBENGINE_EVENT_FIRE(KBEventTypes::onDownloadSDK, pEventData);
61+
return FReply::Handled();
62+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include "KBEnginePluginsPrivatePCH.h"
4+
5+
6+
class KBENGINEPLUGINS_API SClientSDKUpdateUI : public SCompoundWidget
7+
{
8+
9+
public:
10+
SLATE_BEGIN_ARGS(SClientSDKUpdateUI){}
11+
12+
SLATE_END_ARGS()
13+
14+
void Construct(const FArguments& args);
15+
16+
FReply UpdateSDKClicked();
17+
18+
19+
};

Plugins/kbengine_ue4_plugins/Source/KBEnginePlugins/Engine/EncryptionFilter.cpp

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@
55
#include "PacketSenderKCP.h"
66
#include "Engine/KBDebug.h"
77

8-
#ifndef KBENGINE_NO_CRYPTO
9-
#include "cryptlib.h"
10-
#include "rdrand.h"
11-
#include "secblock.h"
12-
#endif
8+
EncryptionFilter::~EncryptionFilter()
9+
{
10+
}
1311

14-
BlowfishFilter::BlowfishFilter(int keySize):
12+
BlowfishFilter::BlowfishFilter(int keySize) :
1513
isGood_(false),
1614
pPacket_(new MemoryStream()),
1715
pEncryptStream_(new MemoryStream()),
1816
packetLen_(0),
19-
padSize_(0)
17+
padSize_(0),
18+
key_(),
19+
keySize_(0),
20+
pBlowFishKey_(NULL)
2021
{
21-
#ifndef KBENGINE_NO_CRYPTO
22-
key_.Init(0, keySize);
22+
unsigned char buf[20] = "";
23+
RAND_bytes(buf, 20);
24+
key_ = (char *)buf;
25+
keySize_ = key_.Len();
2326

24-
CryptoPP::RDRAND rng;
25-
rng.GenerateBlock(key_.GetData(), key_.Num());
2627
init();
27-
#endif
2828
}
2929

30-
BlowfishFilter::BlowfishFilter(const TArray<uint8>& key):
30+
BlowfishFilter::BlowfishFilter(const FString & key) :
3131
isGood_(false),
32-
key_(key),
3332
pPacket_(new MemoryStream()),
3433
pEncryptStream_(new MemoryStream()),
3534
packetLen_(0),
36-
padSize_(0)
35+
padSize_(0),
36+
key_(key),
37+
keySize_(key_.Len()),
38+
pBlowFishKey_(NULL)
3739
{
3840
init();
3941
}
@@ -42,31 +44,32 @@ BlowfishFilter::~BlowfishFilter()
4244
{
4345
KBE_SAFE_RELEASE(pPacket_);
4446
KBE_SAFE_RELEASE(pEncryptStream_);
47+
KBE_SAFE_RELEASE(pBlowFishKey_);
4548
}
4649

4750
bool BlowfishFilter::init()
4851
{
49-
#ifndef KBENGINE_NO_CRYPTO
50-
if (key_.Num() >= encripter.MinKeyLength() && key_.Num() <= encripter.MaxKeyLength())
52+
pBlowFishKey_ = new BF_KEY;
53+
54+
if (MIN_KEY_SIZE <= keySize_ && keySize_ <= MAX_KEY_SIZE)
5155
{
52-
encripter.SetKey(key_.GetData(), key_.Num());
53-
decripter.SetKey(key_.GetData(), key_.Num());
56+
57+
BF_set_key(this->pBlowFishKey(), key_.Len(), reinterpret_cast<const unsigned char*>(TCHAR_TO_ANSI(*key_)));
5458
isGood_ = true;
5559
}
5660
else
5761
{
58-
ERROR_MSG("BlowfishFilter::init: invalid length %d", key_.Num());
62+
ERROR_MSG("BlowfishFilter::init: invalid length %d", key_.Len());
5963
isGood_ = false;
6064
}
61-
#endif
65+
6266
return isGood_;
6367
}
6468

6569
void BlowfishFilter::encrypt(MemoryStream *pMemoryStream)
6670
{
6771
// BlowFish 每次只能加密和解密8字节数据
6872
// 不足8字节则填充0
69-
#ifndef KBENGINE_NO_CRYPTO
7073
uint8 padSize = 0;
7174

7275
if (pMemoryStream->length() % BLOCK_SIZE != 0)
@@ -86,12 +89,10 @@ void BlowfishFilter::encrypt(MemoryStream *pMemoryStream)
8689

8790
pMemoryStream->swap(*pEncryptStream_);
8891
pEncryptStream_->clear(false);
89-
#endif
9092
}
9193

9294
void BlowfishFilter::encrypt(uint8 *buf, MessageLengthEx len)
9395
{
94-
#ifndef KBENGINE_NO_CRYPTO
9596
if (len % BLOCK_SIZE != 0)
9697
{
9798
ERROR_MSG("BlowfishFilter::encrypt: Input length (%d) is not a multiple of block size ", len);
@@ -113,9 +114,8 @@ void BlowfishFilter::encrypt(uint8 *buf, MessageLengthEx len)
113114
prevBlock = *(uint64*)(data + i);
114115
}
115116

116-
encripter.ProcessData(data + i, data + i, BLOCK_SIZE);
117+
BF_ecb_encrypt(data + i, data + i, this->pBlowFishKey(), BF_ENCRYPT);
117118
}
118-
#endif
119119
}
120120

121121
void BlowfishFilter::encrypt(uint8 *buf, MessageLengthEx offset, MessageLengthEx len)
@@ -130,7 +130,6 @@ void BlowfishFilter::decrypt(MemoryStream *pMemoryStream)
130130

131131
void BlowfishFilter::decrypt(uint8 *buf, MessageLengthEx len)
132132
{
133-
#ifndef KBENGINE_NO_CRYPTO
134133
if (len % BLOCK_SIZE != 0)
135134
{
136135
ERROR_MSG("BlowfishFilter::decrypt: Input length (%d) is not a multiple of block size ", len);
@@ -141,16 +140,15 @@ void BlowfishFilter::decrypt(uint8 *buf, MessageLengthEx len)
141140
uint64 prevBlock = 0;
142141
for (uint32 i = 0; i < len; i += BLOCK_SIZE)
143142
{
144-
decripter.ProcessData(data + i, data + i, BLOCK_SIZE);
143+
BF_ecb_encrypt(data + i, data + i, this->pBlowFishKey(), BF_DECRYPT);
145144

146145
if (prevBlock != 0)
147146
{
148147
*(uint64*)(data + i) = *(uint64*)(data + i) ^ (prevBlock);
149148
}
150-
149+
151150
prevBlock = *(uint64*)(data + i);
152151
}
153-
#endif
154152
}
155153

156154
void BlowfishFilter::decrypt(uint8 *buf, MessageLengthEx offset, MessageLengthEx len)
@@ -160,21 +158,18 @@ void BlowfishFilter::decrypt(uint8 *buf, MessageLengthEx offset, MessageLengthEx
160158

161159
bool BlowfishFilter::send(PacketSenderBase* pPacketSender, MemoryStream *pPacket)
162160
{
163-
#ifndef KBENGINE_NO_CRYPTO
164161
if (!isGood_)
165162
{
166163
ERROR_MSG("BlowfishFilter::send: Dropping packet due to invalid filter");
167164
return false;
168165
}
169166

170167
encrypt(pPacket);
171-
#endif
172168
return pPacketSender->send(pPacket);;
173169
}
174170

175171
bool BlowfishFilter::recv(MessageReader* pMessageReader, MemoryStream *pPacket)
176172
{
177-
#ifndef KBENGINE_NO_CRYPTO
178173
if (!isGood_)
179174
{
180175
ERROR_MSG("BlowfishFilter::recv: Dropping packet due to invalid filter");
@@ -185,7 +180,7 @@ bool BlowfishFilter::recv(MessageReader* pMessageReader, MemoryStream *pPacket)
185180
uint32 len = pPacket->length();
186181
uint16 packeLen = pPacket->readUint16();
187182

188-
if ( 0 == pPacket_->length() && len > MIN_PACKET_SIZE && packeLen - 1 == len - 3)
183+
if (0 == pPacket_->length() && len > MIN_PACKET_SIZE && packeLen - 1 == len - 3)
189184
{
190185
int padSize = pPacket->readUint8();
191186
decrypt(pPacket);
@@ -267,12 +262,6 @@ bool BlowfishFilter::recv(MessageReader* pMessageReader, MemoryStream *pPacket)
267262
packetLen_ = 0;
268263
padSize_ = 0;
269264
}
270-
#else
271-
if (pMessageReader)
272-
{
273-
pMessageReader->process(pPacket->data() + pPacket->rpos(), 0, pPacket->length());
274-
}
275-
#endif
276-
277265
return true;
278266
}
267+
Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#pragma once
22
#include "KBECommon.h"
33

4-
#ifndef KBENGINE_NO_CRYPTO
5-
// https://stackoverflow.com/questions/51416259/unreal-engine-4-20-build-error-in-plugin-adaptive-unity-build-disabling-pch-f
6-
#pragma warning(disable:4668) // x is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
7-
#include "blowfish.h"
8-
#pragma warning(default:4668)
9-
#include "modes.h"
4+
#if PLATFORM_WINDOWS
5+
#include "WindowsHWrapper.h"
6+
#include "AllowWindowsPlatformTypes.h"
107
#endif
118

9+
#define UI UI_ST
10+
THIRD_PARTY_INCLUDES_START
11+
#include "openssl/rand.h"
12+
#include "openssl/blowfish.h"
13+
THIRD_PARTY_INCLUDES_END
14+
#undef UI
15+
16+
#if PLATFORM_WINDOWS
17+
#include "HideWindowsPlatformTypes.h"
18+
#endif
1219

1320
class MemoryStream;
1421
class PacketSenderBase;
@@ -17,8 +24,9 @@ class MessageReader;
1724
class EncryptionFilter
1825
{
1926
public:
20-
virtual ~EncryptionFilter() {}
2127

28+
EncryptionFilter() {}
29+
virtual ~EncryptionFilter();
2230
virtual void encrypt(MemoryStream *pMemoryStream) = 0;
2331
virtual void encrypt(uint8 *buf, MessageLengthEx len) = 0;
2432
virtual void encrypt(uint8 *buf, MessageLengthEx offset, MessageLengthEx len) = 0;
@@ -39,11 +47,20 @@ class BlowfishFilter : public EncryptionFilter
3947
static const uint32 BLOCK_SIZE = 64 / 8;
4048
static const uint32 MIN_PACKET_SIZE = (sizeof(MessageLength) + 1 + BLOCK_SIZE);
4149

42-
BlowfishFilter(int keySize=16);
43-
BlowfishFilter(const TArray<uint8>& key);
50+
51+
// key的最小和最大大小
52+
static const int MIN_KEY_SIZE = 32 / 8;
53+
static const int MAX_KEY_SIZE = 448 / 8;
54+
55+
// 默认key的大小
56+
static const int DEFAULT_KEY_SIZE = 128 / 8;
57+
58+
BlowfishFilter(const FString & key);
59+
BlowfishFilter(int keySize = DEFAULT_KEY_SIZE);
60+
4461
virtual ~BlowfishFilter();
4562

46-
virtual void encrypt(MemoryStream *pMemoryStream) ;
63+
virtual void encrypt(MemoryStream *pMemoryStream);
4764
virtual void encrypt(uint8 *buf, MessageLengthEx len);
4865
virtual void encrypt(uint8 *buf, MessageLengthEx offset, MessageLengthEx len);
4966

@@ -54,22 +71,29 @@ class BlowfishFilter : public EncryptionFilter
5471
virtual bool send(PacketSenderBase *pPacketSender, MemoryStream *pPacket);
5572
virtual bool recv(MessageReader *pMessageReader, MemoryStream *pPacket);
5673

57-
TArray<uint8>& key() {
58-
return key_;
74+
75+
BF_KEY * pBlowFishKey() { return (BF_KEY*)pBlowFishKey_; }
76+
77+
TArray<uint8> key()
78+
{
79+
TArray<uint8> keyArray;
80+
keyArray.SetNum(key_.Len());
81+
memcpy(keyArray.GetData(), TCHAR_TO_ANSI(*key_), key_.Len());
82+
83+
return keyArray;
5984
}
6085

6186
private:
6287
bool init();
6388

6489
private:
6590
bool isGood_;
66-
TArray<uint8> key_;
6791
MemoryStream* pPacket_;
6892
MemoryStream* pEncryptStream_;
6993
MessageLength packetLen_;
7094
uint8 padSize_;
71-
#ifndef KBENGINE_NO_CRYPTO
72-
CryptoPP::ECB_Mode<CryptoPP::Blowfish>::Encryption encripter;
73-
CryptoPP::ECB_Mode<CryptoPP::Blowfish>::Decryption decripter;
74-
#endif
95+
96+
FString key_;
97+
int keySize_;
98+
void * pBlowFishKey_;
7599
};

0 commit comments

Comments
 (0)