summaryrefslogtreecommitdiffstats
path: root/sploit/symtbl.py (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-01-04Rename sploit package to nsploitMalfurious1-160/+0
Rename all affected files, references to file paths, and module imports within the code. Since this line of development represents a fork from the original sploit, a name change is seen as necessary to distinguish the projects, as well as allow them to be installed side by side. What does the "n" mean? Great question! You can think of it as meaning "new sploit" if you want, though that's not quite intended. The name is simply distinct and easy to pronounce. I had originally settled on "msploit" (something along the lines of "Malf's sploit"), but this name is too close to "metasploit" for me - and N is right next to it on the keyboard. Signed-off-by: Malfurious <m@lfurio.us>
2025-01-01symtbl: Refactor abstract IndexTbl interfaceMalfurious1-68/+44
There are some useful concepts expressed in the Symtbl class that can provide good value if applied elsewhere as well. In this particular case, I want to address the somewhat awkward relationship between Symtbl and the Payload class by providing an abstract base for both of them. I will go into more details in an upcoming commit for Payload. This patch shouldn't change any behavior for Symtbl barring perhaps its new preference of the new IndexEntry type described below. Some characteristics of Symtbl are refactored into two new interface types: IndexEntry provides "base" and implements logic supporting the use of instance objects as integers. The intent is to extend from this class when creating special types to be used in IndexTbls, Symtbls, etc. IndexTbl (extends IndexEntry) provides a unified system for attribute / element access, and acts as an abstract container where storage and lookup semantics are up to the specific implementation. Symtbl (extends IndexTbl) is now better described as an Index table, where indices represent numeric addresses. The nominal data type is int, however IndexEntries (which are int-like) may be nested to record the addresses of ROP gadgets, sub-symtbls, and perhaps more in the future. Signed-off-by: Malfurious <m@lfurio.us>
2023-03-31symtbl: Fix function docstring formattingMalfurious1-19/+19
Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-22symtbl: order symtbl iteration by offsetdusoleil1-2/+2
When iterating over a symtbl, the returned tuples should be sorted by offset. Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-19symtbl: Support offset translation for int-like objectsMalfurious1-1/+1
This fixes a bug with Symtbl's __getitem__. An object that is convertable to int should also cause __getitem__ to behave as though an int was given, and translate the object as a foreign offset. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-16arch: Move private methods to bottom of filedusoleil1-1/+1
Also check type when setting arch. Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-14symtbl: Overload __getitem__ for translating raw offsetsMalfurious1-3/+6
Can now use Symtbl subscript syntax to obtain the mapped address of a foreign offset (not a defined symbol) without having to modify the object or add a new symbol entry. Assuming a base value of 10, tbl[15] will return 25, for example. We now assert that the defined table keys are strings, to prevent the creation of entries that are now un-readable by this patch. However, this always should have been the case. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-13symtbl: Only print column headings if table is populatedMalfurious1-1/+2
QoL change - Don't print the headings if the table is empty. Just report "0 symbols" and the base address. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-13symtbl: Display all nested objects in bracketsMalfurious1-1/+1
When printing a human readable Symtbl, show all nested objects within [brackets], not just Symtbl itself. Primarily useful since more types are being developed with the intent of being stored in a Symtbl. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-03-13Prefer __repr__ for pretty-printing objectsMalfurious1-5/+1
Define human-readable string formatting for objects in repr, rather than str, as this will enable an interactive interpreter to more conveniently show this data to the user. I believe this especially makes sense in cases where __str__ doesn't perform a semantic type conversion for its class (currently, all affected cases). Scripts can still easily yield this information by using `print(object)`, as print will fallback to repr(object) when there is not an explicitly defined __str__. Furthermore, this patch still maintains backwards compatability (for the time being) of using str(object) to retrieve the information. This is because the default __str__ implementation will defer to __repr__ if provided. This made the Symtbl case of providing both of them especially redundant. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-02-24symtbl: Refactor module as an improved container type (and more)Malfurious1-51/+182
This effort was triggered by three immediate wants of the module: An improved data container interface to support things like key iteration and better key management. This is primarily wanted by the ROP module (which is still in development). The introduction of package documentation across the project. This module is now fully documented. To fix a bug in the Symtbl constructor, which would not allow a caller to supply "self" as an initial symbol name, even though it is legal in every other context. This problem was caused by the constructor's bound instance parameter sharing this name. This patch addresses all of these concerns, and also introduces some fringe / QoL improvements that were discovered during the API refactor. Element access may now be done via subscripting, as well as the previous (and still generally perferred) .attribute notation. The syntax for storing subtables within a parent Symtbl is now greatly streamlined due to some implementation-level changes to the class. You may now directly assign just a Symtbl object or a normal int, and you don't have to fuss with tuples anymore. The subtable's base is taken as its offset in the parent, and the new operator replacement for the .map() method may be used to define a desired value for the parent. This detail is actually a breaking change compared to the previous version. While not technically a bug, it is unintuitive that the previous version would not remove subtables when their offset was changed by a simple assignment - the table would just move. This patch make it such that any symbol assignment to a regular int will replace an old mounted subtable if one exists. There are now no normal instance methods on the Symtbl type (only dunder method overrides). This is to free up the available symbol namespace as much as possible. The previous methods map(), adjust(), and rebase() are now implemented as operators which, in every case, yield a new derivative object, rather than mutating the original. All operators are listed here: @ remap to absolute address + remap to relative address - remap to negated relative address >> adjust all symbol offsets upward << adjust all symbol offsets downward % rebase all symbol offsets around an absolute zero point Additionally, Symtbl objects will convert to an integer via int(), hex(), oct(), or bin(), yielding the base value. The addition of these operators presents another breaking change to the previous version. Previously, symbol adjustments or rebases affected the tracked offsets and caused symbols to shift around in linked tables as well. Since these operators now preserve the state of their source object, this is no longer the case. The amount of shift due to adjustment or rebasing is localized in a specific Symtbl instance (and is affected the the use of the related operators), however this value is inherited by derivatives of that object. There is a third breaking change caused by the use of operators as well. Previously, the map() function allowed the caller to specify that the given absolute address is not that of the table base, but of some offset in the table, from which the new base is calculated. However, the remapping operators take only a single numeric value as their right hand side operand, which is the absolute or relative address. The new intended way of accomplishing this (which is _nearly_ equivalent) is through the combined use of the rebase and remap operations: # The address of the puts() function in a libc tbl is leaked sym = sym % sym.puts @ leak aka: adjust offsets such that the known point is at the base, then move that base to the known location. The way in which this is different to what you would end up with before is that previously, following a map(abs, off) the base of the table would be accurately valued according to the known information. Now, the 'base' is considered to be the leaked value, but internal offsets are shifted such that they still resolve correctly. Finally, a few new pieces of functionality are added to build out the container API: - symbol key deletion - iteration over symbol:offset pairs - can now check for symbol existence with the "in" keyword - len(symtbl) returns the number of symbols defined Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
2023-02-24symtbl: Rename file to match class nameMalfurious1-0/+53
I assume that the preferred style is to leave one major class each to a file. In this case, synchronize the names of the Symtbl class and its containing module. Per PEP8, the module is lowercase, and the class remains Pascal case. If other memory-oriented utilities are introduced in the future, we may wish to move them, as well as Symtbl, back into a subpackage named 'mem'. Signed-off-by: Malfurious <m@lfurio.us> Signed-off-by: dusoleil <howcansocksbereal@gmail.com>