Exemplo n.º 1
0
		public SystemService Build(IProcessorArchitecture arch)
		{
			SystemService svc = new SystemService();
			svc.Name = Name;
			svc.SyscallInfo = new SyscallInfo();
			svc.SyscallInfo.Vector = Convert.ToInt32(SyscallInfo.Vector, 16);
			if (SyscallInfo.RegisterValues != null)
			{
				svc.SyscallInfo.RegisterValues = new RegValue[SyscallInfo.RegisterValues.Length];
				for (int i = 0; i < SyscallInfo.RegisterValues.Length; ++i)
				{
                    svc.SyscallInfo.RegisterValues[i] = new RegValue
                    {
                        Register = arch.GetRegister(SyscallInfo.RegisterValues[i].Register),
                        Value = Convert.ToInt32(SyscallInfo.RegisterValues[i].Value, 16),
                    };
				}
			}
			else
			{
				svc.SyscallInfo.RegisterValues = new RegValue[0];
			}
            TypeLibraryLoader loader = new TypeLibraryLoader(arch, true);
			ProcedureSerializer sser = arch.CreateProcedureSerializer(loader, "stdapi");
            svc.Signature = sser.Deserialize(Signature, arch.CreateFrame());
			svc.Characteristics = Characteristics != null ? Characteristics : DefaultProcedureCharacteristics.Instance;
			return svc;
		}
Exemplo n.º 2
0
        public SystemService Build(IProcessorArchitecture arch)
        {
            SystemService svc = new SystemService();

            svc.Name               = Name;
            svc.SyscallInfo        = new SyscallInfo();
            svc.SyscallInfo.Vector = Convert.ToInt32(SyscallInfo.Vector, 16);
            if (SyscallInfo.RegisterValues != null)
            {
                svc.SyscallInfo.RegisterValues = new RegValue[SyscallInfo.RegisterValues.Length];
                for (int i = 0; i < SyscallInfo.RegisterValues.Length; ++i)
                {
                    svc.SyscallInfo.RegisterValues[i] = new RegValue
                    {
                        Register = arch.GetRegister(SyscallInfo.RegisterValues[i].Register),
                        Value    = Convert.ToInt32(SyscallInfo.RegisterValues[i].Value, 16),
                    };
                }
            }
            else
            {
                svc.SyscallInfo.RegisterValues = new RegValue[0];
            }
            TypeLibraryLoader   loader = new TypeLibraryLoader(arch, true);
            ProcedureSerializer sser   = arch.CreateProcedureSerializer(loader, "stdapi");

            svc.Signature       = sser.Deserialize(Signature, arch.CreateFrame());
            svc.Characteristics = Characteristics != null ? Characteristics : DefaultProcedureCharacteristics.Instance;
            return(svc);
        }
Exemplo n.º 3
0
        public void ApplyChangesToProcedure(Procedure procedure)
        {
            var ser = arch.CreateProcedureSerializer(new TypeLibraryLoader(arch, true), "stdapi");          //BUG:Where does convetion come from? Platform?
            var sp  = new SignatureParser(arch);

            sp.Parse(dlg.Signature.Text);
            Debug.Assert(sp.IsValid);
            procedure.Signature = ser.Deserialize(sp.Signature, procedure.Frame);
        }
Exemplo n.º 4
0
        private void EditSignature()
        {
            //$TODO: need "current program"
            IProcessorArchitecture arch = null; // Decompiler.Program.Architecture;
            var ser  = arch.CreateProcedureSerializer(new TypeLibraryLoader(arch, true), "stdapi");
            var proc = ser.Serialize(SelectedProcedureEntry.Value, SelectedProcedureEntry.Key);
            var i    = new ProcedureDialogInteractor(arch, proc);

            using (ProcedureDialog dlg = i.CreateDialog())
            {
                if (DialogResult.OK == UIService.ShowModalDialog(dlg))
                {
                    //$REVIEW: Need to pass InputFile into the SelectedProcedureEntry piece.
                    var program = Decompiler.Project.Programs[0];
                    program.UserProcedures[SelectedProcedureEntry.Key] =
                        i.SerializedProcedure;
                    ser = arch.CreateProcedureSerializer(new TypeLibraryLoader(arch, true), "stdapi");
                    SelectedProcedureEntry.Value.Signature =
                        ser.Deserialize(i.SerializedProcedure.Signature, SelectedProcedureEntry.Value.Frame);

                    canAdvance = false;
                }
            }
        }
Exemplo n.º 5
0
 public void LoadProcedure(Procedure_v1 sp)
 {
     try
     {
         var sser      = arch.CreateProcedureSerializer(this, this.defaultConvention);
         var signature = sser.Deserialize(sp.Signature, arch.CreateFrame());
         signaturesByName[sp.Name] = signature;    //$BUGBUG: catch dupes?
         if (sp.Ordinal != Procedure_v1.NoOrdinal)
         {
             servicesByOrdinal[sp.Ordinal] = new SystemService {
                 Name      = sp.Name,
                 Signature = signature,
             };
         }
     }
     catch (Exception ex)
     {
         Debug.Print("An error occurred when loading the signature of procedure {0}.", sp.Name);
         throw new ApplicationException(
                   string.Format("An error occurred when loading the signature of procedure {0}.", sp.Name),
                   ex);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Guesses the signature of a procedure based on its name.
 /// </summary>
 /// <param name="fnName"></param>
 /// <param name="loader"></param>
 /// <param name="arch"></param>
 /// <returns></returns>
 public static ProcedureSignature SignatureFromName(string fnName, TypeLibraryLoader loader, IProcessorArchitecture arch)
 {
     int argBytes;
     if (fnName[0] == '_')
     {
         // Win32 prefixes cdecl and stdcall functions with '_'. Stdcalls will have @<nn> 
         // where <nn> is the number of bytes pushed on the stack. If 0 bytes are pushed
         // the result is indistinguishable from the corresponding cdecl call, which is OK.
         int lastAt = fnName.LastIndexOf('@');
         if (lastAt < 0)
             return CdeclSignature(fnName.Substring(1), arch);
         string name = fnName.Substring(1, lastAt - 1);
         if (!Int32.TryParse(fnName.Substring(lastAt + 1), out argBytes))
             return CdeclSignature(name, arch);
         else
             return StdcallSignature(name, argBytes, arch);
     }
     else if (fnName[0] == '@')
     {
         // Win32 prefixes fastcall functions with '@'.
         int lastAt = fnName.LastIndexOf('@');
         if (lastAt <= 0)
             return CdeclSignature(fnName.Substring(1), arch);
         string name = fnName.Substring(1, lastAt - 1);
         if (!Int32.TryParse(fnName.Substring(lastAt + 1), out argBytes))
             return CdeclSignature(name, arch);
         else
             return FastcallSignature(name, argBytes, arch);
     }
     else if (fnName[0] == '?')
     {
         // Microsoft-mangled signatures begin with '?'
         var pmnp = new MsMangledNameParser(fnName);
         StructField_v1 field = null;
         try
         {
             field = pmnp.Parse();
         }
         catch (Exception ex)
         {
             Debug.Print("*** Error parsing {0}. {1}", fnName, ex.Message);
             pmnp.ToString();
             return null;
         }
         var sproc = field.Type as SerializedSignature;
         if (sproc != null)
         {
             var sser = arch.CreateProcedureSerializer(loader, "__cdecl");
             return sser.Deserialize(sproc, arch.CreateFrame());    //$BUGBUG: catch dupes?   
         }
     }
     return null;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Guesses the signature of a procedure based on its name.
        /// </summary>
        /// <param name="fnName"></param>
        /// <param name="loader"></param>
        /// <param name="arch"></param>
        /// <returns></returns>
        public static ProcedureSignature SignatureFromName(string fnName, TypeLibraryLoader loader, IProcessorArchitecture arch)
        {
            int argBytes;

            if (fnName[0] == '_')
            {
                // Win32 prefixes cdecl and stdcall functions with '_'. Stdcalls will have @<nn>
                // where <nn> is the number of bytes pushed on the stack. If 0 bytes are pushed
                // the result is indistinguishable from the corresponding cdecl call, which is OK.
                int lastAt = fnName.LastIndexOf('@');
                if (lastAt < 0)
                {
                    return(CdeclSignature(fnName.Substring(1), arch));
                }
                string name = fnName.Substring(1, lastAt - 1);
                if (!Int32.TryParse(fnName.Substring(lastAt + 1), out argBytes))
                {
                    return(CdeclSignature(name, arch));
                }
                else
                {
                    return(StdcallSignature(name, argBytes, arch));
                }
            }
            else if (fnName[0] == '@')
            {
                // Win32 prefixes fastcall functions with '@'.
                int lastAt = fnName.LastIndexOf('@');
                if (lastAt <= 0)
                {
                    return(CdeclSignature(fnName.Substring(1), arch));
                }
                string name = fnName.Substring(1, lastAt - 1);
                if (!Int32.TryParse(fnName.Substring(lastAt + 1), out argBytes))
                {
                    return(CdeclSignature(name, arch));
                }
                else
                {
                    return(FastcallSignature(name, argBytes, arch));
                }
            }
            else if (fnName[0] == '?')
            {
                // Microsoft-mangled signatures begin with '?'
                var            pmnp  = new MsMangledNameParser(fnName);
                StructField_v1 field = null;
                try
                {
                    field = pmnp.Parse();
                }
                catch (Exception ex)
                {
                    Debug.Print("*** Error parsing {0}. {1}", fnName, ex.Message);
                    pmnp.ToString();
                    return(null);
                }
                var sproc = field.Type as SerializedSignature;
                if (sproc != null)
                {
                    var sser = arch.CreateProcedureSerializer(loader, "__cdecl");
                    return(sser.Deserialize(sproc, arch.CreateFrame()));    //$BUGBUG: catch dupes?
                }
            }
            return(null);
        }