Skip to content

Commit 7ab7fef

Browse files
committed
i18n:更改输出为英文;
feat:添加延迟加载查找; feat:添加递归查找参数 --recursive; 默认递归 20 层; feat:添加额外查找目录参数 --search-dirs; feat:添加不跳过核心 dll 参数 --all; feat:添加 --ignore-dll 参数,忽略 dll; feat:添加版本号管理功能;
1 parent f58fc9b commit 7ab7fef

File tree

6 files changed

+1170
-200
lines changed

6 files changed

+1170
-200
lines changed

CMakeLists.txt

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
project(win_deploy VERSION 1.0)
4-
# set the C++ standard to C++ 17
3+
# Get current year for copyright
4+
string(TIMESTAMP PROJECT_YEAR "%Y")
5+
6+
project(win_deploy
7+
VERSION 1.1.0.0
8+
DESCRIPTION "Windows DLL dependency analyzer and deployment tool"
9+
LANGUAGES CXX
10+
)
11+
12+
# Project version configuration (explicit for flexibility)
13+
set(PROJECT_VERSION_MAJOR 1)
14+
set(PROJECT_VERSION_MINOR 1)
15+
set(PROJECT_VERSION_PATCH 0)
16+
set(PROJECT_VERSION_TWEAK 0)
17+
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}")
18+
set(PROJECT_NAME "win_deploy")
19+
20+
# Set the C++ standard to C++ 17
521
set(CMAKE_CXX_STANDARD 17)
622
set(CXX_STANDARD_REQUIRED true)
723
if(MSVC)
@@ -17,4 +33,41 @@ set(
1733
add_executable(
1834
win_deploy
1935
${SOURCES}
36+
${CMAKE_BINARY_DIR}/version.rc
2037
)
38+
39+
# Set version properties for the executable
40+
set_target_properties(win_deploy PROPERTIES
41+
VERSION ${PROJECT_VERSION}
42+
SOVERSION ${PROJECT_VERSION_MAJOR}
43+
OUTPUT_NAME "win_deploy"
44+
)
45+
46+
# Configure version header file (optional)
47+
configure_file(
48+
${CMAKE_SOURCE_DIR}/version.h.in
49+
${CMAKE_BINARY_DIR}/version.h
50+
@ONLY
51+
)
52+
53+
# Configure Windows version resource
54+
configure_file(
55+
${CMAKE_SOURCE_DIR}/version.rc.in
56+
${CMAKE_BINARY_DIR}/version.rc
57+
@ONLY
58+
)
59+
60+
# Add version information to the source files
61+
target_compile_definitions(win_deploy PRIVATE
62+
PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
63+
PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
64+
PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
65+
PROJECT_VERSION_TWEAK=${PROJECT_VERSION_TWEAK}
66+
PROJECT_VERSION="${PROJECT_VERSION}"
67+
)
68+
69+
# Display build information
70+
message(STATUS "Project: ${PROJECT_NAME}")
71+
message(STATUS "Version: ${PROJECT_VERSION}")
72+
message(STATUS "Description: ${PROJECT_DESCRIPTION}")
73+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

README.md

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# WinDeploy - Windows Dependency DLL Analysis and Deployment Tool
22

3-
**[中文](README_CN.MD) | [English](README.MD)**
3+
**[English](README.MD) | [中文](README_CN.MD)**
44

55
## Project Introduction
66

@@ -9,8 +9,11 @@ WinDeploy is a command-line tool for analyzing the dependency DLLs of Windows ex
99
## Features
1010

1111
- Analyze PE headers of Windows executable files to extract the list of dependent DLLs
12+
- Support recursive analysis of all levels of DLL dependencies
1213
- Support searching for DLL files in multiple locations (executable directory, system directories, PATH environment variables, etc.)
14+
- Support loading additional search directories and ignore lists from files
1315
- Optionally copy dependent DLLs to a specified directory
16+
- Automatically identify and skip Windows system core DLLs (such as KERNEL32.dll, USER32.dll, etc.)
1417
- Support for x64 and x86 architecture PE files
1518
- Use RAII pattern to manage Windows resources, ensuring proper resource release
1619
- Detailed error handling and log output
@@ -53,56 +56,138 @@ After building, the executable file will be located in the `build/bin` directory
5356
### Basic Usage
5457

5558
```bash
56-
# Analyze dependency DLLs of an executable
59+
# Analyze dependency DLLs of an executable (first level only)
5760
win_deploy.exe C:\Path\To\YourApp.exe
61+
62+
# Recursively analyze all levels of dependency DLLs
63+
win_deploy.exe C:\Path\To\YourApp.exe --recursive
64+
65+
# Recursively analyze with specified maximum depth (default: 20)
66+
win_deploy.exe C:\Path\To\YourApp.exe --recursive 10
5867
```
5968

60-
### Copy Dependency DLLs to a Specified Directory
69+
### Release Mode
6170

6271
```bash
63-
# Copy dependency DLLs to a specified directory
64-
win_deploy.exe C:\Path\To\YourApp.exe --copy C:\DestDir
72+
# Release mode: Recursively analyze dependencies (depth: 2) and copy to executable's directory
73+
win_deploy.exe C:\Path\To\YourApp.exe --release
74+
75+
# Release mode with specified recursion depth
76+
win_deploy.exe C:\Path\To\YourApp.exe --release 3
6577
```
6678

67-
### Copy Dependency DLLs to the Executable's Directory
79+
### Copy Dependency DLLs
6880

6981
```bash
82+
# Copy dependency DLLs to a specified directory
83+
win_deploy.exe C:\Path\To\YourApp.exe --copy C:\DestDir
84+
7085
# Copy dependency DLLs to the executable's directory
7186
win_deploy.exe C:\Path\To\YourApp.exe --copy-exe-dir
87+
88+
# Copy all DLLs (including system core DLLs)
89+
win_deploy.exe C:\Path\To\YourApp.exe --copy-exe-dir --copy-all
90+
```
91+
92+
### Using Additional Search Directories
93+
94+
```bash
95+
# Load additional search directories from file
96+
win_deploy.exe C:\Path\To\YourApp.exe --search-dirs search_paths.txt
97+
98+
# search_paths.txt file format (one directory path per line):
99+
# C:\MyLibs\bin
100+
# D:\ThirdParty\libs
101+
# # Lines starting with # or ; are treated as comments
102+
```
103+
104+
### Using Ignore List
105+
106+
```bash
107+
# Load ignore list from file
108+
win_deploy.exe C:\Path\To\YourApp.exe --ignore-dll ignore.txt
109+
110+
# ignore.txt file format:
111+
# # Can contain DLL names
112+
# unwanted.dll
113+
# # Can contain full paths
114+
# C:\Windows\System32\skip_this.dll
115+
# # Can contain directory paths (all DLLs in that directory will be ignored)
116+
# C:\TemporaryLibs
117+
```
118+
119+
### Combining Options
120+
121+
```bash
122+
# Release mode + additional search directories + ignore list
123+
win_deploy.exe C:\Path\To\YourApp.exe --release --search-dirs search_paths.txt --ignore-dll ignore.txt
72124
```
73125

74126
### Command Line Arguments
75127

76128
```
77129
Usage: win_deploy.exe <executable_path> [options]
130+
78131
Options:
79-
--copy <target_dir> Copy dependency DLLs to the specified directory
80-
--copy-exe-dir Copy dependency DLLs to the executable's directory
132+
--release [depth] Release mode: Recursively analyze dependencies (default depth: 2)
133+
and copy to the executable's directory
134+
--recursive [depth] Recursively analyze all DLL dependencies (default depth: 20)
135+
--copy <target_dir> Copy dependency DLLs to the specified directory
136+
--copy-exe-dir Copy dependency DLLs to the executable's directory
137+
--copy-all Copy all DLLs (including system core DLLs)
138+
--search-dirs <file> Load additional search directories from file (one path per line)
139+
--ignore-dll <file> Load ignore list from file (DLL names, paths, or directories)
140+
81141
Examples:
82142
win_deploy.exe C:\Path\To\YourApp.exe
143+
win_deploy.exe C:\Path\To\YourApp.exe --release
144+
win_deploy.exe C:\Path\To\YourApp.exe --release 3
145+
win_deploy.exe C:\Path\To\YourApp.exe --recursive
146+
win_deploy.exe C:\Path\To\YourApp.exe --recursive 10
83147
win_deploy.exe C:\Path\To\YourApp.exe --copy C:\DestDir
84148
win_deploy.exe C:\Path\To\YourApp.exe --copy-exe-dir
149+
win_deploy.exe C:\Path\To\YourApp.exe --copy-exe-dir --copy-all
150+
win_deploy.exe C:\Path\To\YourApp.exe --search-dirs test_path.txt
151+
win_deploy.exe C:\Path\To\YourApp.exe --release --ignore-dll ignore.txt
152+
win_deploy.exe C:\Path\To\YourApp.exe --release --search-dirs test_path.txt --ignore-dll ignore.txt
85153
```
86154

155+
**Notes**:
156+
157+
- By default, system core DLLs (such as KERNEL32.dll, USER32.dll, etc.) are automatically skipped during copying
158+
- Use the `--copy-all` parameter to copy all DLLs, including system core DLLs
159+
- `--release` mode is equivalent to `--recursive 2 --copy-exe-dir`
160+
87161
## How It Works
88162

89-
1. **PE File Analysis**: The tool reads the PE header of the executable file, parses the Import Directory, and obtains all dependent DLL names.
90-
2. **DLL Search**: Search for DLL files in the following order:
163+
1. **PE File Analysis**: The tool reads the PE header of the executable file, parses the Import Directory and Delay Load Import Directory, and obtains all dependent DLL names.
91164

165+
2. **Recursive Analysis**: If recursive mode is enabled, the tool will逐层 analyze the dependencies of each dependent DLL until the maximum recursion depth is reached or all dependencies are analyzed.
166+
167+
3. **DLL Search**: Search for DLL files in the following priority order:
168+
169+
- **Additional specified search directories** (specified via `--search-dirs` parameter, highest priority)
92170
- Executable file directory
93171
- Current working directory
94172
- System directory (System32)
95173
- Windows directory
96174
- All directories in the PATH environment variable
97-
3. **File Copying**: If the copy option is specified, the tool will copy the found DLL files to the target directory, automatically create the directory structure, and skip existing files.
175+
176+
4. **File Copying**: If the copy option is specified, the tool will copy the found DLL files to the target directory:
177+
- Automatically identify and skip Windows system core DLLs (unless using `--copy-all`)
178+
- Skip DLLs in the ignore list
179+
- Automatically create target directory
180+
- Skip existing files
98181

99182
## Technical Details
100183

101184
- Use Windows API for file operations and PE file parsing
102185
- Implement RVA (Relative Virtual Address) to file offset conversion
186+
- Support parsing of regular import tables and delay load import tables
103187
- Use RAII pattern to manage Windows handles and memory-mapped views
104-
- Support detection of various PE file architectures
188+
- Support detection of various PE file architectures (x64, x86)
105189
- Include complete error handling and boundary checks
190+
- Automatically detect system core DLL list, including KERNEL32, USER32, GDI32, ADVAPI32, etc.
106191

107192
## Project Structure
108193

@@ -112,7 +197,8 @@ windeployexe/
112197
├── CMakeLists.txt # CMake build configuration
113198
├── CMakeSettings.json # Visual Studio CMake settings
114199
├── .gitignore # Git ignore file
115-
└── README.MD # Project documentation
200+
├── README.MD # Project documentation (English)
201+
└── README_CN.md # Project documentation (Chinese)
116202
```
117203

118204
## License

0 commit comments

Comments
 (0)