Ghidra is a software reverse engineering (SRE) framework
Let segmentop scripts follow natural parameter order
caheckman05f292a5e715
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.ccindex 56dd7f979f..54b3b01d5a 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc@@ -1363,8 +1363,8 @@ Address SegmentedResolver::resolve(uintb val,int4 sz,const Address &point,uintbuintb base = glb->context->getTrackedValue(segop->getResolve(),point);fullEncoding = (base << 8 * innersz) + (val & calc_mask(innersz));vector<uintb> seginput;- seginput.push_back(val);seginput.push_back(base);+ seginput.push_back(val);val = segop->execute(seginput);return Address(spc,AddrSpace::addressToByte(val,spc->getWordSize()));}@@ -1375,8 +1375,8 @@ Address SegmentedResolver::resolve(uintb val,int4 sz,const Address &point,uintbuintb base = (val >> 8*innersz) & calc_mask(outersz);val = val & calc_mask(innersz);vector<uintb> seginput;- seginput.push_back(val);seginput.push_back(base);+ seginput.push_back(val);val = segop->execute(seginput);return Address(spc,AddrSpace::addressToByte(val,spc->getWordSize()));}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex 4d7277572c..71555482a7 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -644,12 +644,12 @@ int4 ActionSegmentize::apply(Funcdata &data)}if (segdef->getNumVariableTerms()==1)- bindlist[1] = data.newConstant(4,0);+ bindlist[0] = data.newConstant(4,0);// Redefine the op as a segmentopdata.opSetOpcode(segroot,CPUI_SEGMENTOP);data.opSetInput(segroot,data.newVarnodeSpace(spc),0);- data.opSetInput(segroot,bindlist[1],1);- data.opSetInput(segroot,bindlist[0],2);+ data.opSetInput(segroot,bindlist[0],1);+ data.opSetInput(segroot,bindlist[1],2);for(int4 j=segroot->numInput()-1;j>2;--j) // Remove anything elsedata.opRemoveInput(segroot,j);count += 1;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.ccindex 97bb840876..ea9c31c5d8 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc@@ -127,8 +127,8 @@ void EmulatePcodeOp::executeSegmentOp(void)uintb in1 = getVarnodeValue(currentOp->getIn(1));uintb in2 = getVarnodeValue(currentOp->getIn(2));vector<uintb> bindlist;- bindlist.push_back(in2);bindlist.push_back(in1);+ bindlist.push_back(in2);uintb res = segdef->execute(bindlist);setVarnodeValue(currentOp->getOut(), res);}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.ccindex 46efe6eb0f..272e4c1566 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc@@ -36,7 +36,7 @@ void connect_to_console(Funcdata *fd)if (remote == (RemoteSocket *)0) {remote = new RemoteSocket();if (remote->open("/tmp/ghidrasocket")) {- ghidra_dcp = new IfaceStatus("[ghidradbg]> ",*remote->getInputStream(),*remote->getOutputStream());+ ghidra_dcp = new IfaceTerm("[ghidradbg]> ",*remote->getInputStream(),*remote->getOutputStream());IfaceCapability::registerAllCommands(ghidra_dcp);}}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.ccindex a9c28db6c2..ecbebec273 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc@@ -7459,8 +7459,8 @@ int4 RuleSegment::applyOp(PcodeOp *op,Funcdata &data)if (vn1->isConstant() && vn2->isConstant()) {vector<uintb> bindlist;- bindlist.push_back(vn2->getOffset());bindlist.push_back(vn1->getOffset());+ bindlist.push_back(vn2->getOffset());uintb val = segdef->execute(bindlist);data.opRemoveInput(op,2);data.opRemoveInput(op,1);diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.ccindex 0d13d3a7b6..082c2f2825 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/userop.cc@@ -143,13 +143,13 @@ bool SegmentOp::unify(Funcdata &data,PcodeOp *op,innervn = op->getIn(2);if (basevn->isConstant())basevn = data.newConstant(baseinsize,basevn->getOffset());- bindlist[1] = basevn;+ bindlist[0] = basevn;}else- bindlist[1] = (Varnode *)0;+ bindlist[0] = (Varnode *)0;if (innervn->isConstant())innervn = data.newConstant(innerinsize,innervn->getOffset());- bindlist[0] = innervn;+ bindlist[1] = innervn;return true;}diff --git a/Ghidra/Processors/HCS12/data/languages/HCS12.pspec b/Ghidra/Processors/HCS12/data/languages/HCS12.pspecindex 90fb9f51c1..830e243b49 100644--- a/Ghidra/Processors/HCS12/data/languages/HCS12.pspec+++ b/Ghidra/Processors/HCS12/data/languages/HCS12.pspec@@ -8,8 +8,8 @@<segmentop space="RAM" userop="segment" farpointer="no"><pcode>- <input name="inner" size="2"/><input name="base" size="3"/>+ <input name="inner" size="2"/><output name="res" size="3"/><body><![CDATA[res = base ^ zext(inner);diff --git a/Ghidra/Processors/Z80/data/languages/z80.cspec b/Ghidra/Processors/Z80/data/languages/z80.cspecindex 9a4e34c425..d264cf3b9d 100644--- a/Ghidra/Processors/Z80/data/languages/z80.cspec+++ b/Ghidra/Processors/Z80/data/languages/z80.cspec@@ -11,8 +11,8 @@<stackpointer register="SP" space="ram"/><segmentop space="ram" userop="segment" farpointer="yes"><pcode>- <input name="inner" size="2"/><input name="base" size="2"/>+ <input name="inner" size="2"/><output name="res" size="2"/><body><![CDATA[res = (base << 12) + inner;diff --git a/Ghidra/Processors/x86/data/languages/x86-16-real.pspec b/Ghidra/Processors/x86/data/languages/x86-16-real.pspecindex 8b307e612e..ba7ff91207 100644--- a/Ghidra/Processors/x86/data/languages/x86-16-real.pspec+++ b/Ghidra/Processors/x86/data/languages/x86-16-real.pspec@@ -9,8 +9,8 @@<segmented_address space="ram" type="real" /><segmentop space="ram" userop="segment" farpointer="yes"><pcode>- <input name="inner" size="2"/><input name="base" size="2"/>+ <input name="inner" size="2"/><output name="res" size="4"/><body><![CDATA[res = (zext(base) << 4) + zext(inner);diff --git a/Ghidra/Processors/x86/data/languages/x86-16.pspec b/Ghidra/Processors/x86/data/languages/x86-16.pspecindex 1b3042e81a..ae2d69c72d 100644--- a/Ghidra/Processors/x86/data/languages/x86-16.pspec+++ b/Ghidra/Processors/x86/data/languages/x86-16.pspec@@ -10,8 +10,8 @@<segmented_address space="ram" type="protected"/><segmentop space="ram" userop="segment" farpointer="yes"><pcode>- <input name="inner" size="2"/><input name="base" size="2"/>+ <input name="inner" size="2"/><output name="res" size="4"/><body><![CDATA[res = (zext(base) << 16) + zext(inner);