本帖最后由 Patek 于 2021-1-20 14:57 编辑
问答区:https://bbs.125.la/forum.php?mod=viewthread&tid=14662610&extra=
如有错误,还望大佬们能指正,感谢!
环境:
Win10 、 [size=20.0005px]Chrome 87.0.42 *** 、 WT-js 1.83
[size=20.0005px]
0x1:
打开浏览器开发者调试工具(F12),转到url : http://explorer.bohrweb.org/addressDetail.html?address=BfErfYxuQqdiaPtGb1zGBuyGVDYFA1wDd4S
发现一路的 debuger:
针对这个站点,我的方案是,遇到 debuger ,则在 debuger 那行添加断点 ( add breakpoint ),并编辑调试代码 ( edit breakpoint ) ,写入 “false”, 有四处需要修改的:
0x2:
现在,我们可以看到正常的请求了,我们把他的查询结果搜索一下,用以确定我们需要的数据来源url
复制一些数据,CTRL + F 我们来查找一下:
我们得到数据来源地址:https://explorer.bohrweb.org/api/transaction/page/other/0x757ACAB8A991F75DC04C62FA424380091A9C5B8E/1
因为网页加载完了之后,它才有数据返回,我们确定是从哪发起的请求:
这里我们在 param 这里下一个断点,完了再刷新一下网页。看下都用了什么参数:
很好,我们正确的断了下来。
经过分析,getUrlParam 这个函数是用来获取 URL 的参数值的。
得出: param = '0x' + addressDecode('BfErfYxuQqdiaPtGb1zGBuyGVDYFA1wDd4S')
F9 继续让代码跑起来,我们看看这个 addressDecode () 函数在哪里,把它扣出来
function SHA256 ( msgBytes) { var shaObj = new jsSHA ( "SHA-256", "HEX") ; var msgHex = byteArray2hexStr ( msgBytes) ; shaObj.update ( msgHex) ; var hashHex = shaObj.getHash ( "HEX") ; var hashBytes = hexStr2byteArray ( hashHex) ; return hashBytes;} //return pubkey by 65 bytes, priKeyBytes is byte[ ] function getPubKeyFromPriKey ( priKeyBytes) { var EC = elliptic.ec; var ec = new EC ( var key = ec.keyFromPrivate ( priKeyBytes, var pubkey = key.getPublic ( ) ; var x = pubkey.x; var y = pubkey.y; var xHex = x.toString ( while ( xHex.length < 64) { xHex = "0" + xHex;} var yHex = y.toString ( while ( yHex.length < 64) { yHex = "0" + yHex;} var pubkeyHex = "04" + xHex + yHex; var pubkeyBytes = hexStr2byteArray ( pubkeyHex) ; return pubkeyBytes;} function computeAddress ( add_pre_fix, pubBytes) { if ( pubBytes.length == 65) { pubBytes = pubBytes.slice ( 1) ;} var hash = CryptoJS.SHA3 ( pubBytes) .toString ( ) ; var addressHex = hash.substring ( 24) ; addressHex = add_pre_fix + addressHex; var addressBytes = hexStr2byteArray ( addressHex) ; return addressBytes;} //return address by Base58Check String, function getBase58CheckAddress ( addressBytes) { var hash0 = SHA256 ( addressBytes) ; var hash1 = SHA256 ( hash0) ; var checkSum = hash1.slice ( 0, 4) ; checkSum = addressBytes.concat ( checkSum) ; var base58Check = encode58 ( checkSum) ; return base58Check;} function decodeBase58Address ( base58Sting) { var zeroAddress = hexStr2byteArray ( "000000000000000000000000000000000000000000") ;if ( typeof ( base58Sting) != alert ( "Input format error!") ; return;} if ( base58Sting.length <= 4) { alert ( "Input length error!") ; return;} var address = decode58 ( base58Sting) ;if ( base58Sting.length <= 4) { alert ( "Decode58 output length error!") ; return;} var len = address.length; var offset = len - 4; var checkSum = address.slice ( offset) ; address = address.slice ( 0, offset) ; // var hash0 = SHA256 ( address) ; // var hash1 = SHA256 ( hash0) ; // var checkSum1 = hash1.slice ( 0, 4) ; // if ( checkSum[ 0] == checkSum1[ 0] && checkSum[ 1] == checkSum1[ 1] && checkSum[ 2] // == checkSum1[ 2] && checkSum[ 3] == checkSum1[ 3] // ) { return address; // } // alert ( "Check sum error!") ; // return zeroAddress;} function getRndPriKey ( ) { var array = new Array ( 32) ; var count = 0;for ( var i = 0; i < 32; i++) { array[ i] = 0;for ( var j = 0; j < 8; j++) { var random = Math.random ( ) ;if ( random >= 0.5) { array[ i] |= ( 1 << j) ; count++;} } } var hexString = byteArray2hexStr ( array) ; return hexString;} function Base64 ( ) { var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; // public method for encoding this.encode = function ( input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; // input = _utf8_encode ( input) ;while ( i < input.length) { chr1 = input.charCodeAt ( i++) ; chr2 = input.charCodeAt ( i++) ; chr3 = input.charCodeAt ( i++) ; enc1 = chr1 >> 2; enc2 = ( ( chr1 & 3) << 4) | ( chr2 >> 4) ; enc3 = ( ( chr2 & 15) << 2) | ( chr3 >> 6) ; enc4 = chr3 & 63;if ( isNaN ( chr2) ) { enc3 = enc4 = 64;} else if ( isNaN ( chr3) ) { enc4 = 64;} output = output + _keyStr.charAt ( enc1) + _keyStr.charAt ( enc2) + _keyStr.charAt ( enc3) + _keyStr.charAt ( enc4) ;} return output;} // public method for encoding this.encodeIgnoreUtf8 = function ( inputBytes) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; // input = _utf8_encode ( input) ;while ( i < inputBytes.length) { chr1 = inputBytes[ i++] ; chr2 = inputBytes[ i++] ; chr3 = inputBytes[ i++] ; enc1 = chr1 >> 2; enc2 = ( ( chr1 & 3) << 4) | ( chr2 >> 4) ; enc3 = ( ( chr2 & 15) << 2) | ( chr3 >> 6) ; enc4 = chr3 & 63;if ( isNaN ( chr2) ) { enc3 = enc4 = 64;} else if ( isNaN ( chr3) ) { enc4 = 64;} output = output + _keyStr.charAt ( enc1) + _keyStr.charAt ( enc2) + _keyStr.charAt ( enc3) + _keyStr.charAt ( enc4) ;} return output;} // public method for decoding this.decode = function ( input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace ( /[ ^A-Za-z0-9\+\/\=] /g, "") ;while ( i < input.length) { enc1 = _keyStr.indexOf ( input.charAt ( i++) ); enc2 = _keyStr.indexOf ( input.charAt ( i++) ); enc3 = _keyStr.indexOf ( input.charAt ( i++) ); enc4 = _keyStr.indexOf ( input.charAt ( i++) ); chr1 = ( enc1 << 2) | ( enc2 >> 4) ; chr2 = ( ( enc2 & 15) << 4) | ( enc3 >> 2) ; chr3 = ( ( enc3 & 3) << 6) | enc4; output = output + String.fromCharCode ( chr1) ;if ( enc3 != 64) { output = output + String.fromCharCode ( chr2) ;} if ( enc4 != 64) { output = output + String.fromCharCode ( chr3) ;} } output = _utf8_decode ( output) ; return output;} // public method for decoding this.decodeToByteArray = function ( input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace ( /[ ^A-Za-z0-9\+\/\=] /g, "") ;while ( i < input.length) { enc1 = _keyStr.indexOf ( input.charAt ( i++) ); enc2 = _keyStr.indexOf ( input.charAt ( i++) ); enc3 = _keyStr.indexOf ( input.charAt ( i++) ); enc4 = _keyStr.indexOf ( input.charAt ( i++) ); chr1 = ( enc1 << 2) | ( enc2 >> 4) ; chr2 = ( ( enc2 & 15) << 4) | ( enc3 >> 2) ; chr3 = ( ( enc3 & 3) << 6) | enc4; output = output + String.fromCharCode ( chr1) ;if ( enc3 != 64) { output = output + String.fromCharCode ( chr2) ;} if ( enc4 != 64) { output = output + String.fromCharCode ( chr3) ;} } var outBytes = _out2ByteArray ( output) ; return outBytes;} // private method for UTF-8 decoding _out2ByteArray = function ( utftext) { var byteArray = new Array ( utftext.length) var i = 0; var c = c1 = c2 = 0;while ( i < utftext.length) { c = utftext.charCodeAt ( i) ; byteArray[ i] = c; i++;} return byteArray;} // private method for UTF-8 encoding _utf8_encode = function ( string) { string = string.replace ( /\r\n/g, "\n") ; var utftext = "";for ( var n = 0; n < string.length; n++) { var c = string.charCodeAt ( n) ;if ( c < 128) { utftext += String.fromCharCode ( c) ;} else if ( ( c > 127) && ( c < 2048) ) { utftext += String.fromCharCode ( ( c >> 6) | 192) ; utftext += String.fromCharCode ( ( c & 63) | 128) ;} else { utftext += String.fromCharCode ( ( c >> 12) | 224) ; utftext += String.fromCharCode ( ( ( c >> 6) & 63) | 128) ; utftext += String.fromCharCode ( ( c & 63) | 128) ;} } return utftext;} // private method for UTF-8 decoding _utf8_decode = function ( utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0;while ( i < utftext.length) { c = utftext.charCodeAt ( i) ;if ( c < 128) { string += String.fromCharCode ( c) ; i++;} else if ( ( c > 191) && ( c < 224) ) { c2 = utftext.charCodeAt ( i + 1) ; string += String.fromCharCode ( ( ( c & 31) << 6) | ( c2 & 63) ); i += 2;} else { c2 = utftext.charCodeAt ( i + 1) ; c3 = utftext.charCodeAt ( i + 2) ; string += String.fromCharCode ( ( ( c & 15) << 12) | ( ( c2 & 63) << 6) | ( c3 & 63) ); i += 3;} } return string;} } function stringToBytes ( str) { var bytes = new Array ( ) ; var len, c; len = str.length;for ( var i = 0; i < len; i++) { c = str.charCodeAt ( i) ;if ( c >= 0x010000 && c <= 0x10FFFF) { bytes.push ( ( ( c >> 18) & 0x07) | 0xF0) ; bytes.push ( ( ( c >> 12) & 0x3F) | 0x80) ; bytes.push ( ( ( c >> 6) & 0x3F) | 0x80) ; bytes.push ( ( c & 0x3F) | 0x80) ;} else if ( c >= 0x000800 && c <= 0x00FFFF) { bytes.push ( ( ( c >> 12) & 0x0F) | 0xE0) ; bytes.push ( ( ( c >> 6) & 0x3F) | 0x80) ; bytes.push ( ( c & 0x3F) | 0x80) ;} else if ( c >= 0x000080 && c <= 0x0007FF) { bytes.push ( ( ( c >> 6) & 0x1F) | 0xC0) ; bytes.push ( ( c & 0x3F) | 0x80) ;} else { bytes.push ( c & 0xFF) ;} } return bytes;} function bytesToString ( arr) { if ( typeof arr === return arr;} var str = _arr = arr;for ( var i = 0; i < _arr.length; i+
0x5:
js代码很短,所以我们省去一下麻烦,全部拿下来了。接下来我们放到 js调试工具里面跑一下...
尿性.....
我们要知道 , let 是 ECMA 的语法,和 var 差不多都是声明变量,我们改成 var .... 就行,( 注意:let 和 var 的作用域是不同的哈 )
我们知道,这个代码是将 encodeAddress 声明为一个对象,并把 do58DecodeAddress 和 do58EncodeAddress 这个两个函数声明为它的方法
我们把
let encodeAddress = {
do58DecodeAddress ,
do58EncodeAddress
}
这段删掉,并把上面两个函数(do58DecodeAddress ,do58EncodeAddress )包起来,改成:
var encodeAddress = {
do58DecodeAddress : function (src){
//var src = "kaAACefr3fk9smimWNtxkDz3q6aPUdtEAKD";
var bytes = decodeBase58Address(src);
var xx = byteArray2hexStr(bytes);
return xx;
} ,
do58EncodeAddress : function (src) {
//var src = "18888A4A39B0E62A091608E9631FFD19427D2D338DBD";
var bytes = hexStr2byteArray(src);
var xx = getBase58CheckAddress(bytes);
return xx;
}
}
继续加载代码,得到错误提示:
splice0x 和 addressEncode 这两个函数中的 let 我们 改成 var
加载成功,测试是否能正常运行:
diu ~~~ 我们跟到 464 行检查下
.....
这个 string 是 decode58 的形参,这里判断 c 是否存在于 ALPHABET_MAP 这个对象中。
我们知道,中括号是用来表示数组,但是,它传入的是一个字符串,我们的 脚本组件 不太 care 这种方式,所以我们的改造一下
好了,再加载执行看看:
757ACAB8A991F75DC04C62FA424380091A9C5B8E
https://explorer.bohrweb.org/api/transaction/page/other/0x757ACAB8A991F75DC04C62FA424380091A9C5B8E/1
对上了 !
我们再来写个函数,把它拼接起来
收工!!!!
感谢观看,如有错误,麻烦指正,希望共同进步,十分感谢!
附上:
js.txt
(19.43 KB, 下载次数: 2)
评分
查看全部评分