Merge "Add prebuild and postbuild info to OTA_analysis."

This commit is contained in:
Treehugger Robot
2021-07-28 19:47:03 +00:00
committed by Gerrit Code Review
2 changed files with 88 additions and 5 deletions

View File

@@ -13,6 +13,22 @@
</li> </li>
</ul> </ul>
</div> </div>
<div
v-if="payload && payload.metadata"
v-bind="$attrs"
>
<ul class="align">
<li
v-for="formatter in MetadataFormat"
:key="formatter.name"
>
<strong> {{ formatter.name }} </strong>
<p class="wrap">
{{ String(payload[formatter.key]) }}
</p>
</li>
</ul>
</div>
<div v-if="payload && payload.manifest"> <div v-if="payload && payload.manifest">
<ul class="align"> <ul class="align">
<li> <li>
@@ -47,7 +63,7 @@
</template> </template>
<script> <script>
import { Payload } from '@/services/payload.js' import { Payload, MetadataFormat } from '@/services/payload.js'
export default { export default {
props: { props: {
@@ -60,6 +76,11 @@ export default {
required: true, required: true,
}, },
}, },
data() {
return {
MetadataFormat
}
}
} }
</script> </script>
@@ -75,4 +96,16 @@ export default {
.align strong::after { .align strong::after {
content: ':'; content: ':';
} }
li {
list-style-type: none;
}
.wrap {
width: 50%;
display: inline-block;
white-space: pre-wrap;
word-wrap: break-word;
font-family: inherit;
}
</style> </style>

View File

@@ -10,11 +10,33 @@
import * as zip from '@zip.js/zip.js/dist/zip-full.min.js' import * as zip from '@zip.js/zip.js/dist/zip-full.min.js'
import { chromeos_update_engine as update_metadata_pb } from './update_metadata_pb.js' import { chromeos_update_engine as update_metadata_pb } from './update_metadata_pb.js'
const /** Number */ _MAGIC = 'CrAU' const /** String */ _MAGIC = 'CrAU'
const /** Number */ _VERSION_SIZE = 8 const /** Number */ _VERSION_SIZE = 8
const /** Number */ _MANIFEST_LEN_SIZE = 8 const /** Number */ _MANIFEST_LEN_SIZE = 8
const /** Number */ _METADATA_SIGNATURE_LEN_SIZE = 4 const /** Number */ _METADATA_SIGNATURE_LEN_SIZE = 4
const /** Number */ _BRILLO_MAJOR_PAYLOAD_VERSION = 2 const /** Number */ _BRILLO_MAJOR_PAYLOAD_VERSION = 2
export const /** Array<Object> */ MetadataFormat = [
{
prefix: 'pre-build',
key: 'preBuild',
name: 'Pre-build'
},
{
prefix: 'pre-build-incremental',
key: 'preBuildVersion',
name: 'Pre-build version'
},
{
prefix: 'post-build',
key: 'postBuild',
name: 'Post-build'
},
{
prefix: 'post-build-incremental',
key: 'postBuildVersion',
name: 'Post-build version'
}
]
export class Payload { export class Payload {
/** /**
@@ -26,7 +48,10 @@ export class Payload {
this.cursor = 0 this.cursor = 0
} }
async unzipPayload() { /**
* Unzip the OTA package, get payload.bin and metadata
*/
async unzip() {
let /** Array<Entry> */ entries = await this.packedFile.getEntries() let /** Array<Entry> */ entries = await this.packedFile.getEntries()
this.payload = null this.payload = null
for (let entry of entries) { for (let entry of entries) {
@@ -34,6 +59,9 @@ export class Payload {
//TODO: only read in the manifest instead of the whole payload //TODO: only read in the manifest instead of the whole payload
this.payload = await entry.getData(new zip.BlobWriter()) this.payload = await entry.getData(new zip.BlobWriter())
} }
if (entry.filename == 'META-INF/com/android/metadata') {
this.metadata = await entry.getData(new zip.TextWriter())
}
} }
if (!this.payload) { if (!this.payload) {
alert('Please select a legit OTA package') alert('Please select a legit OTA package')
@@ -106,11 +134,22 @@ export class Payload {
.decode(signature_raw) .decode(signature_raw)
} }
parseMetadata() {
for (let formatter of MetadataFormat) {
let regex = new RegExp(formatter.prefix + '.+')
if (this.metadata.match(regex)) {
this[formatter.key] =
trimEntry(this.metadata.match(regex)[0], formatter.prefix)
} else this[formatter.key] = ''
}
}
async init() { async init() {
await this.unzipPayload() await this.unzip()
this.readHeader() this.readHeader()
this.readManifest() this.readManifest()
this.readSignature() this.readSignature()
this.parseMetadata()
} }
} }
@@ -160,3 +199,14 @@ export function octToHex(bufferArray, space = true, maxLine = 16) {
} }
return hex_table return hex_table
} }
/**
* Trim the prefix in an entry. This is required because the lookbehind
* regular expression is not supported in safari yet.
* @param {String} entry
* @param {String} prefix
* @return String
*/
function trimEntry(entry, prefix) {
return entry.slice(prefix.length + 1, entry.length)
}