Skip to content

Commit 35fa200

Browse files
committed
Add ENCRYPTION_KEY file
1 parent 7eaa7c8 commit 35fa200

File tree

5 files changed

+151
-5
lines changed

5 files changed

+151
-5
lines changed

ENCRYPTION_KEY

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
USE YOUR OWN KEY

scripts/pack.js scripts/package.js

File renamed without changes.

src/CMakeLists.txt

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
cmake_minimum_required(VERSION 3.1)
22

3-
# Have to set this before creating project.
4-
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
5-
3+
# Makefiles do not work without a build type.
64
if((CMAKE_GENERATOR STREQUAL "Unix Makefiles") AND (NOT CMAKE_BUILD_TYPE))
75
message(FATAL_ERROR "You must specify a build type.")
86
endif()
97

8+
# Target macOS version, Have to set this before creating project.
9+
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
10+
11+
# Project name and executable name.
1012
project(muban)
1113
set(APP_NAME "muban")
1214

15+
# Utility executable, not shipped in final product.
16+
add_executable(bin2c bin2c.c)
17+
18+
# The main executable.
1319
file(GLOB APP_SRC "*.h" "*.cc")
14-
add_executable(${APP_NAME} ${APP_SRC})
20+
add_executable(${APP_NAME}
21+
${APP_SRC} "${CMAKE_CURRENT_BINARY_DIR}/encryption_key.h")
22+
23+
# Convert the ENCRYPTION_KEY file into encryption_key.h
24+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/encryption_key.h
25+
COMMAND bin2c -c ../ENCRYPTION_KEY ${CMAKE_CURRENT_BINARY_DIR}/encryption_key.h
26+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
27+
DEPENDS bin2c ../ENCRYPTION_KEY)
28+
target_include_directories(${APP_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
1529

30+
# Get the absolute path the libyue.
1631
get_filename_component(LIBYUE_DIR
1732
"${CMAKE_SOURCE_DIR}/../libyue"
1833
ABSOLUTE)
1934

20-
35+
# Add libyue to include dirs.
2136
target_include_directories(${APP_NAME} PRIVATE "${LIBYUE_DIR}/include")
37+
38+
# Use C++14 standard.
2239
set_target_properties(${APP_NAME} PROPERTIES
2340
CXX_STANDARD 14
2441
CXX_STANDARD_REQUIRED ON

src/bin2c.c

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* bin2c.c
3+
*
4+
* convert a binary file into a C source vector
5+
*
6+
* THE "BEER-WARE LICENSE" (Revision 3.1415):
7+
* sandro AT sigala DOT it wrote this file. As long as you retain this notice you can do
8+
* whatever you want with this stuff. If we meet some day, and you think this stuff is
9+
* worth it, you can buy me a beer in return. Sandro Sigala
10+
*
11+
* syntax: bin2c [-c] [-z] <input_file> <output_file>
12+
*
13+
* -c add the "const" keyword to definition
14+
* -z terminate the array with a zero (useful for embedded C strings)
15+
*
16+
* examples:
17+
* bin2c -c myimage.png myimage_png.cpp
18+
* bin2c -z sometext.txt sometext_txt.cpp
19+
*/
20+
21+
#include <ctype.h>
22+
#include <stdio.h>
23+
#include <stdlib.h>
24+
#include <string.h>
25+
26+
#ifndef PATH_MAX
27+
#define PATH_MAX 1024
28+
#endif
29+
30+
int useconst = 0;
31+
int zeroterminated = 0;
32+
33+
int myfgetc(FILE *f)
34+
{
35+
int c = fgetc(f);
36+
if (c == EOF && zeroterminated)
37+
{
38+
zeroterminated = 0;
39+
return 0;
40+
}
41+
return c;
42+
}
43+
44+
void process(const char *ifname, const char *ofname)
45+
{
46+
FILE *ifile, *ofile;
47+
ifile = fopen(ifname, "rb");
48+
if (ifile == NULL)
49+
{
50+
fprintf(stderr, "cannot open %s for reading\n", ifname);
51+
exit(1);
52+
}
53+
ofile = fopen(ofname, "wb");
54+
if (ofile == NULL)
55+
{
56+
fprintf(stderr, "cannot open %s for writing\n", ofname);
57+
exit(1);
58+
}
59+
char buf[PATH_MAX], *p;
60+
const char *cp;
61+
if ((cp = strrchr(ifname, '/')) != NULL)
62+
{
63+
++cp;
64+
} else {
65+
if ((cp = strrchr(ifname, '\\')) != NULL)
66+
++cp;
67+
else
68+
cp = ifname;
69+
}
70+
strcpy(buf, cp);
71+
for (p = buf; *p != '\0'; ++p)
72+
{
73+
if (!isalnum(*p))
74+
*p = '_';
75+
}
76+
fprintf(ofile, "static %sunsigned char %s[] = {\n", useconst ? "const " : "", buf);
77+
int c, col = 1;
78+
while ((c = myfgetc(ifile)) != EOF)
79+
{
80+
if (col >= 78 - 6)
81+
{
82+
fputc('\n', ofile);
83+
col = 1;
84+
}
85+
fprintf(ofile, "0x%.2x,", c);
86+
col += 6;
87+
}
88+
fprintf(ofile, "\n};\n");
89+
90+
fclose(ifile);
91+
fclose(ofile);
92+
}
93+
94+
void usage(void)
95+
{
96+
fprintf(stderr, "usage: bin2c [-cz] <input_file> <output_file>\n");
97+
exit(1);
98+
}
99+
100+
int main(int argc, char **argv)
101+
{
102+
while (argc > 3)
103+
{
104+
if (!strcmp(argv[1], "-c"))
105+
{
106+
useconst = 1;
107+
--argc;
108+
++argv;
109+
} else if (!strcmp(argv[1], "-z"))
110+
{
111+
zeroterminated = 1;
112+
--argc;
113+
++argv;
114+
} else {
115+
usage();
116+
}
117+
}
118+
if (argc != 3)
119+
{
120+
usage();
121+
}
122+
process(argv[1], argv[2]);
123+
return 0;
124+
}

src/main.cc

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "base/command_line.h"
44
#include "nativeui/nativeui.h"
55

6+
// Generated from the ENCRYPTION_KEY file.
7+
#include "encryption_key.h"
8+
static_assert(sizeof(ENCRYPTION_KEY) == 16, "ENCRYPTION_KEY must be 16 bytes");
9+
610
#if defined(OS_WIN)
711
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
812
base::CommandLine::Init(0, nullptr);

0 commit comments

Comments
 (0)