├── strings+
├── strings+.exe
├── StringsPlus.sln
├── .gitattributes
├── readme.md
├── .gitignore
└── stringsplus
├── stringsplus.vcxproj
└── stringsplus.cpp
/strings+:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigwriteshark/StringsPlus/HEAD/strings+
--------------------------------------------------------------------------------
/strings+.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigwriteshark/StringsPlus/HEAD/strings+.exe
--------------------------------------------------------------------------------
/StringsPlus.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.705
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stringsplus", "stringsplus\stringsplus.vcxproj", "{F212D228-CD3D-4FB5-B0C3-0982159FEA67}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|ARM64 = Debug|ARM64
12 | Debug|Win32 = Debug|Win32
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|ARM = Release|ARM
16 | Release|ARM64 = Release|ARM64
17 | Release|Win32 = Release|Win32
18 | Release|x64 = Release|x64
19 | Release|x86 = Release|x86
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|ARM.ActiveCfg = Debug|Win32
23 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|ARM64.ActiveCfg = Debug|Win32
24 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|Win32.ActiveCfg = Debug|Win32
25 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|Win32.Build.0 = Debug|Win32
26 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|x64.ActiveCfg = Debug|x64
27 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|x64.Build.0 = Debug|x64
28 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|x86.ActiveCfg = Debug|Win32
29 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Debug|x86.Build.0 = Debug|Win32
30 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|ARM.ActiveCfg = Release|Win32
31 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|ARM64.ActiveCfg = Release|Win32
32 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|Win32.ActiveCfg = Release|Win32
33 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|Win32.Build.0 = Release|Win32
34 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|x64.ActiveCfg = Release|x64
35 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|x64.Build.0 = Release|x64
36 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|x86.ActiveCfg = Release|Win32
37 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}.Release|x86.Build.0 = Release|Win32
38 | EndGlobalSection
39 | GlobalSection(SolutionProperties) = preSolution
40 | HideSolutionNode = FALSE
41 | EndGlobalSection
42 | GlobalSection(ExtensibilityGlobals) = postSolution
43 | SolutionGuid = {1A12C14F-7D50-4049-969D-1C240BACC755}
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | [English readme]
2 | strings+ command scan binary file, print all ascii strings and all unicode strings. it can run in windows and linux, it can run in x86 and x64.
3 |
4 | Format:
5 |
6 | [strings+] [path] [-n [filename]] [-q] [-l [length]] [-h]
7 |
8 | [strings+] command name, if windows that is strings+.exe, if linux that is strings+
9 | [path] source files' directory, example: c:\mydir or /home/mydir
10 | [-n [filename]] source files wildcard, example: -n *.exe
11 | [-q] be quiet, no output message. example: -q
12 | [-l [length]] filter string's max length, no less than 2. example: -l 3
13 | [-h] show help message.
14 |
15 | Sample in windows:
16 |
17 | 1. path:>strings+.exe [path] scan all files in [path]
18 | 2. path:>strings+.exe [path] -n [filename] scan [filename] in [path]
19 | 3. path:>strings+.exe [path] -n [*.*] scan *.* in [path]
20 | 4. path:>strings+.exe [path] -n [*.exe] -l 3 scan string that length <= 3 from *.exe in [path]
21 |
22 | Sample in linux:
23 |
24 | 1. $./strings+ [path] scan all files in [path]
25 | 2. $./strings+ [path] -n '[filename]' scan [filename] in [path]
26 | 3. $./strings+ [path] -n '[*.*]' scan *.* in [path]
27 | 4. $./strings+ [path] -n '[*.exe]' -l 3 scan string that length <= 3 from *.exe in [path]
28 |
29 | Output:
30 |
31 | Output to a file named [path]/t.[filename].txt
32 |
33 |
34 | 【中文说明】
35 |
36 | strings+ 程序可以扫描二进制文件,打印出所有的ascii码字符串,和所有的unicode字符串。它可以运行在windows平台,或者linux平台。
37 |
38 | 格式:
39 |
40 | [strings+] [path] [-n [filename]] [-q] [-l [length]] [-h]
41 | [strings+] 命令名,如果是windows则为strings+.exe,如果是linux平台则是strings+
42 | [path] 需要扫描的文件的所在目录,请注意是目录,而不是全路径名(不包含文件名),例如: c:\mydir or /home/mydir
43 | [-n [filename]] -n选项:指定要扫描的文件的文件名(可以包含通配符*,?),例如: -n *.exe,或者-n my.bin
44 | [-q] -q选项:指定静默运行,运行时不打印输出结果. 比如: -q
45 | [-l [length]] -l选项:指定一个字符串长度过滤,扫描出来的字符串如果长度小于指定长度,则被忽略,这个长度必须大于等于2. 例如: -l 3
46 | [-h] -h选项:显示帮助信息.
47 |
48 | windows下的使用举例:
49 |
50 | 1. path:>strings+.exe [path] 扫描[path]目录下所有的文件
51 | 2. path:>strings+.exe [path] -n [filename] 扫描[path]目录下匹配[filename]的文件
52 | 3. path:>strings+.exe [path] -n [*.*] 扫描[path]目录下所有的文件
53 | 4. path:>strings+.exe [path] -n [*.exe] -l 3 扫描[path]目录下*.exe且长度<=3的字符串
54 |
55 |
56 | Sample in linux:
57 |
58 | 1. $./strings+ [path] 扫描[path]目录下所有的文件
59 | 2. $./strings+ [path] -n '[filename]' 扫描[path]目录下匹配[filename]的文件
60 | 3. $./strings+ [path] -n '[*.*]' 扫描[path]目录下所有的文件
61 | 4. $./strings+ [path] -n '[*.exe]' -l 3 扫描[path]目录下*.exe且长度<=3的字符串
62 |
63 | 输出结果:
64 |
65 | 扫描出来的字符串,会保存到一个文本文件里,该输出文件保存在和源文件相同的目录下,输出文件的名称和源文件名称相匹配,输出文件的名称样式为:[path]/t.[源文件名].txt。
66 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 |
263 | !*.exe
264 | /ConsoleApplication1
265 |
--------------------------------------------------------------------------------
/stringsplus/stringsplus.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {F212D228-CD3D-4FB5-B0C3-0982159FEA67}
24 | Win32Proj
25 | string
26 | 10.0.17763.0
27 | stringsplus
28 |
29 |
30 |
31 | Application
32 | true
33 | v141
34 | MultiByte
35 |
36 |
37 | Application
38 | false
39 | v141
40 | true
41 | Unicode
42 |
43 |
44 | Application
45 | true
46 | v141
47 | NotSet
48 |
49 |
50 | Application
51 | false
52 | v141
53 | true
54 | Unicode
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 | $(VC_IncludePath);$(WindowsSDK_IncludePath);
77 | $(SolutionDir)
78 | strings+
79 |
80 |
81 | true
82 | $(SolutionDir)
83 | $(Configuration)\
84 | strings+
85 |
86 |
87 | false
88 | $(SolutionDir)
89 | strings+
90 |
91 |
92 | false
93 | $(SolutionDir)
94 | $(Configuration)\
95 | strings+
96 |
97 |
98 |
99 | NotUsing
100 | Level3
101 | Disabled
102 | true
103 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
104 | true
105 | pch.h
106 |
107 |
108 | Console
109 | true
110 | $(OutDir)$(TargetName)$(TargetExt)
111 |
112 |
113 |
114 |
115 | NotUsing
116 | Level3
117 | Disabled
118 | true
119 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
120 | true
121 | pch.h
122 |
123 |
124 | Console
125 | true
126 | $(OutDir)$(TargetName)$(TargetExt)
127 |
128 |
129 |
130 |
131 | NotUsing
132 | Level3
133 | MaxSpeed
134 | true
135 | true
136 | true
137 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
138 | true
139 | pch.h
140 |
141 |
142 | Console
143 | true
144 | true
145 | true
146 | $(OutDir)$(TargetName)$(TargetExt)
147 |
148 |
149 |
150 |
151 | NotUsing
152 | Level3
153 | MaxSpeed
154 | true
155 | true
156 | true
157 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
158 | true
159 | pch.h
160 |
161 |
162 | Console
163 | true
164 | true
165 | true
166 | $(OutDir)$(TargetName)$(TargetExt)
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
--------------------------------------------------------------------------------
/stringsplus/stringsplus.cpp:
--------------------------------------------------------------------------------
1 | // string+.cpp
2 | //
3 | #define _CRT_SECURE_NO_WARNINGS
4 |
5 |
6 | #ifdef _WIN32
7 | #include
8 | #include
9 | #else
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #endif
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #define MAX_PATH 300
27 | #define MATCH_CHAR(c1,c2,ignore_case) ( (c1==c2) || ((ignore_case) &&(tolower(c1)==tolower(c2))) )
28 |
29 | using namespace std;
30 |
31 |
32 | //String's encode
33 | enum enumEncode
34 | {
35 | ASCII,
36 | Unicode,
37 | };
38 |
39 |
40 | enum EnumFileType
41 | {
42 | EnumFileType_File,
43 | EnumFileType_Directory
44 | };
45 |
46 |
47 | //struct of param, analysis argv
48 | struct struParam
49 | {
50 | char full_path[MAX_PATH];
51 | char file_name[MAX_PATH];
52 | bool is_quiet;
53 | int filter_length;
54 |
55 | struParam()
56 | {
57 | memset(full_path, 0, MAX_PATH);
58 | memset(file_name, 0, MAX_PATH);
59 | is_quiet = false;
60 | filter_length = 2;
61 | }
62 |
63 | string tostring()
64 | {
65 | stringstream ss;
66 | ss << "struParam:" << endl;
67 | ss << " full_path: " << full_path << endl;
68 | ss << " file_name: " << file_name << endl;
69 | return ss.str();
70 | }
71 | };
72 |
73 | const wchar_t* ll = L"lavender my love";
74 | const char* ParamFileName = "-n";
75 | const char* ParamQuiet = "-q";
76 | const char* ParamFilterLength = "-l";
77 | const char* ParamHelp = "-h";
78 | struParam g_Param;
79 | list> g_lstFiles; //0.File path 1.File name 2.File full name
80 |
81 |
82 | //Check and process argv
83 | bool ProcessParams(int argc, const char* argv[], struParam& param);
84 |
85 | //Get param's value by name
86 | bool FindParameterValue(int argc, const char* argv[], const char* paramName, char* paramValue);
87 |
88 | //Enum files from a folder
89 | void EnumFilesFromFolder(string folderPath, string wildcard, int depth, list>& lstFiles, bool inc_sub_dirs = false);
90 |
91 | bool EnumWildCharMatch(const char *src, const char *pattern, bool ignore_case);
92 |
93 | //Scan file and find unicode string or ascii string
94 | bool GetStringsFromFile(tuple& file, struParam param);
95 |
96 | //Show help message
97 | void ShowHelp();
98 |
99 |
100 | //main
101 | int main(int argc, const char* argv[])
102 | {
103 | //Check and process params
104 | if (!ProcessParams(argc, argv, g_Param))
105 | {
106 | return 0;
107 | }
108 |
109 | //Get file list
110 | g_lstFiles.clear();
111 | EnumFilesFromFolder(g_Param.full_path, g_Param.file_name, 0, g_lstFiles);
112 |
113 | //Process each of the file
114 | for (auto f : g_lstFiles)
115 | {
116 | GetStringsFromFile(f, g_Param);
117 | }
118 |
119 | return 0;
120 | }
121 |
122 |
123 | //Check and process argv
124 | bool ProcessParams(int argc, const char* argv[], struParam& param)
125 | {
126 | //check param
127 | if (argc < 2)
128 | {
129 | ShowHelp();
130 | return false;
131 | }
132 |
133 | strcpy(param.full_path, argv[1]);
134 |
135 | char value[MAX_PATH];
136 |
137 | memset(value, 0, MAX_PATH);
138 | if (FindParameterValue(argc, argv, ParamFileName, value))
139 | {
140 | strcpy(param.file_name, value);
141 | }
142 |
143 | memset(value, 0, MAX_PATH);
144 | if (FindParameterValue(argc, argv, ParamQuiet, value))
145 | {
146 | param.is_quiet = true;
147 | }
148 |
149 | memset(value, 0, MAX_PATH);
150 | if (FindParameterValue(argc, argv, ParamFilterLength, value))
151 | {
152 | int len = atoi(value);
153 | param.filter_length = (len < 2 ? len = 2 : len);
154 | }
155 |
156 | memset(value, 0, MAX_PATH);
157 | if (FindParameterValue(argc, argv, ParamHelp, value))
158 | {
159 | ShowHelp();
160 | return false;
161 | }
162 |
163 | return true;
164 | }
165 |
166 |
167 | //Enum files from a folder
168 | void EnumFilesFromFolder(string folderPath, string wildcard, int depth, list>& lstFiles, bool inc_sub_dirs)
169 | {
170 | lstFiles.clear();
171 |
172 | #ifdef _WIN32
173 | _finddata_t FileInfo;
174 | string strfind = folderPath + "\\" + wildcard;
175 | long Handle = (long)_findfirst(strfind.c_str(), &FileInfo);
176 |
177 | if (Handle == -1L)
178 | {
179 | cerr << "can not match the folder path" << endl;
180 | exit(-1);
181 | }
182 | do {
183 | if (FileInfo.attrib & _A_SUBDIR)
184 | {
185 | if ((depth - 1 > 0) && (strcmp(FileInfo.name, ".") != 0) && (strcmp(FileInfo.name, "..") != 0))
186 | {
187 | string newPath = folderPath + "\\" + FileInfo.name;
188 | EnumFilesFromFolder(newPath, wildcard, depth - 1, lstFiles);
189 | }
190 | }
191 | else
192 | {
193 | string filename = (folderPath + "\\" + FileInfo.name);
194 | lstFiles.push_back(make_tuple(folderPath, FileInfo.name, filename));
195 | //cout << folderPath << "\\" << FileInfo.name << " " << endl;
196 | }
197 | } while (_findnext(Handle, &FileInfo) == 0);
198 |
199 | _findclose(Handle);
200 | #else
201 | EnumFileType type = EnumFileType_File;
202 | unsigned int nFilePerDir = 0;
203 |
204 | char real_path[260];
205 | size_t length = folderPath.length();
206 |
207 | strcpy(real_path, folderPath.c_str());
208 | if (real_path[length - 1] != '/')
209 | strcat(real_path, "/");
210 |
211 | stack ps;
212 | ps.push(real_path);
213 |
214 | while (!ps.empty())
215 | {
216 | unsigned int nAlreadyCount = 0;
217 | string search_path = ps.top();
218 | ps.pop();
219 |
220 | DIR* dir = opendir((search_path).c_str());
221 |
222 | if (dir != 0)
223 | {
224 | struct stat file_stat;
225 | struct dirent *s_dir = readdir(dir);
226 |
227 | do
228 | {
229 | if ((strcmp(s_dir->d_name, ".") == 0) || (strcmp(s_dir->d_name, "..") == 0)) continue;
230 |
231 | stat((search_path + s_dir->d_name).c_str(), &file_stat);
232 |
233 | bool curIsDir = S_ISDIR(file_stat.st_mode);
234 | if ((type == EnumFileType_File && !curIsDir) ||
235 | (type == EnumFileType_Directory && curIsDir))
236 | {
237 | if (EnumWildCharMatch(s_dir->d_name, wildcard.c_str(), false))
238 | {
239 | string filename = (search_path + s_dir->d_name);
240 | lstFiles.push_back(make_tuple(search_path, s_dir->d_name, filename));
241 | }
242 |
243 | if (inc_sub_dirs)
244 | ps.push(search_path + s_dir->d_name + "/");
245 |
246 | if (nFilePerDir > 0 && ++nAlreadyCount == nFilePerDir) break;
247 | }
248 | else
249 | {
250 | if (inc_sub_dirs && curIsDir)
251 | ps.push(search_path + s_dir->d_name + "/");
252 | }
253 | } while ((s_dir = readdir(dir)) != 0);
254 | closedir(dir);
255 | }
256 | }
257 | #endif
258 | }
259 |
260 |
261 |
262 | bool EnumWildCharMatch(const char *src, const char *pattern, bool ignore_case)
263 | {
264 | bool result = false;
265 |
266 | while (*src)
267 | {
268 | if (*pattern == '*')
269 | {
270 | while ((*pattern == '*') || (*pattern == '?'))
271 | pattern++;
272 |
273 | if (!*pattern) return true;
274 |
275 | while (*src && (!MATCH_CHAR(*src, *pattern, ignore_case)))
276 | src++;
277 |
278 | if (!*src) return false;
279 |
280 | result = EnumWildCharMatch(src, pattern, ignore_case);
281 | while ((!result) && (*(src + 1)) && MATCH_CHAR(*(src + 1), *pattern, ignore_case))
282 | result = EnumWildCharMatch(++src, pattern, ignore_case);
283 |
284 | return result;
285 | }
286 | else
287 | {
288 | if (MATCH_CHAR(*src, *pattern, ignore_case) || ('?' == *pattern))
289 | return EnumWildCharMatch(++src, ++pattern, ignore_case);
290 | else
291 | return false;
292 | }
293 | }
294 |
295 | if (*pattern)
296 | return (*pattern == '*') && (*(pattern + 1) == 0);
297 |
298 | return true;
299 | }
300 |
301 |
302 |
303 | //Get param's value by name
304 | bool FindParameterValue(int argc, const char* argv[], const char* paramName, char* paramValue)
305 | {
306 | if (argv == NULL)
307 | {
308 | paramValue = NULL;
309 | return false;
310 | }
311 | for (int i = 0; i < argc; i++)
312 | {
313 | if (strcmp(argv[i], paramName) != 0 || i == argc - 1) continue;
314 | strcpy(paramValue, argv[i + 1]);
315 | return true;
316 | }
317 |
318 | paramValue = NULL;
319 | return false;
320 | }
321 |
322 |
323 | //Scan file and find unicode string or ascii string
324 | bool GetStringsFromFile(tuple& file, struParam param)
325 | {
326 |
327 | string fname = std::get<2>(file);
328 | string oname = std::get<0>(file) + string("/t.") + std::get<1>(file) + string(".txt");
329 | ifstream io;
330 | io.open(fname, std::ios::binary);
331 | ofstream oo;
332 | oo.open(oname);
333 | list lstAStr;
334 | int pos = 0;
335 |
336 |
337 | auto ProcessString = [&]()
338 | {
339 | if (lstAStr.size() < param.filter_length)
340 | {
341 | lstAStr.clear();
342 | return;
343 | }
344 |
345 | oo << "\t" << pos - lstAStr.size() << "\t\t";
346 | while (!lstAStr.empty())
347 | {
348 | unsigned char c = lstAStr.front();
349 | if (!param.is_quiet) printf("%c", c);
350 | oo.put(c);
351 | lstAStr.pop_front();
352 | }
353 | oo << endl;
354 | if (!param.is_quiet) printf("\n");
355 | };
356 |
357 |
358 | //ascii strings
359 | {
360 | unsigned char c;
361 | io.seekg(0, ios::beg);
362 | oo << "\nASCII string:" << endl;
363 | pos = 0;
364 | while (!io.eof())
365 | {
366 | c = io.get();
367 | pos++;
368 |
369 | if (isprint(c))
370 | {
371 | lstAStr.push_back(c);
372 | }
373 | else
374 | {
375 | ProcessString();
376 | }
377 | }
378 | oo << endl;
379 | oo << endl;
380 | }
381 |
382 | //unicode strings
383 | {
384 | unsigned char c;
385 | io.clear();
386 | io.seekg(0, ios::beg);
387 | oo << "\nUnicode string:" << endl;
388 | pos = 0;
389 | while (!io.eof())
390 | {
391 | c = io.get();
392 | pos++;
393 | if (isprint(c))
394 | {
395 | if (io.eof()) break;
396 | unsigned d = io.get();
397 | pos++;
398 | if (d == 0)
399 | {
400 | lstAStr.push_back(c);
401 | lstAStr.push_back(' ');
402 | }
403 | else
404 | {
405 | ProcessString();
406 | }
407 | }
408 | else
409 | {
410 | if (io.eof()) break;
411 | ProcessString();
412 | }
413 | }
414 | oo << endl;
415 | oo << endl;
416 | }
417 |
418 | io.close();
419 | oo.close();
420 |
421 | return true;
422 | }
423 |
424 |
425 | //Show help message
426 | void ShowHelp()
427 | {
428 | printf("\nFormat: ");
429 | printf("\n[strings+] [path] [-n [filename]] [-q] [-l [length]] [-h] ");
430 | printf("\n [strings+] command name, if windows that is strings+.exe, if linux that is strings+ ");
431 | printf("\n [path] source files' directory, example: c:\\mydir or /home/mydir ");
432 | printf("\n [-n [filename]] source files wildcard, example: -n *.exe ");
433 | printf("\n [-q] be quiet, no output message. example: -q ");
434 | printf("\n [-l [length]] filter string's max length, no less than 2. example: -l 3 ");
435 | printf("\n [-h] show help message. ");
436 | printf("\nSample in windows: ");
437 | printf("\n 1. path:>strings+.exe [path] scan all files in [path] ");
438 | printf("\n 2. path:>strings+.exe [path] -n [filename] scan [filename] in [path] ");
439 | printf("\n 3. path:>strings+.exe [path] -n [*.*] scan *.* in [path] ");
440 | printf("\n 4. path:>strings+.exe [path] -n [*.exe] -l 3 scan string that length <= 3 from *.exe in [path] ");
441 | printf("\nSample in linux: ");
442 | printf("\n 1. $./strings+ [path] scan all files in [path] ");
443 | printf("\n 2. $./strings+ [path] -n '[filename]' scan [filename] in [path] ");
444 | printf("\n 3. $./strings+ [path] -n '[*.*]' scan *.* in [path] ");
445 | printf("\n 4. $./strings+ [path] -n '[*.exe]' -l 3 scan string that length <= 3 from *.exe in [path] ");
446 | printf("\nOutput: ");
447 | printf("\n Output to a file named [path]/t.[filename].txt ");
448 | printf("\n");
449 | }
450 |
451 |
452 |
453 |
454 |
455 |
456 |
--------------------------------------------------------------------------------