2017-09-22 21:24:31 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2021-01-19 08:06:51 +01:00
|
|
|
Copyright 2021 whatever127
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-29 23:40:56 +02:00
|
|
|
require_once dirname(__FILE__).'/shared/main.php';
|
|
|
|
require_once dirname(__FILE__).'/shared/requests.php';
|
2017-12-20 17:35:14 +01:00
|
|
|
require_once dirname(__FILE__).'/shared/packs.php';
|
2022-08-25 17:46:16 +02:00
|
|
|
require_once dirname(__FILE__).'/shared/cache.php';
|
2022-09-13 23:41:50 +02:00
|
|
|
require_once dirname(__FILE__).'/shared/fileinfo.php';
|
2017-09-23 17:47:19 +02:00
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
/*
|
|
|
|
$updateId = Update Identifier
|
|
|
|
$usePack = Desired language
|
|
|
|
$desiredEdition = Desired edition
|
|
|
|
|
|
|
|
$requestType = 0 = uncached request,;
|
|
|
|
1 = use cache if available;
|
|
|
|
2 = offline information retrieval
|
|
|
|
*/
|
|
|
|
|
2018-11-16 17:59:48 +01:00
|
|
|
function uupGetFiles(
|
|
|
|
$updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6',
|
|
|
|
$usePack = 0,
|
|
|
|
$desiredEdition = 0,
|
2019-01-15 21:28:57 +01:00
|
|
|
$requestType = 0
|
2018-11-16 17:59:48 +01:00
|
|
|
) {
|
2017-09-23 17:47:19 +02:00
|
|
|
uupApiPrintBrand();
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2019-09-14 17:26:57 +02:00
|
|
|
if(!$updateId) {
|
|
|
|
return array('error' => 'UNSPECIFIED_UPDATE');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!uupApiCheckUpdateId($updateId)) {
|
2022-09-13 23:41:50 +02:00
|
|
|
return array('error' => 'INCORRECT_ID');
|
2019-09-14 17:26:57 +02:00
|
|
|
}
|
|
|
|
|
2022-10-22 01:20:13 +02:00
|
|
|
$edition = is_array($desiredEdition) ? implode('_', $desiredEdition) : $desiredEdition;
|
2023-03-14 16:09:51 +01:00
|
|
|
$res = "api-get-{$updateId}_{$usePack}_{$edition}_{$requestType}";
|
2022-10-22 01:20:13 +02:00
|
|
|
$cache = new UupDumpCache($res);
|
|
|
|
$fromCache = $cache->get();
|
|
|
|
if($fromCache !== false) return $fromCache;
|
|
|
|
|
2022-09-13 23:41:50 +02:00
|
|
|
$info = uupApiReadFileinfo($updateId);
|
2017-12-20 17:35:14 +01:00
|
|
|
if(empty($info)) {
|
|
|
|
$info = array(
|
|
|
|
'ring' => 'WIF',
|
|
|
|
'flight' => 'Active',
|
2018-04-11 18:01:27 +02:00
|
|
|
'arch' => 'amd64',
|
2017-12-20 17:35:14 +01:00
|
|
|
'checkBuild' => '10.0.16251.0',
|
2018-04-29 21:33:19 +02:00
|
|
|
'sku' => '48',
|
2017-12-20 17:35:14 +01:00
|
|
|
'files' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($info['build'])) {
|
|
|
|
$build = explode('.', $info['build']);
|
|
|
|
$build = $build[0];
|
|
|
|
} else {
|
|
|
|
$build = 9841;
|
|
|
|
}
|
|
|
|
|
2018-04-29 21:33:19 +02:00
|
|
|
if(!isset($info['sku'])) {
|
|
|
|
$info['sku'] = 48;
|
|
|
|
}
|
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
if($usePack) {
|
2023-10-29 00:07:48 +02:00
|
|
|
$genPack = uupApiGetPacks($updateId);
|
2019-01-05 01:25:25 +01:00
|
|
|
if(empty($genPack)) return array('error' => 'UNSUPPORTED_COMBINATION');
|
|
|
|
|
|
|
|
if(!isset($genPack[$usePack])) {
|
2017-09-22 21:24:31 +02:00
|
|
|
return array('error' => 'UNSUPPORTED_LANG');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
$appEdition = 0;
|
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
if(!is_array($desiredEdition)) {
|
|
|
|
$desiredEdition = strtoupper($desiredEdition);
|
|
|
|
$fileListSource = $desiredEdition;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
switch($desiredEdition) {
|
|
|
|
case '0':
|
|
|
|
if($usePack) {
|
|
|
|
$fileListSource = 'GENERATEDPACKS';
|
2018-04-29 21:33:19 +02:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesPacksList = array();
|
2019-06-16 19:00:45 +02:00
|
|
|
foreach($genPack[$usePack] as $val) {
|
|
|
|
foreach($val as $package) {
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesPacksList[] = $package;
|
2019-06-16 19:00:45 +02:00
|
|
|
}
|
2018-04-29 21:33:19 +02:00
|
|
|
}
|
2019-06-16 19:00:45 +02:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
array_unique($filesPacksList);
|
|
|
|
sort($filesPacksList);
|
2018-04-29 21:33:19 +02:00
|
|
|
}
|
2019-06-16 19:00:45 +02:00
|
|
|
break;
|
2018-04-29 21:33:19 +02:00
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
case 'WUBFILE': break;
|
2018-04-29 21:33:19 +02:00
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
case 'UPDATEONLY': break;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
case 'APP': $appEdition = 1;
|
2023-09-27 17:28:08 +02:00
|
|
|
case 'APP_MOMENT': $appEdition = 1;
|
2022-03-05 19:46:31 +01:00
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
default:
|
|
|
|
if(!isset($genPack[$usePack][$desiredEdition])) {
|
|
|
|
return array('error' => 'UNSUPPORTED_COMBINATION');
|
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2019-06-16 19:00:45 +02:00
|
|
|
$fileListSource = 'GENERATEDPACKS';
|
2023-09-27 17:28:08 +02:00
|
|
|
$filesPacksList = $genPack[$usePack][$desiredEdition];
|
|
|
|
if($desiredEdition == 'APP' && isset($genPack[$usePack]['APP_MOMENT'])) {
|
|
|
|
$filesPacksList = array_merge($filesPacksList, $genPack[$usePack]['APP_MOMENT']);
|
|
|
|
}
|
2019-06-16 19:00:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$fileListSource = 'GENERATEDPACKS';
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesPacksList = array();
|
2019-06-16 19:00:45 +02:00
|
|
|
foreach($desiredEdition as $edition) {
|
|
|
|
$edition = strtoupper($edition);
|
|
|
|
|
|
|
|
if(!isset($genPack[$usePack][$edition])) {
|
2018-03-17 22:20:20 +01:00
|
|
|
return array('error' => 'UNSUPPORTED_COMBINATION');
|
|
|
|
}
|
|
|
|
|
2023-09-27 17:28:08 +02:00
|
|
|
if($edition == 'APP' || $edition == 'APP_MOMENT') $appEdition = 1;
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesPacksList = array_merge($filesPacksList, $genPack[$usePack][$edition]);
|
2019-06-16 19:00:45 +02:00
|
|
|
}
|
2017-10-16 18:03:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 22:53:33 +02:00
|
|
|
$rev = 1;
|
|
|
|
if(preg_match('/_rev\./', $updateId)) {
|
|
|
|
$rev = preg_replace('/.*_rev\./', '', $updateId);
|
|
|
|
$updateId = preg_replace('/_rev\..*/', '', $updateId);
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$updateSku = $info['sku'];
|
2018-10-11 21:48:46 +02:00
|
|
|
$updateArch = (isset($info['arch'])) ? $info['arch'] : 'UNKNOWN';
|
|
|
|
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
|
|
|
|
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
|
2021-09-19 15:58:48 +02:00
|
|
|
$sha256capable = isset($info['sha256ready']);
|
2022-08-25 03:59:37 +02:00
|
|
|
$hasUpdates = false;
|
2018-10-11 21:48:46 +02:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
if(isset($info['releasetype'])) {
|
|
|
|
$type = $info['releasetype'];
|
|
|
|
}
|
|
|
|
if(!isset($type)) {
|
|
|
|
$type = 'Production';
|
|
|
|
if($updateSku == 189 || $updateSku == 135) foreach($info['files'] as $val) {
|
|
|
|
if(preg_match('/NonProductionFM/i', $val['name'])) $type = 'Test';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
if($requestType < 2) {
|
2022-10-23 17:58:14 +02:00
|
|
|
$filesInfoList = uupGetOnlineFiles($updateId, $rev, $info, $requestType, $type);
|
2019-01-15 21:28:57 +01:00
|
|
|
} else {
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesInfoList = uupGetOfflineFiles($info);
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
if(isset($filesInfoList['error'])) {
|
|
|
|
return $filesInfoList;
|
2019-01-25 20:29:53 +01:00
|
|
|
}
|
|
|
|
|
2021-09-25 18:18:22 +02:00
|
|
|
$diffs = preg_grep('/.*_Diffs_.*|.*_Forward_CompDB_.*|\.cbsu\.cab$/i', array_keys($filesInfoList));
|
|
|
|
foreach($diffs as $val) {
|
|
|
|
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:09:51 +01:00
|
|
|
$baseless = preg_grep('/^baseless_/i', array_keys($filesInfoList));
|
2022-03-05 19:46:31 +01:00
|
|
|
foreach($baseless as $val) {
|
|
|
|
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
|
|
|
}
|
2021-01-19 08:06:51 +01:00
|
|
|
|
2023-03-14 16:09:51 +01:00
|
|
|
$expresscab = preg_grep('/Windows(10|11)\.0-KB.*-EXPRESS|SSU-.*-EXPRESS/i', array_keys($filesInfoList));
|
|
|
|
|
|
|
|
$expresspsf = array();
|
|
|
|
foreach($expresscab as $val) {
|
|
|
|
$name = preg_replace('/-EXPRESS.cab$/i', '', $val);
|
|
|
|
$expresspsf[] = $name;
|
|
|
|
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
|
|
|
}
|
|
|
|
unset($index, $name, $expresscab);
|
|
|
|
|
|
|
|
foreach($expresspsf as $val) {
|
|
|
|
if(isset($filesInfoList[$val.'.cab'])) {
|
|
|
|
if(isset($filesInfoList[$val.'.psf'])) unset($filesInfoList[$val.'.psf']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($expresspsf);
|
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
$psf = array_keys($filesInfoList);
|
|
|
|
$psf = preg_grep('/\.psf$/i', $psf);
|
2021-06-12 16:18:56 +02:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
$psfk = preg_grep('/Windows(10|11)\.0-KB.*/i', $psf);
|
|
|
|
$psfk = preg_grep('/.*-EXPRESS/i', $psfk, PREG_GREP_INVERT);
|
2023-03-14 16:09:51 +01:00
|
|
|
if($build < 17763) $psfk = preg_grep('/Windows(10|11)\.0-KB.*_\d\.psf$/i', $psfk, PREG_GREP_INVERT);
|
2022-03-05 19:46:31 +01:00
|
|
|
foreach($psfk as $key => $val) {
|
|
|
|
if(isset($psf[$key])) unset($psf[$key]);
|
|
|
|
}
|
|
|
|
unset($psfk);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
$removeFiles = array();
|
|
|
|
foreach($psf as $val) {
|
|
|
|
$name = preg_replace('/\.psf$/i', '', $val);
|
|
|
|
$removeFiles[] = $name;
|
|
|
|
unset($filesInfoList[$val]);
|
|
|
|
}
|
|
|
|
unset($index, $name, $psf);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
$temp = preg_grep('/'.$updateArch.'_.*|arm64\.arm_.*|arm64\.x86_.*/i', $removeFiles);
|
|
|
|
foreach($temp as $key => $val) {
|
|
|
|
if(isset($filesInfoList[$val.'.cab'])) unset($filesInfoList[$val.'.cab']);
|
|
|
|
unset($removeFiles[$key]);
|
|
|
|
}
|
|
|
|
unset($temp);
|
2021-09-19 15:58:48 +02:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
foreach($removeFiles as $val) {
|
|
|
|
if(isset($filesInfoList[$val.'.esd'])) {
|
|
|
|
if(isset($filesInfoList[$val.'.cab'])) unset($filesInfoList[$val.'.cab']);
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-05 19:46:31 +01:00
|
|
|
unset($removeFiles);
|
|
|
|
|
|
|
|
$msu = array_keys($filesInfoList);
|
|
|
|
$msu = preg_grep('/\.msu$/i', $msu);
|
|
|
|
$removeMSUs = array();
|
|
|
|
foreach($msu as $val) {
|
|
|
|
$name = preg_replace('/\.msu$/i', '', $val);
|
|
|
|
$removeMSUs[] = $name;
|
|
|
|
}
|
|
|
|
unset($index, $name, $msu);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesInfoKeys = array_keys($filesInfoList);
|
2022-08-25 03:59:37 +02:00
|
|
|
$updatesRegex = '/Windows(10|11)\.0-KB|SSU-.*?\....$/i';
|
2019-01-15 21:28:57 +01:00
|
|
|
|
|
|
|
switch($fileListSource) {
|
|
|
|
case 'UPDATEONLY':
|
|
|
|
$skipPackBuild = 1;
|
2023-03-14 16:09:51 +01:00
|
|
|
$removeFiles = preg_grep('/Windows(10|11)\.0-KB.*-baseless/i', $filesInfoKeys);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
|
|
|
foreach($removeFiles as $val) {
|
2021-02-06 14:26:21 +01:00
|
|
|
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
2021-02-06 14:26:21 +01:00
|
|
|
unset($removeFiles);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
foreach($removeMSUs as $val) {
|
2022-08-25 03:59:37 +02:00
|
|
|
if(isset($filesInfoList[$val.'.cab']) && isset($filesInfoList[$val.'.msu'])) {
|
|
|
|
unset($filesInfoList[$val.'.msu']);
|
2022-03-05 19:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($removeMSUs);
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesInfoKeys = array_keys($filesInfoList);
|
2021-12-01 00:35:43 +01:00
|
|
|
$temp = preg_grep('/.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $filesInfoKeys);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2022-08-25 03:59:37 +02:00
|
|
|
$filesInfoKeys = preg_grep($updatesRegex, $filesInfoKeys);
|
2021-02-06 14:26:21 +01:00
|
|
|
if(count($filesInfoKeys) == 0) {
|
2019-01-15 21:28:57 +01:00
|
|
|
return array('error' => 'NOT_CUMULATIVE_UPDATE');
|
|
|
|
}
|
2021-12-01 00:35:43 +01:00
|
|
|
|
|
|
|
if($build > 21380) $filesInfoKeys = array_merge($filesInfoKeys, $temp);
|
|
|
|
unset($temp);
|
2022-08-25 03:59:37 +02:00
|
|
|
$hasUpdates = true;
|
2019-01-15 21:28:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'WUBFILE':
|
|
|
|
$skipPackBuild = 1;
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesInfoKeys = preg_grep('/WindowsUpdateBox.exe/i', $filesInfoKeys);
|
2019-01-15 21:28:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$uupCleanFunc = 'uupCleanName';
|
|
|
|
if($updateSku == 189) $uupCleanFunc = 'uupCleanWCOS';
|
|
|
|
if($updateSku == 135) $uupCleanFunc = 'uupCleanHolo';
|
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
if($fileListSource == 'GENERATEDPACKS') {
|
2022-03-05 19:46:31 +01:00
|
|
|
foreach($removeMSUs as $val) {
|
2022-08-25 03:59:37 +02:00
|
|
|
if(isset($filesInfoList[$val.'.cab']) && isset($filesInfoList[$val.'.msu'])) {
|
|
|
|
unset($filesInfoList[$val.'.msu']);
|
2022-03-05 19:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($removeMSUs);
|
|
|
|
$filesInfoKeys = array_keys($filesInfoList);
|
|
|
|
|
2023-03-14 16:09:51 +01:00
|
|
|
$temp = preg_grep('/Windows(10|11)\.0-KB.*-baseless/i', $filesInfoKeys, PREG_GREP_INVERT);
|
2022-03-05 19:46:31 +01:00
|
|
|
if($appEdition) {
|
2024-06-21 21:07:17 +02:00
|
|
|
$temp = preg_grep('/.*?AggregatedMetadata.*?\.cab/i', $temp);
|
2022-03-05 19:46:31 +01:00
|
|
|
} else if($build > 21380) {
|
|
|
|
$temp = preg_grep('/Windows(10|11)\.0-KB|SSU-.*?\....$|.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $temp);
|
2021-12-01 00:35:43 +01:00
|
|
|
} else {
|
2022-08-25 03:59:37 +02:00
|
|
|
$temp = preg_grep($updatesRegex, $temp);
|
2021-12-01 00:35:43 +01:00
|
|
|
}
|
2022-08-25 03:59:37 +02:00
|
|
|
|
|
|
|
$hasUpdates = !empty(preg_grep($updatesRegex, $temp));
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesPacksList = array_merge($filesPacksList, $temp);
|
2019-01-15 21:28:57 +01:00
|
|
|
|
|
|
|
$newFiles = array();
|
2021-09-19 15:58:48 +02:00
|
|
|
$failedFile = false;
|
|
|
|
if($sha256capable) {
|
|
|
|
$tmp = [];
|
|
|
|
foreach($filesInfoList as $key => $val) {
|
|
|
|
$tmp[$val['sha256']] = $key;
|
|
|
|
}
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2021-09-19 15:58:48 +02:00
|
|
|
foreach($filesPacksList as $val) {
|
|
|
|
if(isset($tmp[$val])) {
|
|
|
|
$name = $tmp[$val];
|
|
|
|
$newFiles[$name] = $filesInfoList[$name];
|
|
|
|
} else if(isset($filesInfoList[$val])) {
|
|
|
|
$name = $val;
|
|
|
|
$newFiles[$name] = $filesInfoList[$name];
|
|
|
|
} else {
|
2021-09-25 18:18:22 +02:00
|
|
|
$failedFile = true;
|
2021-12-01 00:35:43 +01:00
|
|
|
consoleLogger("Missing file: $val");
|
2021-09-19 15:58:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach($filesPacksList as $val) {
|
|
|
|
$name = $uupCleanFunc($val);
|
|
|
|
$filesPacksKeys[] = $name;
|
|
|
|
|
|
|
|
if(isset($filesInfoList[$name])) {
|
|
|
|
$newFiles[$name] = $filesInfoList[$name];
|
|
|
|
} else {
|
2021-09-25 18:18:22 +02:00
|
|
|
$failedFile = true;
|
2021-12-01 00:35:43 +01:00
|
|
|
consoleLogger("Missing file: $name");
|
2021-09-19 15:58:48 +02:00
|
|
|
}
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 15:58:48 +02:00
|
|
|
if($failedFile) {
|
2019-02-23 23:23:35 +01:00
|
|
|
return array('error' => 'MISSING_FILES');
|
|
|
|
}
|
2021-09-19 15:58:48 +02:00
|
|
|
|
|
|
|
$filesInfoList = $newFiles;
|
|
|
|
$filesInfoKeys = array_keys($filesInfoList);
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
if(empty($filesInfoKeys)) {
|
2019-01-15 21:28:57 +01:00
|
|
|
return array('error' => 'NO_FILES');
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$filesNew = array();
|
|
|
|
foreach($filesInfoKeys as $val) {
|
|
|
|
$filesNew[$val] = $filesInfoList[$val];
|
2022-09-07 01:28:19 +02:00
|
|
|
$filesNew[$val]['url'] = uupApiFixDownloadLink($filesInfoList[$val]['url']);
|
2019-01-15 21:28:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$files = $filesNew;
|
|
|
|
ksort($files);
|
|
|
|
|
|
|
|
consoleLogger('Successfully parsed the information.');
|
|
|
|
|
2022-10-22 01:20:13 +02:00
|
|
|
$data = [
|
2019-01-15 21:28:57 +01:00
|
|
|
'apiVersion' => uupApiVersion(),
|
|
|
|
'updateName' => $updateName,
|
|
|
|
'arch' => $updateArch,
|
|
|
|
'build' => $updateBuild,
|
2021-02-06 14:26:21 +01:00
|
|
|
'sku' => $updateSku,
|
2022-08-25 03:59:37 +02:00
|
|
|
'hasUpdates' => $hasUpdates,
|
2024-06-21 13:31:41 +02:00
|
|
|
'appxPresent' => uupAreAppxPresent($genPack),
|
2019-01-15 21:28:57 +01:00
|
|
|
'files' => $files,
|
2022-10-22 01:20:13 +02:00
|
|
|
];
|
2019-01-15 21:28:57 +01:00
|
|
|
|
2022-10-22 01:20:13 +02:00
|
|
|
if($requestType > 0) {
|
|
|
|
$cacheData = $data;
|
2022-10-23 17:58:14 +02:00
|
|
|
$cache->put($cacheData, 30);
|
2018-11-16 17:59:48 +01:00
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2022-10-22 01:20:13 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-10-23 17:58:14 +02:00
|
|
|
function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
|
2023-03-14 16:09:51 +01:00
|
|
|
$res = "api-get-online-{$updateId}_rev.$rev";
|
2022-10-23 17:58:14 +02:00
|
|
|
$cache = new UupDumpCache($res);
|
|
|
|
$fromCache = $cache->get();
|
|
|
|
$cached = ($fromCache !== false);
|
|
|
|
|
|
|
|
if($cached) {
|
|
|
|
$out = $fromCache['out'];
|
|
|
|
$fetchTime = $fromCache['fetchTime'];
|
|
|
|
} else {
|
|
|
|
$fetchTime = time();
|
|
|
|
consoleLogger('Fetching information from the server...');
|
2023-10-21 02:34:51 +02:00
|
|
|
|
|
|
|
$composerArgs = [$updateId, $info, $rev, $type];
|
|
|
|
$out = sendWuPostRequestHelper('clientSecured', 'composeFileGetRequest', $composerArgs);
|
|
|
|
|
2023-11-08 23:58:39 +01:00
|
|
|
if($out === false || $out['error'] != 200) {
|
2023-10-21 02:34:51 +02:00
|
|
|
consoleLogger('The request has failed');
|
|
|
|
return array('error' => 'WU_REQUEST_FAILED');
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = $out['out'];
|
2022-10-23 17:58:14 +02:00
|
|
|
consoleLogger('Information has been successfully fetched.');
|
|
|
|
}
|
2022-10-22 01:20:13 +02:00
|
|
|
|
2017-09-22 21:24:31 +02:00
|
|
|
consoleLogger('Parsing information...');
|
2018-11-16 21:29:29 +01:00
|
|
|
$xmlOut = @simplexml_load_string($out);
|
|
|
|
if($xmlOut === false) {
|
2022-08-25 17:46:16 +02:00
|
|
|
$cache->delete();
|
2018-11-16 21:51:54 +01:00
|
|
|
return array('error' => 'XML_PARSE_ERROR');
|
2018-11-16 21:29:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-11 21:48:46 +02:00
|
|
|
$xmlBody = $xmlOut->children('s', true)->Body->children();
|
|
|
|
|
|
|
|
if(!isset($xmlBody->GetExtendedUpdateInfo2Response)) {
|
2017-10-01 16:06:01 +02:00
|
|
|
consoleLogger('An error has occurred');
|
2017-09-22 21:24:31 +02:00
|
|
|
return array('error' => 'EMPTY_FILELIST');
|
|
|
|
}
|
|
|
|
|
2018-10-11 21:48:46 +02:00
|
|
|
$getResponse = $xmlBody->GetExtendedUpdateInfo2Response;
|
|
|
|
$getResult = $getResponse->GetExtendedUpdateInfo2Result;
|
|
|
|
|
|
|
|
if(!isset($getResult->FileLocations)) {
|
|
|
|
consoleLogger('An error has occurred');
|
|
|
|
return array('error' => 'EMPTY_FILELIST');
|
|
|
|
}
|
2018-03-29 19:41:22 +02:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$uupCleanFunc = 'uupCleanName';
|
|
|
|
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
|
|
|
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
|
|
|
|
2021-09-19 15:58:48 +02:00
|
|
|
$sha256capable = isset($info['sha256ready']);
|
|
|
|
|
2018-10-11 21:48:46 +02:00
|
|
|
$fileLocations = $getResult->FileLocations;
|
2017-09-22 21:24:31 +02:00
|
|
|
$info = $info['files'];
|
|
|
|
|
|
|
|
$files = array();
|
2018-10-11 21:48:46 +02:00
|
|
|
foreach($fileLocations->FileLocation as $val) {
|
|
|
|
$sha1 = bin2hex(base64_decode((string)$val->FileDigest));
|
2021-09-19 15:58:48 +02:00
|
|
|
$sha256 = isset($info[$sha1]['sha256']) ? $info[$sha1]['sha256'] : null;
|
2018-10-11 21:48:46 +02:00
|
|
|
$url = (string)$val->Url;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2018-10-11 21:48:46 +02:00
|
|
|
preg_match('/files\/(.{8}-.{4}-.{4}-.{4}-.{12})/', $url, $guid);
|
|
|
|
$guid = $guid[1];
|
2017-09-22 21:24:31 +02:00
|
|
|
|
|
|
|
if(empty($info[$sha1]['name'])) {
|
|
|
|
$name = $guid;
|
2017-11-03 19:33:17 +01:00
|
|
|
$size = -1;
|
2017-09-22 21:24:31 +02:00
|
|
|
} else {
|
2021-02-06 14:26:21 +01:00
|
|
|
$name = $info[$sha1]['name'];
|
2017-09-22 21:24:31 +02:00
|
|
|
$size = $info[$sha1]['size'];
|
|
|
|
}
|
|
|
|
|
2021-09-25 18:18:22 +02:00
|
|
|
if($sha256capable) {
|
2022-03-05 19:46:31 +01:00
|
|
|
$tempname = uupCleanSha256($name);
|
|
|
|
if(isset($files[$tempname])) {
|
2022-06-17 01:00:48 +02:00
|
|
|
if($size > $files[$tempname]['size']) {
|
|
|
|
$smaller = uupAppendSha1($tempname, $files[$tempname]['sha1']);
|
|
|
|
$files[$smaller] = $files[$tempname];
|
|
|
|
unset($files[$tempname]);
|
|
|
|
$newName = $tempname;
|
|
|
|
} else {
|
|
|
|
$newName = uupAppendSha1($tempname, $sha1);
|
|
|
|
}
|
2022-03-05 19:46:31 +01:00
|
|
|
} else {
|
|
|
|
$newName = $tempname;
|
|
|
|
}
|
2021-09-25 18:18:22 +02:00
|
|
|
} else {
|
|
|
|
$newName = $uupCleanFunc($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isset($fileSizes[$newName])) $fileSizes[$newName] = -2;
|
2017-09-22 21:24:31 +02:00
|
|
|
|
2021-09-25 18:18:22 +02:00
|
|
|
if($size > $fileSizes[$newName]) {
|
2018-10-11 21:48:46 +02:00
|
|
|
preg_match('/P1=(.*?)&/', $url, $expire);
|
2017-10-27 21:38:31 +02:00
|
|
|
if(isset($expire[0])) {
|
2018-10-11 21:48:46 +02:00
|
|
|
$expire = $expire[1];
|
2017-10-16 18:03:26 +02:00
|
|
|
}
|
2017-10-27 21:38:31 +02:00
|
|
|
|
2017-11-03 19:33:17 +01:00
|
|
|
$expire = intval($expire);
|
|
|
|
|
|
|
|
if($size < 0) {
|
|
|
|
$temp = ($expire - $fetchTime) / 600;
|
|
|
|
$size = ($temp - 1) * 31457280;
|
|
|
|
if($size < 0) $size = 0;
|
|
|
|
unset($temp);
|
|
|
|
}
|
|
|
|
|
2021-09-25 18:18:22 +02:00
|
|
|
$fileSizes[$newName] = $size;
|
2017-10-27 21:38:31 +02:00
|
|
|
|
|
|
|
$temp = array();
|
|
|
|
$temp['sha1'] = $sha1;
|
2021-09-19 15:58:48 +02:00
|
|
|
$temp['sha256'] = $sha256;
|
2017-10-27 21:38:31 +02:00
|
|
|
$temp['size'] = $size;
|
|
|
|
$temp['url'] = $url;
|
|
|
|
$temp['uuid'] = $guid;
|
2017-11-03 19:33:17 +01:00
|
|
|
$temp['expire'] = $expire;
|
2019-07-28 20:15:47 +02:00
|
|
|
$temp['debug'] = $val->asXML();
|
2017-10-27 21:38:31 +02:00
|
|
|
|
|
|
|
$files[$newName] = $temp;
|
2017-09-22 21:24:31 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-04 21:24:27 +02:00
|
|
|
|
2022-10-23 17:58:14 +02:00
|
|
|
if($cacheRequests == 1 && $cached == 0) {
|
|
|
|
$cacheData = [
|
|
|
|
'out' => $out,
|
|
|
|
'fetchTime' => $fetchTime,
|
|
|
|
];
|
|
|
|
|
|
|
|
$cache->put($cacheData, 90);
|
|
|
|
}
|
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
return $files;
|
|
|
|
}
|
2018-03-17 22:20:20 +01:00
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
function uupGetOfflineFiles($info) {
|
|
|
|
if(empty($info['files'])) return array();
|
2018-03-17 22:20:20 +01:00
|
|
|
|
2021-02-06 14:26:21 +01:00
|
|
|
$uupCleanFunc = 'uupCleanName';
|
|
|
|
if($info['sku'] == 189) $uupCleanFunc = 'uupCleanWCOS';
|
|
|
|
if($info['sku'] == 135) $uupCleanFunc = 'uupCleanHolo';
|
|
|
|
|
2021-09-19 15:58:48 +02:00
|
|
|
$sha256capable = isset($info['sha256ready']);
|
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
consoleLogger('Parsing information...');
|
|
|
|
foreach($info['files'] as $sha1 => $val) {
|
|
|
|
$name = $val['name'];
|
|
|
|
$size = $val['size'];
|
2021-09-19 15:58:48 +02:00
|
|
|
$sha256 = isset($val['sha256']) ? $val['sha256'] : null;
|
2017-10-16 18:03:26 +02:00
|
|
|
|
2021-09-25 18:18:22 +02:00
|
|
|
if($sha256capable) {
|
2022-03-05 19:46:31 +01:00
|
|
|
$tempname = uupCleanSha256($name);
|
|
|
|
if(isset($files[$tempname])) {
|
2022-06-17 01:00:48 +02:00
|
|
|
if($size > $files[$tempname]['size']) {
|
|
|
|
$smaller = uupAppendSha1($tempname, $files[$tempname]['sha1']);
|
|
|
|
$files[$smaller] = $files[$tempname];
|
|
|
|
unset($files[$tempname]);
|
|
|
|
$newName = $tempname;
|
|
|
|
} else {
|
|
|
|
$newName = uupAppendSha1($tempname, $sha1);
|
|
|
|
}
|
2022-03-05 19:46:31 +01:00
|
|
|
} else {
|
|
|
|
$newName = $tempname;
|
|
|
|
}
|
2021-09-25 18:18:22 +02:00
|
|
|
} else {
|
|
|
|
$newName = $uupCleanFunc($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isset($fileSizes[$newName])) $fileSizes[$newName] = 0;
|
|
|
|
|
|
|
|
if($size > $fileSizes[$newName]) {
|
|
|
|
$fileSizes[$newName] = $size;
|
2017-10-16 18:03:26 +02:00
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
$temp = array();
|
|
|
|
$temp['sha1'] = $sha1;
|
2021-09-19 15:58:48 +02:00
|
|
|
$temp['sha256'] = $sha256;
|
2019-01-15 21:28:57 +01:00
|
|
|
$temp['size'] = $size;
|
|
|
|
$temp['url'] = null;
|
|
|
|
$temp['uuid'] = null;
|
|
|
|
$temp['expire'] = 0;
|
2019-07-28 20:15:47 +02:00
|
|
|
$temp['debug'] = null;
|
2018-05-15 21:17:11 +02:00
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
$files[$newName] = $temp;
|
2018-04-29 21:33:19 +02:00
|
|
|
}
|
2017-09-22 21:24:31 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:28:57 +01:00
|
|
|
return $files;
|
2017-09-22 21:24:31 +02:00
|
|
|
}
|
2019-01-31 20:17:41 +01:00
|
|
|
|
2022-03-05 19:46:31 +01:00
|
|
|
function uupAppendSha1($name, $sha1) {
|
|
|
|
$n = strrpos($name, '.');
|
|
|
|
if($n === false) $n = strlen($name);
|
|
|
|
return substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uupCleanSha256($name) {
|
|
|
|
$replace = array(
|
|
|
|
'prss_signed_appx_' => null,
|
|
|
|
'~31bf3856ad364e35' => null,
|
|
|
|
'~~.' => '.',
|
|
|
|
'~.' => '.',
|
|
|
|
'~' => '-',
|
|
|
|
);
|
|
|
|
|
|
|
|
return strtr($name, $replace);
|
|
|
|
}
|
|
|
|
|
2019-01-31 20:17:41 +01:00
|
|
|
function uupCleanName($name) {
|
|
|
|
$replace = array(
|
|
|
|
'cabs_' => null,
|
|
|
|
'metadataesd_' => null,
|
2019-02-23 23:23:35 +01:00
|
|
|
'prss_signed_appx_' => null,
|
2019-01-31 20:17:41 +01:00
|
|
|
'~31bf3856ad364e35' => null,
|
|
|
|
'~~.' => '.',
|
|
|
|
'~.' => '.',
|
|
|
|
'~' => '-',
|
|
|
|
);
|
|
|
|
|
|
|
|
$name = strtr($name, 'QWERTYUIOPASDFGHJKLZXCVBNM', 'qwertyuiopasdfghjklzxcvbnm');
|
|
|
|
return strtr($name, $replace);
|
|
|
|
}
|
2021-02-06 14:26:21 +01:00
|
|
|
|
|
|
|
function uupCleanWCOS($name) {
|
|
|
|
$name = preg_replace('/^(appx)_(messaging_desktop|.*?)_/i', '$1/$2/', $name);
|
|
|
|
$name = preg_replace('/^(retail)_(.{3,5})_fre_/i', '$1/$2/fre/', $name);
|
|
|
|
return strtr($name, 'QWERTYUIOPASDFGHJKLZXCVBNM', 'qwertyuiopasdfghjklzxcvbnm');
|
|
|
|
}
|
|
|
|
|
|
|
|
function uupCleanHolo($name) {
|
|
|
|
$name = preg_replace('/^(appx)_(Cortana_WCOS|FeedbackHub_WCOS|HEVCExtension_HoloLens|MixedRealityViewer_arm64|MoviesTV_Hololens|Outlook_WindowsTeam|WinStore_HoloLens)_/i', '$1/$2/', $name);
|
|
|
|
$name = preg_replace('/^(appx)_(.*?)_/i', '$1/$2/', $name);
|
|
|
|
$name = preg_replace('/^(retail)_(.{3,5})_fre_/i', '$1/$2/fre/', $name);
|
|
|
|
return strtr($name, 'QWERTYUIOPASDFGHJKLZXCVBNM', 'qwertyuiopasdfghjklzxcvbnm');
|
|
|
|
}
|