Skip to content

How do you implement relocations for a native (C/C++) architecture plugin? #1620

Answered by plafosse
nshp asked this question in Architectures
Discussion options

You must be logged in to vote

Maybe the best answer is... just show me the code.

class x86ElfRelocationHandler: public RelocationHandler
{
public:
	virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
	{
		(void)view; (void)arch;
		set<uint32_t> relocTypes;
		for (auto& reloc : result)
		{
			reloc.type = StandardRelocationType;
			switch (reloc.nativeType)
			{
			case R_386_NONE:
				reloc.type = IgnoredRelocation;
				break;
			case R_386_32:
				reloc.pcRelative = false;
				reloc.baseRelative = false;
				reloc.hasSign = false;
				reloc.size = 4;
				reloc.truncateSize = 4;
				break;
			case R_386_PC32:
			case R_386_GOT32:
			case R_386_PLT32:
…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nshp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants