Friday, December 14, 2012

how to use Vi to view file in hex mode


":%!xxd" (minus quotes) will show file in hex mode
“:%!xxd -r“ will return to normal editing.

Monday, December 10, 2012

debug the java security policy

while run a java app with security manager,it just simply failed,we need more information.invoke app with following parameters:
java -Djava.security.manager -Djava.security.debug=access:failure
then we get following result:

About to get os.name property value
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.security.SecurityPermission getProperty.policy.expandProperties)
access: access allowed (java.security.SecurityPermission getProperty.policy.ignoreIdentityScope)
access: access allowed (java.security.SecurityPermission getProperty.policy.allowSystemProperty)
access: access allowed (java.util.PropertyPermission sun.security.policy.utf8 read)
access: access allowed (java.util.PropertyPermission sun.security.policy.numcaches read)
access: access allowed (java.util.PropertyPermission java.security.policy read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.1)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.util.PropertyPermission java.ext.dirs read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\ext\* read)
access: access allowed (java.io.FilePermission C:\Windows\Sun\Java\lib\ext\* read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.2)
access: access allowed (java.util.PropertyPermission user.home read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.3)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\examplepolicy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\examplepolicy read)
access: access allowed (java.util.PropertyPermission java.protocol.handler.pkgs read)
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.util.PropertyPermission java.util.logging.manager read)
access: access allowed (java.lang.RuntimePermission setContextClassLoader)
access: access allowed (java.lang.RuntimePermission shutdownHooks)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.PropertyPermission java.util.logging.config.class read)
access: access allowed (java.util.PropertyPermission java.util.logging.config.file read)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.PropertyPermission http.maxRedirects read)
access: access allowed (java.util.PropertyPermission java.version read)
access: access allowed (java.util.PropertyPermission http.agent read)
access: access allowed (java.util.PropertyPermission http.auth.digest.validateProxy read)
access: access allowed (java.util.PropertyPermission http.auth.digest.validateServer read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.enableBuffering read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.timeout read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.bufferSize read)
access: access allowed (java.util.PropertyPermission sun.net.http.allowRestrictedHeaders read)
access: access allowed (java.util.PropertyPermission http.auth.serializeRequests read)
access: access allowed (java.util.PropertyPermission http.auth.ntlm.domain read)
access: access allowed (java.net.NetPermission getCookieHandler)
access: access allowed (java.net.NetPermission getResponseCache)
access: access allowed (java.util.PropertyPermission user.dir read)
access: access allowed (java.io.FilePermission C:\test read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.4)
access: access allowed (java.util.PropertyPermission java.security.auth.policy read)
access: access allowed (java.security.SecurityPermission getProperty.auth.policy.url.1)
access: access allowed (java.io.FilePermission C:\test read)
  The name of your operating system is: Windows 7
About to get java.version property value
access: access allowed (java.util.PropertyPermission java.version read)
  The version of the JVM you are running is: 1.6.0_30
About to get user.home property value
access: access allowed (java.util.PropertyPermission user.home read)
  Your user home directory is: C:\Users\dwei
About to get java.home property value
access: access allowed (java.util.PropertyPermission java.home read)
  Your JRE installation directory is: C:\Program Files (x86)\Java\jdk1.6.0_30\jre

specify the policy file while run a applet

try out the java security guide,created the policy file,saved as a examplepolicy in local folder,the go to run the command line that invoke the applet view from sun.
appletviewer -J-Djava.security.policy=examplepolicy http://docs.oracle.com/javase/tutorial/security/tour1/examples/WriteFile.html

if we run the appletviewer from the folder that contains examplepolicy,the applet will be correctly run.oterwise the examplepolicy can not be find,so the applet will fail.

since the default jre\lib\security\java.security has a default item that load the policy from {user_home}\.java.policy,we can save newly created policy into that file,the invoke the applet anywhere,just make sure has the permission to write to that folder.

developers normally set up their JAVA_HOME to a JDK, so make sure change the java.security file in JDK\JRE\lib\security\java.security ,not the file under Program Files\Java\Jre\lib\security\java.security


locally fill a PDF form from FDF file

while open the insurance company online PDF documentation,it should automatically fill the claim form with logged in personal information.but it is downloading a file content call FDF, forms data format file which was used to fill the pdf.

open up the FDF file,found out that the file contains the url of the pdf file,I change that url to pdf file that downloaded previously from the same web site,vola, when double click th FDF file,the pdf was opened and automatically filled with information in FDF file.

take a look at the FDF file,we can also change the information in FDF to fill the PDF form.

Friday, November 23, 2012

Outlook Runtime Error -2147221233 The operation failed. An object cannot be found

This error comes out after my windows 7 get updated from microsoft, maybe some for outlook

in my VBA code ,I have following code to move a message to another folder.

 Msg.Move objNS.Folders(2).Folders("foldername")

is suddenly pop up the error messages,did some debug,find out that we need change to following code now

 Msg.Move objNS.Folders(1).Folders(13)

all index started with 1
objNS.Folders(1) is first folder in my outlook name space

objNS.Folders(1).Folders(13) is the 13th sub folder in previous folder,there is not method to get a sub folder by it's name,maybe a iteration will help to find the folder with specific name,but it is too heavy here,if we do not add new sub folder between first one and 13th,then we will be ok with previous code.




Wednesday, November 21, 2012

Installing the IDEA Module in GnuPG


(THIS INFORMATION COMES FROM http://www.spywarewarrior.com)

The "official" Win32 builds of GnuPG do not include support for the IDEA algorithm, which is patented.* This can prove to be a problem when exchanging messages and files with PGP users (esp. PGP 2.6.x users) or importing old PGP keys. This web page explains how to install the IDEA module for GnuPG so that GnuPG can use the IDEA algorithm.
The IDEA module has been distributed as both a source code file (IDEA.C) and a compiled .DLL (IDEA.DLL). Unless you plan to compile the source code yourself, you want the IDEA.DLL, which is placed somewhere in the GnuPG installation directory and loaded with the load-extension option.
Please note that the IDEA module, its location within the GnuPG installation directory, and the method for loading that module with the load-extension option have changed over successive versions of GnuPG:
Please consult the appropriate directions for your version of GnuPG. All of the versions of the IDEA module discussed on this page are available for download from this site -- see the Downloadssection below.
* The IDEA is patented in many countries, including the U.S., and may be used for non-commercial
   purposes. For commercial uses you'll need to buy a license from MediaCrypt. For the "official"
   explanation of why the IDEA algorithm is not supported in GnuPG by default see HERE.

GnuPG 1.2.0 and later

There were big changes in GnuPG 1.2.0 with respect to the IDEA module. There's a new IDEA.DLL as well as a change from previous versions in the way the IDEA.DLL is loaded.

From the GnuPG 1.2.0 Announcement
* All modules are now linked statically; the --load-extension
  option is in general not useful anymore.  The only exception is
  to specify the deprecated IDEA cipher plugin.

* The IDEA plugin has changed.  Previous versions of the IDEA
  plugin will no longer work with GnuPG.  However, the current
  version of the plugin will work with earlier GnuPG versions.

Files

For "official" versions of GnuPG  (from gnupg.org), a new set of IDEA files is available from ftp.gnupg.dk (idea.c.gz & ideadll.zip):
FileSize (kb)Notes
idea.c13815/13727new source (gnupg.org)
idea.dll8192new Win32 DLL (gnupg.org)
The Nullify builds use Disastry's IDEA module (ideadll.zip), the same as previous Nullify builds:
FileSize (kb)Notes
idea.dll45056Disastry's IDEA module
See the Downloads section below for links to these files.

To Install

1. Place the IDEA.DLL in \LIB sub-dir of the GnuPG installation dir. 
2. Add the following line to the GPG.CONF file (in previous GnuPG
    versions it was in the OPTIONS file):
load-extension Lib\idea
    You can also specify a full path to the IDEA.DLL file:
load-extension C:\GnuPG\Lib\idea.dll
    This GPG.CONF file option line works for both the "official" and  
    Nullify
 GnuPG builds.

Friday, September 21, 2012

Web Service in Windows .Net

I followed a Shiv Pal Singh's post in CodeGuru that create a web service with .net in windows without a studio tools,here is the steps and content that recorded to help me remember.

1) install the IIS from windows 7,after installation the server is up,default page(actually is a html with one picture 

embedded with lot of links) can be see in browser.

2) add a default html in server's newly created virtual directory can also be see in browser,but the asmx web service file 

can not be see in browser because of the script handler is not properly registered in system

go to c:\windows\Microsoft.NET\Framework64\v.2.0.50727,run following command

ASPNET_REGIIS.exe -I 

remember this is 64 bit,not 32,running 32 in 64 will get a error

then stop and start the server:

net stop w3svc

net start w3svc

3) copy following content in to virtual directory,name is as FirstService.asmx, language is CS,not C


 <%@ WebService language="CS" class="FirstService" %>

  using System;
  using System.Web.Services;
  using System.Xml.Serialization;

  [WebService(Namespace="http://localhost/WebService/")]
  public class FirstService : WebService
  {
      [WebMethod]
      public int Add(int a, int b)
      {
          return a + b;
      }

      [WebMethod]
      public String SayHello()
      {
          return "Hello World";
      }
  }


we will get list of operations,use link can test the service,url http://localhost/WebService/FirstService.asmx?WSDL can 

return the wsdl file of the web service

now web service serverside is done

following step will test web service from local or another machine by web and standalone windows app

1) create following asp.net web page to test the web service,name it  as WebApp.aspx



<%@ Page Language="C#" %>
  <script runat="server">
  void runSrvice_Click(Object sender, EventArgs e)
  {
      FirstService mySvc = new FirstService();
      Label1.Text = mySvc.SayHello();
      Label2.Text = mySvc.Add(Int32.Parse(txtNum1.Text),
                    Int32.Parse(txtNum2.Text)).ToString();
  }
  </script>
  <html>
  <head>
  </head>
  <body>
  <form runat="server">
    <p>
        <em>First Number to Add </em>:
        <asp:TextBox id="txtNum1" runat="server"
             Width="43px">4</asp:TextBox>
    </p>
    <p>
        <em>Second Number To Add </em>:
        <asp:TextBox id="txtNum2" runat="server"
             Width="44px">5</asp:TextBox>
    </p>
    <p>
        <strong><u>Web Service Result -</u></strong>
    </p>
    <p>
        <em>Hello world Service</em> :
        <asp:Label id="Label1" runat="server"
             Font-Underline="True">Label</asp:Label>
    </p>
    <p>
        <em>Add Service</em> :
        & <asp:Label id="Label2" runat="server"
               Font-Underline="True">Label</asp:Label>
    </p>
    <p align="left">
        <asp:Button id="runSrvice" onclick="runSrvice_Click"
             runat="server" Text="Execute"></asp:Button>
    </p>
  </form>
  </body>

  </html>



This client is some code running from server to test web service,then display result in client page

2) standalone windows app,net point to a server that web service stay,we need use WSDL file from server to create a 

dll, link this dll with client code will make client test code connect with server and successfully test the operation


use following step to create DLL

WSDL http://localhost/WebService/FirstService.asmx?WSDL

this will download the server's WSDl file and create a agent file(C#) called FirstService.cs,use following command to 

compile the source code to a DLL,then put this dll in virtual dir\bin folder,IIS looking for this agent at run time.

csc /t:library FirstService.cs

create source code of the WinApp.cs


 using System;
 using System.IO;

 namespace SvcConsumer{
 class SvcEater
 {
        public static void Main(String[] args)
        {
                FirstService mySvc = new FirstService();
                Console.WriteLine("Calling Hello World Service: " + mySvc.SayHello());
                Console.WriteLine("Calling Add(2, 3) Service: " +
                mySvc.Add(2, 3).ToString());
        }
 }
}

using following to compile the client

csc /r:FirstService.dll WinApp.cs

exe file created,it will test our  web service created in previous steps