tostring

[代码审计]php反序列化漏洞

为君一笑 提交于 2019-12-01 02:40:32
0x01 php面向对象简介 对象:可以对其做事情的一些东西。一个对象有状态、行为和标识三种属性。 类:一个共享相同结构和行为的对象的集合。 每个类的定义都以关键字class开头,后面跟着类的名字。 一个类可以包含有属于自己的变量,变量(称为“属性”)以及函数(“称为方法”)。 类定义了一件事物的抽象特点。通常来说,类定义了事物的属性和它可以做到的。 类可能会包含一些特殊的函数叫magic函数,magic函数命名是以符号“_”开头的,比如_construct,_destruct,_toString,_sleep,_wakeup等。 这些函数在某些情况下会自动调用,比如:_construct当一个对象创建时调用(constructor);_destruct当一个对象被销毁时调用(destructor);_toString当一个对象被当作一个字符串时使用。 0x02 php对象概念及特性 我们先创建一个简单的php对象: <?php class TestClass { //一个变量 public $variable = 'This is a string'; //一个简单的方法 public function PrintVariable() { echo $this->variable; } } //创建一个对象 $object = new TestClass(); //调用一个方法

Why does String(null) work?

人走茶凉 提交于 2019-12-01 02:12:52
null and undefined don't have a toString or valueOf method. Afaik using String calls the toString method of its parameter (e.g. String({}) => [object Object] ). Why do String(null) or String(undefined work then? It doesn't implicitly do Object.prototype.toString.call(null) . because that evaluates to [object Null] . [edit]: from the spec ECMA-262/5th edition (page 48). This doesn't add to clarification, I'd say: /* Table 13 — ToString Conversions ------------------------------------------------------------------------- Argument Type | Result ----------------------------------------------------

Weaving in toString() implementation with AspectJ

心不动则不痛 提交于 2019-12-01 00:10:57
问题 Trying to weave in a default toString() method for a large number of DTOs, using compile-time weaving only. The goal is to return a JSON representation using the Jackson library. Followed the suggestions in this article, turned it into annotation-style aspect config, and ended up with the following code: public @Aspect class JsonToStringAspect { private interface JsonToString { public String toString(); } public static class JsonToStringImpl implements JsonToString { public String toString()

How to format a decimal without trailing zeros

送分小仙女□ 提交于 2019-11-30 23:47:29
问题 I've just learned that a decimal somehow remembers how much trailaing zero's were needed to store a number. With other words: it remembers the size of the fraction. For example: 123M.ToString() ==> resuls in: 123 123.00M.ToString() ==> resuls in: 123.00 123.450M.ToString() ==> resuls in: 123.450 I am looking for a formatting string or another trick to get rid of those "unneeded" trailing zeros, but keeping the significant digits. So: 123M.ToString() ==> resuls in: 123 123.00M.ToString() ==>

Read Registry_binary and convert to string

▼魔方 西西 提交于 2019-11-30 23:41:47
I have been searching for the last 2 hours, and I actualy just have been searching stupid. I am trying to read a Registry_binary Value and convert this to a string. I tried several things I've found online(includeing some stackoverflow posts), but seems I cannot get it work: class Class1 { RegistryKey RegKey; String keys; static void Main() { Class1 c=new Class1(); c.initialize(); } void initialize() { RegKey=Registry.LocalMachine.OpenSubKey("the location", true); var bytearray=Converter<RegKey.GetValue("key"), String[keys]>; Console.WriteLine(bytearray); System.Threading.Thread.Sleep(5000); }

Java: design interface to force implementations to override toString

左心房为你撑大大i 提交于 2019-11-30 22:26:54
问题 I'm developing an SPI and would like to define a Reportable interface such that any implementations must override toString() to something that is meaningful. Is there any way in Java to write an interface such that any of its concrete implementations must override Object's toString() ? For instance: public interface Reportable { public String toString(); } public class Widget implements Fizz, Buzz, Reportable { // ... @Override public String toString() { // ... } } I know the above code doesn

Printing F# discriminated union

孤者浪人 提交于 2019-11-30 20:16:21
I am writing a F# program which parses a string into a AST type which is a discriminated union. When I use fsi (on Mono + Mac OS X) to run my code, the AST is printed out in a nice format. But when I use printfn "%s" <| ast.ToString() I get something like FSI_0002.Absyn+clazz . Writing a ToString method for all the discriminated union types would be a big chore. How do I make the value print the way fsi does it? Have you tried printfn "%A" ast ? The %A specifier takes into consideration the StructuredFormatDisplayAttribute [MSDN] , if present. Kwang Yul Seo To convert a discriminated union

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

心已入冬 提交于 2019-11-30 17:19:15
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? The recommended way is to write toString manually (or generate by IDE) and hope that you don't have too many of such classes. The purpose of data class is to accommodate the most common cases of 85%, which leaves 15%

Join an array by a comma and a space

元气小坏坏 提交于 2019-11-30 17:10:57
I have an array that I want converted to a comma delimited string. Array.toString() works, but if I have a rather large array it won't wrap because there are no spaces after the commas: document.body.innerHTML = ['css','html','xhtml','html5','css3','javascript','jquery','lesscss','arrays','wordpress','facebook','fbml','table','.htaccess','php','c','.net','c#','java'].toString(); // css,html,xhtml,html5,css3,javascript,jquery,lesscss,arrays,wordpress,facebook,fbml,table,.htaccess,php,c,.net,c#,java How can I have spaces after the commas in order to allow line/word wrapping? Example output: css,

How to get floats value without including exponential notation

寵の児 提交于 2019-11-30 12:30:01
In C#, is it possible to perform ToString on a float and get the value without using exponentials? For example, consider the following: float dummy; dummy = 0.000006F; Console.WriteLine(dummy.ToString()); This gives the output 6E-06 However, what I was is 0.000006 The closest I could find was using the "F" qualifier, however I then need to specify the number of decimal places otherwise the value get rounded. Is there actually a way of doing this automatically or do I need to do a load of funky logic to either trim zeroes or figure out the number of required decimals. Thanks; Richard Moss Try