Closed roblabla closed 2 months ago
This was implemented in v2.0.0-beta.4. The diff structures are defined with protobuf, and the diff command accepts options for output and format. Let me know if this fits your needs!
This is great! I wrote a quick python script that's able to generate a "simili-patchfile", and github seems to accept it:
import json
import sys
with open(sys.argv[1]) as f:
data = json.load(f)
left_sects = data['left']['sections']
right_sects = data['right']['sections']
left_fun = next((fun for sect in left_sects for fun in sect['functions'] if fun['symbol']['name'] == sys.argv[2]), None)
right_fun = next((fun for sect in right_sects for fun in sect['functions'] if fun['symbol']['name'] == sys.argv[2]), None)
for left_instr, right_instr in zip(left_fun['instructions'], right_fun['instructions']):
if 'diff_kind' not in left_instr:
print(' ' + left_instr['instruction']['formatted'])
elif left_instr['diff_kind'] == 'DIFF_INSERT':
print('+' + right_instr['instruction']['formatted'])
elif left_instr['diff_kind'] == 'DIFF_DELETE':
print('-' + left_instr['instruction']['formatted'])
else:
print('-' + left_instr['instruction']['formatted'])
print('+' + right_instr['instruction']['formatted'])
One small question: My script will currently treat differing relocations as being a diff, while objdiff does not. I'm not sure how I'm supposed to detect this and treat them as a match.
It should, unless you pass --relax-reloc-diffs. So that's odd. Do you have an example?
Ah, that fixed it. I had missed the --relax-reloc-diffs
flag. With this, everything's working great!
It'd be awesome to use
objdiff-cli diff
as part of a CI pipeline to be able to display the diff between an implementation and the original.I currently do this hackily by diffing some asm dumps manually (See https://github.com/happyhavoc/th06/actions/runs/10192215949#user-content-enemy____updateeffects), but this runs into all kind of issues that objdiff already solves.
Unfortunately,
objdiff-cli diff
seems to only support TUI operation, and cannot just output the diff to standard output.