tostring

浅谈PHP反序列化漏洞原理

梦想与她 提交于 2019-11-30 03:02:23
序列化与反序列化 序列化用途:方便于对象在网络中的传输和存储 0x01 php反序列化漏洞 在PHP应用中,序列化和反序列化一般用做缓存,比如session缓存,cookie等。 常见的序列化格式: 二进制格式 字节数组 json字符串 xml字符串 序列化就是将对象转换为流,利于储存和传输的格式 反序列化与序列化相反,将流转换为对象 例如:json序列化、XML序列化、二进制序列化、SOAP序列化 而php的序列化和反序列化基本都围绕着 serialize() , unserialize() 这两个函数 php对象中常见的魔术方法 __construct() // 当一个对象创建时被调用, __destruct() // 当一个对象销毁时被调用, __toString() // 当一个对象被当作一个字符串被调用。 __wakeup() // 使用unserialize()会检查是否存在__wakeup()方法,如果存在则会先调用,预先准备对象需要的资源 __sleep() // 使用serialize()会检查是否存在__wakeup()方法,如果存在则会先调用,预先准备对象需要的资源 __destruct() // 对象被销毁时触发 __call() // 在对象上下文中调用不可访问的方法时触发 __callStatic() // 在静态上下文中调用不可访问的方法时触发 _

Checking session if empty or not

痞子三分冷 提交于 2019-11-30 03:00:41
I want to check that session is null or empty i.e. some thing like this: if(Session["emp_num"] != null) { if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } } Or just if(Session["emp_num"] != null) { // The code } because sometimes when i check only with: if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } I face the following exception: Null Reference exception Use this if the session variable emp_num will store a string: if (!string.IsNullOrEmpty(Session["emp_num"] as string)) { //The code } If it doesn't store a string, but some other type, you

How to force a sign when formatting an Int in c#

被刻印的时光 ゝ 提交于 2019-11-30 01:45:59
问题 I want to format an integer i ( -100 < i < 100 ), such that: -99 formats as "-99" 9 formats as "+09" -1 formats as "-01" 0 formats as "+00" i.ToString("00") is close but does not add the + sign when the int is positive. Is there any way to do this without explicit distinguishing between i >= 0 and i < 0 ? 回答1: Try this: i.ToString("+00;-00;+00"); When separated by a semicolon (;) the first section will apply to positive values and zero (0), the second section will apply to negative values,

Kotlin - generate toString() for a non-data class

元气小坏坏 提交于 2019-11-30 00:22:44
问题 Situation: I have a class with lateinit fields, so they are not present in the constructor: class ConfirmRequest() { lateinit var playerId: String } I'd like to have a toString() method with all fields and don't want to write it manually, to avoid boiler print. In Java I'd use the Lombok @ToString annotation for this problem. Question: Is there any way to implement it in Kotlin? 回答1: The recommended way is to write toString manually (or generate by IDE) and hope that you don't have too many

隐式调用 以及使用技巧

馋奶兔 提交于 2019-11-29 18:29:31
原文链接: https://www.jb51.net/article/134837.htm 数据类型转换 toSting 和 valueOf ? 1 2 3 4 5 6 7 8 9 10 11 12 13 var obj = { a: 1, toString: function () { console.log( 'toString' ) return '2' }, valueOf: function () { console.log( 'valueOf' ) return 3 } } console.log(obj == '2' ); //依次输出 'valueOf' false console.log(String(obj)); //依次输出 'toString' '2' ? 1 2 3 4 5 6 7 8 9 10 11 12 13 var obj = { a: 1, toString: function () { console.log( 'toString' ) return '2' }, valueOf: function () { console.log( 'valueOf' ) return {} //修改为对象 } } console.log(obj == '2' ); //依次输出 'valueOf' 'toString' true console.log

Lombok的用法

一个人想着一个人 提交于 2019-11-29 18:25:27
  Lombok是一款Java开发插件,使得Java开发者可以通过其定义的一些注解来消除业务工程中冗长和繁琐的代码,尤其对于简单的Java模型对象(POJO)。在开发环境中使用Lombok插件后,Java开发人员可以节省出重复构建,诸如hashCode和equals这样的方法以及各种业务对象模型的accessor和ToString等方法的大量时间。对于这些方法,它能够在编译源代码期间自动帮我们生成这些方法,并没有如反射那样降低程序的性能。  需要在IDEA中安装Lombok插件 maven项目 在 pom.xml中添加 依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> </dependency> @Data注解:在JavaBean或类JavaBean中使用,这个注解包含范围最广,它包含getter、setter、equals、canEqual、hashCode、toString 注解,即当使用当前注解时,会自动生成包含的所有方法; @getter注解:在JavaBean或类JavaBean中使用,使用此注解会生成对应的getter方法; @setter注解:在JavaBean或类JavaBean中使用

Generate Java Object from toString representation [duplicate]

醉酒当歌 提交于 2019-11-29 17:44:35
This question already has an answer here: Converting back from toString to Object 7 answers How to get back an object after performing .toString() on it? [duplicate] 4 answers We all know how to implement toString () method. It could be slightly custom implementation and different pattern how we print the object data. Using the generated toString , can we recreate the Object? I am not talking about Serialization here. Let me explain a scenario, You might have an application running happily in production and your log prints these objects when you received some request and doing some operations.

Javascript object get code as string

隐身守侯 提交于 2019-11-29 17:29:02
问题 First off, I am sorry if this is a duplicate, but every time I googled for 'object' and 'code' I got tutorial pages. I want to know if there is any easy way to get the code associated with an object. Something like function A(){ this.name = 'Kaiser Sauze'; } a = new A(); console.log(a.displayCode()); //OUTPUT "function A(){ this.name = 'Kaiser Sauze';}" I want to be able to view the code, modify it and reload the function, all from within the browser. I wanted to know if there was some way to

Naming(toString) Lambda-Expressions for Debugging purpose

回眸只為那壹抹淺笑 提交于 2019-11-29 17:28:43
Sometimes it is usefull to name lambdas. Especially when you pass them around as parameter. A realy simple example is public class Main { public static void main(String[] args) { Predicate<String> p = nameIt("isNotEmpty", (s) -> !s.trim().isEmpty()); maybePrint("Hello", p); maybePrint(" ", p); } static <T> void maybePrint(T s, Predicate<T> pred) { if (pred.test(s)) { System.out.println(s.toString()); } else { System.err.println(pred + " says no to \"" + s + "\""); } } } It would be nice to have some functionality by the jvm to name lambdas without loosing the great performance optimizations

Does StringBuilder become immutable after a call to ToString?

风流意气都作罢 提交于 2019-11-29 17:00:38
问题 I distinctly remember from the early days of .NET that calling ToString on a StringBuilder used to provide the new string object (to be returned) with the internal char buffer used by StringBuilder. This way if you constructed a huge string using StringBuilder, calling ToString didn't have to copy it. In doing that, the StringBuilder had to prevent any additional changes to the buffer, because it was now used by an immutable string. As a result the StringBuilder would switch to a "copy-on