javascript 中的 EDID 编辑
EDID edit in javascript
我想生成一个 Eisa 3 个字符的 ID,但似乎我太累了,看不出我到底搞砸了哪里..加上 js 中的位移或其他任何东西都不是我的头等大事;)
有人感兴趣吗? :)
看来我需要添加更多细节:我目前正在使用 vim & xxd 玩弄 EDID .bin,现在我的校验和方面的内容正常事情(还没有在 js 中)并保存那个 .bin,我想尝试通过编写基于 Web 的 EDID 修改工具来构建 dgallegos 工作(至少为制造商、序列号等生成正确的十六进制。)
nb:非常感谢 dgallegos 基于 Web 的 EDID reader ;)
var getEisaId = function()
{
var FIVE_BIT_LETTER_MASK = 0x1F;
var EISA_ID_BYTE1 = 8;
var EISA_ID_BYTE2 = 9;
var EISA_LETTER1_OFF = 2
var EISA_LETTER2_OFF = 5;
var LETTER2_TOP_BYTES = 3;
var LETTER2_TOP_MASK = 0x03;
var LETTER2_BOT_MASK = 0x07;
var firstLetter = (0xA1 >> EISA_LETTER1_OFF) &
FIVE_BIT_LETTER_MASK;
// Get the first two bits [2:0] of the top byte
var secondLetterTop = 0xA1 & LETTER2_TOP_MASK;
// Get the last three bits [7:5] of the bottom byte
var secondLetterBottom = (0x00 >> EISA_LETTER2_OFF) &
LETTER2_BOT_MASK;
// Combine the top and bottom
var secondLetter = (secondLetterTop << LETTER2_TOP_BYTES) | secondLetterBottom;
var thirdLetter = 0x00 & FIVE_BIT_LETTER_MASK;
return intToAscii(firstLetter)+intToAscii(secondLetter)+intToAscii(thirdLetter);
}
function intToAscii(intCode)
{
var abc = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
return abc[intCode];
}
getEisaId();
/* ==== this is fine ;p ====*/
function asciiToInt(asciiChar){
return "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(asciiChar);
}
//var byte9 = ( asciiToInt("0").toString(2) & 0x1F ).toString(16)
/* ==== this is not yet aside for "HHH" :/ ====*/
var generateEisaId = function(threeCharsId){
var FIVE_BIT_LETTER_MASK = 0x1F;
var EISA_LETTER1_OFF = 2;
var EISA_LETTER2_OFF = 5;
var LETTER2_TOP_BYTES = 3;
var LETTER2_TOP_MASK = 0x03;
var LETTER2_BOT_MASK = 0x07; // 111 in base 2
var charsArr = threeCharsId.split('').splice(0, 3); // delete anything after 3rd char
// format 1st char
var firstLetterBin = asciiToInt(charsArr[0]); //.toString(2); // get index from letter, and get its binary representation
console.log('1st letter: ' + charsArr[0] + ' > ' + asciiToInt(charsArr[0]) + ' (int/base10) > ' + firstLetterBin.toString(2) + ' (bin/base2)');
// format 2nd char
var secondLetterBin = asciiToInt(charsArr[1]); //.toString(2);
console.log('2nd letter: ' + charsArr[1] + ' > ' + asciiToInt(charsArr[1]) + ' (int/base10) > ' + secondLetterBin.toString(2) + ' (bin/base2)');
// get the second letter binary chunk for the 1st two bits of the top byte
//var secondLetterTopBin = secondLetterBin >> LETTER2_TOP_MASK;
//var secondLetterTopBin = secondLetterBin & LETTER2_TOP_MASK;
//var secondLetterTopBin = secondLetterBin & LETTER2_TOP_MASK;
var secondLetterTopBin = secondLetterBin >> 3; // shift 3 positions right ( drop stuff )
console.log('2nd letter top bin: ' + secondLetterTopBin.toString(2));
// get the second letter binary chunk for the last three bits of the bottom byte
//var secondLetterBottomBin = secondLetterBin & LETTER2_BOT_MASK;
var secondLetterBottomBin = ( secondLetterBin << 2 ) & 0x07;
console.log('2nd letter bottom bin: ' + secondLetterBottomBin.toString(2));
// format Last char
var thirdLetterBin = asciiToInt(charsArr[2]); //.toString(2);
console.log('3rd letter: ' + charsArr[2] + ' > ' + asciiToInt(charsArr[2]) + ' (int/base10) > ' + thirdLetterBin.toString(2) + ' (bin/base2)');
// 1st byte - add 1st char binary to top byte & shift it 2 positions left to make room for 2nd char 1st binary chunk of 2 bits
var firstLetterOnceOffset = ( firstLetterBin << EISA_LETTER1_OFF ) & FIVE_BIT_LETTER_MASK;
//var firstLetterOnceOffset = ( firstLetterBin & 0xA0 );
console.log('1st letter once offset: ' + firstLetterOnceOffset.toString(2));
//var topByte = ( ( firstLetterBin << EISA_LETTER1_OFF ) | secondLetterTopBin ) >> 2;
var topByte = ( firstLetterBin << EISA_LETTER1_OFF ) | secondLetterTopBin;
console.log('top byte: ' + topByte.toString(2) );
// 2nd byte - add 3rd char binary to bottom byte & shift it 3 positions right to make room for 2nd char 2nd binary chunk of 3 bits
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << EISA_LETTER2_OFF )
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << EISA_LETTER2_OFF );
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK );
var bottomByte = thirdLetterBin | ( secondLetterBottomBin << EISA_LETTER2_OFF ); // & 0xA0;
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << 8 );
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << 8 ); // &0x1F;
console.log('bottom byte: ' + bottomByte.toString(2));
// padding ?
var n1 = topByte.toString(2);
n1 = "00000000".substr(n1.length) + n1;
console.log('padded top byte: ' + n1);
var n2 = bottomByte.toString(2);
n2 = "00000000".substr(n2.length) + n2;
console.log('padded bottom byte: ' + n2);
// get hex's of the padded versions ?
var eisaIdP = '0x' + parseInt(n1, 2).toString(16) + ' 0x' + parseInt(n2, 2).toString(16);
console.log('padded: ' + eisaIdP);
// get hex's for both of the aboves
var eisaId = '0x' + topByte.toString(16) + bottomByte.toString(16);
return eisaId;
}
var myId = generateEisaId('HHH');
var myId = generateEisaId('AAA');
console.log('generated Eisa Id hex: ' + myId);
好吧,睡了一觉,回头看看那些东西,"it got clear" ;)
对于一些背景知识,3 个字母分为 2 个字节。
我们有一个 "dictionnary" 索引字母作为整数数组。
从存储它们索引的数组的长度,我们知道每个字母可用的位最大为 5 位(如果我们要将这 3 个字母存储在所述 2 个字节中,这会在第一个字节上给我们一个未设置的位),因为用作我们 "dictionnary" 中最后一个字符索引的整数在一个字节中占用 5 位(因此被认为是最大值)
试图让字母 'Z' 显示 3 次(所以 'ZZZ' )因此会导致以下过程:
/*
Z -> 26 (dec/base10)
0x1A (hex/base16)
11010 ( bin/base2)
Z: 11010
padded Z: 00011010
bytes: 00000000 | 00000000
split: 0 00000 00 | 000 00000
result: 0 11010 11 | 010 11010
formatted: 01101011 | 01011010
hex: 0x6b | 0x5a
-> SUCCESS! ==> gives us 'ZZZ'
*/
任何东西都更清晰(至少对我来说)和一点点颜色,以下内容确实有帮助(但没有突出显示“两位操作之间丢失 0”..但是?..)
R: 检查实际的浏览器控制台 ;)
var logBits = function(num, showHex){
var numBits = num.toString(2);
//var prefixLen = 8 - numBits;
var prefixStr = '';
//console.log(8 - numBits.length);
for(var i=0; i< 8 - numBits.length; i++){ prefixStr +='0'; }
if(showHex === true) console.log('0b%c' + prefixStr + '%c' + numBits + ' 0x' + num.toString(16), 'color: blue;', 'color: black;');
else console.log('0b%c' + prefixStr + '%c' + numBits, 'color: blue;', 'color: black;');
}
// to do: alternate version that colors in other color ( or doesn't color at all )
// "leading zeros that were lost we manipulating bits" to better perceive the changes in logs
// usage:
logBits(26);
上面写完了,剩下的就到这里了:
// helper
function asciiToInt(asciiChar){
return "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(asciiChar);
}
var genEisaId = function(threeCharsId, arr){
var charsArr = threeCharsId.split('').splice(0, 3); // delete anything after 3rd char
// get mapping idx's
var firstLetterBin = asciiToInt(charsArr[0]);
var secondLetterBin = asciiToInt(charsArr[1]);
var thirdLetterBin = asciiToInt(charsArr[2]);
// process
var secondLetter1stChunk = secondLetterBin >> 3; // discard the three last bits
var secondLetter2ndChunk = secondLetterBin & 0x07; //0b00111; // gets only the three last bits
// build
var firstByte = (firstLetterBin << 2 ) | secondLetter1stChunk;
var secondByte = (secondLetter2ndChunk << 5) | thirdLetterBin;
// post-proc
//var firstByteHex = firstByte.toString(16);
//var secondByteHex = secondByte.toString(16);
var firstByteHex = (firstByte.toString(16).length == 2 )? firstByte.toString(16) : '0' + firstByte.toString(16);
var secondByteHex = (secondByte.toString(16).length == 2) ? secondByte.toString(16) : '0' + secondByte.toString(16);
// return hex's
if(arr === true) return['0x' + firstByteHex, '0x' + secondByteHex];
else return '0x' + firstByteHex + ' 0x' + secondByteHex;
}
// usage:
console.log ( genEisaId('TEF') )
上面的函数很乐意在给定一串字符时生成任何 3 个字母的 EISA ID 十六进制(如果太长,有些可能会被删除;))
再次感谢@dgallegos 在 http://www.edidreader.com/ 上的工作并在 github 上分享(通过深入研究 "getEisaId()" 和 "intToAscii" 获得了很大帮助映射和解码的基础)。
我希望发布“也会帮助其他人生成 Id 或发现他的有用工具:)
我想生成一个 Eisa 3 个字符的 ID,但似乎我太累了,看不出我到底搞砸了哪里..加上 js 中的位移或其他任何东西都不是我的头等大事;)
有人感兴趣吗? :)
看来我需要添加更多细节:我目前正在使用 vim & xxd 玩弄 EDID .bin,现在我的校验和方面的内容正常事情(还没有在 js 中)并保存那个 .bin,我想尝试通过编写基于 Web 的 EDID 修改工具来构建 dgallegos 工作(至少为制造商、序列号等生成正确的十六进制。)
nb:非常感谢 dgallegos 基于 Web 的 EDID reader ;)
var getEisaId = function()
{
var FIVE_BIT_LETTER_MASK = 0x1F;
var EISA_ID_BYTE1 = 8;
var EISA_ID_BYTE2 = 9;
var EISA_LETTER1_OFF = 2
var EISA_LETTER2_OFF = 5;
var LETTER2_TOP_BYTES = 3;
var LETTER2_TOP_MASK = 0x03;
var LETTER2_BOT_MASK = 0x07;
var firstLetter = (0xA1 >> EISA_LETTER1_OFF) &
FIVE_BIT_LETTER_MASK;
// Get the first two bits [2:0] of the top byte
var secondLetterTop = 0xA1 & LETTER2_TOP_MASK;
// Get the last three bits [7:5] of the bottom byte
var secondLetterBottom = (0x00 >> EISA_LETTER2_OFF) &
LETTER2_BOT_MASK;
// Combine the top and bottom
var secondLetter = (secondLetterTop << LETTER2_TOP_BYTES) | secondLetterBottom;
var thirdLetter = 0x00 & FIVE_BIT_LETTER_MASK;
return intToAscii(firstLetter)+intToAscii(secondLetter)+intToAscii(thirdLetter);
}
function intToAscii(intCode)
{
var abc = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
return abc[intCode];
}
getEisaId();
/* ==== this is fine ;p ====*/
function asciiToInt(asciiChar){
return "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(asciiChar);
}
//var byte9 = ( asciiToInt("0").toString(2) & 0x1F ).toString(16)
/* ==== this is not yet aside for "HHH" :/ ====*/
var generateEisaId = function(threeCharsId){
var FIVE_BIT_LETTER_MASK = 0x1F;
var EISA_LETTER1_OFF = 2;
var EISA_LETTER2_OFF = 5;
var LETTER2_TOP_BYTES = 3;
var LETTER2_TOP_MASK = 0x03;
var LETTER2_BOT_MASK = 0x07; // 111 in base 2
var charsArr = threeCharsId.split('').splice(0, 3); // delete anything after 3rd char
// format 1st char
var firstLetterBin = asciiToInt(charsArr[0]); //.toString(2); // get index from letter, and get its binary representation
console.log('1st letter: ' + charsArr[0] + ' > ' + asciiToInt(charsArr[0]) + ' (int/base10) > ' + firstLetterBin.toString(2) + ' (bin/base2)');
// format 2nd char
var secondLetterBin = asciiToInt(charsArr[1]); //.toString(2);
console.log('2nd letter: ' + charsArr[1] + ' > ' + asciiToInt(charsArr[1]) + ' (int/base10) > ' + secondLetterBin.toString(2) + ' (bin/base2)');
// get the second letter binary chunk for the 1st two bits of the top byte
//var secondLetterTopBin = secondLetterBin >> LETTER2_TOP_MASK;
//var secondLetterTopBin = secondLetterBin & LETTER2_TOP_MASK;
//var secondLetterTopBin = secondLetterBin & LETTER2_TOP_MASK;
var secondLetterTopBin = secondLetterBin >> 3; // shift 3 positions right ( drop stuff )
console.log('2nd letter top bin: ' + secondLetterTopBin.toString(2));
// get the second letter binary chunk for the last three bits of the bottom byte
//var secondLetterBottomBin = secondLetterBin & LETTER2_BOT_MASK;
var secondLetterBottomBin = ( secondLetterBin << 2 ) & 0x07;
console.log('2nd letter bottom bin: ' + secondLetterBottomBin.toString(2));
// format Last char
var thirdLetterBin = asciiToInt(charsArr[2]); //.toString(2);
console.log('3rd letter: ' + charsArr[2] + ' > ' + asciiToInt(charsArr[2]) + ' (int/base10) > ' + thirdLetterBin.toString(2) + ' (bin/base2)');
// 1st byte - add 1st char binary to top byte & shift it 2 positions left to make room for 2nd char 1st binary chunk of 2 bits
var firstLetterOnceOffset = ( firstLetterBin << EISA_LETTER1_OFF ) & FIVE_BIT_LETTER_MASK;
//var firstLetterOnceOffset = ( firstLetterBin & 0xA0 );
console.log('1st letter once offset: ' + firstLetterOnceOffset.toString(2));
//var topByte = ( ( firstLetterBin << EISA_LETTER1_OFF ) | secondLetterTopBin ) >> 2;
var topByte = ( firstLetterBin << EISA_LETTER1_OFF ) | secondLetterTopBin;
console.log('top byte: ' + topByte.toString(2) );
// 2nd byte - add 3rd char binary to bottom byte & shift it 3 positions right to make room for 2nd char 2nd binary chunk of 3 bits
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << EISA_LETTER2_OFF )
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << EISA_LETTER2_OFF );
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK );
var bottomByte = thirdLetterBin | ( secondLetterBottomBin << EISA_LETTER2_OFF ); // & 0xA0;
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << 8 );
//var bottomByte = ( thirdLetterBin & FIVE_BIT_LETTER_MASK ) | ( secondLetterBottomBin << 8 ); // &0x1F;
console.log('bottom byte: ' + bottomByte.toString(2));
// padding ?
var n1 = topByte.toString(2);
n1 = "00000000".substr(n1.length) + n1;
console.log('padded top byte: ' + n1);
var n2 = bottomByte.toString(2);
n2 = "00000000".substr(n2.length) + n2;
console.log('padded bottom byte: ' + n2);
// get hex's of the padded versions ?
var eisaIdP = '0x' + parseInt(n1, 2).toString(16) + ' 0x' + parseInt(n2, 2).toString(16);
console.log('padded: ' + eisaIdP);
// get hex's for both of the aboves
var eisaId = '0x' + topByte.toString(16) + bottomByte.toString(16);
return eisaId;
}
var myId = generateEisaId('HHH');
var myId = generateEisaId('AAA');
console.log('generated Eisa Id hex: ' + myId);
好吧,睡了一觉,回头看看那些东西,"it got clear" ;)
对于一些背景知识,3 个字母分为 2 个字节。 我们有一个 "dictionnary" 索引字母作为整数数组。 从存储它们索引的数组的长度,我们知道每个字母可用的位最大为 5 位(如果我们要将这 3 个字母存储在所述 2 个字节中,这会在第一个字节上给我们一个未设置的位),因为用作我们 "dictionnary" 中最后一个字符索引的整数在一个字节中占用 5 位(因此被认为是最大值)
试图让字母 'Z' 显示 3 次(所以 'ZZZ' )因此会导致以下过程:
/*
Z -> 26 (dec/base10)
0x1A (hex/base16)
11010 ( bin/base2)
Z: 11010
padded Z: 00011010
bytes: 00000000 | 00000000
split: 0 00000 00 | 000 00000
result: 0 11010 11 | 010 11010
formatted: 01101011 | 01011010
hex: 0x6b | 0x5a
-> SUCCESS! ==> gives us 'ZZZ'
*/
任何东西都更清晰(至少对我来说)和一点点颜色,以下内容确实有帮助(但没有突出显示“两位操作之间丢失 0”..但是?..)
R: 检查实际的浏览器控制台 ;)
var logBits = function(num, showHex){
var numBits = num.toString(2);
//var prefixLen = 8 - numBits;
var prefixStr = '';
//console.log(8 - numBits.length);
for(var i=0; i< 8 - numBits.length; i++){ prefixStr +='0'; }
if(showHex === true) console.log('0b%c' + prefixStr + '%c' + numBits + ' 0x' + num.toString(16), 'color: blue;', 'color: black;');
else console.log('0b%c' + prefixStr + '%c' + numBits, 'color: blue;', 'color: black;');
}
// to do: alternate version that colors in other color ( or doesn't color at all )
// "leading zeros that were lost we manipulating bits" to better perceive the changes in logs
// usage:
logBits(26);
上面写完了,剩下的就到这里了:
// helper
function asciiToInt(asciiChar){
return "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(asciiChar);
}
var genEisaId = function(threeCharsId, arr){
var charsArr = threeCharsId.split('').splice(0, 3); // delete anything after 3rd char
// get mapping idx's
var firstLetterBin = asciiToInt(charsArr[0]);
var secondLetterBin = asciiToInt(charsArr[1]);
var thirdLetterBin = asciiToInt(charsArr[2]);
// process
var secondLetter1stChunk = secondLetterBin >> 3; // discard the three last bits
var secondLetter2ndChunk = secondLetterBin & 0x07; //0b00111; // gets only the three last bits
// build
var firstByte = (firstLetterBin << 2 ) | secondLetter1stChunk;
var secondByte = (secondLetter2ndChunk << 5) | thirdLetterBin;
// post-proc
//var firstByteHex = firstByte.toString(16);
//var secondByteHex = secondByte.toString(16);
var firstByteHex = (firstByte.toString(16).length == 2 )? firstByte.toString(16) : '0' + firstByte.toString(16);
var secondByteHex = (secondByte.toString(16).length == 2) ? secondByte.toString(16) : '0' + secondByte.toString(16);
// return hex's
if(arr === true) return['0x' + firstByteHex, '0x' + secondByteHex];
else return '0x' + firstByteHex + ' 0x' + secondByteHex;
}
// usage:
console.log ( genEisaId('TEF') )
上面的函数很乐意在给定一串字符时生成任何 3 个字母的 EISA ID 十六进制(如果太长,有些可能会被删除;))
再次感谢@dgallegos 在 http://www.edidreader.com/ 上的工作并在 github 上分享(通过深入研究 "getEisaId()" 和 "intToAscii" 获得了很大帮助映射和解码的基础)。
我希望发布“也会帮助其他人生成 Id 或发现他的有用工具:)