-
-
Notifications
You must be signed in to change notification settings - Fork 535
Structured function disassembly #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
350051f to
aaf2610
Compare
|
I was thinking about this and I think we shouldn't use the I think it'd be best to keep the number of tokens lower and make these keys optional (like |
|
Just put |
6ce880c to
14fb7cb
Compare
|
I updated it with {
"name": "server_main_loop",
"start_ea": "0x8048a98",
"stack_frame": [
{
"name": "var_18",
"offset": "0x10",
"size": "0x4",
"type": "int"
},
{
"name": "status",
"offset": "0x14",
"size": "0x4",
"type": "int"
},
{
"name": "var_10",
"offset": "0x18",
"size": "0x4",
"type": "_DWORD"
},
{
"name": "var_C",
"offset": "0x1c",
"size": "0x4",
"type": "_DWORD"
},
{
"name": "__saved_registers",
"offset": "0x28",
"size": "0x4",
"type": "_DWORD"
},
{
"name": "__return_address",
"offset": "0x2c",
"size": "0x4",
"type": "_UNKNOWN *"
},
{
"name": "fd",
"offset": "0x30",
"size": "0x4",
"type": "int"
},
{
"name": "arg_4",
"offset": "0x34",
"size": "0x4",
"type": "int"
}
],
"lines": [
{
"address": "0x8048a98",
"instruction": "push ebp",
"comments": [
"Main server loop: accepts connections and forks handlers"
],
"segment": ".text"
},
{
"address": "0x8048a99",
"instruction": "mov ebp, esp",
"segment": ".text"
},
{
"address": "0x8048a9b",
"instruction": "sub esp, 28h",
"segment": ".text"
},
{
"address": "0x8048a9e",
"instruction": "mov [ebp+var_10], 1",
"segment": ".text"
},
{
"address": "0x8048aa5",
"instruction": "jmp loc_8048B22",
"comments": [
"loc_8048B22=0x8048b22",
"*loc_8048B22=0xf07d83"
],
"segment": ".text"
},
{
"address": "0x8048aa7",
"instruction": "mov eax, 0",
"segment": ".text",
"label": "loc_8048AA7"
},
{
"address": "0x8048aac",
"instruction": "mov dword ptr [esp+8], 0",
"comments": [
"addr_len"
],
"segment": ".text"
},
{
"address": "0x8048ab4",
"instruction": "mov [esp+4], eax",
"comments": [
"addr"
],
"segment": ".text"
},
{
"address": "0x8048ab8",
"instruction": "mov eax, [ebp+fd]",
"segment": ".text"
},
{
"address": "0x8048abb",
"instruction": "mov [esp], eax",
"comments": [
"fd"
],
"segment": ".text"
},
{
"address": "0x8048abe",
"instruction": "call _accept",
"comments": [
"Accept incoming connection",
"_accept=0x804871c"
],
"segment": ".text"
},
{
"address": "0x8048ac3",
"instruction": "mov [ebp+var_18], eax",
"segment": ".text"
},
{
"address": "0x8048ac6",
"instruction": "cmp [ebp+var_18], 0FFFFFFFFh",
"segment": ".text"
},
{
"address": "0x8048aca",
"instruction": "jz loc_8048B1E",
"comments": [
"loc_8048B1E=0x8048b1e",
"*loc_8048B1E=0x90"
],
"segment": ".text"
},
{
"address": "0x8048acc",
"instruction": "call _fork",
"comments": [
"Fork child process to handle connection",
"_fork=0x80487cc"
],
"segment": ".text"
},
{
"address": "0x8048ad1",
"instruction": "mov [ebp+var_C], eax",
"segment": ".text"
},
{
"address": "0x8048ad4",
"instruction": "cmp [ebp+var_C], 0FFFFFFFFh",
"segment": ".text"
},
{
"address": "0x8048ad8",
"instruction": "jz loc_8048B21",
"comments": [
"loc_8048B21=0x8048b21",
"*loc_8048B21=0x90"
],
"segment": ".text"
},
{
"address": "0x8048ada",
"instruction": "cmp [ebp+var_C], 0",
"comments": [
"Check if this is child process"
],
"segment": ".text"
},
{
"address": "0x8048ade",
"instruction": "jnz loc_8048B11",
"comments": [
"loc_8048B11=0x8048b11",
"*loc_8048B11=0x8b 0x45 0xe8"
],
"segment": ".text"
},
{
"address": "0x8048ae0",
"instruction": "mov eax, name",
"comments": [
"name=0x804b0a0",
"*name=0x8049978"
],
"segment": ".text"
},
{
"address": "0x8048ae5",
"instruction": "mov [esp], eax",
"comments": [
"name"
],
"segment": ".text"
},
{
"address": "0x8048ae8",
"instruction": "call drop_privileges",
"comments": [
"drop_privileges=0x8048b2e"
],
"segment": ".text"
},
{
"address": "0x8048aed",
"instruction": "mov eax, [ebp+var_18]",
"segment": ".text"
},
{
"address": "0x8048af0",
"instruction": "mov [esp], eax",
"segment": ".text"
},
{
"address": "0x8048af3",
"instruction": "mov eax, [ebp+arg_4]",
"segment": ".text"
},
{
"address": "0x8048af6",
"instruction": "call eax",
"comments": [
"Call connection handler function"
],
"segment": ".text"
},
{
"address": "0x8048af8",
"instruction": "mov [ebp+status], eax",
"segment": ".text"
},
{
"address": "0x8048afb",
"instruction": "mov eax, [ebp+var_18]",
"segment": ".text"
},
{
"address": "0x8048afe",
"instruction": "mov [esp], eax",
"comments": [
"fd"
],
"segment": ".text"
},
{
"address": "0x8048b01",
"instruction": "call _close",
"comments": [
"_close=0x804879c"
],
"segment": ".text"
},
{
"address": "0x8048b06",
"instruction": "mov eax, [ebp+status]",
"segment": ".text"
},
{
"address": "0x8048b09",
"instruction": "mov [esp], eax",
"comments": [
"status"
],
"segment": ".text"
},
{
"address": "0x8048b0c",
"instruction": "call _exit",
"comments": [
"_exit=0x804883c"
],
"segment": ".text"
},
{
"address": "0x8048b11",
"instruction": "mov eax, [ebp+var_18]",
"segment": ".text",
"label": "loc_8048B11"
},
{
"address": "0x8048b14",
"instruction": "mov [esp], eax",
"comments": [
"fd"
],
"segment": ".text"
},
{
"address": "0x8048b17",
"instruction": "call _close",
"comments": [
"_close=0x804879c"
],
"segment": ".text"
},
{
"address": "0x8048b1c",
"instruction": "jmp loc_8048B22",
"comments": [
"loc_8048B22=0x8048b22",
"*loc_8048B22=0xf07d83"
],
"segment": ".text"
},
{
"address": "0x8048b1e",
"instruction": "nop ",
"segment": ".text",
"label": "loc_8048B1E"
},
{
"address": "0x8048b1f",
"instruction": "jmp loc_8048B22",
"comments": [
"loc_8048B22=0x8048b22",
"*loc_8048B22=0xf07d83"
],
"segment": ".text"
},
{
"address": "0x8048b21",
"instruction": "nop ",
"segment": ".text",
"label": "loc_8048B21"
},
{
"address": "0x8048b22",
"instruction": "cmp [ebp+var_10], 0",
"segment": ".text",
"label": "loc_8048B22"
},
{
"address": "0x8048b26",
"instruction": "jnz loc_8048AA7",
"comments": [
"loc_8048AA7=0x8048aa7",
"*loc_8048AA7=0xb8 0x0 0x0 0x0 0x0"
],
"segment": ".text"
},
{
"address": "0x8048b2c",
"instruction": "leave ",
"segment": ".text"
},
{
"address": "0x8048b2d",
"instruction": "retn ",
"segment": ".text"
}
],
"return_type": "int",
"arguments": [
{
"name": "fd",
"type": "int"
},
{
"name": "",
"type": "int"
}
]
} |
Add all the auto comments, include addresses and values when avail
14fb7cb to
dd9ac9c
Compare
|
Looks good, thanks! |
Structured function disassembly
This PR reimplements the
disassemble_functionfunction to return structured disassembly, including stack locals, segments, labels, address references, and comments.It uses the memory read functions from #82 to provide extra context (such as string decoding or value inlining).
Currently left as a draft. It should satisfy #35, however, I'm unsure if this is too verbose and if we should be more concise.
Some change details
The function now returns the following datatypes:
Example output:
{ "name": "setup_server_socket", "start_ea": "0x8048944", "return_type": null, "arguments": null, "stack_frame": [ { "name": "var_2C", "offset": "0x2c", "size": "0x2", "type": "_WORD" }, { "name": "addr", "offset": "0x38", "size": "0x10", "type": "sockaddr" }, { "name": "optval", "offset": "0x48", "size": "0x4", "type": "_DWORD" }, { "name": "fd", "offset": "0x4c", "size": "0x4", "type": "int" }, { "name": "__saved_registers", "offset": "0x58", "size": "0x4", "type": "_DWORD" }, { "name": "__return_address", "offset": "0x5c", "size": "0x4", "type": "_UNKNOWN *" }, { "name": "arg_0", "offset": "0x60", "size": "0x4", "type": "_DWORD" } ], "lines": [ { "segment": ".text", "address": "0x8048944", "label": null, "instruction": "push ebp", "comments": [ "Creates and configures a listening TCP socket" ] }, { "segment": ".text", "address": "0x8048945", "label": null, "instruction": "mov ebp, esp", "comments": [] }, { "segment": ".text", "address": "0x8048947", "label": null, "instruction": "sub esp, 58h", "comments": [] }, { "segment": ".text", "address": "0x804894a", "label": null, "instruction": "mov eax, [ebp+arg_0]", "comments": [ "Port number from argument" ] }, { "segment": ".text", "address": "0x804894d", "label": null, "instruction": "mov [ebp+var_2C], ax", "comments": [] }, { "segment": ".text", "address": "0x8048951", "label": null, "instruction": "mov [ebp+fd], 0", "comments": [] }, { "segment": ".text", "address": "0x8048958", "label": null, "instruction": "mov [ebp+optval], 1", "comments": [] }, { "segment": ".text", "address": "0x804895f", "label": null, "instruction": "mov [ebp+addr.sa_family], 2", "comments": [] }, { "segment": ".text", "address": "0x8048965", "label": null, "instruction": "movzx eax, [ebp+var_2C]", "comments": [] }, { "segment": ".text", "address": "0x8048969", "label": null, "instruction": "mov [esp], eax", "comments": [ "hostshort" ] }, { "segment": ".text", "address": "0x804896c", "label": null, "instruction": "call _htons", "comments": [ "_htons=0x80486dc" ] }, { "segment": ".text", "address": "0x8048971", "label": null, "instruction": "mov word ptr [ebp+addr.sa_data], ax", "comments": [] }, { "segment": ".text", "address": "0x8048975", "label": null, "instruction": "mov dword ptr [esp], 0", "comments": [ "hostlong" ] }, { "segment": ".text", "address": "0x804897c", "label": null, "instruction": "call _htonl", "comments": [ "_htonl=0x80487ec" ] }, { "segment": ".text", "address": "0x8048981", "label": null, "instruction": "mov dword ptr [ebp+addr.sa_data+2], eax", "comments": [] }, { "segment": ".text", "address": "0x8048984", "label": null, "instruction": "mov dword ptr [esp+4], 1", "comments": [ "Ignore SIGPIPE signals" ] }, { "segment": ".text", "address": "0x804898c", "label": null, "instruction": "mov dword ptr [esp], 11h", "comments": [ "sig" ] }, { "segment": ".text", "address": "0x8048993", "label": null, "instruction": "call _signal", "comments": [ "_signal=0x804867c" ] }, { "segment": ".text", "address": "0x8048998", "label": null, "instruction": "cmp eax, 0FFFFFFFFh", "comments": [] }, { "segment": ".text", "address": "0x804899b", "label": null, "instruction": "jnz loc_80489B1", "comments": [ "loc_80489B1=0x80489b1", "*loc_80489B1=0x6082444c7" ] }, { "segment": ".text", "address": "0x804899d", "label": null, "instruction": "mov dword ptr [esp+4], offset format", "comments": [ "format=0x80498d0", "*format=\"Unable to set SIGCHLD handler\"" ] }, { "segment": ".text", "address": "0x80489a5", "label": null, "instruction": "mov dword ptr [esp], 0FFFFFFFFh", "comments": [ "status" ] }, { "segment": ".text", "address": "0x80489ac", "label": null, "instruction": "call _err", "comments": [ "_err=0x804866c" ] }, { "segment": ".text", "address": "0x80489b1", "label": "loc_80489B1", "instruction": "mov dword ptr [esp+8], 6", "comments": [ "protocol" ] }, { "segment": ".text", "address": "0x80489b9", "label": null, "instruction": "mov dword ptr [esp+4], 1", "comments": [ "type" ] }, { "segment": ".text", "address": "0x80489c1", "label": null, "instruction": "mov dword ptr [esp], 2", "comments": [ "AF_INET, SOCK_STREAM, TCP socket" ] }, { "segment": ".text", "address": "0x80489c8", "label": null, "instruction": "call _socket", "comments": [ "_socket=0x804872c" ] }, { "segment": ".text", "address": "0x80489cd", "label": null, "instruction": "mov [ebp+fd], eax", "comments": [] }, { "segment": ".text", "address": "0x80489d0", "label": null, "instruction": "cmp [ebp+fd], 0FFFFFFFFh", "comments": [] }, { "segment": ".text", "address": "0x80489d4", "label": null, "instruction": "jnz loc_80489EA", "comments": [ "loc_80489EA=0x80489ea", "*loc_80489EA=0x4102444c7" ] }, { "segment": ".text", "address": "0x80489d6", "label": null, "instruction": "mov dword ptr [esp+4], offset aUnableToCreate", "comments": [ "aUnableToCreate=0x80498ee", "*aUnableToCreate=\"Unable to create socket\"" ] }, { "segment": ".text", "address": "0x80489de", "label": null, "instruction": "mov dword ptr [esp], 0FFFFFFFFh", "comments": [ "status" ] }, { "segment": ".text", "address": "0x80489e5", "label": null, "instruction": "call _err", "comments": [ "_err=0x804866c" ] }, { "segment": ".text", "address": "0x80489ea", "label": "loc_80489EA", "instruction": "mov dword ptr [esp+10h], 4", "comments": [ "optlen" ] }, { "segment": ".text", "address": "0x80489f2", "label": null, "instruction": "lea eax, [ebp+optval]", "comments": [] }, { "segment": ".text", "address": "0x80489f5", "label": null, "instruction": "mov [esp+0Ch], eax", "comments": [ "optval" ] }, { "segment": ".text", "address": "0x80489f9", "label": null, "instruction": "mov dword ptr [esp+8], 2", "comments": [ "Set SO_REUSEADDR socket option" ] }, { "segment": ".text", "address": "0x8048a01", "label": null, "instruction": "mov dword ptr [esp+4], 1", "comments": [ "level" ] }, { "segment": ".text", "address": "0x8048a09", "label": null, "instruction": "mov eax, [ebp+fd]", "comments": [] }, { "segment": ".text", "address": "0x8048a0c", "label": null, "instruction": "mov [esp], eax", "comments": [ "fd" ] }, { "segment": ".text", "address": "0x8048a0f", "label": null, "instruction": "call _setsockopt", "comments": [ "_setsockopt=0x80487dc" ] }, { "segment": ".text", "address": "0x8048a14", "label": null, "instruction": "cmp eax, 0FFFFFFFFh", "comments": [] }, { "segment": ".text", "address": "0x8048a17", "label": null, "instruction": "jnz loc_8048A2D", "comments": [ "loc_8048A2D=0x8048a2d", "*loc_8048A2D=0x8d 0x55 0xe0" ] }, { "segment": ".text", "address": "0x8048a19", "label": null, "instruction": "mov dword ptr [esp+4], offset aUnableToSetReu", "comments": [ "aUnableToSetReu=0x8049906", "*aUnableToSetReu=\"Unable to set reuse\"" ] }, { "segment": ".text", "address": "0x8048a21", "label": null, "instruction": "mov dword ptr [esp], 0FFFFFFFFh", "comments": [ "status" ] }, { "segment": ".text", "address": "0x8048a28", "label": null, "instruction": "call _err", "comments": [ "_err=0x804866c" ] }, { "segment": ".text", "address": "0x8048a2d", "label": "loc_8048A2D", "instruction": "lea edx, [ebp+addr]", "comments": [] }, { "segment": ".text", "address": "0x8048a30", "label": null, "instruction": "mov eax, 0", "comments": [] }, { "segment": ".text", "address": "0x8048a35", "label": null, "instruction": "mov eax, edx", "comments": [] }, { "segment": ".text", "address": "0x8048a37", "label": null, "instruction": "mov dword ptr [esp+8], 10h", "comments": [ "len" ] }, { "segment": ".text", "address": "0x8048a3f", "label": null, "instruction": "mov [esp+4], eax", "comments": [ "addr" ] }, { "segment": ".text", "address": "0x8048a43", "label": null, "instruction": "mov eax, [ebp+fd]", "comments": [] }, { "segment": ".text", "address": "0x8048a46", "label": null, "instruction": "mov [esp], eax", "comments": [ "fd" ] }, { "segment": ".text", "address": "0x8048a49", "label": null, "instruction": "call _bind", "comments": [ "_bind=0x804877c" ] }, { "segment": ".text", "address": "0x8048a4e", "label": null, "instruction": "cmp eax, 0FFFFFFFFh", "comments": [] }, { "segment": ".text", "address": "0x8048a51", "label": null, "instruction": "jnz loc_8048A67", "comments": [ "loc_8048A67=0x8048a67", "*loc_8048A67=0x14042444c7" ] }, { "segment": ".text", "address": "0x8048a53", "label": null, "instruction": "mov dword ptr [esp+4], offset aUnableToBindSo", "comments": [ "aUnableToBindSo=0x804991a", "*aUnableToBindSo=\"Unable to bind socket\"" ] }, { "segment": ".text", "address": "0x8048a5b", "label": null, "instruction": "mov dword ptr [esp], 0FFFFFFFFh", "comments": [ "status" ] }, { "segment": ".text", "address": "0x8048a62", "label": null, "instruction": "call _err", "comments": [ "_err=0x804866c" ] }, { "segment": ".text", "address": "0x8048a67", "label": "loc_8048A67", "instruction": "mov dword ptr [esp+4], 14h", "comments": [ "Listen with backlog of 20 connections" ] }, { "segment": ".text", "address": "0x8048a6f", "label": null, "instruction": "mov eax, [ebp+fd]", "comments": [] }, { "segment": ".text", "address": "0x8048a72", "label": null, "instruction": "mov [esp], eax", "comments": [ "fd" ] }, { "segment": ".text", "address": "0x8048a75", "label": null, "instruction": "call _listen", "comments": [ "_listen=0x80486bc" ] }, { "segment": ".text", "address": "0x8048a7a", "label": null, "instruction": "cmp eax, 0FFFFFFFFh", "comments": [] }, { "segment": ".text", "address": "0x8048a7d", "label": null, "instruction": "jnz loc_8048A93", "comments": [ "loc_8048A93=0x8048a93", "*loc_8048A93=0x8b 0x45 0xf4" ] }, { "segment": ".text", "address": "0x8048a7f", "label": null, "instruction": "mov dword ptr [esp+4], offset aUnableToListen", "comments": [ "aUnableToListen=0x8049930", "*aUnableToListen=\"Unable to listen on socket\"" ] }, { "segment": ".text", "address": "0x8048a87", "label": null, "instruction": "mov dword ptr [esp], 0FFFFFFFFh", "comments": [ "status" ] }, { "segment": ".text", "address": "0x8048a8e", "label": null, "instruction": "call _err", "comments": [ "_err=0x804866c" ] }, { "segment": ".text", "address": "0x8048a93", "label": "loc_8048A93", "instruction": "mov eax, [ebp+fd]", "comments": [] }, { "segment": ".text", "address": "0x8048a96", "label": null, "instruction": "leave ", "comments": [] }, { "segment": ".text", "address": "0x8048a97", "label": null, "instruction": "retn ", "comments": [] } ] }