sigmaker 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sigmaker-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mahmoud Rusty Abdelkader
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.1
2
+ Name: sigmaker
3
+ Version: 0.1.0
4
+ Summary: IDA Pro plugin to generate signatures for code
5
+ Author: Mahmoud Abdelkader
6
+ Requires-Python: >=3.10
7
+ Provides-Extra: dev
8
+ License-File: LICENSE
@@ -0,0 +1,97 @@
1
+ # Signature Maker Plugin for IDA Pro 9.0+
2
+
3
+ [![ida-sigmaker tests](https://github.com/mahmoudimus/ida-sigmaker/actions/workflows/python.yml/badge.svg)](https://github.com/mahmoudimus/ida-sigmaker/actions/workflows/python.yml)
4
+
5
+ An IDA Pro 9.0+ cross-platform signature maker plugin that works on MacOS/Linux/Windows. The primary goal of this plugin is to work with future versions of IDA without needing to compile against the IDA SDK as well as to allow for easier community contributions.
6
+
7
+ ## What is a "sigmaker"?
8
+
9
+ Sigmaker stands for "signature maker." It enables users to create unique binary pattern signatures that can identify specific addresses or routines within a binary, even after the binary has been updated.
10
+
11
+ In malware analysis or binary reverse engineering, a common challenge is pinpointing an important address, such as a function or global variable. However, when the binary is updated, all the effort spent identifying these locations can be lost if their addresses change.
12
+
13
+ To preserve this work, reverse engineers take advantage of the fact that most programs do not change drastically between updates. While some functions or data may be modified, much of the binary remains the same. Most often, previously identified addresses are simply relocated. This is where `sigmaker` comes in.
14
+
15
+ Sigmaker lets you create unique patterns to track important parts of a program, making your analysis more resilient to updates. By generating signatures for specific functions, data references, or other critical locations, you can quickly relocate these points in a new version of the binary, saving time and effort in future reverse engineering tasks.
16
+
17
+ ## Requirements
18
+
19
+ - IDA Pro 9.0+
20
+ - IDA Python
21
+ - Python 3.10+
22
+
23
+ ## Installation
24
+
25
+ sigmaker's main value proposition is its cross-platform (Windows, macOS, Linux) Python 3 support. It uses zero third party dependencies, making the code both portable and easy to install.
26
+
27
+ - Copy `sigmaker.py` into the /plugins/ folder to the plugin directory!
28
+ - Restart your disassembler.
29
+
30
+ That's it!
31
+
32
+ ### Need to find your plugin directory?
33
+
34
+ From IDA's Python console run the following command to find its plugin directory:
35
+
36
+ ```python
37
+ import idaapi, os; print(os.path.join(idaapi.get_user_idadir(), "plugins"))
38
+ ```
39
+
40
+ ### Where and what is my default user directory?
41
+
42
+ The user directory is a location where IDA stores some of the global settings and which can be used for some additional customization.
43
+ Default location:
44
+
45
+ - On Windows: `%APPDATA%/Hex-Rays/IDA Pro`
46
+ - On Linux and Mac: `$HOME/.idapro`
47
+
48
+ ## Usage
49
+
50
+ In disassembly view, select a line you want to generate a signature for, and press
51
+ **CTRL+ALT+S**
52
+ ![](https://i.imgur.com/b4MKkca.png)
53
+
54
+ The generated signature will be printed to the output console, as well as copied to the clipboard:
55
+ ![](https://i.imgur.com/mTFbKce.png)
56
+
57
+ ___
58
+
59
+ | Signature type | Example preview |
60
+ | --- | ----------- |
61
+ | IDA Signature | E8 ? ? ? ? 45 33 F6 66 44 89 34 33 |
62
+ | x64Dbg Signature | E8 ?? ?? ?? ?? 45 33 F6 66 44 89 34 33 |
63
+ | C Byte Array Signature + String mask | \xE8\x00\x00\x00\x00\x45\x33\xF6\x66\x44\x89\x34\x33 x????xxxxxxxx |
64
+ | C Raw Bytes Signature + Bitmask | 0xE8, 0x00, 0x00, 0x00, 0x00, 0x45, 0x33, 0xF6, 0x66, 0x44, 0x89, 0x34, 0x33 0b1111111100001 |
65
+
66
+ ___
67
+
68
+ ### Finding XREFs
69
+
70
+ Generating code Signatures by data or code xrefs and finding the shortest ones is also supported:
71
+ ![](https://i.imgur.com/P0VRIFQ.png)
72
+
73
+ ___
74
+
75
+ ### Signature searching
76
+
77
+ Searching for Signatures works for supported formats:
78
+
79
+ ![](https://i.imgur.com/lD4Zfwb.png)
80
+
81
+ Just enter any string containing your Signature, it will automatically try to figure out what kind of Signature format is being used:
82
+
83
+ ![](https://i.imgur.com/oWMs7LN.png)
84
+
85
+ Currently, all output formats you can generate are supported.
86
+
87
+ Match(es) of your signature will be printed to console:
88
+
89
+ ![](https://i.imgur.com/Pe4REkX.png)
90
+
91
+ ## Acknowledgements
92
+
93
+ Thank you to to [@A200K](https://github.com/A200K)'s [IDA-Pro-SigMaker](https://github.com/A200K/IDA-Pro-SigMaker) plugin which served as an inspiration and the initial port of this plugin.
94
+
95
+ ## Contact
96
+
97
+ ping me on x [@mahmoudimus](https://x.com/mahmoudimus) or you may contact me from any one of the addresses on [mahmoudimus.com](https://mahmoudimus.com).
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel", "cython>=3.0.11"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sigmaker"
7
+ requires-python = ">= 3.10"
8
+ version = "0.1.0"
9
+ authors = [{ name = "Mahmoud Abdelkader" }]
10
+ description = "IDA Pro plugin to generate signatures for code"
11
+ dependencies = []
12
+
13
+ [project.optional-dependencies]
14
+ dev = []
15
+
16
+ [tool.setuptools]
17
+ package-dir = { "" = "src" }
18
+
19
+ [tool.setuptools.packages.find]
20
+ where = ["src"]
21
+
22
+ [tool.cyright]
23
+ include = ["*.py", "src/", "include/"]
24
+ exclude = ["build/", "docs/", "scripts/", "samples/", "tests/"]
25
+
26
+ reportGeneralTypeIssues = true
27
+ reportOptionalSubscript = true
28
+ reportOptionalMemberAccess = true
29
+ reportOptionalCall = true
30
+ reportOptionalIterable = true
31
+ reportOptionalContextManager = true
32
+ reportOptionalOperand = true
33
+ reportMissingModuleSource = true
34
+
35
+ [tool.cython-lint]
36
+ max-line-length = 88
37
+ ignore = ['E503', 'E504']
38
+ exclude = []
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,218 @@
1
+ """Build script for the IDA Pro sigmaker Cython module.
2
+
3
+ This ``setup.py`` detects the host platform and architecture in order to
4
+ select appropriate compilation and linkage flags.
5
+ The build expects the IDA SDK to be installed and accessible via the
6
+ environment variable ``IDA_SDK``.
7
+ """
8
+
9
+ import functools
10
+ import os
11
+ import pathlib
12
+ import platform
13
+ import re
14
+
15
+ from Cython.Build import cythonize
16
+ from setuptools import Extension, find_packages, setup
17
+
18
+ # ---------------------------------------------------------------------------
19
+ # Platform detection
20
+ # Use the host system and architecture to adjust compiler options.
21
+ OSTYPE = platform.system()
22
+ ARCH = platform.processor() or platform.machine()
23
+ x64 = platform.architecture()[0] == "64bit"
24
+ COMPILER_OPTIMIZATION_LEVEL = re.compile(r"-O[0-3]\b")
25
+
26
+
27
+ if ARCH == "ppc64le":
28
+ LIBRARY = "ppc64le"
29
+ elif ARCH == "aarch64":
30
+ LIBRARY = "aarch64"
31
+ elif ARCH == "arm" or ARCH == "arm64":
32
+ LIBRARY = "arm64"
33
+ else: # 'AMD64', 'x86_64', 'i686', 'i386'
34
+ LIBRARY = "amd64" if x64 else "intel32"
35
+
36
+ if OSTYPE == "Darwin":
37
+ LIBRARY_EXT = ".dylib"
38
+ elif OSTYPE == "Linux":
39
+ LIBRARY_EXT = ".so"
40
+ else:
41
+ LIBRARY_EXT = ".dll"
42
+
43
+
44
+ def compile_args(debug_mode=False):
45
+ """Return platform-specific compilation arguments."""
46
+ match OSTYPE:
47
+ case "Windows":
48
+ if debug_mode:
49
+ debug_flags = ["/Z7", "/Od"]
50
+ # For MSVC: `/TP` tells the compiler to treat sources as C++
51
+ # files and `/EHa` enables asynchronous exception handling.
52
+ return ["/TP", "/EHa"] + debug_flags
53
+ case "Linux":
54
+ # Suppress a few warnings that are often triggered by IDA
55
+ # headers. These are the same warnings ignored in amplpy's
56
+ # build script【561865107149785†L125-L153】.
57
+ if debug_mode:
58
+ debug_flags = ["-g", "-O0", "-Wall", "-Wextra", "-Wpedantic"]
59
+ return [
60
+ "-Wno-stringop-truncation",
61
+ "-Wno-catch-value",
62
+ "-Wno-unused-variable",
63
+ ] + debug_flags
64
+ case "Darwin":
65
+ # On macOS specify the minimum supported version and optionally
66
+ # enable debug symbols when the DEBUG environment variable is set.
67
+ ignore_warnings = [
68
+ "-Wno-unused-variable",
69
+ "-Wno-nullability-completeness",
70
+ "-Wno-sign-compare",
71
+ "-Wno-logical-op-parentheses",
72
+ "-Wno-varargs",
73
+ "-Wno-unused-private-field",
74
+ "-Wno-c99-extensions",
75
+ "-Wno-nested-anon-types",
76
+ "-Wno-gnu-anonymous-struct",
77
+ "-Wno-nullability-extension",
78
+ "-Wno-extra-semi",
79
+ ]
80
+ debug_flags = []
81
+ if debug_mode:
82
+ debug_flags = [
83
+ "-g",
84
+ "-fno-omit-frame-pointer",
85
+ "-O0",
86
+ "-ggdb",
87
+ "-UNDEBUG",
88
+ "-Wall",
89
+ "-Wextra",
90
+ "-Wpedantic",
91
+ # Cython is not deprecation-proof
92
+ "-Wno-deprecated-declarations",
93
+ ]
94
+ # If DEBUG is set, ensure CFLAGS has -O0 (override any -O[0-3])
95
+ cflags = os.environ.get("CFLAGS", "")
96
+ # Remove any -O[0-3] flags
97
+ cflags = COMPILER_OPTIMIZATION_LEVEL.sub("", cflags)
98
+ # Add -O0 at the beginning (or just set if empty)
99
+ cflags = "-O0 " + cflags.strip()
100
+ os.environ["CFLAGS"] = cflags.strip()
101
+ return ["-mmacosx-version-min=10.9"] + debug_flags + ignore_warnings
102
+ case _:
103
+ # Default: no extra flags
104
+ return []
105
+
106
+
107
+ def link_args(debug_mode=False):
108
+ """Return platform-specific linker arguments."""
109
+ debug_flags = []
110
+ match OSTYPE:
111
+ case "Darwin":
112
+ # Use @loader_path to encode a relative rpath. The placeholder
113
+ # ``{rpath}`` will be substituted at runtime below.
114
+ rpath = os.path.join("lib")
115
+ if debug_mode:
116
+ debug_flags = ["-g"]
117
+ return [
118
+ "-Wl,-headerpad_max_install_names,-rpath,@loader_path/" + rpath
119
+ ] + debug_flags
120
+ case "Linux":
121
+ rpath = os.path.join("lib")
122
+ if debug_mode:
123
+ debug_flags = ["-g"]
124
+ return ["-Wl,-rpath,$ORIGIN/" + rpath] + debug_flags
125
+ case "Windows":
126
+ if debug_mode:
127
+ return ["/DEBUG"]
128
+ return []
129
+ case _:
130
+ return []
131
+
132
+
133
+ def using_ida_sdk(include_dirs, library_dirs):
134
+ IDA_SDK = pathlib.Path(os.environ.get("IDA_SDK", "/opt/ida/9/sdk"))
135
+ if not IDA_SDK.exists():
136
+ raise FileNotFoundError(f"IDA SDK not found at {IDA_SDK}")
137
+ include_dirs.append(IDA_SDK / "include")
138
+ library_dirs.append(IDA_SDK / "lib")
139
+
140
+ match OSTYPE:
141
+ case "Windows":
142
+ library_dirs.append(IDA_SDK / "lib" / "x64_win_vc_64")
143
+ library_dirs.append(IDA_SDK / "lib" / "x64_win_qt")
144
+ case "Darwin":
145
+ if LIBRARY == "arm64" or LIBRARY == "aarch64":
146
+ library_dirs.append(IDA_SDK / "lib" / "arm64_mac_clang_64")
147
+ else:
148
+ library_dirs.append(IDA_SDK / "lib" / "x64_mac_clang_64")
149
+ case "Linux":
150
+ library_dirs.append(IDA_SDK / "lib" / "x64_linux_gcc_64")
151
+ case _:
152
+ pass
153
+
154
+
155
+ def ext_modules(with_ida_sdk=False, debug_mode=False):
156
+ include_dirs = [
157
+ pathlib.Path(__file__).parent / "include",
158
+ ]
159
+ library_dirs = []
160
+ libraries = []
161
+ if with_ida_sdk:
162
+ using_ida_sdk(include_dirs, library_dirs)
163
+
164
+ include_paths = [str(path) for path in include_dirs]
165
+ library_paths = [str(path) for path in library_dirs]
166
+
167
+ modules = []
168
+ macros: list[tuple[str, str | None]] = [("__EA64__", "1")] if x64 else []
169
+ if debug_mode:
170
+ # Profiling requires special macro directives
171
+ macros.append(("CYTHON_TRACE", "1"))
172
+ macros.append(("CYTHON_CLINE_IN_TRACEBACK", "1"))
173
+ macros.append(("CYTHON_CLINE_IN_TRACEBACK_RUNTIME", "1"))
174
+ macros.append(("CYTHON_USE_SYS_MONITORING", "1"))
175
+
176
+ partialed_cythonize = functools.partial(
177
+ cythonize,
178
+ compiler_directives={
179
+ "language_level": "3",
180
+ "binding": True,
181
+ "embedsignature": True,
182
+ "boundscheck": False,
183
+ "wraparound": False,
184
+ # these are enabled for debugging only
185
+ "profile": debug_mode,
186
+ "linetrace": debug_mode,
187
+ },
188
+ annotate=debug_mode,
189
+ gdb_debug=debug_mode,
190
+ )
191
+ modules += partialed_cythonize(
192
+ Extension(
193
+ "*",
194
+ ["src/**/*.pyx"],
195
+ language="c++",
196
+ include_dirs=include_paths,
197
+ library_dirs=library_paths,
198
+ libraries=libraries,
199
+ extra_compile_args=compile_args(debug_mode),
200
+ extra_link_args=link_args(debug_mode),
201
+ define_macros=macros,
202
+ )
203
+ )
204
+
205
+ return modules
206
+
207
+
208
+ DEBUG_MODE = os.environ.get("DEBUG", "0") == "1"
209
+ setup(
210
+ name="ida-sigmaker",
211
+ version="0.1.0",
212
+ description="IDA Pro plugin to generate signatures for code",
213
+ ext_modules=ext_modules(with_ida_sdk=False, debug_mode=DEBUG_MODE),
214
+ packages=find_packages(include=("sigmaker*",)),
215
+ package_dir={"": "src"},
216
+ python_requires=">=3.10",
217
+ zip_safe=False,
218
+ )