Skip to content

Commit b842ff7

Browse files
committed
dramatically reduce dll size, by replacing vector<char> with char[]
Signed-off-by: fufesou <shuanglongchen@yeah.net>
1 parent 59a235b commit b842ff7

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

Img2Mem/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int write_imgdata(const std::vector<char>& data, const char* outfile)
5252

5353
ofs << "#include \"pch.h\"\n";
5454
ofs << "#include \"./img.h\"\n\n";
55-
ofs << "std::vector<unsigned char> g_img{\n";
55+
ofs << "unsigned char g_img[] = {\n";
5656

5757
auto total = data.size();
5858
const unsigned char* pdata = reinterpret_cast<const unsigned char*>(data.data());
@@ -72,7 +72,9 @@ int write_imgdata(const std::vector<char>& data, const char* outfile)
7272
ofs << buf;
7373
ofs << "\n";
7474
}
75-
ofs << "};\n";
75+
ofs << "};\n\n";
76+
77+
ofs << "long long g_imgLen = sizeof(g_img);\n";
7678

7779
return 0;
7880
}
@@ -112,7 +114,7 @@ int save_img(const char* outfile)
112114
return 0;
113115
}
114116

115-
std::copy(g_img.begin(), g_img.end(), std::ostreambuf_iterator<char>(ofs));
117+
std::copy(g_img, g_img + g_imgLen, std::ostreambuf_iterator<char>(ofs));
116118
printf("Succeeded to write to %s\n", outfile);
117119
return 0;
118120
}

WindowInjection/dllmain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ HWND CreateWin(HMODULE hModule, UINT zbid, const TCHAR* title, const TCHAR* clas
217217
return nullptr;
218218
}
219219

220-
bool test = true;
220+
bool test = false;
221221
if (test)
222222
{
223223
mi.rcMonitor.left += 100;
@@ -323,8 +323,8 @@ DWORD WINAPI UwU(LPVOID lpParam)
323323
if (g_loadFromMemory)
324324
{
325325
DIBres = g_bitmapLoader.CreateDIBFromMemory(
326-
reinterpret_cast<char*>(g_img.data()),
327-
static_cast<unsigned int>(g_img.size()),
326+
reinterpret_cast<char*>(g_img),
327+
static_cast<unsigned int>(g_imgLen),
328328
rect);
329329
}
330330
else

WindowInjection/img.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "pch.h"
22
#include "./img.h"
33

4-
std::vector<unsigned char> g_img{
4+
unsigned char g_img[] = {
55
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x07, 0x80,
66
0x00, 0x00, 0x04, 0x38, 0x08, 0x03, 0x00, 0x00, 0x00, 0xdf, 0x0d, 0x31, 0x71, 0x00, 0x00, 0x00, 0xf3, 0x50, 0x4c, 0x54,
77
0x45, 0xc7, 0xc6, 0xe1, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xc1, 0x50, 0x50, 0x5a, 0x2d, 0x2c, 0x33, 0x8e, 0x8d, 0xa0, 0xaa,
@@ -657,3 +657,5 @@ std::vector<unsigned char> g_img{
657657
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x01, 0xa8, 0x05, 0x5a, 0xd7,
658658
0x4c, 0x3a, 0x97, 0x67, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
659659
};
660+
661+
long long g_imgLen = sizeof(g_img);

WindowInjection/img.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "framework.h"
44

5-
#include <vector>
65

7-
extern std::vector<unsigned char> g_img;
6+
extern unsigned char g_img[];
7+
extern long long g_imgLen;
88

0 commit comments

Comments
 (0)