2011-10-17 06:22:22 +08:00
|
|
|
|
/*
|
2015-10-30 05:45:26 +08:00
|
|
|
|
Copyright (C) 2011-2015 de4dot@gmail.com
|
2011-10-17 06:22:22 +08:00
|
|
|
|
|
|
|
|
|
This file is part of de4dot.
|
|
|
|
|
|
|
|
|
|
de4dot is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
de4dot is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace de4dot.blocks.cflow {
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public enum ValueType : byte {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
Unknown,
|
|
|
|
|
Null,
|
2012-08-04 18:02:40 +08:00
|
|
|
|
Object,
|
2011-10-17 06:22:22 +08:00
|
|
|
|
Boxed,
|
|
|
|
|
Int32,
|
|
|
|
|
Int64,
|
|
|
|
|
Real8,
|
|
|
|
|
String,
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public enum Bool3 {
|
2011-10-17 13:28:53 +08:00
|
|
|
|
Unknown = -1,
|
|
|
|
|
False,
|
|
|
|
|
True,
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public abstract class Value {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
public readonly ValueType valueType;
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsUnknown() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Unknown;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsNull() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsObject() {
|
2012-08-04 18:02:40 +08:00
|
|
|
|
return valueType == ValueType.Object;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsBoxed() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Boxed;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsInt32() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Int32;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsInt64() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Int64;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsReal8() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.Real8;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 20:03:57 +08:00
|
|
|
|
public bool IsString() {
|
2011-10-19 05:31:50 +08:00
|
|
|
|
return valueType == ValueType.String;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 06:22:22 +08:00
|
|
|
|
protected Value(ValueType valueType) {
|
|
|
|
|
this.valueType = valueType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public class UnknownValue : Value {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
public UnknownValue()
|
|
|
|
|
: base(ValueType.Unknown) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "<unknown>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-04 18:02:40 +08:00
|
|
|
|
public class ObjectValue : Value {
|
|
|
|
|
public readonly object obj; // can be null but that doesn't mean that this ObjectValue instance is null
|
|
|
|
|
|
|
|
|
|
public ObjectValue()
|
|
|
|
|
: this(null) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObjectValue(object obj)
|
|
|
|
|
: base(ValueType.Object) {
|
|
|
|
|
this.obj = obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "<non-null object>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public class NullValue : Value {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
// There's only one type of null
|
|
|
|
|
public static readonly NullValue Instance = new NullValue();
|
|
|
|
|
|
|
|
|
|
NullValue()
|
|
|
|
|
: base(ValueType.Null) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "null";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public class BoxedValue : Value {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
public readonly Value value;
|
|
|
|
|
|
|
|
|
|
public BoxedValue(Value value)
|
|
|
|
|
: base(ValueType.Boxed) {
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return string.Format("box({0})", value.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 20:17:33 +08:00
|
|
|
|
public class StringValue : Value {
|
2011-10-17 06:22:22 +08:00
|
|
|
|
public readonly string value;
|
|
|
|
|
|
|
|
|
|
public StringValue(string value)
|
|
|
|
|
: base(ValueType.String) {
|
|
|
|
|
this.value = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return string.Format("\"{0}\"", value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|