author
int64
658
755k
date
stringlengths
19
19
timezone
int64
-46,800
43.2k
hash
stringlengths
40
40
message
stringlengths
5
490
mods
list
language
stringclasses
20 values
license
stringclasses
3 values
repo
stringlengths
5
68
original_message
stringlengths
12
491
718,767
19.04.2021 21:07:00
-10,800
c090fc40ea60aa5ade7d83f17cf5d9cbece662fb
FIX Issue added check to prevent divide by zero error in "printDiscoveredStats".
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -815,7 +815,8 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nnumPointers,\nnumVtables) = self.getDiscoveredInfo()\n- self.vprint(\"Percentage of discovered executable surface area: %.1f%% (%s / %s)\" % (disc*100.0/(disc+undisc), disc, disc+undisc))\n+ percentage = disc*100.0/(disc+undisc) if disc or undisc else 0\n+ self.vprint(\"Percentage of discovered executable surface area: %.1f%% (%s / %s)\" % (percentage, disc, disc+undisc))\nself.vprint(\" Xrefs/Blocks/Funcs: (%s / %s / %s)\" % (numXrefs, numBlocks, numFuncs))\nself.vprint(\" Locs, Ops/Strings/Unicode/Nums/Ptrs/Vtables: (%s: %s / %s / %s / %s / %s / %s)\" % (numLocs, numOps, numStrings, numUnis, numNumbers, numPointers, numVtables))\n" } ]
Python
Apache License 2.0
vivisect/vivisect
FIX Issue #391, added check to prevent divide by zero error in "printDiscoveredStats". (#392)
718,765
03.05.2021 16:57:53
14,400
58e87801a405e8d4f56f2a435ff30386572b4dff
Prepare for v1.0.2 release
[ { "change_type": "MODIFY", "old_path": ".bumpversion.cfg", "new_path": ".bumpversion.cfg", "diff": "[bumpversion]\n-current_version = 1.0.1\n+current_version = 1.0.2\ncommit = True\ntag = True\ntag_message =\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "Vivisect Changelog\n******************\n+v1.0.2 - 2021-05-02\n+===================\n+\n+Features\n+--------\n+- Refactor and update the posix impapi\n+ (`#390 <https://github.com/vivisect/vivisect/pull/390>`_)\n+\n+Fixes\n+-----\n+- Ancient visgraph bug\n+ (`#387 <https://github.com/vivisect/vivisect/pull/387>`_)\n+- Easier version engineering\n+ (`#388 <https://github.com/vivisect/vivisect/pull/388>`_)\n+- Remove Travis CI config and fully cut over to Circle CI\n+ (`#389 <https://github.com/vivisect/vivisect/pull/389>`_)\n+- Add check to prevent divide by zero in print stats\n+ (`#392 <https://github.com/vivisect/vivisect/pull/392>`_)\n+- Fix SaveToWorkspaceServer\n+ (`#393 <https://github.com/vivisect/vivisect/pull/393>`_)\n+- Intel emulator bug fixes\n+ (`#394 <https://github.com/vivisect/vivisect/pull/394>`_)\n+- Tests for intel emulator and more fixes\n+ (`#395 <https://github.com/vivisect/vivisect/pull/395>`_)\n+\n+\nv1.0.1 - 2021-04-05\n===================\n" }, { "change_type": "MODIFY", "old_path": "README.md", "new_path": "README.md", "diff": "@@ -103,7 +103,6 @@ be loadable in python3 vivisect.\n## Build Status\n[![CircleCI](https://circleci.com/gh/vivisect/vivisect/tree/master.svg?style=svg)](https://circleci.com/gh/vivisect/vivisect/tree/master)\n-[![Build Status](https://travis-ci.org/vivisect/vivisect.svg?branch=master)](https://travis-ci.org/vivisect/vivisect)\n## Extending Vivisect / Vdb\n" }, { "change_type": "MODIFY", "old_path": "setup.py", "new_path": "setup.py", "diff": "from setuptools import find_packages, setup\nfrom os import path\n-VERSION = '1.0.1'\n+VERSION = '1.0.2'\ndirn = path.abspath(path.dirname(__file__))\nwith open(path.join(dirn, 'README.md'), 'r') as fd:\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -2291,6 +2291,6 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these yourself\n-version = (1, 0, 1)\n+version = (1, 0, 2)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -3086,6 +3086,6 @@ def getVivPath(*pathents):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these directly\n-version = (1, 0, 1)\n+version = (1, 0, 2)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Prepare for v1.0.2 release (#398)
718,768
06.05.2021 09:54:12
21,600
1cd994946a3ca7d43ed7e1cb1146a27c2f499181
ci: check style via black and isort see
[ { "change_type": "ADD", "old_path": null, "new_path": ".github/workflows/style.yml", "diff": "+name: style\n+\n+on:\n+ push:\n+ branches: [ master ]\n+ pull_request:\n+ branches: [ master ]\n+\n+jobs:\n+ code_style:\n+ runs-on: ubuntu-latest\n+ steps:\n+ - name: Checkout viv\n+ uses: actions/checkout@v2\n+ - name: Set up Python 3.8\n+ uses: actions/setup-python@v2\n+ with:\n+ python-version: 3.8\n+ - name: Install dependencies\n+ run: pip install 'isort==5.*' black\n+ - name: Lint with isort\n+ run: isort --profile black --length-sort --line-width 120 -c .\n+ - name: Lint with black\n+ run: black -l 120 --check .\n" } ]
Python
Apache License 2.0
vivisect/vivisect
ci: check style via black and isort (#356) see #294 Co-authored-by: James Gross <45212823+rakuy0@users.noreply.github.com>
718,765
31.07.2021 00:09:44
14,400
6de41d2f238ec4531ae0f85b57ea9d11ac8d5f9e
Fix vstruct number issue Squash a few bugs in vstruct related to negative numbers and unformatted values.
[ { "change_type": "MODIFY", "old_path": "vivisect/tests/teststruct.py", "new_path": "vivisect/tests/teststruct.py", "diff": "@@ -28,4 +28,7 @@ class StructTest(unittest.TestCase):\nself.assertEqual(vs.foo, 0x03020100)\nself.assertEqual(vs.bar, 0x07060504)\nself.assertEqual(vs.baz, 0x0b0a0908)\n- self.assertEqual(vs.biz, 0xfffefdfc)\n+ self.assertEqual(vs.biz, -0x010204)\n+\n+ fd.seek(0)\n+ self.assertEqual(vs.vsEmit(), fd.read())\n" }, { "change_type": "MODIFY", "old_path": "vstruct/primitives.py", "new_path": "vstruct/primitives.py", "diff": "@@ -123,16 +123,33 @@ class v_prim(v_base):\nnum_fmts = {\n+ # big endian unsigned\n(True, 1): '>B',\n(True, 2): '>H',\n(True, 4): '>I',\n(True, 8): '>Q',\n+\n+ # little endian unsigned\n(False, 1): '<B',\n(False, 2): '<H',\n(False, 4): '<I',\n(False, 8): '<Q',\n}\n+signed_fmts = {\n+ # big endian signed\n+ (True, 1): '>b',\n+ (True, 2): '>h',\n+ (True, 4): '>i',\n+ (True, 8): '>q',\n+\n+ # little endian signed\n+ (False, 1): '<b',\n+ (False, 2): '<h',\n+ (False, 4): '<i',\n+ (False, 8): '<q',\n+}\n+\nclass v_number(v_prim):\n_vs_length = 1\n@@ -140,13 +157,13 @@ class v_number(v_prim):\ndef __init__(self, value=0, bigend=False, enum=None):\nv_prim.__init__(self)\nself._vs_bigend = bigend\n- self._vs_value = value\nself._vs_enum = enum\nself._vs_length = self.__class__._vs_length\nself._vs_fmt = num_fmts.get((bigend, self._vs_length))\n# TODO: could use envi.bits, but do we really want to dep on envi?\nself.maxval = (2 ** (8 * self._vs_length)) - 1\n+ self.vsSetValue(value)\ndef vsGetValue(self):\nreturn self._vs_value\n@@ -171,7 +188,7 @@ class v_number(v_prim):\nelse:\nr = []\nfor i in range(self._vs_length):\n- r.append(ord(fbytes[offset + i]))\n+ r.append(fbytes[offset + i])\nif not self._vs_bigend:\nr.reverse()\n@@ -328,13 +345,13 @@ class v_number(v_prim):\nclass v_snumber(v_number):\n_vs_length = 1\n- def __init__(self, value=0, bigend=False):\n- v_number.__init__(self, value=value, bigend=bigend)\n-\n- # TODO: could use envi.bits, but do we really want to dep on envi?\n+ def __init__(self, value=0, bigend=False, enum=None):\nsmaxval = (2**((8 * self._vs_length)-1)) - 1\nself.smask = smaxval + 1\n+ v_number.__init__(self, value=value, bigend=bigend, enum=enum)\n+ self._vs_fmt = signed_fmts.get((bigend, self._vs_length))\n+\ndef vsSetValue(self, value):\nvalue = value & self.maxval\nif value & self.smask:\n" }, { "change_type": "MODIFY", "old_path": "vstruct/tests/testbasic.py", "new_path": "vstruct/tests/testbasic.py", "diff": "@@ -299,3 +299,44 @@ class VStructTest(unittest.TestCase):\ns.vsParse(bytez)\nself.assertEqual(s.vsGetValue(), \"accelerator.dll\")\nself.assertEqual(s.vsEmit(), b'a\\x00c\\x00c\\x00e\\x00l\\x00e\\x00r\\x00a\\x00t\\x00o\\x00r\\x00.\\x00d\\x00l\\x00l\\x00\\x00\\x00')\n+\n+ def test_unsigned(self):\n+ s = v_uint16(value=17)\n+ byts = s.vsEmit()\n+ self.assertEqual(b'\\x11\\x00', byts)\n+\n+ new = v_uint16()\n+ new.vsParse(byts)\n+ self.assertEqual(new.vsEmit(), s.vsEmit())\n+\n+ # test class that skips by having a real format\n+ class v_silly(v_number):\n+ _vs_builder = True\n+ _vs_length = 5\n+\n+ num = v_silly(value=1947824, bigend=True)\n+ byts = num.vsEmit()\n+ self.assertEqual(b'\\x00\\x00\\x1d\\xb8\\xb0', byts)\n+\n+ othr = v_silly(bigend=True)\n+ othr.vsParse(byts)\n+ self.assertEqual(othr, num)\n+\n+ def test_signed(self):\n+ s = v_int16(value=-1)\n+ self.assertEqual(b'\\xff\\xff', s.vsEmit())\n+\n+ s.vsSetValue(1)\n+ self.assertEqual(b'\\x01\\x00', s.vsEmit())\n+\n+ s = v_int16(value=-1, bigend=True)\n+ self.assertEqual(b'\\xff\\xff', s.vsEmit())\n+\n+ s.vsSetValue(1)\n+ self.assertEqual(b'\\x00\\x01', s.vsEmit())\n+\n+ s = v_int32(value=32)\n+ self.assertEqual(b'\\x20\\x00\\x00\\x00', s.vsEmit())\n+\n+ s = v_int32(value=-32)\n+ self.assertEqual(b'\\xe0\\xff\\xff\\xff', s.vsEmit())\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Fix vstruct number issue (#412) Squash a few bugs in vstruct related to negative numbers and unformatted values.
718,768
10.08.2021 12:18:23
21,600
2179f686d3fcc4995c3ca503f075f890f3eeec2a
pe: better handle invalid export filename if cannot be parsed, return None as documented. decode as ASCII, as documented by Microsoft. closes
[ { "change_type": "MODIFY", "old_path": "PE/__init__.py", "new_path": "PE/__init__.py", "diff": "@@ -454,7 +454,13 @@ class PE(object):\n'''\nif self.IMAGE_EXPORT_DIRECTORY is not None:\nrawname = self.readAtRva(self.IMAGE_EXPORT_DIRECTORY.Name, 32)\n- return rawname.split(b'\\x00')[0].decode('utf-8')\n+ if not rawname:\n+ return None\n+\n+ try:\n+ return rawname.partition(b'\\x00')[0].decode('ascii')\n+ except UnicodeDecodeError:\n+ return None\nreturn None\ndef getImports(self):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
pe: better handle invalid export filename (#426) if cannot be parsed, return None as documented. decode as ASCII, as documented by Microsoft. closes #425
718,765
10.08.2021 14:40:57
14,400
6453b76b9946239ef7603294d6eac2ac3f151837
Change amd64 symboliks callconv class declaration Reorder Amd64 symboliks callconv declaration to avoid exceptions
[ { "change_type": "MODIFY", "old_path": "vivisect/symboliks/archs/amd64.py", "new_path": "vivisect/symboliks/archs/amd64.py", "diff": "@@ -212,10 +212,10 @@ class Amd64SymbolikTranslator(vsym_i386.IntelSymbolikTranslator):\nclass Amd64ArgDefSymEmu(vsym_i386.ArgDefSymEmu):\n__xlator__ = Amd64SymbolikTranslator\n-class MSx64CallSym(e_amd64.MSx64Call, vsym_callconv.SymbolikCallingConvention):\n+class MSx64CallSym(vsym_callconv.SymbolikCallingConvention, e_amd64.MSx64Call):\n__argdefemu__ = Amd64ArgDefSymEmu\n-class SysVAmd64CallSym(e_amd64.SysVAmd64Call, vsym_callconv.SymbolikCallingConvention):\n+class SysVAmd64CallSym(vsym_callconv.SymbolikCallingConvention, e_amd64.SysVAmd64Call):\n__argdefemu__ = Amd64ArgDefSymEmu\nmsx64callsym = MSx64CallSym()\n" }, { "change_type": "MODIFY", "old_path": "vivisect/symboliks/common.py", "new_path": "vivisect/symboliks/common.py", "diff": "@@ -2,7 +2,6 @@ import hashlib\nimport operator\nimport functools\nimport itertools\n-import collections\nimport vstruct\nimport envi.bits as e_bits\n" }, { "change_type": "MODIFY", "old_path": "vivisect/symboliks/tests/test_intel.py", "new_path": "vivisect/symboliks/tests/test_intel.py", "diff": "import unittest\n+import vivisect.const as v_const\n+\n+import vivisect.tools.graphutil as v_t_graph\n+\nimport vivisect.symboliks.archs.i386 as i386sym\nimport vivisect.symboliks.analysis as v_s_analysis\n@@ -25,6 +29,7 @@ class IntelSymTests(unittest.TestCase):\n@classmethod\ndef setUpClass(cls):\ncls.i386_vw = helpers.getTestWorkspace('linux', 'i386', 'vdir.llvm')\n+ #cls.gcc_vw = helpers.getTestWorkspace('linux', 'amd64', 'gcc-7')\ndef test_constraints(self):\nfva = 0x080509e0\n@@ -165,3 +170,23 @@ class IntelSymTests(unittest.TestCase):\n]\nfor ret, effects in sctx.getSymbolikOutputs(fva):\nself.assertTrue((ret, effects) in out, msg='(%s, %s) is not in the symbolik outputs' % (ret, effects))\n+\n+ def SKIPtest_symbolik_gcc_subchildren(self):\n+ '''\n+ So before intify in vivisect/symboliks/common.py, this would bomb out on int has no\n+ attribute \"kids\" because the dellocate callspace function wasn't properly marshalling\n+ argc dellocation as Const() (and instead as raw ints)\n+\n+ This is here mostly for codification purposes, since actually running this consumes\n+ more RAM than CI can handle.\n+ '''\n+ vw = self.gcc_vw\n+ fva = 0x00406ad6\n+ sctx = v_s_analysis.getSymbolikAnalysisContext(vw, consolve=True)\n+ graph = sctx.getSymbolikGraph(fva)\n+ for path in v_t_graph.getLongPath(graph):\n+ for emu, effects in sctx.getSymbolikPaths(fva, paths=[path, ], graph=graph):\n+ break\n+\n+ calls = [x for x in effects if x.efftype == v_const.EFFTYPE_CALLFUNC]\n+ self.assertEqual(len(calls), 26)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Change amd64 symboliks callconv class declaration (#413) Reorder Amd64 symboliks callconv declaration to avoid exceptions
718,770
12.08.2021 06:48:51
14,400
ad6fbba99a6e82ddefbbf8137e7e4e450fe5fc11
impapi windows/arm and winkern/arm
[ { "change_type": "ADD", "old_path": null, "new_path": "vivisect/impapi/windows/arm.py", "diff": "+import vivisect.impapi.windows.i386 as v_w_i386\n+apitypes = dict(v_w_i386.apitypes)\n+\n+api = {\n+}\n+\n+i386_omits = set([\n+ 'ntdll.seh3_prolog',\n+ 'ntdll.seh4_prolog',\n+ 'ntdll.seh4_gs_prolog',\n+ 'ntdll.seh3_epilog',\n+ 'ntdll.seh4_epilog',\n+ 'ntdll.eh_prolog',\n+ 'ntdll.gs_prolog',\n+])\n+\n+for normname,(rtype,rname,cconv,cname,cargs) in v_w_i386.api.items():\n+ if normname in i386_omits:\n+ continue\n+\n+ api[normname] = (rtype,rname,'armcall',cname,cargs)\n+\n" }, { "change_type": "ADD", "old_path": null, "new_path": "vivisect/impapi/winkern/arm.py", "diff": "+import vivisect.impapi.winkern.i386 as v_k_i386\n+\n+apitypes = dict(v_k_i386.apitypes)\n+\n+api = {}\n+for normname, (rtype, rname, cconv, cname, cargs) in v_k_i386.api.items():\n+ api[normname] = (rtype, rname, 'armcall', cname, cargs)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testimpapi.py", "new_path": "vivisect/tests/testimpapi.py", "diff": "@@ -14,9 +14,16 @@ class ImpApiTest(unittest.TestCase):\nimp = viv_impapi.getImportApi('windows','i386')\nself.assertEqual( imp.getImpApiCallConv('ntdll.RtlAllocateHeap'), 'stdcall')\n+ imp = viv_impapi.getImportApi('windows','arm')\n+ self.assertEqual( imp.getImpApiCallConv('ntdll.RtlAllocateHeap'), 'armcall')\n+\n#def test_impapi_posix(self):\n#imp = viv_impapi.getImpApi('windows','i386')\ndef test_impapi_winkern(self):\nimp = viv_impapi.getImportApi('winkern','i386')\nself.assertEqual( imp.getImpApiCallConv('ntoskrnl.ObReferenceObjectByHandle'), 'stdcall')\n+\n+ imp = viv_impapi.getImportApi('winkern','arm')\n+ self.assertEqual( imp.getImpApiCallConv('ntoskrnl.ObReferenceObjectByHandle'), 'armcall')\n+\n" } ]
Python
Apache License 2.0
vivisect/vivisect
impapi windows/arm and winkern/arm (#431)
718,768
20.08.2021 17:33:48
21,600
0c1ddbdc7e35183b7f15dfb17592a8e3464c22d2
pe: better handle invalid import name closes
[ { "change_type": "MODIFY", "old_path": "PE/__init__.py", "new_path": "PE/__init__.py", "diff": "@@ -903,8 +903,13 @@ class PE(object):\nidx+=1\ncontinue\n+ try:\nfuncname = ibn.Name\n+ except UnicodeDecodeError:\n+ funcname = None\n+ logger.warning(\"pe: failed to read import name at RVA 0x%x\", ibn_rva)\n+ if funcname is not None:\nimports_list.append((save_name + arrayoff, libname, funcname))\nidx += 1\n" } ]
Python
Apache License 2.0
vivisect/vivisect
pe: better handle invalid import name (#441) closes #440
718,765
22.08.2021 04:03:13
14,400
08b3c5212bbec1ca220798b0233dd7bbf0735e51
V104 release prep Prep for releasing v1.0.4
[ { "change_type": "MODIFY", "old_path": ".bumpversion.cfg", "new_path": ".bumpversion.cfg", "diff": "[bumpversion]\n-current_version = 1.0.3\n+current_version = 1.0.4\n[bumpversion:file:setup.py]\nsearch = VERSION = '{current_version}'\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "Vivisect Changelog\n******************\n+v1.0.4 - 2021-08-22\n+===================\n+\n+Features\n+--------\n+- Add structures to UI and a compressed version of the file to the meta events.\n+ (`#396 <https://github.com/vivisect/vivisect/pull/396`_)\n+- Actual documentation!\n+ (`#400 <https://github.com/vivisect/vivisect/pull/400>`_)\n+- Massive ELFPLT overhaul.\n+ (`#401 <https://github.com/vivisect/vivisect/pull/401>`_)\n+- Speed tweaks for the pointers pass and the workspace emulator.\n+ (`#402 <https://github.com/vivisect/vivisect/pull/402>`_)\n+\n+Fixes\n+-----\n+- RTD didn't like python 3.9, so go with 3.8.\n+ (`#400 <https://github.com/vivisect/vivisect/pull/400>`_)\n+- Have ud2 on amd64 halt codeflow and fix a MACH-O bug.\n+ (`#403 <https://github.com/vivisect/vivisect/pull/403>`_)\n+- Fix issues in vtrace's windows, vivisect/reports, PE/carve, and others.\n+ (`#404 <https://github.com/vivisect/vivisect/pull/404>`_)\n+- Tons of i386 emulator fixes.\n+ (`#405 <https://github.com/vivisect/vivisect/pull/405>`_)\n+- Safeguard mnemonic counting in codeblocks.py.\n+ (`#408 <https://github.com/vivisect/vivisect/pull/408>`_)\n+- Fix funcgraph issues with line highlighting.\n+ (`#409 <https://github.com/vivisect/vivisect/pull/409>`_)\n+- Fix issues in i386 decoding, a new thunk pass, new ELF relocations support, and more.\n+ (`#411 <https://github.com/vivisect/vivisect/pull/411>`_)\n+- Fix vstruct signed number issue.\n+ (`#412 <https://github.com/vivisect/vivisect/pull/412>`_)\n+- Change AMD64 symboliks class declaration to get the right dealloc method.\n+ (`#413 <https://github.com/vivisect/vivisect/pull/413>`_)\n+- Remove wintypes import for vtrace to avoid a python bug.\n+ (`#416 <https://github.com/vivisect/vivisect/pull/416>`_)\n+- Raise specific exception on invalid architecture.\n+ (`#418 <https://github.com/vivisect/vivisect/pull/418>`_)\n+- Raise specific exception on invalid section alignment.\n+ (`#420 <https://github.com/vivisect/vivisect/pull/420>`_)\n+- Raise specific exception on corrupt file.\n+ (`#422 <https://github.com/vivisect/vivisect/pull/422>`_)\n+- Better handle invalid exported filename in PE files.\n+ (`#426 <https://github.com/vivisect/vivisect/pull/426>`_)\n+- Fix struct.unpack issue and float issue on corrupt files.\n+ (`#428 <https://github.com/vivisect/vivisect/pull/428>`_)\n+- ARM impapi files.\n+ (`#431 <https://github.com/vivisect/vivisect/pull/431>`_)\n+- Fix python 3.8 compatibility issues (and add to CI) and fix platformDetach.\n+ (`#432 <https://github.com/vivisect/vivisect/pull/432>`_)\n+- Alignment and padding of PE sections.\n+ (`#436 <https://github.com/vivisect/vivisect/pull/436>`_)\n+- Better handle invalid import name.\n+ (`#441 <https://github.com/vivisect/vivisect/pull/441>`_)\n+\nv1.0.3 - 2021-05-02\n===================\n" }, { "change_type": "MODIFY", "old_path": "setup.py", "new_path": "setup.py", "diff": "from setuptools import find_packages, setup\nfrom os import path\n-VERSION = '1.0.3'\n+VERSION = '1.0.4'\ndirn = path.abspath(path.dirname(__file__))\nwith open(path.join(dirn, 'README.md'), 'r') as fd:\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -2293,6 +2293,6 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these yourself\n-version = (1, 0, 3)\n+version = (1, 0, 4)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -3135,6 +3135,6 @@ def getVivPath(*pathents):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these directly\n-version = (1, 0, 3)\n+version = (1, 0, 4)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
V104 release prep (#442) Prep for releasing v1.0.4
718,768
25.08.2021 10:17:50
21,600
fea0883f8368c339eec1050aaa8e7d2108164b98
envi: memory: return None on truncated ptr read closes
[ { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "import re\nimport struct\n+import logging\nimport envi\nimport envi.exc as e_exc\n@@ -11,6 +12,10 @@ A module containing memory utilities and the definition of the\nmemory access API used by all vtoys trace/emulators/workspaces.\n\"\"\"\n+\n+logger = logging.getLogger(__name__)\n+\n+\ndef getPermName(perm):\n'''\nReturn the human readable name for a *single* memory\n@@ -167,7 +172,8 @@ class IMemory:\n# FIXME change this (and all uses of it) to passing in format...\nif len(bytes) != size:\n- raise Exception(\"Read gave wrong length at va: 0x%.8x (wanted %d got %d)\" % (addr, size, len(bytes)))\n+ logger.warning(\"Read gave wrong length at va: 0x%.8x (wanted %d got %d)\", addr, size, len(bytes))\n+ return None\nreturn e_bits.parsebytes(bytes, 0, size, False, self.getEndian())\n" } ]
Python
Apache License 2.0
vivisect/vivisect
envi: memory: return None on truncated ptr read (#444) closes #443
718,776
01.09.2021 05:59:53
-7,200
27ea43a1ea34dfeb866d755608a2e4f1e876bbba
only do rep on string instructions * only do rep on string instructions closes * use REP opcodes tuple
[ { "change_type": "MODIFY", "old_path": "envi/archs/i386/emu.py", "new_path": "envi/archs/i386/emu.py", "diff": "@@ -9,7 +9,7 @@ from envi.const import *\nimport envi.exc as e_exc\nimport envi.bits as e_bits\n-from envi.archs.i386.opconst import PREFIX_REX_W\n+from envi.archs.i386.opconst import PREFIX_REX_W, REP_OPCODES\nfrom envi.archs.i386.regs import *\nfrom envi.archs.i386.disasm import *\nfrom envi.archs.i386 import i386Module\n@@ -245,8 +245,9 @@ class IntelEmulator(i386RegisterContext, envi.Emulator):\nif meth is None:\nraise e_exc.UnsupportedInstruction(self, op)\n+ # The behavior of the REP prefix is undefined when used with non-string instructions.\nrep_prefix = op.prefixes & PREFIX_REP_MASK\n- if rep_prefix and not self.getEmuOpt('i386:reponce'):\n+ if rep_prefix and op.opcode in REP_OPCODES and not self.getEmuOpt('i386:reponce'):\n# REP instructions (REP/REPNZ/REPZ/REPSIMD) get their own handlers\nhandler = self.__rep_prefix_handlers__.get(rep_prefix)\nnewpc = handler(meth, op)\n@@ -273,9 +274,6 @@ class IntelEmulator(i386RegisterContext, envi.Emulator):\nThen the instruction is repeated and ECX decremented until either\nECX reaches 0 or the ZF is cleared.\n'''\n- if op.mnem.startswith('nop'):\n- return\n-\necx = emu.getRegister(REG_ECX)\nemu.setFlag(EFLAGS_ZF, 1)\n" }, { "change_type": "MODIFY", "old_path": "envi/archs/i386/opconst.py", "new_path": "envi/archs/i386/opconst.py", "diff": "@@ -197,15 +197,24 @@ INS_OFLOW = INS_TRAPS | 0x08 # gen overflow trap\n#/* INS_SYSTEM */\nINS_HALT = INS_SYSTEM | 0x01 # halt machine\n-INS_IN = INS_SYSTEM | 0x02 # input form port\n+INS_IN = INS_SYSTEM | 0x02 # input from port\nINS_OUT = INS_SYSTEM | 0x03 # output to port\nINS_CPUID = INS_SYSTEM | 0x04 # iden\nINS_NOP = INS_OTHER | 0x01\nINS_BCDCONV = INS_OTHER | 0x02 # convert to/from BCD\nINS_SZCONV = INS_OTHER | 0x03 # convert size of operand\n-INS_CRYPT = INS_OTHER | 0x4 # AES-NI instruction support\n+INS_CRYPT = INS_OTHER | 0x04 # AES-NI instruction support\n+# string instructions that support REP prefix\n+REP_OPCODES = (\n+ INS_IN, # INS\n+ INS_OUT, # OUTS\n+ INS_STRMOV, # MOVS\n+ INS_STRLOAD, # LODS\n+ INS_STRSTOR, # STOS\n+ INS_STRCMP # CMPS, SCAS\n+ )\nOP_R = 0x001\nOP_W = 0x002\n" }, { "change_type": "MODIFY", "old_path": "envi/tests/test_arch_i386_emu.py", "new_path": "envi/tests/test_arch_i386_emu.py", "diff": "@@ -108,7 +108,12 @@ i386Tests = [\n# lea ecx,dword [esp + -973695896] (test SIB getOperAddr)\n{'bytes': '8d8c246894f6c5',\n'setup': ({'esp': 0x7fd0}, {}),\n- 'tests': ({'ecx': 0xc5f71438}, {})}\n+ 'tests': ({'ecx': 0xc5f71438}, {})},\n+ # rep ret\n+ # The behavior of the REP prefix is undefined when used with non-string instructions.\n+ {'bytes': 'f3c3',\n+ 'setup': ({'ecx': 0x1}, {'esp': b'\\x00\\x00\\x00\\x60'}),\n+ 'tests': ({'ecx': 0x1, 'eip': 0x60000000}, {})}\n]\n" } ]
Python
Apache License 2.0
vivisect/vivisect
only do rep on string instructions (#447) * only do rep on string instructions closes #446 * use REP opcodes tuple Co-authored-by: atlas0fd00m <atlas@r4780y.com>
718,768
14.09.2021 17:46:06
21,600
bfa65d4be4aac24092434910407ba280cd5e1900
elf: use integer division for struct array count closes
[ { "change_type": "MODIFY", "old_path": "Elf/__init__.py", "new_path": "Elf/__init__.py", "diff": "@@ -422,7 +422,7 @@ class Elf(vs_elf.Elf32, vs_elf.Elf64):\n# only parse the symbols that are not already accounted for.\n# symbols are ordered, so existence of index Y is always the same\nsym = self._cls_symbol(bigend=self.bigend)\n- count = len(symtab) / len(sym)\n+ count = len(symtab) // len(sym)\ndiff = count - len(self.dynamic_symbols)\nif diff == 0:\nreturn\n" } ]
Python
Apache License 2.0
vivisect/vivisect
elf: use integer division for struct array count (#455) closes #452
718,770
14.09.2021 23:08:32
14,400
0108e9a4331fdf877c60877a7a6c16d37b9e9c40
Bugfix: Elf align to page Bugfix: Align Elf/PE files to page.
[ { "change_type": "MODIFY", "old_path": "envi/bits.py", "new_path": "envi/bits.py", "diff": "@@ -353,3 +353,14 @@ def masktest(s):\ndef domask(testval):\nreturn testval & maskin == matchval\nreturn domask\n+\n+def align(origsize, alignment):\n+ '''\n+ Returns an aligned size based on alignment argument\n+ '''\n+ remainder = origsize % alignment\n+ if remainder == 0:\n+ return origsize\n+ else:\n+ return origsize + (alignment - remainder)\n+\n" }, { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -137,7 +137,7 @@ class IMemory:\ndef allocateMemory(self, size, perms=MM_RWX, suggestaddr=0):\nraise Exception(\"must implement allocateMemory!\")\n- def addMemoryMap(self, mapva, perms, fname, bytes):\n+ def addMemoryMap(self, mapva, perms, fname, bytes, align=None):\nraise Exception(\"must implement addMemoryMap!\")\ndef getMemoryMaps(self):\n@@ -412,13 +412,13 @@ class MemoryObject(IMemory):\nself._map_defs = []\nself._supervisor = False\n- def allocateMemory(self, size, perms=MM_RWX, suggestaddr=0x1000, name='', fill=b'\\0'):\n+ def allocateMemory(self, size, perms=MM_RWX, suggestaddr=0x1000, name='', fill=b'\\0', align=None):\n'''\nFind a free block of memory (no maps exist) and allocate a new map\nUses findFreeMemoryBlock()\n'''\nbaseva = self.findFreeMemoryBlock(size, suggestaddr)\n- self.addMemoryMap(baseva, perms, name, fill*size)\n+ self.addMemoryMap(baseva, perms, name, fill*size, align)\nreturn baseva\ndef findFreeMemoryBlock(self, size, suggestaddr=0x1000, MIN_MEM_ADDR = 0x1000):\n@@ -468,15 +468,22 @@ class MemoryObject(IMemory):\nreturn baseva\n- def addMemoryMap(self, va, perms, fname, bytez):\n+ def addMemoryMap(self, va, perms, fname, bytez, align=None):\n'''\nAdd a memory map to this object...\n+ Returns the length of the map (since alignment could alter it)\n'''\n+ if align:\n+ curlen = len(bytez)\n+ newlen = e_bits.align(curlen, align)\n+ delta = newlen - curlen\n+ bytez += b'\\x00' * delta\n+\nmsize = len(bytez)\nmmap = (va, msize, perms, fname)\nhlpr = [va, va+msize, mmap, bytez]\nself._map_defs.append(hlpr)\n- return\n+ return msize\ndef delMemoryMap(self, mapva):\n'''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -1793,12 +1793,16 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nreturn xrefs\nreturn [ xtup for xtup in xrefs if xtup[XR_RTYPE] == rtype ]\n- def addMemoryMap(self, va, perms, fname, bytes):\n+ def addMemoryMap(self, va, perms, fname, bytes, align=None):\n\"\"\"\nAdd a memory map to the workspace. This is the *only* way to\nget memory backings into the workspace.\n\"\"\"\n- self._fireEvent(VWE_ADDMMAP, (va, perms, fname, bytes))\n+ self._fireEvent(VWE_ADDMMAP, (va, perms, fname, bytes, align))\n+\n+ # since we don't return anything from _fireEvent(), pull the new info:\n+ mva, msz, mperm, mbytes = self.getMemoryMap(va)\n+ return msz\ndef delMemoryMap(self, mapva):\n'''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/base.py", "new_path": "vivisect/base.py", "diff": "@@ -383,10 +383,16 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\nself._call_graph.setNodeProp(fnode, 'repr', name)\ndef _handleADDMMAP(self, einfo):\n+ if len(einfo) == 5:\n+ # new \"alignment-friendly\" event\n+ va, perms, fname, mbytes, align = einfo\n+ else:\n+ # DEPRECATED (21-09-13) - old event style, to support older .viv's\nva, perms, fname, mbytes = einfo\n- e_mem.MemoryObject.addMemoryMap(self, va, perms, fname, mbytes)\n+ align = None\n+\n+ blen = e_mem.MemoryObject.addMemoryMap(self, va, perms, fname, mbytes, align)\n- blen = len(mbytes)\nself.locmap.initMapLookup(va, blen)\nself.blockmap.initMapLookup(va, blen)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -6,6 +6,7 @@ import collections\nimport Elf\nimport envi.bits as e_bits\n+import envi.const as e_const\nimport vivisect\nimport vivisect.parsers as v_parsers\n@@ -214,11 +215,11 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue\nlogger.info('Loading: %s', pgm)\nbytez = elf.readAtOffset(pgm.p_offset, pgm.p_filesz)\n- bytez += b\"\\x00\" * (pgm.p_memsz - pgm.p_filesz)\n+ bytez += b'\\x00' * (pgm.p_memsz - pgm.p_filesz)\npva = pgm.p_vaddr\nif addbase:\npva += baseaddr\n- vw.addMemoryMap(pva, pgm.p_flags & 0x7, fname, bytez)\n+ vw.addMemoryMap(pva, pgm.p_flags & 0x7, fname, bytez, align=e_const.PAGE_SIZE)\nelse:\nlogger.info('Skipping: %s', pgm)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -32,14 +32,6 @@ for mod in (PE, vtrace):\n# 0x183 DEC Alpha AXP\n-def align(v, alignment):\n- remainder = v % alignment\n- if remainder == 0:\n- return v\n- else:\n- return v + (alignment - remainder)\n-\n-\ndef parseFile(vw, filename, baseaddr=None):\npe = PE.PE(open(filename, \"rb\"))\nreturn loadPeIntoWorkspace(vw, pe, filename=filename, baseaddr=baseaddr)\n@@ -327,21 +319,12 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\n# According to http://code.google.com/p/corkami/wiki/PE#section_table if SizeOfRawData is larger than VirtualSize, VS is used..\nreadsize = sec.SizeOfRawData if sec.SizeOfRawData < sec.VirtualSize else sec.VirtualSize\n- # align the read to the FileAlignment\n- readsize = align(readsize, filealign)\n-\nsecoff = pe.rvaToOffset(secrva)\nsecbytes = pe.readAtOffset(secoff, readsize, shortok=True)\nslen = len(secbytes)\n- if slen != readsize:\n- logger.warning(\"Section at offset 0x%x should have 0x%x bytes, but we only got 0x%x bytes\", secoff, readsize, slen)\n+ secbytes += b'\\x00' * (sec.VirtualSize - slen)\n- if slen != align(sec.VirtualSize, secalign):\n- # pad the section up to next the SectionAlignment\n- secbytes += b'\\x00' * (align(sec.VirtualSize, secalign) - slen)\n-\n- slen = len(secbytes)\n- vw.addMemoryMap(secbase, mapflags, fname, secbytes)\n+ slen = vw.addMemoryMap(secbase, mapflags, fname, secbytes, align=filealign)\nvw.addSegment(secbase, slen, secname, fname)\n# Mark dead data on resource and import data directories\n" }, { "change_type": "MODIFY", "old_path": "vivisect/storage/mpfile.py", "new_path": "vivisect/storage/mpfile.py", "diff": "@@ -34,7 +34,7 @@ def vivEventsToFile(filename, events):\nfor event in events:\nif event[0] == 20:\nmape = base64.b64encode(event[1][3])\n- event = (event[0], (event[1][0], event[1][1], event[1][2], mape))\n+ event = (event[0], (event[1][0], event[1][1], event[1][2], mape, event[1][4]))\nmsgpack.pack(event, f, use_bin_type=False)\n@@ -54,6 +54,10 @@ def vivEventsFromFile(filename):\nfor event in unpacker:\nif event[0] == 20:\nmape = base64.b64decode(event[1][3])\n+ if len(event[1]) == 5:\n+ event = (event[0], (event[1][0], event[1][1], event[1][2], mape, event[1][4]))\n+ else:\n+ # DEPRECATED: for loading older MPFILEs\nevent = (event[0], (event[1][0], event[1][1], event[1][2], mape))\nevents.append(event)\nreturn events\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/stabilitydata/redxor.stability.json", "new_path": "vivisect/tests/stabilitydata/redxor.stability.json", "diff": "4,\nnull\n],\n+ [\n+ 4234248,\n+ 8,\n+ 4,\n+ null\n+ ],\n[\n4229536,\n8,\n[]\n],\n[\n- 4231367,\n- 19,\n+ 4231882,\n+ 5,\n2,\n[]\n],\n[\n- 4231882,\n- 5,\n+ 4231367,\n+ 19,\n2,\n[]\n],\n4228375,\n\"redxor.CheckLKM\"\n],\n+ [\n+ 6336456,\n+ \"_end\"\n+ ],\n[\n6334184,\n\"redxor.coOutputWPos\"\n4230600,\n\"str_HTTP/1.0\\rUser-Ag_00408dc8\"\n],\n- [\n- 4231367,\n- \"str_out of pty devic_004090c7\"\n- ],\n[\n4231882,\n\"str_%s_004092ca\"\n],\n+ [\n+ 4231367,\n+ \"str_out of pty devic_004090c7\"\n+ ],\n[\n4231887,\n\"str_%s/.bash_profile_004092cf\"\n1,\n1\n],\n+ [\n+ 4234248,\n+ 0,\n+ 3,\n+ 0\n+ ],\n[\n4229536,\n0,\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testmalware.py", "new_path": "vivisect/tests/testmalware.py", "diff": "@@ -28,10 +28,10 @@ class MalwareTests(unittest.TestCase):\nvw = self.mmap_vw\nmaps = set([\n(268435456, 0x1000, 4, '0e25aa791c9119108af073bc9e9d0fa2'),\n- (268439552, 0x67000, 5, '0e25aa791c9119108af073bc9e9d0fa2'),\n- (268861440, 0xe000, 4, '0e25aa791c9119108af073bc9e9d0fa2'),\n- (268918784, 0x14000, 6, '0e25aa791c9119108af073bc9e9d0fa2'),\n- (269004800, 0x5000, 4, '0e25aa791c9119108af073bc9e9d0fa2'),\n+ (268439552, 0x66c00, 5, '0e25aa791c9119108af073bc9e9d0fa2'),\n+ (268861440, 0xdc00, 4, '0e25aa791c9119108af073bc9e9d0fa2'),\n+ (268918784, 0x13600, 6, '0e25aa791c9119108af073bc9e9d0fa2'),\n+ (269004800, 0x4600, 4, '0e25aa791c9119108af073bc9e9d0fa2'),\n])\nself.assertEqual(maps, set(vw.getMemoryMaps()))\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testpe.py", "new_path": "vivisect/tests/testpe.py", "diff": "@@ -535,10 +535,10 @@ class PETests(unittest.TestCase):\nans = {\n# name -> (Base, Size, Flags)\n'PE_Header': (0x400000, 0x1000, e_memory.MM_READ),\n- '.text': (0x401000, 0x72000, e_memory.MM_READ | e_memory.MM_EXEC),\n- '.data': (0x4b6000, 0x5000, e_memory.MM_READ | e_memory.MM_WRITE),\n- '.rdata': (0x473000, 0x43000, e_memory.MM_READ),\n- '.reloc': (0x4bf000, 0x7000, e_memory.MM_READ),\n+ '.text': (0x401000, 0x71800, e_memory.MM_READ | e_memory.MM_EXEC),\n+ '.data': (0x4b6000, 0x4200, e_memory.MM_READ | e_memory.MM_WRITE),\n+ '.rdata': (0x473000, 0x42e00, e_memory.MM_READ),\n+ '.reloc': (0x4bf000, 0x6800, e_memory.MM_READ),\n}\nfor sva, ssize, sname, sfname in vw.getSegments():\nself.assertEqual(ans[sname][0], sva)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -463,17 +463,17 @@ class VivisectTest(unittest.TestCase):\nself.assertTrue(len(vw.getLocations()) > 76000)\n# tuples are Name, Number of Locations, Size in bytes, Percentage of space\n- ans = {0: ('Undefined', 0, 70828, 18),\n+ ans = {0: ('Undefined', 0, 55596, 14),\n1: ('Num/Int', 715, 3703, 0),\n2: ('String', 265, 6485, 1),\n3: ('Unicode', 174, 5596, 1),\n4: ('Pointer', 361, 2888, 0),\n- 5: ('Opcode', 72507, 279377, 71),\n+ 5: ('Opcode', 72507, 279377, 73),\n6: ('Structure', 1018, 12740, 3),\n7: ('Clsid', 0, 0, 0),\n8: ('VFTable', 0, 0, 0),\n9: ('Import Entry', 370, 2960, 0),\n- 10: ('Pad', 865, 8639, 2)}\n+ 10: ('Pad', 864, 8511, 2)}\ndist = vw.getLocationDistribution()\nfor loctype, locdist in dist.items():\nself.assertEqual(locdist, ans[loctype])\n@@ -1143,12 +1143,12 @@ class VivisectTest(unittest.TestCase):\n'PE_Header': (0x140000000, 0x1000, e_memory.MM_READ),\n'.text': (0x140001000, 0x49000, e_memory.MM_READ | e_memory.MM_EXEC),\n'.rdata': (0x14004a000, 0xc000, e_memory.MM_READ),\n- '.data': (0x140056000, 0x3000, e_memory.MM_READ | e_memory.MM_WRITE),\n+ '.data': (0x140056000, 0x2a00, e_memory.MM_READ | e_memory.MM_WRITE),\n'.pdata': (0x140059000, 0x3000, e_memory.MM_READ),\n- '.00cfg': (0x14005c000, 0x1000, e_memory.MM_READ),\n- '.freestd': (0x14005d000, 0x1000, e_memory.MM_READ),\n- '.tls': (0x14005e000, 0x1000, e_memory.MM_READ | e_memory.MM_WRITE),\n- '.reloc': (0x140092000, 0x1000, e_memory.MM_READ),\n+ '.00cfg': (0x14005c000, 0x200, e_memory.MM_READ),\n+ '.freestd': (0x14005d000, 0x200, e_memory.MM_READ),\n+ '.tls': (0x14005e000, 0x200, e_memory.MM_READ | e_memory.MM_WRITE),\n+ '.reloc': (0x140092000, 0x400, e_memory.MM_READ),\n}\nfor sva, ssize, sname, sfname in vw.getSegments():\nself.assertEqual(ans[sname][0], sva)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Bugfix: Elf align to page (#451) Bugfix: Align Elf/PE files to page.
718,768
15.09.2021 10:32:41
21,600
08e7a937d2729fb433286e97dd7dbc778cbf1f4e
elfplt_late: log to appropriate logger, not root closes
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt_late.py", "new_path": "vivisect/analysis/elf/elfplt_late.py", "diff": "@@ -106,14 +106,14 @@ def analyzePLT(vw, pltva, pltsz):\nfillPLTviaGOTXrefs(vw, jmpheur, pltva, pltsz)\nelse:\n- logging.info(\"analyzePLT(0x%x, 0x%x) skipping GOT-XREF-Offset method: no existing functions found\", pltva, pltsz)\n+ logger.info(\"analyzePLT(0x%x, 0x%x) skipping GOT-XREF-Offset method: no existing functions found\", pltva, pltsz)\n# PLT-Func-Distance method\nif len(distanceheur):\nfillPLTGaps(vw, curplts, distanceheur, pltva, pltsz)\nelse:\n- logging.info(\"skipping analyzePLT(0x%x, 0x%x) (PLT-Func-Distance method): no existing functions found\", pltva, pltsz)\n+ logger.info(\"skipping analyzePLT(0x%x, 0x%x) (PLT-Func-Distance method): no existing functions found\", pltva, pltsz)\nlogger.info(\"elfplt_late (done): pltva: 0x%x, %d\", pltva, pltsz)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
elfplt_late: log to appropriate logger, not root (#458) closes #457
718,765
17.09.2021 11:51:31
14,400
d5b895eeeb19a0304d965cbf4fc86a5f3a5183c5
AddRelocation Robustness Add some safety to relocs in elf parsing.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -389,11 +389,16 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nExpects data to have whatever is necessary for the reloc type. eg. addend\n\"\"\"\n# split \"current\" va into fname and offset. future relocations will want to base all va's from an image base\n- mmva, mmsz, mmperm, fname = self.getMemoryMap(va) # FIXME: getFileByVa does not obey file defs\n+ mmap = self.getMemoryMap(va)\n+ if not mmap:\n+ logger.warning('addRelocation: No matching map found for %s', va)\n+ return None\n+ mmva, mmsz, mmperm, fname = mmap # FIXME: getFileByVa does not obey file defs\nimgbase = self.getFileMeta(fname, 'imagebase')\noffset = va - imgbase\nself._fireEvent(VWE_ADDRELOC, (fname, offset, rtype, data))\n+ return self.getRelocation(va)\ndef getRelocations(self):\n\"\"\"\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -639,7 +639,8 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\nif rtype == Elf.R_X86_64_IRELATIVE:\n# before making import, let's fix up the pointer as a BASEPTR Relocation\nptr = r.r_addend\n- vw.addRelocation(rlva, RTYPE_BASEPTR, ptr)\n+ rloc = vw.addRelocation(rlva, RTYPE_BASEPTR, ptr)\n+ if rloc:\nlogger.info('Reloc: R_X86_64_IRELATIVE 0x%x', rlva)\nif rtype in (Elf.R_386_JMP_SLOT, Elf.R_X86_64_GLOB_DAT, Elf.R_X86_64_IRELATIVE):\n@@ -671,7 +672,9 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\n# first make it a relocation that is based on the imagebase\nptr = r.r_addend\nlogger.info('R_X86_64_IRELATIVE: adding Relocation 0x%x -> 0x%x (name: %r %r) ', rlva, ptr, name, dmglname)\n- vw.addRelocation(rlva, RTYPE_BASEPTR, ptr)\n+ rloc = vw.addRelocation(rlva, RTYPE_BASEPTR, ptr)\n+ if rloc is not None:\n+ continue\n# next get the target and find a name, since the reloc itself doesn't have one\ntgt = vw.readMemoryPtr(rlva)\n@@ -741,6 +744,7 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\n# that does *not* mean it's not an IMPORT\nif ptr and not isPLT(vw, ptr):\nlogger.info('R_ARM_JUMP_SLOT: adding Relocation 0x%x -> 0x%x (%s) ', rlva, ptr, dmglname)\n+ # even if addRelocation fails, still make the name, same thing down in GLOB_DAT\nif addbase:\nvw.addRelocation(rlva, vivisect.RTYPE_BASEPTR, ptr)\nelse:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -584,6 +584,14 @@ class VivisectTest(unittest.TestCase):\nfor va, disp in ans:\nself.assertEqual(disp, vw.reprVa(va))\n+ def test_basic_reloc(self):\n+ vw = self.chgrp_vw\n+ rloc = vw.addRelocation(0xdeadbeef, v_const.RTYPE_BASEOFF)\n+ self.assertIsNone(rloc)\n+\n+ rloc = vw.addRelocation(0x08054184, v_const.RTYPE_BASEPTR)\n+ self.assertIsNotNone(rloc)\n+\ndef test_naughty(self):\n'''\nTest us some error conditions\n" } ]
Python
Apache License 2.0
vivisect/vivisect
AddRelocation Robustness (#456) Add some safety to relocs in elf parsing.
718,770
17.09.2021 22:45:35
14,400
5c3f69977f433c5613ceaec57763644dd919ac27
allow duplicate init_function and fini_function entries that differ between section and dynamics analysis
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -352,15 +352,19 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nvw.makeString(sva)\nelif sname == \".init\":\n- vw.makeName(sva, \"init_function\", filelocal=True)\n- new_functions.append((\"init_function\", sva))\n+ init_tup = (\"init_function\", sva)\n+ if init_tup not in new_functions:\n+ vw.makeName(sva, \"init_function\", filelocal=True, makeuniq=True)\n+ new_functions.append(init_tup)\nelif sname == \".init_array\":\nmakeFunctionTable(elf, vw, sec.sh_addr, size, 'init_function', new_functions, new_pointers, baseaddr, addbase)\nelif sname == \".fini\":\n- vw.makeName(sva, \"fini_function\", filelocal=True)\n- new_functions.append((\"fini_function\", sva))\n+ fini_tup = (\"fini_function\", sva)\n+ if fini_tup not in new_functions:\n+ vw.makeName(sva, \"fini_function\", filelocal=True, makeuniq=True)\n+ new_functions.append(fini_tup)\nelif sname == \".fini_array\":\nmakeFunctionTable(elf, vw, sec.sh_addr, size, 'fini_function', new_functions, new_pointers, baseaddr, addbase)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
allow duplicate init_function and fini_function entries that differ between section and dynamics analysis (#459)
718,770
20.09.2021 22:02:06
14,400
93a0644e1dd9c5167547b7370fe2f68cec08bab2
Vtrace Symbol Test Add Vtrace Symbol Test
[ { "change_type": "ADD", "old_path": null, "new_path": "vtrace/tests/test_symcache.py", "diff": "+import os\n+import unittest\n+import vtrace.tests as vt_tests\n+\n+\n+class VtraceSymbolTest(vt_tests.VtraceProcessTest):\n+\n+ def test_symbol(self):\n+ symlist = self.trace.getSymList()\n+ # currently there are 6355, but we don't care about exactness, just that\n+ # it's a largish number\n+ self.assertGreater(len(symlist), 1000)\n+ sym0 = symlist[0]\n+\n+ symPyRevType = self.trace.getSymByName('PyReversed_Type')\n+ self.assertIsNotNone(symPyRevType)\n+ self.assertIn(symPyRevType.fname, ('python', 'python3', 'python2', 'libpython3'))\n+ self.assertEqual(symPyRevType.name, 'PyReversed_Type')\n+ self.assertAlmostEqual(symPyRevType.size, 0x1a0, delta=20)\n+\n+ symPyRevT2 = self.trace.getSymByAddr(symPyRevType.value)\n+ self.assertEqual(symPyRevType, symPyRevT2)\n+\n+\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Vtrace Symbol Test (#460) Add Vtrace Symbol Test
718,765
22.09.2021 12:53:11
14,400
885076381379ca62a7c4ac6519ddbc79323c661b
V1.0.5 Release Prep v1.0.5 Release Prep
[ { "change_type": "MODIFY", "old_path": ".bumpversion.cfg", "new_path": ".bumpversion.cfg", "diff": "[bumpversion]\n-current_version = 1.0.4\n+current_version = 1.0.5\n[bumpversion:file:setup.py]\nsearch = VERSION = '{current_version}'\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "Vivisect Changelog\n******************\n+V1.0.5 - 2021-09-10\n+===================\n+\n+Fixes\n+-----\n+- Fix ascii string size when the string terminates at the end of a memory map.\n+ (`#437 <https://github.com/vivisect/vivisect/pull/437>`_)\n+- Better handle PE delay imports that use VA pointers instead of RVA pointers.\n+ (`#439 <https://github.com/vivisect/vivisect/pull/439>`_)\n+- envi.IMemory.readMemValue: return None on truncated read.\n+ (`#444 <https://github.com/vivisect/vivisect/pull/444>`_)\n+- Only apply the rep prefix on string instructions in intel emulation.\n+ (`#447 <https://github.com/vivisect/vivisect/pull/447>`_)\n+- Fix a pair of regressions in ELF analysis.\n+ (`#448 <https://github.com/vivisect/vivisect/pull/448>`_)\n+- Align ELF memory maps to page.\n+ (`#451 <https://github.com/vivisect/vivisect/pull/451>`_)\n+- Integer division for struct array count in ELF.\n+ (`#455 <https://github.com/vivisect/vivisect/pull/455>`_)\n+- Safe harness for addRelocation method on the workspace.\n+ (`#456 <https://github.com/vivisect/vivisect/pull/456>`_)\n+- Log to appropriate logger in elfplt late module.\n+ (`#458 <https://github.com/vivisect/vivisect/pull/458>`_)\n+- Allow duplicate init and fini functions in ELF files.\n+ (`#459 <https://github.com/vivisect/vivisect/pull/459>`_)\n+- Add Vtrace Symbol test.\n+ (`#460 <https://github.com/vivisect/vivisect/pull/460>`_)\n+\nv1.0.4 - 2021-08-22\n===================\nFeatures\n--------\n- Add structures to UI and a compressed version of the file to the meta events.\n- (`#396 <https://github.com/vivisect/vivisect/pull/396`_)\n+ (`#396 <https://github.com/vivisect/vivisect/pull/396>`_)\n- Actual documentation!\n(`#400 <https://github.com/vivisect/vivisect/pull/400>`_)\n- Massive ELFPLT overhaul.\n" }, { "change_type": "MODIFY", "old_path": "setup.py", "new_path": "setup.py", "diff": "from setuptools import find_packages, setup\nfrom os import path\n-VERSION = '1.0.4'\n+VERSION = '1.0.5'\ndirn = path.abspath(path.dirname(__file__))\nwith open(path.join(dirn, 'README.md'), 'r') as fd:\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -2293,6 +2293,6 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these yourself\n-version = (1, 0, 4)\n+version = (1, 0, 5)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -3144,6 +3144,6 @@ def getVivPath(*pathents):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these directly\n-version = (1, 0, 4)\n+version = (1, 0, 5)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
V1.0.5 Release Prep (#449) v1.0.5 Release Prep
718,765
23.09.2021 23:56:54
14,400
91f3952994815e2fa2da04482b70dd882a1eb451
add changelog to docs thanks
[ { "change_type": "MODIFY", "old_path": "docs/index.rst", "new_path": "docs/index.rst", "diff": "@@ -18,6 +18,7 @@ Welcome to vivisect's documentation!\nvivisect/extensions\nvivisect/scripting\nvivisect/remote\n+ vivisect/changelog\nIndices and tables\n" }, { "change_type": "ADD", "old_path": null, "new_path": "docs/vivisect/changelog.rst", "diff": "+.. _changelog:\n+\n+.. include:: ../../CHANGELOG.rst\n" } ]
Python
Apache License 2.0
vivisect/vivisect
add changelog to docs (#462) thanks @rakuy0
718,765
24.09.2021 00:27:23
14,400
0274ff1dee066ccb9c9f5072fb7ac7b98655f854
add test for workspace failure
[ { "change_type": "MODIFY", "old_path": "vivisect/tests/teststorage.py", "new_path": "vivisect/tests/teststorage.py", "diff": "@@ -114,3 +114,13 @@ class StorageTests(unittest.TestCase):\nbasicfile.close()\nos.unlink(mpfile.name)\nos.unlink(basicfile.name)\n+\n+ def test_bad_event(self):\n+ vw = vivisect.VivWorkspace()\n+ with self.assertLogs() as logcap:\n+ vw.importWorkspace([(VWE_MAX + 1, (0xabad1dea, 4, 3, 'nope')),\n+ (VWE_ADDFILE, ('VivisectFile', 0x1000, '3bfdad02b9a6522c84e356cf8f69135b'))])\n+ files = vw.getFiles()\n+ self.assertIn(\"IndexError: list index out of range\", ''.join(logcap.output))\n+ self.assertEqual(1, len(files))\n+ self.assertEqual('VivisectFile', files[0])\n" } ]
Python
Apache License 2.0
vivisect/vivisect
add test for workspace failure (#463)
718,765
19.10.2021 19:33:29
14,400
a116ffeb695654da5a0949ad6f0c5ba78bea5d18
fix some qt issues in vdb
[ { "change_type": "MODIFY", "old_path": "envi/qt/memorymap.py", "new_path": "envi/qt/memorymap.py", "diff": "@@ -10,6 +10,7 @@ import envi.cli as e_cli\nfrom vqt.common import ACT\nimport vqt.tree as vq_tree\n+# TODO: Why is this here and not jut mixed in w/ vtrace since they're the only consumers?\nclass VQMemoryMapView(vq_tree.VQTreeView):\ndef __init__(self, mem, parent=None):\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -81,7 +81,7 @@ def setupBreakOnEntry(trace):\notb = vtrace.OneTimeBreak(None, expression=entrySymExpr)\ntrace.addBreakpoint(otb)\n-class VdbTrace:\n+class VdbTrace(object):\n\"\"\"\nUsed to hand thing that need a persistant reference to a trace\nwhen using vdb to manage tracers.\n" }, { "change_type": "MODIFY", "old_path": "vdb/qt/main.py", "new_path": "vdb/qt/main.py", "diff": "@@ -220,6 +220,9 @@ class VdbWindow(vq_app.VQMainCmdWindow):\nself.addHotKey('ctrl+b','debug:break')\nself.addHotKey('ctrl+p','vdb:view:python')\n+ self.addHotKey('ctrl+w', 'file:quit')\n+ self.addHotKeyTarget('file:quit', self.close)\n+\n# Get hotkey overrides\nself.loadHotKeys(self._vq_settings)\n" }, { "change_type": "MODIFY", "old_path": "vtrace/qt.py", "new_path": "vtrace/qt.py", "diff": "@@ -71,7 +71,7 @@ class RegisterListModel(envi_qt_memory.EnviNavModel):\nreturn True\n-class RegistersListView(vq_tree.VQTreeView, VQTraceNotifier):\n+class RegistersListView(VQTraceNotifier, vq_tree.VQTreeView):\n'''\nA pure \"list view\" object for registers\n'''\n@@ -199,12 +199,12 @@ class RegistersView(QWidget):\n# show general in dropdown by default if exists, otherwise all\n# (preferences will re-set)\nif 'general' in self.regviews:\n- self.regViewNameSelected('general')\nidx = self.viewnames.findText('general')\n+ self.regViewNameSelected('general')\nself.viewnames.setCurrentIndex(idx)\nelse:\n- self.regViewNameSelected('all')\nidx = self.viewnames.findText('all')\n+ self.regViewNameSelected('all')\nself.viewnames.setCurrentIndex(idx)\nstatusreg_widget = VQFlagsGridView(trace=trace, parent=self)\n@@ -216,8 +216,7 @@ class RegistersView(QWidget):\nsplitview.addWidget(statusreg_widget)\nvbox.addWidget(splitview)\n- sig = QtCore.SIGNAL('currentIndexChanged(str)')\n- self.viewnames.connect(self.viewnames, sig, self.regViewNameSelected)\n+ self.viewnames.currentTextChanged.connect(self.regViewNameSelected)\nself.setLayout(vbox)\n@@ -225,7 +224,7 @@ class RegistersView(QWidget):\nself.reglist.regnames = self.regviews.get(str(name), None)\nself.reglist.vqLoad()\n-class VQFlagsGridView(QWidget, VQTraceNotifier):\n+class VQFlagsGridView(VQTraceNotifier, QWidget):\n'''\nShow the state of the status register (if available).\n'''\n@@ -366,7 +365,7 @@ def getProcessPid(trace=None, parent=None):\nclass FileDescModel(vq_tree.VQTreeModel):\ncolumns = ('Fd','Type','Name')\n-class VQFileDescView(vq_tree.VQTreeView, VQTraceNotifier):\n+class VQFileDescView(VQTraceNotifier, vq_tree.VQTreeView):\ndef __init__(self, trace, parent=None):\nVQTraceNotifier.__init__(self, trace)\n@@ -490,7 +489,7 @@ class VQTraceToolBar(QToolBar, vtrace.Notifier):\nelse:\nself._updateActions(trace.isAttached(), trace.shouldRunAgain())\n-class VQMemoryMapView(envi_qt_memmap.VQMemoryMapView, VQTraceNotifier):\n+class VQMemoryMapView(VQTraceNotifier, envi_qt_memmap.VQMemoryMapView):\n'''\nA memory map view which is sensitive to the status of a\ntrace object.\n@@ -517,8 +516,8 @@ class VQThreadsView(vq_tree.VQTreeView, VQTraceNotifier):\ndef __init__(self, trace=None, parent=None, selectthread=None):\n# selectthread is an optional endpoint to connect to\n- VQTraceNotifier.__init__(self, trace)\nvq_tree.VQTreeView.__init__(self, parent=parent)\n+ VQTraceNotifier.__init__(self, trace)\nself.setWindowTitle('Threads')\nself.setModel(VQThreadListModel(parent=self))\nself.setAlternatingRowColors(True)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
fix some qt issues in vdb (#466)
718,770
11.11.2021 17:26:29
18,000
3dfa3d2ceab45d9e656ee87699b856ca88c62235
minor bugfix from Vdb/Viv/Emu bridge pr
[ { "change_type": "MODIFY", "old_path": "vivisect/impemu/platarch/arm.py", "new_path": "vivisect/impemu/platarch/arm.py", "diff": "@@ -27,12 +27,7 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nva = kwargs.get('va')\nif va:\n- loc = vw.getLocation(va)\n- if loc:\n- lva, lsz, lt, lflags = loc\n- self.setMemArchitecture(lflags)\n- tmode = (lflags & envi.ARCH_MASK == envi.ARCH_THUMB)\n- self.setThumbMode(tmode)\n+ self._prep(va)\ndef setThumbMode(self, thumb=1):\ne_arm.ArmEmulator.setThumbMode(self, thumb)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
minor bugfix from Vdb/Viv/Emu bridge pr
718,770
11.11.2021 17:26:50
18,000
06a4484c4f5379c307b930097308dfa69db35c48
adding a new posix noret
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -166,6 +166,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nvw.addNoReturnApi(\"*.__assert_fail\")\nvw.addNoReturnApi(\"*.__stack_chk_fail\")\nvw.addNoReturnApi(\"*.pthread_exit\")\n+ vw.addNoReturnApi(\"*.longjmp\")\n# for VivWorkspace, MSB==1, LSB==0... which is the same as True/False\nvw.setEndian(elf.getEndian())\n" } ]
Python
Apache License 2.0
vivisect/vivisect
adding a new posix noret
718,770
11.11.2021 17:27:31
18,000
10fbbd62ea3c4c62d078df641d2cc014702524e3
minor exception handling
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -299,7 +299,6 @@ def analyzePLT(vw, ssva, ssize):\nlogger.error('analyzePLT(0x%x, %r): %s', ssva, ssize, str(e))\n-\nMAX_OPS = 10\ndef analyzeFunction(vw, funcva):\n@@ -386,7 +385,10 @@ def analyzeFunction(vw, funcva):\nelif ltype == vivisect.LOC_POINTER:\n# we have a deref to a pointer.\nfuncname = vw.getName(ltinfo)\n+ if ltinfo:\nlogger.debug(\"0x%x: (0x%x->0x%x) LOC_POINTER by BR_DEREF %r\", funcva, opval, ltinfo, funcname)\n+ else:\n+ logger.debug(\"0x%x: (0x%x->%r) LOC_POINTER by BR_DEREF %r\", funcva, opval, ltinfo, funcname)\nelse:\nlogger.warning(\"0x%x: (0x%x) not LOC_IMPORT or LOC_POINTER?? by BR_DEREF %r\", funcva, opval, loctup)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
minor exception handling
718,770
11.11.2021 18:14:23
18,000
104e8c5c0c9b5daacb6bb09b4eb43746aba2bd78
bugfix: make elfplt analysis use makeFunctionThunk() in a way that actually catches norets using the fmcb_Thunk() analysis hook. bugfix: redo how pointers are incremented
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -944,7 +944,8 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nloctup = self.getLocation(va)\nif loctup is not None:\n- offset += loctup[L_SIZE]\n+ nextva = loctup[L_VA] + loctup[L_SIZE]\n+ offset = nextva - mva\nif offset % align:\noffset += align\noffset &= -align\n@@ -1672,7 +1673,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nret = []\nreturn ret\n- def makeFunctionThunk(self, fva, thname, addVa=True, filelocal=False):\n+ def makeFunctionThunk(self, fva, thname, addVa=True, filelocal=False, basename=None):\n\"\"\"\nInform the workspace that a given function is considered a \"thunk\" to another.\nThis allows the workspace to process argument inheritance and several other things.\n@@ -1681,13 +1682,14 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\n\"\"\"\nself.checkNoRetApi(thname, fva)\nself.setFunctionMeta(fva, \"Thunk\", thname)\n- n = self.getName(fva)\n- base = thname.split(\".\")[-1]\n+ if basename is None:\n+ basename = thname.split(\".\")[-1]\n+\nif addVa:\n- name = \"%s_%.8x\" % (base,fva)\n+ name = \"%s_%.8x\" % (basename, fva)\nelse:\n- name = base\n+ name = basename\nnewname = self.makeName(fva, name, filelocal=filelocal, makeuniq=True)\napi = self.getImpApi(thname)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -477,7 +477,8 @@ def analyzeFunction(vw, funcva):\nfuncname = funcname[:-9]\nlogger.info('makeFunctionThunk(0x%x, \"plt_%s\")', funcva, funcname)\n- vw.makeFunctionThunk(funcva, \"plt_\" + funcname, addVa=False, filelocal=True)\n+ vw.makeFunctionThunk(funcva, \"*.\" + funcname, addVa=False, filelocal=True,\n+ basename=\"plt_\" + funcname)\n'''\ndef printPLTs(vw):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
bugfix: make elfplt analysis use makeFunctionThunk() in a way that actually catches norets using the fmcb_Thunk() analysis hook. bugfix: redo how pointers are incremented
718,770
11.11.2021 18:15:12
18,000
4aef879ff89d7ae1d1131aff053a2b8bf02db0a6
cleanup: remove "thread" from the logging format. that should save a few kb each run :)
[ { "change_type": "MODIFY", "old_path": "envi/common.py", "new_path": "envi/common.py", "diff": "@@ -2,7 +2,7 @@ import logging\nimport binascii\nLOG_FORMAT = '%(asctime)s:%(levelname)s:%(name)s: %(message)s' \\\n- '[%(filename)s:%(funcName)s:%(lineno)s:%(threadName)s]'\n+ '[%(filename)s:%(funcName)s:%(lineno)s]'\nEMULOG = 9\nSHITE = 8\n" } ]
Python
Apache License 2.0
vivisect/vivisect
cleanup: remove "thread" from the logging format. that should save a few kb each run :)
718,770
11.11.2021 18:16:43
18,000
abf7082dcf24aa568bb712bc115f0751fc55d2c9
make function headers display "NORET" for functions that have been categorized as such.
[ { "change_type": "MODIFY", "old_path": "envi/qt/html.py", "new_path": "envi/qt/html.py", "diff": "@@ -75,6 +75,16 @@ div.codeblock:hover {\nbackground-color: #ffff00;\n}\n+.envi-funcflags {\n+ color: #ff00dd;\n+ background-color: #000000;\n+}\n+\n+.envi-funcflags-selected {\n+ color: #000000;\n+ background-color: #ff00dd;\n+}\n+\n</style>\n<style type=\"text/css\" id=\"cmapstyle\">\n" }, { "change_type": "MODIFY", "old_path": "vivisect/renderers/__init__.py", "new_path": "vivisect/renderers/__init__.py", "diff": "@@ -101,7 +101,12 @@ class WorkspaceRenderer(e_canvas.MemoryRenderer):\n# FIXME color code and get args parsing goin on\nmcanv.addText(\" \")\nxrtag = mcanv.getTag(\"xrefs\")\n- mcanv.addText(\"[%d XREFS]\\n\" % xrcount, tag=xrtag)\n+ mcanv.addText(\"[%d XREFS] \" % xrcount, tag=xrtag)\n+\n+ if self.vw.getMeta('NoReturnApisVa', {}).get(lva):\n+ mcanv.addNameText('NORET', typename='funcflags')\n+\n+ mcanv.addText('\\n')\nmcanv.addText(linepre, tag=vatag)\nmcanv.addText('\\n')\n" } ]
Python
Apache License 2.0
vivisect/vivisect
make function headers display "NORET" for functions that have been categorized as such.
718,770
12.11.2021 18:05:50
18,000
6644f2c255f40de198cc9b4166ade21282dfa396
tweak testelf (yay, no longer cares about "unique" names like foo_0 and foo_1)
[ { "change_type": "MODIFY", "old_path": "vivisect/tests/testelf.py", "new_path": "vivisect/tests/testelf.py", "diff": "@@ -37,12 +37,12 @@ def cmpnames(x, y):\nnmset = [x, y]\nfor nmidx in range(2):\n- name = nmset[nmidx]\n+ va, name = nmset[nmidx]\nif len(name) <= 2:\ncontinue\n- if name[-2:] in (b'_0', b'_1', b'_2', b'_3', b'_4', b'_5', b'_6', b'_7', b'_8', b'_9'):\n- nmset[nmidx] = name[:-2]\n+ if name[-2:] in ('_0', '_1', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9'):\n+ nmset[nmidx] = va, name[:-2]\nreturn nmset[0] == nmset[1]\n@@ -156,7 +156,7 @@ class ELFTests(unittest.TestCase):\n# So this portion is because on windows, there's no good python equivalent for cxxfilt that I\n# can find. So we have to skip the portions of the tests that rely on decoding the names\ncmpr = lambda x, y: x == y\n- if platform.system().lower() == 'windows' and testname in comparators:\n+ if testname in comparators:\ncmpr = comparators[testname]\nfor base in baseline:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
tweak testelf (yay, no longer cares about "unique" names like foo_0 and foo_1)
718,770
12.11.2021 18:08:20
18,000
b7423c2056d08c7d4c12208c78ff52cc8d0a42c3
better context for pointer log messages more testelf
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/generic/pointers.py", "new_path": "vivisect/analysis/generic/pointers.py", "diff": "@@ -24,7 +24,7 @@ def analyze(vw):\ncontinue\nfor xfr, xto, xtype, xinfo in vw.getXrefsFrom(rva):\n- logger.debug('pointer(1): 0x%x -> 0x%x', xfr, xto)\n+ logger.debug('pointer(xref): 0x%x -> 0x%x', xfr, xto)\nvw.analyzePointer(xto)\ndone[xfr] = xto\n@@ -32,9 +32,9 @@ def analyze(vw):\nfor pva, tva, fname, pname in vw.getVaSetRows('PointersFromFile'):\nif vw.getLocation(pva) is None:\nif tva is None:\n- logger.debug('making pointer(2) 0x%x (%r)', pva, pname)\n+ logger.debug('making pointer(fromFile) 0x%x (%r)', pva, pname)\nelse:\n- logger.debug('making pointer(2) 0x%x -> 0x%x (%r)', pva, tva, pname)\n+ logger.debug('making pointer(fromFile) 0x%x -> 0x%x (%r)', pva, tva, pname)\nvw.makePointer(pva, tva, follow=True)\ndone[pva] = tva\n@@ -51,7 +51,7 @@ def analyze(vw):\nlogger.debug('following previously discovered pointer 0x%x -> 0x%x', lva, tva)\ntry:\n- logger.debug('pointer(3): 0x%x -> 0x%x', lva, tva)\n+ logger.debug('pointer: 0x%x -> 0x%x', lva, tva)\nvw.followPointer(tva)\ndone[lva] = tva\nexcept Exception as e:\n@@ -62,7 +62,7 @@ def analyze(vw):\nif vw.isDeadData(pval):\ncontinue\ntry:\n- logger.debug('pointer(4): 0x%x -> 0x%x', addr, pval)\n+ logger.debug('make pointer(found): 0x%x -> 0x%x', addr, pval)\nvw.makePointer(addr, follow=True)\ndone[addr] = pval\nexcept Exception as e:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testelf.py", "new_path": "vivisect/tests/testelf.py", "diff": "@@ -34,6 +34,10 @@ def do_analyze(vw):\nlogging.warning(\"ERROR in analysis module: (%r): %r\", mod, e, exc_info=1)\ndef cmpnames(x, y):\n+ '''\n+ Names comparator. Skips \"_#\" duplicate name parts so that processing order\n+ doesn't matter.\n+ '''\nnmset = [x, y]\nfor nmidx in range(2):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
better context for pointer log messages more testelf
718,770
15.11.2021 00:06:23
18,000
698ef925da7c805fe440decb14c7d8778334375e
tweaks per
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -1678,6 +1678,12 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nInform the workspace that a given function is considered a \"thunk\" to another.\nThis allows the workspace to process argument inheritance and several other things.\n+ If basename is provided, that name is used to create the Vivisect name for the thunk.\n+ If basename is not provided, thname is chopped and used for the Vivisect name.\n+ This difference allows, for example, the Elf loader to make PLT functions named \"plt_<foo>\"\n+ but still use the official thunk name \"*.<foo>\". This thunk name is used to look up\n+ the import api. These \"*.<foo>\" thunk names are also used in the addNoReturnApi().\n+\nUsage: vw.makeFunctionThunk(0xvavavava, \"kernel32.CreateProcessA\")\n\"\"\"\nself.checkNoRetApi(thname, fva)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/impemu/emulator.py", "new_path": "vivisect/impemu/emulator.py", "diff": "@@ -496,6 +496,7 @@ class WorkspaceEmulator:\nif self.emustop:\nreturn\n+\niscall = self.checkCall(starteip, endeip, op)\nif self.emustop:\nreturn\n" }, { "change_type": "MODIFY", "old_path": "vivisect/impemu/platarch/arm.py", "new_path": "vivisect/impemu/platarch/arm.py", "diff": "@@ -161,6 +161,7 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nvw = self.vw # Save a dereference many many times\nwhile len(todo):\n+\nva, esnap, self.curpath = todo.pop()\nself.setEmuSnap(esnap)\n@@ -193,12 +194,11 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nhits[starteip] = h\n# If we ran out of path (branches that went\n- # somewhere that we couldn't follow?\n+ # somewhere that we couldn't follow)?\nif self.curpath is None:\nbreak\ntry:\n-\n# FIXME unify with stepi code...\nop = self.parseOpcode(starteip | tmode)\n@@ -207,8 +207,10 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\ntry:\nself.emumon.prehook(self, op, starteip)\nexcept v_exc.BadOpBytes as e:\n- logger.debug(repr(e))\n+ logger.debug(str(e))\nbreak\n+ except v_exc.BadOutInstruction:\n+ pass\nexcept Exception as e:\nlogger.log(self._log_level, \"funcva: 0x%x opva: 0x%x: %r (%r) (in emumon prehook: %r)\", funcva, starteip, op, e, self.emumon)\n@@ -224,8 +226,14 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nif self.emumon:\ntry:\nself.emumon.posthook(self, op, endeip)\n+ except v_exc.BadOpBytes as e:\n+ logger.debug(str(e))\n+ break\n+ except v_exc.BadOutInstruction:\n+ pass\nexcept Exception as e:\nlogger.log(self._log_level, \"funcva: 0x%x opva: 0x%x: %r (%r) (in emumon posthook: %r)\", funcva, starteip, op, e, self.emumon)\n+\nif self.emustop:\nreturn\n@@ -257,6 +265,15 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nvg_path.setNodeProp(self.curpath, 'cleanret', True)\nbreak\n+ # TODO: hook things like error(...) when they have a param that indicates to\n+ # exit. Might be a bit hairy since we'll possibly have to fix up codeblocks\n+ # Make sure we can at least get past the first instruction in certain functions\n+ if self.vw.isNoReturnVa(op.va) and op.va != funcva:\n+ vg_path.setNodeProp(self.curpath, 'cleanret', False)\n+ break\n+\n+ except envi.BadOpcode:\n+ break\nexcept envi.UnsupportedInstruction as e:\nif self.strictops:\nlogger.debug('runFunction breaking after unsupported instruction: 0x%08x %s', e.op.va, e.op.mnem)\n@@ -264,8 +281,10 @@ class ArmWorkspaceEmulator(v_i_emulator.WorkspaceEmulator, e_arm.ArmEmulator):\nelse:\nlogger.debug('runFunction continuing after unsupported instruction: 0x%08x %s', e.op.va, e.op.mnem)\nself.setProgramCounter(e.op.va + e.op.size)\n+ except v_exc.BadOutInstruction:\n+ break\nexcept Exception as e:\n- if self.emumon is not None:\n+ if self.emumon is not None and not isinstance(e, e_exc.BreakpointHit):\nself.emumon.logAnomaly(self, starteip, str(e))\nlogger.debug('runFunction breaking after exception (fva: 0x%x): %s', funcva, e)\nbreak # If we exc during execution, this branch is dead.\n" } ]
Python
Apache License 2.0
vivisect/vivisect
tweaks per @rakuy0
718,770
15.11.2021 02:51:23
18,000
e0c4f65ca4174b63c2ffb7554579d6309132949a
lots of updates to support getBaseAddrAndSize() on each file format (except macho, which is a wip)
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2736,6 +2736,11 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nreturn self.normFileName(filename)\nmod = viv_parsers.getParserModule(fmtname)\n+ # get baseaddr and size, then make sure we have a good baseaddr\n+ baseaddr, size = mod.getMemoryBaseAndSize(self, filename=filename, baseaddr=baseaddr)\n+ baseaddr = self.findFreeMemoryBlock(size, baseaddr)\n+ logger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n+\nfname = mod.parseFile(self, filename=filename, baseaddr=baseaddr)\nself.initMeta(\"StorageName\", filename+\".viv\")\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/blob.py", "new_path": "vivisect/parsers/blob.py", "diff": "@@ -77,3 +77,10 @@ def parseMemory(vw, memobj, baseaddr):\nvw.setFileMeta(fname, 'sha256', v_parsers.sha256Bytes(bytez))\nvw.addMemoryMap(va, perms, fname, bytez)\nvw.setMeta('DefaultCall', archcalls.get(arch,'unknown'))\n+\n+def getBaseAndSize(vw, filename, baseaddr=None):\n+ if baseaddr is None:\n+ baseaddr = vw.config.viv.parsers.blob.baseaddr\n+ size = os.lstat(filename).st_size\n+ return baseaddr, size\n+\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -43,6 +43,87 @@ def parseFd(vw, fd, filename=None, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('FIXME implement parseMemory for elf!')\n+def getBaseAndSize(vw, filename, baseaddr=None):\n+ '''\n+ Returns the default baseaddr and memory size required to load the file\n+ '''\n+ savebase = baseaddr\n+\n+ fd = open(filename, 'rb')\n+ elf = Elf.Elf(fd)\n+\n+ memmaps = getMemoryMapInfo(elf)\n+ baseaddr = 0xffffffffffffffffffffffff\n+ topmem = 0\n+\n+ for mapva, mperms, mname, mbytes, malign in memmaps:\n+ if mapva < baseaddr:\n+ baseaddr = mapva\n+ endva = mapva + len(mbytes)\n+ if endva > topmem:\n+ topmem = endva\n+\n+ size = topmem - baseaddr\n+ if savebase:\n+ # if we provided a baseaddr, override what the file wants\n+ baseaddr = savebase\n+\n+ return baseaddr, size\n+\n+\n+\n+def getMemoryMapInfo(elf):\n+ '''\n+ Gets the default baseaddr and memory map information\n+ All the information necessary to add memory maps (or get overall size info)\n+ '''\n+ memmaps = []\n+\n+ addbase, baseaddr = getAddBaseAddr(elf)\n+\n+ pgms = elf.getPheaders()\n+ for pgm in pgms:\n+ if pgm.p_type == Elf.PT_LOAD:\n+ if pgm.p_memsz == 0:\n+ continue\n+ logger.info('Loading: %s', pgm)\n+ bytez = elf.readAtOffset(pgm.p_offset, pgm.p_filesz)\n+ bytez += b'\\x00' * (pgm.p_memsz - pgm.p_filesz)\n+ pva = pgm.p_vaddr\n+ if addbase:\n+ pva += baseaddr\n+ memmaps.append((pva, pgm.p_flags & 0x7, fname, bytez, e_const.PAGE_SIZE))\n+ else:\n+ logger.info('Skipping: %s', pgm)\n+\n+ if len(pgms) == 0:\n+ secs = elf.getSections()\n+ # fall back to loading sections as best we can...\n+ vw.vprint('elf: no program headers found!')\n+\n+ maps = [ [s.sh_offset,s.sh_size] for s in secs if s.sh_offset and s.sh_size ]\n+ maps.sort()\n+\n+ merged = []\n+ for i in range(len(maps)):\n+\n+ if merged and maps[i][0] == (merged[-1][0] + merged[-1][1]):\n+ merged[-1][1] += maps[i][1]\n+ continue\n+\n+ merged.append( maps[i] )\n+\n+ baseaddr = 0x05000000\n+ for offset,size in merged:\n+ bytez = elf.readAtOffset(offset,size)\n+ memmaps.append((baseaddr + offset, 0x7, fname, bytez, None))\n+\n+ for sec in secs:\n+ if sec.sh_offset and sec.sh_size:\n+ sec.sh_addr = baseaddr + sec.sh_offset\n+\n+\n+\ndef makeStringTable(vw, va, maxva):\nwhile va < maxva:\n@@ -133,6 +214,17 @@ archcalls = {\n'thumb16': 'armcall',\n}\n+def getAddBaseAddr(elf, baseaddr=None):\n+ '''\n+ # NOTE: This is only for prelink'd so's and exe's. Make something for old style so.\n+ '''\n+ addbase = False\n+ if not elf.isPreLinked() and elf.isSharedObject():\n+ addbase = True\n+ if baseaddr is None:\n+ baseaddr = elf.getBaseAddress()\n+ return addbase, baseaddr\n+\ndef loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# analysis of discovered functions and data locations should be stored until the end of loading\ndata_ptrs = []\n@@ -172,12 +264,8 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nvw.setEndian(elf.getEndian())\n# Base addr is earliest section address rounded to pagesize\n- # NOTE: This is only for prelink'd so's and exe's. Make something for old style so.\n- addbase = False\n- if not elf.isPreLinked() and elf.isSharedObject():\n- addbase = True\n- if baseaddr is None:\n- baseaddr = elf.getBaseAddress()\n+ # Some ELF's require adding the baseaddr to most/all later addresses\n+ addbase, baseaddr = getAddBaseAddr(elf, baseaddr)\nelf.fd.seek(0)\nmd5hash = v_parsers.md5Bytes(byts)\n@@ -210,6 +298,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\npgms = elf.getPheaders()\nsecs = elf.getSections()\n+ '''\nfor pgm in pgms:\nif pgm.p_type == Elf.PT_LOAD:\nif pgm.p_memsz == 0:\n@@ -248,7 +337,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nfor sec in secs:\nif sec.sh_offset and sec.sh_size:\nsec.sh_addr = baseaddr + sec.sh_offset\n-\n+ '''\n# First add all section definitions so we have them\nfor sec in secs:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/ihex.py", "new_path": "vivisect/parsers/ihex.py", "diff": "@@ -30,6 +30,7 @@ def parseFile(vw, filename, baseaddr=None):\nvw.setMeta('DefaultCall', archcalls.get(arch, 'unknown'))\n+ # figure out of there's an offset into the file we need to skip\noffset = vw.config.viv.parsers.ihex.offset\nif not offset:\noffset = 0\n@@ -65,3 +66,39 @@ def parseFile(vw, filename, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('ihex loader cannot parse memory!')\n+\n+def getBaseAndSize(vw, filename, baseaddr=None):\n+ '''\n+ Returns the default baseaddr and memory size required to load the file\n+ '''\n+ savebase = baseaddr\n+\n+ # figure out of there's an offset into the file we need to skip\n+ offset = vw.config.viv.parsers.ihex.offset\n+ if not offset:\n+ offset = 0\n+ ihex = v_ihex.IHexFile()\n+ with open(filename, 'rb') as f:\n+ shdr = f.read(offset)\n+ sbytes = f.read()\n+\n+ ihex.vsParse(sbytes)\n+\n+ memmaps = ihex.geMemoryMaps()\n+ baseaddr = 0xffffffffffffffffffffffff\n+ topmem = 0\n+\n+ for mapva, mperms, mname, mbytes, malign in memmaps:\n+ if mapva < baseaddr:\n+ baseaddr = mapva\n+ endva = mapva + len(mbytes)\n+ if endva > topmem:\n+ topmem = endva\n+\n+ size = topmem - baseaddr\n+ if savebase:\n+ # if we provided a baseaddr, override what the file wants\n+ baseaddr = savebase\n+\n+ return baseaddr, size\n+\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/const.py", "new_path": "vstruct/defs/macho/const.py", "diff": "@@ -202,3 +202,14 @@ N_SECT = 0xe # defined in section number n_sect\nN_PBUD = 0xc # prebound undefined (defined in a dylib)\nN_INDR = 0xa # indirect\n+ENDIAN_LSB = 0\n+ENDIAN_MSB = 1\n+\n+hdr_info = {\n+ 'cefaedfe': (4, ENDIAN_LSB), # Mach-O Little Endian (32-bit)\n+ 'cffaedfe': (8, ENDIAN_LSB), # Mach-O Little Endian (64-bit)\n+ 'feedface': (4, ENDIAN_MSB), # Mach-O Big Endian (32-bit)\n+ 'feedfacf': (8, ENDIAN_MSB), # Mach-O Big Endian (64-bit)\n+ 'cafebabe': (0, -1), # Universal Binary Big Endian. These fat binaries are archives that can include binaries for multiple architectures, but typically contain PowerPC and Intel x86.\n+ 'bebafeca': (0, -1), # Universal Binary Big Endian. These fat binaries are archives that can include binaries for multiple architectures, but typically contain PowerPC and Intel x86.\n+}\n" } ]
Python
Apache License 2.0
vivisect/vivisect
lots of updates to support getBaseAddrAndSize() on each file format (except macho, which is a wip)
718,765
16.11.2021 10:55:18
18,000
f06aee9983a1bfd602cc3adb57dbabcba3834086
Delete Relocation Add a delete relocation even handler
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -400,6 +400,22 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nself._fireEvent(VWE_ADDRELOC, (fname, offset, rtype, data))\nreturn self.getRelocation(va)\n+ def delRelocation(self, va, full=False):\n+ \"\"\"\n+ Delete a tracked relocation.\n+ \"\"\"\n+ mmap = self.getMemoryMap(va)\n+ if not mmap:\n+ logger.warning('delRelocation: No matching map found for %s', va)\n+ return None\n+\n+ mmva, mmsz, mmperm, fname = mmap # FIXME: getFileByVa does not obey file defs\n+ reloc = self.getRelocation(va)\n+ if not reloc:\n+ return None\n+ self._fireEvent(VWE_DELRELOC, (fname, va, reloc, full))\n+ return reloc\n+\ndef getRelocations(self):\n\"\"\"\nGet the current list of relocation entries.\n" }, { "change_type": "MODIFY", "old_path": "vivisect/base.py", "new_path": "vivisect/base.py", "diff": "@@ -261,6 +261,29 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\nself._handleADDXREF((rva, ptr, REF_PTR, 0))\nself._handleADDLOCATION((rva, self.psize, LOC_POINTER, ptr))\n+ def _handleDELRELOC(self, einfo):\n+ fname, rva, rtyp, full = einfo\n+ imgbase = self.getFileMeta(fname, 'imagebase')\n+ ptroff = rva - imgbase\n+\n+ self.reloc_by_va.pop(rva, None)\n+ delidx = -1\n+\n+ for idx, (fn, off, typ, data) in enumerate(self.relocations):\n+ if fn == fname and off == ptroff and typ == rtyp:\n+ delidx = idx\n+ break\n+\n+ if delidx >= 0:\n+ self.relocations.pop(delidx)\n+\n+ if full:\n+ if rtyp == RTYPE_BASEPTR:\n+ ptr = imgbase + data\n+ ptr, reftype, rflags = self.arch.archModifyXrefAddr(ptr, None, None)\n+ self._handleDELXREF((rva, ptr, REF_PTR, 0))\n+ self._handleDELLOCATION((rva, self.psize, LOC_POINTER, ptr))\n+\ndef _handleADDMODULE(self, einfo):\nlogger.warning('DEPRECATED (ADDMODULE) ignored: %s', einfo)\n@@ -510,7 +533,7 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\nself.ehand[VWE_ADDSEGMENT] = self._handleADDSEGMENT\nself.ehand[VWE_DELSEGMENT] = None\nself.ehand[VWE_ADDRELOC] = self._handleADDRELOC\n- self.ehand[VWE_DELRELOC] = None\n+ self.ehand[VWE_DELRELOC] = self._handleDELRELOC\nself.ehand[VWE_ADDMODULE] = self._handleADDMODULE\nself.ehand[VWE_DELMODULE] = self._handleDELMODULE\nself.ehand[VWE_ADDFMODULE] = self._handleADDFMODULE\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -12,6 +12,7 @@ import vivisect.const as v_const\nimport vivisect.tools.graphutil as v_t_graphutil\nimport vivisect.tests.helpers as helpers\n+import vivisect.tests.utils as v_t_utils\nlogger = logging.getLogger(__name__)\n@@ -25,12 +26,13 @@ def isint(x):\nreturn type(x) is int\n-class VivisectTest(unittest.TestCase):\n+class VivisectTest(v_t_utils.VivTest):\n@classmethod\ndef setUpClass(cls):\ncls.firefox_vw = helpers.getTestWorkspace('windows', 'amd64', 'firefox.exe')\ncls.chgrp_vw = helpers.getTestWorkspace('linux', 'i386', 'chgrp.llvm')\ncls.vdir_vw = helpers.getTestWorkspace('linux', 'i386', 'vdir.llvm')\n+ cls.chown_vw = helpers.getTestWorkspace('linux', 'amd64', 'chown')\nfor vw in cls.vdir_vw, cls.chgrp_vw, cls.firefox_vw:\noldcanv = vw.canvas\n@@ -1486,3 +1488,30 @@ class VivisectTest(unittest.TestCase):\n0x140049b40, 0x140049aa0, 0x1400497a0, 0x140049720, 0x140049820, 0x140049a20]\nself.assertEqual(thunks, set(impthunk))\n+\n+ def test_del_reloc(self):\n+ with self.snap(self.chown_vw) as vw:\n+ base = vw.getFileMeta('chown', 'imagebase')\n+\n+ va = 0x20f950\n+ rva = 0x20f950 + base\n+\n+ reloc = [rdat for rdat in vw.getRelocations() if rdat[1] == va]\n+ self.len(reloc, 1)\n+ rtyp = vw.getRelocation(rva)\n+ self.assertEqual(2, rtyp)\n+\n+ old = len(vw.getRelocations())\n+ self.assertEqual(2, vw.delRelocation(rva, full=True))\n+\n+ self.none(vw.getLocation(rva))\n+ self.len(vw.getXrefsFrom(rva), 0)\n+ self.len(vw.getXrefsTo(0x20028a0), 1)\n+ self.eq(2, self.chown_vw.getRelocation(rva))\n+ self.eq(1, old - len(vw.getRelocations()))\n+\n+ self.none(vw.delRelocation(0xabad1dea))\n+\n+ self.nn(self.chown_vw.getLocation(rva))\n+ self.len(self.chown_vw.getXrefsFrom(rva), 1)\n+ self.len(self.chown_vw.getXrefsTo(0x20028a0), 2)\n" }, { "change_type": "ADD", "old_path": null, "new_path": "vivisect/tests/utils.py", "diff": "+import unittest\n+import contextlib\n+\n+import vivisect.cli as v_cli\n+\n+class VivTest(unittest.TestCase):\n+ '''\n+ Base class for vivisect unit tests so that we have a common place to throw certain common\n+ utilities.\n+ '''\n+\n+ def eq(self, x, y):\n+ '''\n+ Assert x is equal to y\n+ '''\n+ self.assertEqual(x, y)\n+\n+ def len(self, x, y):\n+ '''\n+ Assert that length of x is equal to y\n+ '''\n+ self.assertEqual(len(x), y)\n+\n+ def none(self, x):\n+ '''\n+ Assert x is none\n+ '''\n+ self.assertIsNone(x)\n+\n+ def nn(self, x):\n+ '''\n+ Assert x is not none\n+ '''\n+ self.assertIsNotNone(x)\n+\n+ @contextlib.contextmanager\n+ def snap(self, vw):\n+ '''\n+ Checkpoint a workspace. Yields a new workspace that can be editted\n+ as the test needs, and once the context handler ends, all changes will\n+ tossed\n+\n+ To be used with some caution, as it does create a duplicate workspace.\n+ '''\n+ safe = v_cli.VivCli()\n+ events = list(vw.exportWorkspace())\n+ safe.importWorkspace(events)\n+ yield safe\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Delete Relocation (#471) Add a delete relocation even handler
718,770
16.11.2021 20:19:39
18,000
351dfe860273789efc7f6fffcaa1e33abc01e311
working on getMemBaseAndSize
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2759,7 +2759,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nmod = viv_parsers.getParserModule(fmtname)\n# get baseaddr and size, then make sure we have a good baseaddr\n- baseaddr, size = mod.getMemoryBaseAndSize(self, filename=filename, baseaddr=baseaddr)\n+ baseaddr, size = mod.getMemBaseAndSize(self, filename=filename, baseaddr=baseaddr)\nbaseaddr = self.findFreeMemoryBlock(size, baseaddr)\nlogger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/blob.py", "new_path": "vivisect/parsers/blob.py", "diff": "+import os\nimport envi\nimport vivisect.exc as v_exc\nimport vivisect.parsers as v_parsers\n@@ -78,7 +79,7 @@ def parseMemory(vw, memobj, baseaddr):\nvw.addMemoryMap(va, perms, fname, bytez)\nvw.setMeta('DefaultCall', archcalls.get(arch,'unknown'))\n-def getBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, filename, baseaddr=None):\nif baseaddr is None:\nbaseaddr = vw.config.viv.parsers.blob.baseaddr\nsize = os.lstat(filename).st_size\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -43,7 +43,7 @@ def parseFd(vw, fd, filename=None, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('FIXME implement parseMemory for elf!')\n-def getBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, filename, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\n@@ -72,7 +72,7 @@ def getBaseAndSize(vw, filename, baseaddr=None):\n-def getMemoryMapInfo(elf):\n+def getMemoryMapInfo(elf, fname=None):\n'''\nGets the default baseaddr and memory map information\nAll the information necessary to add memory maps (or get overall size info)\n@@ -99,7 +99,7 @@ def getMemoryMapInfo(elf):\nif len(pgms) == 0:\nsecs = elf.getSections()\n# fall back to loading sections as best we can...\n- vw.vprint('elf: no program headers found!')\n+ logger.info('elf: no program headers found! (in %r)', fname)\nmaps = [ [s.sh_offset,s.sh_size] for s in secs if s.sh_offset and s.sh_size ]\nmaps.sort()\n@@ -122,6 +122,8 @@ def getMemoryMapInfo(elf):\nif sec.sh_offset and sec.sh_size:\nsec.sh_addr = baseaddr + sec.sh_offset\n+ return memmaps\n+\ndef makeStringTable(vw, va, maxva):\n@@ -295,49 +297,10 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nfor sec in elf.getSections():\nsecnames.append(sec.getName())\n- pgms = elf.getPheaders()\nsecs = elf.getSections()\n- '''\n- for pgm in pgms:\n- if pgm.p_type == Elf.PT_LOAD:\n- if pgm.p_memsz == 0:\n- continue\n- logger.info('Loading: %s', pgm)\n- bytez = elf.readAtOffset(pgm.p_offset, pgm.p_filesz)\n- bytez += b'\\x00' * (pgm.p_memsz - pgm.p_filesz)\n- pva = pgm.p_vaddr\n- if addbase:\n- pva += baseaddr\n- vw.addMemoryMap(pva, pgm.p_flags & 0x7, fname, bytez, align=e_const.PAGE_SIZE)\n- else:\n- logger.info('Skipping: %s', pgm)\n-\n- if len(pgms) == 0:\n- # fall back to loading sections as best we can...\n- vw.vprint('elf: no program headers found!')\n-\n- maps = [ [s.sh_offset,s.sh_size] for s in secs if s.sh_offset and s.sh_size ]\n- maps.sort()\n-\n- merged = []\n- for i in range(len(maps)):\n-\n- if merged and maps[i][0] == (merged[-1][0] + merged[-1][1]):\n- merged[-1][1] += maps[i][1]\n- continue\n-\n- merged.append( maps[i] )\n-\n- baseaddr = 0x05000000\n- for offset,size in merged:\n- bytez = elf.readAtOffset(offset,size)\n- vw.addMemoryMap(baseaddr + offset, 0x7, fname, bytez)\n-\n- for sec in secs:\n- if sec.sh_offset and sec.sh_size:\n- sec.sh_addr = baseaddr + sec.sh_offset\n- '''\n+ for mmapva, mmperms, mfname, mbytez, malign in getMemoryMapInfo(elf, fname):\n+ vw.addMemoryMap(mmapva, mmperms, mfname, mbytez, malign)\n# First add all section definitions so we have them\nfor sec in secs:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/ihex.py", "new_path": "vivisect/parsers/ihex.py", "diff": "@@ -67,7 +67,7 @@ def parseFile(vw, filename, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('ihex loader cannot parse memory!')\n-def getBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, filename, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\n@@ -84,11 +84,11 @@ def getBaseAndSize(vw, filename, baseaddr=None):\nihex.vsParse(sbytes)\n- memmaps = ihex.geMemoryMaps()\n+ memmaps = ihex.getMemoryMaps()\nbaseaddr = 0xffffffffffffffffffffffff\ntopmem = 0\n- for mapva, mperms, mname, mbytes, malign in memmaps:\n+ for mapva, mperms, mname, mbytes in memmaps:\nif mapva < baseaddr:\nbaseaddr = mapva\nendva = mapva + len(mbytes)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/srec.py", "new_path": "vivisect/parsers/srec.py", "diff": "@@ -64,3 +64,39 @@ def parseFile(vw, filename, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('srec loader cannot parse memory!')\n+\n+def getMemBaseAndSize(vw, filename, baseaddr=None):\n+ '''\n+ Returns the default baseaddr and memory size required to load the file\n+ '''\n+ savebase = baseaddr\n+\n+ # figure out of there's an offset into the file we need to skip\n+ offset = vw.config.viv.parsers.srec.offset\n+ if not offset:\n+ offset = 0\n+ srec = v_srec.SRecFile()\n+ with open(filename, 'rb') as f:\n+ shdr = f.read(offset)\n+ sbytes = f.read()\n+\n+ srec.vsParse(sbytes)\n+\n+ memmaps = srec.getMemoryMaps()\n+ baseaddr = 0xffffffffffffffffffffffff\n+ topmem = 0\n+\n+ for mapva, mperms, mname, mbytes in memmaps:\n+ if mapva < baseaddr:\n+ baseaddr = mapva\n+ endva = mapva + len(mbytes)\n+ if endva > topmem:\n+ topmem = endva\n+\n+ size = topmem - baseaddr\n+ if savebase:\n+ # if we provided a baseaddr, override what the file wants\n+ baseaddr = savebase\n+\n+ return baseaddr, size\n+\n" } ]
Python
Apache License 2.0
vivisect/vivisect
working on getMemBaseAndSize
718,770
18.11.2021 23:38:07
18,000
dfb3d8554e2291dd45f7d3c35655e689bbba9625
bugfix: treating baseaddr as if it is only as provided by DLL. separated out "imagebase" and "baseaddr". making progress on loading. not done yet... but the baseaddr bug helps.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2794,6 +2794,59 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\n# Snapin our analysis modules\nself._snapInAnalysisModules()\n+ def writeMemory(self, va, bytez):\n+ '''\n+ Override writeMemory to hook into the Event subsystem.\n+ '''\n+ fname = self.getFileByVa(va)\n+ fileva = self.getFileMeta(fname, 'imagebase')\n+ off = va - fileva\n+ self._fireEvent(VWE_WRITEMEM, (fname, off, bytez, self._supervisor))\n+\n+ def connectImportsWithExports(self):\n+ \"\"\"\n+ Look for any \"imported\" symbols that are satisfied by current exports.\n+ Wire up the connection.\n+\n+ Currently this is simply a pointer write at the location of the Import.\n+ If this behavior is ever insufficient, we'll want to track the special\n+ nature through the Export/Import events.\n+ \"\"\"\n+ # store old setting and set _supervisor mode (so we can write wherever\n+ # we want, regardless of permissions)\n+ oldsup = self._supervisor\n+ self._supervisor = True\n+\n+ for iva, isz, itype, isym in self.getImports():\n+ impfname, impsym = isym.split('.', 1)\n+ for eva, num, esym, efname in self.getExports():\n+ if impsym != esym:\n+ continue\n+\n+ if impfname not in (efname, '*'):\n+ continue\n+\n+ # file and symbol name match. apply the magic.\n+ # do we ever *not* write in the full address at the import site?\n+ self.writeMemoryPtr(iva, eva)\n+\n+ # check if any xrefs to the import are branches and make code-xrefs for them\n+ for xrfr, xrto, xrt, xrflags in self.getXrefsTo(iva):\n+ loc = self.getLocation(xrfr)\n+ if not loc:\n+ continue\n+\n+ lva, lsz, ltype, ltinfo = loc\n+ if ltype != LOC_OP:\n+ logger.warning(\"XREF not from an Opcode: 0x%x -> 0x%x (%r)\", lva, eva, loc)\n+ continue\n+\n+ op = self.parseOpcode(lva)\n+ self.addXref(lva, eva, REF_CODE)\n+\n+ # restore previous supervisor mode\n+ self._supervisor = oldsup\n+\ndef getFiles(self):\n\"\"\"\nReturn the current list of file objects in this\n" }, { "change_type": "MODIFY", "old_path": "vivisect/base.py", "new_path": "vivisect/base.py", "diff": "@@ -526,6 +526,18 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\n'''\npass\n+ def _handleWRITEMEM(self, einfo):\n+ '''\n+ Handle permanent writes to a memory map after initialization\n+ (fname, off, bytez, supv) where supv is supervisor mode...\n+ '''\n+ fname, off, bytez, supv = einfo\n+ imgbase = self.getFileMeta(fname, 'imagebase')\n+ savesupv = self._supervisor\n+ self._supervisor = True\n+ e_mem.MemoryObject.writeMemory(self, imgbase + off, bytez)\n+ self._supervisor = savesupv\n+\ndef _initEventHandlers(self):\nself.ehand = [None for x in range(VWE_MAX)]\nself.ehand[VWE_ADDLOCATION] = self._handleADDLOCATION\n@@ -569,6 +581,7 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\nself.ehand[VWE_CHAT] = self._handleCHAT\nself.ehand[VWE_SYMHINT] = self._handleSYMHINT\nself.ehand[VWE_AUTOANALFIN] = self._handleAUTOANALFIN\n+ self.ehand[VWE_WRITEMEM] = self._handleWRITEMEM\nself.thand = [None for x in range(VTE_MAX)]\nself.thand[VTE_IAMLEADER] = self._handleIAMLEADER\n" }, { "change_type": "MODIFY", "old_path": "vivisect/const.py", "new_path": "vivisect/const.py", "diff": "@@ -71,7 +71,9 @@ VWE_CHAT = 40 # (username, message)\nVWE_SYMHINT = 41 # (va, idx, hint)\nVWE_AUTOANALFIN = 42 # (starttime, endtime)\n-VWE_MAX = 43\n+VWE_WRITEMEM = 43 # (mapva, offset, bytes)\n+\n+VWE_MAX = 44\n# Constants for vivisect \"transient\" events which flow through\n# the event subsystem but are not recorded to the workspace.\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -13,6 +13,7 @@ import vtrace # needed only for setting the logging level\nimport vtrace.platforms.win32 as vt_win32\nimport envi.exc as e_exc\n+import envi.bits as e_bits\nimport envi.const as e_const\nimport envi.symstore.symcache as e_symcache\n@@ -76,8 +77,8 @@ archcalls = {\n# map PE relocation types to vivisect types where possible\nrelmap = {\n- PE.IMAGE_REL_BASED_HIGHLOW: vivisect.RTYPE_BASEOFF,\n- PE.IMAGE_REL_BASED_DIR64: vivisect.RTYPE_BASEOFF,\n+ PE.IMAGE_REL_BASED_HIGHLOW: (vivisect.RTYPE_BASEOFF, 4),\n+ PE.IMAGE_REL_BASED_DIR64: (vivisect.RTYPE_BASEOFF, 8),\n}\n@@ -105,18 +106,24 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nvw.setMeta('Platform', platform)\nvw.setMeta('DefaultCall', archcalls.get(arch, 'unknown'))\n+ logger.info(\"PE loader: Arch: %r\\tFormat: pe\\tPlatform: %r\\tFilename: %r\\tBaseAddr: 0x%x\", \\\n+ arch, platform, filename, baseaddr)\n# Set ourselves up for extended windows binary analysis\n+ imagebase = pe.IMAGE_NT_HEADERS.OptionalHeader.ImageBase\nif baseaddr is None:\n- baseaddr = pe.IMAGE_NT_HEADERS.OptionalHeader.ImageBase\n- entry = pe.IMAGE_NT_HEADERS.OptionalHeader.AddressOfEntryPoint + baseaddr\n- entryrva = entry - baseaddr\n+ baseaddr = imagebase\n+\n+ entryrva = pe.IMAGE_NT_HEADERS.OptionalHeader.AddressOfEntryPoint\n+ entry = entryrva + baseaddr\ncodebase = pe.IMAGE_NT_HEADERS.OptionalHeader.BaseOfCode\ncodesize = pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfCode\ncodervamax = codebase+codesize\n+ logger.info(\"PE Imagebase: 0x%x\\tentry: 0x%x\\tcodebase: 0x%x\\tcodesize: 0x%x\", \\\n+ imagebase, entry, codebase, codesize)\n# grab the file bytes for hashing\npe.fd.seek(0)\nfhash = v_parsers.md5Bytes(byts)\n@@ -131,6 +138,9 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nif fvivname is None:\nfvivname = fhash\n+ logger.info(\"PE dllname: %r\\tfvivname: %r\\tmd5: %r\\tsha256: %r\", \\\n+ dllname, fvivname, fhash, sha256)\n+\n# create the file and store md5 and sha256 hashes\nfname = vw.addFile(fvivname.lower(), baseaddr, fhash)\nvw.setFileMeta(fname, 'sha256', sha256)\n@@ -350,15 +360,18 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nfor rva, rtype in pe.getRelocations():\n# map PE reloc to VIV reloc ( or dont... )\n- vtype = relmap.get(rtype)\n- if vtype is None:\n+ vtypedata = relmap.get(rtype)\n+ if vtypedata is None:\nlogger.info('Skipping PE Relocation type: %d at %d (no handler)', rtype, rva)\ncontinue\n+ vtype, vtsize = vtypedata\n+\ntry:\n- mapoffset = vw.readMemoryPtr(rva + baseaddr) - baseaddr\n- except:\n- # the target adderss of the relocation is not accessible.\n+ vtfmt = e_bits.getFormat(vtsize) # for PowerPC, will need to get Endianness\n+ mapoffset = vw.readMemoryFormat(rva + baseaddr, vtfmt)[0] - imagebase\n+ except Exception as e:\n+ # the target address of the relocation is not accessible.\n# for example, it's not mapped, or split across sections, etc.\n# technically, the PE is corrupt.\n# by continuing on here, we are a bit more robust (but maybe incorrect)\n@@ -366,9 +379,10 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\n#\n# discussed in:\n# https://github.com/vivisect/vivisect/issues/346\n- logger.warning('Skipping invalid PE relocation: %d', rva)\n+ logger.warning('Skipping invalid PE relocation: %d (%r)', rva, e)\ncontinue\nelse:\n+ logger.info('PE relocation: 0x%x -> %r+0x%x', baseaddr+rva, fname, mapoffset)\nvw.addRelocation(rva + baseaddr, vtype, mapoffset)\nfor rva, lname, iname in pe.getImports():\n" } ]
Python
Apache License 2.0
vivisect/vivisect
bugfix: treating baseaddr as if it is only as provided by DLL. separated out "imagebase" and "baseaddr". making progress on loading. not done yet... but the baseaddr bug helps.
718,770
23.11.2021 14:54:47
18,000
0e088d7c32bd9aec20bba94b8f13d24a1107cb2c
feature: -o to select the output filename bugfix: libc_start_main() errored out with a string mismatch bugfix: move "connectExportsToImports()" to it's own "linker" analysis module bugfix: ELF mobile loading ability!!!!!!!!!!!! <AGCK!> feature: new VaSet "ResolvedImports" for imports that have been resolved and turned into Pointers.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -176,6 +176,8 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nself.addVaSet('CodeFragments', (('va', VASET_ADDRESS), ('calls_from', VASET_COMPLEX)))\nself.addVaSet('EmucodeFunctions', (('va', VASET_ADDRESS),))\nself.addVaSet('FuncWrappers', (('va', VASET_ADDRESS), ('wrapped_va', VASET_ADDRESS),))\n+ self.addVaSet('ResolvedImports', (('va',VASET_ADDRESS), ('symbol', VASET_STRING), \\\n+ ('resolved address', VASET_ADDRESS)))\ndef vprint(self, msg):\nlogger.info(msg)\n@@ -2758,13 +2760,19 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nreturn self.normFileName(filename)\nmod = viv_parsers.getParserModule(fmtname)\n+\n# get baseaddr and size, then make sure we have a good baseaddr\nbaseaddr, size = mod.getMemBaseAndSize(self, filename=filename, baseaddr=baseaddr)\n+ logger.debug('initial baseva: 0x%x size: 0x%x', baseaddr, size)\n+ if baseaddr == 0:\n+ baseaddr = 0x300000\n+\nbaseaddr = self.findFreeMemoryBlock(size, baseaddr)\nlogger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\nfname = mod.parseFile(self, filename=filename, baseaddr=baseaddr)\n+ if not self.getMeta('StorageName'):\nself.initMeta(\"StorageName\", filename+\".viv\")\n# Snapin our analysis modules\n@@ -2812,6 +2820,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nIf this behavior is ever insufficient, we'll want to track the special\nnature through the Export/Import events.\n\"\"\"\n+ logger.info('linking Imports with Exports')\n# store old setting and set _supervisor mode (so we can write wherever\n# we want, regardless of permissions)\noldsup = self._supervisor\n@@ -2828,8 +2837,16 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\n# file and symbol name match. apply the magic.\n# do we ever *not* write in the full address at the import site?\n+ logger.debug(\"connecting Import 0x%x -> Export 0x%x (%r)\", iva, eva, isym)\nself.writeMemoryPtr(iva, eva)\n+ # remove the LOC_IMPORT and make it a Pointer instead\n+ self.delLocation(iva)\n+ self.makePointer(iva, follow=False) # don't follow, it'll be analyzed later?\n+\n+ # store the former Import in a VaSet\n+ self.setVaSetRow('ResolvedImports', (iva, isym, eva))\n+\n# check if any xrefs to the import are branches and make code-xrefs for them\nfor xrfr, xrto, xrt, xrflags in self.getXrefsTo(iva):\nloc = self.getLocation(xrfr)\n@@ -2843,6 +2860,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nop = self.parseOpcode(lva)\nself.addXref(lva, eva, REF_CODE)\n+ logger.debug(\"addXref(0x%x -> 0x%x)\", lva, eva)\n# restore previous supervisor mode\nself._supervisor = oldsup\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/__init__.py", "new_path": "vivisect/analysis/__init__.py", "diff": "@@ -20,6 +20,7 @@ def addAnalysisModules(vw):\nif fmt == 'pe':\n+ vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.entrypoints\")\nvw.addAnalysisModule(\"vivisect.analysis.pe\")\n@@ -90,6 +91,7 @@ def addAnalysisModules(vw):\n# elfplt wants to be run before generic.entrypoints.\nvw.addAnalysisModule(\"vivisect.analysis.elf.elfplt\")\n+ vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.entrypoints\")\nvw.addAnalysisModule(\"vivisect.analysis.elf\")\n@@ -143,6 +145,7 @@ def addAnalysisModules(vw):\nelif fmt == 'macho': # MACH-O ###################################################\n+ vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.entrypoints\")\nif arch == 'i386':\nviv_analysis_i386.addEntrySigs(vw)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -104,9 +104,9 @@ def getGOTByFilename(vw, filename):\nif FGOT is not None:\n# be sure to add the imgbase to FGOT if required\nif vw.getFileMeta(filename, 'addbase'):\n- imgbase = vw.getFileMeta(filename, 'imagebase')\n- logger.debug('Adding Imagebase: 0x%x', imgbase)\n+ imgbase = vw.getFileMeta(filename, 'baseoff')\nFGOT += imgbase\n+ logger.debug('Adding Imagebase(%r) for Dynamics GOT: 0x%x (0x%x)', filename, imgbase, FGOT)\nif FGOT != gotva and None not in (FGOT, gotva):\nlogger.warning(\"Dynamics and Sections have different GOT entries: S:0x%x D:0x%x. using Dynamics\", gotva, FGOT)\n@@ -137,9 +137,9 @@ def getGOTs(vw):\nif FGOT is not None:\n# be sure to add the imgbase to FGOT if required\nif vw.getFileMeta(filename, 'addbase'):\n- imgbase = vw.getFileMeta(filename, 'imagebase')\n- #logger.debug('Adding Imagebase: 0x%x', imgbase)\n+ imgbase = vw.getFileMeta(filename, 'baseoff')\nFGOT += imgbase\n+ logger.debug('Adding Imagebase(%r) for Dynamics GOT: 0x%x (0x%x)', filename, imgbase, FGOT)\nflist = out[filename]\n@@ -170,19 +170,25 @@ def getPLTs(vw):\nfor fname in vw.getFiles():\nfdyns = vw.getFileMeta(fname, 'ELF_DYNAMICS')\nif fdyns is not None:\n- FGOT = fdyns.get('DT_JMPREL')\n- FGOTSZ = fdyns.get('DT_PLTRELSZ')\n+ FPLT = fdyns.get('DT_JMPREL')\n+ FPLTSZ = fdyns.get('DT_PLTRELSZ')\n+\n+ # if we don't have FPLT or FPLTSZ, skip this\n+ if None in (FPLT, FPLTSZ):\n+ continue\n+\nif vw.getFileMeta(fname, 'addbase'):\n- imgbase = vw.getFileMeta(fname, 'imagebase')\n- logger.debug('Adding Imagebase: 0x%x', imgbase)\n- FGOT += imgbase\n+ imgbase = vw.getFileMeta(fname, 'baseoff')\n+ FPLT += imgbase\n+ logger.debug('Adding Imagebase(%r): 0x%x (0x%x)', fname, imgbase, FPLT)\nnewish = True\nfor pltva, pltsize in plts:\n- if FGOT == pltva:\n+ if FPLT == pltva:\nnewish = False\n- if newish and FGOT and FGOTSZ:\n- plts.append((FGOT, FGOTSZ))\n+\n+ if newish:\n+ plts.append((FPLT, FPLTSZ))\nreturn plts\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/libc_start_main.py", "new_path": "vivisect/analysis/elf/libc_start_main.py", "diff": "@@ -87,7 +87,7 @@ class AnalysisMonitor(viv_imp_monitor.AnalysisMonitor):\nif op.iflags & envi.IF_CALL:\n# it's a call, get the target\nbranches = [br for br in op.getBranches(emu) if not (br[1] & envi.BR_FALL)]\n- logger.debug('libc_start_main: 0x%x\\ttgts: %r', self.startmain, branches)\n+ logger.debug('libc_start_main: %r\\ttgts: %r', [hex(x) for x in self.startmain], branches)\n# check if it matches what we believe to be __libc_start_main\nfor branch in branches:\n" }, { "change_type": "ADD", "old_path": null, "new_path": "vivisect/analysis/generic/linker.py", "diff": "+'''\n+Connect any Exports we have to Imports we may also have\n+(most useful for multiple file workspaces)\n+'''\n+def analyze(vw):\n+ #vw.connectImportsWithExports()\n+ pass\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -72,14 +72,14 @@ def getMemBaseAndSize(vw, filename, baseaddr=None):\n-def getMemoryMapInfo(elf, fname=None):\n+def getMemoryMapInfo(elf, fname=None, baseaddr=None):\n'''\nGets the default baseaddr and memory map information\nAll the information necessary to add memory maps (or get overall size info)\n'''\nmemmaps = []\n- addbase, baseaddr = getAddBaseAddr(elf)\n+ addbase, baseoff, baseaddr = getAddBaseAddr(elf, baseaddr)\npgms = elf.getPheaders()\nfor pgm in pgms:\n@@ -90,8 +90,7 @@ def getMemoryMapInfo(elf, fname=None):\nbytez = elf.readAtOffset(pgm.p_offset, pgm.p_filesz)\nbytez += b'\\x00' * (pgm.p_memsz - pgm.p_filesz)\npva = pgm.p_vaddr\n- if addbase:\n- pva += baseaddr\n+ pva += baseoff\nmemmaps.append((pva, pgm.p_flags & 0x7, fname, bytez, e_const.PAGE_SIZE))\nelse:\nlogger.info('Skipping: %s', pgm)\n@@ -151,7 +150,8 @@ def makeSymbolTable(vw, va, maxva):\nva += len(s)\nreturn ret\n-def makeDynamicTable(vw, va, maxva):\n+def makeDynamicTable(vw, va, maxva, baseoff=0):\n+ logger.debug(\"0x%x -> 0x%x\", va, maxva)\nret = []\nsname = 'elf.Elf%dDynamic' % (vw.getPointerSize() * 8)\nwhile va < maxva:\n@@ -165,7 +165,7 @@ def makeDynamicTable(vw, va, maxva):\nbreak\nreturn ret\n-def makeRelocTable(vw, va, maxva, addbase, baseaddr, addend=False):\n+def makeRelocTable(vw, va, maxva, baseoff, addend=False):\nif addend:\nsname = 'elf.Elf%dReloca' % (vw.getPointerSize() * 8)\nelse:\n@@ -177,25 +177,23 @@ def makeRelocTable(vw, va, maxva, addbase, baseaddr, addend=False):\nvw.setComment(va, tname)\nva += len(s)\n-def makeFunctionTable(elf, vw, tbladdr, size, tblname, funcs, ptrs, baseaddr=0, addbase=False):\n- logger.debug('makeFunctionTable(tbladdr=0x%x, size=0x%x, tblname=%r, baseaddr=0x%x)', tbladdr, size, tblname, baseaddr)\n+def makeFunctionTable(elf, vw, tbladdr, size, tblname, funcs, ptrs, baseoff=0):\n+ logger.debug('makeFunctionTable(tbladdr=0x%x, size=0x%x, tblname=%r, baseoff=0x%x)', tbladdr, size, tblname, baseoff)\npsize = vw.getPointerSize()\nfmtgrps = e_bits.fmt_chars[vw.getEndian()]\npfmt = fmtgrps[psize]\nsecbytes = elf.readAtRva(tbladdr, size)\n- if addbase:\n- tbladdr += baseaddr\n+ tbladdr += baseoff\nptr_count = 0\nfor off in range(0, size, psize):\naddr, = struct.unpack_from(pfmt, secbytes, off)\n- if addbase:\n- addr += baseaddr\n+ addr += baseoff\nnstub = tblname + \"_%d\"\npname = nstub % ptr_count\n- vw.makeName(addr, pname, filelocal=True)\n+ vw.makeName(addr, pname, filelocal=True, makeuniq=True)\nptrs.append((tbladdr + off, addr, pname))\nfuncs.append((pname, addr))\nptr_count += 1\n@@ -220,15 +218,25 @@ def getAddBaseAddr(elf, baseaddr=None):\n'''\n# NOTE: This is only for prelink'd so's and exe's. Make something for old style so.\n'''\n- addbase = False\n+ baseoff = 0\n+ logger.debug(\"baseaddr: %r\\tbaseoff: 0x%x\", baseaddr, baseoff)\n+ elfbaseaddr = elf.getBaseAddress()\n+ if baseaddr is None:\n+ baseaddr = elfbaseaddr\n+\nif not elf.isPreLinked() and elf.isSharedObject():\naddbase = True\n- if baseaddr is None:\n- baseaddr = elf.getBaseAddress()\n- return addbase, baseaddr\n+ baseoff = baseaddr\n+ else:\n+ addbase = False\n+ baseoff = baseaddr - elfbaseaddr\n+\n+ logger.debug(\"baseaddr: %r\\tbaseoff: 0x%x\", baseaddr, baseoff)\n+ return addbase, baseoff, baseaddr\ndef loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# analysis of discovered functions and data locations should be stored until the end of loading\n+ logger.info(\"loadElfIntoWorkspace(filename=%r, baseaddr: %r\", filename, baseaddr)\ndata_ptrs = []\nnew_pointers = []\nnew_functions = []\n@@ -267,7 +275,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# Base addr is earliest section address rounded to pagesize\n# Some ELF's require adding the baseaddr to most/all later addresses\n- addbase, baseaddr = getAddBaseAddr(elf, baseaddr)\n+ addbase, baseoff, baseaddr = getAddBaseAddr(elf, baseaddr)\nelf.fd.seek(0)\nmd5hash = v_parsers.md5Bytes(byts)\n@@ -299,7 +307,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nsecs = elf.getSections()\n- for mmapva, mmperms, mfname, mbytez, malign in getMemoryMapInfo(elf, fname):\n+ for mmapva, mmperms, mfname, mbytez, malign in getMemoryMapInfo(elf, fname, baseaddr):\nvw.addMemoryMap(mmapva, mmperms, mfname, mbytez, malign)\n# First add all section definitions so we have them\n@@ -310,8 +318,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue # Skip non-memory mapped sections\nsva = sec.sh_addr\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nvw.addSegment(sva, size, sname, fname)\n@@ -326,8 +333,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue\nsva = phdr.p_vaddr\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nvw.addSegment(sva, phdr.p_memsz, 'PHDR%d' % pcount, fname)\npcount += 1\n@@ -335,54 +341,49 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# load information from dynamics:\nf_init = elf.dyns.get(Elf.DT_INIT)\nif f_init is not None:\n- if addbase:\n- f_init += baseaddr\n- vw.makeName(f_init, \"init_function\", filelocal=True)\n+ f_init += baseoff\n+ vw.makeName(f_init, \"init_function\", filelocal=True, makeuniq=True)\nvw.addEntryPoint(f_init)\nf_fini = elf.dyns.get(Elf.DT_FINI)\nif f_fini is not None:\n- if addbase:\n- f_fini += baseaddr\n- vw.makeName(f_fini, \"fini_function\", filelocal=True)\n+ f_fini += baseoff\n+ vw.makeName(f_fini, \"fini_function\", filelocal=True, makeuniq=True)\nvw.addEntryPoint(f_fini)\nf_inita = elf.dyns.get(Elf.DT_INIT_ARRAY)\nif f_inita is not None:\nf_initasz = elf.dyns.get(Elf.DT_INIT_ARRAYSZ)\n- makeFunctionTable(elf, vw, f_inita, f_initasz, 'init_array', new_functions, new_pointers, baseaddr, addbase)\n+ makeFunctionTable(elf, vw, f_inita, f_initasz, 'init_array', new_functions, new_pointers, baseoff)\nf_finia = elf.dyns.get(Elf.DT_FINI_ARRAY)\nif f_finia is not None:\nf_finiasz = elf.dyns.get(Elf.DT_FINI_ARRAYSZ)\n- makeFunctionTable(elf, vw, f_finia, f_finiasz, 'fini_array', new_functions, new_pointers, baseaddr, addbase)\n+ makeFunctionTable(elf, vw, f_finia, f_finiasz, 'fini_array', new_functions, new_pointers, baseoff)\nf_preinita = elf.dyns.get(Elf.DT_PREINIT_ARRAY)\nif f_preinita is not None:\nf_preinitasz = elf.dyns.get(Elf.DT_PREINIT_ARRAY)\n- makeFunctionTable(elf, vw, f_preinita, f_preinitasz, 'preinit_array', new_functions, new_pointers, baseaddr, addbase)\n+ makeFunctionTable(elf, vw, f_preinita, f_preinitasz, 'preinit_array', new_functions, new_pointers, baseoff)\n# dynamic table\nphdr = elf.getDynPHdr() # file offset?\nif phdr is not None:\nsva, size = phdr.p_vaddr, phdr.p_memsz\n- if addbase:\n- sva += baseaddr # getDynInfo returns (offset, filesz)\n- makeDynamicTable(vw, sva, sva+size)\n+ sva += baseoff # getDynInfo returns (offset, filesz)\n+ makeDynamicTable(vw, sva, sva+size, baseoff)\n# if there's no Dynamics PHDR, don't bother trying to parse it from Sections. It doesn't exist.\n# dynstr table\nsva, size = elf.getDynStrTabInfo()\nif sva is not None:\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nmakeStringTable(vw, sva, sva+size)\n# dynsyms table\nsva, symsz, size = elf.getDynSymTabInfo()\nif sva is not None:\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\n[s for s in makeSymbolTable(vw, sva, sva+size)]\n# Now trigger section specific analysis\n@@ -394,8 +395,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue # Skip non-memory mapped sections\nsva = sec.sh_addr\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\n# if we've already defined a location at this address, skip it. (eg. DYNAMICS)\nif vw.getLocation(sva) == sva:\n@@ -411,7 +411,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nnew_functions.append(init_tup)\nelif sname == \".init_array\":\n- makeFunctionTable(elf, vw, sec.sh_addr, size, 'init_function', new_functions, new_pointers, baseaddr, addbase)\n+ makeFunctionTable(elf, vw, sec.sh_addr, size, 'init_function', new_functions, new_pointers, baseoff)\nelif sname == \".fini\":\nfini_tup = (\"fini_function\", sva)\n@@ -420,10 +420,10 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nnew_functions.append(fini_tup)\nelif sname == \".fini_array\":\n- makeFunctionTable(elf, vw, sec.sh_addr, size, 'fini_function', new_functions, new_pointers, baseaddr, addbase)\n+ makeFunctionTable(elf, vw, sec.sh_addr, size, 'fini_function', new_functions, new_pointers, baseoff)\nelif sname == \".dynamic\": # Imports\n- makeDynamicTable(vw, sva, sva+size)\n+ makeDynamicTable(vw, sva, sva+size, baseoff)\nelif sname == \".dynstr\": # String table for dynamics\nmakeStringTable(vw, sva, sva+size)\n@@ -439,10 +439,10 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nmakeSymbolTable(vw, sva, sva+size)\nelif sec.sh_type == Elf.SHT_REL:\n- makeRelocTable(vw, sva, sva+size, addbase, baseaddr)\n+ makeRelocTable(vw, sva, sva+size, baseoff)\nelif sec.sh_type == Elf.SHT_RELA:\n- makeRelocTable(vw, sva, sva+size, addbase, baseaddr, addend=True)\n+ makeRelocTable(vw, sva, sva+size, baseoff, addend=True)\nif sec.sh_flags & Elf.SHF_STRINGS:\nmakeStringTable(vw, sva, sva+size)\n@@ -463,11 +463,12 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# but isn't currently accessible from the gui\nvw.setFileMeta(fname, 'ELF_DYNAMICS', elfmeta)\nvw.setFileMeta(fname, 'addbase', addbase)\n+ vw.setFileMeta(fname, 'baseoff', baseoff)\n# applyRelocs is specifically prior to \"process Dynamic Symbols\" because Dynamics-only symbols\n# (ie. not using Section Headers) may not get all the symbols. Some ELF's simply list too\n# small a space using SYMTAB and SYMTABSZ\n- postfix = applyRelocs(elf, vw, addbase, baseaddr)\n+ postfix = applyRelocs(elf, vw, addbase, baseoff)\n# process Dynamic Symbols - this must happen *after* relocations, which can expand the size of this\nfor s in elf.getDynSyms():\n@@ -476,8 +477,8 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nif sva == 0:\ncontinue\n- if addbase:\n- sva += baseaddr\n+\n+ sva += baseoff\nif sva == 0:\ncontinue\n@@ -504,8 +505,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# So aparently Elf64 binaries on amd64 use HIOS and then\n# s.st_other cause that's what all the kewl kids are doing...\nsva = s.st_other\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nif vw.isValidPointer(sva):\ntry:\nnew_functions.append((\"DynSym: STT_HIOS\", sva))\n@@ -516,8 +516,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nelif stype == Elf.STT_MDPROC: # there's only one that isn't HI or LO...\nsva = s.st_other\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nif vw.isValidPointer(sva):\ntry:\nvw.addExport(sva, EXP_DATA, dmglname, fname, makeuniq=True)\n@@ -530,10 +529,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nif dmglname in postfix:\nfor rlva, addend in postfix[dmglname]:\n- if addbase:\n- vw.addRelocation(rlva, RTYPE_BASEPTR, sva + addend - baseaddr)\n- else:\n- vw.addRelocation(rlva, RTYPE_BASEPTR, sva + addend)\n+ vw.addRelocation(rlva, RTYPE_BASEPTR, sva + addend - baseoff)\nvw.addVaSet(\"FileSymbols\", ((\"Name\", VASET_STRING), (\"va\", VASET_ADDRESS)))\nvw.addVaSet(\"WeakSymbols\", ((\"Name\", VASET_STRING), (\"va\", VASET_ADDRESS)))\n@@ -559,8 +555,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# mapping symbol\nif arch in ('arm', 'thumb', 'thumb16'):\nsymname = s.getName()\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nif symname == '$a':\n# ARM code\nlogger.info('mapping (NOTYPE) ARM symbol: 0x%x: %r', sva, dmglname)\n@@ -577,8 +572,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ndata_ptrs.append(sva)\nelif s.getInfoType() == Elf.STT_OBJECT:\nsymname = s.getName()\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nif symname:\nvw.makeName(sva, symname, filelocal=True, makeuniq=True)\nvalu = vw.readMemoryPtr(sva)\n@@ -623,8 +617,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# TODO: make use of _ZTSN (typeinfo) and _ZTVN (vtable) entries if name demangles cleanly\n- if addbase:\n- sva += baseaddr\n+ sva += baseoff\nif vw.isValidPointer(sva) and len(dmglname):\ntry:\nif s.getInfoBind() == Elf.STB_WEAK:\n@@ -645,10 +638,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nif s.st_info == Elf.STT_FUNC:\nnew_functions.append((\"STT_FUNC\", sva))\n- if addbase:\n- eentry = baseaddr + elf.e_entry\n- else:\n- eentry = elf.e_entry\n+ eentry = baseoff + elf.e_entry\nif vw.isValidPointer(eentry):\nvw.addExport(eentry, EXP_FUNCTION, '__entry', fname)\n@@ -671,7 +661,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nreturn fname\n-def applyRelocs(elf, vw, addbase=False, baseaddr=0):\n+def applyRelocs(elf, vw, addbase=False, baseoff=0):\n'''\nprocess relocations / strings (relocs use Dynamic Symbols)\n'''\n@@ -682,8 +672,7 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\nfor r in relocs:\nrtype = Elf.getRelocType(r.r_info)\nrlva = r.r_offset\n- if addbase:\n- rlva += baseaddr\n+ rlva += baseoff\ntry:\n# If it has a name, it's an externally resolved \"import\" entry,\n# otherwise, just a regular reloc\n@@ -811,8 +800,7 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\nvw.makeName(rlva, pname)\n# name the target as well\n- if addbase:\n- ptr += baseaddr\n+ ptr += baseoff\n# normalize thumb addresses\nptr &= -2\nvw.makeName(ptr, name)\n@@ -839,8 +827,7 @@ def applyRelocs(elf, vw, addbase=False, baseaddr=0):\nif vw.vaByName(pname) is None:\nvw.makeName(rlva, pname)\n- if addbase:\n- ptr += baseaddr\n+ ptr += baseoff\nvw.makeImport(ptr, \"*\", dmglname)\nvw.setComment(ptr, name)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/teststorage.py", "new_path": "vivisect/tests/teststorage.py", "diff": "@@ -65,8 +65,8 @@ class StorageTests(unittest.TestCase):\nold = list(vw.exportWorkspace())\nnew = list(ovw.exportWorkspace())\n- self.assertEqual(len(old), 35)\n- self.assertEqual(len(new), 36) # the last event is a setMeta made by loadWorkspace\n+ self.assertEqual(len(old), 36)\n+ self.assertEqual(len(new), 37) # the last event is a setMeta made by loadWorkspace\nself.assertEqual(new[-1], (VWE_SETMETA, ('StorageName', self.tmpf.name)))\nfor idx in range(len(old)):\nself.assertEqual(old[idx], new[idx])\n@@ -96,14 +96,14 @@ class StorageTests(unittest.TestCase):\nmvw._event_list = []\nmvw.loadWorkspace(mpfile.name)\nmevt = list(mvw.exportWorkspace())\n- self.assertEqual(len(mevt), 36)\n+ self.assertEqual(len(mevt), 37)\nbvw = vivisect.VivWorkspace()\nbvw.setMeta('StorageModule', 'vivisect.storage.basicfile')\nbvw._event_list = []\nbvw.loadWorkspace(basicfile.name)\nbevt = list(bvw.exportWorkspace())\n- self.assertEqual(len(bevt), 36)\n+ self.assertEqual(len(bevt), 37)\n# the last three events are specific to the different storage modules\nfor idx in range(len(mevt) - 3):\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -191,7 +191,7 @@ class VivisectTest(v_t_utils.VivTest):\nself.chgrp_vw.do_filemeta('chgrp')\noutput = self.chgrp_vw.canvas.strval\nself.assertIn(\"'DT_INIT': 134516068\", output)\n- self.assertIn(\"'addbase': False,\\n 'canaries': False,\\n 'imagebase': 134512640\", output)\n+ self.assertIn(\"'canaries': False,\\n 'imagebase': 134512640\", output)\nself.chgrp_vw.canvas.clearCanvas()\ndef test_cli_fscope(self):\n@@ -717,7 +717,7 @@ class VivisectTest(v_t_utils.VivTest):\n'''\nvw = self.firefox_vw\nself.assertIsNotNone(vw.parsedbin)\n- self.assertEqual(set(['Emulation Anomalies', 'EntryPoints', 'SwitchCases', 'EmucodeFunctions', 'PointersFromFile', 'FuncWrappers', 'CodeFragments', 'DynamicBranches', 'Bookmarks', 'NoReturnCalls', 'DelayImports', 'Library Loads', 'pe:ordinals']), set(vw.getVaSetNames()))\n+ self.assertEqual(set(['Emulation Anomalies', 'EntryPoints', 'SwitchCases', 'EmucodeFunctions', 'PointersFromFile', 'FuncWrappers', 'CodeFragments', 'DynamicBranches', 'Bookmarks', 'NoReturnCalls', 'DelayImports', 'Library Loads', 'pe:ordinals', 'ResolvedImports']), set(vw.getVaSetNames()))\nself.assertEqual((0x14001fa5a, 6, 10, None), vw.getPrevLocation(0x14001fa60))\nself.assertEqual((0x14001fa5a, 6, 10, None), vw.getPrevLocation(0x14001fa60, adjacent=True))\n" }, { "change_type": "MODIFY", "old_path": "vivisect/vivbin.py", "new_path": "vivisect/vivbin.py", "diff": "@@ -44,6 +44,8 @@ def main():\nhelp='Path to a directory to use for config data')\nparser.add_argument('-a', '--autosave', dest='autosave', default=False, action='store_true',\nhelp='Autosave configuration data')\n+ parser.add_argument('-o', '--outfile', default=None,\n+ help='Name of VivWorkspace file to create (useful for loading multiple binaries into one workspace)')\nparser.add_argument('file', nargs='*')\nargs = parser.parse_args()\n@@ -54,6 +56,9 @@ def main():\nlevel = e_common.LOG_LEVELS[vw.verbose]\ne_common.initLogging(logger, level=level)\n+ if args.outfile:\n+ vw.setMeta('StorageName', args.outfile)\n+\n# do things\nif args.option is not None:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
feature: -o to select the output filename bugfix: libc_start_main() errored out with a string mismatch bugfix: move "connectExportsToImports()" to it's own "linker" analysis module bugfix: ELF mobile loading ability!!!!!!!!!!!! <AGCK!> feature: new VaSet "ResolvedImports" for imports that have been resolved and turned into Pointers.
718,770
23.11.2021 23:01:03
18,000
038e15410bd6c0b72d4a245043320617c00a7324
improvement: Dynamics add-base-offset before storage, and cleanup unittest: adding multi-file and non-caching options in helpers. tests to come.
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -102,12 +102,6 @@ def getGOTByFilename(vw, filename):\nif fdyns is not None:\nFGOT = fdyns.get('DT_PLTGOT')\nif FGOT is not None:\n- # be sure to add the imgbase to FGOT if required\n- if vw.getFileMeta(filename, 'addbase'):\n- imgbase = vw.getFileMeta(filename, 'baseoff')\n- FGOT += imgbase\n- logger.debug('Adding Imagebase(%r) for Dynamics GOT: 0x%x (0x%x)', filename, imgbase, FGOT)\n-\nif FGOT != gotva and None not in (FGOT, gotva):\nlogger.warning(\"Dynamics and Sections have different GOT entries: S:0x%x D:0x%x. using Dynamics\", gotva, FGOT)\n@@ -135,12 +129,6 @@ def getGOTs(vw):\nif fdyns is not None:\nFGOT = fdyns.get('DT_PLTGOT')\nif FGOT is not None:\n- # be sure to add the imgbase to FGOT if required\n- if vw.getFileMeta(filename, 'addbase'):\n- imgbase = vw.getFileMeta(filename, 'baseoff')\n- FGOT += imgbase\n- logger.debug('Adding Imagebase(%r) for Dynamics GOT: 0x%x (0x%x)', filename, imgbase, FGOT)\n-\nflist = out[filename]\nskip = False\n@@ -177,11 +165,6 @@ def getPLTs(vw):\nif None in (FPLT, FPLTSZ):\ncontinue\n- if vw.getFileMeta(fname, 'addbase'):\n- imgbase = vw.getFileMeta(fname, 'baseoff')\n- FPLT += imgbase\n- logger.debug('Adding Imagebase(%r) for Dynamics PLT: 0x%x (0x%x)', fname, imgbase, FPLT)\n-\nnewish = True\nfor pltva, pltsize in plts:\nif FPLT == pltva:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -234,6 +234,20 @@ def getAddBaseAddr(elf, baseaddr=None):\nlogger.debug(\"baseaddr: %r\\tbaseoff: 0x%x\", baseaddr, baseoff)\nreturn addbase, baseoff, baseaddr\n+# which Dynamic Types require rebasing\n+dt_rebase = (\n+ Elf.DT_INIT,\n+ Elf.DT_FINI,\n+ Elf.DT_INIT_ARRAY,\n+ Elf.DT_FINI_ARRAY,\n+ Elf.DT_GNU_HASH,\n+ Elf.DT_STRTAB,\n+ Elf.DT_SYMTAB,\n+ Elf.DT_PLTGOT,\n+ Elf.DT_JMPREL,\n+ Elf.DT_REL,\n+ Elf.DT_VERNEED,\n+)\ndef loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# analysis of discovered functions and data locations should be stored until the end of loading\nlogger.info(\"loadElfIntoWorkspace(filename=%r, baseaddr: %r\", filename, baseaddr)\n@@ -458,7 +472,11 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nelse:\nlogger.debug(\"DYNAMIC:\\t%r\", d)\n- elfmeta[Elf.dt_names.get(d.d_tag)] = d.d_value\n+ dval = d.d_value\n+ if d.d_tag in dt_rebase and addbase:\n+ dval += baseoff\n+\n+ elfmeta[Elf.dt_names.get(d.d_tag)] = dval\n# TODO: create a VaSet instead? setMeta allows more free-form info,\n# but isn't currently accessible from the gui\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/helpers.py", "new_path": "vivisect/tests/helpers.py", "diff": "@@ -32,13 +32,32 @@ def getTestPath(*paths):\n@functools.lru_cache()\n-def getTestWorkspace(*paths):\n+def getTestWorkspace(*paths, vw=None):\ntestdir = os.getenv('VIVTESTFILES')\nif not testdir:\nraise unittest.SkipTest('VIVTESTFILES env var not found!')\n+\n+ testdir = os.path.abspath(testdir)\n+ fpath = os.path.join(testdir, *paths)\n+\n+ if not vw:\n+ vw = v_cli.VivCli()\n+\n+ vw.loadFromFile(fpath)\n+ vw.analyze()\n+ return vw\n+\n+def getTestWorkspace_nocache(*paths, vw=None):\n+ testdir = os.getenv('VIVTESTFILES')\n+ if not testdir:\n+ raise unittest.SkipTest('VIVTESTFILES env var not found!')\n+\ntestdir = os.path.abspath(testdir)\nfpath = os.path.join(testdir, *paths)\n+\n+ if not vw:\nvw = v_cli.VivCli()\n+\nvw.loadFromFile(fpath)\nvw.analyze()\nreturn vw\n" } ]
Python
Apache License 2.0
vivisect/vivisect
improvement: Dynamics add-base-offset before storage, and cleanup unittest: adding multi-file and non-caching options in helpers. tests to come.
718,770
24.11.2021 20:54:53
18,000
ae1922739af7e31353d38034a76dc71f4b3be41b
completed unittests for loading multiple binaries.
[ { "change_type": "ADD", "old_path": null, "new_path": "vivisect/tests/testvivisect_multi.py", "diff": "+import logging\n+import unittest\n+import vivisect.tests.helpers as helpers\n+import vivisect.tests.utils as v_t_utils\n+\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class VivisectMultiFileTest(v_t_utils.VivTest):\n+ def test_multiple_i386(self):\n+ vw = helpers.getTestWorkspace_nocache('linux', 'i386', 'chgrp.llvm')\n+ vw = helpers.getTestWorkspace_nocache('linux', 'i386', 'vdir.llvm', vw=vw)\n+ vw = helpers.getTestWorkspace_nocache('linux', 'i386', 'ld-2.31.so', vw=vw)\n+\n+ # test memory maps are not overlapping\n+ for mmap1 in vw.getMemoryMaps():\n+ for mmap2 in vw.getMemoryMaps():\n+ if mmap1 == mmap2:\n+ continue\n+\n+ mmva1, mmsz1, mmp1, mmnm1 = mmap1\n+ mmva2, mmsz2, mmp2, mmnm2 = mmap2\n+ self.assertFalse(mmva1 <= mmva2 < (mmva1 + mmsz1))\n+ self.assertFalse(mmva2 <= mmva1 < (mmva2 + mmsz2))\n+\n+ # test __entry values\n+ vdir = vw.parseExpression('vdir')\n+ chgrp = vw.parseExpression('chgrp')\n+ ld_2_31 = vw.parseExpression('ld_2_31')\n+\n+ vdir_entry = vw.parseExpression('vdir.__entry')\n+ chgrp_entry = vw.parseExpression('chgrp.__entry')\n+ ld_2_31_entry = vw.parseExpression('ld_2_31.__entry')\n+\n+ self.assertEqual(vdir_entry-vdir, 7024)\n+ self.assertEqual(chgrp_entry-chgrp, 4576)\n+ self.assertEqual(ld_2_31_entry-ld_2_31, 4384)\n+\n+ # test main functions\n+ vdir_main = vw.parseExpression('vdir.main')\n+ chgrp_main = vw.parseExpression('chgrp.main')\n+\n+ self.assertEqual(vdir_main-vdir, 7312)\n+ self.assertEqual(chgrp_main-chgrp, 5712)\n+\n+ # test PLT functions\n+ vdir_plt_names = [(va,name) for va,name in vw.getNames() if 'vdir.plt_' in name]\n+ chgrp_plt_names = [(va,name) for va,name in vw.getNames() if 'chgrp.plt_' in name]\n+ ld_2_31_plt_names = [(va,name) for va,name in vw.getNames() if 'ld_2_31.plt_' in name]\n+ self.assertEqual(len(vdir_plt_names), 0) # can't expect PLT analysis to work for a binary not intended to be relocated.\n+ self.assertEqual(len(chgrp_plt_names), 70) # this is more than we get when loading chgrp on it's own!?\n+ self.assertEqual(len(ld_2_31_plt_names), 8)\n+\n+ ## now just poke at one or two in each proggy\n+ ### chgrp __gmon_start__\n+ got_gmon_start = vw.parseExpression('chgrp+0xbffc')\n+ plt_gmon_start = vw.parseExpression('chgrp+0x11d0')\n+ self.assertIn('*.__gmon_start___', vw.getName(got_gmon_start))\n+ self.assertIn('plt___gmon_start__', vw.getName(plt_gmon_start))\n+ self.assertIn((plt_gmon_start, got_gmon_start, 2, 0), vw.getXrefsFrom(plt_gmon_start))\n+\n+ ### chgrp __assert_fail\n+ got_gmon_start = vw.parseExpression('chgrp+0xbffc')\n+ plt_gmon_start = vw.parseExpression('chgrp+0x11d0')\n+ self.assertIn('*.__gmon_start___', vw.getName(got_gmon_start))\n+ self.assertIn('plt___gmon_start__', vw.getName(plt_gmon_start))\n+ self.assertIn((plt_gmon_start, got_gmon_start, 2, 0), vw.getXrefsFrom(plt_gmon_start))\n+\n+ # test exports\n+ for exp in vw.getExports():\n+ eva, etype, esym, efile = exp\n+ mmap = vw.getMemoryMap(eva)\n+ self.assertEqual(mmap[3], efile, msg=\"Failed: %r for %r\" % (exp, mmap))\n+\n+ # test GOT locations\n+ vdir_main = vw.parseExpression('vdir.main')\n+ chgrp_main = vw.parseExpression('chgrp.main')\n+\n+ self.assertEqual(vdir_main-vdir, 7312)\n+ self.assertEqual(chgrp_main-chgrp, 5712)\n+\n+ # test Relocs\n+ self.assertIn(('ld_2_31', 179948, 2, 135749), vw.getRelocations())\n+ rel0 = vw.parseExpression('ld_2_31 + 179948')\n+ ptr0 = vw.parseExpression('ld_2_31 + 135749')\n+ self.assertIn((rel0, ptr0, 3, 0), vw.getXrefsFrom(rel0))\n+\n+\n+ # test Sections\n+ for seg in vw.getSegments():\n+ if seg[2] == '.text':\n+ if seg[3] == 'vdir':\n+ self.assertEqual(7024, seg[0] - vw.parseExpression('vdir'))\n+ if seg[3] == 'chgrp':\n+ self.assertEqual(4576, seg[0] - vw.parseExpression('chgrp'))\n+ if seg[3] == 'ld_2_31':\n+ self.assertEqual(4352, seg[0] - vw.parseExpression('ld_2_31'))\n" } ]
Python
Apache License 2.0
vivisect/vivisect
completed unittests for loading multiple binaries.
718,770
01.12.2021 12:41:11
18,000
8a305492724aef55bcaaef4e4a201432a2c2f1d5
a couple related bugfixes found floating around.
[ { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -574,7 +574,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nif dohex:\nmemstr = binascii.unhexlify(memstr)\nif douni:\n- memstr = (\"\\x00\".join(memstr)) + \"\\x00\"\n+ memstr = (b\"\\x00\".join(memstr)) + b\"\\x00\"\naddr = self.parseExpression(exprstr)\nself.memobj.writeMemory(addr, memstr)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -566,11 +566,12 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nElf.st_info_bind.get(s.st_other, s.st_other),\ns.name)\n- if s.getInfoType() == Elf.STT_FILE:\n+ symtype = s.getInfoType()\n+ if symtype == Elf.STT_FILE:\nvw.setVaSetRow('FileSymbols', (dmglname, sva))\ncontinue\n- elif s.getInfoType() == Elf.STT_NOTYPE:\n+ elif symtype == Elf.STT_NOTYPE:\n# mapping symbol\nif arch in ('arm', 'thumb', 'thumb16'):\nsymname = s.getName()\n@@ -589,7 +590,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# Data Items (eg. literal pool)\nlogger.info('mapping (NOTYPE) data symbol: 0x%x: %r', sva, dmglname)\ndata_ptrs.append(sva)\n- elif s.getInfoType() == Elf.STT_OBJECT:\n+ elif symtype == Elf.STT_OBJECT:\nsymname = s.getName()\nsva += baseoff\nif symname:\n@@ -622,6 +623,15 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nelse:\nvw.makeNumber(sva, size=s.st_size)\n+ elif symtype == Elf.STT_FUNC:\n+ sva += baseoff\n+\n+ symname = s.getName()\n+ if symname:\n+ vw.makeName(sva, symname, filelocal=True, makeuniq=True)\n+\n+ new_functions.append((\"Symbol: FUNC\", sva))\n+\n# if the symbol has a value of 0, it is likely a relocation point which gets updated\nsname = demangle(s.name)\nif sva == 0:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
a couple related bugfixes found floating around.
718,770
01.12.2021 17:02:39
18,000
011897323f7e66280cb7aeeb1d1b66f053173c86
woops, make linker work again.
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/generic/linker.py", "new_path": "vivisect/analysis/generic/linker.py", "diff": "@@ -3,5 +3,4 @@ Connect any Exports we have to Imports we may also have\n(most useful for multiple file workspaces)\n'''\ndef analyze(vw):\n- #vw.connectImportsWithExports()\n- pass\n+ vw.connectImportsWithExports()\n" } ]
Python
Apache License 2.0
vivisect/vivisect
woops, make linker work again.
718,770
01.12.2021 19:04:08
18,000
2a3dcbdc428e90e47a61c81e4cc78f04f63d7aa7
kill it. too many issues
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -623,15 +623,6 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nelse:\nvw.makeNumber(sva, size=s.st_size)\n- elif symtype == Elf.STT_FUNC:\n- sva += baseoff\n-\n- symname = s.getName()\n- if symname and vw.isValidPointer(sva):\n- vw.makeName(sva, symname, filelocal=True, makeuniq=True)\n-\n- new_functions.append((\"Symbol: FUNC\", sva))\n-\n# if the symbol has a value of 0, it is likely a relocation point which gets updated\nsname = demangle(s.name)\nif sva == 0:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
kill it. too many issues
718,770
01.12.2021 23:34:38
18,000
9a5693908e1c238b9f2ec9b8845c4bc44d8d08b5
rearrange ELF analysis to catch function thunks (elfplt/entrypoints).
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2835,6 +2835,10 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nif impfname not in (efname, '*'):\ncontinue\n+ if self.isFunctionThunk(eva):\n+ logger.info(\"Skipping Exported Thunk\")\n+ continue\n+\n# file and symbol name match. apply the magic.\n# do we ever *not* write in the full address at the import site?\nlogger.debug(\"connecting Import 0x%x -> Export 0x%x (%r)\", iva, eva, isym)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/__init__.py", "new_path": "vivisect/analysis/__init__.py", "diff": "@@ -91,9 +91,9 @@ def addAnalysisModules(vw):\n# elfplt wants to be run before generic.entrypoints.\nvw.addAnalysisModule(\"vivisect.analysis.elf.elfplt\")\n- vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.entrypoints\")\nvw.addAnalysisModule(\"vivisect.analysis.elf\")\n+ vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nif arch in ('i386', 'amd64', 'arm'):\nvw.addImpApi('posix', arch)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
rearrange ELF analysis to catch function thunks (elfplt/entrypoints).
718,770
02.12.2021 00:06:25
18,000
f488325cf0f6d0915c17e7ce6808a5db01fabc61
even later for ELF. make sure all of PLT is analyzed before linking.
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/__init__.py", "new_path": "vivisect/analysis/__init__.py", "diff": "@@ -93,7 +93,6 @@ def addAnalysisModules(vw):\nvw.addAnalysisModule(\"vivisect.analysis.elf.elfplt\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.entrypoints\")\nvw.addAnalysisModule(\"vivisect.analysis.elf\")\n- vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nif arch in ('i386', 'amd64', 'arm'):\nvw.addImpApi('posix', arch)\n@@ -140,6 +139,7 @@ def addAnalysisModules(vw):\nvw.addFuncAnalysisModule(\"vivisect.analysis.elf.elfplt\")\n# late-analysis ELF PLT tidying up, allowing unused PLT entries to be made into functions\nvw.addAnalysisModule(\"vivisect.analysis.elf.elfplt_late\")\n+ vw.addAnalysisModule(\"vivisect.analysis.generic.linker\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.thunks\")\nvw.addAnalysisModule(\"vivisect.analysis.generic.pointers\")\n" } ]
Python
Apache License 2.0
vivisect/vivisect
even later for ELF. make sure all of PLT is analyzed before linking.
718,770
27.12.2021 17:05:57
18,000
b28b46c8fb302ba9b8e813179178e66e182c096d
updates to support big-endian MachO
[ { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/__init__.py", "new_path": "vstruct/defs/macho/__init__.py", "diff": "@@ -4,8 +4,6 @@ Structure definitions for the OSX MachO binary format.\nimport struct\nimport logging\nimport binascii\n-import vstruct\n-import envi.bits as e_bits\nimport vstruct\nimport envi.bits as e_bits\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/loader.py", "new_path": "vstruct/defs/macho/loader.py", "diff": "import vstruct\n-import envi.common as e_common\nfrom vstruct.primitives import *\nfrom vstruct.defs.macho.const import *\n@@ -502,9 +501,7 @@ class data_in_code_entry(vstruct.VStruct):\ncommand_classes = {\nLC_SEGMENT: segment_command,\n- LC_SEGMENT_64: segment_command_64,\nLC_SYMTAB: symtab_command,\n- LC_DYSYMTAB: dysymtab_command,\nLC_LOAD_DYLIB: dylib_command,\nLC_SEGMENT: segment_command,\n" } ]
Python
Apache License 2.0
vivisect/vivisect
updates to support big-endian MachO
718,770
27.12.2021 17:30:06
18,000
8f05afcd8cd9e97b2c4990db0413552089ae2a70
make LC_UNIXTHREAD/thread_command work with .flavor (and getEntryPoints()) updates to work with bigendian (and wonky git-shit)
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/macho.py", "new_path": "vivisect/parsers/macho.py", "diff": "@@ -130,8 +130,8 @@ def _loadMacho(vw, filebytes, filename=None, baseaddr=None):\nfor libname in macho.getLibDeps():\nlogger.debug(\"deplib: %r\", libname)\n# FIXME hack....\n- libname = libname.split(b'/')[-1]\n- libname = libname.split(b'.')[0].lower()\n+ libname = libname.split('/')[-1]\n+ libname = libname.split('.')[0].lower()\nvw.addLibraryDependancy(libname)\nlogger.debug(\"memoryMaps: \\n%r\", '\\n'.join([\"0x%x, 0x%x, 0x%x, %r\" % (w,x,y,z) for w,x,y,z in vw.getMemoryMaps()]))\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/loader.py", "new_path": "vstruct/defs/macho/loader.py", "diff": "@@ -234,12 +234,32 @@ class dylinker_command(load_command):\nload_command.__init__(self, bigend=bigend)\nself.name = lc_str() # dynamic linker's path name\n-\n+# Thread commands contain machine-specific data structures suitable for\n+# use in the thread state primitives. The machine specific data structures\n+# follow the struct thread_command as follows.\n+# Each flavor of machine specific data structure is preceded by an unsigned\n+# long constant for the flavor of that data structure, an uint32_t\n+# that is the count of longs of the size of the state data structure and then\n+# the state data structure follows. This triple may be repeated for many\n+# flavors. The constants for the flavors, counts and state data structure\n+# definitions are expected to be in the header file <machine/thread_status.h>.\n+# These machine specific data structures sizes must be multiples of\n+# 4 bytes The cmdsize reflects the total size of the thread_command\n+# and all of the sizes of the constants for the flavors, counts and state\n+# data structures.\n+#\n+# For executable objects that are unix processes there will be one\n+# thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.\n+# This is the same as a LC_THREAD, except that a stack is automatically\n+# created (based on the shell's limit for the stack size). Command arguments\n+# and environment variables are copied onto that stack.\nclass thread_command(load_command):\ndef __init__(self, bigend=False):\n# LC_THREAD or LC_UNIXTHREAD\nload_command.__init__(self, bigend=bigend)\n+ self.flavor = v_uint32(bigend=bigend) # flavor of thread state\n+ self.count = v_uint32(bigend=bigend) # count of longs in thread state\nclass routines_command(load_command):\n@@ -467,6 +487,10 @@ class version_min_command(load_command):\nself.sdk = v_uint32(bigend=bigend)\n+# The entry_point_command is a replacement for thread_command.\n+# It is used for main executables to specify the location (file offset)\n+# of main(). If -stack_size was used at link time, the stacksize\n+# field will contain the stack size need for the main thread.\nclass entry_point_command(load_command):\ndef __init__(self, bigend=False):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
make LC_UNIXTHREAD/thread_command work with .flavor (and getEntryPoints()) updates to work with bigendian (and wonky git-shit)
718,770
28.12.2021 09:05:50
18,000
c17e328a69baa17b86226d33f6714eebd0d96df2
bugfix: vsParse doesn't have bigend defined
[ { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/loader.py", "new_path": "vstruct/defs/macho/loader.py", "diff": "@@ -74,7 +74,7 @@ class segment_command(load_command):\n# segment, which follows directly after the segment info structure\nstep = len(self)\nfor i in range(self.nsects):\n- sect = section(bigend=bigend)\n+ sect = section(bigend=self.getEndian())\nstep += sect.vsParse(bytes[offset+step:])\nself.sections.vsAddElement(sect)\n@@ -106,7 +106,7 @@ class segment_command_64(load_command):\n# segment, which follows directly after the segment info structure\nstep = len(self)\nfor i in range(self.nsects):\n- sect = section_64(bigend=bigend)\n+ sect = section_64(self.getEndian())\nstep += sect.vsParse(bytes[offset+step:])\nself.sections.vsAddElement(sect)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
bugfix: vsParse doesn't have bigend defined
718,770
05.01.2022 22:27:22
18,000
cbd95278008751b9223c8911e08d2b5251514a3f
minor changes to PE parser to not overwrite existing VaSets
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -93,6 +93,7 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nvw.setMeta('Architecture', arch)\nvw.setMeta('Format', 'pe')\nvw.parsedbin = pe\n+ ### TODO: this doesn't work from Memory (read() needs to know how big the file is)\nbyts = pe.getFileBytes()\nvw.setMeta('FileBytes', v_parsers.compressBytes(byts))\n@@ -164,8 +165,12 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nvw.setFileMeta(fname, 'Version', vsver)\n# Setup some va sets used by windows analysis modules\n+ # these will already exist for Multi-file workspaces\n+ if not 'Library Loads' in vw.getVaSetNames():\nvw.addVaSet(\"Library Loads\", ((\"Address\", VASET_ADDRESS), (\"Library\", VASET_STRING)))\n+ if not 'pe:ordinals' in vw.getVaSetNames():\nvw.addVaSet('pe:ordinals', (('Address', VASET_ADDRESS), ('Ordinal', VASET_INTEGER)))\n+ if not 'DelayImports' in vw.getVaSetNames():\nvw.addVaSet('DelayImports', (('Address', VASET_ADDRESS), ('DelayImport', VASET_STRING)))\n# SizeOfHeaders spoofable...\n" } ]
Python
Apache License 2.0
vivisect/vivisect
minor changes to PE parser to not overwrite existing VaSets
718,765
12.01.2022 14:49:10
18,000
e4bc9b93cd00853aa9d6d981b185e086c5fc5e0f
more mach-o definitions and support Add more definitions for FAT64 and CPU arch names/constants.
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/macho.py", "new_path": "vivisect/parsers/macho.py", "diff": "import envi.common as e_common\nimport vivisect.parsers as viv_parsers\n+\nimport vstruct.defs.macho as vs_macho\n+import vstruct.defs.macho.fat as vsm_fat\n+import vstruct.defs.macho.const as vsm_const\ndef parseFile(vw, filename, baseaddr=None):\nwith open(filename, 'rb') as f:\n@@ -49,10 +52,15 @@ def _loadMacho(vw, filebytes, filename=None, baseaddr=None):\narchlist = []\noffset = 0\n- fat = vs_macho.fat_header()\n+ fat = vsm_fat.fat_header()\noffset = fat.vsParse(filebytes, offset=offset)\n+ if fat.magic in vsm_const.FAT_64:\n+ archcon = vsm_fat.fat_arch_64\n+ else:\n+ archcon = vsm_fat.fat_arch\n+\nfor i in range(fat.nfat_arch):\n- ar = vs_macho.fat_arch()\n+ ar = archcon()\noffset = ar.vsParse(filebytes, offset=offset)\narchname = vs_macho.mach_cpu_names.get(ar.cputype)\nif archname == fatarch:\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/const.py", "new_path": "vstruct/defs/macho/const.py", "diff": "@@ -130,21 +130,27 @@ S_ATTR_LOC_RELOC = 0x00000100 # section has local relocation entries\nINDIRECT_SYMBOL_LOCAL = 0x80000000 # section has local relocation entries\nINDIRECT_SYMBOL_ABS = 0x40000000 # section has local relocation entries\n+CPU_ARCH_MASK = 0xff000000\n+CPU_ARCH_ABI64 = 0x01000000\n+CPU_ARCH_ABI64_32 = 0x02000000\n+\nCPU_TYPE_ANY = -1\nCPU_TYPE_VAX = 1\nCPU_TYPE_MC680 = 6\nCPU_TYPE_X86 = 7\n-CPU_TYPE_X86_64 = 0x01000007\n+CPU_TYPE_X86_64 = CPU_TYPE_X86 | CPU_ARCH_ABI64\nCPU_TYPE_MIPS = 8\nCPU_TYPE_MC98000 = 10\nCPU_TYPE_HPPA = 11\nCPU_TYPE_ARM = 12\n+CPU_TYPE_ARM64 = CPU_TYPE_ARM | CPU_ARCH_ABI64\n+CPU_TYPE_ARM64_32 = CPU_TYPE_ARM | CPU_ARCH_ABI64_32\nCPU_TYPE_MC88000 = 13\nCPU_TYPE_SPARC = 14\nCPU_TYPE_I860 = 15\nCPU_TYPE_ALPHA = 16\nCPU_TYPE_POWERPC = 18\n-#CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)\n+CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64\nmach_cpu_names = {\nCPU_TYPE_VAX : 'vax',\n@@ -155,11 +161,14 @@ mach_cpu_names = {\nCPU_TYPE_MC98000 : 'mc98000',\nCPU_TYPE_HPPA : 'hppa',\nCPU_TYPE_ARM : 'arm',\n+ CPU_TYPE_ARM64 : 'arm64',\n+ CPU_TYPE_ARM64_32 : 'arm64_32',\nCPU_TYPE_MC88000 : 'mc88000',\nCPU_TYPE_SPARC : 'sparc',\nCPU_TYPE_I860 : 'i860',\nCPU_TYPE_ALPHA : 'alpha',\nCPU_TYPE_POWERPC : 'powerpc',\n+ CPU_TYPE_POWERPC64 : 'powerpc64',\n}\n# Symbol types\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/fat.py", "new_path": "vstruct/defs/macho/fat.py", "diff": "@@ -18,3 +18,12 @@ class fat_arch(vstruct.VStruct):\nself.size = v_uint32(bigend=True) # size of this object file */\nself.align = v_uint32(bigend=True) # alignment as a power of 2 */\n+class fat_arch_64(vstruct.VStruct):\n+ def __init__(self):\n+ vstruct.VStruct.__init__(self)\n+ self.cputype = v_uint32(bigend=True) # cpu specifier (int) */\n+ self.cpusubtype = v_uint32(bigend=True) # machine specifier (int) */\n+ self.offset = v_uint64(bigend=True) # file offset to this object file */\n+ self.size = v_uint64(bigend=True) # size of this object file */\n+ self.align = v_uint32(bigend=True) # alignment as a power of 2 */\n+ self.reserved = v_uint32(bigend=True)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
more mach-o definitions and support (#495) Add more definitions for FAT64 and CPU arch names/constants.
718,765
13.01.2022 10:52:06
18,000
4869e826c27f7f3cec5dd64169766f5edb6246bd
fix pe32 vs pe32+ check Use the OptionalHeader magic instead of the FileHeader.Machine value for determining PE32 vs PE32+
[ { "change_type": "MODIFY", "old_path": "PE/__init__.py", "new_path": "PE/__init__.py", "diff": "@@ -10,6 +10,9 @@ import vivisect.exc as v_exc\nfrom . import ordlookup\n+PE32_MAGIC = 0x10b\n+PE32PLUS_MAGIC = 0x20b\n+\nIMAGE_FILE_RELOCS_STRIPPED = 0x0001\nIMAGE_FILE_EXECUTABLE_IMAGE = 0x0002\nIMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004\n@@ -406,14 +409,16 @@ class PE(object):\ndosbytes = self.readAtOffset(0, len(self.IMAGE_DOS_HEADER))\nself.IMAGE_DOS_HEADER.vsParse(dosbytes)\n- nt = self.readStructAtOffset(self.IMAGE_DOS_HEADER.e_lfanew, \"pe.IMAGE_NT_HEADERS\")\n-\n# Parse in a default 32 bit, and then check for 64...\n- if nt.FileHeader.Machine in [ IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_IA64 ]:\n+ nt = self.readStructAtOffset(self.IMAGE_DOS_HEADER.e_lfanew, \"pe.IMAGE_NT_HEADERS\")\n+ magic = struct.unpack(\"<H\", nt.OptionalHeader.Magic)[0]\n+ if magic == PE32PLUS_MAGIC:\nnt = self.readStructAtOffset(self.IMAGE_DOS_HEADER.e_lfanew, \"pe.IMAGE_NT_HEADERS64\")\nself.pe32p = True\nself.psize = 8\nself.high_bit_mask = 0x8000000000000000\n+ elif magic != PE32_MAGIC:\n+ logger.warning('nt.OptionalHeader magic got invalid value of %x', magic)\nself.IMAGE_NT_HEADERS = nt\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testpe.py", "new_path": "vivisect/tests/testpe.py", "diff": "@@ -7,12 +7,14 @@ import envi.memory as e_memory\nimport vivisect\nimport vivisect.const as viv_con\nimport vivisect.parsers.pe\n+\nimport vivisect.tests.helpers as helpers\n+import vivisect.tests.utils as v_t_utils\nlogger = logging.getLogger(__name__)\n-class PETests(unittest.TestCase):\n+class PETests(v_t_utils.VivTest):\n@classmethod\ndef setUpClass(cls):\n@@ -508,7 +510,7 @@ class PETests(unittest.TestCase):\n(4371200, 4, 9, 'gdi32.StartPage')])\nfailed = False\n- # self.assertEqual(imps, vw.getImports())\n+\nfor iloc in vw.getImports():\nif iloc not in imps:\nlogger.critical(f'{iloc} was not found in the predefined imports. A new one?')\n@@ -518,10 +520,36 @@ class PETests(unittest.TestCase):\nfor iloc in imps:\nif iloc not in oimp:\nlogger.critical(f'The imports are missing {iloc}.')\n+ failed = True\nif failed:\nself.fail('Please see test logs for import test failures')\n+ def test_pe_pe32p(self):\n+ '''\n+ test that we use the right check for constructing the optional header\n+ and that the data directories are right\n+ '''\n+ file_path = helpers.getTestPath('windows', 'amd64', 'a7712b7c45ae081a1576a387308077f808c666449d1ea9ba680ec410569d476f.file')\n+ pe = PE.peFromFileName(file_path)\n+ self.assertTrue(pe.pe32p)\n+ self.eq(pe.psize, 8)\n+\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfStackReserve, 0x100000)\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfStackCommit, 0x1000)\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfHeapReserve, 0x100000)\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfHeapCommit, 0x1000)\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.LoaderFlags, 0)\n+ self.eq(pe.IMAGE_NT_HEADERS.OptionalHeader.NumberOfRvaAndSizes, 0x10)\n+\n+ ddir = pe.getDataDirectory(PE.IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR)\n+ self.eq(ddir.VirtualAddress, 0x2008)\n+ self.eq(ddir.Size, 0x48)\n+\n+ ddir = pe.getDataDirectory(PE.IMAGE_DIRECTORY_ENTRY_RESOURCE)\n+ self.eq(ddir.VirtualAddress, 0x9a2000)\n+ self.eq(ddir.Size, 0x3c78)\n+\ndef test_hiaddr_imports(self):\n# Test if imports located at a high relative address are discovered.\nfile_path = helpers.getTestPath('windows', 'i386', 'section_has_hi_virtualaddr.exe')\n" } ]
Python
Apache License 2.0
vivisect/vivisect
fix pe32 vs pe32+ check (#494) Use the OptionalHeader magic instead of the FileHeader.Machine value for determining PE32 vs PE32+
718,765
13.01.2022 11:22:37
18,000
37b0b655d8dedfcf322e86b0f144b096e48d547e
V1.0.7 Release Prep v1.0.7 release prep
[ { "change_type": "MODIFY", "old_path": ".bumpversion.cfg", "new_path": ".bumpversion.cfg", "diff": "[bumpversion]\n-current_version = 1.0.6\n+current_version = 1.0.7\n[bumpversion:file:setup.py]\nsearch = VERSION = '{current_version}'\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "Vivisect Changelog\n******************\n+V1.0.7 - 2022-01-13\n+===================\n+\n+Features\n+--------\n+- More Mach-O structure definitions and parsing support.\n+ (`#495 <https://github.com/vivisect/vivisect/pull/495>`_)\n+\n+Fixes\n+-----\n+- Tweak how i386 analysis detections calling conventions.\n+ (`#493 <https://github.com/vivisect/vivisect/pull/493>`_)\n+- Use OptionalHeader.Magic for determining PE32/PE32+.\n+ (`#494 <https://github.com/vivisect/vivisect/pull/494>`_)\n+\nV1.0.6 - 2022-01-03\n===================\n" }, { "change_type": "MODIFY", "old_path": "setup.py", "new_path": "setup.py", "diff": "from setuptools import find_packages, setup\nfrom os import path\n-VERSION = '1.0.6'\n+VERSION = '1.0.7'\ndirn = path.abspath(path.dirname(__file__))\nwith open(path.join(dirn, 'README.md'), 'r') as fd:\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -2299,6 +2299,6 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these yourself\n-version = (1, 0, 6)\n+version = (1, 0, 7)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -3168,6 +3168,6 @@ def getVivPath(*pathents):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these directly\n-version = (1, 0, 6)\n+version = (1, 0, 7)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
V1.0.7 Release Prep (#496) v1.0.7 release prep
718,770
05.01.2022 22:37:33
18,000
bd0a1266fc3f0e7f2c42e27a7650caacd1548a7a
improving the MemObjFile shim to make a memobj act like a file object.
[ { "change_type": "MODIFY", "old_path": "vstruct/__init__.py", "new_path": "vstruct/__init__.py", "diff": "@@ -20,7 +20,16 @@ class MemObjFile:\ndef seek(self, offset):\nself.offset = self.baseaddr + offset\n- def read(self, size):\n+ def flush(self):\n+ pass\n+\n+ def tell(self):\n+ return self.offset - self.baseaddr\n+\n+ def read(self, size=None):\n+ if size is None:\n+ # end of map for now, but perhaps this should be end of contiguous maps\n+ _, size, _, _ = self.memobj.getMemoryMap(self.offset)\nret = self.memobj.readMemory(self.offset, size)\nself.offset += size\nreturn ret\n" } ]
Python
Apache License 2.0
vivisect/vivisect
improving the MemObjFile shim to make a memobj act like a file object.
718,770
19.01.2022 23:26:59
18,000
9fb4b35a102b1ab42dc2ec52acc380c3bb6551fb
we recreate the workspace through the proxy, but never snap in the appropriate analysis modules. this likely dates back to the days when analysis modules were added to the eventlist.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -630,6 +630,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nself.server.vprint('%s connecting...' % uname)\nwsevents = self.server.exportWorkspace()\nself.importWorkspace(wsevents)\n+ self._snapInAnalysisModules()\nself.server.vprint('%s connection complete!' % uname)\nthr = threading.Thread(target=self._clientThread)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
we recreate the workspace through the proxy, but never snap in the appropriate analysis modules. this likely dates back to the days when analysis modules were added to the eventlist. (#498)
718,770
10.02.2022 21:08:36
18,000
73e2fb65f8a4e5531189d1f23974ba6caf0815cf
fix a bug in elfplt for an odd binary.
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -172,6 +172,9 @@ def getPLTs(vw):\nif fdyns is not None:\nFGOT = fdyns.get('DT_JMPREL')\nFGOTSZ = fdyns.get('DT_PLTRELSZ')\n+ if None in (FGOT, FGOTSZ):\n+ continue\n+\nif vw.getFileMeta(fname, 'addbase'):\nimgbase = vw.getFileMeta(fname, 'imagebase')\nlogger.debug('Adding Imagebase: 0x%x', imgbase)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
fix a bug in elfplt for an odd binary. (#503)
718,770
04.03.2022 23:23:17
18,000
931708510e5d725768a87ef89805e1be6c07075a
save bugfix
[ { "change_type": "MODIFY", "old_path": "vivisect/qt/main.py", "new_path": "vivisect/qt/main.py", "diff": "@@ -487,7 +487,7 @@ class VQVivMainWindow(viv_base.VivEventDist, vq_app.VQMainCmdWindow):\n# forces a local save\nfname = filename\nif not fname:\n- fname = vw.getMeta(\"StorageName\")\n+ fname = self.vw.getMeta(\"StorageName\")\nself.vw.vprint('Saving workspace... (%r)' % fname)\ntry:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
save bugfix (#507)
718,770
16.03.2022 16:29:38
14,400
05baf6b375e0d031a25b04a8827aa8304ab1bd76
make the loader use 1M alignment by default (and make it settable, instead of hard-coding it to ENVI's page-size)
[ { "change_type": "MODIFY", "old_path": "envi/const.py", "new_path": "envi/const.py", "diff": "@@ -41,4 +41,3 @@ for idx in range(8):\nPAGE_SIZE = 1 << 12\nPAGE_NMASK = PAGE_SIZE - 1\nPAGE_MASK = ~PAGE_NMASK\n-\n" }, { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -440,7 +440,7 @@ class MemoryObject(IMemory):\nself.addMemoryMap(baseva, perms, name, fill*size, align)\nreturn baseva\n- def findFreeMemoryBlock(self, size, suggestaddr=0x1000, MIN_MEM_ADDR = 0x1000):\n+ def findFreeMemoryBlock(self, size, suggestaddr=0x1000, MIN_MEM_ADDR = 0x1000, mapalign=0x10000):\n'''\nFind a block of memory in the address-space of the correct size which\ndoesn't overlap any existing maps. Attempts to offer the map starting\n@@ -456,6 +456,9 @@ class MemoryObject(IMemory):\ntmpva = suggestaddr\nmaxaddr = (1 << (8 * self.imem_psize)) - 1\n+ MAP_ALIGN_NMASK = mapalign - 1\n+ MAP_ALIGN_MASK = ~MAP_ALIGN_NMASK\n+\nwhile baseva is None:\n# if we roll into illegal memory, start over at page 2. skip 0.\nif tmpva > maxaddr:\n@@ -478,8 +481,8 @@ class MemoryObject(IMemory):\n# we ran into a memory map. adjust.\ngood = False\ntmpva = mmendva\n- tmpva += PAGE_NMASK\n- tmpva &= PAGE_MASK\n+ tmpva += MAP_ALIGN_NMASK\n+ tmpva &= MAP_ALIGN_MASK\nbreak\nif good:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
make the loader use 1M alignment by default (and make it settable, instead of hard-coding it to ENVI's page-size)
718,765
30.03.2022 15:05:47
14,400
a3333bd02e9383a3868bf614dc09782b33dc7de2
tweak how we handle section names
[ { "change_type": "MODIFY", "old_path": "vivisect/tests/testpe.py", "new_path": "vivisect/tests/testpe.py", "diff": "@@ -595,3 +595,21 @@ class PETests(v_t_utils.VivTest):\nself.assertEqual(loc[1], 40)\nself.assertEqual(loc[2], viv_con.LOC_STRUCT)\nself.assertEqual(loc[3], 'pe.IMAGE_SECTION_HEADER')\n+\n+ def test_bad_pe_sectname(self):\n+ vw = helpers.getTestWorkspace('windows', 'i386', 'HelloSection-err.exe')\n+ segs = vw.getSegments()\n+ pesections = [\n+ # about as blunt and direct of a name as we can get\n+ \"[invalid name] b'\\\\xfftext\\\\x00\\\\x00\\\\x00'\",\n+ '.rdata\\x00\\x00',\n+ '.data\\x00\\x00\\x00',\n+ '.rsrc\\x00\\x00\\x00',\n+ '.reloc\\x00\\x00',\n+ ]\n+ sections = [x.Name for x in vw.parsedbin.getSections()]\n+ valids = [x.isNameValid() for x in vw.parsedbin.getSections()]\n+ self.eq(valids, [False, True, True, True, True])\n+ self.len(sections, 5)\n+ for name in pesections:\n+ self.isin(name, sections)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/utils.py", "new_path": "vivisect/tests/utils.py", "diff": "@@ -33,6 +33,12 @@ class VivTest(unittest.TestCase):\n'''\nself.assertIsNotNone(x)\n+ def isin(self, x, y):\n+ '''\n+ Assert that x is a member of the container y\n+ '''\n+ self.assertIn(x, y)\n+\n@contextlib.contextmanager\ndef snap(self, vw):\n'''\n" }, { "change_type": "MODIFY", "old_path": "vstruct/defs/pe.py", "new_path": "vstruct/defs/pe.py", "diff": "+import binascii\nimport vstruct\nfrom vstruct.primitives import *\n@@ -264,11 +265,43 @@ class VS_FIXEDFILEINFO(vstruct.VStruct):\nself.FileDateMS = v_uint32()\nself.FileDateLS = v_uint32()\n+class v_name(v_bytes):\n+ '''\n+ Specifically for things that *should* be utf-8 strings, but aren't really enforced as such\n+ '''\n+ def __repr__(self):\n+ try:\n+ name = self._vs_value.decode('utf-8')\n+ return name\n+ except UnicodeDecodeError:\n+ return binascii.hexlify(self._vs_value).decode('utf-8')\n+\n+ __str__ = __repr__\n+\n+ def vsGetValue(self):\n+ '''\n+ Get the type specific value for this field.\n+ (Used by the structure dereference method to return\n+ a python native for the field by name)\n+ '''\n+ try:\n+ name = self._vs_value.decode('utf-8')\n+ return name\n+ except UnicodeDecodeError:\n+ return \"[invalid name] %r\" % self._vs_value\n+\n+ def isValid(self):\n+ try:\n+ self._vs_value.decode('utf-8')\n+ return True\n+ except UnicodeDecodeError:\n+ return False\n+\nclass IMAGE_SECTION_HEADER(vstruct.VStruct):\ndef __init__(self):\nvstruct.VStruct.__init__(self)\n- self.Name = v_str(8)\n+ self.Name = v_name(8)\nself.VirtualSize = v_uint32()\nself.VirtualAddress = v_uint32()\nself.SizeOfRawData = v_uint32()\n@@ -279,6 +312,10 @@ class IMAGE_SECTION_HEADER(vstruct.VStruct):\nself.NumberOfLineNumbers = v_uint16()\nself.Characteristics = v_uint32()\n+ def isNameValid(self):\n+ # we've gotta bypass\n+ name = self.vsGetField('Name')\n+ return name.isValid()\nclass IMAGE_RUNTIME_FUNCTION_ENTRY(vstruct.VStruct):\n\"\"\"\n" } ]
Python
Apache License 2.0
vivisect/vivisect
tweak how we handle section names (#514)
718,770
14.04.2022 13:51:09
14,400
9b651db3606956e104a32cfade96842670301a70
improved output from the do_names command.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2323,6 +2323,23 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nreturn foff\nreturn (foff - offset) + 2\n+ def getFileAndOffset(self, va):\n+ '''\n+ Helper function which identifies the file a given VA is a part of, then\n+ splits the file base and offset\n+\n+ Returns: (filename, filebase, offset)\n+\n+ If no file is identified, None is returned\n+ '''\n+ fname = self.getFileByVa(va)\n+ if not fname:\n+ return None\n+\n+ fbase = self.getFileMeta(fname, 'imagebase')\n+ off = va - fbase\n+ return (fname, fbase, off)\n+\ndef addLocation(self, va, size, ltype, tinfo=None):\n\"\"\"\nAdd a location tuple.\n" }, { "change_type": "MODIFY", "old_path": "vivisect/cli.py", "new_path": "vivisect/cli.py", "diff": "@@ -184,7 +184,12 @@ class VivCli(e_cli.EnviCli, vivisect.VivWorkspace):\nregex = re.compile(line, re.I)\nfor va, name in self.getNames():\nif regex.search(name):\n- self.vprint('0x%.8x: %s' % (va, name))\n+ ftup = self.getFileAndOffset(va)\n+ if ftup:\n+ fname, fbase, off = ftup\n+ self.vprint('0x%.8x: %s (%r + 0x%x)' % (va, name, fname, off))\n+ else:\n+ self.vprint(\"WARNING: 0x%x: %r doesn't exist in a file!\" % (va, name))\ndef do_save(self, line):\n\"\"\"\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -310,6 +310,9 @@ class VivisectTest(v_t_utils.VivTest):\nself.chgrp_vw.do_names('plt_.*64')\noutput = self.chgrp_vw.canvas.strval\nself.assertIn(\"0x08048e60: chgrp.plt_fseeko64\", output)\n+ self.chgrp_vw.do_names('__entry')\n+ output = self.chgrp_vw.canvas.strval\n+ self.assertIn(\"0x080491e0: chgrp.__entry ('chgrp' + 0x11e0)\", output)\nself.chgrp_vw.canvas.clearCanvas()\ndef test_cli_pathcount(self):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
improved output from the do_names command. (#516)
718,770
27.04.2022 07:31:06
14,400
162fffdd911ff5475f7f80d1b111db6ea12a72eb
somehow got this one wrong.
[ { "change_type": "MODIFY", "old_path": "vivisect/vivbin.py", "new_path": "vivisect/vivbin.py", "diff": "@@ -7,8 +7,8 @@ import argparse\nimport cProfile\nimport importlib.util\n+import envi.exc as e_exc\nimport envi.common as e_common\n-import envi.config as e_config\nimport envi.threads as e_threads\nimport vivisect.cli as viv_cli\n@@ -64,7 +64,7 @@ def main():\ntry:\nvw.config.parseConfigOption(option)\n- except e_config.ConfigNoAssignment as e:\n+ except e_exc.ConfigNoAssignment as e:\nlogger.critical(vw.config.reprConfigPaths() + \"\\n\")\nlogger.critical(e)\nlogger.critical(\"syntax: \\t-O <secname>.<optname>=<optval> (optval must be json syntax)\")\n" } ]
Python
Apache License 2.0
vivisect/vivisect
somehow got this one wrong. (#518)
718,765
28.04.2022 12:35:31
14,400
f42c3ca5bfc15404f0894659ffd1ab1df6b1018c
libc_start_main logging fix Fix a logging message in libc_start_main
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/libc_start_main.py", "new_path": "vivisect/analysis/elf/libc_start_main.py", "diff": "@@ -87,7 +87,7 @@ class AnalysisMonitor(viv_imp_monitor.AnalysisMonitor):\nif op.iflags & envi.IF_CALL:\n# it's a call, get the target\nbranches = [br for br in op.getBranches(emu) if not (br[1] & envi.BR_FALL)]\n- logger.debug('libc_start_main: 0x%x\\ttgts: %r', self.startmain, branches)\n+ logger.debug('libc_start_main: %r\\t\\ttgts: %r', [hex(x) for x in self.startmain], branches)\n# check if it matches what we believe to be __libc_start_main\nfor branch in branches:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
libc_start_main logging fix (#519) Fix a logging message in libc_start_main
718,765
28.04.2022 19:12:43
14,400
7ef22b78aace366599fc6c143a93ca193d533ce0
V1.0.8 Release Prep V1.0.7 Release Prep
[ { "change_type": "MODIFY", "old_path": ".bumpversion.cfg", "new_path": ".bumpversion.cfg", "diff": "[bumpversion]\n-current_version = 1.0.7\n+current_version = 1.0.8\n[bumpversion:file:setup.py]\nsearch = VERSION = '{current_version}'\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "Vivisect Changelog\n******************\n+V1.0.8 - 2022-04-28\n+===================\n+\n+Features\n+========\n+- Improved Save-As capabilities when connected to a remote server and better struct making from the UI.\n+ (`#501 <https://github.com/vivisect/vivisect/pull/501>`_)\n+- Improve output for the UI's ``names`` command.\n+ (`#516 <https://github.com/vivisect/vivisect/pull/516>`_)\n+\n+Fixes\n+=====\n+- Fix issue in the proxy case where we forgot to snap in the analysis modules.\n+ (`#498 <https://github.com/vivisect/vivisect/pull/498>`_)\n+- Fix string naming.\n+ (`#502 <https://github.com/vivisect/vivisect/pull/502>`_)\n+- Fix a bug in ELFPLT analysis where certain dynamic tables were missing.\n+ (`#503 <https://github.com/vivisect/vivisect/pull/503>`_)\n+- Fix an issue where ELF parsing of STT_FUNCs was based on too many bits.\n+ (`#505 <https://github.com/vivisect/vivisect/pull/505>`_)\n+- Fix an missing name issue in Save-As.\n+ (`#507 <https://github.com/vivisect/vivisect/pull/507>`_)\n+- Improve thread safety for client workspaces.\n+ (`#508 <https://github.com/vivisect/vivisect/pull/508>`_)\n+- Fix the i386 Emulator's handling of rep(n)z.\n+ (`#513 <https://github.com/vivisect/vivisect/pull/513>`_)\n+- Fix issue when dealing with invalid PE section names.\n+ (`#514 <https://github.com/vivisect/vivisect/pull/514>`_)\n+- Fix an incorrect import name in vivbin.\n+ (`#518 <https://github.com/vivisect/vivisect/pull/518>`_)\n+- Fix a debug logging message in the ``libc_start_main`` analysis pass that would cause that analysis pass to exception out.\n+ (`#519 <https://github.com/vivisect/vivisect/pull/519>`_)\n+\nV1.0.7 - 2022-01-13\n===================\n@@ -338,4 +371,4 @@ Fixes\nv0.1.0rc1 - 2020-07-30\n======================\n-- Initial Pypi Release\n+- Initial PyPI Release\n" }, { "change_type": "MODIFY", "old_path": "setup.py", "new_path": "setup.py", "diff": "from setuptools import find_packages, setup\nfrom os import path\n-VERSION = '1.0.7'\n+VERSION = '1.0.8'\ndirn = path.abspath(path.dirname(__file__))\nwith open(path.join(dirn, 'README.md'), 'r') as fd:\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -2299,6 +2299,6 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these yourself\n-version = (1, 0, 7)\n+version = (1, 0, 8)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -3193,6 +3193,6 @@ def getVivPath(*pathents):\n##############################################################################\n# The following are touched during the release process by bump2version.\n# You should have no reason to modify these directly\n-version = (1, 0, 7)\n+version = (1, 0, 8)\nverstring = '.'.join([str(x) for x in version])\ncommit = ''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
V1.0.8 Release Prep (#520) V1.0.7 Release Prep
718,770
09.05.2022 14:27:55
14,400
aa7c3e9290846bb333b1ff1044ec112657a00a08
update impapi to cover msvcr100.dll
[ { "change_type": "MODIFY", "old_path": "vivisect/impapi/windows/i386.py", "new_path": "vivisect/impapi/windows/i386.py", "diff": "@@ -7325,3 +7325,6 @@ api = {\n'mfc42.?afxbeginthread@@ygpavcwinthread@@p6aipax@z0hikpau_security_attributes@@@z':( 'int', None, 'cdecl', 'mfc42.?AfxBeginThread@@YGPAVCWinThread@@P6AIPAX@Z0HIKPAU_SECURITY_ATTRIBUTES@@@Z', (('void *','funcptr'), ('void *','ptr'), ('int',None), ('int',None), ('int',None), ('void *','ptr')) ),\n} # END\n+\n+msvcr100 = {'msvcr100.' + name.split('.', 1)[1] : data for name, data in api.items() if name.startswith('msvcrt.')}\n+\n" } ]
Python
Apache License 2.0
vivisect/vivisect
update impapi to cover msvcr100.dll (#522)
718,770
11.05.2022 13:33:35
14,400
94f4e65aa842f23d89acfadd2a15c59f60c6f029
one last thing. funcrgraph bugfix (for backwards compat)
[ { "change_type": "MODIFY", "old_path": "vivisect/remote/server.py", "new_path": "vivisect/remote/server.py", "diff": "@@ -205,7 +205,7 @@ class VivServer:\nlock, fpath, pevents, users, leaders, leaderloc = wsinfo\noldclient = False\n- elif chan in self._req_wsinfo:\n+ elif chan in self.wsdict:\n# DEPRECATED: this is for backwards compat. use only the chandict code one year from today, 5/10/2022.\nwsname = chan\nwsinfo = self._req_wsinfo(wsname)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
one last thing. (#523) funcrgraph bugfix (for backwards compat)
718,770
16.05.2022 22:36:31
14,400
c17653195d5e03ec4257a7a10629e08f529426ef
Easy Bugfix: update SaveToServer dialog
[ { "change_type": "MODIFY", "old_path": "vivisect/qt/remote.py", "new_path": "vivisect/qt/remote.py", "diff": "@@ -98,7 +98,20 @@ class VivSaveServerDialog(VivServerDialog):\ndef __init__(self, vw, parent=None):\nVivServerDialog.__init__(self, vw, parent=parent)\n+\nself.wsname = QLineEdit(vw.getMeta('StorageName', ''), parent=self)\n+ wslabel = QLabel(\"Storage Path:\")\n+\n+ bot_box = QWidget(parent=self)\n+ hbox = QHBoxLayout(bot_box)\n+ hbox.setContentsMargins(2, 2, 2, 2)\n+ hbox.setSpacing(4)\n+ hbox.addWidget(wslabel)\n+ hbox.addWidget(self.wsname)\n+\n+ layout = self.layout()\n+ layout.insertRow(1, bot_box)\n+\nself.setWindowTitle('Save to Workspace Server...')\ndef getNameAndServer(self):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Easy Bugfix: update SaveToServer dialog (#527)
718,770
17.05.2022 15:00:05
14,400
ec9032d396e13926001f51fdb84e5f50bb504f0e
log loadPeIntoWorkspace and args
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -83,6 +83,10 @@ relmap = {\ndef loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\n+ if baseaddr:\n+ logger.info(\"loadPeIntoWorkspace(%r, %r, baseaddr=0x%x\", pe, filename, baseaddr)\n+ else:\n+ logger.info(\"loadPeIntoWorkspace(%r, %r, baseaddr=%r\", pe, filename, baseaddr)\nmach = pe.IMAGE_NT_HEADERS.FileHeader.Machine\n" } ]
Python
Apache License 2.0
vivisect/vivisect
log loadPeIntoWorkspace and args
718,776
25.05.2022 07:18:00
-7,200
b8565c5019a28676c0e0d4389712ec9088efcbfa
Update windows.py Add `Ex` to imphooks
[ { "change_type": "MODIFY", "old_path": "vivisect/impemu/platarch/windows.py", "new_path": "vivisect/impemu/platarch/windows.py", "diff": "@@ -80,14 +80,14 @@ class WindowsMixin(v_i_emulator.WorkspaceEmulator):\ndef kernel32_LoadLibraryExW(self, emu, callconv, api, argv):\nreturn self.kernel32_LoadLibraryW(emu, callconv, api, argv)\n- @imphook('kernel32.GetModuleHandleA')\n+ @imphook('kernel32.GetModuleHandleExA')\ndef kernel32_GetModuleHandleExA(self, emu, callconv, api, argv):\ndwFlags,lpLibName,phModule = argv\nlibname = self.readLibraryPath(lpLibName, unicode=False)\nretval = emu.setVivTaint('dynlib',libname)\ncallconv.execCallReturn(emu, retval, len(argv))\n- @imphook('kernel32.GetModuleHandleW')\n+ @imphook('kernel32.GetModuleHandleExW')\ndef kernel32_GetModuleHandleExA(self, emu, callconv, api, argv):\ndwFlags,lpLibName,phModule = argv\nlibname = self.readLibraryPath(lpLibName, unicode=True)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Update windows.py (#530) Add `Ex` to imphooks
718,770
17.06.2022 18:08:22
14,400
5048cb7675fcb2f83e05993e052dd77179253ec3
move the "file not based at 0" decision to the individual parsers. blob certainly cares.
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2794,8 +2794,6 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\n# get baseaddr and size, then make sure we have a good baseaddr\nbaseaddr, size = mod.getMemBaseAndSize(self, filename=filename, baseaddr=baseaddr)\nlogger.debug('initial baseva: 0x%x size: 0x%x', baseaddr, size)\n- if baseaddr == 0:\n- baseaddr = 0x300000\nbaseaddr = self.findFreeMemoryBlock(size, baseaddr)\nlogger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/defconfig.py", "new_path": "vivisect/defconfig.py", "diff": "@@ -9,11 +9,13 @@ defconfig = {\n'parsers':{\n'pe':{\n+ 'baseaddr': 0x200000,\n'loadresources':False,\n'carvepes':True,\n'nx':False,\n},\n'elf':{\n+ 'baseaddr': 0x200000,\n},\n'blob':{\n'arch':'',\n@@ -60,11 +62,13 @@ docconfig = {\n'parsers':{\n'pe':{\n+ 'baseaddr': 'Address used to relocate PE files if base-address is 0 and PE is relocatable',\n'loadresources':'Should we load resource segments?',\n'carvepes':'Should we carve pes?',\n'nx':'Should we truly treat sections that dont execute as non executable?'\n},\n'elf':{\n+ 'baseaddr': 'Address used to relocate ELF files if base-address is 0 and ELF is relocatable',\n},\n'blob':{\n'arch':'What architecture is the blob?',\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -64,6 +64,10 @@ def getMemBaseAndSize(vw, filename, baseaddr=None):\ntopmem = endva\nsize = topmem - baseaddr\n+\n+ if baseaddr == 0:\n+ baseaddr = vw.config.viv.parsers.elf.baseoffset\n+\nif savebase:\n# if we provided a baseaddr, override what the file wants\nbaseaddr = savebase\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -610,6 +610,10 @@ def getMemBaseAndSize(vw, filename, baseaddr=None):\ntopmem = endva\nsize = topmem - baseaddr\n+\n+ if baseaddr == 0:\n+ baseaddr = vw.config.viv.parsers.pe.baseoffset\n+\nif savebase:\n# if we provided a baseaddr, override what the file wants\nbaseaddr = savebase\n" } ]
Python
Apache License 2.0
vivisect/vivisect
move the "file not based at 0" decision to the individual parsers. blob certainly cares.
718,765
22.07.2022 00:11:07
14,400
1d079e01b10ab6c9756ef27f13d8109bee71d0d2
Docbuild Fixes
[ { "change_type": "MODIFY", "old_path": ".readthedocs.yaml", "new_path": ".readthedocs.yaml", "diff": "+version: 2\n+\npython:\nversion: 3.8\n- pip_install: true\n- extra_requirements:\n- - docs\n+ install:\n+ - requirements: requirements_doc.txt\n" }, { "change_type": "MODIFY", "old_path": "CHANGELOG.rst", "new_path": "CHANGELOG.rst", "diff": "@@ -6,14 +6,14 @@ V1.0.8 - 2022-04-28\n===================\nFeatures\n-========\n+--------\n- Improved Save-As capabilities when connected to a remote server and better struct making from the UI.\n(`#501 <https://github.com/vivisect/vivisect/pull/501>`_)\n- Improve output for the UI's ``names`` command.\n(`#516 <https://github.com/vivisect/vivisect/pull/516>`_)\nFixes\n-=====\n+-----\n- Fix issue in the proxy case where we forgot to snap in the analysis modules.\n(`#498 <https://github.com/vivisect/vivisect/pull/498>`_)\n- Fix string naming.\n" }, { "change_type": "MODIFY", "old_path": "README.md", "new_path": "README.md", "diff": "@@ -31,3 +31,5 @@ be loadable in python3 vivisect.\n## Build Status\n[![CircleCI](https://circleci.com/gh/vivisect/vivisect/tree/master.svg?style=svg)](https://circleci.com/gh/vivisect/vivisect/tree/master)\n+\n+[![Documentation Status](https://readthedocs.org/projects/vivisect/badge/?version=latest)](https://vivisect.readthedocs.io/en/latest/?badge=latest)\n" }, { "change_type": "MODIFY", "old_path": "requirements_doc.txt", "new_path": "requirements_doc.txt", "diff": "-r requirements_dev.txt\nsphinx>=1.8.2,<2.0.0\nsphinx-rtd-theme>=0.4.2,<1.0.0\n+jinja2<3.1.0\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Docbuild Fixes (#535)
718,770
08.08.2022 08:20:34
14,400
e2a204fb75479e9f04f3caa198a47cf8afedae68
Update vivisect/analysis/elf/elfplt.py pre checking both FPLT and FPLTSZ for None individually
[ { "change_type": "MODIFY", "old_path": "vivisect/analysis/elf/elfplt.py", "new_path": "vivisect/analysis/elf/elfplt.py", "diff": "@@ -162,7 +162,7 @@ def getPLTs(vw):\nFPLTSZ = fdyns.get('DT_PLTRELSZ')\n# if we don't have FPLT or FPLTSZ, skip this\n- if None in (FPLT, FPLTSZ):\n+ if FPLT is None or FPLTSZ is None:\ncontinue\nif vw.getFileMeta(fname, 'addbase'):\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Update vivisect/analysis/elf/elfplt.py pre @rakuy0, checking both FPLT and FPLTSZ for None individually
718,770
01.09.2022 09:41:18
14,400
848338daaa8814e85de355b189a93b6d24f79640
add api entry for *.__read_chk on posix
[ { "change_type": "MODIFY", "old_path": "vivisect/impapi/posix/i386.py", "new_path": "vivisect/impapi/posix/i386.py", "diff": "@@ -1118,6 +1118,7 @@ api = {\n'*.readdir_r': ('int', None, 'cdecl', '*.readdir_r', (('DIR *', 'dirstream'), ('struct dirent *', 'entry'), ('struct dirent * *', 'result'))),\n'*.readlink': ('ssize_t', None, 'cdecl', '*.readlink', (('const char *', 'filename'), ('char *', 'buffer'), ('size_t', 'size'))),\n'*.readv': ('ssize_t', None, 'cdecl', '*.readv', (('int', 'filedes'), ('const struct iovec *', 'vector'), ('int', 'count'))),\n+ '*.__read_chk': ('ssize_t', None, 'cdecl', '*.__read_chk', (('int', 'filedes'), ('void *', 'buffer'), ('size_t', 'nbytes'), ('size_t', 'buflen'))),\n'*.realloc': ('void *', None, 'cdecl', '*.realloc', (('void *', 'ptr'), ('size_t', 'newsize'))),\n'*.reallocarray': ('void *', None, 'cdecl', '*.reallocarray', (('void *', 'ptr'), ('size_t', 'nmemb'), ('size_t', 'size'))),\n'*.realpath': ('char *', None, 'cdecl', '*.realpath', (('const char * restrict', 'name'), ('char * restrict', 'resolved'))),\n" } ]
Python
Apache License 2.0
vivisect/vivisect
add api entry for *.__read_chk on posix (#545)
718,770
01.09.2022 11:25:36
14,400
96e70b5f74e80dfdd2d2a6f62a89bf2a1f5f3f7b
fix opcache key creation
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -1167,7 +1167,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nif loctup is not None and loctup[L_TINFO] and loctup[L_LTYPE] == LOC_OP:\narch = loctup[L_TINFO]\nif not skipcache:\n- key = (va, arch, b[:16])\n+ key = (va, arch, b[off:off+16])\nvalu = self._op_cache.get(key, None)\nif not valu:\nvalu = self.imem_archs[(arch & envi.ARCH_MASK) >> 16].archParseOpcode(b, off, va)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
fix opcache key creation (#544)
718,770
09.09.2022 14:22:06
14,400
d11eb54be2bc682ffc85ef2cbe2a5c5b6d7c3e65
pe bugfix and start-of-cleanup
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -333,7 +333,7 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nif sec.SizeOfRawData > pe.filesize:\ncontinue\n- plen = sec.VirtualSize - sec.SizeOfRawData\n+ #plen = sec.VirtualSize - sec.SizeOfRawData\ntry:\n# According to http://code.google.com/p/corkami/wiki/PE#section_table if SizeOfRawData is larger than VirtualSize, VS is used..\n@@ -589,7 +589,7 @@ def getMemBaseAndSize(vw, filename, baseaddr=None):\nnbase = nsec.VirtualAddress + baseaddr\nmlen = nbase - secbase\n- memmaps.append((secbase, 7, '', plen))\n+ memmaps.append((secbase, 7, '', mlen))\ncontinue\nif sec.SizeOfRawData < sec.VirtualSize:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
pe bugfix and start-of-cleanup
718,770
14.09.2022 08:15:12
14,400
1eb944f130aaa46ea6d547a03eccccdc0e2b2f9e
macho log-fix per change to blob file to fix bug in file lookups
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/blob.py", "new_path": "vivisect/parsers/blob.py", "diff": "@@ -36,9 +36,9 @@ def parseFd(vw, fd, filename=None, baseaddr=None):\nvw.setMeta('DefaultCall', archcalls.get(arch, 'unknown'))\nbytez = fd.read()\n- vw.addMemoryMap(baseaddr, 7, filename, bytez)\n- vw.addSegment(baseaddr, len(bytez), '%.8x' % baseaddr, 'blob')\nfname = vw.addFile(filename, baseaddr, v_parsers.md5Bytes(bytez))\n+ vw.addMemoryMap(baseaddr, 7, fname, bytez)\n+ vw.addSegment(baseaddr, len(bytez), '%.8x' % baseaddr, fname)\nvw.setFileMeta(fname, 'sha256', v_parsers.sha256Bytes(bytez))\ndef parseFile(vw, filename, baseaddr=None):\n@@ -64,8 +64,8 @@ def parseFile(vw, filename, baseaddr=None):\nbytez = f.read()\nfname = vw.addFile(filename, baseaddr, v_parsers.md5File(filename))\nvw.setFileMeta(fname, 'sha256', v_parsers.sha256Bytes(bytez))\n- vw.addMemoryMap(baseaddr, 7, filename, bytez)\n- vw.addSegment(baseaddr, len(bytez), '%.8x' % baseaddr, 'blob')\n+ vw.addMemoryMap(baseaddr, 7, fname, bytez)\n+ vw.addSegment(baseaddr, len(bytez), '%.8x' % baseaddr, fname)\ndef parseMemory(vw, memobj, baseaddr):\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/macho.py", "new_path": "vivisect/parsers/macho.py", "diff": "@@ -151,7 +151,7 @@ def _loadMacho(vw, filebytes, filename=None, baseaddr=None):\nlogger.debug(\"Applying struct %r at 0x%x\", sname, va+offset)\nvw.makeStructure(va + offset, sname)\nexcept Exception as e:\n- print(\"Error: %r\" % e)\n+ logger.warning(\"Error: %r\", e)\nfor va, cmdname in cmdinfo:\nvw.makeName(va, \"macho_\" + cmdname)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
macho log-fix per @rakuy0 change to blob file to fix bug in file lookups
718,770
14.09.2022 09:41:12
14,400
7609a9bb2e09ef8ade69aaa8f7bdc77a13b226ca
admin rights stuff per (and a try/finally clause around getAdminRights()) moving connectImportsWithExports() into the linker analysis module instead of the VivWorkspace remove superfluous `op = vw.parseOpcode()` call
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2858,64 +2858,6 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\noff = va - fileva\nself._fireEvent(VWE_WRITEMEM, (fname, off, bytez, self._supervisor))\n- def connectImportsWithExports(self):\n- \"\"\"\n- Look for any \"imported\" symbols that are satisfied by current exports.\n- Wire up the connection.\n-\n- Currently this is simply a pointer write at the location of the Import.\n- If this behavior is ever insufficient, we'll want to track the special\n- nature through the Export/Import events.\n- \"\"\"\n- logger.info('linking Imports with Exports')\n- # store old setting and set _supervisor mode (so we can write wherever\n- # we want, regardless of permissions)\n- oldsup = self._supervisor\n- self._supervisor = True\n-\n- for iva, isz, itype, isym in self.getImports():\n- impfname, impsym = isym.split('.', 1)\n- for eva, num, esym, efname in self.getExports():\n- if impsym != esym:\n- continue\n-\n- if impfname not in (efname, '*'):\n- continue\n-\n- if self.isFunctionThunk(eva):\n- logger.info(\"Skipping Exported Thunk\")\n- continue\n-\n- # file and symbol name match. apply the magic.\n- # do we ever *not* write in the full address at the import site?\n- logger.debug(\"connecting Import 0x%x -> Export 0x%x (%r)\", iva, eva, isym)\n- self.writeMemoryPtr(iva, eva)\n-\n- # remove the LOC_IMPORT and make it a Pointer instead\n- self.delLocation(iva)\n- self.makePointer(iva, follow=False) # don't follow, it'll be analyzed later?\n-\n- # store the former Import in a VaSet\n- self.setVaSetRow('ResolvedImports', (iva, isym, eva))\n-\n- # check if any xrefs to the import are branches and make code-xrefs for them\n- for xrfr, xrto, xrt, xrflags in self.getXrefsTo(iva):\n- loc = self.getLocation(xrfr)\n- if not loc:\n- continue\n-\n- lva, lsz, ltype, ltinfo = loc\n- if ltype != LOC_OP:\n- logger.warning(\"XREF not from an Opcode: 0x%x -> 0x%x (%r)\", lva, eva, loc)\n- continue\n-\n- op = self.parseOpcode(lva)\n- self.addXref(lva, eva, REF_CODE)\n- logger.debug(\"addXref(0x%x -> 0x%x)\", lva, eva)\n-\n- # restore previous supervisor mode\n- self._supervisor = oldsup\n-\ndef getFiles(self):\n\"\"\"\nReturn the current list of file objects in this\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/generic/linker.py", "new_path": "vivisect/analysis/generic/linker.py", "diff": "Connect any Exports we have to Imports we may also have\n(most useful for multiple file workspaces)\n'''\n+\n+import logging\n+logger = logging.getLogger(__name__)\n+\n+\n+def connectImportsWithExports(vw):\n+ \"\"\"\n+ Look for any \"imported\" symbols that are satisfied by current exports.\n+ Wire up the connection.\n+\n+ Currently this is simply a pointer write at the location of the Import.\n+ If this behavior is ever insufficient, we'll want to track the special\n+ nature through the Export/Import events.\n+ \"\"\"\n+ logger.info('linking Imports with Exports')\n+ # store old setting and set _supervisor mode (so we can write wherever\n+ # we want, regardless of permissions)\n+ with vw.getAdminRights():\n+ for iva, isz, itype, isym in vw.getImports():\n+ impfname, impsym = isym.split('.', 1)\n+ for eva, num, esym, efname in vw.getExports():\n+ if impsym != esym:\n+ continue\n+\n+ if impfname not in (efname, '*'):\n+ continue\n+\n+ if vw.isFunctionThunk(eva):\n+ logger.info(\"Skipping Exported Thunk\")\n+ continue\n+\n+ # file and symbol name match. apply the magic.\n+ # do we ever *not* write in the full address at the import site?\n+ logger.debug(\"connecting Import 0x%x -> Export 0x%x (%r)\", iva, eva, isym)\n+ vw.writeMemoryPtr(iva, eva)\n+\n+ # remove the LOC_IMPORT and make it a Pointer instead\n+ vw.delLocation(iva)\n+ vw.makePointer(iva, follow=False) # don't follow, it'll be analyzed later?\n+\n+ # store the former Import in a VaSet\n+ vw.setVaSetRow('ResolvedImports', (iva, isym, eva))\n+\n+ # check if any xrefs to the import are branches and make code-xrefs for them\n+ for xrfr, xrto, xrt, xrflags in vw.getXrefsTo(iva):\n+ loc = vw.getLocation(xrfr)\n+ if not loc:\n+ continue\n+\n+ lva, lsz, ltype, ltinfo = loc\n+ if ltype != LOC_OP:\n+ logger.warning(\"XREF not from an Opcode: 0x%x -> 0x%x (%r)\", lva, eva, loc)\n+ continue\n+\n+ vw.addXref(lva, eva, REF_CODE)\n+ logger.debug(\"addXref(0x%x -> 0x%x)\", lva, eva)\n+\n+\ndef analyze(vw):\n- vw.connectImportsWithExports()\n+ connectImportsWithExports(vw)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/base.py", "new_path": "vivisect/base.py", "diff": "@@ -210,9 +210,20 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\n@contextlib.contextmanager\ndef getAdminRights(self):\n+ '''\n+ Support function for ContextManager to support usage like:\n+ \"with vw.getAdminWrites():\"\n+\n+ Sets _supervisor privileges (allowing writes to all workspace maps),\n+ yields to perform the user's write-action, then sets _supervisor back\n+ to the original value.\n+ '''\n+ oldrights = self._supervisor\nself._supervisor = True\n+ try:\nyield\n- self._supervisor = False\n+ finally:\n+ self._supervisor = oldrights\ndef _handleADDLOCATION(self, loc):\nlva, lsize, ltype, linfo = loc\n@@ -544,10 +555,8 @@ class VivWorkspaceCore(viv_impapi.ImportApi):\n'''\nfname, off, bytez, supv = einfo\nimgbase = self.getFileMeta(fname, 'imagebase')\n- savesupv = self._supervisor\n- self._supervisor = True\n+ with self.getAdminRights():\ne_mem.MemoryObject.writeMemory(self, imgbase + off, bytez)\n- self._supervisor = savesupv\ndef _initEventHandlers(self):\nself.ehand = [None for x in range(VWE_MAX)]\n" } ]
Python
Apache License 2.0
vivisect/vivisect
admin rights stuff per @rakuy0 (and a try/finally clause around getAdminRights()) moving connectImportsWithExports() into the linker analysis module instead of the VivWorkspace remove superfluous `op = vw.parseOpcode()` call
718,770
14.09.2022 12:05:53
14,400
9ded4ca0e1f62436185172d0ecfe712599d489a9
avoid double-parsing: part 1 (ELF loads without apparent flaws)
[ { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2807,13 +2807,6 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nmod = viv_parsers.getParserModule(fmtname)\n- # get baseaddr and size, then make sure we have a good baseaddr\n- baseaddr, size = mod.getMemBaseAndSize(self, filename=filename, baseaddr=baseaddr)\n- logger.debug('initial baseva: 0x%x size: 0x%x', baseaddr, size)\n-\n- baseaddr = self.findFreeMemoryBlock(size, baseaddr)\n- logger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n-\nfname = mod.parseFile(self, filename=filename, baseaddr=baseaddr)\nif not self.getMeta('StorageName'):\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -44,15 +44,12 @@ def parseFd(vw, fd, filename=None, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('FIXME implement parseMemory for elf!')\n-def getMemBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, elf, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\nsavebase = baseaddr\n- fd = open(filename, 'rb')\n- elf = Elf.Elf(fd)\n-\nmemmaps = getMemoryMapInfo(elf)\nbaseaddr = 0xffffffffffffffffffffffff\ntopmem = 0\n@@ -260,6 +257,15 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nnew_pointers = []\nnew_functions = []\n+ # get baseaddr and size, then make sure we have a good baseaddr\n+ filebaseaddr, size = getMemBaseAndSize(vw, elf, baseaddr=baseaddr)\n+ if baseaddr is None:\n+ baseaddr = filebaseaddr\n+\n+ logger.debug('initial file baseva: 0x%x size: 0x%x', baseaddr, size)\n+ baseaddr = vw.findFreeMemoryBlock(size, baseaddr)\n+ logger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n+\narch = arch_names.get(elf.e_machine)\nif arch is None:\nraise Exception(\"Unsupported Architecture: %d\\n\", elf.e_machine)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
avoid double-parsing: part 1 (ELF loads without apparent flaws)
718,770
18.09.2022 20:04:36
14,400
d496c8f9ca344cf516e4687f466e2f00b8e71bf2
most things are initially roughed in and tested.
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/ihex.py", "new_path": "vivisect/parsers/ihex.py", "diff": "@@ -67,23 +67,12 @@ def parseFile(vw, filename, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('ihex loader cannot parse memory!')\n-def getMemBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, ihex, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\nsavebase = baseaddr\n- # figure out of there's an offset into the file we need to skip\n- offset = vw.config.viv.parsers.ihex.offset\n- if not offset:\n- offset = 0\n- ihex = v_ihex.IHexFile()\n- with open(filename, 'rb') as f:\n- shdr = f.read(offset)\n- sbytes = f.read()\n-\n- ihex.vsParse(sbytes)\n-\nmemmaps = ihex.getMemoryMaps()\nbaseaddr = 0xffffffffffffffffffffffff\ntopmem = 0\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/macho.py", "new_path": "vivisect/parsers/macho.py", "diff": "@@ -84,31 +84,41 @@ def checkFatMagicAndTrunc(vw, filebytes):\ndef _loadMacho(vw, filebytes, filename=None, baseaddr=None):\n+ hdr = e_common.hexify(filebytes[:4])\n+\n+ # Check for the FAT binary magic...\n+ if hdr in ('cafebabe', 'bebafeca'):\n+ filebytes = checkFatMagicAndTrunc(vw, filebytes)\n+\n+ # Instantiate the parser wrapper and parse bytes\n+ macho = vs_macho.mach_o()\n+ macho.vsParse(filebytes)\n+ # find the lowest loadable address, then get an offset so we can apply it later\n+ fakebase, size = getMemBaseAndSize(vw, macho, baseaddr=baseaddr))\n+ offset = baseaddr - fakebase\n+ logger.debug('initial file baseva: 0x%x size: 0x%x (address offset: 0x%x)', fakebase, size, offset)\n+\n+ # Determine base address to load into\n# We fake them to *much* higher than norm so pointer tests do better...\n+ # 1) baseaddr arg\n+ # 2) vw.config.viv.parsers.macho.baseaddr if non-zero\n+ # 3) vw.findFreeMemoryBlock() if baseaddr is zero/None or already exists in another map (collision)\n+\nif baseaddr is None:\nbaseaddr = vw.config.viv.parsers.macho.baseaddr\n+ if vw.isValidPointer(baseaddr):\n+ logger.info(\"baseaddr (0x%x) is in use. Finding appropriate address base.\", baseaddr)\n+ baseaddr = vw.findFreeMemoryBlock(size, fakebase)\n+ logger.debug(\"loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\n+\nif filename is None:\nfilename = 'macho_%.8x' % baseaddr # FIXME more than one!\n- # find the lowest loadable address, then get an offset so we can apply it later\n- fakebase, size = getMemBaseAndSize(vw, filename)\n- offset = baseaddr - fakebase\n- logger.debug(\"address offset: 0x%x\" % offset)\n-\n# grab md5 and sha256 hashes before we modify the bytes\nfhash = viv_parsers.md5Bytes(filebytes)\nsha256 = viv_parsers.sha256Bytes(filebytes)\n- hdr = e_common.hexify(filebytes[:4])\n-\n- # Check for the FAT binary magic...\n- if hdr in ('cafebabe', 'bebafeca'):\n- filebytes = checkFatMagicAndTrunc(vw, filebytes)\n-\n- # Instantiate the parser wrapper and parse bytes\n- macho = vs_macho.mach_o()\n- macho.vsParse(filebytes)\narch = vs_macho.mach_cpu_names.get(macho.mach_header.cputype)\nif arch is None:\n@@ -168,19 +178,13 @@ def _loadMacho(vw, filebytes, filename=None, baseaddr=None):\nreturn fname\n-def getMemBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, macho, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\nif baseaddr is None:\nbaseaddr = vw.config.viv.parsers.macho.baseaddr\n- with open(filename, 'rb') as f:\n- filebytes = f.read()\n-\n- macho = vs_macho.mach_o()\n- macho.vsParse(filebytes)\n-\nmemmaps = macho.getSegments()\nbaseaddr = 0xffffffffffffffffffffffff\ntopmem = 0\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/pe.py", "new_path": "vivisect/parsers/pe.py", "diff": "@@ -83,10 +83,14 @@ relmap = {\ndef loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\n- if baseaddr:\n- logger.info(\"loadPeIntoWorkspace(%r, %r, baseaddr=0x%x\", pe, filename, baseaddr)\n- else:\n- logger.info(\"loadPeIntoWorkspace(%r, %r, baseaddr=%r\", pe, filename, baseaddr)\n+ # get baseaddr and size, then make sure we have a good baseaddr\n+ filebaseaddr, size = getMemBaseAndSize(vw, pe, baseaddr=baseaddr)\n+ if baseaddr is None:\n+ baseaddr = filebaseaddr\n+\n+ logger.debug('initial file baseva: 0x%x size: 0x%x', baseaddr, size)\n+ baseaddr = vw.findFreeMemoryBlock(size, baseaddr)\n+ logger.info(\"loadPeIntoWorkspace: loading %r (size: 0x%x) at 0x%x\", filename, size, baseaddr)\nmach = pe.IMAGE_NT_HEADERS.FileHeader.Machine\n@@ -560,14 +564,12 @@ def loadPeIntoWorkspace(vw, pe, filename=None, baseaddr=None):\nreturn fname\n-def getMemBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, pe, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\nsavebase = baseaddr\n- pe = PE.PE(open(filename, 'rb'))\n-\nif baseaddr is None:\nbaseaddr = pe.IMAGE_NT_HEADERS.OptionalHeader.ImageBase\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/srec.py", "new_path": "vivisect/parsers/srec.py", "diff": "@@ -65,23 +65,12 @@ def parseFile(vw, filename, baseaddr=None):\ndef parseMemory(vw, memobj, baseaddr):\nraise Exception('srec loader cannot parse memory!')\n-def getMemBaseAndSize(vw, filename, baseaddr=None):\n+def getMemBaseAndSize(vw, srec, baseaddr=None):\n'''\nReturns the default baseaddr and memory size required to load the file\n'''\nsavebase = baseaddr\n- # figure out of there's an offset into the file we need to skip\n- offset = vw.config.viv.parsers.srec.offset\n- if not offset:\n- offset = 0\n- srec = v_srec.SRecFile()\n- with open(filename, 'rb') as f:\n- shdr = f.read(offset)\n- sbytes = f.read()\n-\n- srec.vsParse(sbytes)\n-\nmemmaps = srec.getMemoryMaps()\nbaseaddr = 0xffffffffffffffffffffffff\ntopmem = 0\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/teststorage.py", "new_path": "vivisect/tests/teststorage.py", "diff": "@@ -65,8 +65,8 @@ class StorageTests(unittest.TestCase):\nold = list(vw.exportWorkspace())\nnew = list(ovw.exportWorkspace())\n- self.assertEqual(len(old), 38)\n- self.assertEqual(len(new), 39) # the last event is a setMeta made by loadWorkspace\n+ self.assertEqual(len(old), 39)\n+ self.assertEqual(len(new), 40) # the last event is a setMeta made by loadWorkspace\nself.assertEqual(new[-1], (VWE_SETMETA, ('StorageName', self.tmpf.name)))\nfor idx in range(len(old)):\nself.assertEqual(old[idx], new[idx])\n@@ -96,7 +96,7 @@ class StorageTests(unittest.TestCase):\nmvw._event_list = []\nmvw.loadWorkspace(mpfile.name)\nmevt = list(mvw.exportWorkspace())\n- self.assertEqual(len(mevt), 39)\n+ self.assertEqual(len(mevt), 40)\nbvw = vivisect.VivWorkspace()\nbvw.setMeta('StorageModule', 'vivisect.storage.basicfile')\n" } ]
Python
Apache License 2.0
vivisect/vivisect
most things are initially roughed in and tested.
718,770
30.09.2022 08:14:07
14,400
c74322be800d53bc60cf3f1ca5a0f77eb1cf34c3
unittest tweaks and minor bugfix
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/macho.py", "new_path": "vivisect/parsers/macho.py", "diff": "@@ -94,7 +94,7 @@ def _loadMacho(vw, filebytes, filename=None, baseaddr=None):\nmacho = vs_macho.mach_o()\nmacho.vsParse(filebytes)\n# find the lowest loadable address, then get an offset so we can apply it later\n- fakebase, size = getMemBaseAndSize(vw, macho, baseaddr=baseaddr))\n+ fakebase, size = getMemBaseAndSize(vw, macho, baseaddr=baseaddr)\noffset = baseaddr - fakebase\nlogger.debug('initial file baseva: 0x%x size: 0x%x (address offset: 0x%x)', fakebase, size, offset)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/teststorage.py", "new_path": "vivisect/tests/teststorage.py", "diff": "@@ -103,7 +103,7 @@ class StorageTests(unittest.TestCase):\nbvw._event_list = []\nbvw.loadWorkspace(basicfile.name)\nbevt = list(bvw.exportWorkspace())\n- self.assertEqual(len(bevt), 39)\n+ self.assertEqual(len(bevt), 40)\n# the last three events are specific to the different storage modules\nfor idx in range(len(mevt) - 3):\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect_multi.py", "new_path": "vivisect/tests/testvivisect_multi.py", "diff": "@@ -81,7 +81,7 @@ class VivisectMultiFileTest(v_t_utils.VivTest):\nself.assertEqual(chgrp_main-chgrp, 5712)\n# test Relocs\n- self.assertIn(('ld_2_31', 179948, 2, 135749), vw.getRelocations())\n+ self.assertIn(('ld_2_31', 179948, 2, 135749, 4), vw.getRelocations())\nrel0 = vw.parseExpression('ld_2_31 + 179948')\nptr0 = vw.parseExpression('ld_2_31 + 135749')\nself.assertIn((rel0, ptr0, 3, 0), vw.getXrefsFrom(rel0))\n" } ]
Python
Apache License 2.0
vivisect/vivisect
unittest tweaks and minor bugfix
718,770
29.10.2022 16:38:59
14,400
8e9bba09f3867aa09e7aabc68480b00b50f968e4
Enabling POSIX Library Load notifications (since PTRACE event model doesn't alert on library loads like Windows does). a couple other general bugfixes/deprecation-cleanup "because we're in the area." (this is ripped out of the Vtrace PR because it's important enough to get it's own)
[ { "change_type": "MODIFY", "old_path": "envi/threads.py", "new_path": "envi/threads.py", "diff": "@@ -19,8 +19,7 @@ def firethread(func):\nand callers may not expect sync behavior!\n'''\ndef dothread(*args, **kwargs):\n- thr = threading.Thread(target=func, args=args, kwargs=kwargs)\n- thr.setDaemon(True)\n+ thr = threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True)\nthr.start()\nreturn thr\nfunctools.update_wrapper(dothread, func)\n@@ -44,8 +43,7 @@ def maintthread(stime):\ntime.sleep(stime)\ndef dothread(*args, **kwargs):\n- thr = threading.Thread(target=maintloop, args=args, kwargs=kwargs)\n- thr.setDaemon(True)\n+ thr = threading.Thread(target=maintloop, args=args, kwargs=kwargs, daemon=True)\nthr.start()\nfunctools.update_wrapper(dothread, func)\n" }, { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -492,6 +492,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\ntrace.setMeta('PendingBreak', False)\nbp = trace.getCurrentBreakpoint()\nif bp:\n+ if not bp.silent:\nself.vprint(\"Thread: %d Hit Break: %s\" % (tid, repr(bp)))\ncmdstr = self.bpcmds.get(bp.id, None)\nif cmdstr is not None:\n@@ -574,7 +575,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nif dohex:\nmemstr = binascii.unhexlify(memstr)\nif douni:\n- memstr = (\"\\x00\".join(memstr)) + \"\\x00\"\n+ memstr = (b\"\\x00\".join(memstr)) + b\"\\x00\"\naddr = self.parseExpression(exprstr)\nself.memobj.writeMemory(addr, memstr)\n@@ -1861,6 +1862,8 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nself.vprint(\" [ Breakpoints ]\")\nfor bp in self.trace.getBreakpoints():\n+ if bp.untouchable: # don't list untouchable bp's\n+ continue\nself._print_bp(bp)\ndef _print_bp(self, bp):\n" }, { "change_type": "MODIFY", "old_path": "vtrace/__init__.py", "new_path": "vtrace/__init__.py", "diff": "@@ -156,6 +156,11 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\n# Add event numbers to here for auto-continue\nself.auto_continue = [NOTIFY_LOAD_LIBRARY, NOTIFY_CREATE_THREAD, NOTIFY_UNLOAD_LIBRARY, NOTIFY_EXIT_THREAD, NOTIFY_DEBUG_PRINT]\n+ # Create a LoadLibrary hook to enable simple and consistent\n+ # Break-On-Load/Init functionality. This is also necessary for\n+ # resolving symbols on new library loads.\n+ self.registerNotifier(NOTIFY_LOAD_LIBRARY, LibraryNotifier())\n+\ndef execute(self, cmdline):\n\"\"\"\nStart a new process and debug it\n@@ -694,7 +699,7 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\n\"\"\"\nself.requireAttached()\nbp = self.bpbyid.pop(id, None)\n- if bp is not None:\n+ if bp is not None and not bp.untouchable:\nbp.deactivate(self)\nif bp in self.deferred:\nself.deferred.remove(bp)\n@@ -708,6 +713,20 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\n# Remove cached breakpoint code\nBreakpoint.bpcodeobj.pop(id, None)\n+ def _updateBreakAddresses(self):\n+ \"\"\"\n+ Update breakpoint address resolution (in unresolved breakpoints).\n+ Intended to be run after events which change the namespace, such as\n+ NOTIFY_LOAD_LIBRARY events\n+ \"\"\"\n+ for bp in self.deferred:\n+ bp.resolveAddress(self)\n+ if bp.address is not None:\n+ self.breakpoints[bp.address] = bp\n+ self.deferred.remove(bp)\n+ bp.activate(self)\n+ logger.warning(\"Resolved bp address: %r\", bp)\n+\ndef getCurrentBreakpoint(self):\n\"\"\"\nReturn the current breakpoint otherwise None\n@@ -755,7 +774,7 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\nNOTE: code which wants to be remote-safe should use this\n\"\"\"\nbp = self.getBreakpoint(bpid)\n- if bp is None:\n+ if bp is None or bp.untouchable:\nraise Exception(\"Breakpoint %d Not Found\" % bpid)\nif not enabled: # To catch the \"disable\" of fastbreaks...\nbp.deactivate(self)\n" }, { "change_type": "MODIFY", "old_path": "vtrace/breakpoints.py", "new_path": "vtrace/breakpoints.py", "diff": "@@ -31,6 +31,9 @@ class Breakpoint:\nself.active = False\nself.fastbreak = False # no NOTIFY_BREAK, autocont, no NOTIFY_CONTINUE\nself.stealthbreak = False # no NOTIFY_BREAK\n+ self.silent = False\n+ self.untouchable = False # system breakpoint. can't remove it or see it.\n+ self._complained = False\nself.id = -1\nself.vte = None\n@@ -96,9 +99,13 @@ class Breakpoint:\nif self.address is None and self.vte:\ntry:\nself.address = trace.parseExpression(self.vte)\n+\nexcept Exception as e:\n- logger.warning('Failed to resolve breakpoint address for expression: %s', self.vte)\n- logger.warning('Error:', exc_info=1)\n+ # this will happen with unresolved breakpoints.\n+ # depending on when resolution happens, the library may not have loaded yet.\n+ if not self._complained:\n+ logger.warning('Failed to resolve breakpoint address for expression: %s (delayed resolution?)', self.vte)\n+ self._complained = True\nself.address = None\n# If we resolved, lets get our saved code...\n@@ -404,3 +411,17 @@ class PostHookBreakpoint(NiceBreakpoint):\nret_addr, args = tup\nself.runPostHookCallbacks(event, trace, ret_addr, args)\n+\n+class PosixLibLoadHookBreakpoint(Breakpoint):\n+ '''\n+ POSIX systems need to hook DL to identfy when libraries are loaded.\n+ '''\n+ def __init__(self, expression):\n+ Breakpoint.__init__(self, None, expression=expression)\n+ self.untouchable = True\n+ self.silent = True\n+\n+ def notify(self, event, trace):\n+ logger.debug(\"PosixLibLoadHookBreakpoint: reanalyze maps and resolve symbols\")\n+ trace._findLibraryMaps(b'\\x7fELF', always=True)\n+ # handle unresolved expression bp's\n" }, { "change_type": "MODIFY", "old_path": "vtrace/notifiers.py", "new_path": "vtrace/notifiers.py", "diff": "@@ -136,3 +136,12 @@ class DistributedNotifier(Notifier):\ndef deregisterNotifier(self, event, notif):\nnlist = self.notifiers.get(event)\nnlist.remove(notif)\n+\n+class LibraryNotifier(Notifier):\n+ def notify(self, event, trace):\n+ logger.info(\"LibraryNotifier.notify(%r, %r)\", event, trace)\n+\n+ # update unresolved breakpoints:\n+ trace._updateBreakAddresses()\n+\n+\n" }, { "change_type": "MODIFY", "old_path": "vtrace/platforms/base.py", "new_path": "vtrace/platforms/base.py", "diff": "@@ -537,6 +537,7 @@ class TracerBase(vtrace.Notifier):\nabout a LOAD_LIBRARY. (This means *not* from inside another\nnotifer)\n\"\"\"\n+ logger.info(\"addLibraryBase(%r, 0x%x, %r)\", libname, address, always)\nself.setMeta(\"LatestLibrary\", None)\nself.setMeta(\"LatestLibraryNorm\", None)\n@@ -878,7 +879,7 @@ class TracerBase(vtrace.Notifier):\ndef threadwrap(func):\ndef trfunc(self, *args, **kwargs):\n- if threading.currentThread().__class__ == TracerThread:\n+ if threading.current_thread().__class__ == TracerThread:\nreturn func(self, *args, **kwargs)\n# Proxy the call through a single thread\nq = queue.Queue()\n@@ -904,9 +905,8 @@ class TracerThread(threading.Thread):\nto make particular calls and on what platforms... YAY!\n\"\"\"\ndef __init__(self):\n- threading.Thread.__init__(self)\n+ threading.Thread.__init__(self, daemon=True)\nself.queue = queue.Queue()\n- self.setDaemon(True)\nself.start()\ndef run(self):\n" }, { "change_type": "MODIFY", "old_path": "vtrace/platforms/linux.py", "new_path": "vtrace/platforms/linux.py", "diff": "@@ -413,6 +413,12 @@ class LinuxMixin(v_posix.PtraceMixin, v_posix.PosixMixin):\nraise Exception(\"PT_ATTACH failed!\")\nself.setMeta(\"ExeName\", self._findExe(pid))\n+ def _LibraryLoadHack(self):\n+ # drop special breakpoint at ld._dl_catch_exception\n+ import vtrace.breakpoints as v_bp\n+ bp = v_bp.PosixLibLoadHookBreakpoint('ld._dl_catch_exception')\n+ self.addBreakpoint(bp)\n+\ndef platformPs(self):\npslist = []\nfor dname in self.platformListDir('/proc'):\n" }, { "change_type": "MODIFY", "old_path": "vtrace/platforms/posix.py", "new_path": "vtrace/platforms/posix.py", "diff": "@@ -61,6 +61,14 @@ class PosixMixin:\n# break after our library load events to make things easy\nself.runAgain(False) # Clear this, if they want BREAK to run, it will\nself.fireNotifiers(vtrace.NOTIFY_BREAK)\n+ # POSIX hack - Windows signals on library load, POSIX doesn't\n+ self._LibraryLoadHack()\n+\n+ def _LibraryLoadHack(self):\n+ '''\n+ Implement at the platform level\n+ '''\n+ pass\ndef platformProcessEvent(self, event):\npid, status = event\n" }, { "change_type": "MODIFY", "old_path": "vtrace/tests/testbasic.py", "new_path": "vtrace/tests/testbasic.py", "diff": "@@ -59,6 +59,6 @@ class VtraceBasicTest(vt_tests.VtraceProcessTest):\nclass VtraceBasicExecTest(VtraceBasicTest, vt_tests.VtraceExecTest):\nbreakpoints = {\n'windows': 'ntdll.NtTerminateProcess',\n- 'linux': 'ld.malloc',\n+ 'linux': 'libc.malloc',\n'freebsd': 'ld._rtld_thread_init',\n}\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Enabling POSIX Library Load notifications (since PTRACE event model doesn't alert on library loads like Windows does). a couple other general bugfixes/deprecation-cleanup "because we're in the area." (this is ripped out of the Vtrace PR because it's important enough to get it's own)
718,770
30.10.2022 19:17:48
14,400
70269ab567e9ebc333faf79db11e961e4d4fdcbc
Update vstruct/defs/macho/__init__.py
[ { "change_type": "MODIFY", "old_path": "vstruct/defs/macho/__init__.py", "new_path": "vstruct/defs/macho/__init__.py", "diff": "@@ -54,7 +54,7 @@ class mach_o(vstruct.VStruct):\nself._entrypoints = []\noffset = len(self.mach_header)\nfor fname, vs in self.load_commands:\n- if vs.cmd == LC_UNIXTHREAD:\n+ if vs.cmd in (LC_MAIN, LC_UNIXTHREAD):\neoff = len(vs)\npsize = vs.flavor\nbigend = self.vsGetEndian()\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Update vstruct/defs/macho/__init__.py
718,770
19.11.2022 14:23:38
18,000
063c9d2071b3a0ecdc9697edb4556208dbca5cb0
fix i386's vtrace archGetBackTrace() results (they're reversed from what the rest of the system do)
[ { "change_type": "MODIFY", "old_path": "vtrace/archs/i386.py", "new_path": "vtrace/archs/i386.py", "diff": "@@ -144,7 +144,7 @@ class i386Mixin(e_i386.i386Module, e_i386.i386RegisterContext, i386WatchMixin):\nebp, eip = struct.unpack(\"<LL\", buf)\nif frames[-1] == (ebp, eip):\nbreak\n- frames.append((ebp, eip))\n+ frames.append((eip, ebp))\ncurrent += 1\nexcept:\nbreak\n" } ]
Python
Apache License 2.0
vivisect/vivisect
fix i386's vtrace archGetBackTrace() results (they're reversed from what the rest of the system do) (#553)
718,770
19.11.2022 14:49:00
18,000
fb23b9f2ba86ff7f36975bb088367ddca7c64887
minor bugfixes: VDB RegisterView widget and MSP430 archGetRegisterGroups
[ { "change_type": "MODIFY", "old_path": "envi/archs/msp430/__init__.py", "new_path": "envi/archs/msp430/__init__.py", "diff": "@@ -24,11 +24,9 @@ class Msp430Module(envi.ArchitectureModule):\ndef archGetNopInstr(self):\nreturn b'\\x03\\x43' # NOP is emulated with: MOV #0, R3\n- def archGetRegisterGroups(self):\n- groups = envi.ArchitectureModule.archGetRegisterGroups(self)\n- general= ('general', registers, )\n- groups.append(general)\n- return groups\n+ def initRegGroups(self):\n+ envi.ArchitectureModule.initRegGroups(self)\n+ self._regGrps.update({'general': registers})\ndef getPointerSize(self):\nreturn 2\n" }, { "change_type": "MODIFY", "old_path": "vtrace/qt.py", "new_path": "vtrace/qt.py", "diff": "@@ -183,7 +183,7 @@ class RegistersView(QWidget):\nself.flagviews = {}\nreg_groups = trace.archGetRegisterGroups()\n- for name, group in reg_groups:\n+ for name, group in reg_groups.items():\nself.regviews[name] = group\nself.viewnames.addItem(name)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
minor bugfixes: VDB RegisterView widget and MSP430 archGetRegisterGroups (#552) Co-authored-by: James Gross <45212823+rakuy0@users.noreply.github.com>
718,770
21.11.2022 00:35:07
18,000
8d508dc3cfcb7f0d6e216667fdb7a228d60713b4
elf bugfixes (test)
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -117,7 +117,7 @@ def getMemoryMapInfo(elf, fname=None, baseaddr=None):\nbaseaddr = 0x05000000\nfor offset,size in merged:\nbytez = elf.readAtOffset(offset,size)\n- memmaps.append((baseaddr + offset, 0x7, fname, bytez, None))\n+ memmaps.append((baseaddr + offset, 0x7, fname, bytez, 0))\nfor sec in secs:\nif sec.sh_offset and sec.sh_size:\n@@ -229,6 +229,11 @@ def getAddBaseAddr(elf, baseaddr=None):\nif not elf.isPreLinked() and elf.isSharedObject():\naddbase = True\nbaseoff = baseaddr\n+\n+ elif elf.isRelocatable():\n+ addbase = True\n+ baseoff = 0\n+\nelse:\naddbase = False\nbaseoff = baseaddr - elfbaseaddr\n@@ -301,6 +306,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\n# Base addr is earliest section address rounded to pagesize\n# Some ELF's require adding the baseaddr to most/all later addresses\naddbase, baseoff, baseaddr = getAddBaseAddr(elf, baseaddr)\n+ logger.warning(\"addbase: %r, baseoff: 0x%x, baseaddr: 0x%x\", addbase, baseoff, baseaddr)\nelf.fd.seek(0)\nmd5hash = v_parsers.md5Bytes(byts)\n@@ -421,7 +427,9 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue # Skip non-memory mapped sections\nsva = sec.sh_addr\n+ logger.warning(\"sva = sec.sh_addr (0x%x)\", sva)\nsva += baseoff\n+ logger.warning(\"sva += baseoff (0x%x) == 0x%x\", baseoff, sva)\n# if we've already defined a location at this address, skip it. (eg. DYNAMICS)\nif vw.getLocation(sva) == sva:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
elf bugfixes (test)
718,770
21.11.2022 07:35:13
18,000
a2dc2ce4c37f5bb75dea1c4e4245b97215efd504
remove default baseaddr for ELF's with no Program Headers
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -98,6 +98,7 @@ def getMemoryMapInfo(elf, fname=None, baseaddr=None):\nlogger.info('Skipping: %s', pgm)\nif len(pgms) == 0:\n+ # NOTE: among other file types, Linux Kernel modules have no program headers\nsecs = elf.getSections()\n# fall back to loading sections as best we can...\nlogger.info('elf: no program headers found! (in %r)', fname)\n@@ -114,7 +115,6 @@ def getMemoryMapInfo(elf, fname=None, baseaddr=None):\nmerged.append( maps[i] )\n- baseaddr = 0x05000000\nfor offset,size in merged:\nbytez = elf.readAtOffset(offset,size)\nmemmaps.append((baseaddr + offset, 0x7, fname, bytez, 0))\n" } ]
Python
Apache License 2.0
vivisect/vivisect
remove default baseaddr for ELF's with no Program Headers
718,770
22.11.2022 12:04:09
18,000
06d3c1cf5f715830473f2be5f6b266d6820637be
upstream bugfix: alignment issues for Section-only ELFs
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -56,7 +56,7 @@ def getMemBaseAndSize(vw, elf, baseaddr=None):\nfor mapva, mperms, mname, mbytes, malign in memmaps:\nif mapva < baseaddr:\n- baseaddr = mapva\n+ baseaddr = mapva & -e_const.PAGE_SIZE # align to page-size\nendva = mapva + len(mbytes)\nif endva > topmem:\ntopmem = endva\n@@ -103,7 +103,7 @@ def getMemoryMapInfo(elf, fname=None, baseaddr=None):\n# fall back to loading sections as best we can...\nlogger.info('elf: no program headers found! (in %r)', fname)\n- maps = [ [s.sh_offset,s.sh_size] for s in secs if s.sh_offset and s.sh_size ]\n+ maps = [ [s.sh_offset,s.sh_size,s.sh_addralign] for s in secs if s.sh_offset and s.sh_size ]\nmaps.sort()\nmerged = []\n@@ -115,9 +115,9 @@ def getMemoryMapInfo(elf, fname=None, baseaddr=None):\nmerged.append( maps[i] )\n- for offset,size in merged:\n+ for offset,size,align in merged:\nbytez = elf.readAtOffset(offset,size)\n- memmaps.append((baseaddr + offset, 0x7, fname, bytez, 0))\n+ memmaps.append((baseaddr + offset, 0x7, fname, bytez, align))\nfor sec in secs:\nif sec.sh_offset and sec.sh_size:\n" } ]
Python
Apache License 2.0
vivisect/vivisect
upstream bugfix: alignment issues for Section-only ELFs
718,770
27.11.2022 19:13:32
18,000
7c4c2055ae43d1806efa475e5b015127f9ea9f34
modify hellokernel unittest to allow for relocation. add comment to ELF "isRelocatable()" function to describe what this means
[ { "change_type": "MODIFY", "old_path": "Elf/__init__.py", "new_path": "Elf/__init__.py", "diff": "@@ -757,6 +757,8 @@ class Elf(vs_elf.Elf32, vs_elf.Elf64):\ndef isRelocatable(self):\n'''\nReturns true if the given Elf binary is marked as a relocatable file.\n+ isRelocatable() helps determine if this ELF is a Kernel Module (.ko)\n+ or Object file (.o), *not* a Shared Object (.so) or executable.\n'''\nreturn self.e_type == ET_REL\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -1593,7 +1593,7 @@ class VivisectTest(v_t_utils.VivTest):\ndef test_relocatable_elf_simple(self):\nkmod = helpers.getTestWorkspace('linux', 'amd64', 'hellokernel.ko')\n- self.eq(set(kmod.getFunctions()), set([0x7c, 0x95]))\n+ self.eq(set(kmod.getFunctions()), set([0x20007c, 0x200095]))\ndef test_guid(self):\nvw = vivisect.VivWorkspace()\n" } ]
Python
Apache License 2.0
vivisect/vivisect
modify hellokernel unittest to allow for relocation. add comment to ELF "isRelocatable()" function to describe what this means
718,770
29.11.2022 08:14:58
18,000
1c6b0b2a70998496a2dba1d42648a364f07d8797
restore kernel module basing behavior to match master
[ { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -63,7 +63,7 @@ def getMemBaseAndSize(vw, elf, baseaddr=None):\nsize = topmem - baseaddr\n- if baseaddr == 0:\n+ if baseaddr == 0 and not elf.isRelocatable():\nbaseaddr = vw.config.viv.parsers.elf.baseaddr\nif savebase:\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -1593,7 +1593,7 @@ class VivisectTest(v_t_utils.VivTest):\ndef test_relocatable_elf_simple(self):\nkmod = helpers.getTestWorkspace('linux', 'amd64', 'hellokernel.ko')\n- self.eq(set(kmod.getFunctions()), set([0x20007c, 0x200095]))\n+ self.eq(set(kmod.getFunctions()), set([0x7c, 0x95]))\ndef test_guid(self):\nvw = vivisect.VivWorkspace()\n" } ]
Python
Apache License 2.0
vivisect/vivisect
restore kernel module basing behavior to match master
718,770
04.12.2022 19:30:13
18,000
c7d9190c70585824920ca2963c3c3e9854a5a2fd
missed one (per
[ { "change_type": "MODIFY", "old_path": "vtrace/platforms/posix.py", "new_path": "vtrace/platforms/posix.py", "diff": "@@ -62,9 +62,9 @@ class PosixMixin:\nself.runAgain(False) # Clear this, if they want BREAK to run, it will\nself.fireNotifiers(vtrace.NOTIFY_BREAK)\n# POSIX hack - Windows signals on library load, POSIX doesn't\n- self._LibraryLoadHack()\n+ self._LibraryLoadHook()\n- def _LibraryLoadHack(self):\n+ def _LibraryLoadHook(self):\n'''\nImplement at the platform level\n'''\n" } ]
Python
Apache License 2.0
vivisect/vivisect
missed one (per @rakuy0)
718,770
28.12.2022 16:38:10
18,000
7c3bbd2bfdfce519cc53b139758371c704710fb1
all the changes and i discussed. (i think)
[ { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -492,6 +492,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\ntrace.setMeta('PendingBreak', False)\nbp = trace.getCurrentBreakpoint()\nif bp:\n+ if not self.silent:\nself.vprint(\"Thread: %d Hit Break: %s\" % (tid, repr(bp)))\ncmdstr = self.bpcmds.get(bp.id, None)\nif cmdstr is not None:\n@@ -1721,7 +1722,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nwhere options include:\n-F toggles a breakpoint's FastBreak mode\n- -S toggles a breakpoint's Stealth mode (doesn't fire Notifiers, still runs BP code)\n+ -S toggles a breakpoint's Silent mode (doesn't print console msg, still runs BP code)\n-V prints more metadata about a given breakpoint (default is just the code)\nNOTE: Your code must be surrounded by \"s and may not\n@@ -1750,7 +1751,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nverbose = True\nelif opt == '-S':\n- bp.stealthbreak = not bp.stealthbreak\n+ bp.silent = not bp.silent\nelif opt == '-F':\nbp.fastbreak = not bp.fastbreak\n@@ -1764,12 +1765,12 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nself.vprint(\"%r\" % bp)\nself.vprint(\" code: %s\" % (pystr))\nself.vprint(\" FastBreak: %r\" % bp.fastbreak)\n- self.vprint(\" resonce: %r\" % bp.resonce)\n- self.vprint(\" active: %r\" % bp.active)\nself.vprint(\" enabled: %r\" % bp.enabled)\n+ self.vprint(\" silent: %r\" % bp.silent)\n+ self.vprint(\" active: %r\" % bp.active)\n+ self.vprint(\" resonce: %r\" % bp.resonce)\n+ if bp.stealthbreak:\nself.vprint(\" stealth: %r\" % bp.stealthbreak)\n- if bp.untouchable:\n- self.vprint(\" untouchable: %r\" % bp.untouchable)\nelse:\nself.vprint(\"[%d] Breakpoint code: %s\" % (bpid,pystr))\n" }, { "change_type": "MODIFY", "old_path": "vtrace/breakpoints.py", "new_path": "vtrace/breakpoints.py", "diff": "@@ -25,14 +25,14 @@ class Breakpoint:\nbpcodeobj = {} # Cache compiled code objects on the class def\ndef __init__(self, address, expression=None):\n- self.resonce = False\n+ self.resonce = False # has this addr expression been resolved yet?\nself.address = address\n- self.enabled = True\n- self.active = False\n+ self.enabled = True # should this BP be used/ignored\n+ self.active = False # have we placed a BP in the code (eg. i386: \\xCC)\n+ self.silent = False # don't print \"Hit Break\" messages, still runs code/notifiers\nself.fastbreak = False # no NOTIFY_BREAK, autocont, no NOTIFY_CONTINUE\n- self.stealthbreak = False # no NOTIFY_BREAK\n- self.untouchable = False # system breakpoint. can't remove it or see it.\n- self._complained = False\n+ self.stealthbreak = False # no NOTIFY_BREAK - used for hidden/system events\n+ self._complained = False # only complain about not resolving this *once*\nself.id = -1\nself.vte = None\n@@ -417,10 +417,12 @@ class PosixLibLoadHookBreakpoint(Breakpoint):\n'''\ndef __init__(self, expression):\nBreakpoint.__init__(self, None, expression=expression)\n- self.untouchable = True\nself.stealthbreak = True\ndef notify(self, event, trace):\nlogger.debug(\"PosixLibLoadHookBreakpoint: reanalyze maps and resolve symbols\")\n- trace._findLibraryMaps(b'\\x7fELF', always=True)\n+ if not trace._findLibraryMaps(b'\\x7fELF', always=True):\n+ # if we find new maps, we'll let the LOAD_LIBRARY Autoload config setting handle\n+ # whether we continue or not. if we fire this and *don't* find a new map,\n+ # let's just continue like nothing ever happened. \"Nothing to see here.\"\ntrace.runAgain()\n" }, { "change_type": "MODIFY", "old_path": "vtrace/platforms/base.py", "new_path": "vtrace/platforms/base.py", "diff": "@@ -576,9 +576,11 @@ class TracerBase(vtrace.Notifier):\ndef _findLibraryMaps(self, magic, always=False):\n# A utility for platforms which lack library load\n# notification through the operating system\n+ # TODO: update to handle *losing* memory maps as well.\nbmaps = self.getMeta(\"BadMaps\", [])\ndone = {}\nmlen = len(magic)\n+ newcount = 0\nfor addr, size, perms, fname in self.getMemoryMaps():\nif not fname:\n@@ -587,7 +589,7 @@ class TracerBase(vtrace.Notifier):\nif done.get(fname):\ncontinue\n- if addr in self.getMeta(\"LibraryPaths\"):\n+ if fname == self.getMeta(\"LibraryPaths\").get(addr):\ncontinue\nif fname in bmaps:\n@@ -597,10 +599,13 @@ class TracerBase(vtrace.Notifier):\nif self.readMemory(addr, mlen) == magic:\ndone[fname] = True\nself.addLibraryBase(fname, addr, always=always)\n+ newcount += 1\nexcept Exception as e:\nlogger.warning('findLibraryMaps(0x%x, %d, %s, %s) hit exception: %s', addr, size, perms, fname, e)\n+ return newcount\n+\ndef _loadBinaryNorm(self, normname):\nif not self.libloaded.get(normname, False):\nfname = self.libpaths.get(normname)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
all the changes @invisig0th and i discussed. (i think)
718,770
28.12.2022 16:48:07
18,000
d1f6b9c3bab867b7aeeb280cdc08f477e7f09b58
untouchable -> stealthbreak
[ { "change_type": "MODIFY", "old_path": "vdb/__init__.py", "new_path": "vdb/__init__.py", "diff": "@@ -1843,7 +1843,7 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nelif opt == \"-C\":\nfor bp in self.trace.getBreakpoints():\n- if bp.untouchable:\n+ if bp.stealthbreak:\ncontinue\nself.bpcmds.pop(bp.id, None)\n@@ -1914,8 +1914,8 @@ class Vdb(e_cli.EnviMutableCli, v_notif.Notifier, v_util.TraceManager):\nself.vprint(\" [ Breakpoints ]\")\nfor bp in self.trace.getBreakpoints():\n- if bp.untouchable and not showall:\n- # don't list untouchable bp's (unless forced)\n+ if bp.stealthbreak and not showall:\n+ # don't list stealthbreak bp's (unless forced)\ncontinue\nself._print_bp(bp)\n" }, { "change_type": "MODIFY", "old_path": "vtrace/__init__.py", "new_path": "vtrace/__init__.py", "diff": "@@ -699,7 +699,7 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\n\"\"\"\nself.requireAttached()\nbp = self.bpbyid.pop(id, None)\n- if bp is not None and not bp.untouchable:\n+ if bp is not None and not bp.stealthbreak:\nbp.deactivate(self)\nif bp in self.deferred:\nself.deferred.remove(bp)\n@@ -760,7 +760,7 @@ class Trace(e_mem.IMemory, e_reg.RegisterContext, e_resolv.SymbolResolver, objec\nNOTE: code which wants to be remote-safe should use this\n\"\"\"\nbp = self.getBreakpoint(bpid)\n- if bp is None or bp.untouchable:\n+ if bp is None or bp.stealthbreak:\nraise Exception(\"Breakpoint %d Not Found\" % bpid)\nif not enabled: # To catch the \"disable\" of fastbreaks...\nbp.deactivate(self)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
untouchable -> stealthbreak
718,770
30.12.2022 08:46:17
18,000
4e24cfcac316482f4e5517f838ec843e779afc48
final change to completely supplant PR 557
[ { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -146,12 +146,15 @@ class IMemory:\nmmap = self.getMemoryMap(va)\nif mmap is None:\nreturn False\n+\nmapva, mapsize, mapperm, mapfile = mmap\nmapend = mapva+mapsize\nif va+size > mapend:\nreturn False\n- if mapperm & perm != perm:\n+\n+ if mapperm & perm != perm and not self._supervisor:\nreturn False\n+\nreturn True\ndef allocateMemory(self, size, perms=MM_RWX, suggestaddr=0):\n@@ -578,7 +581,7 @@ class MemoryObject(IMemory):\nfor mva, mmaxva, mmap, mbytes in self._map_defs:\nif mva <= va < mmaxva:\nmva, msize, mperms, mfname = mmap\n- if not mperms & MM_READ:\n+ if not (mperms & MM_READ or self._supervisor):\nmsg = \"Bad Memory Read (no READ permission): %s: %s\" % (hex(va), hex(size))\nif _origva is not None:\nmsg += \" (original va: %s)\" % hex(_origva)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
final change to completely supplant PR 557
718,770
30.12.2022 08:48:07
18,000
7be248c08a88d8cd531daa6f2f1eb65471e942ce
minor tweak and a minor bugfix in linker
[ { "change_type": "MODIFY", "old_path": "Elf/__init__.py", "new_path": "Elf/__init__.py", "diff": "@@ -87,6 +87,7 @@ class Elf(vs_elf.Elf32, vs_elf.Elf64):\nelse:\nself.r_types = {}\n+ self.dyns = {}\nself.pheaders = []\nself.sections = []\nself.secnames = {}\n@@ -290,7 +291,6 @@ class Elf(vs_elf.Elf32, vs_elf.Elf64):\nThis must be run before most Dynamic-data accessors like getDynStrtabString(),\ngetDynSymTabInfo(), etc..\n'''\n- self.dyns = {}\ndynbytes = self.getDynBytes()\nif dynbytes is None:\nreturn\n" }, { "change_type": "MODIFY", "old_path": "vivisect/analysis/generic/linker.py", "new_path": "vivisect/analysis/generic/linker.py", "diff": "@@ -5,7 +5,7 @@ Connect any Exports we have to Imports we may also have\nimport logging\nlogger = logging.getLogger(__name__)\n-from vivisect import LOC_OP\n+from vivisect import LOC_OP, REF_CODE\ndef analyze(vw):\n\"\"\"\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -399,7 +399,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nmakeFunctionTable(elf, vw, f_preinita, f_preinitasz, 'preinit_array', new_functions, new_pointers, baseoff)\n# dynamic table\n- phdr = elf.getDynPHdr() # file offset?\n+ phdr = elf.getDynPHdr() # this is the Program Header which points at the DYNAMICS table, not the other way around.\nif phdr is not None:\nsva, size = phdr.p_vaddr, phdr.p_memsz\nsva += baseoff # getDynInfo returns (offset, filesz)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect_multi.py", "new_path": "vivisect/tests/testvivisect_multi.py", "diff": "@@ -9,6 +9,14 @@ logger = logging.getLogger(__name__)\nclass VivisectMultiFileTest(v_t_utils.VivTest):\ndef test_multiple_i386(self):\n+ '''\n+ Note: because we're using a non-relocatable executable (vdir.llvm) and relocating it, this\n+ will unfortunately throw a lot of ugly exceptions, because there are hard-coded addresses\n+ in the instructions themselves, which are relocations because the file isn't \"relocatable\"\n+\n+ We only test the things which should work because they are made available for relocation\n+ through the ELF metadata.\n+ '''\nvw = helpers.getTestWorkspace_nocache('linux', 'i386', 'chgrp.llvm')\nvw = helpers.getTestWorkspace_nocache('linux', 'i386', 'vdir.llvm', vw=vw)\nvw = helpers.getTestWorkspace_nocache('linux', 'i386', 'ld-2.31.so', vw=vw)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
minor tweak and a minor bugfix in linker
718,770
30.12.2022 16:47:25
18,000
bd92aa527fbd5044ce81e719649f284701d58394
cleanup and mods per
[ { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -143,6 +143,7 @@ class IMemory:\nExample probeMemory(0x41414141, 20, envi.memory.MM_WRITE)\n(check if the memory for 20 bytes at 0x41414141 is writable)\n\"\"\"\n+ #FIXME: make probeMemory handle cross-map access as well as _supervisor\nmmap = self.getMemoryMap(va)\nif mmap is None:\nreturn False\n@@ -439,7 +440,7 @@ class MemoryObject(IMemory):\ndef getAdminRights(self):\n'''\nSupport function for ContextManager to support usage like:\n- \"with vw.getAdminWrites():\"\n+ \"with vw.getAdminRights():\"\nSets _supervisor privileges (allowing writes to all workspace maps),\nyields to perform the user's write-action, then sets _supervisor back\n@@ -606,7 +607,7 @@ class MemoryObject(IMemory):\ndef _reqProbeMem(self, va, size, perm):\n'''\n- Calls probeMemory() and either returns or raises the appropriate exception\n+ Checks memory map permissions and either returns True or raises the appropriate exception\n'''\nmsg = None\n@@ -633,7 +634,7 @@ class MemoryObject(IMemory):\nmapva, mapsize, mapperm, mapfile = curmap\n# check permissions\n- if mapperm & perm != perm:\n+ if (mapperm & perm != perm) and not self._supervisor:\nif curmap != startmap:\nmsg = \"Bad Memory Access (%r): 0x%x: 0x%x (orig va: 0x%x)\" % (\ngetPermName(perm), mapva, size, va)\n" }, { "change_type": "MODIFY", "old_path": "vivisect/__init__.py", "new_path": "vivisect/__init__.py", "diff": "@@ -2852,6 +2852,7 @@ class VivWorkspace(e_mem.MemoryObject, viv_base.VivWorkspaceCore):\nOverride writeMemory to hook into the Event subsystem.\nStores overwritten data for easy undo.\n'''\n+ self._reqProbeMem(va, len(bytez), e_mem.MM_WRITE)\noldbytes = self.readMemory(va, len(bytez))\nself._fireEvent(VWE_WRITEMEM, (va, bytez, oldbytes))\n" }, { "change_type": "MODIFY", "old_path": "vivisect/const.py", "new_path": "vivisect/const.py", "diff": "@@ -71,7 +71,7 @@ VWE_CHAT = 40 # (username, message)\nVWE_SYMHINT = 41 # (va, idx, hint)\nVWE_AUTOANALFIN = 42 # (starttime, endtime)\n-VWE_WRITEMEM = 43 # (mapva, offset, bytes)\n+VWE_WRITEMEM = 43 # (va, bytes, oldbytes)\nVWE_MAX = 44\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -300,7 +300,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\nvw.addNoReturnApi(\"*.pthread_exit\")\nvw.addNoReturnApi(\"*.longjmp\")\n- # for VivWorkspace, MSB==1, LSB==0... which is the same as True/False\n+ # for VivWorkspace, MSB==1, LSB==0... which is the same as True/False for Big-Endian\nvw.setEndian(elf.getEndian())\n# Base addr is earliest section address rounded to pagesize\n@@ -427,9 +427,7 @@ def loadElfIntoWorkspace(vw, elf, filename=None, baseaddr=None):\ncontinue # Skip non-memory mapped sections\nsva = sec.sh_addr\n- logger.warning(\"sva = sec.sh_addr (0x%x)\", sva)\nsva += baseoff\n- logger.warning(\"sva += baseoff (0x%x) == 0x%x\", baseoff, sva)\n# if we've already defined a location at this address, skip it. (eg. DYNAMICS)\nif vw.getLocation(sva) == sva:\n@@ -1057,3 +1055,37 @@ def isStripped(elf):\nreturn True\nreturn False\n+\n+\n+'''\n+Base Offsets are complicated, so let's break them down a bit.\n+\n+Base Offsets originally refered to whether to add a base address to values to come up with a virtual address.\n+Variations of ELFs that regularly cause problems/differences:\n+ * Shared Objects\n+ * Kernel Modules / Object files\n+ * Prelinked SO's and EXEs\n+\n+Accesses which are impacted by these addresses/offsets:\n+ * Pointer to Program Headers\n+ * Pointer to Section Headers\n+ * Program Headers\n+ * Sections\n+ * Dynamics Table\n+ * Dynamics Entries (see dt_rebase for existing list which require adding base offsets)\n+ Via either Sections or Dynamics:\n+ * String Table(s)\n+ * Symbol Table(s)\n+ * Relocs Table(s)\n+ * GOT\n+ * PLT\n+ * INIT / FINI\n+ * INIT_ARRAY / FINI_ARRAY / PREINIT_ARRAY\n+ * ??? Dwarf?\n+\n+If a file isn't intended for relocation, this can cause problems because:\n+ * Pointers can be hard-coded into the instructions themselves\n+ * ELF headers/Dynamics can not understand the relocatable parts\n+\n+\n+'''\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -5,6 +5,7 @@ import tempfile\nimport unittest\nimport envi\n+import envi.exc as e_exc\nimport envi.memory as e_memory\nimport envi.memcanvas as e_mcanvas\n@@ -1610,3 +1611,28 @@ class VivisectTest(v_t_utils.VivTest):\n# since it's assigned, the result from \"vw.getVivGuid()\" should be the same\nself.assertEqual(newguid, vw.getVivGuid())\n+\n+ def test_write_fail(self):\n+ with self.snap(self.chown_vw) as vw:\n+ base = vw.getFileMeta('chown', 'imagebase')\n+\n+ oldmem = vw.readMemory(base, 10)\n+\n+ #import envi.interactive as ei; ei.dbg_interact(locals(), globals())\n+ with self.assertRaises(e_exc.SegmentationViolation):\n+ vw.writeMemory(base, b\"testing...\")\n+\n+ self.assertEqual(oldmem, vw.readMemory(base, 10))\n+\n+ with vw.getAdminRights():\n+ vw.writeMemory(base, b\"testing...\")\n+\n+ self.assertEqual(b'testing...', vw.readMemory(base, 10))\n+\n+ with self.assertRaises(e_exc.SegmentationViolation):\n+ vw.writeMemory(base, b\"FOOBARBAZ.\")\n+\n+ self.assertEqual(b'testing...', vw.readMemory(base, 10))\n+\n+ with vw.getAdminRights():\n+ vw.writeMemory(base, oldmem)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
cleanup and mods per @invisig0th
718,770
30.12.2022 17:15:05
18,000
d08253f8de49c88201c63eedeb8976cdaf6d28a9
_reqProbeMem bugfix! cleanup isSet->is_set
[ { "change_type": "MODIFY", "old_path": "envi/cli.py", "new_path": "envi/cli.py", "diff": "@@ -259,7 +259,7 @@ class EnviCli(Cmd):\nif intro is not None:\nself.vprint(intro)\n- while not self.shutdown.isSet():\n+ while not self.shutdown.is_set():\ntry:\nCmd.cmdloop(self, intro=intro)\nexcept Exception:\n@@ -311,7 +311,7 @@ class EnviCli(Cmd):\nself.vprint(\"\\nERROR: (%s) %s\" % (msg.__class__.__name__, msg))\nlogger.warning(\"\\nERROR: (%s) %s\", msg.__class__.__name__, msg, exc_info=1)\n- if self.shutdown.isSet():\n+ if self.shutdown.is_set():\nreturn True\ndef do_help(self, line):\n" }, { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -628,10 +628,10 @@ class MemoryObject(IMemory):\n# check that all memory is valid and correct permissions\nptr = va\ncurmap = startmap\n- endmapva, endmapsize, endmapperm, endmapfile = endmap\n+ endmapva, endmapsz, endmapperm, endmapfile = endmap\nwhile True:\n- mapva, mapsize, mapperm, mapfile = curmap\n+ mapva, mapsz, mapperm, mapfile = curmap\n# check permissions\nif (mapperm & perm != perm) and not self._supervisor:\n@@ -644,11 +644,11 @@ class MemoryObject(IMemory):\nraise envi.SegmentationViolation(va, msg)\n# if the endmap exists, and we are here, and the perms check out... we're good!\n- if ptr == endmapva:\n+ if endmapva <= ptr < endmapva+endmapsz:\nbreak\n# go to next map\n- ptr = mapva + mapsize\n+ ptr = mapva + mapsz\ncurmap = self.getMemoryMap(ptr)\nif not curmap:\nmsg = \"Bad Memory Access (invalid memory range): 0x%x: 0x%x (%s)\" % (\n" } ]
Python
Apache License 2.0
vivisect/vivisect
_reqProbeMem bugfix! cleanup isSet->is_set
718,766
13.01.2023 12:35:53
18,000
5a3d41efec8c03e0e1d731b55e2f4af327f90670
Don't log to root logger
[ { "change_type": "MODIFY", "old_path": "vstruct/defs/minidump.py", "new_path": "vstruct/defs/minidump.py", "diff": "@@ -3,6 +3,8 @@ import logging\nimport vstruct\nfrom vstruct.primitives import *\n+logger = logging.getLogger(__name__)\n+\nclass MiniDumpString(vstruct.VStruct):\ndef __init__(self):\nvstruct.VStruct.__init__(self)\n@@ -570,7 +572,7 @@ class MiniDump(object):\nstream = vars(self)[sclass.__name__] = sclass()\nstream.vsParse(bytez, offset=soffset)\nelse:\n- logging.info('Unknown stream type of %d', header.StreamType)\n+ logger.info('Unknown stream type of %d', header.StreamType)\ndef tree(self):\ntxt = []\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Don't log to root logger (#565)
718,772
23.01.2023 08:57:30
28,800
8181858bd4025cc1959edd2482dd0d87bdcd3838
Update vamp signatures (replaces old PR#208) * Update vamp signatures (former PR#208) * unit test for signatures * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert
[ { "change_type": "ADD", "old_path": null, "new_path": "vivisect/tests/testvampsigs.py", "diff": "+import unittest\n+\n+import vivisect\n+import envi.memory as e_mem\n+\n+\n+class VampSigTests(unittest.TestCase):\n+ '''\n+ Tests to verify detection of signatures for special functions in PE files.\n+ If a signature is detected during makeFunc(), it should mark the\n+ function as a thunk and name it according to the signature.\n+ '''\n+\n+ def run_test(self, opcode_string):\n+ # Create a Vivisect workspace, architecture does not matter.\n+ vw = vivisect.VivWorkspace()\n+ vw.setMeta('Architecture', 'i386')\n+ vw.setMeta('Platform', 'windows')\n+ vw.setMeta('Format', 'pe')\n+\n+ # Add the module that detects signatures.\n+ vw.addFuncAnalysisModule(\"vivisect.analysis.ms.msvc\")\n+\n+ # Put the opcodes into an executable memory map.\n+ mapbase = 0x400000\n+ bufferpgsz = 2 * 4096\n+ vw.addMemoryMap(mapbase - bufferpgsz, e_mem.MM_RWX,\n+ 'test', '@' * bufferpgsz)\n+ bytez = bytes(bytearray.fromhex(opcode_string))\n+ vw.addMemoryMap(mapbase, e_mem.MM_RWX, 'test', bytez)\n+ vw.addSegment(mapbase, len(bytez), 'test_code_%x' % mapbase, 'test')\n+\n+ # Make a function, triggering signature detection.\n+ fva = mapbase\n+ vw.makeFunction(fva)\n+ return vw.getFunctionMeta(fva, 'Thunk')\n+\n+\n+ def test_sig_behavior(self):\n+ '''\n+ Test the behavior of signature detection.\n+ '''\n+ # True signature.\n+ opcodes = '680000000064a10000000050'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh3_prolog')\n+\n+ # Incorrect signature.\n+ opcodes = '680000000064a100000000aa'\n+ self.assertEqual(self.run_test(opcodes), None)\n+\n+ # Signature with masked out bytes changed.\n+ opcodes = '68aaaaaaaa64a10000000050'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh3_prolog')\n+\n+ # Signature with extra opcodes.\n+ opcodes = '680000000064a100000000504141414141'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh3_prolog')\n+\n+ # Signature with opcodes before.\n+ opcodes = '4141680000000064a10000000050'\n+ self.assertEqual(self.run_test(opcodes), None)\n+\n+\n+ def test_seh_sigs(self):\n+ '''\n+ Test detection of seh prolog and epilog signatures.\n+ '''\n+ opcodes = '680000000064a10000000050'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh3_prolog')\n+\n+ opcodes = '8b4df064890d00000000595f5e5bc951c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh3_epilog')\n+\n+ opcodes = '680000000064ff35000000008b442410'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh4_prolog')\n+\n+ opcodes = '8b4df064890d00000000595f5f5e5b8be55d51c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh4_epilog')\n+\n+ opcodes = '8b4df064890d00000000595f5f5e5b8be55d51f2c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.seh4_epilog')\n+\n+ opcodes = 'a10000000033c58945fc'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.gs_prolog')\n+\n+\n+ def test_alloca_probe_sigs(self):\n+ '''\n+ Test detection of alloca_probe signatures.\n+ '''\n+ opcodes = '513d001000008d4c2408721481e9001000002d0010000085013d0010000073ec2bc88bc485018be18b088b400450c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll._alloca_probe')\n+\n+ opcodes = '518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8720a8bc159948b00890424c32d001000008500ebe9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll._alloca_probe')\n+\n+ opcodes = '518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8f2720b8bc159948b00890424f2c32d001000008500ebe7'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll._alloca_probe')\n+\n+ opcodes = '4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd37316664181e200f04d8d9b00f0ffff41c603004d3bd375f04c8b14244c8b5c24084883c410c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll._alloca_probe')\n+\n+ opcodes = '4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd3f27317664181e200f04d8d9b00f0ffff41c603004d3bd3f275ef4c8b14244c8b5c24084883c410f2c3'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll._alloca_probe')\n+\n+\n+ def test_security_cookie_sigs(self):\n+ '''\n+ Test detection of security_check_cookie signatures.\n+ '''\n+ opcodes = '3b0d000000007502f3c3e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie')\n+\n+ opcodes = '3b0d00000000f27502f2c3f2e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie')\n+\n+ opcodes = '483b0d00000000751148c1c11066f7c1ffff7502f3c348c1c910e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie_64')\n+\n+ opcodes = '483b0d00000000f2751148c1c11066f7c1fffff27502f2c348c1c910e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie_64')\n+\n+ opcodes = '483b0d00000000f2751248c1c11066f7c1fffff27502f2c348c1c910e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie_64')\n+\n+\n+ def test_gs_failure_sigs(self):\n+ '''\n+ Test detection of gs_failure signatures.\n+ '''\n+ opcodes = '3b0d000000007502f3c3e9'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.security_check_cookie')\n+ opcodes = '8bff558bec5151a300000000890d00000000891500000000891d00000000893500000000893d000000008c15000000008c0d000000008c1d000000008c05000000008c25000000008c2d000000009c'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.report_gsfailure')\n+\n+ opcodes = '8bff558bec81ec28030000a300000000890d00000000891500000000891d00000000893500000000893d00000000668c1500000000668c0d00000000668c1d00000000668c0500000000668c2500000000668c2d000000009c'\n+ self.assertEqual(self.run_test(opcodes), 'ntdll.report_gsfailure')\n" }, { "change_type": "MODIFY", "old_path": "vivisect/tests/testvivisect.py", "new_path": "vivisect/tests/testvivisect.py", "diff": "@@ -1528,7 +1528,8 @@ class VivisectTest(v_t_utils.VivTest):\n0x140049770, 0x140049bf0, 0x140049b80, 0x140049780, 0x140049a00, 0x140049900, 0x140049700,\n0x140049800, 0x140049880, 0x140049c00, 0x140049b00, 0x140049a10, 0x140049790, 0x140049810,\n0x140049a90, 0x140049710, 0x14001ef10, 0x140049890, 0x140049910, 0x140049b90, 0x140049c10,\n- 0x140049b40, 0x140049aa0, 0x1400497a0, 0x140049720, 0x140049820, 0x140049a20, 0x140048a10]\n+ 0x140049b40, 0x140049aa0, 0x1400497a0, 0x140049720, 0x140049820, 0x140049a20, 0x140048a10,\n+ 0x140048a80]\nself.assertEqual(thunks, set(impthunk))\n" }, { "change_type": "MODIFY", "old_path": "vivisect/vamp/msvc/__init__.py", "new_path": "vivisect/vamp/msvc/__init__.py", "diff": "@@ -8,28 +8,45 @@ import envi.bytesig as e_bytesig\nsigs = [\n('680000000064a10000000050', 'ff00000000ffffffffffffff', 'ntdll.seh3_prolog'),\n('8b4df064890d00000000595f5e5bc951c3', None, 'ntdll.seh3_epilog'),\n- ('8b4df064890d00000000595f5f5e5b8be55d51c3', None, 'ntdll.seh4_epilog'),\n('680000000064ff35000000008b442410', 'ff00000000ffffffffffffffffffffff', 'ntdll.seh4_prolog'),\n+ # Seen in 32-bit samples using VS 2005, 2008, 2010, 2012, 2013.\n+ ('8b4df064890d00000000595f5f5e5b8be55d51c3', None, 'ntdll.seh4_epilog'),\n+ # Seen in 32-bit samples using VS 2015, 2017 15.0.\n+ ('8b4df064890d00000000595f5f5e5b8be55d51f2c3', None, 'ntdll.seh4_epilog'),\n('a10000000033c58945fc', 'ff00000000ffffffffff', 'ntdll.gs_prolog'),\n- ('513d001000008d4c2408721481e9001000002d0010000085013d0010000073ec2bc88bc485018be18b088b400450c3', None, 'ntdll._alloca_probe'), #32-bit VS 6.0\n- ('518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8720a8bc159948b00890424c32d001000008500ebe9', None, 'ntdll._alloca_probe'), # 32-bit VS 2005, 2008, 2010, 2012, 2013\n- ('518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8f2720b8bc159948b00890424f2c32d001000008500ebe7', None, 'ntdll._alloca_probe'), # 32-bit VS 2015, 2017, 2019\n- ('4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd37316664181e200f04d8d9b00f0ffff41c603004d3bd375f04c8b14244c8b5c24084883c410c3', None, 'ntdll._alloca_probe'), # 64-bit VS 2005, 2008, 2010, 2012, 2013, 2015\n- ('4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd3f27317664181e200f04d8d9b00f0ffff41c603004d3bd3f275ef4c8b14244c8b5c24084883c410f2c3', None, 'ntdll._alloca_probe'), # 64-bit VS 2017, 2019\n+ # Seen in 32-bit samples using VS 6.\n+ ('513d001000008d4c2408721481e9001000002d0010000085013d0010000073ec2bc88bc485018be18b088b400450c3', None, 'ntdll._alloca_probe'),\n+ # Seen in 32-bit samples using VS 2005, 2008, 2010, 2012, 2013.\n+ ('518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8720a8bc159948b00890424c32d001000008500ebe9', None, 'ntdll._alloca_probe'),\n+ # Seen in 32-bit samples using VS 2015, 2017, 2019.\n+ ('518d4c24042bc81bc0f7d023c88bc42500f0ffff3bc8f2720b8bc159948b00890424f2c32d001000008500ebe7', None, 'ntdll._alloca_probe'),\n+ # Seen in 64-bit samples using VS 2005, 2008, 2010, 2012, 2013, 2015.\n+ ('4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd37316664181e200f04d8d9b00f0ffff41c603004d3bd375f04c8b14244c8b5c24084883c410c3', None, 'ntdll._alloca_probe'),\n+ # Seen in 64-bit samples using VS 2017, 2019.\n+ ('4883ec104c8914244c895c24084d33db4c8d5424184c2bd04d0f42d3654c8b1c25100000004d3bd3f27317664181e200f04d8d9b00f0ffff41c603004d3bd3f275ef4c8b14244c8b5c24084883c410f2c3', None, 'ntdll._alloca_probe'),\n+\n+# ('3b0d000000000f85afdc0200c3', 'ffff00000000ffffffffffffff', 'ntdll.security_check_cookie'),\n+ # 32-bit assembly used in VS 2005, 2008, 2010, 2012, 2013.\n+ ('3b0d000000007502f3c3e9', 'ffff00000000ffffffffff','ntdll.security_check_cookie'),\n+ # 32-bit assembly used in VS 2015, 2017 (includes bnd opcodes).\n+ ('3b0d00000000f27502f2c3f2e9', 'ffff00000000ffffffffffffff', 'ntdll.security_check_cookie'),\n+ # 64-bit assembly used in VS 2005, 2008, 2010, 2012, 2013.\n+ ('483b0d00000000751148c1c11066f7c1ffff7502f3c348c1c910e9', 'ffffff00000000ffffffffffffffffffffffffffffffffffffffff', 'ntdll.security_check_cookie_64'),\n+ # 64-bit assembly used in VS 2015.\n+ ('483b0d00000000f2751148c1c11066f7c1fffff27502f2c348c1c910e9', 'ffffff00000000ffffffffffffffffffffffffffffffffffffffffffff', 'ntdll.security_check_cookie_64'),\n+ # 64-bit assembly used in VS 2019.\n+ ('483b0d00000000f2751248c1c11066f7c1fffff27502f2c348c1c910e9', 'ffffff00000000ffffffffffffffffffffffffffffffffffffffffffff', 'ntdll.security_check_cookie_64'),\n- ('3b0d000000000f85afdc0200c3', 'ffff00000000ffffffffffffff', 'ntdll.security_check_cookie'),\n('8bff558bec5151a300000000890d00000000891500000000891d00000000893500000000893d000000008c15000000008c0d000000008c1d000000008c05000000008c25000000008c2d000000009c',\n'ffffffffffffffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ff',\n'ntdll.report_gsfailure',\n),\n-\n('8bff558bec81ec28030000a300000000890d00000000891500000000891d00000000893500000000893d00000000668c1500000000668c0d00000000668c1d00000000668c0500000000668c2500000000668c2d000000009c',\n'ffffffffffffffffffffffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffff00000000ffffff00000000ffffff00000000ffffff00000000ffffff00000000ffffff00000000ffffff00000000ff',\n'ntdll.report_gsfailure',\n),\n- ('3b0d000000007502f3c3e9', 'ffff00000000ffffffffff','ntdll.security_check_cookie'),\n('6aff5064a100000000508b44240c64892500000000896c240c8d6c240c50c3',None, 'ntdll.eh_prolog'),\n]\n" } ]
Python
Apache License 2.0
vivisect/vivisect
Update vamp signatures (replaces old PR#208) (#566) * Update vamp signatures (former PR#208) * unit test for signatures * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert * Update vivisect/tests/testvampsigs.py self.assertEqual instead of assert Co-authored-by: todd-plantenga <todd.plantenga@mandiant.com> Co-authored-by: atlas0fd00m <atlas@r4780y.com>
718,770
02.02.2023 08:57:19
18,000
21deba74cafcb187b324d74b260e0d89044ece73
viv_loader Cleanup and Polish * IMemory bug discovered by Rakuy0 merge fail in ELF parser (regressing certain related sections) * minor bugfix for VQVivFuncgraphCanvas.renderMemory
[ { "change_type": "MODIFY", "old_path": "envi/memory.py", "new_path": "envi/memory.py", "diff": "@@ -69,6 +69,7 @@ class IMemory:\nself.setMemArchitecture(arch)\nself.bigend = envi.ENDIAN_LSB\n+ self._supervisor = False\ndef getEndian(self):\n'''\n@@ -434,7 +435,6 @@ class MemoryObject(IMemory):\n\"\"\"\nIMemory.__init__(self, arch=arch)\nself._map_defs = []\n- self._supervisor = False\n@contextlib.contextmanager\ndef getAdminRights(self):\n" }, { "change_type": "MODIFY", "old_path": "vivisect/parsers/elf.py", "new_path": "vivisect/parsers/elf.py", "diff": "@@ -725,7 +725,15 @@ def applyRelocs(elf, vw, addbase=False, baseoff=0):\nfor secidx, r in elf.getRelocs():\nrtype = r.getType()\nrlva = r.r_offset\n+ if elf.isRelocatable():\n+ container = elf.getSectionByIndex(secidx)\n+ if container.sh_flags & elf_lookup.SHF_INFO_LINK:\n+ othr = elf.getSectionByIndex(container.sh_info)\n+ if othr:\n+ rlva += othr.sh_addr\n+\nrlva += baseoff\n+\ntry:\n# If it has a name, it's an externally resolved \"import\" entry,\n# otherwise, just a regular reloc\n" }, { "change_type": "MODIFY", "old_path": "vivisect/qt/funcgraph.py", "new_path": "vivisect/qt/funcgraph.py", "diff": "@@ -111,8 +111,14 @@ class VQVivFuncgraphCanvas(vq_memory.VivCanvasBase):\nrunner = functools.partial(self._renderMemoryFinish, cb)\ne_memcanvas.MemoryCanvas.renderMemory(self, va, size, cb=runner)\n- def renderMemory(self, va, size, cb):\n+ def renderMemory(self, va, size, cb=None):\n+ '''\n+ Funcgraph specific renderMemory() function.\n+ '''\n# For the funcgraph canvas, this will be called once per code block\n+ if not cb:\n+ cb = self.__nopcb\n+\nselector = 'codeblock_%.8x' % va\njs = '''var node = document.querySelector(\"#%s\");\nif (node == null) {\n@@ -127,6 +133,9 @@ class VQVivFuncgraphCanvas(vq_memory.VivCanvasBase):\nlogger.log(MIRE, \"renderMemory(%r, %r) %r\", va, cb, runner)\nself.page().runJavaScript(js, runner)\n+ def __nopcb(self):\n+ pass\n+\ndef contextMenuEvent(self, event):\nif self._canv_curva is not None:\nmenu = vq_ctxmenu.buildContextMenu(self.vw, va=self._canv_curva, parent=self)\n" } ]
Python
Apache License 2.0
vivisect/vivisect
viv_loader Cleanup and Polish (#564) * IMemory bug discovered by Rakuy0 merge fail in ELF parser (regressing certain related sections) * minor bugfix for VQVivFuncgraphCanvas.renderMemory
701,855
03.03.2017 11:54:14
-46,800
ed5031cd0b7cbcc6c96fd51d15731d91b330d836
Add Gulp front end tooling for scss compilation and live reload
[ { "change_type": "MODIFY", "old_path": ".gitignore", "new_path": ".gitignore", "diff": "@@ -92,3 +92,6 @@ ENV/\n# Rope project settings\n.ropeproject\n+\n+# Installed node modules\n+node_modules/\n" }, { "change_type": "MODIFY", "old_path": "csunplugged/config/settings.py", "new_path": "csunplugged/config/settings.py", "diff": "@@ -126,5 +126,5 @@ LOCALE_PATHS = ['locale']\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = (\n- os.path.join(BASE_DIR, 'static'),\n+ os.path.join(BASE_DIR, 'build'),\n)\n" }, { "change_type": "ADD", "old_path": null, "new_path": "csunplugged/gulpfile.js", "diff": "+'use strict';\n+var gulp = require('gulp');\n+var gutil = require('gulp-util');\n+var del = require('del');\n+var uglify = require('gulp-uglify');\n+var gulpif = require('gulp-if');\n+var exec = require('child_process').exec;\n+\n+\n+var notify = require('gulp-notify');\n+\n+var buffer = require('vinyl-buffer');\n+var argv = require('yargs').argv;\n+// sass\n+var sass = require('gulp-sass');\n+var postcss = require('gulp-postcss');\n+var autoprefixer = require('autoprefixer-core');\n+var sourcemaps = require('gulp-sourcemaps');\n+// BrowserSync\n+var browserSync = require('browser-sync');\n+// js\n+var watchify = require('watchify');\n+var browserify = require('browserify');\n+var source = require('vinyl-source-stream');\n+// linting\n+var jshint = require('gulp-jshint');\n+var stylish = require('jshint-stylish');\n+\n+\n+// gulp build --production\n+var production = !!argv.production;\n+// determine if we're doing a build\n+// and if so, bypass the livereload\n+var build = argv._.length ? argv._[0] === 'build' : false;\n+var watch = argv._.length ? argv._[0] === 'watch' : true;\n+\n+// ----------------------------\n+// Error notification methods\n+// ----------------------------\n+var beep = function() {\n+ var os = require('os');\n+ var file = 'gulp/error.wav';\n+ if (os.platform() === 'linux') {\n+ // linux\n+ exec(\"aplay \" + file);\n+ } else {\n+ // mac\n+ console.log(\"afplay \" + file);\n+ exec(\"afplay \" + file);\n+ }\n+};\n+var handleError = function(task) {\n+ return function(err) {\n+ beep();\n+\n+ notify.onError({\n+ message: task + ' failed, check the logs..',\n+ sound: false\n+ })(err);\n+\n+ gutil.log(gutil.colors.bgRed(task + ' error:'), gutil.colors.red(err));\n+ };\n+};\n+// --------------------------\n+// CUSTOM TASK METHODS\n+// --------------------------\n+var tasks = {\n+ // --------------------------\n+ // Delete build folder\n+ // --------------------------\n+ clean: function(cb) {\n+ del(['build/'], cb);\n+ },\n+ // --------------------------\n+ // Copy static images\n+ // --------------------------\n+ images: function() {\n+ return gulp.src('./static/img/**/*')\n+ .pipe(gulp.dest('build/img'));\n+ },\n+ // --------------------------\n+ // CSS\n+ // --------------------------\n+ css: function() {\n+ gulp.src('static/css/**/*.css')\n+ .pipe(gulp.dest('build/css'));\n+ },\n+ // --------------------------\n+ // JS\n+ // --------------------------\n+ js: function() {\n+ gulp.src('static/js/**/*.js')\n+ .pipe(gulp.dest('build/js'));\n+ },\n+ // --------------------------\n+ // SASS (libsass)\n+ // --------------------------\n+ sass: function() {\n+ return gulp.src('./static/scss/*.scss')\n+ // sourcemaps + sass + error handling\n+ .pipe(gulpif(!production, sourcemaps.init()))\n+ .pipe(sass({\n+ sourceComments: !production,\n+ outputStyle: production ? 'compressed' : 'nested'\n+ }))\n+ .on('error', handleError('SASS'))\n+ // generate .maps\n+ .pipe(gulpif(!production, sourcemaps.write({\n+ 'includeContent': false,\n+ 'sourceRoot': '.'\n+ })))\n+ // autoprefixer\n+ .pipe(gulpif(!production, sourcemaps.init({\n+ 'loadMaps': true\n+ })))\n+ .pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))\n+ // we don't serve the source files\n+ // so include scss content inside the sourcemaps\n+ .pipe(sourcemaps.write({\n+ 'includeContent': true\n+ }))\n+ // write sourcemaps to a specific directory\n+ // give it a file and save\n+ .pipe(gulp.dest('build/css'));\n+ },\n+\n+ // --------------------------\n+ // linting\n+ // --------------------------\n+ lintjs: function() {\n+ return gulp.src([\n+ 'gulpfile.js',\n+ './static/js/index.js',\n+ './static/js/**/*.js'\n+ ]).pipe(jshint())\n+ .pipe(jshint.reporter(stylish))\n+ .on('error', function() {\n+ beep();\n+ });\n+ },\n+};\n+\n+gulp.task('browser-sync', function() {\n+ browserSync.init({\n+ proxy: \"localhost:8000\",\n+ port: process.env.PORT || 3000\n+ });\n+});\n+\n+gulp.task('reload-sass', ['sass'], function(){\n+ browserSync.reload();\n+});\n+gulp.task('reload-js', ['js'], function(){\n+ browserSync.reload();\n+});\n+gulp.task('reload-css', ['css'], function(){\n+ browserSync.reload();\n+});\n+gulp.task('reload-templates', [], function(){\n+ browserSync.reload();\n+});\n+\n+// // --------------------------\n+// // CUSTOMS TASKS\n+// // --------------------------\n+gulp.task('clean', tasks.clean);\n+// // for production we require the clean method on every individual task\n+var req = [];\n+// // individual tasks\n+gulp.task('images', req, tasks.images);\n+gulp.task('js', req, tasks.js);\n+gulp.task('css', req, tasks.css);\n+gulp.task('sass', req, tasks.sass);\n+gulp.task('lint:js', tasks.lintjs);\n+gulp.task('optimize', tasks.optimize);\n+gulp.task('test', tasks.test);\n+\n+// --------------------------\n+// DEV/WATCH TASK\n+// --------------------------\n+gulp.task('watch', ['images', 'css', 'js', 'sass', 'browser-sync'], function() {\n+\n+ // --------------------------\n+ // watch:sass\n+ // --------------------------\n+ gulp.watch('./static/scss/**/*.scss', ['reload-sass']);\n+\n+ // --------------------------\n+ // watch:js\n+ // --------------------------\n+ gulp.watch('./static/js/**/*.js', ['lint:js', 'reload-js']);\n+\n+ // --------------------------\n+ // watch:css\n+ // --------------------------\n+ gulp.watch('./static/css/**/*.css', ['reload-css']);\n+\n+ // --------------------------\n+ // watch:templates\n+ // --------------------------\n+ gulp.watch('./templates/**/*.html', ['reload-templates']);\n+\n+ gutil.log(gutil.colors.bgGreen('Watching for changes...'));\n+});\n+\n+// build task\n+gulp.task('build', [\n+ 'clean',\n+ 'images',\n+ 'css',\n+ 'js',\n+ 'sass'\n+]);\n+\n+gulp.task('default', ['watch']);\n+\n+// gulp (watch) : for development and livereload\n+// gulp build : for a one off development build\n+// gulp build --production : for a minified production build\n" } ]
Python
MIT License
uccser/cs-unplugged
Add Gulp front end tooling for scss compilation and live reload
701,852
20.04.2017 11:59:34
-43,200
8434667df3bda962b4e9e8a37650efd42feb77a7
Updated Travis configurations and associated processes.
[ { "change_type": "ADD", "old_path": null, "new_path": ".coveragerc", "diff": "+[run]\n+source = config,dev,general,locale,resources,static,templates,topics,utils\n+omit=*/migrations/*\n+\n+[report]\n+fail_under=50\n" }, { "change_type": "MODIFY", "old_path": ".flake8", "new_path": ".flake8", "diff": "@@ -9,6 +9,7 @@ exclude =\n# These files are mostly or completely autogenerated\nmigrations,\n+ manage.py,\ncsunplugged/manage.py,\n# This contains our built project files and documentation\n" }, { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -8,10 +8,22 @@ python:\n- \"3.6-dev\" # 3.6 development branch\n# Install dependencies\n-install: pip install flake8\n+install:\n+ - pip install flake8 coverage coveralls\n+ - pip install requirements/base.txt\n+\n+before_script:\n+ cd csunplugged &\n# Runs test suite\n-script: flake8\n+script:\n+ - flake8 --config=../.flake8\n+ - coverage run --rcfile=../.coveragerc manage.py test -v 3\n+ - 'if [ \"$TRAVIS_PULL_REQUEST\" != \"false\" ]; then bash manage.py test --reverse -v 0; fi'\n+\n+after_script:\n+ coverage report --rcfile=../.coveragerc\n+ #coveralls\n# Stop email notifications but post to organisation Slack channel\nnotifications:\n" }, { "change_type": "MODIFY", "old_path": "requirements/base.txt", "new_path": "requirements/base.txt", "diff": "@@ -14,6 +14,7 @@ django-environ==0.4.1\nPillow==4.0.0\n# Markdown\n+verto==0.4.0\npython-markdown-math==0.2\n# Models\n" } ]
Python
MIT License
uccser/cs-unplugged
Updated Travis configurations and associated processes.
701,852
20.04.2017 13:19:39
-43,200
a82305411ea33c2a9e063f762185006681992f61
Fix reversed tests.
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -18,8 +18,8 @@ before_script:\n# Runs test suite\nscript:\n- flake8 --config=../.flake8\n- - coverage run --rcfile=../.coveragerc manage.py test -v 3\n- - 'if [ \"$TRAVIS_PULL_REQUEST\" != \"false\" ]; then bash manage.py test --reverse -v 0; fi'\n+ - coverage run --rcfile=../.coveragerc manage.py test --pattern \"test_*.py\" -v 3\n+ - 'if [ \"$TRAVIS_PULL_REQUEST\" != \"false\" ]; then manage.py test --pattern \"test_*.py\" --reverse -v 0; fi'\nafter_script:\ncoverage report --rcfile=../.coveragerc\n" }, { "change_type": "MODIFY", "old_path": "csunplugged/tests/topics/models/classroom_resource.py", "new_path": "csunplugged/tests/topics/models/classroom_resource.py", "diff": "@@ -11,5 +11,5 @@ class ClassroomResourceModelTest(BaseTestWithDB):\nnew_resource = ClassroomResource.objects.create(\ntext='this is a resource'\n)\n- query_result = ClassroomResource.objects.get(pk=1)\n+ query_result = ClassroomResource.objects.get(text='this is a resource')\nself.assertEqual(query_result, new_resource)\n" }, { "change_type": "MODIFY", "old_path": "csunplugged/tests/topics/models/connected_generated_resource.py", "new_path": "csunplugged/tests/topics/models/connected_generated_resource.py", "diff": "@@ -18,5 +18,5 @@ class ConnectedGeneratedResourceModelTest(BaseTestWithDB):\nlesson=lesson,\ndescription='this is a description'\n)\n- query_result = ConnectedGeneratedResource.objects.get(pk=1)\n+ query_result = ConnectedGeneratedResource.objects.get(resource=resource, lesson=lesson)\nself.assertEqual(query_result, new_resource)\n" }, { "change_type": "MODIFY", "old_path": "csunplugged/tests/topics/models/curriculum_area.py", "new_path": "csunplugged/tests/topics/models/curriculum_area.py", "diff": "@@ -12,5 +12,6 @@ class CurriculumAreaModelTest(BaseTestWithDB):\nslug='slug',\nname='name',\n)\n- query_result = CurriculumArea.objects.get(pk=1)\n+ print(CurriculumArea.objects.count())\n+ query_result = CurriculumArea.objects.get(slug='slug')\nself.assertEqual(query_result, new_curriculum_area)\n" } ]
Python
MIT License
uccser/cs-unplugged
Fix reversed tests.
701,852
20.04.2017 13:39:42
-43,200
45ceef548793e90c14cfcbaca3a5f4856949e1a5
Update travis build for running locally and removed kordac
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -11,6 +11,7 @@ python:\ninstall:\n- pip install flake8 coverage coveralls\n- pip install -r requirements/base.txt\n+ - pip install -r requirements/local.txt\nbefore_script:\ncd csunplugged/\n" }, { "change_type": "DELETE", "old_path": "requirements/kordac.txt", "new_path": null, "diff": "-# Required dependencies for Kordac\n-markdown==2.6.8\n-beautifulsoup4==4.5.3\n-Jinja2==2.9.5\n-python-slugify==1.2.1\n" } ]
Python
MIT License
uccser/cs-unplugged
Update travis build for running locally and removed kordac
701,852
20.04.2017 13:43:07
-43,200
d8418663346db1703af0af08b1ee14f917c01a84
Include model_mommy in testing requirements
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -12,6 +12,7 @@ install:\n- pip install flake8 coverage coveralls\n- pip install -r requirements/base.txt\n- pip install -r requirements/local.txt\n+ - pip install -r requirements/test.txt\nbefore_script:\ncd csunplugged/\n" }, { "change_type": "MODIFY", "old_path": "requirements/test.txt", "new_path": "requirements/test.txt", "diff": "# Check Python style\nflake8==3.3.0\n+\n+# Mock Database\n+model_mommy==1.3.2\n" } ]
Python
MIT License
uccser/cs-unplugged
Include model_mommy in testing requirements
701,852
20.04.2017 13:45:23
-43,200
0a9ffdfba21e657ff9d85f9bec5df5109ac4a67b
Cut down dependencies into just the test config.
[ { "change_type": "MODIFY", "old_path": ".travis.yml", "new_path": ".travis.yml", "diff": "@@ -11,7 +11,6 @@ python:\ninstall:\n- pip install flake8 coverage coveralls\n- pip install -r requirements/base.txt\n- - pip install -r requirements/local.txt\n- pip install -r requirements/test.txt\nbefore_script:\n" }, { "change_type": "MODIFY", "old_path": "requirements/test.txt", "new_path": "requirements/test.txt", "diff": "# Test dependencies go here.\n-r base.txt\n+# Debugging Tools\n+django-debug-toolbar==1.6\n+django-extensions==1.7.7\n+\n# Check Python style\nflake8==3.3.0\n" } ]
Python
MIT License
uccser/cs-unplugged
Cut down dependencies into just the test config.