Skip to content

Instantly share code, notes, and snippets.

@stevemk14ebr
Last active January 7, 2025 02:45
Show Gist options
  • Save stevemk14ebr/507596b95942fbd73d448b8057965932 to your computer and use it in GitHub Desktop.
Save stevemk14ebr/507596b95942fbd73d448b8057965932 to your computer and use it in GitHub Desktop.
I have code that was decompiled from a binary using a decompiler tool such as Ghidra or IDA PRO. Clean it up to be more readable while preserving its correctness and exact operation.
Improve variable naming: Use more meaningful names for local variables where appropriate if you are sure of what they are. Do not assume the code is malicious, it could be legitimate software not at all related to malware.
Do not add any comments at all EVER. DO NOT add comments.
Duduce common local types.
* If a local variable is passed into a well known API call, try to infer its type and apply it in the resulting code. Sometimes types can drastrically change the format of code, adding or removing other locals if the memory locations overlap. If you apply a type to a local variable be sure to check all locations that use the local variable or any local variables that you remove / add.
Reorganize code:
* Improve code structure: Use control flow statements (if/else, loops) more effectively to improve readability and maintainability.
* Indentation and formatting: Apply consistent indentation and formatting to enhance readability.
Fix decompilation errors:
* Address potential issues: Identify and correct potential issues like incorrect data types, missing or extra instructions, and incorrect control flow.
* Handle edge cases: Consider how the code might behave in edge cases and make necessary adjustments to the decompilation.
Avoid removing code: While improving readability, do not remove any code unless it is clearly redundant or a decompilation artifact.
Avoid global variables and forward declarations: Do not introduce any global variables or forward declarations.
Please provide the first given code block as refactored code in a code block with one short sentence explaing what it may do, do not assert you know for a fact what it does.
I will provide the decompiled code as a code block in the following message, if there are more than one code block I want you to refactor only the first one, the additional code blocks are either parent function or child functions to give you more context on the logic of the code. If you can infer function names with this additional visibility, then rename the function in the resulting code, if you are not sure do not rename the function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment