ghidra/Ghidra/Features/Base/ghidra_scripts/FixupGolangFuncParamStorageScript.java
dev747368 36c6c8ef77 GP-2432 golang api snapshot, generics, closures, gcwritebarrier
Apply golang runtime function signatures from info stored in json api
snapshot files.

The api snapshot files are created by a custom go helper program that
uses the go compiler parser to parse the go toolchain source tree and
writes the discovered function and type info into a json file.

The go-api-parser helper program is based off of work contributed by
github user monoidic via issue #6367.

Updates generic functions to take a generic dictionary RTTI
parameter (mostly to allow correct assignment of other parameters).

Updates closure functions to take a closure context parameter.  Closure
contexts are passed via a register that is not involved in normal
parameter passing.

Tweaks the signature of gcWriteBarrier functions so that they don't mess
up decompilation of functions that use them.
2025-03-07 16:44:48 +00:00

46 lines
1.7 KiB
Java

/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Assigns custom storage for params of a golang function to match golang's abi-internal
// register-based calling convention, or abi0 (all stack based) if abi-internal is not
// specified for the arch.
//@category Functions
//@menupath Tools.Fix Golang Function Param Storage
import ghidra.app.script.GhidraScript;
import ghidra.app.util.bin.format.golang.GoFunctionFixup;
import ghidra.app.util.bin.format.golang.GoVer;
import ghidra.app.util.bin.format.golang.rtti.GoRttiMapper;
import ghidra.program.model.listing.Function;
public class FixupGolangFuncParamStorageScript extends GhidraScript {
@Override
protected void run() throws Exception {
Function func;
if (currentAddress == null || (func = getFunctionContaining(currentAddress)) == null) {
return;
}
GoVer goVersion = GoVer.fromProgramProperties(currentProgram);
if (goVersion == GoVer.INVALID) {
goVersion = askChoice("Golang Version", "What is the golang version?",
GoRttiMapper.getAllSupportedVersions(), GoVer.INVALID);
}
println("Fixing param storage for function %s@%s".formatted(func.getName(),
func.getEntryPoint()));
GoFunctionFixup fixup = new GoFunctionFixup(func, goVersion);
fixup.apply();
}
}