Skip to content

Instantly share code, notes, and snippets.

@withzombies
Created February 1, 2022 18:33
Show Gist options
  • Save withzombies/b87c2f6412e71d90c64409e2b449b10f to your computer and use it in GitHub Desktop.
Save withzombies/b87c2f6412e71d90c64409e2b449b10f to your computer and use it in GitHub Desktop.
Binary Ninja 3.0 Psuedo C vs Ghidra

For the test case I'm using one from Ghidra's test suite, which is available here

It was compiled on my macOS machine with the following command:

$ clang -o decomp -O1 -g decomp.c -Wall -Wshadow -Wextra -std=c17 -arch arm64e

Some metadata:

~/public-src/ghidra/Ghidra/Test/TestResources/src/cpp/decomp(master*) » file decomp
decomp: Mach-O 64-bit executable arm64e
~/public-src/ghidra/Ghidra/Test/TestResources/src/cpp/decomp(master*) » ll -l decomp
-rwxr-xr-x  1 ryan  staff    34K Feb  1 13:22 decomp

I didn't fix up either decompilation, this is the default settings.

// This is the function we decompile in the examples
static void lzw_decompress(mytable *table,char *instream,int len,char* output)
{
mystring local_2c;
mystring *local_14;
unsigned local_10;
unsigned local_c;
int local_8;
init_string(&local_2c);
local_c = 0;
init_table(table);
local_10 = (unsigned)*instream;
instream = instream + 1;
local_c = local_c + 0x1d & 0xff;
set_string(&local_2c,table->entry + (local_10 ^ local_c));
output = output_string(output,&local_2c);
local_8 = 1;
while (local_8 < len) {
local_10 = (unsigned)*instream;
instream = instream + 1;
local_c = local_c + 0x1d & 0xff;
local_14 = table->entry + (local_10 ^ local_c);
output = output_string(output,local_14);
append_character(&local_2c,local_14->data[0]);
add_code(table,&local_2c);
set_string(&local_2c,local_14);
local_8 = local_8 + 1;
}
*output = 0x00;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment