-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathextract-embedded-files.bat
115 lines (89 loc) · 2.71 KB
/
extract-embedded-files.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@echo off
::
:: (c) The Batchography book by Elias Bachaalany
::
setlocal enabledelayedexpansion
echo Extracting all embedded files...
call :extract-all-files
goto :eof
:extract-one-by-one
call :extract-embedded-file "Configuration-XML" f1.xml
echo Return value: %errorlevel%
call :extract-embedded-file "Readme" f2.xml
echo Return value: %errorlevel%
goto :eof
:extract-all-files
setlocal
for %%a in (
"Configuration-XML=Config.xml"
"Readme=README.txt"
) do (
for /f "usebackq tokens=1-2 delims==" %%b in ('%%~a') do (
set MSG=Extracting '%%b' to '%%c'...
call :extract-embedded-file %%b %%c
if %errorlevel% EQU 0 (
set MSG=!MSG!done.
) else (
set MSG=!MSG!failed.
)
echo !MSG!
)
)
endlocal
goto :eof
:extract-embedded-file <1=SectionName> <2=OutFile>
setlocal
call :get-line-no "//<Begin-%~1" "%~f0"
set MBEGIN=%errorlevel%
call :get-line-no "//>End-%~1" "%~f0"
set MEND=%errorlevel%
:: By default, we assume failure
set err=1
if "%MBEGIN%"=="-1" goto :extract-embedded-file-end
if "%MEND%"=="-1" goto :extract-embedded-file-end
:: Delete previous output file
if exist "%~2" del "%~2"
set /A C=MEND-MBEGIN-1
for /f "useback skip=%MBEGIN% tokens=* delims=" %%a in ("%~f0") DO (
echo %%a >>"%~2"
SET /A C-=1
if !C!==0 (
:: Success
set err=0
goto :extract-embedded-file-end
)
)
:extract-embedded-file-end
(
endlocal
exit /b %err%
)
:get-line-no <1=string> <2=file>
for /f "useback tokens=1 delims=: " %%a in (`findstr /N /C:"%~1" "%~2"`) DO EXIT /B %%a
EXIT /B -1
goto :eof
//<Begin-Configuration-XML
<Provider>
<Name>Microsoft-Windows-DesktopWindowManager-Diag</Name>
<Metadata>
<Guid>{31F60101-3703-48EA-8143-451F8DE779D2}</Guid>
<ResourceFilePath>C:\windows\system32\dwmcore.dll</ResourceFilePath>
<MessageFilePath>C:\windows\system32\dwmcore.dll</MessageFilePath>
<PublisherMessage>Microsoft-Windows-DesktopWindowManager-Diag</PublisherMessage>
</Metadata>
<EventMetadata>
<Event>
<Id>1</Id>
<Channel>Microsoft-Windows-DesktopWindowManager-Diag/Diagnostic</Channel>
<Level>Information</Level>
<Task>DesktopWindowManager_DiagStats</Task>
<Keyword>DesktopWindowManager-WDI</Keyword>
</Event>
</EventMetadata>
</Provider>
//>End-Configuration-XML
//<Begin-Readme
This README file contains various information about this utility.
Please refer to the online manual for more details.
//>End-Readme
echo You can write more Batch file commands in here.