build release with size optimizations

This commit is contained in:
beerpiss 2024-06-27 09:40:15 +07:00
parent b13351ed50
commit fe3807da7f
5 changed files with 47 additions and 31 deletions

View File

@ -7,6 +7,13 @@ license = "0BSD"
[lib]
crate-type = ["cdylib"]
[profile.release]
strip = true # Automatically strip symbols from the binary.
opt-level = "z" # Optimize for size.
lto = true
codegen-units = 1
panic = "abort"
[dependencies]
aes = "0.8.4"
cbc = "0.1.2"

24
src/consts.rs Normal file
View File

@ -0,0 +1,24 @@
pub const GIT_SHA: &str = env!("VERGEN_GIT_SHA");
pub const GIT_BRANCH: &str = env!("VERGEN_GIT_BRANCH");
pub const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
pub const PUBLIC_KEY: [u8; 270] = [
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf5, 0xbd, 0x02, 0xb0, 0x81, 0xc6, 0x4d,
0x4c, 0xa0, 0x40, 0xa8, 0x76, 0x78, 0xe2, 0x61, 0x39, 0x13, 0x1d, 0x2f, 0x0c, 0x70, 0x71, 0x96,
0x56, 0x67, 0xf2, 0xbe, 0xc2, 0x5c, 0xc7, 0xd4, 0xa6, 0xb5, 0x07, 0xc5, 0x7a, 0x19, 0x58, 0x10,
0x70, 0xb5, 0x87, 0x5f, 0x3f, 0x9a, 0x78, 0x9e, 0x96, 0x5c, 0xc7, 0x88, 0x50, 0x8c, 0x34, 0xcc,
0x51, 0xe5, 0xd5, 0xbd, 0xb8, 0xab, 0xed, 0x28, 0x7f, 0x68, 0x6e, 0x27, 0x2a, 0x1d, 0xdb, 0x9a,
0xe9, 0x1d, 0xbc, 0xd8, 0xbf, 0xca, 0xdf, 0x65, 0xa3, 0x0a, 0x19, 0x3d, 0x00, 0x14, 0x16, 0xdd,
0x87, 0x9f, 0xf5, 0x44, 0x9e, 0x56, 0x1e, 0xfd, 0xb5, 0xf0, 0x75, 0x3d, 0x11, 0x4c, 0x4d, 0xa5,
0x1a, 0x24, 0xfe, 0x31, 0x77, 0xc1, 0x55, 0xf7, 0x5d, 0x9c, 0x34, 0xbe, 0x5f, 0x9d, 0x73, 0x2c,
0x3e, 0xdb, 0x39, 0x18, 0x3c, 0xb3, 0x46, 0xe0, 0xf4, 0xa1, 0xcc, 0x2f, 0x7b, 0x07, 0xb7, 0x0e,
0x7a, 0x92, 0x54, 0xa9, 0x9f, 0xfc, 0x4c, 0xe0, 0xbb, 0xcf, 0xba, 0x36, 0xc6, 0xcb, 0x9d, 0xb1,
0x12, 0x4b, 0x50, 0x1c, 0x10, 0x23, 0x87, 0x28, 0x9b, 0x73, 0xe3, 0xd5, 0xc9, 0x38, 0xae, 0xd7,
0x66, 0x73, 0x8f, 0xf8, 0x56, 0x2e, 0x48, 0x0a, 0xdb, 0x7f, 0x11, 0xbf, 0xd6, 0x4e, 0x77, 0x6c,
0xb8, 0x12, 0xaf, 0x0b, 0x7b, 0x08, 0xe3, 0x0f, 0x7e, 0xf1, 0x6a, 0xc0, 0xac, 0x1c, 0xe2, 0x8c,
0x47, 0xb0, 0xec, 0x10, 0xca, 0x02, 0x9c, 0x7d, 0x27, 0x78, 0x33, 0x3c, 0x25, 0x88, 0x5c, 0x4f,
0x4b, 0xb8, 0x72, 0xeb, 0x85, 0x31, 0x39, 0xb1, 0x95, 0xae, 0xc3, 0x79, 0x38, 0x20, 0x25, 0x0e,
0xab, 0xdc, 0x9c, 0xc8, 0x25, 0x53, 0xd2, 0xcf, 0x93, 0xf0, 0x1d, 0x95, 0x58, 0x0b, 0x0c, 0x9f,
0xc5, 0x01, 0x7a, 0xad, 0x4f, 0x55, 0x2f, 0x24, 0xc5, 0x02, 0x03, 0x01, 0x00, 0x01,
];

View File

@ -1,4 +1,5 @@
mod config;
mod consts;
mod helpers;
mod logging;
mod saekawa;
@ -9,7 +10,6 @@ mod updater;
use std::thread;
use helpers::winapi_ext::ThreadHandle;
use log::{error, info, warn};
use winapi::{
shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
@ -17,7 +17,8 @@ use winapi::{
};
use crate::{
helpers::winapi_ext::LibraryHandle,
consts::{CRATE_NAME, CRATE_VERSION, GIT_BRANCH, GIT_SHA},
helpers::winapi_ext::{LibraryHandle, ThreadHandle},
logging::init_logger,
saekawa::{hook_init, hook_release},
};
@ -38,10 +39,11 @@ extern "system" fn DllMain(dll_module: HINSTANCE, call_reason: DWORD, reserved:
}
info!(
"saekawa {} ({}@{}) starting up...",
env!("CARGO_PKG_VERSION"),
&env!("VERGEN_GIT_SHA")[0..7],
env!("VERGEN_GIT_BRANCH"),
"{} {} ({}@{}) starting up...",
CRATE_NAME,
CRATE_VERSION,
&GIT_SHA[0..7],
GIT_BRANCH,
);
if let Err(e) = hook_init(library_handle) {

View File

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
use snafu::{prelude::Snafu, ResultExt};
use crate::{
consts::USER_AGENT,
config::SaekawaConfig,
types::tachi::{
api::{TachiFailureResponse, TachiResponse},
@ -16,7 +17,6 @@ use crate::{
};
const MAX_RETRY_COUNT: u32 = 3;
static SAEKAWA_USER_AGENT: &str = concat!("saekawa/", env!("CARGO_PKG_VERSION"));
#[derive(Snafu, Debug)]
pub enum ScoreImportError {
@ -126,7 +126,7 @@ pub fn execute_score_import(
fn saekawa_client(config: &SaekawaConfig) -> ureq::Agent {
ureq::builder()
.timeout(Duration::from_millis(config.general.timeout))
.user_agent(SAEKAWA_USER_AGENT)
.user_agent(USER_AGENT)
.build()
}

View File

@ -47,27 +47,10 @@ use winapi::{
};
use self::external::{replace_with_new_library, ReplaceArgs};
use crate::helpers::winapi_ext::{get_module_file_name, LibraryHandle, ReadStringFnError};
const PUBLIC_KEY: [u8; 270] = [
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf5, 0xbd, 0x02, 0xb0, 0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b, 0x7b, 0x08, 0xe3, 0x0f, 0x7e, 0xf1, 0x6a, 0xc0, 0xac, 0x1c, 0xe2, 0x8c,
0x47, 0xb0, 0xec, 0x10, 0xca, 0x02, 0x9c, 0x7d, 0x27, 0x78, 0x33, 0x3c, 0x25, 0x88, 0x5c, 0x4f,
0x4b, 0xb8, 0x72, 0xeb, 0x85, 0x31, 0x39, 0xb1, 0x95, 0xae, 0xc3, 0x79, 0x38, 0x20, 0x25, 0x0e,
0xab, 0xdc, 0x9c, 0xc8, 0x25, 0x53, 0xd2, 0xcf, 0x93, 0xf0, 0x1d, 0x95, 0x58, 0x0b, 0x0c, 0x9f,
0xc5, 0x01, 0x7a, 0xad, 0x4f, 0x55, 0x2f, 0x24, 0xc5, 0x02, 0x03, 0x01, 0x00, 0x01,
];
use crate::{
consts::{GIT_SHA, PUBLIC_KEY, USER_AGENT},
helpers::winapi_ext::{get_module_file_name, LibraryHandle, ReadStringFnError},
};
// I don't know what the hell is going on with linking, but you have to link these manually,
// otherwise you end up with the addresses to the intermediary functions, which obviously
@ -190,7 +173,7 @@ struct UpdateInformation {
#[allow(clippy::result_large_err)]
pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
let agent = ureq::builder()
.user_agent(concat!("saekawa/", env!("CARGO_PKG_VERSION")))
.user_agent(USER_AGENT)
.build();
info!("Checking for updates...");
@ -204,7 +187,7 @@ pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
debug!(concat!("current commit: ", env!("VERGEN_GIT_SHA")));
debug!("remote commit: {}", response.commit);
if response.commit == env!("VERGEN_GIT_SHA") {
if response.commit == GIT_SHA {
info!("Already up-to-date.");
return Ok(false);