public void SetUserProcedure(ulong linearAddress, string decl) { var addr = Addr(linearAddress); string name; string?CSignature; if (UserSignatureBuilder.IsValidCIdentifier(decl)) { name = decl; CSignature = null; } else { var usb = new UserSignatureBuilder(program); var sProc = usb.ParseFunctionDeclaration(decl); if (sProc is null || sProc.Name is null) { throw new ArgumentException( $"Failed to parse procedure declaration: '{decl}'"); } name = sProc.Name; CSignature = decl; } program.User.Procedures[addr] = new UserProcedure(addr, name) { CSignature = CSignature, }; if (program.Procedures.TryGetValue(addr, out var proc)) { proc.Name = name; } }
private void EnableControls() { ProcedureBase_v1 sProc; GlobalDataItem_v2 global; var procText = declarationForm.TextBox.Text; if (TryParseSignature(procText, out sProc)) { declarationForm.TextBox.ForeColor = SystemColors.ControlText; return; } if (!editProcedure && TryParseGlobal(procText, out global)) { declarationForm.TextBox.ForeColor = SystemColors.ControlText; return; } // If parser failed, perhaps it's simply a valid name? if (UserSignatureBuilder.IsValidCIdentifier(procText)) { declarationForm.TextBox.ForeColor = SystemColors.ControlText;; return; } // Not valid name either, die. declarationForm.TextBox.ForeColor = Color.Red; }
private void ModifyDeclaration() { var declText = declarationForm.TextBox.Text.Trim(); Procedure proc; if (!program.Procedures.TryGetValue(address, out proc)) { proc = null; } ProcedureBase_v1 sProc; GlobalDataItem_v2 parsedGlobal; string procName = null; string CSignature = null; if (TryParseSignature(declText, out sProc)) { procName = sProc.Name; CSignature = declText; } else if (UserSignatureBuilder.IsValidCIdentifier(declText) && (proc == null || proc.Name != declText)) { procName = declText; } else if (!editProcedure && TryParseGlobal(declText, out parsedGlobal)) { program.User.Procedures.Remove(address); program.ModifyUserGlobal( program.Architecture, address, parsedGlobal.DataType, parsedGlobal.Name ); } if (procName != null) { program.RemoveUserGlobal(address); var up = program.EnsureUserProcedure(address, procName); if (CSignature != null) { up.CSignature = CSignature; } if (proc != null) { proc.Name = procName; } else { var pAddr = new ProgramAddress(program, address); services.RequireService <ICommandFactory>().MarkProcedure(pAddr).Do(); } } }