Skip to content

Commit

Permalink
github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
shuax committed Apr 3, 2022
1 parent 2bfe382 commit 919a00b
Show file tree
Hide file tree
Showing 22 changed files with 2,673 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
strategy:
matrix:
include: [
{ name: windows_x86, os: windows-latest, arch: x86 },
{ name: windows_x64, os: windows-latest, arch: x64 },
]

name: ${{ matrix.name }}

runs-on: ${{ matrix.os }}

steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: 'true'

- name: setup VC-LTL
if: matrix.os == 'windows-latest'
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget install VC-LTL

- name: setup xmake
uses: xmake-io/github-action-setup-xmake@v1

- name: configure
run: xmake f -a ${{ matrix.arch }}

- name: build
run: xmake

- name: upload
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.name }}
path: build/release
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.xmake/
build/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "minhook"]
path = minhook
url = https://github.com/TsudaKageyu/minhook
[submodule "mini_gzip"]
path = mini_gzip
url = https://github.com/shuax/mini_gzip
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# chrome_plus
Chrome 增强软件
# 功能
- 双击关闭标签页
- 保留最后标签页(防止关闭最后一个标签页时关闭浏览器,点X不行)
- 鼠标悬停标签栏滚动
- 按住右键时滚轮滚动标签栏
- 便携设计,程序放在App目录,数据放在Data目录(不兼容原版数据,可以重装系统换电脑不丢数据)
- 移除更新错误警告(因为是绿色版没有自动更新功能)
# 获取
采用GitHub Actions自动编译,请自行前往[编译](https://github.com/shuax/chrome_plus/actions)页面下载
[![build status](https://github.com/shuax/chrome_plus/actions/workflows/build.yml/badge.svg)](https://github.com/shuax/chrome_plus/actions/workflows/build.yml)
# 安装
dll放入解压版Chrome目录即可
44 changes: 44 additions & 0 deletions VC-LTL5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
target("VC-LTL-5")
set_kind("phony")
before_build("windows", function (target)
local function find_in_file()
for _, dir in ipairs(os.dirs("$(projectdir)/*")) do
name = dir:match(".*\\(.*)")
if name:find("VC%-LTL") then
return dir .. [[\build\native\]]
end
end
end
local function find_in_reg()
return vformat("$(reg HKEY_CURRENT_USER\\Code\\VC-LTL;Root)")
end
local VC_LTL_Root = find_in_file() or find_in_reg()
if #VC_LTL_Root==0 then
return
end
local WindowsTargetPlatformMinVersion = "6.0.6000.0"
cprint("${color.warning}VC-LTL Path : %s", VC_LTL_Root)
cprint("${color.warning}WindowsTargetPlatformMinVersion : %s", WindowsTargetPlatformMinVersion)
import("core.tool.toolchain")
local msvc = toolchain.load("msvc")
local runenvs = msvc:runenvs()

local includepath = VC_LTL_Root .. [[TargetPlatform\header;]] .. VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\header;]]

runenvs.INCLUDE = includepath .. runenvs.INCLUDE

local arch = target:arch()
local archpath = "Win32"
if arch=="x86" then
archpath = "Win32"
elseif arch=="x64" then
archpath = "x64"
end
cprint("${color.warning}Platform : %s", archpath)
local libpath = VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\lib\]] .. archpath .. ";"

runenvs.LIB = libpath .. runenvs.LIB

-- print(runenvs.INCLUDE)
-- print(runenvs.LIB)
end)
1 change: 1 addition & 0 deletions minhook
Submodule minhook added at 4a4555
1 change: 1 addition & 0 deletions mini_gzip
Submodule mini_gzip added at 4f793a
176 changes: 176 additions & 0 deletions src/PakFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#pragma warning(disable: 4334)
#pragma warning(disable: 4267)

extern "C"
{
#include "..\mini_gzip\miniz.c"
#include "..\mini_gzip\mini_gzip.h"
#include "..\mini_gzip\mini_gzip.c"
}

#pragma pack(push)
#pragma pack(1)

#define PACK4_FILE_VERSION (4)
#define PACK5_FILE_VERSION (5)

struct PAK4_HEADER
{
uint32_t num_entries;
uint8_t encodeing;
};

struct PAK5_HEADER
{
uint32_t encodeing;
uint16_t resource_count;
uint16_t alias_count;
};

struct PAK_ENTRY
{
uint16_t resource_id;
uint32_t file_offset;
};

struct PAK_ALIAS
{
uint16_t resource_id;
uint16_t entry_index;
};
#pragma pack(pop)

bool CheckHeader(uint8_t *buffer, PAK_ENTRY *&pak_entry, PAK_ENTRY *&end_entry)
{
uint32_t version = *(uint32_t*)buffer;

if (version != PACK4_FILE_VERSION && version != PACK5_FILE_VERSION) return false;

if (version == PACK4_FILE_VERSION)
{
PAK4_HEADER *pak_header = (PAK4_HEADER*)(buffer + sizeof(uint32_t));
if (pak_header->encodeing != 1) return false;

pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK4_HEADER));
end_entry = pak_entry + pak_header->num_entries;
}

if (version == PACK5_FILE_VERSION)
{
PAK5_HEADER *pak_header = (PAK5_HEADER*)(buffer + sizeof(uint32_t));
if (pak_header->encodeing != 1) return false;

pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK5_HEADER));
end_entry = pak_entry + pak_header->resource_count;
}

// 为了保存最后一条的"下一条",这条特殊的条目的id一定为0
if (!end_entry || end_entry->resource_id != 0) return false;

return true;
}

template<typename Function>
void PakFind(uint8_t *buffer, uint8_t* pos, Function f)
{
PAK_ENTRY *pak_entry = NULL;
PAK_ENTRY *end_entry = NULL;

// 检查文件头
if (!CheckHeader(buffer, pak_entry, end_entry)) return;

do
{
PAK_ENTRY *next_entry = pak_entry + 1;
if (pos >= buffer + pak_entry->file_offset && pos <= buffer + next_entry->file_offset)
{
f(buffer + pak_entry->file_offset, next_entry->file_offset - pak_entry->file_offset);
break;
}

pak_entry = next_entry;
} while (pak_entry->resource_id != 0);
}

template<typename Function>
void TraversalGZIPFile(uint8_t *buffer, Function f)
{
PAK_ENTRY *pak_entry = NULL;
PAK_ENTRY *end_entry = NULL;

// 检查文件头
if (!CheckHeader(buffer, pak_entry, end_entry)) return;

do
{
PAK_ENTRY *next_entry = pak_entry + 1;
uint32_t old_size = next_entry->file_offset - pak_entry->file_offset;

if (old_size < 10 * 1024)
{
// 小于10k文件跳过
pak_entry = next_entry;
continue;
}

BYTE gzip[] = { 0x1F, 0x8B, 0x08 };
size_t gzip_len = sizeof(gzip);
if (memcmp(buffer + pak_entry->file_offset, gzip, gzip_len) != 0)
{
// 不是gzip文件跳过
pak_entry = next_entry;
continue;
}

uint32_t original_size = *(uint32_t*)(buffer + next_entry->file_offset - 4);
uint8_t *unpack_buffer = (uint8_t *)malloc(original_size);
if (!unpack_buffer) return;

struct mini_gzip gz;
mini_gz_start(&gz, buffer + pak_entry->file_offset, old_size);
int unpack_len = mini_gz_unpack(&gz, unpack_buffer, original_size);

if (original_size == unpack_len)
{
uint32_t new_len = old_size;
bool changed = f(unpack_buffer, unpack_len, new_len);
if (changed)
{
// 如果有改变
size_t compress_size = 0;
uint8_t *compress_buffer = (uint8_t *)gzip_compress(unpack_buffer, new_len, &compress_size);
if (compress_buffer && compress_size < old_size)
{
/*FILE *fp = fopen("test.gz", "wb");
fwrite(compress_buffer, compress_size, 1, fp);
fclose(fp);*/

//gzip头
memcpy(buffer + pak_entry->file_offset, compress_buffer, 10);

//extra
buffer[pak_entry->file_offset + 3] = 0x04;
uint16_t extra_length = old_size - compress_size - 2;
memcpy(buffer + pak_entry->file_offset + 10, &extra_length, sizeof(extra_length));
memset(buffer + pak_entry->file_offset + 12, '\0', extra_length);

//compress
memcpy(buffer + pak_entry->file_offset + 12 + extra_length, compress_buffer + 10, compress_size - 10);

/*fp = fopen("test2.gz", "wb");
fwrite(buffer + pak_entry->file_offset, old_size, 1, fp);
fclose(fp);*/
}
else
{
DebugLog(L"gzip compress error %d %d", compress_size, old_size);
}

if (compress_buffer) free(compress_buffer);
}
}

free(unpack_buffer);
pak_entry = next_entry;
} while (pak_entry->resource_id != 0);
}
Loading

0 comments on commit 919a00b

Please sign in to comment.