elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [APORTE] [BATCH] WIM Resource Replacer
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] [BATCH] WIM Resource Replacer  (Leído 2,521 veces)
Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.878



Ver Perfil
[APORTE] [BATCH] WIM Resource Replacer
« en: 14 Abril 2014, 05:51 am »

Este Script sirve para automatizar la tarea de montar una imagen WIM de Windows y reemplazar recursos de imágenes (bmp/ico) en las librerías de recursos de la instalación de Windows, así como también sirve para reemplazar archivos.

Ejemplo de los recursos a los que me refiero:



Se necesitan unos requisitos y dependencias para usar este Script:
· Saber de lo que estoy hablando.
· Conocer el nombre de los recursos que quieres reemplazar y disponer de tus imágenes ya modificados (obviamente).
· Dism e ImageX (WAIK/WADK).
· Anolis Resourcer > http://www.anol.is/resourcer/


Las instrucciones de uso y un extenso tutorial lo publiqué en este otro tema: http://foro.elhacker.net/windows/guia_de_personalizacion_de_imagenes_de_implementacion_de_windows_wim_parte_4-t412468.0.html así que lo haré de nuevo de manera resumida: solo tienen que escribir en un archivo de texto delimitando por puntoycomas los recursos que quieren reemplazar, el nombre del recurso y el índice, así como los archivos que quieran reemplazar, y configurar las variables documentadas del Script (La ubicación de la imagen, el directorio de montaje, etc...)

Nota: Ver el ejemplo del archivo delimitado dentro del enlace de abajo o en las instrucciones extendidas del enlace de arriba.

Todo lo necesario está incluido en este archivo comprimido:
http://www.mediafire.com/download/ktzms7i09qt4n2b/wim+resource+replacer+0.2.rar

Imágenes:


(Código corregido, el otro que subí estaba incompleto)
WIM Resource Replacer.cmd
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title WIM Resource Replacer - By Elektro
  10. Mode Con Cols=150 Lines=50
  11. CHCP 1252 1>NUL & REM Windows-1252, Spanish-Latin.
  12.  
  13.  
  14.  
  15. REM =====
  16. REM Info:
  17. REM =====
  18.  
  19. Echo  --------------------------------------------------------------------------------------------------
  20. Echo  This script mounts a Windows Image ^(WIM^) and then replaces image resources inside resource files
  21. Echo  --------------------------------------------------------------------------------------------------
  22.  
  23.  
  24.  
  25. REM ====================
  26. REM User defined values:
  27. REM ====================
  28.  
  29. REM This value indicates whether the Windows Image should be mounted.
  30. REM True  = 'DISM' will try to mount the 'WIM' image.
  31. REM False = 'DISM' will not try to mount the WIM image.
  32. REM Set this value to 'FALSE' if the 'WIM' image is already mounted in the specified mount directory,
  33. REM Otherwise, keep it as 'TRUE'.
  34. Set "MountImage=True"
  35.  
  36. REM This value indicates whether the Windows Image should be unmounted at the end.
  37. REM True  = 'DISM' will try to unmount the 'WIM' image.
  38. REM False = 'DISM' will not try to unmount the WIM image.
  39. REM Set this value to 'FALSE' if you want to keep the image mounted to make other changes,
  40. REM Otherwise, keep it as 'TRUE'.
  41. Set "UnmountImage=True"
  42.  
  43. REM This value indicates whether the Windows Image should be rebuilt at the end.
  44. REM True  = 'ImageX' will try to rebuild the 'WIM' image.
  45. REM False = 'ImageX' will keep the 'WIM' image as is.
  46. REM Set this value to 'FALSE' if you want to keep the image with normal size to make other changes,
  47. REM Otherwise, keep it as 'TRUE'.
  48. Set "Rebuild=True"
  49.  
  50. REM This value indicates whether the Windows Image should be cleaned-up at the end.
  51. REM True  = 'Dism' will try to CleanUp the 'WIM' image components.
  52. REM False = 'Dism' will keep the 'WIM' image as is.
  53. REM Set this value to 'FALSE' if you want to keep the image with normal size to make other changes,
  54. REM Otherwise, keep it as 'TRUE'.
  55. Set "CleanUp=True"
  56.  
  57. REM This value indicates the 'WIM' image to be mounted.
  58. Set "WindowsImage=%UserProfile%\Desktop\win 8 .1\win\sources\Boot.wim"
  59.  
  60. REM This value indicates the Image Index of the 'WIM' image.
  61. Set "ImageIndex=2"
  62.  
  63. REM This value indicates the directory where to mount the 'WIM' image.
  64. Set "MountDir=%HomeDrive%\WinBootMount"
  65.  
  66. REM This value indicates the ubication of Anolis Resourcer 'Anolis.exe' file.
  67. Set "Anolis=%CD%\Tools\Anolis.exe"
  68.  
  69. REM This value indicates the textfile that contains the Recource files to replace.
  70. Set "ResourceList=%CD%\Resources.txt"
  71.  
  72. REM This value indicates the ubication of 'ImageX.exe' file.
  73. Set "ImageX=%CD%\Tools\Dism\ImageX.exe"
  74.  
  75. REM This value indicates the ubication of a custom 'DISM.exe' file if needed.
  76. REM Default ubication: "%SystemRoot%\System32\Dism.exe"
  77. Set "Dism=%CD%\Tools\Dism\Dism.exe"
  78.  
  79. REM This value indicates the ubication of the logfile that will record 'DISM' errors.
  80. Set "DismLogfile=%CD%\%~n0 DISM.log"
  81.  
  82. REM This value indicates the logging-level of the 'DISM' process.
  83. REM 1 = Errors only
  84. REM 2 = Errors and warnings
  85. REM 3 = Errors, warnings, and informational
  86. REM 4 = All of the information listed previously, plus debug output
  87. Set /A "DismLogLevel=2"
  88.  
  89. REM This value indicates the ubication of the logfile that will record Main information.
  90. Set "Logfile=%CD%\%~n0.log"
  91.  
  92.  
  93.  
  94. REM =====
  95. REM Main:
  96. REM =====
  97.  
  98. :: Call Methods.
  99. Call :CheckErrors
  100. Call :CreateLogs
  101. Call :CreateMountDir
  102. Call :GetWIMSizeBefore
  103. Call :StartTimer
  104. Call :Mount
  105. CLS
  106. Call :ParseResources
  107. Call :Unmount
  108. Call :StopTimer
  109. Call :GetWIMSizeAfter
  110. Call :EndLog
  111. Pause&Exit
  112.  
  113.  
  114.  
  115. REM ========
  116. REM Methods:
  117. REM ========
  118.  
  119. :CreateLogs
  120. :: Create the 'DISM' logfile with 'ANSI' encoding,
  121. :: this is necessary to record a non-default 'DISM' loglevel such as '1' or '2'.
  122. Echo+ >"%Logfile%"
  123.  
  124. :: Create the Main Logfile and record starting info on it.
  125. (
  126. Echo    WIM Resource Replacer
  127. Echo ===========================
  128. Echo   %DATE% ^| %TIME:~0,-3%
  129. Echo /\/\/\/\/\/\/\/\/\/\/\/\/\/
  130. Echo [i] Mount Image?...: %MountImage%
  131. Echo [i] Unmount Image?.: %UnmountImage%
  132. Echo [i] CleanUp Image?.: %CleanUp%
  133. Echo [i] Rebuild Image?.: %Rebuild%
  134. Echo [i] Windows Image..: %WindowsImage%
  135. Echo [i] Image Index....: %ImageIndex%
  136. Echo [i] Mount Directory: %MountDir%
  137. Echo [i] ImageX Path....: %ImageX%
  138. Echo [i] Dism Path......: %Dism%
  139. Echo [i] Dism Log File..: %DismLogfile%
  140. Echo [i] Dism Log Level.: %DismLogLevel%
  141. Echo [i] Anolis Path....: %Anolis%
  142. Echo [i] Resource List..: %ResourceList%
  143. Echo [i] Log File.......: %LogFile%
  144. Echo ===========================
  145. )>"%Logfile%"
  146.  
  147. :: Display starting log info.
  148. Type "%Logfile%"
  149.  
  150. :: Continue writting log.
  151. (
  152. Echo Resource conflicts:
  153. Echo ===================
  154. )>>"%LogFile%"
  155.  
  156. Goto:EOF
  157.  
  158.  
  159. :EndLog
  160. (
  161. Echo [i] Done!
  162. Echo [i] WIM Size Before....: %WIMSizeBefore%
  163. Echo [i] WIM Size After.....: %WIMSizeAfter%
  164. Echo [i] Resources Success..: %ResourceSuccessCount% files.
  165. Echo [i] Resources Failed...: %ResourceFailsCount% files.
  166. Echo [i] Resources Not Found: %ResourceNotFoundCount% files.
  167. Echo [i] Files Added........: %FilesAddedCount% files.
  168. Echo [i] Files Failed.......: %FilesFailsCount% files.
  169. Echo [i] Files Not Found....: %FilesNotFoundCount% files.
  170. Echo [i] Elapsed Time.......: %ElapsedTime%
  171. )>>"%LogFile%"
  172.  
  173. :: Display ending information.
  174. CLS
  175. Type "%LogFile%"
  176. Goto:EOF
  177.  
  178.  
  179. :CreateMountDir
  180. :: Create the mount directory.
  181. (
  182. If Not Exist "%MountDir%" If /I "%MountImage%" EQU "True" (
  183. MkDir "%MountDir%" 2>NUL
  184. )
  185. ) || (
  186. Echo [x] Error trying to create the directory "%MountDir%" to mount the Windows Image.
  187. Echo [i] Ensure that you have Admin rights to create the directory.
  188. Echo [i] Ensure that the directory name does not contains illegal characters.
  189. Pause&Exit
  190. )
  191. Goto:EOF
  192.  
  193.  
  194. :Mount
  195. :: Mount the Windows Image into the directory.
  196. Echo [+] Mounting WIM Image...
  197. If /I "%MountImage%" EQU "True" (
  198.  
  199. "%Dism%" /Mount-Image /ImageFile:"%WindowsImage%" /Index:"%ImageIndex%" /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" || (
  200. Echo [x] Error mounting the Image Index "%ImageIndex%" in "%MountDir%"
  201. Echo [i] Ensure that the Image Index exist.
  202. Echo [i] Ensure that you have Admin rights to write inside the directory.
  203. Echo [i] Ensure that the directory is not already mounted.
  204. Echo [i] Ensure that the directory is fully empty.
  205. REM Try to unmount the failed image and discard changes.
  206. If /I "%UnmountImage%" EQU "True" (
  207. Echo [+] Unmounting and discarding changes...
  208. "%Dism%" /Unmount-WIM /Discard /MountDir:"%MountDir%"
  209. )
  210. Pause&Exit
  211. )
  212.  
  213. )
  214. Goto:EOF
  215.  
  216.  
  217. :CleanUp
  218. Echo [+] CleaningUp WIM Image...
  219. "%Dism%" /CleanUp-Image /StartComponentCleanUp /Image:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%" /Quiet
  220. Goto:EOF
  221.  
  222.  
  223. :Unmount
  224. :: Unmount the Windows Image commiting changes.
  225. Echo [+] Unmounting WIM Image...
  226. If /I "%UnmountImage%" EQU "True" (
  227. "%Dism%" /Unmount-WIM /Commit /MountDir:"%MountDir%" /English /LogPath:"%DismLogfile%" /LogLevel:"%DismLogLevel%"
  228. )
  229. Goto:EOF
  230.  
  231.  
  232. :Rebuild
  233. If /I "%Rebuild%" EQU "False" (Goto:EOF)
  234.  
  235. Echo [+] Rebuilding WIM image...
  236.  
  237. ("%ImageX%" /Compress Maximum /Export "%WindowsImage%" "*" "%TEMP%\Rebuilt Image.wim" /Check) && (
  238. Del /Q /F "%WindowsImage%" 1>NUL
  239. Move /Y "%TEMP%\Rebuilt Image.wim" "%WindowsImage%" 1>NUL
  240. ) || (
  241. Echo [x] Error rebuilding Image "%WindowsImage%" to "%TEMP%\Rebuilt Image.wim".
  242. )
  243.  
  244. Goto :EOF
  245.  
  246.  
  247. :StartTimer
  248. Set "StartingDate=%Date%"
  249. Set "StarttingTime=%Time:~0,-3%"
  250. Goto :EOF
  251.  
  252.  
  253. :StopTimer
  254. (
  255. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  256. Echo WScript.Echo Minutes ^& " Minutes"
  257. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  258.  
  259. For /F "Tokens=*" %%# In (
  260. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  261. ) Do (
  262. Set "ElapsedTime=%%#"
  263. )
  264.  
  265. Goto:EOF
  266.  
  267.  
  268. :WriteConvertBytesScript
  269. If Exist "%TEMP%\%~n0 Convert Bytes.vbs" (Goto:EOF)
  270. (
  271. Echo Suffix = Array^("Bytes", "KB", "MB", "GB", "TB"^)
  272. Echo Function Convert^(Bytes^)
  273. Echo Convert = convert0^(Bytes, 0^)
  274. Echo End Function
  275. Echo Function Convert0^(Bytes, Level^)
  276. Echo If Bytes ^>= 1024 Then
  277. Echo Bytes = Round^(Bytes / 1024, 2^)
  278. Echo Level = Level + 1
  279. Echo Convert0 = Convert0^(Bytes, Level^)
  280. Echo End If
  281. Echo Convert0 = Bytes ^& " " ^& Suffix^(Level^)
  282. Echo End Function
  283. Echo WScript.Echo Convert^(WScript.Arguments^(0^)^)
  284. )>"%TEMP%\%~n0 Convert Bytes.vbs"
  285. Goto:EOF
  286.  
  287.  
  288. :GetWIMSizeBefore
  289. Call :WriteConvertBytesScript
  290. For %%# in ("%WindowsImage%") Do (Set "WIMSizeBefore=%%~z#")
  291. For /F "Tokens=*" %%# In (
  292. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeBefore%"'
  293. ) Do (
  294. Set "WIMSizeBefore=%%#"
  295. )
  296. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  297. Goto:EOF
  298.  
  299.  
  300. :GetWIMSizeAfter
  301. Call :WriteConvertBytesScript
  302. For %%# in ("%WindowsImage%") Do (Set "WIMSizeAfter=%%~z#")
  303. For /F "Tokens=*" %%# In (
  304. 'Cscript.exe /Nologo "%TEMP%\%~n0 Convert Bytes.vbs" "%WIMSizeAfter%"'
  305. ) Do (
  306. Set "WIMSizeAfter=%%#"
  307. )
  308. Del /Q "%TEMP%\%~n0 Convert Bytes.vbs"
  309. Goto:EOF
  310.  
  311.  
  312. :TakeOwn
  313. (
  314. Takeown.exe /F "%~f1"
  315. ICacls.exe "%~f1" /Grant "%UserName%":"F"
  316. Attrib.exe -R -A -S -H -I "%~f1"
  317. )>NUL || (Exit /B 1)
  318. Goto:EOF
  319.  
  320.  
  321. :ParseResources
  322. Set /A "ResourceSuccessCount=0"
  323. Set /A "ResourceFailsCount=0"
  324. Set /A "ResourceNotFoundCount=0"
  325. Set /A "FilesAddedCount=0"
  326. Set /A "FilesFailsCount=0"
  327. Set /A "FilesNotFoundCount=0"
  328.  
  329. For /F "UseBackQ Tokens=1,2,* Delims=;" %%a In ("%ResourceList%") Do (
  330.  
  331. If /I "%%~xa" EQU ".dll" (Call :ReplaceResource "%MountDir%\%%~a" "%%~b" "%%~c")
  332. If /I "%%~xa" NEQ ".dll" (Call :CopyFile        "%MountDir%\%%~a" "%%~b")
  333.  
  334. )
  335. Goto:EOF
  336.  
  337.  
  338. :CopyFile
  339. If Not Exist "%~2" (
  340. Echo Can't locate file to copy from: "%~2">>"%LogFile%"
  341. Set /A "FilesNotFoundCount+=1"
  342. Goto:EOF
  343. )
  344.  
  345. Call :TakeOwn "%~f1" || (
  346. Echo Unable to grant file permissions in file: "%~1">>"%Logfile%"
  347. Set /A "FilesFailsCount+=1"
  348. Goto:EOF
  349. )
  350.  
  351. Echo [o] Copying "%~2" to "%~1"
  352. Copy /Y "%~f2" "%~f1" 1>NUL || (
  353. Echo Unable to copy file "%~2">>"%Logfile%"
  354. Set /A "FilesFailsCount+=1"
  355. Goto:EOF
  356. )
  357. Set /A "FilesAddedCount+=1"
  358. Goto:EOF
  359.  
  360.  
  361. :ReplaceResource
  362. If Not Exist "%~f3" (
  363. Echo Can't locate the resource to copy from: "%~3">>"%LogFile%"
  364. Set /A "ResourceNotFoundCount+=1"
  365. Goto:EOF
  366. )
  367.  
  368. If Not Exist "%~f1" (
  369. Echo Can't locate the resource file to edit "%~1">>"%Logfile%"
  370. Set /A "ResourceNotFoundCount+=1"
  371. Goto:EOF
  372. )
  373.  
  374. Call :TakeOwn "%~f1" || (
  375. Echo Unable to grant file permissions in file: "%~1">>"%Logfile%"
  376. Set /A "ResourceFailsCount+=1"
  377. Goto:EOF
  378. )
  379.  
  380. Echo [o] Replacing resource with name "%~2" in resource file "%~f1", with "%~3".
  381.  
  382. If /I "%~x3" EQU ".bmp" (
  383. Start /W "Anolis" "%Anolis%" -op:upd -src:"%~f1" -type:Bitmap -name:"%~2" -lang:1033 -file:"%~f3")
  384. )
  385. If /I "%~x3" EQU ".ico" (
  386. Start /W "Anolis" "%Anolis%" -op:upd -src:"%~f1" -type:Icon -name:"%~2" -lang:1033 -file:"%~f3")
  387. )
  388. Set /A "ResourceSuccessCount+=1"
  389. Goto:EOF
  390.  
  391.  
  392.  
  393. REM ====================
  394. REM File Error Controls:
  395. REM ====================
  396.  
  397. :CheckErrors
  398. :: WIM File Error-Check.
  399. If /I "MountImage" EQU "True" If Not Exist "%WindowsImage%" (
  400. Echo [x] Windows Image not found at: "%WindowsImage%" | MORE
  401. Pause&Exit
  402. )
  403.  
  404. :: ResourceList File Error-Check.
  405. If Not Exist "%ResourceList%" (
  406. Echo [x] Resource-List file not found in: "%ResourceList%" | MORE
  407. Pause&Exit
  408. )
  409.  
  410. :: 'DISM.exe' File Error-Check.
  411. If Not Exist "%DISM%" (
  412. Echo [x] 'DISM' process not found at: "%DISM%" | MORE
  413. Pause&Exit
  414. )
  415.  
  416. :: 'ImageX.exe' File Error-Check.
  417. If Not Exist "%ImageX%" (
  418. Echo [x] 'ImageX' process not found at: "%ImageX%" | MORE
  419. Pause&Exit
  420. )
  421.  
  422. :: 'MountImage' Value check.
  423. If /I "%MountImage%" NEQ "True" If /I "%MountImage%" NEQ "False" (
  424. Echo [x] Error parsing parameter 'MountImage',
  425. Echo     value '%MountImage%' is not a Boolean value.
  426. Pause&Exit
  427. )
  428.  
  429. :: 'UnmountImage' Value check.
  430. If /I "%UnmountImage%" NEQ "True" If /I "%UnmountImage%" NEQ "False" (
  431. Echo [x] Error parsing parameter 'UnmountImage',
  432. Echo     value '%UnmountImage%' is not a Boolean value.
  433. Pause&Exit
  434. )
  435.  
  436. :: 'Rebuild' Value check.
  437. If /I "%Rebuild%" NEQ "True" If /I "%Rebuild%" NEQ "False" (
  438. Echo [x] Error parsing parameter 'Rebuild',
  439. Echo     value '%Rebuild%' is not a Boolean value.
  440. Pause&Exit
  441. )
  442.  
  443. :: 'CleanUp' Value check.
  444. If /I "%CleanUp%" NEQ "True" If /I "%CleanUp%" NEQ "False" (
  445. Echo [x] Error parsing parameter 'CleanUp',
  446. Echo     value '%CleanUp%' is not a Boolean value.
  447. Pause&Exit
  448. )
  449.  
  450. :: 'DismLogLevel' Value check.
  451. Echo "%DismLogLevel%"| Findstr.exe "^\"[^1-4]\"$" 1>NUL 2>&1 || (
  452. Echo [x] Error parsing parameter 'DismLogLevel',
  453. Echo     value '%DismLogLevel%' is not in range '1-4'.
  454. Pause&Exit
  455. )
  456.  
  457. :: Anolis Resourcer File Error-Check.
  458. If Not Exist "%Anolis%" (
  459. Echo [x] Anolis process not found in: "%Anolis%" | MORE
  460. Pause&Exit
  461. )
  462.  
  463. Goto:EOF


« Última modificación: 14 Abril 2014, 08:47 am por Eleкtro » En línea



Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Batch] Un pequeño aporte « 1 2 »
Scripting
najmuddin 13 8,215 Último mensaje 25 Junio 2008, 21:21 pm
por najmuddin
[Batch] Aporte, Soy electronico
Scripting
Geormarsch 5 4,104 Último mensaje 9 Enero 2012, 10:24 am
por leogtz
[APORTE] [BATCH] Acentos en los programas Batch - La mejor solución
Scripting
Príncipe_Azul 5 13,135 Último mensaje 2 Mayo 2014, 00:09 am
por cyberalejo17
[APORTE] [BATCH] Files2List
Scripting
Eleкtro 2 2,167 Último mensaje 14 Abril 2014, 04:40 am
por Eleкtro
[APORTE] [BATCH] Folders2List
Scripting
Eleкtro 2 2,445 Último mensaje 12 Abril 2014, 15:04 pm
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines