Skip to content

Commit

Permalink
Add vbmeta verity disable page
Browse files Browse the repository at this point in the history
  • Loading branch information
affggh committed Nov 1, 2024
1 parent d6e2a4a commit 2c59902
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 7 deletions.
20 changes: 13 additions & 7 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down Expand Up @@ -82,21 +83,24 @@
}
</style>
</head>

<body>
<div id="dialog" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); padding:20px; background-color: #f44336; color: white;">
<div id="dialog"
style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); padding:20px; background-color: #f44336; color: white;">
<p id="message"></p>
<button onclick="closeDialog()">OK</button>
</div>
<div class="container">
<h1>展讯在线签名</h1>
<nav>
<a id="link_a" href="#">AVB Tool</a>
<a id="link_b" href="#">Legacy</a>
<a id="link_b" href="#">Legacy (BSP)</a>
<a id="link_c" href="#">Disable Vbmeta Check</a>
</nav>
</div>
<script>
// Function to show dialog with message
function showDialog(message) {
// Function to show dialog with message
function showDialog(message) {
document.getElementById("message").innerText = message;
document.getElementById("dialog").style.display = "block";
}
Expand Down Expand Up @@ -136,8 +140,10 @@ <h1>展讯在线签名</h1>
showDialog("Your browser does not support Blob download.");
}

document.getElementById("link_a").href = window.location.href + '/' + 'avbtool';
document.getElementById("link_b").href = window.location.href + '/' + 'legacy';
document.getElementById("link_a").href = './avbtool';
document.getElementById("link_b").href = './legacy';
document.getElementById("link_c").href = './vbmeta';
</script>
</body>
</html>

</html>
235 changes: 235 additions & 0 deletions web/vbmeta/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>修改VBMETA校验</title>
<style>
body {
font-family: 'Roboto', sans-serif;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--background);
transition: background-color 0.3s;
}

.card {
width: 90%;
max-width: 400px;
margin: 20px;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
transition: transform 0.2s;
}

.card:hover {
transform: translateY(-4px);
}

.dark-theme {
--background: #121212;
color: white;
}

.dark-theme .card {
background-color: #1e1e1e;
}

.light-theme {
--background: #ffffff;
color: black;
}

.light-theme .card {
background-color: #f7f7f7;
}

.checkbox {
display: flex;
align-items: center;
margin: 10px 0;
}

.checkbox input {
display: none;
}

.checkbox-label {
position: relative;
padding-left: 30px;
cursor: pointer;
user-select: none;
}

.checkbox-label::before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 20px;
height: 20px;
border: 2px solid #6200ea;
border-radius: 4px;
background: white;
transition: background-color 0.3s, border-color 0.3s;
}

.checkbox input:checked+.checkbox-label::before {
background: #6200ea;
border-color: #6200ea;
}

.download-btn {
background-color: #6200ea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}

.download-btn:hover {
background-color: #3700b3;
}
</style>
</head>

<body class="light-theme">

<div class="card" id="file-card">
<h2>拖入或选择Vbmeta文件</h2>
<input type="file" id="file-input" style="display:none;" />
<div id="drop-area" style="border: 2px dashed #6200ea; padding: 20px; text-align: center;">
<p>将文件拖到这里,或<a href="#" id="select-file">点击选择文件</a></p>
</div>
<div id="file-content" style="margin-top: 20px;"></div>
</div>

<div class="card">
<h2>选项</h2>
<div class="checkbox">
<input type="checkbox" id="option1" checked>
<label class="checkbox-label" for="option1">DISABLE_VERITY</label>
</div>
<div class="checkbox">
<input type="checkbox" id="option2" checked>
<label class="checkbox-label" for="option2">DISABLE_VERIFICATION</label>
</div>
<button class="download-btn" id="download-btn">下载</button>
</div>
<script src="./vbmeta_disable_verity.js"></script>
<script>
const dropArea = document.getElementById('drop-area');
const fileInput = document.getElementById('file-input');
const selectFile = document.getElementById('select-file');
const downloadBtn = document.getElementById('download-btn');
const fileContentDiv = document.getElementById('file-content');
const option1 = document.getElementById('option1');
const option2 = document.getElementById('option2');

// 文件大小限制:10MB
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB

dropArea.addEventListener('dragover', (e) => {
e.preventDefault();
dropArea.style.backgroundColor = '#e3f2fd';
});

dropArea.addEventListener('dragleave', () => {
dropArea.style.backgroundColor = 'transparent';
});

dropArea.addEventListener('drop', (e) => {
e.preventDefault();
dropArea.style.backgroundColor = 'transparent';
const files = e.dataTransfer.files;
if (files.length) {
handleFile(files[0]); // 处理第一个文件
}
});

selectFile.addEventListener('click', () => {
fileInput.click();
});

fileInput.addEventListener('change', (e) => {
const files = e.target.files;
if (files.length) {
handleFile(files[0]); // 处理第一个文件
}
});

downloadBtn.addEventListener('click', () => {
const file = fileInput.files[0];

if (!file) {
alert("请先上传一个文件");
return;
}

if (file) {
const reader = new FileReader();
reader.onload = (ev) => {
const arrayBuffer = ev.target.result;
ParseVbmetaData(arrayBuffer, option1.checked, option2.checked);

const modifiedBlob = new Blob([arrayBuffer], { type: file.type });
const url = URL.createObjectURL(modifiedBlob);

// 创建下载链接
const a = document.createElement('a');
a.href = url;
a.download = file.name; // 设置下载文件名
document.body.appendChild(a);
a.click(); // 触发下载
document.body.removeChild(a); // 移除链接

// 释放 Blob URL
URL.revokeObjectURL(url);
};

reader.readAsArrayBuffer(file);
}
});

// 文件处理函数
function handleFile(file) {
if (file.size > MAX_FILE_SIZE) {
alert("文件大小超过 10MB,请选择更小的文件");
return;
}

// 显示文件信息
const fileInfo = `
文件名: ${file.name}
文件大小: ${(file.size / 1024 / 1024).toFixed(2)} MB
`;
fileContentDiv.textContent = fileInfo; // 显示文件信息
}

// 自动切换主题
const setTheme = (theme) => {
document.body.classList.remove('dark-theme', 'light-theme');
document.body.classList.add(theme);
};

const toggleTheme = () => {
const currentTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark-theme' : 'light-theme';
setTheme(currentTheme);
};

toggleTheme(); // 初始设置主题

// 监听系统主题变化
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', toggleTheme);

</script>
</body>

</html>
41 changes: 41 additions & 0 deletions web/vbmeta/vbmeta_disable_verity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@ts-check

const AVB_MAGIC = "AVB0";
const AVB_MAGIC_LEN = 4;
const FLAGS_OFFSET = 123;
const FLAG_DISABLE_VERITY = 0x01;
const FLAG_DISABLE_VERIFICATION = 0x02;

function convertString(array) {
const decoder = new TextDecoder('utf-8');
return decoder.decode(array);
}

// arraybuffer disable_verity:bool disable_verification:bool
function ParseVbmetaData(vbmetaData, disable_verity, disable_verification) {
const view = new Uint8Array(vbmetaData);

const magic = convertString(view.subarray(0, AVB_MAGIC_LEN));
if (magic != AVB_MAGIC) {
throw new Error("Invalid format, this is not a vbmeta image");
}

console.log("Origin flag:", view[FLAGS_OFFSET]);
console.log("DISABLE_VERITY:", Boolean(view[FLAGS_OFFSET] & FLAG_DISABLE_VERITY));
console.log("DISABLE_VERIFICATION:", Boolean(view[FLAGS_OFFSET] & FLAG_DISABLE_VERIFICATION));

let flag = 0;
if (disable_verity) {
flag |= FLAG_DISABLE_VERITY
}

if (disable_verification) {
flag |= FLAG_DISABLE_VERIFICATION
}

view[FLAGS_OFFSET] = flag;

console.log("Edited flag:", view[FLAGS_OFFSET]);
console.log("DISABLE_VERITY:", Boolean(view[FLAGS_OFFSET] & FLAG_DISABLE_VERITY));
console.log("DISABLE_VERIFICATION:", Boolean(view[FLAGS_OFFSET] & FLAG_DISABLE_VERIFICATION));
};

0 comments on commit 2c59902

Please sign in to comment.