feat(staging): adding protobuf decoder (part 2)

This commit is contained in:
Pavel-Savely Savianok 2025-03-01 22:58:48 +03:00
parent bd490d4642
commit ba4b8cc29e
3 changed files with 29 additions and 18 deletions
lib
protobuf-decoder
totp-quickjs
setting/utils

@ -1,6 +1,6 @@
import { decodeVarint } from "./varintUtils";
class BufferReader {
export class BufferReader {
constructor(buffer) {
this.buffer = buffer;
this.offset = 0;

@ -25,22 +25,30 @@ function leftpad(str, len, pad) {
);
}
export function base64decode(base64String) {
var sliceSize = 1024;
var byteCharacters = window.atob(base64String);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
export function base64decode(base64) {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
let result = [];
let i = 0, j = 0;
let b1, b2, b3, b4;
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
while (i < base64.length) {
b1 = chars.indexOf(base64.charAt(i++));
b2 = chars.indexOf(base64.charAt(i++));
b3 = chars.indexOf(base64.charAt(i++));
b4 = chars.indexOf(base64.charAt(i++));
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
if (b1 === -1 || b2 === -1) break;
result[j++] = (b1 << 2) | (b2 >> 4);
if (b3 !== -1) {
result[j++] = ((b2 & 15) << 4) | (b3 >> 2);
}
return byteArrays
if (b4 !== -1) {
result[j++] = ((b3 & 3) << 6) | b4;
}
}
return result.slice(0, j);
}

@ -64,6 +64,9 @@ function getByOtpauthScheme(link){
function getByGoogleMigrationScheme(link){
console.log("Hello")
let data = link.split("data=")[1]; //Returns secret
let decodedProto = decodeProto(base64decode(data));
console.log(decodedProto)
data = decodeURIComponent(data);
console.log(data)
let decode = base64decode(data);
console.log(decode)
console.log(decodeProto(decode));
}