mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
DotNET
DotNET

wpf DataGridComboBoxColumn的数据绑定

Intro If you haven't already, you can download the DataGrid v1 bits and source here.  DataGridComboBoxColumn has had a make-over since the CTP release.  In particular, the whole data binding story has been updated so that you can accomplish basic ComboBox tasks that before required some tedious workarounds.  While other stock columns such as DataGridTextColumn and DataGridCheckBoxColumn use Binding for the visual to data hook up, DataGridComboBoxColumn uses a different route with three possible ways to hook up a binding.  Here are the APIs that are specific to the DataGridComboBoxColumn: public class DataGridComboBoxColumn : DataGridColumn {   public string DisplayMemberPath { get; set; }   public IEnumerable ItemsSource { get; set; }   public virtual BindingBase SelectedItemBinding { get; set; }   public virtual BindingBase SelectedValueBinding { get; set; }   public string SelectedValuePath { get; set; }        public virtual BindingBase TextBinding { get; set; } }   The three mechanisms to hook up the binding are: ·         SelectedItemBinding ·         SelectedValueBinding ·         TextBinding These three bindings basically map to the cell’s content being bound to ComboBox.SelectedItem, ComboBox.SelectedValue, or ComboBox.Text respectively.  SelectedValuePath and DisplayMemberPath are convenience methods on a ComboBox control and apply to ComboBox.SelectedValuePath and ComboBox.DisplayMemberBinding respectively.  Overall, you can think of these APIs as convenience methods that apply to the ComboBox element of the cell.  Let’s go through some use cases. Some examples When the column is bound to a primitive data type such as int, string, or bool, and you want the ComboBox to have a list of similar items to choose from, you can use SelectedItemBinding…

2009-03-30 0comments 111hotness 0likes mikebai Read all
DotNET

[原创]小白单词本

2009-03-29 0comments 117hotness 0likes mikebai Read all
DotNET

C#获取当前路径的方法集合

//获取当前进程的完整路径,包含文件名(进程名)。 string str = this.GetType().Assembly.Location; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。 string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。 string str = System.Environment.CurrentDirectory; result: X:\xxx\xxx (.exe文件所在的目录) //获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。 string str = System.AppDomain.CurrentDomain.BaseDirectory; result: X:\xxx\xxx\ (.exe文件所在的目录+"\") //获取和设置包含该应用程序的目录的名称。 string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; result: X:\xxx\xxx\ (.exe文件所在的目录+"\") //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。 string str = System.Windows.Forms.Application.StartupPath; result: X:\xxx\xxx (.exe文件所在的目录) //获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。 string str = System.Windows.Forms.Application.ExecutablePath; result: X:\xxx\xxx\xxx.exe (.exe文件所在的目录+.exe文件名) //获取应用程序的当前工作目录(不可靠)。 string str = System.IO.Directory.GetCurrentDirectory(); result: X:\xxx\xxx (.exe文件所在的目录)

2009-03-29 0comments 101hotness 0likes mikebai Read all
DotNET

WPF中的URI

from msdn:http://msdn.microsoft.com/zh-cn/library/aa970069.aspx 文件  绝对 pack URI   资源文件 — 本地程序集  Uri uri = new Uri("pack://application:,,,/ResourceFile.xaml", UriKind.Absolute);   子文件夹中的资源文件 — 本地程序集  Uri uri = new Uri("pack://application:,,,/Subfolder/ResourceFile.xaml", UriKind.Absolute);   资源文件 — 所引用的程序集  Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml", UriKind.Absolute);   所引用的程序集的子文件夹中的资源文件  Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml", UriKind.Absolute);   所引用的版本化程序集中的资源文件  Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;v1.0.0.0;component/ResourceFile.xaml", UriKind.Absolute);   内容文件  Uri uri = new Uri("pack://application:,,,/ContentFile.xaml", UriKind.Absolute);   子文件夹中的内容文件  Uri uri = new Uri("pack://application:,,,/Subfolder/ContentFile.xaml", UriKind.Absolute);   源站点文件  Uri uri = new Uri("pack://siteoforigin:,,,/SOOFile.xaml", UriKind.Absolute);   子文件夹中的源站点文件  Uri uri = new Uri("pack://siteoforigin:,,,/Subfolder/SOOFile.xaml", UriKind.Absolute);   文件  相对 pack URI   资源文件 — 本地程序集  Uri uri = new Uri("/ResourceFile.xaml", UriKind.Relative);   子文件夹中的资源文件 — 本地程序集  Uri uri = new Uri("/Subfolder/ResourceFile.xaml", UriKind.Relative);   资源文件 — 所引用的程序集  Uri uri = new Uri("/ReferencedAssembly;component/ResourceFile.xaml", UriKind.Relative);   子文件夹中的资源文件 — 所引用的程序集  Uri uri = new Uri("/ReferencedAssembly;component/Subfolder/ResourceFile.xaml", UriKind.Relative);   内容文件  Uri uri = new Uri("/ContentFile.xaml", UriKind.Relative);   子文件夹中的内容文件  Uri uri = new Uri("/Subfolder/ContentFile.xaml", UriKind.Relative);    

2009-03-28 0comments 99hotness 0likes mikebai Read all
DotNET

UTF8 转 UNICODE

XML文件可以采用多种编码,但是经过不同的编码后对于中文会出现乱码问题,比如“骞垮憡涓戦椈”,对于此问题的解决如下:      static void Main()      {         string utf8String = "骞垮憡涓戦椈";         // Create two different encodings.         Encoding utf8= Encoding.UTF8;         Encoding defaultCode= Encoding.Default;         // Convert the string into a byte[].         byte[] utf8Bytes = default.GetBytes(utf8String );         // Perform the conversion from one encoding to the other.         byte[] defaultBytes = Encoding.Convert(utf8, defaultCode, utf8Bytes );                     // Convert the new byte[] into a char[] and then into a string.         // This is a slightly different approach to converting to illustrate         // the use of GetCharCount/GetChars.         char[] defaultChars = new char[defaultCode.GetCharCount(defaultBytes , 0, defaultBytes .Length)];         defaultCode.GetChars(defaultBytes , 0, defaultBytes .Length, defaultChars , 0);         string defaultString = new string(defaultChars );         // Display the strings created before and after the conversion.         Console.WriteLine("Original string: {0}", utf8String);         Console.WriteLine("Ascii converted string: {0}", defaultString);//或者如下:         byte[] buffer1 = Encoding.Default.GetBytes(utf8String );         byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);         string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);      }

2007-11-14 0comments 110hotness 0likes mikebai Read all
DotNET

常用SQL时间格式

SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm   例如:  select getdate()  06:08.2  这对于在要不同数据库间转移数据或者习惯oracle日期格式YYYY-MM-DD HH24:MI:SS的人多少有些不方便.  我整理了一下SQL Server里面可能经常会用到的日期格式转换方法:  举例如下:  select CONVERT(varchar, getdate(), 120 ) 2004/9/12 11:06  select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','') 2.00409E+13  select CONVERT(varchar(12) , getdate(), 111 ) 2004/9/12  select CONVERT(varchar(12) , getdate(), 112 ) 20040912  select CONVERT(varchar(12) , getdate(), 102 ) 2004.09.12  其它我不常用的日期格式转换方法:  select CONVERT(varchar(12) , getdate(), 101 ) 09/12/2004  select CONVERT(varchar(12) , getdate(), 103 ) 12/09/2004  select CONVERT(varchar(12) , getdate(), 104 ) 12.09.2004  select CONVERT(varchar(12) , getdate(), 105 ) 12-09-2004  select CONVERT(varchar(12) , getdate(), 106 ) 12 09 2004  select CONVERT(varchar(12) , getdate(), 107 ) 09 12, 2004  select CONVERT(varchar(12) , getdate(), 108 ) 11:06:08  select CONVERT(varchar(12) , getdate(), 109 ) 09 12 2004 1  select CONVERT(varchar(12) , getdate(), 110 ) 09-12-2004  select CONVERT(varchar(12) , getdate(), 113 ) 12 09 2004 1  select CONVERT(varchar(12) , getdate(), 114 ) 06:08.2  更多的及具体说明请参考SQL Server的联机丛书.

2007-11-05 0comments 115hotness 0likes mikebai Read all
DotNET

[转载]由浅至深 谈谈.NET混淆原理

Posted by huboy on 2006, 09 23, 1:07 PM. Filed in .NET(C#)这几天,工作特别忙,没空抽出时间来写文章,粗糙之作,还请见谅。 1.名称混淆 - 反混淆 名称混淆返混淆,基本上是不太可能的事,因为以前的名称已经换掉了,也没有第二个名称备份表,所以根本无法还换。不过,可以把不可见字符转换为可见字符,长字符串换成短字符串。有两种方法可以做处理:      1.   在MetaData中有一个区域叫做 _STRING 它存放了所有名称字符串,只要修改这里的内容,即可,此方法需要对元数据结构特别熟悉      2.   如果你对元数据不了解,没关系,你可以用ILDasm把混淆后的程序集反编译,然后一个一个的对应改过来,再用ilAsm编译,一样可以达到反混淆的作用。其实,对名于名称来说,真的没有多大用处,不用反混淆也行,免得浪费自己的时间。2.流程混淆 - 反混淆流程混淆,在上面已经给出例子。它才是有用的一种混淆方式。它改变流程的存放序顺,从而达到静态反编译的功能。(名称混淆还是可以反编译)不过,不管怎样,他没有办法去阻止读取IL,这就是流程混淆的天生不足。我们来看看如何对流程反混淆吧。还是以上面的例子进行操作。首先特别说明一下: br.s 行号 br 行号 都是强行跳转指令,而流程混淆主要是得用这样的语句进行逻辑连接的。所以,我们就需要对照着被混淆过的代码,跟着一句一句的逻辑关系,把语句拉出来重新组合。组合出来后,代码如下:       L_0000: newobj instance void [mscorlib]System.Random::.ctor()      L_0005: stloc.1       L_0006: ldstr ""      L_0021: stloc.2       L_0022: ldc.i4.0       L_0023: stloc.0       L_0024: br.s L_0032      L_0026: ldloc.2       L_0027: ldarg.1       L_0028: ldloc.1       L_0029: callvirt instance float64 [mscorlib]System.Random      ::NextDouble()      L_002e: ldarg.2       L_002f: conv.r8  L_000d: mul       L_000e: conv.i4       L_000f: ldelem.u2       L_0010: box char      L_0015: call string string::Concat(object, object)      L_001a: stloc.2       L_001b: ldloc.0       L_001c: ldc.i4.1       L_001d: add       L_001e: stloc.0       L_0032: ldloc.0       L_0033: ldarg.3       L_0034: ble.s L_0026      L_0036: ldloc.2       L_0037: ret   其实,反流程混淆也相当的容易,只要按照执行流程加入特定的条件即可以得到代码的序顺。 为此,我特别写了一个反流程混淆的工具(Deflow)。将上面的代码反混淆后,得到如下代码:      L_0000: newobj instance void [mscorlib]System.Random::.ctor()      L_0001: stloc.1       L_0002: ldstr ""      L_0003: stloc.2       L_0004: ldc.i4.0       L_0005: stloc.0       L_0006: br.s L_0017      L_0007: ldloc.2       L_0008: ldarg.1       L_0009: ldloc.1       L_000A: callvirt instance float64 [mscorlib]System.Random::NextDouble()      L_000B: ldarg.2       L_000C: conv.r8       L_000D: mul       L_000E: conv.i4       L_000F: ldelem.u2       L_0010: box char      L_0011: call string string::Concat(object, object)      L_0012: stloc.2       L_0013: ldloc.0       L_0014: ldc.i4.1       L_0015: add       L_0016: stloc.0       L_0017: ldloc.0       L_0018: ldarg.3       L_0019: ble.s L_0007      L_001A: ldloc.2 L_001B: re

2007-10-30 0comments 118hotness 0likes mikebai Read all
DotNET

[转载]揭开.NET程序保护的秘密

.NET程序保护主要有如下几种形式1.  混淆2.  编译到本地代码3.  把代码隐藏在资源中1.  混淆这部分的保护软件以Dotfuscator和XenoCode为代表。Dotfuscator是比较初级的混淆器,采取的主要策略是名字混淆,通过把类名、方法名、变量名改成很短的形式,目的是破坏有意义的变量命名。WebCombo.NET 2.0,采用Dotfuscator进行变量名混淆名字混淆的缺点在于a. 名字长度虽短,但是依然容易进行代码分析。对于熟悉汇编语言的逆向工程师,改成短的变量名对阅读代码基本不存在任何难度。b. 在应用反射(Reflector)机制的程序中不能很好的工作。XenoCode是稍微高级的混淆器,它采用的技术除了变量名字混淆外,还加入流程混淆。目的是阻止.NET Reflector对其直接进行反编译。大部分采用了混淆器的.NET软件都是使用该混淆器进行保护。 尽管.NET Reflector不能直接反编译为c#,但是我们在语言栏把它切换到IL,依然可以看到中间语言 .NET Reflector之所以不能反编译,是因为XenoCode把中间语言拆成若干段,每段用br或者br.s(相当于jmp)衔接起来。至于为什么.NET Reflector不会解释成goto,我也不太清楚,估计是因为与一条完整的C#语句等价的IL程序段被拆开两半。(哪位大侠知道请指教一下)。反混淆的方法也非常直接,把代码段重新排序就可以了,反混淆的结果如图 用ida pro分析的流程图,未进行反混淆处理前: 反混淆处理后:  对一个几M甚至几十M的il源文件进行反混淆不是一件轻松的事情,因此写了一个用于重新排序的小程序,正式做法类似编译原理的语句优化步骤,先把每个method分块,每个块的第一个语句是入口点,最后一个语句必须是无条件的控制转移语句(br、leave、ret等)。然后把转跳点合并。这里遇到一个问题,遇到入口被method内部多处引用时,只能随机选择一个。因此部分函数还需要人手调整。但毕竟顺序结构还是占绝大多数,所以人手调整的比例还是很少的。我在转换一个几百个类的dll时,需要调整的类也只有10多个,是可以接受的。显然,如果在有辅助工具的帮助下,XenoCode流程混淆下的程序也不难做到反混淆。加上Reflector的FileDisassembler插件,完全可以把整个assembly的源码导出到本地目录下,再用IDE环境把项目源码导入后进行分析。2.编译到本地代码保护软件以RemoteSoft Protector为代表,应用该保护方法的软件较少,因为正版的RemoteSoft Protector需要几千美金。其中代表软件为WebGrid.NET 3.5。在发布的dll里面包括.NET assembly以及一个名为rscoree.dll的一般Win32 PE文件。查看rscoree.dll可以发现导出表仅有_RSDllMain, _RSEEStartup, _RSEEUpdate, _RSExeMain四项,用Ollydbg打开发现并没加密。用Reflector打开.NET assembly,无论是用C#语言查看还是直接查看IL,所有method都只看到空的函数体。只有发现<PrivateImplementationDetails>中存在对rscoree.dll的引用信息。.class private auto ansi <PrivateImplementationDetails>      extends object{      .method assembly hidebysig static void $$method-1() cil managed noinlining      {      }      .method assembly hidebysig static void $$method-2() cil managed noinlining      {      }      .method private static pinvokeimpl("rscoree.dll" ansi nomangle) void _RSEEStartup(int32 A_0) cil forwardref managed      {      }      .method private static pinvokeimpl("rscoree.dll" ansi nomangle) void _RSEEUpdate(native int A_0) cil forwardref managed      {      }      .field private static bool $$started-1      .field private static bool $$started-2}另外听说有一款国产的保护软件MaxtoCode,分普及版和专业版,普及版可以免费使用。看软件的介绍信息疑也是采用类似技术。缺点是代码编译成了naïve code,所以只能在windows平台运行。逆向人员需要同时懂得.NET虚拟机的知识和Win32汇编,要求较高。3.这是一种很另类的保护方法(也许是我孤陋寡闻),目前只知道Reflector本身是采用这种方法来保护自身的核心代码库。暂时还没时间去研究具体的实现方法。

2007-10-29 0comments 108hotness 0likes mikebai Read all
DotNET

精妙SQL语句收集

一、基础1、说明:创建数据库Create DATABASE database-name2、说明:删除数据库drop database dbname3、说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'--- 开始 备份BACKUP DATABASE pubs TO testBack4、说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)根据已有的表创建新表:A:create table tab_new like tab_old (使用旧表创建新表)B:create table tab_new as select col1,col2… from tab_old definition only5、说明:删除新表drop table tabname6、说明:增加一个列Alter table tabname add column col type注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。7、说明:添加主键: Alter table tabname add primary key(col)说明:删除主键: Alter table tabname drop primary key(col)8、说明:创建索引:create [unique] index idxname on tabname(col….)删除索引:drop index idxname注:索引是不可更改的,想更改必须删除重新建。9、说明:创建视图:create view viewname as select statement删除视图:drop view viewname10、说明:几个简单的基本的sql语句选择:select * from table1 where 范围插入:insert into table1(field1,field2) values(value1,value2)删除:delete from table1 where 范围更新:update table1 set field1=value1 where 范围查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!排序:select * from table1 order by field1,field2 [desc]总数:select count as totalcount from table1求和:select sum(field1) as sumvalue from table1平均:select avg(field1) as avgvalue from table1最大:select max(field1) as maxvalue from table1最小:select min(field1) as minvalue from table111、说明:几个高级查询运算词A: UNION 运算符UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。当 ALL 随 UNION 一起使用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 就是来自 TABLE2。B: EXCEPT 运算符EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。C: INTERSECT 运算符INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。注:使用运算词的几个查询结果行必须是一致的。12、说明:使用外连接A、left outer join:左外连接(左连接):结果集几包括连接表的匹配行,也包括左连接表的所有行。SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.cB:right outer join:右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。C:full outer join:全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。二、提升1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)法一:select * into b from a where 1<>1法二:select top 0 * into b from a2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)insert into b(a, b, c) select d,e,f from b;3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..4、说明:子查询(表名1:a 表名2:b)select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a…

2007-10-22 0comments 112hotness 0likes mikebai Read all
DotNET

.net开发常用工具

      ildasm:反编译.net程序;      ilasm:编译il代码;      Reflector:查看.net程序源码、程序集间的依赖关系;      Xenocode Fox 2007:由.net程序生成.net工程;      PEBrowseDbg:动态调试.net程序;      WinDbg,OlleyDbg:调试分析程序;      MASMPlus:查看编写编译汇编代码;      DebugTrack:跟踪程序调试信息;      eXeScope,PE Explorer:查看PE文件,修改程序资源;      Code Smith:代码生成;      Dis#:.net流程反混淆工具;      CFF Explorer:.net PE文件查看器;      CLRProfiler:.net分析工具;      DNGRuard1.0:.net程序集加密工具;      keymake:注册机,内存补丁;      Stud_PE:查看、学习PE文件;      IEDevToolBar:查看IE各标签属性;      WatiN:Web项目自动化测试;      antlr:解释器生成器;      injectReflector:查看.net内存中IL代码;      PEID:辨别程序开发语言;      Log Explorer for SQL Serverv:SQL Server恢复误删数据;      SnippetCompiler:简单代码编译;      UltraEdit、EditPlus、NotePad:文本编辑、查看;      RegExTool:正则表达式测试;      Beyond Compare:文本比较。

2007-09-02 0comments 117hotness 0likes mikebai Read all
1…1213141516

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang