|
|
2004年7月6日
hoho,好爽啊~ Blog的访问量终于突破10K大关了.
从3月份申请这个Blog以来(即加入到博客园以来),发了不少的Blog(hoho,相对以前的我而言),认识了不少的牛人(Cow?bull?ox?).技术提高了不少.真是High啊:)
感谢dudu提供了这么好的Blog,这么快的访问速度..
嘿嘿..最后一句话,向第二个10K进军:)
在前一个文章 序列化对象 :)中,我提到了 在这里,我使用了序列化,因为序列化的一个好处就是可以还原原始的HashCode, 即,序列化前的对象的GetHashCode()的返回值和序列化后还原的GetHashCode()的返回值是一样的:)
但是,我今天刚刚试了一下,发现不是这样的..示例代码如下:
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;

namespace TestForMapfile_Write
  {
 /**//// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
 {
 /**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
 {
Console.WriteLine("please input p / c or x / y: ");
SharedMemory sm = new SharedMemory();
SharedMemory smClient;
SharedMemory smHT;
Client client;
object obj;
switch( Console.ReadLine())
 {
case "p":
case "P":
sm.Create( 10240,"Tiger");
client = new Client();
Console.WriteLine( client.GetHashCode());
client = new Client();
client.email = "tiger@msn.com";
client.id = 0;
client.name = "tiger";
sm.CopyFrom( Ser(client).ToArray());
Console.WriteLine( client.GetHashCode());
Console.WriteLine("ok");
Console.ReadLine();
break;
case "c":
case "C":
sm.Open( 10240,"Tiger");
MemoryStream ms = new MemoryStream( sm.CopyTo(0));
obj = Deser(ms);
Console.WriteLine( obj.GetHashCode());
Console.WriteLine("ok");
Console.ReadLine();
break;

case "x":
case "X":
smHT = new SharedMemory(10234,"smht");
smClient = new SharedMemory(10234,"smClient");
Hashtable ht = new Hashtable();
obj = new Client(1,"tiger","hh");
smClient.CopyFrom( Ser(obj).ToArray());
ht.Add( obj,1);
obj = new Client( 2,"unrule","unruldem");
smClient.CopyFrom( Ser(obj).ToArray());
ht.Add( obj,2);
smHT.CopyFrom( Ser(ht).ToArray());
Console.WriteLine("OK");
Console.ReadLine();
break;
case "y":
case "Y":
smHT = new SharedMemory();
smHT.Open(10234,"smht");
obj = Deser( new MemoryStream( smHT.CopyTo(0)));
smClient = new SharedMemory();
smClient.Open( 10234,"smClient");
object obj1 = Deser( new MemoryStream( smClient.CopyTo(0)));
 if( ((Hashtable)obj).ContainsKey( (Client)obj1)) {
Console.WriteLine("win");
}
 else {
Console.WriteLine("Fail");
}
 foreach( DictionaryEntry i in (Hashtable)obj) {
Console.WriteLine( ((Client)i.Key).id);
}
Console.ReadLine();
break;
}
}

 public static MemoryStream Ser(object obj) {
MemoryStream ms = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms,obj);
return ms;
}

 public static object Deser(MemoryStream ms) {
BinaryFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(ms);
}
}

[Serializable]
 class Client {
public int id;
public string name;
public string email;

 public Client() {}
 public Client(int ID,string Name,string Email) {
id = ID;
name = Name;
email = Email;
}
}
}
 注意:使用的时候加入前面的.NET中使用Mapping File 的API :)中提到了SharedMemory类 运行时分别运行两个,一个输入X,一个输入Y
这里,我把两个Client对象放到一个Hashtable中,再分别把这些个对象序列化,通过MappingFile传给另一个EXE程序. 再反序列化.结果,输出的是Fail,但是Hashtable中确实是有原始的Client对象..
结论: 通过这个例子,我发现,HashCode是和程序运行相关的,是相对于这个程序在当前运行期是唯一的. 所以了,我们如果想要把一个对象做为Hashtable中的Key同时把这个对象和这个Hashtable传给其它的应用程序(比如上面示例中的Client和Hashtalbe).请注意其对象的HashCode.:)
如果一定要传Hashtable过去.那么只要这个Hashtable的Key是.NET内置的数据类型,那照样可以正常使用:)
so,我前面文章中提到的那个结论(最上面有写)是错的.希望大家在使用中注意一下子.Have a good luck~
hoho,ROR终于开始招新了~
ROR is always interested in new talent...
http://61.153.51.35/forum/attach/2004/07/06/1040823-rorkgme1.zip
From nfo: This is the first Crackme of Team ROR. Try your best to make a keygen for it. No patch, no loader, keymaker only! If you crack it successfully and have interesting in ROR, please drop us a mail at rorteam@hotbox.ru, we will contact you.
from smth: dump ok vc7.0 sha1 found.... hacked upx.... music古香古色... 上面的那个水纹图像不错。 占用cpu so低。 ROR所出rls,一般都质量很好
Good news:)
Soff.net . Welcome back, we miss you :)
发信人: soff (凡事都在一念之间), 信区: NewSoftClub 标 题: 珊瑚虫论坛 发信站: BBS 水木清华站 (Tue Jul 6 12:14:11 2004), 站内
公网: http://soff.net/bbs 教育: http://edu.soff.net/bbs
-- 偶本 bt, 躬耕於 bit, 苟全性命於 bbs, 不求聞達於 mm... ____ ____ __ _____ ____ / __// __/ ____ ___ / /_ / ___// __ \ / /_ / /_ / __ \ / _ \ / __/ (__ )/ /_/ // __// __/ _ / / / // __// /_ /____/ \____//_/ /_/ (_)/_/ /_/ \___/ \__/ 珊瑚虫工作室[Coral Studio]
※ 来源:·BBS 水木清华站 smth.org·[FROM: 221.216.138.*]
|