Skip to content

Instantly share code, notes, and snippets.

@c3rb3ru5d3d53c
Created June 2, 2021 12:47
Show Gist options
  • Save c3rb3ru5d3d53c/1a7eb2ed166926bf9fa725ad25b4f544 to your computer and use it in GitHub Desktop.
Save c3rb3ru5d3d53c/1a7eb2ed166926bf9fa725ad25b4f544 to your computer and use it in GitHub Desktop.
A Ghidra Plugin to that imports Radare2 Scripts generated by Floss
# Parses and Imports Floss Radare2 Script
#@author c3rb3ru5
#@category Strings
#@keybinding
#@menupath
#@toolbar
import re
import json
import base64
from ghidra.program.model.symbol.SourceType import *
from ghidra.program.model.data import *
addressFactory = currentProgram.getAddressFactory()
regClean = re.compile(r'(^\"FLOSS:\s|\"$)')
regAddress = re.compile(r'(?<=@\s)\d+')
regBase64 = re.compile(r'(?<=base64:)[a-zA-Z0-9+\/=]+')
def intToAddress(addr):
return addressFactory.getAddress(hex(addr))
def get_data(file_path):
f = open(file_path, 'r')
data = f.readlines()
f.close()
return data
def clean_string(string):
return re.sub(regClean, '', string)
def parse_data(data):
results = []
for item in data:
address = re.findall(regAddress, item)
text = re.findall(regBase64, item)
if len(address) > 0 and len(text) > 0:
text = base64.b64decode(text[0]).decode('utf-8')
text = clean_string(text)
results.append(
{
'address': int(address[0]),
'comment': text
}
)
return results
def apply_eol_comments(data):
for item in data:
setEOLComment(intToAddress(item['address']), item['comment'])
file_path = str(askFile("Ghidra Floss", "FilePath to Radare2 Floss Script"))
data = get_data(file_path)
data = parse_data(data)
apply_eol_comments(data)
print('Ghidra Floss Import Completed!')
@msm-code
Copy link

Cool, thanks!

For the others, if you have problems with importing in your ghidra version, consider changing:

    return addressFactory.getAddress(hex(addr))

to

    return addressFactory.getAddress(hex(addr).replace("L", ""))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment