protobufjs 命令执行_【原码笔记】-- protobuf.js 与 Long.js
protobuf.js的结构和webpack的加载之后的结构很相似。这样的模块化组合是个不错的结构方式。1个是适应了不同的加载方式,2个模块直接很独立。webpack的功能更全一点。但如果自己封装js库这样够用了。而且模块对外统一接口 module.exports。这和node很像。
(function(global, undefined) {"use strict";
(functionprelude(modules, cache, entries) {function$require(name) {var $module =cache[name];//没有就去加载
if (!$module)
modules[name][0].call($module = cache[name] ={ exports: {} }, $require, $module, $module.exports);return$module.exports;
}//曝光成全局
var proto = global.proto = $require(entries[0]);//AMD
if (typeof define === "function" &&define.amd) {
define(["long"], function(Long) {if (Long &&Long.isLong) {
proto.util.Long=Long;
proto.configure();
}
});returnproto;
}//CommonJS
if (typeof module === "object" && module &&module.exports)
module.exports=proto;
})//传参
({1: [function(require, module, exports) {functionfirst() {
console.log("first");
}
module.exports=first;
}, {}],2: [function(require, module, exports) {functionsecond() {
console.log("second");
}
module.exports=second;
}],3: [function(require, module, exports) {var proto ={};
proto.first= require(1);
proto.second= require(2);
proto.build= "full";
module.exports=proto;
}]
}, {}, [3]);
})(typeof window==="object"&&window||typeof self==="object"&&self||this)
在处理超过16位的整形就得使用Long.js了。 主要是fromString和toString。
functionfromString(str, unsigned, radix) {if (str.length === 0)throw Error('empty string');if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")returnZERO;if (typeof unsigned === 'number') {//For goog.math.long compatibility
radix =unsigned,
unsigned= false;
}else{
unsigned= !!unsigned;
}
radix= radix || 10;if (radix < 2 || 36 0)throw Error('interior hyphen');else if (p === 0) {return fromString(str.substring(1), unsigned, radix).neg();
}//Do several (8) digits each time through the loop, so as to
//minimize the calls to the very expensive emulated div.
var radixToPower = fromNumber(pow_dbl(radix, 8));var result =ZERO;for (var i = 0; i < str.length; i += 8) {var size = Math.min(8, str.length -i),
value= parseInt(str.substring(i, i +size), radix);if (size < 8) {var power =fromNumber(pow_dbl(radix, size));
result=result.mul(power).add(fromNumber(value));
}else{
result=result.mul(radixToPower);
result=result.add(fromNumber(value));
}
}
result.unsigned=unsigned;returnresult;
}
fromstring的思路是把字符串8位一个截取。然后转成Long型(高位,地位,符号位) 加起来。最后是一个Long型。 4294967296 是2的32次方。每次操作之前都会有一个基数的操作 mul(radixToPower)或者mul(power)这两者都是保证result的位数是正确的。
比如{low:123} 和{low:1} 相加之前,先要让{low:123}乘以10,得到{low:1230}再与{low:1}进行位操作。因为第一个是高位,不能直接相加。
functionfromBits(lowBits, highBits, unsigned) {return newLong(lowBits, highBits, unsigned);
}
fromBits 即转为Long对象。value%4294967296 得到低位。/得到高位。结果通过位移合并起来。mul是bit的乘法,add是bit的加法。 原理是讲一个64位的拆成四段。分别16位。this.low左移16位 就得到 low的32-17位是啥。 然后和addend对象的同位相加
最后的合并是通过|运算。位移之后再还原确实很巧妙。一时看上去都不大理解。
LongPrototype.add = functionadd(addend) {if (!isLong(addend))
addend=fromValue(addend);//Divide each number into 4 chunks of 16 bits, and then sum the chunks.
var a48 = this.high >>> 16;var a32 = this.high & 0xFFFF;var a16 = this.low >>> 16;var a00 = this.low & 0xFFFF;var b48 = addend.high >>> 16;var b32 = addend.high & 0xFFFF;var b16 = addend.low >>> 16;var b00 = addend.low & 0xFFFF;var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
c00+= a00 +b00;
c16+= c00 >>> 16;
c00&= 0xFFFF;
c16+= a16 +b16;
c32+= c16 >>> 16;
c16&= 0xFFFF;
c32+= a32 +b32;
c48+= c32 >>> 16;
c32&= 0xFFFF;
c48+= a48 +b48;
c48&= 0xFFFF;return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
};
>>>和>>有什么区别??。
toString
LongPrototype.toString = functiontoString(radix) {
radix= radix || 10;if (radix < 2 || 36
if (this.eq(MIN_VALUE)) {//We need to change the Long value before it can be negated, so we remove
//the bottom-most digit in this base and then recurse to do the rest.
var radixLong =fromNumber(radix),
div= this.div(radixLong),
rem1= div.mul(radixLong).sub(this);return div.toString(radix) +rem1.toInt().toString(radix);
}else
return '-' + this.neg().toString(radix);
}//Do several (6) digits each time through the loop, so as to
//minimize the calls to the very expensive emulated div.
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
rem= this;var result = '';while (true) {var remDiv =rem.div(radixToPower),
intval= rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
digits=intval.toString(radix);
rem=remDiv;if(rem.isZero())return digits +result;else{while (digits.length < 6)
digits= '0' +digits;
result= '' + digits +result;
}
}
};
也是sub之后拼出来的。也就是fromstring的反向操作。
protobufjs 命令执行_【原码笔记】-- protobuf.js 与 Long.js相关推荐
- 细说——命令执行_代码执行
目录 原理 命令执行漏洞原理 代码执行漏洞原理 命令执行与代码执行漏洞区别 命令执行&代码执行漏洞危害 命令执行无回显 代码执行函数 1- eval() 2- assert()-最好不要加上分 ...
- C语言_原码、补码、反码
什么是原码.反码.补码? 原码 - 把一个数根据正负直观翻译成二进制 方法:对于一个有符号数的二进制位,最左边是符号位,正数用0表示,负数用1表示,其它位为数值位. 例如: char a = -10; ...
- 一位原码的乘法规则_原码一位乘法与补码一位乘法
原码1位乘法 在定点计算机中,两个原码表示的数相乘的运算规则是:乘积的符号位由两数的符号按异或运算得到.而乘积的数值部分则是两个正数相乘之积.设n位被乘数和乘数用定点小数表示(定点整数也相同适用) 被 ...
- 原码的定义公式怎么理解_原码、反码、补码
一. 机器数和机器数的真值 在学习原码,反码和补码之前, 需要先了解机器数和真值的概念. 1.机器数 一个数在计算机中的二进制表示形式,叫做这个数的机器数.机器数是带符号的,在计算机用机器数的最高位存 ...
- 原码 反码 换算工具 补码_原码和补码的换算(原码反码补码转换工具)
[-3]反=[10000011]反=11111100 原码 反码 负数的补码是将其原码除符号位之. 两个说法都没有错,我们举个例子来看看就明白了:1.10001的补码是取反后在再加1,也就是11110 ...
- 原码 反码 换算工具 补码_原码/反码/补码在线计算器
原码/反码/补码计算器,在线计算给定整数的原码/反码/补码. 原码, 反码和补码的概念 对于一个数, 计算机要使用一定的编码方式进行存储. 原码, 反码, 补码是机器存储一个具体数字的编码方式. 原码 ...
- 原码 反码 换算工具 补码_原码,反码,补码相互转换在线计算器_三贝计算网_23bei.com...
本计算软件适用于10进制.16进制.2进制数值原码.反码.补码的计算. 输入已知数据变量.选择已知变量的类型(支持原码(10进制).原码(16进制).原码(2进制).反码(2进制).反码(16进制). ...
- protobufjs 命令执行_protobufjs简单使用
npm i protobufjs -D 添加两个proto文件 User.proto syntax = "proto3"; package login; message PBUse ...
- ctf xor题_从一道CTF题目谈PHP中的命令执行
原创 Xenny 合天智汇 快睡的时候,打开B站发现有位用户留言,大意就是让我帮忙看一道题,正好当时有空,于是就打开了他发的链接,代码如下 很明显是一道PHP代码审计的题目,而且只需要绕过第三行的if ...
最新文章
- Vue.js子组件向父组件通信
- (转)Cobbler无人值守批量安装Linux系统
- 华为平板wps语音朗读_打工人必备的手机端WPS小技巧
- 【Flink】Flink ClosureCleaner 闭包清除
- c语言小球消砖块增加一行砖块,基于Unity的小球撞击砖块小游戏
- TwinCAT 3 EL7211模块控制倍福伺服
- JVM垃圾回收机制(收集器、收集算法、卡表)
- php微信号授权登录失败,php 微信授权登录 40029错误
- vulnhub靶机-Pwned
- 【应用赏析】ArcGIS API for iOS在俄勒冈大学校园中的创新应用
- (2)QlikView安装
- 辐射76服务器位置,辐射76快速升级位置分享 前中期哪些位置好升级
- 如何解决win10语言栏消失变成空白问题
- 《黑匣子思维:我们如何更理性地犯错》iphone部分
- ROS系列:第六章 机器人建模
- 1135:配对碱基链
- 【强化学习】Actor-Critic算法详解
- Outlook邮件创建的规则失效,可能的原因
- s8站长交易论坛:我与我的威客经历
- Win10清除COM接口占用
热门文章
- SQLite3简单C++包装类源码示例
- 在Blender中创建真实的汽车CGI视觉动画效果
- 设计模式 之美 -- 工厂方法模式
- 哈希--直接定值法和除留取余法
- 函数返回类的对象与拷贝构造函数
- MySQL--从库启动复制报错1236
- python之路——模块和包
- [bzoj1042][HAOI2008]硬币购物
- github删除文件夹
- BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster( 后缀数组 + 二分 + RMQ + 树状数组 )