hi,
I am writing a very simple example from a book and I am getting an error when I run Peverify. It says it is unable to verify token. There are two files in the example.
The first one - CILCars.il doesn't throw up any errors when I run ilasm // dll CILCars.il
I verify it using peverify CILCars.dll and all is ok
here is the code :
// Reference mscorlib.dll and // System.Windows.Forms.dll. .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89) .ver 4:0:0:0 } .assembly extern System.Windows.Forms { .publickeytoken = (B7 7A 5C 56 19 34 E0 89) .ver 4:0:0:0 } // Define the single-file assembly. .assembly CILCars { .hash algorithm 0X00008004 .ver 1:0:0:0 } .module CILCars.dll // Implementation of CILCars.CILCar type. .namespace CILCars { .class public auto ansi beforefieldinit CILCar extends [mscorlib]System.Object { // The field data of the CILCar. .field public string petName .field public int32 currSpeed // The custom constructor simply allows the caller // to assign the field data. .method public hidebysig specialname rtspecialname instance void .ctor(int32 c, string p) cil managed { .maxstack 8 // Load first arg onto the stack and call base class ctor. ldarg.0 // "this" object, not the int32! call instance void [mscorlib]System.Object::.ctor() // Now load first and second args onto the stack. ldarg.0 // "this" object ldarg.1 // int32 arg // Store topmost stack (int 32) member in currSpeed field. stfld int32 CILCars.CILCar::currSpeed // Load string arg and store in petName field. ldarg.0 // "this" object ldarg.2 // string arg stfld string CILCars.CILCar::petName ret } } } .class public auto ansi beforefieldinit CILCarInfo extends [mscorlib]System.Object { .method public hidebysig static void Display(class CILCars.CILCar c) cil managed { .maxstack 8 // We need a local string variable. .locals init ([0] string caption) // Load string and the incoming CILCar onto the stack. ldstr "{0}'s speed is:" ldarg.0 // Now place the value of the CILCar's petName on the // stack and call the static String.Format() method. ldfld string CILCars.CILCar::petName call string [mscorlib]System.String::Format(string, object) stloc.0 // Now load the value of the currSpeed field and get its string // representation (note call to ToString(). ldarg.0 ldflda int32 CILCars.CILCar::currSpeed call instance string [mscorlib]System.Int32::ToString() ldloc.0 // Now call the MessageBox.Show() method with loaded values. call valuetype [System.Windows.Forms] System.Windows.Forms.DialogResult [System.Windows.Forms] System.Windows.Forms.MessageBox::Show(string, string) pop ret } }
The second file CarClient.il throws up an error when I run peverfity. Here is the code :
// External assembly refs. .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89) .ver 4:0:0:0 } .assembly extern CILCars { .ver 1:0:0:0 } // Our executable assembly. .assembly CarClient { .hash algorithm 0x00008004 .ver 1:0:0:0 } .module CarClient.exe // Implementation of Program type. .namespace CarClient { .class private auto ansi beforefieldinit Program extends [mscorlib]System.Object { .method private hidebysig static void Main(string[] args) cil managed { // Marks the entry point of the *.exe. .entrypoint .maxstack 8 // Declare a local CILCar variable and push // values onto the stack for ctor call. .locals init ([0] class [CILCars]CILCars.CILCar myCILCar) ldc.i4 55 ldstr "Junior" // Make new CILCar; store and load reference. newobj instance void [CILCars]CILCars.CILCar::.ctor(int32, string) stloc.0 ldloc.0 // Call Display() and pass in topmost value on stack. call void [CILCars] CILCars.CILCarInfo::Display( class [CILCars]CILCars.CILCar) ret } } }
Any ideas ?