May 2008 - Posts

How to protect your Intellectual Property or some words about next generation obfuscation

Not once customers asking me about protecting their IP (not address). The regular answer was “obfuscation”. You want more, then this? Use third party unmanaged hash providers (such as RemoteSoft, which is the best so far). However it not enough. the best we can do is to provide sensitive code as remote service. The only way to “hack” such protection is by hacking remote server, which is much more complex mission, in comparison to hacking managed or even native code.

image
© Don Farrall

For a long time Microsoft has no ultimate answer to IP issues of managed code. Sun experienced the same problems with Java. what to do? The answer is to provide comprehensive solution for server side code encoding. This is exactly what was done in Microsoft Software Licensing and Protection Services. This is not free, however it can provide you with comprehensive solution for IP protection, licence management and secure software distribution.

After applying to this service, your code will looks like this

return SLMRuntime.SVMesecMethod(a);

Where SVMesecMethod is server side method, rather then

return MyEncriptor.DecodeString(a);
string DecodeString(string a) {
for ( long offset = 0; offset < a.Length ; offset++ )
                {
                    i = ( i + 1 ) % a.Length ;
                    j = ( j + a[i] ) %  a.Length ;
                    byte temp =  a[i];
                    a[i] = a[j];
                    a[j] = temp;
                    byte a = a[offset];
                    byte b = a[(a[i]+a[j])% a.Length ];
                    a[offset] = (byte)((int)a^(int)b);   
                }   
}

Where DecodeString is maybe complicated (this code actually does not work), but easy reflected source.

SLP service is not new approach. It widely used by different companies to protect their software. Also it’s very common way to distribute Smart Client applications. However this is first time Microsoft provides such service widely for ISVs.

You can request evaluation of this service today, by visiting SLP website.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Quick Silverlight tip: How to open new window or tab by using HyperlinkButton and Ctrl-Shift modifiers

Regular behavior of any HTML anchor element is to open new Window if you’re clicking the link with Shift key and new Tab, if you’re clicking with Ctrl key or middle mouse button. Unfortunately, Silverlight HyperlinkButton does not support opening new window or tab. It also does not support key modifiers. What to do?

image
(rotary reading desk – first tabbed browser, invented in 1588. via Athanasius Kircher society)

First of all, request this feature. This is regular behavior and there is no reason not to support it in Silverlight. Next, we should do something to fix it by now. So let’s start.

We should understand what happens under the hoods of HyperlinkButton. It does not generate html anchor, however it uses window.navigate to move. One of HyperlinkButton properties is TargetName – this one is actually html ”target” attribute. So we can just change it according the keystrokes. This is acceptable, but ugly solution. The better one is to subclass HyperlinkButton and check KeyModifiers. Then void Click event and navigate

if(Keyboard.Modifiers == ModifierKeys.Control | Keyboard.Modifiers == ModifierKeys.Shift)
            {
                this.TargetName=”_blank”;
            }
            base.OnClick();

So far so good, but not good enough. What will happen if user explicitly set TargetName Value? We’ll override it and this is something we wont to do. Also, following approach will work differently between browsers. For example in IE it will open new window, while in FF – new tab by default. So how to avoid it?

We can use HtmlPage.Window.Navigate method to assure opening of new window. Navigate method receives three parameter, Uri for navigation address, target frame and “target features”. What are those target features? Actually, it parameters we’re using in JavaScript for window.open method. Thus HtmlPage.Window.Navigate(new Uri(“http://blogs.microsoft.co.il/blogs/tamir”,null,”menubar=1,resizable=1,width=350,height=250”) will open resizable window with menubar and size of 350x250.

Very well. Now we almost finished, but how to assure, that I opened new tab? Actually, we cannot until all browsers will support CSS3. In CSS3 we have style attributes, which can target into tab or window. By now, the only workaround is to use IWebBrowser2::Navigate2 method for IE and pass 0x1000 (navOpenInBackgroundTab) as second parameter. This “heck” can only be done in Full trust mode. For Mozilla (FireFox or any Geco + ancestors) we should use nsIBrowserWindow::OPEN_NEWTAB override for nsIBrowserWindow::OPEN_NEWWINDOW. There is no known way to do it for Safari.

So, the best thing can be done is inheritance of build-in feature of any supported browser to handle Ctrl/Shift modifiers for force opening links in other tabs or new windows.

Have a nice week and be good people.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Brightness and contrast manipulation in WPF 3.5 SP1

While being in flight, I had to learn new features, introduced in .NET 3.5 SP1. So, let’s start from image manipulation. I want to perform contrast and brightness manipulation in GPU over displayed image. In order to begin, you should download and install .NET 3.5 SP1 and Visual Studio 2008 SP1. Meanwhile (it’s about 500 MB of download) we’ll learn how to write custom shader effect.

image

In order to build custom Shader Effer, we have to use HLSL (High Level Shading Language). This is programming language, introduces in DirectX 9.0 and supports the shader construction with C-like syntax, types, expressions and functions. If you know C – it will be very easy for you to learn it.

What is shader? Shader is consists of vertex shader and pixel shader. Any 3D model flows from application to the vertex shader, then pixel shader frames buffer. So we’ll try from simple matrix transformation. First we should build the struct of the position. It is float4 type and has POSITION inheritance. Also we have to get matrix, which is regular float4x4 object. Then all we have to to is to translate inpos by matrix and return new position. That’s exactly what following code does.

float4 main(float4 inpos : POSITION, uniform float4x4 ModelViewMatrix) : POSITION
  {
     return mul(inpos, ModelViewMatrix);
  }

So by using HLSL we can play freely with vertexes, but what’s happen with pixel shader? This works exactly the same way. We have pixel, which is TEXCOORD in input and COLOR in output. So, here it comes

float4 main(float2 uv : TEXCOORD, float brightness, float contrast) : COLOR
{
    float4 color = tex2D(input, uv); 
    return (color + brightness) * (1.0+contrast)/1.0;
}

For more information about HLSL, please visit MSDN. As for us, we already have our shader effect and how we have to compile it into executable filter. In order to do it, we’ll use directx shader effect compiler. Let’s say, that we have our source in effect.txt file and our output file will be effect.ps. Small tip insert following line into pre-build event, and have your shader effect script ready and up-to-day with each compilation.

fxc /T ps_2_0 /E main /Fo"$(ProjectDir)effect.ps" "$(ProjectDir)effect.txt"

Mode information about FX compiler command switches, can be found here. How we should actually wrap our effect in manage code. But wait. We have to pass parameters into shader effect. How to register external parameters within FX file? Simple. Exactly as input params. Note, the tag inside register method will actually be used within our managed wrapper.

sampler2D input : register(s0);
float brightness : register(c0);
float contrast : register(c1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(input, uv);
    float4 result = color;
    result = color + brightness;
    result = result * (1.0+contrast)/1.0;
    return result;
}

Well done.  Let’s build wrapper. Of cause you should inherit from ShaderEffect object and register your input param

public class BrightContrastEffect : ShaderEffect
    {

public Brush Input
        {
            get { return (Brush)GetValue(InputProperty); }
            set { SetValue(InputProperty, value); }
        }

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BrightContrastEffect), 0);

Then load pixel shader from application resources (you should compile ps file as “Resource”)

private static PixelShader m_shader = new PixelShader() { UriSource = new Uri(@"pack://application:,,,/CustomPixelRender;component/bricon.ps") };

Then parameters (they are regular dependency objects) with additional special PixelShaderConstantCallback, that received the numeric id of registered properties from pixel shader effect.

public float Brightness
        {
            get { return (float)GetValue(BrightnessProperty); }
            set { SetValue(BrightnessProperty, value); }
        }

        public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0)));

        public float Contrast
        {
            get { return (float)GetValue(ContrastProperty); }
            set { SetValue(ContrastProperty, value); }
        }

A couple of updates and we done with code behind.

public BrightContrastEffect()
        {
            PixelShader = m_shader;
            UpdateShaderValue(InputProperty);
            UpdateShaderValue(BrightnessProperty);
            UpdateShaderValue(ContrastProperty);

        }

Next step is XAML. Each UI element in .NET 3.5 SP1 got new property, named Effect, that designed to hold your custom shader effects (exactly as it was with transformations in 3.0 and 3.5). I want to perform a transformation over image.

<Image Source="img.jpg">
           <Image.Effect>
               <l:BrightContrastEffect

Now we should build two sliders to manage brightness and contrast level

<UniformGrid Grid.Row="1">
           <TextBlock Text="Brightness"/>
           <Slider Maximum="1" Minimum="-1" Name="bVal"/>
           <TextBlock Text="Contrast"/>
           <Slider Maximum="1" Minimum="-1" Name="cVal"/>
       </UniformGrid>

And bind to its values from our pixel shader effect

<Image Source="img.jpg">
            <Image.Effect>
                <l:BrightContrastEffect
                    Brightness="{Binding ElementName=bVal, Path=Value}"
                    Contrast="{Binding ElementName=cVal, Path=Value}"/>
            </Image.Effect>
        </Image>

That’s all, folks. Please note, that everything, done with shader effects, done in GPU. Also, the effect applies on rendered object (you can set the same effect not only to image, but to any UIElement in your system. Thus from performance point of view it’s the best method to work with your output. Let’s take for example very big image (3000x3000 pixels), rendered with low quality to 300x300 size. Perform per-pixel transformation (what we done here) will take 300X300Xdpi loops. While if you’ll perform the same operating over source image or memory section, used to create it, you’ll have to do 3000x3000xdpi loops, which is x10^2 more times.

Have a nice day and be good people.

Source code for this article.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Action required: Smart client users group

Recently I browsed INETA to seek for some group and was really surprising. There is no Smart Client user group registered there. Maybe there is a reason? Let’s understand what Smart Client is?

According wikipedia, the term "Smart Client" is meant to refer to simultaneously capturing the benefits of a "thin client" (zero-install, auto-update) and a "fat client" (high performance, high productivity). However, I think, that this term is much wider. It is not only thin-fat client application, it’s also most of applications we’re using today.

image

Thick Client

We always want to provide our users with best experience and increase their performance. However we are (as developers) want to avoid complicated development and deployment. This why we should know as much as possible about user’s system, when users do not want to have real footprint in their systems. That’s dilemma. Is it possible to solve it? Let’s look deeper…

Are we really need installation? Most of old software installations put things in registry. It because you were never sure what client has in his system and were our application can put files or temporary data. Today, when we have local application or user isolated storage, so we not really need to use registry. Maybe only for our own ego – this is cool to have something like “HKLM/Software/MYNAME” in 1,000,000 user’s computers…

No installation is good, but what to me with maintenance. We want our system connected…

Thin Client

Could you imagine your user to visit product site twice a week to see what’s going on? I can not. However I know, that if I’ll ask him first about automatic updates and he’ll agree to forget about application maintenance, his experience will be much better.

So,we are connected. What now? I want to make time reporting system. Web service? Maybe some kind of distributed application. Maybe, even Twitter? This way we can be sure, that our data is safe and if user reinstall whole system, he do not really need to care about backups.

But users not always have internet access. Sometimes they are offline. How to solve the problem of occasionally connected users? I do not want him every lunch want for two minutes, until I realize, that there is no internet connection and will not even give him a chance to use the application?

image

So, we also want our system to be useful offline. But what’s up with Web 10.0? We want millions. We want very broad reach for our application. Also we want to be able to manage application updates remotely?

Let’s take a look into other pan of application development. Do you like JavaScript? I do not! I think it’s too complicated to develop things for web. We should invest into at least 50% of coverage and integration tests, while giving customers pretty poor user experience. What is we want to provide the same look and feel everywhere? In web, desktop, mobile and other devices? Our customers want the application everywhere?

Summary

This is exactly what Smart client designed for. Technologies such as .NET, WPF, Silverlight from Microsoft, Flex, Thermo from Adobe and others tries to make you to be there with your application. But how to do it? How to answer all those hard questions, I asked?

I want to announce new (currently virtual) user group, dedicated to Smart Client development. I do not want to restrict this group geographically, due to fact, that current infrastructures allows us to forget about distances and be together. Join today “Smart Client development” user group.

In order to join, just send me an email to tamir [at] khason.biz with information about you. I put the request to create this user group in INETA. Once it will be opened, I’ll send everyone email to register and connect them selves to this group.

Be in touch.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
New Microsoft R&D center in Israel

Just come back from new Microsoft R&D center house warming. Got some photos and  (how not?) some comments. Steve Ballmer (CEO of Microsoft), Shimon Peres (the President of Israel), Moshe Lichtman (local R&D center corporate VP) and Danny Yamin (local Microsoft subsidiary GM) were here.

The event begun from short introduction of Moshe and Steve about the importance of local R&D and it’s size relative to country (we’re second place in the world with 0.015% of Microsofties per total country population). Yu-hu we’re on map!

DSC08454

Then journalists begun to ask questions. Of cause the first question was Yahoo or not and the answer was “not”

DSC08446

Then, there were two Hebrew localization questions (one about XBOX [just in case Steve saw the money there] and another about Windows Mobile). Both remains actually unanswered with doubtful remark of Danny (Yamin) about timelines of some day in the future. I heard the same answer before. About a year ago, but in practice nothing happed yet.

Side note: Silverlight will not support RTL neither in this nor in next version.

I asked Steve about legacy code of Microsoft. Actually, I, personally, think, that walking dead MSN, crappy Explore.exe (Windows shell) and “always-single-user-ever” Office is bad legacy, that prevent Microsoft from being really responsive and innovative company. He (Ballmer) wants to beat Web? He just have to kill MSN and do it.

However, his response was, that Microsoft loves its legacy and this why Microsoft so powerful. I agree with him, but Microsoft is strong in user’s desktop, not in the web. So with this agenda has not many chances to win there. One day they’ll see themselves hugging with Office COM objects, when the industry movers uses online rich client alternatives.

I believe, that Moshe (Lichtman). Got the point, thus he has absolutely Microsoft independent research center, that looking for innovative not through legacy prism. However, who knows…

DSC08449

Then we moved to central event with Shimon (Peres), Steve (Ballmer) and others. Another short “what was done” by Moshe and we moved toward Shimon.

DSC08478

This was the most impressive speech all over the event. He was able to switch (as always) people attention to “peace all over the world” instead of “thanks Microsoft for investment in Israel”.

DSC08495

Also, he found him young girl (Herzeliya Mayor, Yael German) to kiss while Danny envying him. The big brother is watching? Probably, let’s see what happened later…

DSC08501

Later, Steve told, that he does not like and does not understand technology innovations, thus he’s using regular yellow paper to take notes (BTW, my question)

DSC08518

After his speech the real action begun. It become clear, that Moshe saw Shimon kissing Yael. So he wish Steve to kiss him, but Ballmer did not want to do it, while Danny tightly spying them together with all other kissing people.

DSC08526

Thus, he asked Shimon to do it. When Steve recognized his fault, he was amused to Moshe. “Can't you see. It all makes perfect sense. Expressed in dollars and cents. Pounds, shillings, and pence”.

DSC08528

After all UFO come and took all celebrities out of the event.

DSC08530

The last part of the event was the Buffet. All attendees were really happy and enjoyed.

DSC08541

At the end staff begun to remove all decorations and everyone dissipated back to their homes.

DSC08545

Have a nice day and be good people.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
OpenUp Sidebar gadget

OpenUp competition is on the air? Authors of contributed projects are stressed and want to know what’s going on with their pet project on CodePlex.

What can they do about stress? To get it under control and download new gadget, I built to help them to relieve stress. Just look on your side bar and see three top rated projects (by CodePlex)

image

Click on it or drag it out of SideBar to see all submitted projects and it’s rating

image

Take it easy and return to work. You should continue development of your projects.

Download OpenUp gadget >>

Note: this is very first version with number of bugs. Those days I have no time to fix them, so you can either use it “as-is” or fix bugs and resubmit.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Silverlight 2.0 for building Rich Internet Applications (local event)

If you are developing rich internet applications, web sites or just want to learn what’s new in Silverlight 2.0, you are invited to attend  local (Israel) Microsoft Event 30-June 8:30 AM- 12:30 PM in ILDC (new Microsoft R&D offices in Herzliya).

image

I’ll speak about what is Silverlight 2.0 and what are differences between SL 1.0 and SL 2.0. How to build RIA with Silverlight 2.0. What is DeepZoom and some cool parts of this new internet technology. How to use DataBinding, LINQ and Microsoft Media Encoder. As small bonus for this part of the event, we’ll compare different technologies with Silverlight such as Flex, Flash 10, Thermo and SVG to make you understand differences, “pros and cons” of using each one of those technologies for specific and identifiable needs.

Then we’ll deep dive into DataBinding and learn about DataTemplates, Styles, Accessibility, Authoring and Usability (including differences between Silverlight and WPF approaches). We’ll also take a look into LINQ-to-SQL and SEO of Silverlight applications.

Third part of this event will be dedicated to networking and interoperability. We’ll speak about internet protocols such as ATOM, RSS, REST, JSON, XMLWS, etc and usage of those protocols by Silverlight applications. We’ll understand how WCF can assist us to make our live easier. We’ll also touch security issues of Silverlight deployment and networking such as Cross Domain Policy, progressive download and deploy-on-demand.

I can make you sure, that if ”you are in” new web technologies and want to start using (or if you already using) Silverlight 2.0 for development of your applications – come and see me. Will be fun!

Note: Only a limited number of places available, so do not wait for MS newsletter (by the end of this month). Book now and come to attend this event – it’s free! (there is parking lot in floor -2)

I want to attend “Silverlight 2.0 introduction for building rich internet applications” event (30-June 8:30 AM – 12:30 PM, ILDC Herzelia, 5, Gav-Yam str, floor L2 13,Shenkar str)

See you there…

UPD 29-Jun: Next session will take place at 23 July, 8:30 AM-12:30 PM. Register by visiting Microsoft events web application at https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032382418&culture=he-IL and sign up.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
What’s new in MSDN Downloads?

Just look how many new releases those days in MSDN Download web site.

Too much – too cool. Turn your download managers on

image

Have a nice day

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Gas Price Windows Vista SideBar gadget – new version is available for download

This post is dedicated to some people in Microsoft and it’s subsidiaries. It begun about year ago, when I developed Gas Price information gadget (do not download it there). Before I started, I sent some personal email to those in MSN, who maintains it’s Auto section. I wait two days and got no response, so wrote this post about HTML scrapping and then I finished the gadget, that uses this technology.

image
© Christopher Robbins

Couple of weeks later, Senior Channel Manager of MSN Marketplace replayed to me. He asked whether I want to convert this gadget to “legal” one by gifting all rights to Microsoft. I asked about my benefits of doing it (my time costs money) and the conversation ended – he even did not responded. I was waiting for “YES” or “NO”, but got only silent.

Year after he mailed me again with warning, that they going to “protect” Auto section in order to prevent unauthorized content grabbing. He asked again about possibility to “legalize” the gadget – I told, that they can do with this gadget whatever they want, so handed it off to MSN team. Nothing happened. No one took care on this.

A month later, I asked again by proposing to allow Windows Vista SideBar referrer too aside with affiliate sites for MSN Auto images, thus the gadget can continue to work and MSN remains protected from other “grabbers”. But he demand to completely remove any reference to MSN from the gadget. The same time I got some proposals of using another data for this very popular gadget and populize other resources instead of very unpopular crappy MSN.

I decided to build new version of the gadget (here you can download) and did it today (my spare time – not work [this is for my manager]). This version even better, then previous one. It contains more information, that updates more frequently. I also includes distance from station and gas stations in Canada. So, this how it looks today

image

As you can see this one is much better and uses Automotive.com information. So what I have to do? Submit it instead of old one, right? This the response, I got from automatic system upon submission.

Your item appears to be either missing a valid signature or a valid certificate. You may also want to check the signature to make sure that it includes the date

Just to make things clear, I signed the code with private signature. They want me to sign it with Trusted Authority. This is very smart request, however I do not want to pay $200-$400 to make their sidebar better! There is neither ROI, nor benefit for me to pay money for something, I’m giving for free to anyone.

Just in case, signing code with certificate, trusted by authority even do not removes regular live gallery end-user warning.

Unverified submission.

Only install applications from developers you trust. This is a third-party application, and it could access your computer's files, show you objectionable content, or change its behavior at any time.

So why me to pay? Only because I want to be nice to Microsoft and replace my old gadget by new one to serve dozen thousands of people, who using Windows Vista with SideBar and my gadget?

NO WAY! I will not submit it there. I will never contribute anything for free to Windows Vista Live Gallery. They want me (and million of other developers) to submit it to Google or Yahoo? I’ll do it! I’ll force my customers to use 3rd party addons and visit 3rd party websites to get the information they want to get without paying anyone. At least their marketing guys know how to make developer not to suffer from his own good wish.

Thank you and good buy! You want to win web? You just impossible to do it.

Download Gas Price gadget for Windows Vista SideBar >> (it signed with personal certificate, so do it for your own risk :) )

P.S. Next week, I have a meeting with Steve Ballmer and I’m going to ask him all those questions. If you have any questions and want me to ask him, please send it to me or leave a comment.

UPD (18-May): Some issues were fixed (zips starting with 0, negative prices, sorting). You can download new version of the gadget from the same url and update your local version. Great thank to all, who reported issues.

x-posted from http://blogs.microsoft.co.il/blogs/tamir
OpenUp and my Open Source submissions

Amir Shevat from Microsoft Israel DPE department started cool competition, named OpenUp. I decided to give hand to this initiative and posted sources of some of my applications on CodePlex and submit it to the competition.

Currently, my submission includes (except old Vista Battery Saver and Windows Live Writer Plugins):

Later I’ll submit my other applications (first I have to make it’s code to looks “submittable” :) ). This will include generic plugin based free hosting upload tool, some applications for Windows Mobile, some Time Tracking applications and others. Keep tracking

For more information about OpenUp, visit its website

Vote for me and see you in PDC

image

x-posted from http://blogs.microsoft.co.il/blogs/tamir
Page view counter