Skip to content

Commit

Permalink
Merge pull request #16 from Gatsik/improve-windows-performance
Browse files Browse the repository at this point in the history
Improve windows performance
  • Loading branch information
Brutus5000 authored Jun 3, 2024
2 parents 5a2c98d + 425d53c commit 15689c0
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 36 deletions.
173 changes: 173 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "Release Version"
required: true

jobs:
build-windows:
runs-on: ubuntu-latest
environment: release
env:
PUB_KEY: ${{ secrets.UID_PUBLIC_KEY_PEM }}
MXE_DIR: /usr/lib/mxe
MXE_TARGET: x86_64-w64-mingw32.static
MXE_PACKAGE_PREFIX: mxe-x86-64-w64-mingw32.static

steps:
- uses: actions/checkout@v4

- name: Write PUB key into file
run: echo "$PUB_KEY" > faf_pub.pem

- name: Configure MXE
run: |
echo "deb https://pkg.mxe.cc/repos/apt focal main" | sudo tee /etc/apt/sources.list.d/mxeapt.list
wget -qO- https://pkg.mxe.cc/repos/apt/client-conf/mxeapt.gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/mxeapt.gpg
sudo apt-get update
# the part without MXE_PACKAGE_PREFIX is from https://mxe.cc/#requirements
sudo apt-get install \
autoconf \
automake \
autopoint \
bash \
bison \
bzip2 \
flex \
g++ \
g++-multilib \
gettext \
git \
gperf \
intltool \
libc6-dev-i386 \
libgdk-pixbuf2.0-dev \
libltdl-dev \
libgl-dev \
libpcre3-dev \
libssl-dev \
libtool-bin \
libxml-parser-perl \
lzip \
make \
openssl \
p7zip-full \
patch \
perl \
python3 \
python3-distutils \
python3-mako \
python3-packaging \
python3-pkg-resources \
python-is-python3 \
ruby \
sed \
sqlite3 \
unzip \
wget \
xz-utils \
$MXE_PACKAGE_PREFIX-jsoncpp \
$MXE_PACKAGE_PREFIX-cryptopp \
$MXE_PACKAGE_PREFIX-icu4c
- name: Build
run: |
$MXE_DIR/usr/bin/$MXE_TARGET-cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCRYPTOPP_LIBRARIES=$MXE_DIR/usr/$MXE_TARGET/lib/libcryptopp.a \
-DCRYPTOPP_INCLUDE_DIRS=$MXE_DIR/usr/$MXE_TARGET/include \
-DUID_SKIP_LEGACY=On \
-DUID_PUBKEY_BYTES=$(./encode_openssl_modulus.py $(openssl rsa -noout -inform PEM -in faf_pub.pem -pubin -modulus)) \
-B build
make -C build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: faf-uid-windows
path: build/faf-uid.exe

build-linux:
runs-on: ubuntu-latest
environment: release
env:
PUB_KEY: ${{ secrets.UID_PUBLIC_KEY_PEM }}
JSONCPP_VERSION: 1.7.7
CRYPTOPP_VERSION: 8_9_0

steps:
- uses: actions/checkout@v4

- name: Write PUB key into file
run: echo "$PUB_KEY" > faf_pub.pem

- name: Build jsoncpp
run: |
wget https://github.com/open-source-parsers/jsoncpp/archive/$JSONCPP_VERSION.tar.gz -O jsoncpp.tar.gz
tar xfz jsoncpp.tar.gz
cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_SHARED_LIBS=OFF \
-B jsoncpp-build \
-S jsoncpp-$JSONCPP_VERSION
make -C jsoncpp-build
- name: Build cryptopp
run: |
wget https://github.com/weidai11/cryptopp/archive/CRYPTOPP_$CRYPTOPP_VERSION.zip -O cryptopp.zip
unzip ./cryptopp.zip
mv cryptopp-CRYPTOPP_$CRYPTOPP_VERSION cryptopp
make -C cryptopp -f GNUmakefile CXXFLAGS='-DNDEBUG -O3' libcryptopp.a
- name: Build
run: |
cmake \
-DJSONCPP_LIBRARIES=$(pwd)/jsoncpp-build/src/lib_json/libjsoncpp.a \
-DJSONCPP_INCLUDE_DIRS=$(pwd)/jsoncpp-$JSONCPP_VERSION/include \
-DCRYPTOPP_LIBRARIES=$(pwd)/cryptopp/libcryptopp.a \
-DCRYPTOPP_INCLUDE_DIRS=$(pwd)/cryptopp \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DUID_PUBKEY_BYTES=$(./encode_openssl_modulus.py $(openssl rsa -noout -inform PEM -in faf_pub.pem -pubin -modulus)) \
-B build
make -C build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: faf-uid-linux
path: build/faf-uid

create-release:
needs: [build-windows, build-linux]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: faf-uid-windows
path: release-artifacts/

- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
name: faf-uid-linux
path: release-artifacts/

- name: Create release
id: create_release
uses: ncipollo/[email protected]
with:
commit: ${{ github.sha }}
tag: ${{ github.event.inputs.version }}
draft: true
prerelease: true
artifacts: "release-artifacts/*"
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ endif()

add_definitions(-DUID_PUBKEY_BYTES=${UID_PUBKEY_BYTES})

if (WIN32)
add_definitions(-DWIN32FAFUID)
endif()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")

add_executable(faf-uid
Expand Down
35 changes: 7 additions & 28 deletions machine_info_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include <string>
#include <sstream>
#include <vector>
#include <regex>

#include <unicode/unistr.h>

#define _WIN32_DCOM
#define _WIN32_WINNT 0x0600
#include <iostream>
#include <windows.h>
#include <wbemidl.h>
#include <comdef.h>
#include <winuser.h>

std::string exc_value("invalid");

Expand Down Expand Up @@ -227,7 +228,7 @@ std::vector<std::string> read_wmi_values(std::wstring const& table,
if (vtProp.vt == VT_BSTR)
{
std::string propString;
UnicodeString(vtProp.bstrVal).toUTF8String(propString);
icu::UnicodeString(vtProp.bstrVal).toUTF8String(propString);
result.push_back(propString);
}
else if (vtProp.vt == VT_I4)
Expand Down Expand Up @@ -262,18 +263,6 @@ std::string wmi_value(std::wstring const& table,
return exc_value;
}

std::string match_regex(std::string const& input,
char const* r_string)
{
std::regex r(r_string);
std::smatch sm;
if (std::regex_search(input, sm, r))
{
return sm[1];
}
return exc_value;
}

std::string machine_info_uuid()
{
return wmi_value(L"Win32_ComputerSystemProduct",
Expand All @@ -294,24 +283,14 @@ std::string machine_info_manufacturer()

std::string machine_info_display_width()
{
std::string v_mode_desc = wmi_value(L"Win32_VideoController",
L"VideoModeDescription");
if (v_mode_desc == exc_value)
{
return exc_value;
}
return match_regex(v_mode_desc, "(\\d+) x \\d+ x \\d+ colors");
SetProcessDPIAware();
return std::to_string(GetSystemMetrics(SM_CXSCREEN));
}

std::string machine_info_display_height()
{
std::string v_mode_desc = wmi_value(L"Win32_VideoController",
L"VideoModeDescription");
if (v_mode_desc == exc_value)
{
return exc_value;
}
return match_regex(v_mode_desc, "\\d+ x (\\d+) x \\d+ colors");
SetProcessDPIAware();
return std::to_string(GetSystemMetrics(SM_CYSCREEN));
}

std::string machine_info_memory_serial0()
Expand Down
23 changes: 15 additions & 8 deletions uid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include <cassert>
#include <stdint.h>

#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include <cryptopp/osrng.h>
#include <cryptopp/rsa.h>
#include <cryptopp/base64.h>
#include <cryptopp/integer.h>
#include <cryptopp/files.h>
#include "cryptopp/aes.h"
#include "cryptopp/modes.h"
#include "cryptopp/osrng.h"
#include "cryptopp/rsa.h"
#include "cryptopp/base64.h"
#include "cryptopp/integer.h"
#include "cryptopp/files.h"

#include <json/json.h>

Expand Down Expand Up @@ -58,7 +58,8 @@ int main(int argc, char *argv[])
machine_info_free();

//std::cout << root << std::endl;
std::string json_string = std::string("2") + Json::FastWriter().write(root);
Json::StreamWriterBuilder json_builder;
std::string json_string = std::string("2") + Json::writeString(json_builder, root);
//std::cout << json_string << "<-END" << std::endl;

try
Expand Down Expand Up @@ -133,9 +134,15 @@ int main(int argc, char *argv[])
new CryptoPP::FileSink(std::cout), false /*insertLineBreaks*/
);
b.Put(paddingSize);
#ifdef WIN32FAFUID
b.Put(reinterpret_cast<const byte*>(iv_b64.c_str()), iv_b64.size());
b.Put(reinterpret_cast<const byte*>(json_string_encrypted_b64.c_str()), json_string_encrypted_b64.size());
b.Put(reinterpret_cast<const byte*>(aes_key_encrypted_base64.c_str()), aes_key_encrypted_base64.size());
#else
b.Put(reinterpret_cast<const CryptoPP::byte*>(iv_b64.c_str()), iv_b64.size());
b.Put(reinterpret_cast<const CryptoPP::byte*>(json_string_encrypted_b64.c_str()), json_string_encrypted_b64.size());
b.Put(reinterpret_cast<const CryptoPP::byte*>(aes_key_encrypted_base64.c_str()), aes_key_encrypted_base64.size());
#endif
b.MessageEnd();
}
}
Expand Down

0 comments on commit 15689c0

Please sign in to comment.