Refactor inject - [merged] #147

Closed
opened 2020-08-21 15:51:39 +03:00 by icex2 · 18 comments
icex2 commented 2020-08-21 15:51:39 +03:00 (Migrated from github.com)

Merges refactor-inject -> master

Major refactoring of the inject.exe tool which addresses the following major and minor issues (copy-paste from commit message):

Major:

  • Inject's debugger is not attached to the process before injecting DLL files. This misses out on OutputDebugString calls by anything logging in the DllMain functions of the hook dlls.

Minor:

  • Fix coloring of log entries
  • Add ASCII header to easily determine start
  • Fix file logging, log everything to a single log file
  • Enhance inject's debugger: log further debug events to incrase visibility on issues, proper exception handling for inject
  • Re-iterated code structure of inject

Screenshot:
image

_Merges refactor-inject -> master_ Major refactoring of the `inject.exe` tool which addresses the following major and minor issues (copy-paste from commit message): Major: * Inject's debugger is not attached to the process before injecting DLL files. This misses out on OutputDebugString calls by anything logging in the DllMain functions of the hook dlls. Minor: * Fix coloring of log entries * Add ASCII header to easily determine start * Fix file logging, log _everything_ to a single log file * Enhance inject's debugger: log further debug events to incrase visibility on issues, proper exception handling for inject * Re-iterated code structure of inject Screenshot: ![image](https://dev.s-ul.net/djhackers/bemanitools/uploads/57411e887f504948db57b3b5c8c197d3/image.png)
icex2 commented 2020-08-21 17:24:53 +03:00 (Migrated from github.com)

added 4 commits

  • 01779035 - util: Add signal module introducing signal and exception handling
  • 1c18422f - util/log: Add log_error which logs errors but does not abort
  • 4d01397a - inject: Major refactoring
  • 48a035c4 - inject: Fix windows psapi mess by explicitly defining version

Compare with previous version

added 4 commits <ul><li>01779035 - util: Add signal module introducing signal and exception handling</li><li>1c18422f - util/log: Add log_error which logs errors but does not abort</li><li>4d01397a - inject: Major refactoring</li><li>48a035c4 - inject: Fix windows psapi mess by explicitly defining version</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1285&start_sha=8138a7747b9c6dc5d7db2c789dc9e075aed16d92)
icex2 commented 2020-08-21 19:10:26 +03:00 (Migrated from github.com)

added 1 commit

  • b87fa799 - inject/logger: Add timestamps to log messages

Compare with previous version

added 1 commit <ul><li>b87fa799 - inject/logger: Add timestamps to log messages</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1287&start_sha=48a035c4eb5e97323e42d37c55bc24b64e9196c8)
icex2 commented 2020-09-01 05:45:35 +03:00 (Migrated from github.com)

In GitLab by @xyen on Sep 1, 2020, 04:45

Commented on src/main/inject/logger.c line 97

This is probably useful to port over to launcher / occur in log_writer_stdout

In GitLab by @xyen on Sep 1, 2020, 04:45 Commented on [src/main/inject/logger.c line 97](https://github.com/djhackersdev/bemanitools/compare/5de9fdee437e8aba712627c48e3080ac289f93b7..2280e17f1ef4dd4b647cf7385d8c73be408bf40e#diff-b4f75f2a0dc972fbede6b993011be338R97) This is probably useful to port over to launcher / occur in log_writer_stdout
icex2 commented 2020-09-01 05:45:35 +03:00 (Migrated from github.com)

In GitLab by @xyen on Sep 1, 2020, 04:45

Commented on src/main/inject/debugger.c line 40

Why do we need the filesize? you never seem to actually use it.

In GitLab by @xyen on Sep 1, 2020, 04:45 Commented on [src/main/inject/debugger.c line 40](https://github.com/djhackersdev/bemanitools/compare/3ab55b9ef02a1e052b4ca16c61a021092eced6d1..b87fa7995c2d7ad9bfd435605f81764a8158f8d8#diff-3391f44a35cb1c9d87265871235aa177R40) Why do we need the filesize? you never seem to actually use it.
icex2 commented 2020-09-01 05:45:35 +03:00 (Migrated from github.com)

In GitLab by @xyen on Sep 1, 2020, 04:45

Commented on src/main/inject/debugger.c line 196

This probably fits better in util's, and if we ever write a stack unwinder / crash handler it'll be useful there as well.

In GitLab by @xyen on Sep 1, 2020, 04:45 Commented on [src/main/inject/debugger.c line 196](https://github.com/djhackersdev/bemanitools/compare/3ab55b9ef02a1e052b4ca16c61a021092eced6d1..b87fa7995c2d7ad9bfd435605f81764a8158f8d8#diff-3391f44a35cb1c9d87265871235aa177R196) This probably fits better in util's, and if we ever write a stack unwinder / crash handler it'll be useful there as well.
icex2 commented 2020-09-01 05:45:36 +03:00 (Migrated from github.com)

In GitLab by @xyen on Sep 1, 2020, 04:45

Commented on src/main/util/log.h line 25

keep the naming as log_fatal, so we know that it'll hang / kill after calling this log message

In GitLab by @xyen on Sep 1, 2020, 04:45 Commented on [src/main/util/log.h line 25](https://github.com/djhackersdev/bemanitools/compare/3ab55b9ef02a1e052b4ca16c61a021092eced6d1..8062eeac3758c753dafaf42c58e14e0835057017#diff-6714a0d43d809ad5c819681cb86fe6a3R25) keep the naming as log_fatal, so we know that it'll hang / kill after calling this log message
icex2 commented 2020-09-02 20:53:54 +03:00 (Migrated from github.com)

It checks if the file size is > 0 afterwards. But I don't think that's super valuable and a file size of 1 byte would not be valid and be caught there. Removed.

It checks if the file size is > 0 afterwards. But I don't think that's super valuable and a file size of 1 byte would not be valid and be caught there. Removed.
icex2 commented 2020-09-02 20:55:31 +03:00 (Migrated from github.com)

Actually, there is something already in util/signal.c. Avoiding that duplicated code by exposing exception_code_to_str and using it in innject/debugger.c.

Actually, there is something already in `util/signal.c`. Avoiding that duplicated code by exposing `exception_code_to_str` and using it in `innject/debugger.c`.
icex2 commented 2020-09-02 21:06:10 +03:00 (Migrated from github.com)

There are situations when I still want something logged as an error because it is an error but the application should shut down gracefully. See the various spots in inject/main.c. For example, remote process created but hooking fails -> you want to cleanup the remote process to avoid having a zombie floating around that you have to kill with task manager all the time.

There are situations when I still want something logged as an error because it is an error but the application should shut down gracefully. See the various spots in `inject/main.c`. For example, remote process created but hooking fails -> you want to cleanup the remote process to avoid having a zombie floating around that you have to kill with task manager all the time.
icex2 commented 2020-09-02 21:06:51 +03:00 (Migrated from github.com)

changed this line in version 4 of the diff

changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1299&start_sha=b87fa7995c2d7ad9bfd435605f81764a8158f8d8#166e980a51a4b2d4545188eb0c1039fe9252193a_196_189)
icex2 commented 2020-09-02 21:06:51 +03:00 (Migrated from github.com)

changed this line in version 4 of the diff

changed this line in [version 4 of the diff](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1299&start_sha=b87fa7995c2d7ad9bfd435605f81764a8158f8d8#166e980a51a4b2d4545188eb0c1039fe9252193a_40_40)
icex2 commented 2020-09-02 21:06:52 +03:00 (Migrated from github.com)

added 5 commits

  • 022f397a - inject: Major refactoring
  • 00cd6b5d - inject: Fix windows psapi mess by explicitly defining version
  • faf1c45e - inject/logger: Add timestamps to log messages
  • 48dc109f - util/signal: Expose signal_exception_code_to_str
  • 8062eeac - inject/debugger: Avoid code dupe

Compare with previous version

added 5 commits <ul><li>022f397a - inject: Major refactoring</li><li>00cd6b5d - inject: Fix windows psapi mess by explicitly defining version</li><li>faf1c45e - inject/logger: Add timestamps to log messages</li><li>48dc109f - util/signal: Expose signal_exception_code_to_str</li><li>8062eeac - inject/debugger: Avoid code dupe</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1299&start_sha=b87fa7995c2d7ad9bfd435605f81764a8158f8d8)
icex2 commented 2020-09-02 22:29:52 +03:00 (Migrated from github.com)

changed this line in version 5 of the diff

changed this line in [version 5 of the diff](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1300&start_sha=8062eeac3758c753dafaf42c58e14e0835057017#7e9307f89d16d0d17f3f2b7b8ca24d93bbf49e76_25_25)
icex2 commented 2020-09-02 22:29:52 +03:00 (Migrated from github.com)

added 1 commit

  • 3f472817 - util/log: Remove log_error, replace occurances with log_warning

Compare with previous version

added 1 commit <ul><li>3f472817 - util/log: Remove log_error, replace occurances with log_warning</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1300&start_sha=8062eeac3758c753dafaf42c58e14e0835057017)
icex2 commented 2020-09-02 22:34:41 +03:00 (Migrated from github.com)

Decided to go for log_warning + "ERROR" string in the message in direct messaging with Xyen and Tau.

Decided to go for `log_warning` + "ERROR" string in the message in direct messaging with Xyen and Tau.
icex2 commented 2020-09-02 22:34:42 +03:00 (Migrated from github.com)

resolved all threads

resolved all threads
icex2 commented 2020-09-02 22:52:16 +03:00 (Migrated from github.com)

In GitLab by @xyen on Sep 2, 2020, 21:52

approved this merge request

In GitLab by @xyen on Sep 2, 2020, 21:52 approved this merge request
icex2 commented 2020-09-02 22:53:09 +03:00 (Migrated from github.com)

added 29 commits

  • 3f472817...5de9fdee - 18 commits from branch master
  • e934a4ab - Makefile: Fix clang format command
  • 3f0ea853 - Makefile: Fix minor inconsistency
  • a20cc7c4 - util/log: Add TODO pointing out design flaw
  • 5d2104ad - util: Add signal module introducing signal and exception handling
  • 806afe6e - util/log: Add log_error which logs errors but does not abort
  • 189ff755 - inject: Major refactoring
  • 19820943 - inject: Fix windows psapi mess by explicitly defining version
  • 8343449b - inject/logger: Add timestamps to log messages
  • b7694894 - util/signal: Expose signal_exception_code_to_str
  • afba1d5a - inject/debugger: Avoid code dupe
  • 2280e17f - util/log: Remove log_error, replace occurances with log_warning

Compare with previous version

added 29 commits <ul><li>3f472817...5de9fdee - 18 commits from branch <code>master</code></li><li>e934a4ab - Makefile: Fix clang format command</li><li>3f0ea853 - Makefile: Fix minor inconsistency</li><li>a20cc7c4 - util/log: Add TODO pointing out design flaw</li><li>5d2104ad - util: Add signal module introducing signal and exception handling</li><li>806afe6e - util/log: Add log_error which logs errors but does not abort</li><li>189ff755 - inject: Major refactoring</li><li>19820943 - inject: Fix windows psapi mess by explicitly defining version</li><li>8343449b - inject/logger: Add timestamps to log messages</li><li>b7694894 - util/signal: Expose signal_exception_code_to_str</li><li>afba1d5a - inject/debugger: Avoid code dupe</li><li>2280e17f - util/log: Remove log_error, replace occurances with log_warning</li></ul> [Compare with previous version](/djhackers/bemanitools/-/merge_requests/46/diffs?diff_id=1303&start_sha=3f4728177bb9a590f81759859290a414f053bd9a)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/djhackersdev_bemanitools#147